开发者

How do I customize NetBeans PHP auto DocBlock for methods and attributes?

After I create a method I use /**<enter> to generate the DocBlock. It auto fills the @param and @return for that function. Example:

/**
 *
 * @param type $str
 * @return type 
 */
public function strlen($s开发者_开发百科tr){
    return strlen($str);
}

How can I customize the block being generated so that it also fills in the @author and end up with this after /**<enter>

/**
 *
 * @param type $str
 * @return type 
 * @author John Doe <john@doe.com>
 */
public function strlen($str){
    return strlen($str);
}

Thanks


There may be a better way to do this, but here's what I've used: under Tools > Options > Editor > Code Templates, there are some predefined combos for generating code quickly. One of the default templates in 7.0 is:

vdoc<tab>

This generates a pseudo-docblock and the variable definition. You can replace this and add new ones that expand into whatever text you want, much like vim abbreviations. You can find more on this on the Netbeans documentation site:

http://netbeans.org/kb/docs/php/code-templates.html#using-templates


I believe the answer you're looking for will be found here: phpDocumentor Tutorial

I think you'll want to look at the --customtags Command-line switch.

So most likely, when you go to Tools -> Options -> "PHP" -> "PHPDoc", you can add that --customtags command-line switch into the PHPDoc script line.

I haven't attempted this personally, but I have been playing around with the idea of using NetBeans in combination with DocBlocks and PHPDocumentor to "automagically" create a good amount of usable documentation without being too strenuous on the rest of the coders. ;-)

There's a nice video tutorial about setting up NetBeans to work with PHPDocumentor available here: Generating PHP Documentation With NetBeans IDE 7.0


To enable proper @author tag autocompletion, just go to: Tools->Templates->PHP->PHP Class, press the "Settings" button and uncomment the line starting with #user=. Now you're able to edit the name and email, which are passed to your Class comment.


Short Answer from various sources: No you can't edit a template that could add it for you.

  1. If you are still looking for a feature alike, you can create a Macro do to it and then bind it to a shortcut ("Alt + W" for instance).

To create a Macro : Tools -> Options -> Editor -> Macros

Example :

Alt+W => insert-break "/**" insert-break

This Macro helps add PHPDoc with the left hand which makes it faster. You can generate whatever you wish to generate like using this Macro, and then placing the cursor at the right place and then adding the @author YOUR_NAME at the end of the comment.


  1. You can also set the general Author of your project by going to : Tools -> Templates; Click "Settings"

Add the line :

user=YOUR NAME <email.prefix at domain.extension>

This will add the @author to all your new class/interface definitions.

I hope this will help you!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