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.

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

(0)

相关推荐

  • 使用IDEA配置Maven搭建开发框架ssm教程

    一.配置Maven环境 1.下载Maven 下载链接http://maven.apache.org/download.cgi 2.下载完成解压压缩包并创建本地仓库文件夹 3.打开解压缩文件,配置本地仓库路径 4.配置Maven环境变量 5.在cmd中查看maven是否配置正确 在cmd中输入mvn -v命令查看 二.在IntelliJ IDEA中配置Maven 打开-File-Settings 三.新建maven JAVAWEB项目 1.打开-File-New-Project Next Next

  • Intellij IDEA 配置Subversion插件实现步骤详解

    Intellij IDEA 配置Subversion插件实现步骤详解 在使用Intellij的过程中,突然发现svn不起效了,在VCS–>Checkout from Version Control中也未发现Subversion这一项.如下图: 一.原因查找 经过分析是因为插件被禁用或移除导致此功能失效. 二.解决方案 打开Settings,Plugins,搜索Subversion,在筛选出结果的方框上打勾,即可启动插件.如下图: 三.使用方法 点击VCS–>Enable Version -.-

  • 在idea环境下构建springCloud项目

    springCloud是基于springboot搭建的微服务.它利用Spring Boot的开发便利性巧妙地简化了分布式系统基础设施的开发,如服务发现注册.配置中心.消息总线.负载均衡.断路器.数据监控等,都可以用Spring Boot的开发风格做到一键启动和部署. spring cloud官方文档:http://projects.spring.io/spring-cloud/ spring cloud 中文网 : https://springcloud.cc/ 最终搭建后的工程源代码:http

  • Idea 无法引用类问题解决办法

    今天遇到一个最别坑的问题,就是我引入了一个lombok.jar包.这个Jar包中的其它类我都可以通过Alt+Enter来快速导入包,但是就其中一个@Data这个注解就是不行.我以为是版本问题,我就在build.gradle里面去改变这个Jar包的版本.结果还是不行.最后之前用Idea的同事也遇到过这个问题,过来帮我解决了这个问题.现在记录下来,希望也能够帮助遇到这样问题的朋友. 同一个包下的@ToString注解能够快捷导入,但是@Data就是不行. 可以通过以下方式来解决这个问题: 1. Se

  • 在Intellij IDEA中使用Debug(图文教程)

    Debug用来追踪代码的运行流程,通常在程序运行过程中出现异常,启用Debug模式可以分析定位异常发生的位置,以及在运行过程中参数的变化.通常我们也可以启用Debug模式来跟踪代码的运行流程去学习三方框架的源码. 所以学习下如何在Intellij IDEA中使用好Debug,主要包括如下内容: 一.Debug开篇 二.基本用法&快捷键 三.变量查看 四.计算表达式 五.智能步入 六.断点条件设置 七.多线程调试 八.回退断点 九.中断Debug 十.附:JRebel激活 一.Debug开篇 首先

  • IDEA-Maven环境配置及使用教程

    一.Maven的下载 IDEA的往期下载地址:https://www.jetbrains.com/ 1.点击进入 1.往期的下载地址:http://www.apache.org/ 操作步骤:我们点击进入Projects---->如图 (1) . (2). (3). (4). (5).解压后我们可以看到这个目录 (6).解压文件后,我们要新增两个环境变量 1.M2_HOME------------------>D:\javafile\apache-maven-3.5.0 2.PATH:-----

  • IntelliJ IDEA(2017)安装和破解的方法

    IntelliJ IDEA是来自捷克的Jetbrains公司开发的Java开发工具(完爆Eclipse/MyEclipse).有旗舰版和社区版两大版本,相对社区版而言旗舰版的功能更加丰富.官网提供了两个版本之间差异的详细比较.擅长企业级应用.移动应用以及Web应用开发. 支持MacOS,Windows7+,Linux(Ubuntu14)三大主流操系统,支持主流技术(Maven,Git,Tomcat-)和框架(Spring,SpringBoot,SpringCloud-),同时支持Scala,Gr

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

    本文介绍了IDEA添加Java类注释模版的方法,分享给大家,具体如下: IDEA版本:IntelliJ IDEA 2017.2.5 x64 eclipse能在类上方输入/**,回车添加类注释模版,但idea没有默认添加这个功能,需要做一些设置.下面介绍三种方法实现: 创建类默认添加类注释 手动添加类注释 批量添加JavaDoc注释 一.设置新建类默认添加注释 依次点击Setting|Editor|File and code templates,添加如图配置 例子: /** *describe:

  • 在JavaScript中调用Java类和接口的方法

    前言 本文中所有的代码使用 JavaScript 编写,但你也可以用其他兼容 JSR 223 的脚本语言.这些例子可作为脚本文件也可以在交互式 Shell 中一次运行一个语句的方式来运行.在 JavaScript 中访问对象的属性和方法的语法与 Java 语言相同. 本文包含如下几部分: 1.访问 Java 类 为了在 JavaScript 中访问原生类型或者引用 Java 类型,可以调用 Java.type() 函数,该函数根据传入的完整类名返回对应对象的类型.下面代码显示如何获取不同的对象类

  • 在DWR中实现直接获取一个JAVA类的返回值的两种方法

    第一种实现(来源网上转贴): js 代码 function Test() { var _data = ""; this.getString = function() { //设置成同步 DWREngine.setAsync(false); //调用Java类Test的getString方法,callBackFun为回调函数 JTest.getString(function(data){_data = data;} //重新设置为异步方式 DWREngine.setAsync(true)

  • IDEA代码规范插件P3C+代码注释模板配置方法

    IDEA配置阿里规范插件P3C 进入idea ->File -> Settings ->Plugins 到搜索框中搜索:Alibaba Java Coding Guidelines 下载安装插件,安装之后重启IDEA ,进入你的编辑器右击会发现多 了,检查规范和关闭检查. 检查会发现你这个java文件是否存在问题并给出提示如: 也常常遇到类是 class 或者方法上面缺少 javadoc注解 如: 所有的类都必须添加创建者信息 所有的抽象方法(包括接口中的方法)必须要用javadoc注释

  • 详解Java类动态加载和热替换

    前言 最近,遇到了两个和Java类的加载和卸载相关的问题: 1) 是一道关于Java的判断题:一个类被首次加载后,会长期留驻JVM,直到JVM退出.这个说法,是不是正确的? 2) 在开发的一个集成平台中,需要集成类似接口的多种工具,并且工具可能会有新增,同时在不同的环境部署会有裁剪(例如对外提供服务的应用,不能提供特定的采购的工具),如何才能更好地实现? 针对上面的第2点,我们采用Java插件化开发实现.上面的两个问题,都和Java的类加载和热替换机制有关. 1. Java的类加载器和双亲委派模

  • PHP与Java进行通信的实现方法

    缘起: 最近做了一个电商平台与网银整合的小东西,程序是开源的 Ecmall的,网银的接口也很规范,给出的文档很全,唯一的小问题是,网银使用的签名和验签的lib是只有java和c的,对java还熟悉一些,所以选择了使用java作为签名和验签的接口. 方法: 网上关于php与java交互的资料其实挺多的.总体来说其实也是这么几种方法: •PHP直接通过exec或者system之类的命令调用命令行,然后以java Hello 这种类型得方式来运行java程序,但是缺点是很明显的,不能很好地与java类

  • C#实现为类和函数代码自动添加版权注释信息的方法

    本文实例讲述了C#实现为类和函数代码自动添加版权注释信息的方法,分享给大家供大家参考之用.具体方法如下: 以web项目为例: 一:给类加注释 1.在visual studio 的安装路径下 如:[盘符]:/Program files/Microsoft Visual Studio 8/Common7/IDE/ItemTemplates/web/cshare/2052/class.zip ,将里面的class.cs改为: /*------------------------------------

  • Java经验点滴:类注释文档编写方法

    文章来源:csdn 作者:chensheng913 对于Java语言,最体贴的一项设计就是它并没有打算让人们为了写程序而写程序--人们也需要考虑程序的文档化问题.对于程序的文档化,最大的问题莫过于对文档的维护.若文档与代码分离,那么每次改变代码后都要改变文档,这无疑会变成相当麻烦的一件事情. 解决的方法看起来似乎很简单:将代码同文档"链接"起来.为达到这个目的,最简单的方法是将所有内容都置于同一个文件.然而,为使一切都整齐划一,还必须使用一种特殊的注释语法,以便标记出特殊的文档:另外还

  • idea 自动生成类注释和方法注释的实现步骤

    换电脑重新安装了idea,记录下添加自动注释的方法,以备后续使用 idea版本:2018.3.1 1. 生成类注释 打开setting -> Editor -> File and Code Templates -> Files -> Class 生成类注解模板 /** * @program: ${PROJECT_NAME} * @description: ${description} * @author ${USER} * @date ${YEAR}-${MONTH}-${DAY}

  • 基于IntelliJ IDEA的类注释和方法注释操作

    效果图如下: 类注释: 方法注释: idea不会默认帮我们设置,所以需要手动设置. 1:IDEA中在创建类时会自动给添加注释 打开idea,操作 File–>settings–>Editor–>File and Code Templates–>Files (1)NAME:设置类名,与下面的NAME:设置类名,与下面的{NAME}一样才能获取到创建的类名 (2)TODO:代办事项的标记,一般生成类或方法都需要添加描述 (3)USER.USER.{DATE}.TIME:设置创建类的用户

随机推荐