Complete autocomplete in NetBeans – vdoc in action

Complete autocomplete in NetBeans – vdoc in action

Sometimes it takes some time to find a file containing a class having some method. For example, when you work with some older framework, where files are included in many different places and you see such a construction:

class SomeController extends Controller
{

	public function someAction ()
	{
		$user = factory::get('user');
		$id = $user->getId();
		...
	}

}

How to find out, where’s this coming from, what class is the $user object and what else methods does it have? In newer code sources we would find a class property like

class SomeController extends Controller
{
	/**
	*
	* Namespace\User;
	*/
	private $user;

	...

}

vdoc in action

For older code we can easily achieve it using IDE like NetBeans for instance. When we create a new project, all the source is scanned first and indexed. If we don’t know the type of the object, we can always click right mouse button on the method getId() and from the popup menu choose “Find usage”. NetBeans will find all the places that use this method and also the main object, where the method is implemented. When we finally know the base class of object $user, we can take care of using it in the future by defining object class in the comment. To do it:

1. Put your cursor right before of after a variable
2. Start typing “vdoc”
3. Hit ENTER when NetBeans starts autocompleting
4. With the TAB key chose variable or type
5. While statnding on the type field hit CTRL+SPACE to choose from available types list

After this operation you’ll get similar code:

/* @var $user UserModel */
$user = factory::get('user');
$id = $user->getId();

The /* var */ part gives your IDE the knowledge of the variable whereabouts. From now on using the variable $user-> NetBeans will show us all the public methods and properties of the class and CTRL+LMB will take us to declaration of the class or method.

https://blogs.oracle.com/netbeansphp/entry/defining_a_variable_type_in

Leave a comment

Your email address will not be published. Required fields are marked *