IDEA添加Java类注释模版的方法

 更新时间:2017年12月08日 13:43:35   作者:shengpli  
本篇文章主要介绍了IDEA添加Java类注释模版的方法,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧

本文介绍了IDEA添加Java类注释模版的方法,分享给大家,具体如下:

IDEA版本:IntelliJ IDEA 2017.2.5 x64

eclipse能在类上方输入/**,回车添加类注释模版,但idea没有默认添加这个功能,需要做一些设置。下面介绍三种方法实现:

  1. 创建类默认添加类注释
  2. 手动添加类注释
  3. 批量添加JavaDoc注释

一、设置新建类默认添加注释

依次点击Setting|Editor|File and code templates,添加如图配置

例子:

/**
*describe: 
*
*@author xxx
*@date ${YEAR}/${MONTH}/${DAY}
*/

支持的变量在描述内,找到需要配置即可!

二、利用Live Template手动添加注释模版

依次点击Setting|Editor|Live templates

1、点击+添加templates group,如My Live Templates

2、点击+添加live templates,修改abbreviation,再添加模版内容,模版变量以$var$格式定义,如

/**
*describe: 
*
*@author xxx
*@date $date$
*/

 

3. 点击define定义模版作用范围,选择Java

 

4. 点击Edit variables定义变量,表达式解释见附件

 

5. 保存后,在类任意位置输入cc即可添加模版

三、批量添加注释

安装JavaDoc插件,alt+insert即可批量添加注释,包括所有类和方法,但是不能定制化,注释都是固定的。

附件

Item
Description
annotated("annotation qname")
Creates a symbol of type with an annotation that resides at the specified location. For an example, see Live Templates in the iterations group.
arrayVariable()
Suggests all array variables applicable in the current scope. For an example, see Live Templates in the iterations group.
anonymousSuper()
Suggests a supertype for a Kotlin object expression.
camelCase(String)
Returns the string passed as a parameter, converted to camel case. For example, my-text-file/my text file/my_text_file will be converted to myTextFile.
capitalize(String)
Capitalizes the first letter of the name passed as a parameter.
capitalizeAndUnderscore(sCamelCaseName)
Capitalizes the all letters of a CamelCase name passed as a parameter, and inserts an underscore between the parts. For example, if the string passed as a parameter is FooBar, then the function returns FOO_BAR.
castToLeftSideType()
Casts the right-side expression to the left-side expression type. It is used in the iterations group to have a single template for generating both raw-type and Generics Collections.
className(sClassName)
Returns the name of the current class (the class where the template is expanded).
classNameComplete()
This expression substitutes for the class name completion at the variable position.
clipboard()
Returns the contents of the system clipboard.
snakeCase(String)
Returns CamelCase string out of snake_case string. For example, if the string passed as a parameter is foo_bar, then the function returns fooBar.
complete()
This expression substitutes for the code completion invocation at the variable position.
completeSmart()
This expression substitutes for the smart type completion invocation at the variable position.
componentTypeOf (<array variable or array type>)
Returns component type of an array. For example, see the Live Templates in the iterations group in the other group.
currentPackage()
Returns the current package name.
date(sDate)
Returns the current system date in the specified format.
By default, the current date is returned in the default system format. However, if you specify date format in double quotes, the date will be presented in this format:

