Eclipse completions - @var (PHPDoc) question

心已入冬 提交于 2020-01-02 06:32:49

问题


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.


回答1:


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




回答2:


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.



来源:https://stackoverflow.com/questions/7014837/eclipse-completions-var-phpdoc-question

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!