简体   繁体   中英

NetBeans template prompts user for variables

I am taking a programming class in college where my professor requires me to include information on the assignment withing a JavaDoc comment block in a specific format. I'm wanting to create a java class template so that when I create my file, I just type in the assignment specific information, and it places it in the template. Is this possible, or do the variables used in netbeans templates have to be pre-defined?

"I'm wanting comments that are generated when the user creates a .java file in netbeans."

Then your best solution is modifying the templates and defining custom User.properties when needed.

In NetBeans 7.2 (latest I think), go to [ Tools ] -> [ Templates ], and in the Template Manager window you can expand whatever template for whatever language you like and customize it.

For example, if you expand Java , you can then change the Java Class by highlighting it and selecting [ Open in Editor ]. At that point, you can easily see the normal javadoc comment block at the top.

/**
 *
 * @author ${user}
 * @professor Mr. LordZardeck's Professor
 */
public class ${name} {

}

If you want to add custom properties, like the above uses the user property, in the Template Manager window, select [ Settings ]. That will open the User.properties file where you can add properties of your own. If you look at the bottom of the file, the last line is commented out, but it is an example of a custom property, uncommented it is:

user=Your Name <your.name at your.org>

So, with this you can specify static tags that can be auto-created without any work by simply changing the templates (like the professor tag added to the java class template). For a tag whose variable might change from assignment to assignment, you can use the custom user properties to assign those at the start of each assignment, then the templates will auto-fill your assignment information into the auto-generated custom javadoc tags when your template is opened.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM