X

Defining a variable type in comment II

In the previous post I wrote about the new feature, which is requested by many people. In this entry I will write little more about this feature.

I wrote that the comment has to have a defined form. NetBeans can help you with writing it. There is registered new code template, which has the default abreviation vdoc. So when you write vdoc and press TAB key the letters vdoc are replaced with the comment template. The variable name is selected and you can change it. Then you can press TAB again and the type is selected.

As you can see the code completion works for both - variables and types.

This code template is smart:). If there is used a variable after the place, where you writing the template, then is the name of the variable suggested by default. If there is not any variable used after the place, where you are using the template, then the name of variable above is suggested as default. If NetBeans are not able locate any variable near to the line, where you are using the template, then as the default name is suggested variable

If NetBeans are able to find out the type of predefined variable then the type is also automatically entered.

I already mentioned that the mark occurrences works as well inside these comments.  The last thinks, which I want to mentioned today is that the hyperlink functionality works for the types. So when you place mouse cursor over the type and press CTRL, then the type is changed to a link, which will navigate to the type declaration. You can use CTRL+B shortcut, when the caret is inside the type name or Navigate -> Go to Declaration from context menu.


Join the discussion

Comments ( 34 )
  • Demian Turner Thursday, January 8, 2009

    A seriously nice feature - great work!


  • Łukasz Muchlado Thursday, January 8, 2009

    Runs like charm :) Because of that kind of features I have almost completely moved from using Eclipse's PDT2 to NetBeans.


  • Sam Thursday, January 8, 2009

    Why variables completion shows PHP platform vars? Noone will document them anyway…


  • Toby Mathews Thursday, January 8, 2009

    I must be doing something wrong, but I can't get this to work? Typing 'vdoc' and a tab results in just that text displaying - is there something I need to enable first?


  • Petr Thursday, January 8, 2009

    To Sam:

    I know, it would be better without the platform variables. We just reused what we had and we didn't implement special case for this. It's a question of the time. If you want, you can enter bug for this.

    To Toby:

    The feature was committed on Monday evening. So you have to use a recent build. Which build do you use?

    Thanks,

    Petr


  • Dietmar Sunday, January 11, 2009

    Hi,

    do you know, when this feature is going to be released in a stable version?

    Thanx

    Dietmar


  • Petr Monday, January 12, 2009

    To Dietmar:

    Currently the stable version of NB is planned at the end of June (http://wiki.netbeans.org/NetBeans70). But we will see, whether the reality will reflect the plans:). So far everything is going well.


  • Symen Timmermans Friday, January 16, 2009

    Hi Petr,

    This is seriously one of the best new features I was hoping to see in Netbeans. I recently switched from Aptana to Netbeans, just to see how I would like it. Turns out I like it pretty good. Aptana really has some quirks.

    I just downloaded the nightly build of the php editor, and tried out this feature.

    Unfortunately, it is not very CakePHP friendly.

    In CakePHP, the framework binds model classes to the controller runtime, for instance: in my UsersController I can use $this->User as a reference to my User model, and $this->User->Post as a reference to my Post model. There are no references in the code for these relations, so every editor fails to give me code hinting.

    What I (and a lot of CakePHP developers) could use is a way to do this:

    /\* @var $this->User User \*/

    and

    /\* @var $this->User->Post Post \*/

    But in any way, keep up the good work!


  • radek Monday, January 19, 2009
  • Petr Monday, January 19, 2009

    In the screencast there is a bug. The class property variable has to be with $. But Radek is right. Probably this should solved your problem.


  • Symen Timmermans Tuesday, January 20, 2009

    Thanks Radek and Petr!

    A lot of people are searching for this kind of functionality! I can now direct them to Netbeans!


  • Toby Mathews Tuesday, January 20, 2009

    Ah, I'm using a stable version too, I guess that's why I haven't got this feature.


  • azrael_valedhel Friday, January 23, 2009

    I downloaded the fresh nightbuild and this does not work here (windows xp sp3)

    code:

    class INI {

    /\*\*

    \* @var ADOConnection

    \*/

    static public $db; // code completion runs nicely for INI::$db->

    }

    //...

    /\* @var $query ADORecordSet \*/

    $query = INI::$db->Execute("sql query here");

    $query-> // no code completion here, when ctrl-space on the var - I can see ? where type should be.

    Is this a bug or am I doing something wrong?

    I can't get this feature to work at all (not only the example given), although I can see that the @var is a bit bolder.

    Strange...


  • Petr Sunday, January 25, 2009

    Hi Azrael,

    could you send me an example of code, which doesn't work for you? It can be bug, but I just to want to have an reproducible case.

    Regards,

    Petr


  • Yudi Setiawan Monday, January 26, 2009

    Hi,

    Just wondering does the code-completion support method-chaining?

    I'm using the lates night build (200901261401).

    Consider this sample of code:

    class Person

    {

    private $m_szName;

    private $m_iAge;

    public function setName($szName)

    {

    $this->m_szName = $szName;

    return $this;

    }

    public function setAge($iAge)

    {

    $this->m_iAge = $iAge;

    return $this;

    }

    public function introduce()

    {

    printf(

    'Hello my name is %s and I am %d years old.',

    $this->m_szName,

    $this->m_iAge);

    }

    }

    $peter = new Person();

    $peter->setName('Peter')-> //CC offers no suggestions here.

    Note that the CC does work after $peter->.

    Thanks a lot for the nice work.


  • Petr Tuesday, February 3, 2009

    To Yudi,

    I'm sorry for the late response. Method chaining is supported, but NetBeans has to know the return type of a method / function. Is not clever enough now, to recognize, that a method/function returns an instance of the class. You have to help to the IDE with through a PHP Doc. So your method can look like

    class Person

    {

    /\*\*

    \* @returns Person

    \*/

    public function setName($szName)

    {

    $this->m_szName = $szName;

    return $this;

    }

    }

    It's enough to write /\*\* and press Enter before a method / function declaration and NetBeans will generate a basic stub of the PHP doc for you.

    Regards,

    Petr


  • Yudi Setiawan Tuesday, February 10, 2009

    Cool !

    Thanks a lot for the help.

    Really appreciate it.

    Btw, was wondering is there any progress/news on the problem that Azrael reported?

    I think I kinda experienced the same problem, too.

    Thanks for the nice work.

    Netbeans for PHP rocks ! :-)


  • Nurlan Thursday, May 14, 2009

    Hello everybody!

    Will @var work in methods?

    In current beta release there is no code-completion here:

    class User

    {

    public $id;

    public $name;

    }

    class SomeClass

    {

    function foo()

    {

    /\*\* @var $q User \*/

    $q-> //no code-completion!

    }

    }


  • Nurlan Thursday, May 14, 2009

    Sorry, the code above works perfectly when comment is used this way:

    /\* @var $q User \*/

    not this:

    /\*\* @var $q User \*/


  • alexey_baranov Wednesday, November 18, 2009

    fantastic!


  • alexey_baranov Saturday, April 24, 2010

    Amazing!!


  • gedrox Tuesday, June 15, 2010

    Thank you! Have been searching for this for a while.


  • Phạm Lê Hoài An Thursday, June 24, 2010

    Thank you very much! It's what I need and seek in long time with netbeans!


  • replica handbags UK Tuesday, July 6, 2010

    After a heavy night of drinking at the local bar, a drunk stumbles into a Catholic church and slowly makes his way into the confessional booth. There, the priest patiently awaits the man to begin his confession.


  • replica watches Sunday, August 1, 2010

    Hello everybody!

    Will @var work in methods?

    In current beta release there is no code-completion here:

    class User

    {

    public $id;

    public $name;

    }

    Zenith replica watches,http://www.watcheslux.com/zenith-watches.html

    class SomeClass

    {

    function foo()

    {

    /\*\* @var $q User \*/

    $q-> //no code-completion!

    }

    }


  • replica watches Sunday, August 1, 2010

    /\*\*

    \* @var ADOConnection

    \*/

    static public $db; // code completion runs nicely for INI::$db->

    }

    //...

    /\* @var $query ADORecordSet \*/

    $query = INI::$db->Execute("sql query here");

    $query-> // no code completion here, when ctrl-space on the var - I can see ? where type should be.

    Is this a bug or am I doing something wrong?

    I can't get this feature to work at all (not only the example given), although I can see that the @var is a bit bolder.

    Strange...

    Posted by azrael_valedhel on Ja


  • Galina Thursday, September 9, 2010

    I have this feature, but sometimes it works, sometimes doesn't.

    For example:

    One peace of code:

    $user = User::getInstanceById($id); /\* @var $user User \*/

    $user->//here it works

    But in the file, it doesn't work in the other place.

    $user = User::getInstanceById($id); /\* @var $user User \*/

    $user->//it doesn't work

    But the first place didn't work yesterday too...

    I don't know what it means... what do i do wrong?


  • Petr Pisl Thursday, September 9, 2010

    To Galina: Could you enter a bug in our Bugzilla? ( https://netbeans.org/bugzilla/ ) and attach the file?

    Thanks,

    Petr


  • video surveillance Sunday, December 19, 2010

    Hey... thanks for the info!!! am such a stupid that I couldn't do it on my on..

    thanks !!


  • steve21 Tuesday, January 11, 2011

    Runs like charm :) Because of that kind of features I have almost completely moved from using Eclipse's PDT2 to NetBeans.tks.

    http://www.areshop.com

    http://www.wonshoes.com


  • florida cpa Saturday, January 15, 2011

    Why NetBeans don't locate the variable near the line??


  • mulberry Monday, February 21, 2011

    I needed to get on was arriving in two minutes, what luck!


  • Hermes Friday, March 4, 2011

    We're at the point where we're going to have to start forcing the public to make yes or no


  • Emanuil Wednesday, March 9, 2011

    That's brilliant! NetBeans rocks! Keep up the great work!

    Can't wait for version 7 to be released.


Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.Captcha
Oracle

Integrated Cloud Applications & Platform Services