Intellij IDEA 2018.1.2版本

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

步骤一:安装插件

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

  

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

  

  1. ## Tutorial for writing your templates
  2. ##
  3. ## 1. First you need to know basic syntax of velocity[1].
  4. ## 2. Then it is necessary to understand the variable that CodeGenerator provides
  5. ## and its inner structure for retrieving the information you need for generating code.
  6. ## 3. Learn to use the utils provided so that you can ask for further information
  7. ## or reduce your workload.
  8. ##
  9. ## Variables Provided (Class Mode)
  10. ## -------------------------------
  11. ## Class mode means you want to create new classes(file).
  12. ##
  13. ## - ClassName: String The name spcified by `Target Class Name`
  14. ## - PackageName: String The package name specified by `Target Class Name`
  15. ## - class0: ClassEntry The class that the action is triggered upon
  16. ## - raw: PsiClass
  17. ## - String packageName
  18. ## - importList: List<String>
  19. ## - fields: List<FieldEntry>
  20. ## - allFields: List<FieldEntry>
  21. ## - methods: List<MethodEntry>
  22. ## - allMethods: List<MethodEntry>
  23. ## - innerClasses: List<ClassEntry>
  24. ## - allInnerClasses: List<ClassEntry>
  25. ## - typeParamList: List<String>
  26. ## - name: String
  27. ## - superName: String
  28. ## - superQualifiedName: String
  29. ## - qualifiedName: String
  30. ## - typeParams: int
  31. ## - hasSuper: boolean
  32. ## - deprecated: boolean
  33. ## - enum: boolean
  34. ## - exception: boolean
  35. ## - abstract: boolean
  36. ## - implementNames: String[]
  37. ## - isImplements(String): bool
  38. ## - isExtends(String): bool
  39. ## - matchName(String): bool
  40. ##
  41. ## - class1: ClassEntry The first selected class, where `1` is the postfix
  42. ## you specify in pipeline
  43. ## ...
  44. ##
  45. ## - MemberEntry (FieldEntry/MethodEntry common properties)
  46. ## - raw: PsiField(for field), PsiMethod(for method)
  47. ## - name: String
  48. ## - accessor: String
  49. ## - array: boolean
  50. ## - nestedArray: boolean
  51. ## - collection: boolean
  52. ## - map: boolean
  53. ## - primitive: boolean
  54. ## - string: boolean
  55. ## - primitiveArray: boolean
  56. ## - objectArray: boolean
  57. ## - numeric: boolean
  58. ## - object: boolean
  59. ## - date: boolean
  60. ## - set: boolean
  61. ## - list: boolean
  62. ## - stringArray: boolean
  63. ## - calendar: boolean
  64. ## - typeName: String
  65. ## - typeQualifiedName: String
  66. ## - type: String
  67. ## - boolean: boolean
  68. ## - long: boolean
  69. ## - float: boolean
  70. ## - double: boolean
  71. ## - void: boolean
  72. ## - notNull: boolean
  73. ## - char: boolean
  74. ## - byte: boolean
  75. ## - short: boolean
  76. ## - modifierStatic: boolean
  77. ## - modifierPublic: boolean
  78. ## - modifierProtected: boolean
  79. ## - modifierPackageLocal: boolean
  80. ## - modifierPrivate: boolean
  81. ## - modifierFinal: boolean
  82. ##
  83. ## - FieldEntry
  84. ## - constant: boolean
  85. ## - modifierTransient: boolean
  86. ## - modifierVolatile: boolean
  87. ## - enum: boolean
  88. ## - matchName(String): bool
  89. ##
  90. ## - MethodEntry
  91. ## - methodName: String
  92. ## - fieldName: String
  93. ## - modifierAbstract: boolean
  94. ## - modifierSynchronzied: boolean
  95. ## - modifierSynchronized: boolean
  96. ## - returnTypeVoid: boolean
  97. ## - getter: boolean
  98. ## - deprecated: boolean
  99. ## - matchName(String): bool
  100. ##
  101. ## Variables for Body Mode
  102. ## -----------------------
  103. ## - class0: ClassEntry The current class
  104. ## - fields: List<FieldEntry> All selected fields
  105. ## - methods: List<MethodEntry> All selected methods
  106. ## - members: List<MemberEntry> selected fields+methods
  107. ## - parentMethod: MethodEntry The nearest method that surround the current cursor
  108. ##
  109. ## Utilities
  110. ## ---------
  111. ## - settings: CodeStyleSettings settings of code style
  112. ## - project: Project The project instance, normally used by Psi related utilities
  113. ## - helper: GenerationHelper
  114. ## - StringUtil: Class
  115. ## - NameUtil: Class
  116. ## - PsiShortNamesCache: Class utility to search classes
  117. ## - PsiJavaPsiFacade: Class Java specific utility to search classes
  118. ## - GlobalSearchScope: Class class to create search scopes, used by above utilities
  119. ## - EntryFactory: Class EntryFactory.of(...) to turn PsiXXX to XXXEntry.
  120. ##
  121. ## Other feature
  122. ## -------------
  123. ## - Auto import. If the generated code contains full qualified name, Code Generator will try to
  124. ## import the packages automatically and shorten the name.
  125. ## For example `java.util.List<>` -> `List<>`
  126. ##
  127. ## References
  128. ## ----------
  129. ## - Velocity syntax: http://velocity.apache.org/engine/1.7/user-guide.html
  130.  
  131. public static class Builder {
  132. private ${class0.name} instance = new ${class0.name}();
  133.  
  134. private Builder() {}
  135.  
  136. public static Builder getInstance() {
  137. return new Builder();
  138. }
  139. public static Builder getInstance(${class0.name} instance) {
  140. Builder builder = new Builder();
  141. builder.instance = instance;
  142. return builder;
  143. }
  144. #if ( $members.size() > 0 )
  145. #foreach( $member in $members )
  146. #set($name = $StringUtil.capitalizeWithJavaBeanConvention($StringUtil.sanitizeJavaIdentifier($helper.getPropertyName($member.element, $project))))
  147. public Builder add${name}(${member.type} ${member.accessor}) {
  148. this.instance.set${name}(${member.accessor});
  149. return this;
  150. }
  151. #end
  152. #end
  153. public ${class0.name} build() {
  154. return this.instance;
  155. }
  156. }

