Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » PHP Development Tools (PDT) » How to format @return javadoc comments for multitype(I want code hinting when a function returns an array or collection)
How to format @return javadoc comments for multitype [message #1144537] Fri, 18 October 2013 23:42 Go to next message
sneakyimp Mising name is currently offline sneakyimp Mising nameFriend
Messages: 41
Registered: December 2009
Member
I use Eclipse for PHP development and really appreciate the productivity gain. I am a javadoc comment zealot too because the code hinting and autocompletion really speed things up and reduce errors in code.

Can anyone tell me how to write a javadoc comment for @return when my function returns an array of class objects? When I iterate through the array, I want Eclipse to give me code hints for each returned object.

For example, here's one of my class functions in a class called BCDataObject:
	/**
	 * Fetches all data records from the db table.
	 * @param CI_DB_driver $db CodeIgniter JDatabase object to access database
	 * @return multitype:BCDataObject
	 */
	public static function fetch_all($db) {
		$query = $db->get(static::DATABASE_TABLE);
		
		$results = array();
		foreach ($query->result_array() as $record) {
			$results[] = new static($db, $record);
		}
		return $results;
	} // fetch_all()


I know that Eclipse is smart enough to recognize that the function returns a collection of objects because it automatically created this boilerplate javadoc when I first created the javadoc block by typing a slash and two asterisks and hitting return. In fact, this is the doc block auto-created by eclipse:
/**
 * 
 * @param unknown_type $db
 * @return multitype:BCDataObject
 */


The problem I have is that when I go to a place where I am using this code, I can use my function to get the array of objects but when I do a foreach loop on the result, Eclipse doesn't seem to know the type of the objects I am iterating so I don't get autocomplete or code hinting. For example, in this block of code:
$v = BCDataObject::fetch_all($this->db);
foreach($v as $user) {
  echo $user . "<br>";
}

Eclipse doesn't give me code hints or autocomplete for the var $user -- for some reason it fails to recognize that each element of $v will be of type BCDataObject.

Can anyone tell me how to create my javadoc so I get this type of code hinting? Is it possible?
Re: How to format @return javadoc comments for multitype [message #1144614 is a reply to message #1144537] Sat, 19 October 2013 00:56 Go to previous messageGo to next message
Valery Cheban is currently offline Valery ChebanFriend
Messages: 17
Registered: January 2013
Junior Member
Hello!
It's very simple, use:

@return BCDataObject[]


OR

$v = BCDataObject::fetch_all($this->db);
foreach($v as $user) {
  /* @var $user BCDataObject */
  echo $user . "<br>";
}

[Updated on: Sat, 19 October 2013 00:56]

Report message to a moderator

Re: How to format @return javadoc comments for multitype [message #1144620 is a reply to message #1144537] Sat, 19 October 2013 01:03 Go to previous messageGo to next message
Toshihiro Izumi is currently offline Toshihiro IzumiFriend
Messages: 360
Registered: July 2009
Location: Japan
Senior Member
Which version of PDT are you using?
Content assist for that "$user" works in PDT 3.1.2 or later. It doesn't work in PDT 3.1.1 or former versions.
Re: How to format @return javadoc comments for multitype [message #1145838 is a reply to message #1144620] Sat, 19 October 2013 20:40 Go to previous messageGo to next message
sneakyimp Mising name is currently offline sneakyimp Mising nameFriend
Messages: 41
Registered: December 2009
Member
Thank you for the tip regarding version, Toshihiro, My version of PDT is 3.0.2 so I should probably upgrade.

Valery, my routine does not return a single BCDataObject, it returns an array of them. I appreciate the tip on adding the @var comment, but that looks like extra work.

icon4.gif  Re: How to format @return javadoc comments for multitype [message #1146886 is a reply to message #1145838] Sun, 20 October 2013 13:32 Go to previous messageGo to next message
Valery Cheban is currently offline Valery ChebanFriend
Messages: 17
Registered: January 2013
Junior Member
>>my routine does not return a single BCDataObject

I see that, attention on "[]":

@return BCDataObject[]

And update your PDT. The last stable PDT is 3.2
icon6.gif  Re: How to format @return javadoc comments for multitype [message #1146897 is a reply to message #1146886] Sun, 20 October 2013 13:41 Go to previous message
Valery Cheban is currently offline Valery ChebanFriend
Messages: 17
Registered: January 2013
Junior Member
In my daily practic i use this:

@return SplFileInfo[] | array[SplFileInfo]


see attach.
Previous Topic:xml formatting
Next Topic:Syntax Highlighting - Deprecated
Goto Forum:
  


Current Time: Tue Mar 19 09:20:53 GMT 2024

Powered by FUDForum. Page generated in 0.02694 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top