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.


Comments:

A seriously nice feature - great work!

Posted by Demian Turner on January 08, 2009 at 03: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 04:16 AM CET #

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

Posted by Sam on January 08, 2009 at 04:21 AM 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 05:32 AM 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 07:03 AM 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 12: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 12, 2009 at 05:40 PM 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 07:12 AM 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 03: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 02: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 03: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 04:28 AM 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 23, 2009 at 10:44 PM 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 01: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 12: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 03, 2009 at 04:11 PM 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 10, 2009 at 08:43 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 07:27 AM 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 07:51 AM CEST #

fantastic!

Posted by alexey_baranov on November 18, 2009 at 05:18 AM CET #

Amazing!!

Posted by alexey_baranov on April 24, 2010 at 01:02 PM CEST #

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

Posted by gedrox on June 15, 2010 at 08:59 AM CEST #

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

Posted by Phạm Lê Hoài An on June 24, 2010 at 11:37 AM CEST #

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.

Posted by replica handbags UK on July 06, 2010 at 08:33 PM CEST #

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

Posted by replica watches on August 02, 2010 at 01:53 AM CEST #

/\*\*
\* @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

Posted by replica watches on August 02, 2010 at 01:54 AM CEST #

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?

Posted by Galina on September 09, 2010 at 06:42 AM CEST #

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

Thanks,
Petr

Posted by Petr Pisl on September 09, 2010 at 09:47 AM CEST #

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

Posted by video surveillance on December 19, 2010 at 02:31 PM CET #

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

Posted by steve21 on January 11, 2011 at 08:27 PM CET #

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

Posted by florida cpa on January 15, 2011 at 01:14 PM CET #

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

Posted by mulberry on February 22, 2011 at 12:40 AM CET #

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

Posted by Hermes on March 04, 2011 at 02:31 AM CET #

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

Can't wait for version 7 to be released.

Posted by Emanuil on March 09, 2011 at 02:57 AM CET #

Post a Comment:
  • HTML Syntax: NOT allowed
About

This blogs is written by NetBeans developers who contribute to the PHP support mainly.

Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today