├── .gitignore ├── LICENSE ├── README.md ├── pom.xml └── src └── main └── java └── com └── softwareloop └── mybatis └── generator └── plugins └── LombokPlugin.java /.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | /.idea 3 | *.DS_Store 4 | *.iml 5 | *.ipr 6 | *.iws 7 | *~ 8 | *.bak 9 | *.orig 10 | *.log 11 | *.project 12 | /.settings/ 13 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright {yyyy} {name of copyright owner} 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | 203 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # MyBatis Generator Lombok plugin 2 | 3 | A plugin for [MyBatis Generator](http://mybatis.github.io/generator/) 4 | to use [Lombok](http://projectlombok.org/) annotations 5 | instead of getters and setters. Helps to reduce the amount of 6 | generated boilerplate code. 7 | 8 | Code __before__ applying the Lombok plugin: 9 | 10 | ```java 11 | package example.dto; 12 | 13 | public class Contact { 14 | private Long id; 15 | 16 | private String firstName; 17 | 18 | private String lastName; 19 | 20 | private String phone; 21 | 22 | private String email; 23 | 24 | public Long getId() { 25 | return id; 26 | } 27 | 28 | public void setId(Long id) { 29 | this.id = id; 30 | } 31 | 32 | public String getFirstName() { 33 | return firstName; 34 | } 35 | 36 | public void setFirstName(String firstName) { 37 | this.firstName = firstName; 38 | } 39 | 40 | public String getLastName() { 41 | return lastName; 42 | } 43 | 44 | public void setLastName(String lastName) { 45 | this.lastName = lastName; 46 | } 47 | 48 | public String getPhone() { 49 | return phone; 50 | } 51 | 52 | public void setPhone(String phone) { 53 | this.phone = phone; 54 | } 55 | 56 | public String getEmail() { 57 | return email; 58 | } 59 | 60 | public void setEmail(String email) { 61 | this.email = email; 62 | } 63 | } 64 | ``` 65 | 66 | Code __after__ applying the Lombok plugin (much shorter): 67 | 68 | ```java 69 | package example.dto; 70 | 71 | import lombok.Data; 72 | 73 | @Data 74 | public class Contact { 75 | private Long id; 76 | 77 | private String firstName; 78 | 79 | private String lastName; 80 | 81 | private String phone; 82 | 83 | private String email; 84 | } 85 | ``` 86 | 87 | ## Using the plugin 88 | 89 | In your Maven pom.xml file, set up the MyBatis Generator plugin, and add 90 | mybatis-generator-lombok-plugin as a dependency: 91 | 92 | ```xml 93 | 94 | org.mybatis.generator 95 | mybatis-generator-maven-plugin 96 | ${mybatis.generator.version} 97 | 98 | true 99 | 100 | 101 | 102 | com.softwareloop 103 | mybatis-generator-lombok-plugin 104 | 1.0 105 | 106 | 107 | 108 | ``` 109 | 110 | Then, in your MyBatis Generator configuration, include the plugin: 111 | 112 | ```xml 113 | 114 | 117 | 118 | 119 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | ``` 145 | 146 | ## Authors 147 | 148 | Maintainer: 149 | 150 | * [softwareloop](https://github.com/softwareloop) 151 | 152 | Contributors: 153 | 154 | * [izebit](https://github.com/izebit) 155 | * [kimmking](https://github.com/kimmking) 156 | * [tomoki1207](https://github.com/tomoki1207) 157 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4.0.0 4 | 5 | com.softwareloop 6 | mybatis-generator-lombok-plugin 7 | 1.1-SNAPSHOT 8 | 9 | mybatis-generator-lombok-plugin 10 | A plugin for MyBatis Generator to use Lombok annotations instead of getters and setters 11 | https://github.com/softwareloop/mybatis-generator-lombok-plugin 12 | 13 | 14 | 15 | Apache License v2.0 16 | http://www.apache.org/licenses/LICENSE-2.0 17 | repo 18 | OSI-approved license 19 | 20 | 21 | 22 | 23 | scm:git:git@github.com:softwareloop/mybatis-generator-lombok-plugin.git 24 | scm:git:git@github.com:softwareloop/mybatis-generator-lombok-plugin.git 25 | git@github.com:softwareloop/mybatis-generator-lombok-plugin.git 26 | HEAD 27 | 28 | 29 | 30 | 31 | Paolo Predonzani 32 | paolo.predonzani@gmail.com 33 | https://github.com/softwareloop 34 | 35 | 36 | 37 | 38 | 39 | Artem Konovalov 40 | https://github.com/izebit 41 | 42 | 43 | Kimmking 44 | https://github.com/kimmking 45 | 46 | 47 | MaruyamaTomoki 48 | https://github.com/tomoki1207 49 | 50 | 51 | 52 | 53 | 54 | org.mybatis.generator 55 | mybatis-generator-core 56 | 1.3.2 57 | provided 58 | 59 | 60 | 61 | 62 | 63 | ossrh 64 | https://oss.sonatype.org/content/repositories/snapshots 65 | 66 | 67 | ossrh 68 | https://oss.sonatype.org/service/local/staging/deploy/maven2/ 69 | 70 | 71 | 72 | 91 | 92 | 93 | 94 | 95 | org.apache.maven.plugins 96 | maven-resources-plugin 97 | 2.7 98 | 99 | UTF-8 100 | 101 | 102 | 103 | org.apache.maven.plugins 104 | maven-enforcer-plugin 105 | 1.2 106 | 107 | 108 | enforce-maven 109 | 110 | enforce 111 | 112 | 113 | 114 | 115 | (,2.1.0),(2.1.0,2.2.0),(2.2.0,) 116 | Maven 2.1.0 and 2.2.0 produce incorrect GPG signatures and checksums respectively. 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | org.apache.maven.plugins 125 | maven-release-plugin 126 | 2.5.1 127 | 128 | forked-path 129 | false 130 | -Psonatype-oss-release 131 | true 132 | v@{project.version} 133 | 134 | 135 | 136 | org.apache.maven.plugins 137 | maven-compiler-plugin 138 | 139 | 6 140 | 6 141 | 142 | 143 | 144 | 145 | 146 | 147 | sonatype-oss-release 148 | 149 | 150 | 151 | org.apache.maven.plugins 152 | maven-source-plugin 153 | 2.4 154 | 155 | 156 | attach-sources 157 | 158 | jar-no-fork 159 | 160 | 161 | 162 | 163 | 164 | org.apache.maven.plugins 165 | maven-javadoc-plugin 166 | 2.10.1 167 | 168 | 169 | attach-javadocs 170 | 171 | jar 172 | 173 | 174 | 175 | 176 | 177 | org.apache.maven.plugins 178 | maven-gpg-plugin 179 | 1.6 180 | 181 | 182 | sign-artifacts 183 | verify 184 | 185 | sign 186 | 187 | 188 | 189 | 190 | 191 | 192 | 193 | 194 | 195 | -------------------------------------------------------------------------------- /src/main/java/com/softwareloop/mybatis/generator/plugins/LombokPlugin.java: -------------------------------------------------------------------------------- 1 | package com.softwareloop.mybatis.generator.plugins; 2 | 3 | import org.mybatis.generator.api.IntrospectedColumn; 4 | import org.mybatis.generator.api.IntrospectedTable; 5 | import org.mybatis.generator.api.PluginAdapter; 6 | import org.mybatis.generator.api.dom.java.FullyQualifiedJavaType; 7 | import org.mybatis.generator.api.dom.java.Interface; 8 | import org.mybatis.generator.api.dom.java.Method; 9 | import org.mybatis.generator.api.dom.java.TopLevelClass; 10 | 11 | import java.util.*; 12 | 13 | 14 | /** 15 | * A MyBatis Generator plugin to use Lombok's annotations. 16 | * For example, use @Data annotation instead of getter ands setter. 17 | * 18 | * @author Paolo Predonzani (http://softwareloop.com/) 19 | */ 20 | public class LombokPlugin extends PluginAdapter { 21 | 22 | private final Collection annotations; 23 | 24 | /** 25 | * LombokPlugin constructor 26 | */ 27 | public LombokPlugin() { 28 | annotations = new LinkedHashSet(Annotations.values().length); 29 | } 30 | 31 | /** 32 | * @param warnings list of warnings 33 | * @return always true 34 | */ 35 | public boolean validate(List warnings) { 36 | return true; 37 | } 38 | 39 | /** 40 | * Intercepts base record class generation 41 | * 42 | * @param topLevelClass the generated base record class 43 | * @param introspectedTable The class containing information about the table as 44 | * introspected from the database 45 | * @return always true 46 | */ 47 | @Override 48 | public boolean modelBaseRecordClassGenerated( 49 | TopLevelClass topLevelClass, 50 | IntrospectedTable introspectedTable 51 | ) { 52 | addAnnotations(topLevelClass); 53 | return true; 54 | } 55 | 56 | /** 57 | * Intercepts primary key class generation 58 | * 59 | * @param topLevelClass the generated primary key class 60 | * @param introspectedTable The class containing information about the table as 61 | * introspected from the database 62 | * @return always true 63 | */ 64 | @Override 65 | public boolean modelPrimaryKeyClassGenerated( 66 | TopLevelClass topLevelClass, 67 | IntrospectedTable introspectedTable 68 | ) { 69 | addAnnotations(topLevelClass); 70 | return true; 71 | } 72 | 73 | /** 74 | * Intercepts "record with blob" class generation 75 | * 76 | * @param topLevelClass the generated record with BLOBs class 77 | * @param introspectedTable The class containing information about the table as 78 | * introspected from the database 79 | * @return always true 80 | */ 81 | @Override 82 | public boolean modelRecordWithBLOBsClassGenerated( 83 | TopLevelClass topLevelClass, 84 | IntrospectedTable introspectedTable 85 | ) { 86 | addAnnotations(topLevelClass); 87 | return true; 88 | } 89 | 90 | /** 91 | * Prevents all getters from being generated. 92 | * See SimpleModelGenerator 93 | * 94 | * @param method the getter, or accessor, method generated for the specified 95 | * column 96 | * @param topLevelClass the partially implemented model class 97 | * @param introspectedColumn The class containing information about the column related 98 | * to this field as introspected from the database 99 | * @param introspectedTable The class containing information about the table as 100 | * introspected from the database 101 | * @param modelClassType the type of class that the field is generated for 102 | */ 103 | @Override 104 | public boolean modelGetterMethodGenerated( 105 | Method method, 106 | TopLevelClass topLevelClass, 107 | IntrospectedColumn introspectedColumn, 108 | IntrospectedTable introspectedTable, 109 | ModelClassType modelClassType 110 | ) { 111 | return false; 112 | } 113 | 114 | /** 115 | * Prevents all setters from being generated 116 | * See SimpleModelGenerator 117 | * 118 | * @param method the setter, or mutator, method generated for the specified 119 | * column 120 | * @param topLevelClass the partially implemented model class 121 | * @param introspectedColumn The class containing information about the column related 122 | * to this field as introspected from the database 123 | * @param introspectedTable The class containing information about the table as 124 | * introspected from the database 125 | * @param modelClassType the type of class that the field is generated for 126 | * @return always false 127 | */ 128 | @Override 129 | public boolean modelSetterMethodGenerated( 130 | Method method, 131 | TopLevelClass topLevelClass, 132 | IntrospectedColumn introspectedColumn, 133 | IntrospectedTable introspectedTable, 134 | ModelClassType modelClassType 135 | ) { 136 | return false; 137 | } 138 | 139 | /** 140 | * Adds the lombok annotations' imports and annotations to the class 141 | * 142 | * @param topLevelClass the partially implemented model class 143 | */ 144 | private void addAnnotations(TopLevelClass topLevelClass) { 145 | for (Annotations annotation : annotations) { 146 | topLevelClass.addImportedType(annotation.javaType); 147 | topLevelClass.addAnnotation(annotation.asAnnotation()); 148 | } 149 | } 150 | 151 | @Override 152 | public void setProperties(Properties properties) { 153 | super.setProperties(properties); 154 | 155 | //@Data is default annotation 156 | annotations.add(Annotations.DATA); 157 | 158 | for (String annotationName : properties.stringPropertyNames()) { 159 | if (annotationName.contains(".")) { 160 | // Not an annotation name 161 | continue; 162 | } 163 | String value = properties.getProperty(annotationName); 164 | if (!Boolean.parseBoolean(value)) { 165 | // The annotation is disabled, skip it 166 | continue; 167 | } 168 | Annotations annotation = Annotations.getValueOf(annotationName); 169 | if (annotation == null) { 170 | continue; 171 | } 172 | String optionsPrefix = annotationName + "."; 173 | for (String propertyName : properties.stringPropertyNames()) { 174 | if (!propertyName.startsWith(optionsPrefix)) { 175 | // A property not related to this annotation 176 | continue; 177 | } 178 | String propertyValue = properties.getProperty(propertyName); 179 | annotation.appendOptions(propertyName, propertyValue); 180 | annotations.add(annotation); 181 | annotations.addAll(Annotations.getDependencies(annotation)); 182 | } 183 | } 184 | } 185 | 186 | @Override 187 | public boolean clientGenerated( 188 | Interface interfaze, 189 | TopLevelClass topLevelClass, 190 | IntrospectedTable introspectedTable 191 | ) { 192 | interfaze.addImportedType(new FullyQualifiedJavaType( 193 | "org.apache.ibatis.annotations.Mapper")); 194 | interfaze.addAnnotation("@Mapper"); 195 | return true; 196 | } 197 | 198 | private enum Annotations { 199 | DATA("data", "@Data", "lombok.Data"), 200 | BUILDER("builder", "@Builder", "lombok.Builder"), 201 | ALL_ARGS_CONSTRUCTOR("allArgsConstructor", "@AllArgsConstructor", "lombok.AllArgsConstructor"), 202 | NO_ARGS_CONSTRUCTOR("noArgsConstructor", "@NoArgsConstructor", "lombok.NoArgsConstructor"), 203 | ACCESSORS("accessors", "@Accessors", "lombok.experimental.Accessors"), 204 | TO_STRING("toString", "@ToString", "lombok.ToString"); 205 | 206 | 207 | private final String paramName; 208 | private final String name; 209 | private final FullyQualifiedJavaType javaType; 210 | private final List options; 211 | 212 | 213 | Annotations(String paramName, String name, String className) { 214 | this.paramName = paramName; 215 | this.name = name; 216 | this.javaType = new FullyQualifiedJavaType(className); 217 | this.options = new ArrayList(); 218 | } 219 | 220 | private static Annotations getValueOf(String paramName) { 221 | for (Annotations annotation : Annotations.values()) 222 | if (String.CASE_INSENSITIVE_ORDER.compare(paramName, annotation.paramName) == 0) 223 | return annotation; 224 | 225 | return null; 226 | } 227 | 228 | private static Collection getDependencies(Annotations annotation) { 229 | if (annotation == ALL_ARGS_CONSTRUCTOR) 230 | return Collections.singleton(NO_ARGS_CONSTRUCTOR); 231 | else 232 | return Collections.emptyList(); 233 | } 234 | 235 | // A trivial quoting. 236 | // Because Lombok annotation options type is almost String or boolean. 237 | private static String quote(String value) { 238 | if (Boolean.TRUE.toString().equals(value) || Boolean.FALSE.toString().equals(value)) 239 | // case of boolean, not passed as an array. 240 | return value; 241 | return value.replaceAll("[\\w]+", "\"$0\""); 242 | } 243 | 244 | private void appendOptions(String key, String value) { 245 | String keyPart = key.substring(key.indexOf(".") + 1); 246 | String valuePart = value.contains(",") ? String.format("{%s}", value) : value; 247 | this.options.add(String.format("%s=%s", keyPart, quote(valuePart))); 248 | } 249 | 250 | private String asAnnotation() { 251 | if (options.isEmpty()) { 252 | return name; 253 | } 254 | StringBuilder sb = new StringBuilder(); 255 | sb.append(name); 256 | sb.append("("); 257 | boolean first = true; 258 | for (String option : options) { 259 | if (first) { 260 | first = false; 261 | } else { 262 | sb.append(", "); 263 | } 264 | sb.append(option); 265 | } 266 | sb.append(")"); 267 | return sb.toString(); 268 | } 269 | } 270 | } 271 | --------------------------------------------------------------------------------