Defining a variable type in comment II

Posted by Petr Pisl on Jan 08 2009, 09:22:18 AM CET

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.


Category: Features | Permalink | Comments [25]

Trackback URL: http://blogs.sun.com/netbeansphp/entry/defining_a_variable_type_in
Comments:

A seriously nice feature - great work!

Posted by Demian Turner on January 08, 2009 at 11:45 AM CET #

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

Posted by Łukasz Muchlado on January 08, 2009 at 12:16 PM CET #

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

Posted by Sam on January 08, 2009 at 12:21 PM CET #

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?

Posted by Toby Mathews on January 08, 2009 at 01:32 PM CET #

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

Posted by Petr on January 08, 2009 at 03:03 PM CET #

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

Posted by Dietmar on January 12, 2009 at 08:21 AM CET #

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.

Posted by Petr on January 13, 2009 at 01:40 AM CET #

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!

Posted by Symen Timmermans on January 16, 2009 at 03:12 PM CET #

To Symen:

Not sure if it is what you are looking for:
http://blogs.sun.com/netbeansphp/entry/screencat_about_class_property_variables

Posted by radek on January 19, 2009 at 11:34 AM CET #

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.

Posted by Petr on January 19, 2009 at 10:03 PM CET #

Thanks Radek and Petr!

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

Posted by Symen Timmermans on January 20, 2009 at 11:55 AM CET #

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

Posted by Toby Mathews on January 20, 2009 at 12:28 PM CET #

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...

Posted by azrael_valedhel on January 24, 2009 at 06:44 AM CET #

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

Posted by Petr on January 25, 2009 at 09:40 PM CET #

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.

Posted by Yudi Setiawan on January 27, 2009 at 08:46 AM CET #

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

Posted by Petr on February 04, 2009 at 12:11 AM CET #

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 ! :-)

Posted by Yudi Setiawan on February 11, 2009 at 04:43 AM CET #

look many scripts
http://s4.gladiatus.us/game/c.php?uid=138745

Posted by 212.200.212.230 on February 16, 2009 at 01:31 PM CET #

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!
}
}

Posted by Nurlan on May 14, 2009 at 02:27 PM CEST #

Sorry, the code above works perfectly when comment is used this way:
/* @var $q User */
not this:
/** @var $q User */

Posted by Nurlan on May 14, 2009 at 02:51 PM CEST #

The Solaris 10 03/05 Certified software consists of the Solaris 10 03/05 Operating Environment and a subset of Solaris 10 patches which have been reviewed to ensure that their application introduces no new security vulnerabilities.
http://www.watchrolexshop.com
http://www.gamegoldme.com
http://www.cheap-lotrogold.com
http://www.globalsale.me/Aion-gold-083.aspx
http://www.cheap-gamegold.org
http://www.gamegoldvip.org

Posted by replica rolex on June 25, 2009 at 07:47 AM CEST #

Хорошая статья, больше бы таких!

Posted by Инокентий on June 25, 2009 at 02:09 PM CEST #

Thanks.

Posted by porno izle on June 29, 2009 at 12:22 AM CEST #

üretimimiz ve kapasitemiz.

Posted by kabin on July 01, 2009 at 10:02 AM CEST #

iyi üreetim.

Posted by kabin on July 01, 2009 at 10:03 AM CEST #

Post a Comment:

Name:
E-Mail:
URL:

Your Comment:

HTML Syntax: NOT allowed