decapitalize(sName)
Replaces the first letter of the name passed as a parameter with the corresponding lowercase letter.
descendantClassEnum(<String>)
Shows the children of the class entered as a string parameter.
enum(sCompletionString1,sCompletionString2,...)
List of comma-delimited strings suggested for completion at the template invocation.
escapeString(sEscapeString)
Escapes the specified string.
expectedType()
Returns the type which is expected as a result of the whole template. Makes sense if the template is expanded in the right part of an assignment, after return, etc.
fileName(sFileName)
Returns file name with extension.
fileNameWithoutExtension()
Returns file name without extension.
firstWord(sFirstWord)
Returns the first word of the string passed as a parameter.
groovyScript("groovy code")
Returns Groovy script with the specified code.
You can use groovyScript macro with multiple arguments. The first argument is a script text that is executed or a path to the file that contains a script. The next arguments are bound to _1, _2, _3, ..._nvariables that are available inside your script. 
Also, _editor variable is available inside the script. This variable is bound to the current editor.
guessElementType (<container>)
Makes a guess on the type of elements stored in a java.util.Collection. To make a guess, IntelliJ IDEA tries to find the places where the elements were added to or extracted from the container.
iterableComponentType(<ArrayOrIterable>)
Returns the type of an iterable component, such as an array or a collection.
iterableVariable()
Returns the name of a variable that can be iterated.
lineNumber()
Returns the current line number.
lowercaseAndDash(String)
Returns lower case separated by dashes, of the string passed as a parameter. For example, the string MyExampleName is converted to my-example-name.
methodName()
Returns the name of the embracing method (where the template is expanded).
methodParameters()
Returns the list of parameters of the embracing method (where the template is expanded).
methodReturnType()
Returns the type of the value returned by the current method (the method within which the template is expanded).
qualifiedClassName()
Returns the fully qualified name of the current class (the class where the template is expanded).
Clear the Shorten FQ names check box.
rightSideType()
Declares the left-side variable with a type of the right-side expression. It is used in theiterations group to have a single template for generating both raw-type and Generics Collections.
snakeCase(sCamelCaseText)
Returns snake_case string out of CamelCase string passed as a parameter.
spaceSeparated(String)
Returns string separated with spaces out of CamelCase string passed as a parameter. For example, if the string passed as a parameter is fooBar, then the function returns foo bar.
subtypes(sType)
Returns the subtypes of the type passed as a parameter.
suggestIndexName()
Suggests the name of an index variable. Returns i if there is no such variable in scope, otherwise returns j if there is no such variable in scope, etc.
suggestVariableName()
Suggests the name for a variable based on the variable type and its initializer expression, according to your code style settings that refer to the variable naming rules.
For example, if it is a variable that holds an element within iteration, IntelliJ IDEA makes a guess on the most reasonable names, also taking into account the name of the container being iterated.
suggestFirstVariableName(sFirstVariableName)
Doesn't suggest true, false, this, super.
time(sSystemTime)
Returns the current system time.
typeOfVariable(VAR)
Returns the type of the variable passed as a parameter.
underscoresToCamelCase(sCamelCaseText)
Returns the string passed as a parameter with CamelHump letters substituting for underscores. For example, if the string passed as a parameter is foo_bar, then the function returns fooBar.
underscoresToSpaces(sParameterWithSpaces)
Returns the string passed as a parameter with spaces substituting for underscores.
user()
Returns the name of the current user.
variableOfType(<type>)
Suggests all variables that may be assigned to the type passed as a parameter, for example variableOfType("java.util.Vector"). If you pass an empty string ("") as a parameter, suggests all variables regardless of their types.
JsArrayVariable
Returns JavaScript array name.
jsClassName()
Returns the name of the current JavaScript class.
jsComponentType
Returns the JavaScript component type.
jsMethodName()
Returns the name of the current JavaScript method.
jsQualifiedClassName
Returns the complete name of the current JavaScript class.
jsSuggestIndexName
Returns a suggested name for an index.
jsSuggestVariableName
Returns a suggested name for a variable.

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本之家。

相关文章

  • Java设计模式中的门面模式详解

    Java设计模式中的门面模式详解

    门面模式又叫外观模式(Facade Pattern),主要用于隐藏系统的复杂性,并向客户端提供了一个客户端可以访问系统的接口,本文通过实例代码给大家介绍下java门面模式的相关知识,感兴趣的朋友一起看看吧
    2022-09-09
  • Mybatis Plus 代码生成器的实现

    Mybatis Plus 代码生成器的实现

    这篇文章主要介绍了Mybatis Plus 代码生成器的实现,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
    2020-03-03
  • 简单说说JVM堆区的相关知识

    简单说说JVM堆区的相关知识

    今天给大家带来的是关于Java虚拟机的相关知识,文章围绕着JVM堆区展开,文中有非常详细的介绍及代码示例,需要的朋友可以参考下
    2021-06-06
  • Java中HashMap和HashTable区别

    Java中HashMap和HashTable区别

    HashMap和Hashtable都是Java常见的基于哈希表实现的Map接口的实现类,本文主要介绍了Java中HashMap和HashTable区别,具有一定的参考价值,感兴趣的可以了解一下
    2023-11-11
  • SpringBoot如何监听redis Key变化事件案例详解

    SpringBoot如何监听redis Key变化事件案例详解

    项目中需要监听redis的一些事件比如键删除,修改,过期等,下面这篇文章主要给大家介绍了关于SpringBoot如何监听redis Key变化事件的相关资料,文中通过实例代码介绍的非常详细,需要的朋友可以参考下
    2022-08-08
  • 详解Java 自动装箱与自动拆箱

    详解Java 自动装箱与自动拆箱

    这篇文章主要介绍了Java 自动装箱与自动拆箱的相关资料,帮助大家更好的理解和学习Java,感兴趣的朋友可以了解下
    2020-09-09
  • 基于@ComponentScan注解及其XML配置方式

    基于@ComponentScan注解及其XML配置方式

    这篇文章主要介绍了基于@ComponentScan注解及其XML配置方式,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教
    2023-09-09
  • 解决一个JSON反序列化问题的办法(空字符串变为空集合)

    解决一个JSON反序列化问题的办法(空字符串变为空集合)

    在平时的业务开发中,经常会有拿到一串序列化后的字符串要来反序列化,下面这篇文章主要给大家介绍了如何解决一个JSON反序列化问题的相关资料,空字符串变为空集合,需要的朋友可以参考下
    2024-03-03
  • C#中NAudio音频库的安装与使用教程详解

    C#中NAudio音频库的安装与使用教程详解

    NAudio为.NET平台下的开源库,采用ML-PL协议,它支持许多音频操作,可实现多种API播放与录制、多种不同音频格式等功能,下面就跟随小编一起学习一下NAudio的安装与使用吧
    2023-11-11
  • java学生信息管理系统设计

    java学生信息管理系统设计

    这篇文章主要为大家详细介绍了java学生信息管理系统设计,学生信息添加进入数据库的事务,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
    2016-11-11

最新评论