4

I have strange problem.

When I use @return Model\Article in the model-loading method then I see the model's methods in autocomplete of Eclipse.

The model-loading method returns more objects so I want it to @return My\BaseModel and then put the /* @var $model Model\Article */ for each model specificaly (when I use it).

The problem is that the @return Model\Article works well (I see Model\Article + My\BaseModel methods) but the other way (@return My\BaseModel and inline /*...*/) doesn't - it say's 'No completions available'.

I tried to place the inline comment before and after the $model = ...;, but neither worked.

I'm sorry for my bad English - I hope you understand.

Thank you for any kind of help, best regards, Jakub Chábek.

grongor
  • 1,305
  • 1
  • 13
  • 26

2 Answers2

5

Chronial: we did something wrong ...

All: here is bug report with same problem, but it is solved - I tried it and it works!

Here is working example:

namespace test {
    class AAA {

        /**
         * 
         * @return \test\AAA
         */
        static function getInstance() {
            return new static ();
        }
    }
}
namespace test2 {
    class BBB extends \test\AAA {
        /**
         * 
         * @return \test2\BBB
         */
        function showme() {
        }
    }
}

namespace test3 {
    $aaa = \test2\BBB::getInstance ();
    /* @var $aaa \test2\BBB */
    $aaa->
}

So there must be an misstake on my side ... but can't really find it :D

grongor
  • 1,305
  • 1
  • 13
  • 26
  • do you want know where was the ***** problem ? check this ... `/* @var $article Model\Article */` and this `/* @var $article \Model\Article */` ... wow, how I couldn't try it ?! – grongor Aug 13 '11 at 14:48
4

I've had problems with that before, too. Never found an easy and clean solution. When you are really desperate for code-completion, place an assignment at a position that will never be reached:

if (false) $myVar = new MyClass();

Eclipse will not realize that this code will never be executed and give you the appropriate code-completion.

Chronial
  • 66,706
  • 14
  • 93
  • 99
  • wow dude, are you kidding ? how is this *** possible ? :D it makes me laught and cry at the same time ... Why it work's like that ? Is it bug or there is an reason for it ? – grongor Aug 13 '11 at 00:36
  • Well, it just not feasible to try and make eclipse understand which parts of your code can be reached. The `if (false)` is just a very specific case insofar as it is obvious what is going to happen. – Chronial Aug 13 '11 at 00:39
  • But I don't really understand WHY is Eclipse ignoring the /* @var ... */ and it implements it while metting this condition ... – grongor Aug 13 '11 at 00:42
  • I don't know why it ignores it either. And Eclipse doesn't "implement" my solution. It just recognizes obvious type-assignments and does not recognize obvious program-flows. I just combine both to make eclipse do what I want ^^. – Chronial Aug 13 '11 at 00:47
  • I really dont know what to do ... it is annoying to write this and I would look like an idiot if I will distribute this code :D I think that I will blame Eclipse developers and then forget about that ... but thank you for your answer! It is really interesting ... – grongor Aug 13 '11 at 00:49
  • @Chronial: Better IDEs (like PhpStorm) have absolutely no problem to understand control flow (to some degree). Such a hack wouldn't work there. Good for Eclipse that it has bugs to fix it's other bugs ;) – NikiC Aug 13 '11 at 08:18
  • Bugs to fix it's other bugs - I will write it somewhere, perfectly said :D but ... I really like Eclipse more then PhpStorm, that's why I will stick with Eclipse anyway :) by the way, don't say 'better IDEs', because it's really subjectional – grongor Aug 13 '11 at 10:13