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 IO流常用字节字符流原理解析

    Java IO流常用字节字符流原理解析

    这篇文章主要介绍了Java IO流常用字节字符流原理解析,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下
    2020-03-03
  • spring-data-redis自定义实现看门狗机制

    spring-data-redis自定义实现看门狗机制

    redission看门狗机制是解决分布式锁的续约问题,本文主要介绍了spring-data-redis自定义实现看门狗机制,具有一定的参考价值,感兴趣的可以了解一下
    2024-03-03
  • spring boot+mybatis搭建一个后端restfull服务的实例详解

    spring boot+mybatis搭建一个后端restfull服务的实例详解

    这篇文章主要介绍了spring boot+mybatis搭建一个后端restfull服务,本文通过实例代码给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下
    2020-11-11
  • springboot自定义校验注解的实现过程

    springboot自定义校验注解的实现过程

    这篇文章主要介绍了springboot自定义校验注解的实现过程,本文结合示例代码给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友参考下吧
    2023-11-11
  • java编程SpringSecurity入门原理及应用简介

    java编程SpringSecurity入门原理及应用简介

    Spring 是非常流行和成功的 Java 应用开发框架,Spring Security 正是 Spring 家族中的成员。Spring Security 基于 Spring 框架,提供了一套 Web 应用安全性的完整解决方案
    2021-09-09
  • Java实现将Object转换成指定Class对象的操作代码

    Java实现将Object转换成指定Class对象的操作代码

    这篇文章主要介绍了Java实现将Object转换成指定Class对象的操作,在Java中,将Object转换为指定类型的Class对象实际上是两个不同概念的操作,由于你提到的“将Object转换成指定Class对象”可能有些混淆,我将分别展示这两种操作的示例代码,需要的朋友可以参考下
    2024-09-09
  • 浅谈Java编程之if-else的优化技巧总结

    浅谈Java编程之if-else的优化技巧总结

    说实话,其实我很讨厌在代码里大量使用if-else,一是因为该类代码执行方式属于面向过程的,二嘛,则是会显得代码过于冗余.这篇笔记,主要记录一些自己在工作实践当中针对if-else的优化心得,将会不定期地长期更新,需要的朋友可以参考下
    2021-06-06
  • java中TCP/UDP详细总结

    java中TCP/UDP详细总结

    本篇文章对Java中的TCP/UDP知识点进行了归纳总结分析。需要的朋友参考下
    2017-04-04
  • 关于Java中的IO流总结(推荐)

    关于Java中的IO流总结(推荐)

    下面小编就为大家带来一篇关于Java中的IO流总结(推荐)。小编觉得挺不错的,现在就分享给大家,也给大家做个参考。一起跟随小编过来看看吧
    2017-05-05
  • Java实现窗体程序显示日历表

    Java实现窗体程序显示日历表

    这篇文章主要为大家详细介绍了Java实现窗体程序显示日历表,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
    2022-06-06

最新评论