Intellij-安装CodeGenerator插件并且添加Builder模板

Intellij IDEA 2018.1.2版本

CodeGenerator插件地址:https://github.com/lotabout/CodeGenerator/releases

步骤一:安装插件

  下载CodeGenerator.jar到本地磁盘,打开Intellij安装插件的界面进行安装

  

步骤二:添加Builder模式的模板

  

## Tutorial for writing your templates
##
## 1. First you need to know basic syntax of velocity[1].
## 2. Then it is necessary to understand the variable that CodeGenerator provides
##    and its inner structure for retrieving the information you need for generating code.
## 3. Learn to use the utils provided so that you can ask for further information
##    or reduce your workload.
##
## Variables Provided (Class Mode)
## -------------------------------
## Class mode means you want to create new classes(file).
##
## - ClassName: String     The name spcified by `Target Class Name`
## - PackageName: String   The package name specified by `Target Class Name`
## - class0: ClassEntry    The class that the action is triggered upon
##   - raw: PsiClass
##   - String packageName
##   - importList: List<String>
##   - fields: List<FieldEntry>
##   - allFields: List<FieldEntry>
##   - methods: List<MethodEntry>
##   - allMethods: List<MethodEntry>
##   - innerClasses: List<ClassEntry>
##   - allInnerClasses: List<ClassEntry>
##   - typeParamList:  List<String>
##   - name: String
##   - superName: String
##   - superQualifiedName: String
##   - qualifiedName: String
##   - typeParams: int
##   - hasSuper: boolean
##   - deprecated: boolean
##   - enum: boolean
##   - exception: boolean
##   - abstract: boolean
##   - implementNames: String[]
##   - isImplements(String): bool
##   - isExtends(String): bool
##   - matchName(String): bool
##
## - class1: ClassEntry    The first selected class, where `1` is the postfix
##                         you specify in pipeline
##   ...
##
## - MemberEntry (FieldEntry/MethodEntry common properties)
##    - raw: PsiField(for field), PsiMethod(for method)
##    - name: String
##    - accessor: String
##    - array: boolean
##    - nestedArray: boolean
##    - collection: boolean
##    - map: boolean
##    - primitive: boolean
##    - string: boolean
##    - primitiveArray: boolean
##    - objectArray: boolean
##    - numeric: boolean
##    - object: boolean
##    - date: boolean
##    - set: boolean
##    - list: boolean
##    - stringArray: boolean
##    - calendar: boolean
##    - typeName: String
##    - typeQualifiedName: String
##    - type: String
##    - boolean: boolean
##    - long: boolean
##    - float: boolean
##    - double: boolean
##    - void: boolean
##    - notNull: boolean
##    - char: boolean
##    - byte: boolean
##    - short: boolean
##    - modifierStatic: boolean
##    - modifierPublic: boolean
##    - modifierProtected: boolean
##    - modifierPackageLocal: boolean
##    - modifierPrivate: boolean
##    - modifierFinal: boolean
##
## - FieldEntry
##   - constant: boolean
##   - modifierTransient: boolean
##   - modifierVolatile: boolean
##   - enum: boolean
##   - matchName(String): bool
##
## - MethodEntry
##   - methodName: String
##   - fieldName: String
##   - modifierAbstract: boolean
##   - modifierSynchronzied: boolean
##   - modifierSynchronized: boolean
##   - returnTypeVoid: boolean
##   - getter: boolean
##   - deprecated: boolean
##   - matchName(String): bool
##
## Variables for Body Mode
## -----------------------
## - class0: ClassEntry         The current class
## - fields: List<FieldEntry>   All selected fields
## - methods: List<MethodEntry> All selected methods
## - members: List<MemberEntry> selected fields+methods
## - parentMethod: MethodEntry  The nearest method that surround the current cursor
##
## Utilities
## ---------
## - settings: CodeStyleSettings settings of code style
## - project: Project            The project instance, normally used by Psi related utilities
## - helper: GenerationHelper
## - StringUtil: Class
## - NameUtil: Class
## - PsiShortNamesCache: Class   utility to search classes
## - PsiJavaPsiFacade: Class     Java specific utility to search classes
## - GlobalSearchScope: Class    class to create search scopes, used by above utilities
## - EntryFactory: Class         EntryFactory.of(...) to turn PsiXXX to XXXEntry.
##
## Other feature
## -------------
## - Auto import.      If the generated code contains full qualified name, Code Generator will try to
##                     import the packages automatically and shorten the name.
##                     For example `java.util.List<>` -> `List<>`
##
## References
## ----------
## - Velocity syntax: http://velocity.apache.org/engine/1.7/user-guide.html