参考:

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

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

  1. IntelliJ IDEA lombok插件的安装和使用

    IntelliJ IDEA是一款非常优秀的集成开发工具,功能强大,而且插件众多.lombok是开源的代码生成库,是一款非常实用的小工具,我们在编辑实体类时可以通过lombok注解减少getter.se ...

  2. IntelliJ IDEA - 热部署插件JRebel 安装使用教程

    IntelliJ IDEA - JRebel 安装使用教程 JRebel 能做什么? JRebel 是一款热部署插件.当你的 Java-web 项目在 tomcat 中 run/debug 的时候 , ...

  3. 在IntelliJ IDEA14中安装go语言插件

    go语言的集成开发环境仍不成熟,试用了liteide,感觉很不适应,弹出菜单对程序员的干扰太大.所以就试大牌的IntelliJ IDEA,这工具本来是JAVA开发阵营的,不过它已经变为一个非常强大的支 ...

  4. 安装IntelliJ IDEA热部署tomcat插件JreBel

    最近试着使用IntelliJ IDEA这款IDE,网上说它是最好用的java开发工具~但奈何国内ecilpse市场占有率实在稳固,所以国内这个工具也就少数人在使用 当然使用起来跟ecilpse还是有很 ...

  5. Intellij idea 离线安装activiti工作流插件

    想在Intellij idea上安装一个activiti插件玩玩,由于网络环境原因,不能使用网上已有的在线搜索acti bpm并安装的方式.也在网上找了好久没找到离线安装的方式.自己摸索了一下装好了, ...

  6. 详述 IntelliJ IDEA 插件的安装及使用方法

    首先,进入插件安装界面: Mac:IntelliJ IDEA -> Preferences -> Plugins; Windows:File -> Settings -> Pl ...

  7. IntelliJ IDEA 中安装junit插件

    1.在Intellij IDEA 中安装了 Junit,TestNG插件,首先检查一下intellij IDEA 是否在安装时默认安装了这两个插件,检查方法 打开 settings -->Plu ...

  8. 十五、详述 IntelliJ IDEA 插件的安装及使用方法

    正文 首先,进入插件安装界面: Mac:IntelliJ IDEA -> Preferences -> Plugins; Windows:File -> Settings -> ...

  9. 详述IntelliJ IDEA插件的安装及使用方法(图解)

    intellij idea是一款非常优秀的软件开发工具,它拥有这强大的插件体系,可以帮助开发者完成很多重量级的功能.今天,我们来学习一下如何安装和卸载intellij idea的插件. Intelli ...

随机推荐

  1. Error setting expression 'XXX‘'[Ljava.lang.with value '[Ljava.lang.String;@10101fb'

    ognl报的警告,说明你的格式错误,一般是日期格式错误,格式转换器的应用,id设置的类型不对String 类型,输入了Int类型所以方法一是改变这个类中的id的属性 然后get和set也跟着改变 另一 ...

  2. LDA汇总

    1.Blei的LDA代码(C):http://www.cs.princeton.edu/~blei/lda-c/index.html2.D.Bei的主页:http://www.cs.princeton ...

  3. 使用系统的CoreLocation定位

    ////  ViewController.m//  LBS////  Created by tonnyhuang on 15/8/28.//  Copyright (c) 2015年 tonnyhua ...

  4. C++和Python混合编程

    为何人工智能(AI)首选Python?读完这篇文章你就知道了:https://blog.csdn.net/qq_41769259/article/details/79419322 C++调用Pytho ...

  5. codevs 1083

    这道题是看了人家大牛的解题报告: 对了,要说明一下,(A+B)&1 ,表示,判断(A+B)是奇数否? 下面给出代码: #include<iostream> #include< ...

  6. NET平台开源项目速览(6)FluentValidation验证组件介绍与入门(转载)

    原文地址:http://www.cnblogs.com/asxinyu/p/dotnet_Opensource_project_FluentValidation_1.html 阅读目录 1.基本介绍 ...

  7. Tomcat监听443端口的方法

    当我们需要更安全的访问网站的时候就会选择使用https协议,而https协议默认的端口号为443端口,这就是我们为什么向让Tomcat监听在443端口的原因,因为监控在非80端口和443端口的web服 ...

  8. Win10下安装msi程序包时报2503、2502错误问题及其解决办法

    Win10系统下安装TortoiseSvn.Node.js时(.msi后缀的安装文件),在点击安装时老是提示2503,2502错误,因此无法安装上. 搜索了下一般都提到是权限不够引起的该问题.但是右键 ...

  9. DBCC--CHECKDB--不可被替代的原因

    CHECKSUM不能发现的两类问题 1. 发生在内存中的页错误,如内存损坏+第三方程序修改等 2. MS SQL Server潜在BUG导致的逻辑错误,该类错误可以使用重建索引或重建约束来修复 CHE ...

  10. C# 委托和接口

    能用委托解决的事情,接口也都可以解决.如下所示: public static void Main() { , , , }; Util.TransformAll(values, new Squarer( ...