简体   繁体   English

NetBeans模板提示用户输入变量

[英]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. 我正在大学上编程课程,我的教授要求我用特定格式的JavaDoc注释块包括有关作业的信息。 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. 我想创建一个Java类模板,以便在创建文件时,只需输入特定于作业的信息,然后将其放置在模板中。 Is this possible, or do the variables used in netbeans templates have to be pre-defined? 这可能吗,还是必须预先定义netbeans模板中使用的变量?

"I'm wanting comments that are generated when the user creates a .java file in netbeans." “我想要用户在netbeans中创建.java文件时生成的注释。”

Then your best solution is modifying the templates and defining custom User.properties when needed. 然后,最好的解决方案是修改模板并在需要时定义自定义User.properties。

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. 在NetBeans 7.2(我认为是最新的)中,转到[ 工具 ]-> [ 模板 ],然后在“ 模板管理器”窗口中,可以使用所需的任何语言扩展任何模板并对其进行自定义。

For example, if you expand Java , you can then change the Java Class by highlighting it and selecting [ Open in Editor ]. 例如,如果展开Java ,则可以通过突出显示Java类并选择[ 在编辑器中打开 ]来更改Java类 At that point, you can easily see the normal javadoc comment block at the top. 那时,您可以轻松地在顶部看到普通的javadoc注释块。

/**
 *
 * @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. 这将打开User.properties文件,您可以在其中添加自己的属性。 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). 因此,通过此操作,您可以指定静态标签,只需更改模板即可自动创建静态标签,而无需进行任何工作(例如添加到java类模板的Professor标签)。 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. 对于变量在分配之间可能有所不同的标记,您可以使用自定义用户属性在每次分配开始时进行分配,然后当您使用模板时,模板会将您的分配信息自动填充到自动生成的自定义javadoc标记中打开。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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