public static class Builder {
private ${class0.name} instance = new ${class0.name}();

private Builder() {}

public static Builder getInstance() {
return new Builder();
}
public static Builder getInstance(${class0.name} instance) {
            Builder builder = new Builder();
            builder.instance = instance;
            return builder;
        }
#if ( $members.size() > 0 )
    #foreach( $member in $members )
    #set($name = $StringUtil.capitalizeWithJavaBeanConvention($StringUtil.sanitizeJavaIdentifier($helper.getPropertyName($member.element, $project))))
    public Builder add${name}(${member.type} ${member.accessor}) {
    this.instance.set${name}(${member.accessor});
    return this;
    }
    #end
#end
public ${class0.name} build() {
return this.instance;
}
}

参考:

  【1】个人博客,http://www.littlefisher.site/2018/04/02/Eclipse%E8%BD%ACIDEA%E6%8C%87%E5%8D%97/

原文地址:https://www.cnblogs.com/happyflyingpig/p/9071316.html

时间: 2024-10-10 23:35:07

Intellij-安装CodeGenerator插件并且添加Builder模板的相关文章

android stuido 在线安装svn插件,添加版本库无响应

问题:android stuido 中在线安装svn插件,添加版本库无响应. 原因: 由于android stuido 版本较高,在线安装1.6x 版本的svn,添加版本库一直没有响应,最后卡死.. 解决方式:先删除SVN插件,重启后,再次在线安装,或者其他方式安装. 结果:问题解决.

intellij安装angularjs插件

1.先下载angular插件 http://plugins.jetbrains.com/plugin/6971?pr=idea 2.打开Intellij IDEA ,File-〉Settings---〉Plugins 点击" 点击""确定 重新启动Intellij IDEA,在Html文件中输入ng,出现提示,则说明插件安装成功:

eclipse离线安装maven插件/离线添加m2eclipse插件与警告问题解决

尝试了几次在线安装都失败了之后,俺果断放弃了在线安装,还是离线安装好啊. 安装插件: 1,下载M2Eclipse插件压缩包: 2,解压文件放入一个文件夹,将该文件夹放入eclipse安装目录下的dropin文件夹中; 3,重启eclipse(如果你之前已经开启了),进入欢迎界面,恭喜你,安装成功了.可是,怎么就弹出警告了呢,接下来就是解决方法. 解决警告弹出问题: 1,点击弹出警告的 install jdk,在新的界面中如果没有jdk选项,那你就新建个,目录就是你安装过的jdk的目录,之后记得选

Intellij安装lombok插件,解决注解@Slf4j注入后找不到变量log

1.进入设置 2.搜索插件 3.安装

IntelliJ IDEA lombok插件的安装和使用

IntelliJ IDEA是一款非常优秀的集成开发工具,功能强大,而且插件众多.lombok是开源的代码生成库,是一款非常实用的小工具,我们在编辑实体类时可以通过lombok注解减少getter.setter等方法的编写,在更改实体类时只需要修改属性即可,减少了很多重复代码的编写工作.本文小编只介绍IntelliJ IDEA中lombok插件的安装和配置以及简单的使用方法,更多请大家参考下文lombok在Eclipse下的使用,里面包含了使用方法和常用lombok注解的介绍. lombok插件的

【图】intellij idea安装mybatis插件方法

1)选择file -> setting -> plugins,搜索mybatis,这时因为没有安装过插件,所以会出现如图所示: 2)点击Browse,这是会弹出如下窗口,intellij idea会自动从网络搜索插件,方便下载,如图所示: 3)点击Install plugin即可自动下载安装,之后重启intellij idea即可.

IntelliJ Idea 14 安装 Golang 插件 google-go-lang-idea-

IntelliJ Idea 14 安装 Golang 插件 google-go-lang-idea-plugin 的方法 2015-03-08 16:51   zsjangel 阅读 4249 次   0 人喜欢  1 条评论  收藏 IDEA 的编辑器都很强悍,所以现在学Go 也想用他啊,无奈这个插件搞了好久,整理了下流程记录下 1. 当然是下载 IDEA 编辑器了 http://www.jetbrains.com/idea/download/ 附上旗舰版注册机地址 http://downlo

Eclipse Wowza 插件报 &quot;The builder launch configuration could not be found&quot; 错误的解决办法

前边有篇博客<Eclipse 报 "The builder launch configuration could not be found" 错误的解决办法>介绍了 Eclipse 报错 "The builder launch configuration could not be found" 的解决办法,按那个办法处理之后,发现不报错了,但 ant 的自动构建没了.这样没法接受.        看来逃避是解决不了问题呢.所以觉得<Eclipse

idea 安装 lombok插件

一,前言 lombok是什么?lombak是一个工具,主要用来简化,减少代码的编写.使代码看起来更清晰,简洁. 而且lombok只是一个工具,不会打包到war中,不会增加任何消耗.只是在编译期中帮助我们完成额外的工作. 例如getter/setter的编写,构造器,tostring方法等. 同时.lombok可以通过@Builder注解,让类可以拥有使用[.]操作符连续调用的形式进行赋值. 二,lombok插件的安装 想要使用lombok,需要两个步骤: 1,针对开发工具,添加lombok插件.