├── .gitignore ├── LICENSE.txt ├── build.xml ├── buildScripts ├── ivy-repo │ ├── easytesting.org-fest-assert-1.3.xml │ ├── easytesting.org-fest-util-1.1.4.xml │ ├── eclipse.org-core.runtime-3.6.0.xml │ ├── eclipse.org-ecj-3.6.0.xml │ ├── eclipse.org-jdt.core-3.6.0.xml │ ├── junit.org-junit-4.8.2.xml │ ├── projectlombok.org-javac-1.6.0.18.xml │ ├── projectlombok.org-lombok-0.10.0-BETA2-HEAD.xml │ ├── projectlombok.org-lombok-test-core-0.10.0-BETA2-HEAD.xml │ └── projectlombok.org-spi-0.2.4.xml ├── ivy.xml └── ivysettings.xml ├── readme.txt ├── src ├── core │ └── lombok │ │ ├── GenerateBoundSetter.java │ │ ├── GenerateJavaBean.java │ │ └── core │ │ └── util │ │ ├── Arrays.java │ │ ├── AstGeneration.java │ │ ├── ErrorMessages.java │ │ └── Names.java ├── eclipse │ └── lombok │ │ └── eclipse │ │ └── handlers │ │ ├── BoundSetterHandler.java │ │ ├── Eclipse.java │ │ ├── FieldBuilder.java │ │ ├── JavaBeanHandler.java │ │ ├── Lombok.java │ │ ├── MemberChecks.java │ │ └── MethodBuilder.java └── javac │ └── lombok │ └── javac │ └── handlers │ ├── BoundSetterHandler.java │ ├── FieldBuilder.java │ ├── JCNoType.java │ ├── JavaBeanHandler.java │ ├── Lombok.java │ ├── MemberChecks.java │ └── MethodBuilder.java └── test ├── core └── lombok │ └── core │ └── util │ ├── Arrays_array_Test.java │ ├── Arrays_copy_Test.java │ ├── Arrays_isNotEmpty_Test.java │ ├── AstGeneration_stopAstGeneration_Test.java │ ├── AstGeneration_stopAstGeneration_with_parameters_Test.java │ ├── ErrorMessages_canBeUsedOnClassOnly_Test.java │ ├── ErrorMessages_canBeUsedOnFieldOnly_Test.java │ ├── Names_nameOfConstantBasedOnProperty_Test.java │ └── Names_splitNameOf_Test.java ├── eclipse └── lombok │ └── eclipse │ └── handlers │ └── TestWithEcj.java ├── javac └── lombok │ └── javac │ └── handlers │ └── TestWithDelombok.java └── transform └── resource ├── after-delombok ├── CompleteJavaBean.java ├── GenerateJavaBeanNotInClass.java └── SimpleJavaBean.java ├── after-ecj ├── CompleteJavaBean.java ├── GenerateJavaBeanNotInClass.java └── SimpleJavaBean.java ├── before ├── CompleteJavaBean.java ├── GenerateJavaBeanNotInClass.java └── SimpleJavaBean.java ├── messages-delombok └── GenerateJavaBeanNotInClass.java.messages └── messages-ecj └── GenerateJavaBeanNotInClass.java.messages /.gitignore: -------------------------------------------------------------------------------- 1 | /lib 2 | /bin 3 | /.classpath 4 | /.project 5 | /ivyCache 6 | /.settings 7 | /.factorypath 8 | /.apt_generated 9 | /build 10 | /dist 11 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | 2 | Apache License 3 | Version 2.0, January 2004 4 | http://www.apache.org/licenses/ 5 | 6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 7 | 8 | 1. Definitions. 9 | 10 | "License" shall mean the terms and conditions for use, reproduction, 11 | and distribution as defined by Sections 1 through 9 of this document. 12 | 13 | "Licensor" shall mean the copyright owner or entity authorized by 14 | the copyright owner that is granting the License. 15 | 16 | "Legal Entity" shall mean the union of the acting entity and all 17 | other entities that control, are controlled by, or are under common 18 | control with that entity. For the purposes of this definition, 19 | "control" means (i) the power, direct or indirect, to cause the 20 | direction or management of such entity, whether by contract or 21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 22 | outstanding shares, or (iii) beneficial ownership of such entity. 23 | 24 | "You" (or "Your") shall mean an individual or Legal Entity 25 | exercising permissions granted by this License. 26 | 27 | "Source" form shall mean the preferred form for making modifications, 28 | including but not limited to software source code, documentation 29 | source, and configuration files. 30 | 31 | "Object" form shall mean any form resulting from mechanical 32 | transformation or translation of a Source form, including but 33 | not limited to compiled object code, generated documentation, 34 | and conversions to other media types. 35 | 36 | "Work" shall mean the work of authorship, whether in Source or 37 | Object form, made available under the License, as indicated by a 38 | copyright notice that is included in or attached to the work 39 | (an example is provided in the Appendix below). 40 | 41 | "Derivative Works" shall mean any work, whether in Source or Object 42 | form, that is based on (or derived from) the Work and for which the 43 | editorial revisions, annotations, elaborations, or other modifications 44 | represent, as a whole, an original work of authorship. For the purposes 45 | of this License, Derivative Works shall not include works that remain 46 | separable from, or merely link (or bind by name) to the interfaces of, 47 | the Work and Derivative Works thereof. 48 | 49 | "Contribution" shall mean any work of authorship, including 50 | the original version of the Work and any modifications or additions 51 | to that Work or Derivative Works thereof, that is intentionally 52 | submitted to Licensor for inclusion in the Work by the copyright owner 53 | or by an individual or Legal Entity authorized to submit on behalf of 54 | the copyright owner. For the purposes of this definition, "submitted" 55 | means any form of electronic, verbal, or written communication sent 56 | to the Licensor or its representatives, including but not limited to 57 | communication on electronic mailing lists, source code control systems, 58 | and issue tracking systems that are managed by, or on behalf of, the 59 | Licensor for the purpose of discussing and improving the Work, but 60 | excluding communication that is conspicuously marked or otherwise 61 | designated in writing by the copyright owner as "Not a Contribution." 62 | 63 | "Contributor" shall mean Licensor and any individual or Legal Entity 64 | on behalf of whom a Contribution has been received by Licensor and 65 | subsequently incorporated within the Work. 66 | 67 | 2. Grant of Copyright License. Subject to the terms and conditions of 68 | this License, each Contributor hereby grants to You a perpetual, 69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 70 | copyright license to reproduce, prepare Derivative Works of, 71 | publicly display, publicly perform, sublicense, and distribute the 72 | Work and such Derivative Works in Source or Object form. 73 | 74 | 3. Grant of Patent License. Subject to the terms and conditions of 75 | this License, each Contributor hereby grants to You a perpetual, 76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 77 | (except as stated in this section) patent license to make, have made, 78 | use, offer to sell, sell, import, and otherwise transfer the Work, 79 | where such license applies only to those patent claims licensable 80 | by such Contributor that are necessarily infringed by their 81 | Contribution(s) alone or by combination of their Contribution(s) 82 | with the Work to which such Contribution(s) was submitted. If You 83 | institute patent litigation against any entity (including a 84 | cross-claim or counterclaim in a lawsuit) alleging that the Work 85 | or a Contribution incorporated within the Work constitutes direct 86 | or contributory patent infringement, then any patent licenses 87 | granted to You under this License for that Work shall terminate 88 | as of the date such litigation is filed. 89 | 90 | 4. Redistribution. You may reproduce and distribute copies of the 91 | Work or Derivative Works thereof in any medium, with or without 92 | modifications, and in Source or Object form, provided that You 93 | meet the following conditions: 94 | 95 | (a) You must give any other recipients of the Work or 96 | Derivative Works a copy of this License; and 97 | 98 | (b) You must cause any modified files to carry prominent notices 99 | stating that You changed the files; and 100 | 101 | (c) You must retain, in the Source form of any Derivative Works 102 | that You distribute, all copyright, patent, trademark, and 103 | attribution notices from the Source form of the Work, 104 | excluding those notices that do not pertain to any part of 105 | the Derivative Works; and 106 | 107 | (d) If the Work includes a "NOTICE" text file as part of its 108 | distribution, then any Derivative Works that You distribute must 109 | include a readable copy of the attribution notices contained 110 | within such NOTICE file, excluding those notices that do not 111 | pertain to any part of the Derivative Works, in at least one 112 | of the following places: within a NOTICE text file distributed 113 | as part of the Derivative Works; within the Source form or 114 | documentation, if provided along with the Derivative Works; or, 115 | within a display generated by the Derivative Works, if and 116 | wherever such third-party notices normally appear. The contents 117 | of the NOTICE file are for informational purposes only and 118 | do not modify the License. You may add Your own attribution 119 | notices within Derivative Works that You distribute, alongside 120 | or as an addendum to the NOTICE text from the Work, provided 121 | that such additional attribution notices cannot be construed 122 | as modifying the License. 123 | 124 | You may add Your own copyright statement to Your modifications and 125 | may provide additional or different license terms and conditions 126 | for use, reproduction, or distribution of Your modifications, or 127 | for any such Derivative Works as a whole, provided Your use, 128 | reproduction, and distribution of the Work otherwise complies with 129 | the conditions stated in this License. 130 | 131 | 5. Submission of Contributions. Unless You explicitly state otherwise, 132 | any Contribution intentionally submitted for inclusion in the Work 133 | by You to the Licensor shall be under the terms and conditions of 134 | this License, without any additional terms or conditions. 135 | Notwithstanding the above, nothing herein shall supersede or modify 136 | the terms of any separate license agreement you may have executed 137 | with Licensor regarding such Contributions. 138 | 139 | 6. Trademarks. This License does not grant permission to use the trade 140 | names, trademarks, service marks, or product names of the Licensor, 141 | except as required for reasonable and customary use in describing the 142 | origin of the Work and reproducing the content of the NOTICE file. 143 | 144 | 7. Disclaimer of Warranty. Unless required by applicable law or 145 | agreed to in writing, Licensor provides the Work (and each 146 | Contributor provides its Contributions) on an "AS IS" BASIS, 147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 148 | implied, including, without limitation, any warranties or conditions 149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 150 | PARTICULAR PURPOSE. You are solely responsible for determining the 151 | appropriateness of using or redistributing the Work and assume any 152 | risks associated with Your exercise of permissions under this License. 153 | 154 | 8. Limitation of Liability. In no event and under no legal theory, 155 | whether in tort (including negligence), contract, or otherwise, 156 | unless required by applicable law (such as deliberate and grossly 157 | negligent acts) or agreed to in writing, shall any Contributor be 158 | liable to You for damages, including any direct, indirect, special, 159 | incidental, or consequential damages of any character arising as a 160 | result of this License or out of the use or inability to use the 161 | Work (including but not limited to damages for loss of goodwill, 162 | work stoppage, computer failure or malfunction, or any and all 163 | other commercial damages or losses), even if such Contributor 164 | has been advised of the possibility of such damages. 165 | 166 | 9. Accepting Warranty or Additional Liability. While redistributing 167 | the Work or Derivative Works thereof, You may choose to offer, 168 | and charge a fee for, acceptance of support, warranty, indemnity, 169 | or other liability obligations and/or rights consistent with this 170 | License. However, in accepting such obligations, You may act only 171 | on Your own behalf and on Your sole responsibility, not on behalf 172 | of any other Contributor, and only if You agree to indemnify, 173 | defend, and hold each Contributor harmless for any liability 174 | incurred by, or claims asserted against, such Contributor by reason 175 | of your accepting any such warranty or additional liability. 176 | 177 | END OF TERMS AND CONDITIONS 178 | 179 | APPENDIX: How to apply the Apache License to your work. 180 | 181 | To apply the Apache License to your work, attach the following 182 | boilerplate notice, with the fields enclosed by brackets "[]" 183 | replaced with your own identifying information. (Don't include 184 | the brackets!) The text should be enclosed in the appropriate 185 | comment syntax for the file format. We also recommend that a 186 | file or class name and description of purpose be included on the 187 | same "printed page" as the copyright notice for easier 188 | identification within third-party archives. 189 | 190 | Copyright [yyyy] [name of copyright owner] 191 | 192 | Licensed under the Apache License, Version 2.0 (the "License"); 193 | you may not use this file except in compliance with the License. 194 | You may obtain a copy of the License at 195 | 196 | http://www.apache.org/licenses/LICENSE-2.0 197 | 198 | Unless required by applicable law or agreed to in writing, software 199 | distributed under the License is distributed on an "AS IS" BASIS, 200 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 201 | See the License for the specific language governing permissions and 202 | limitations under the License. 203 | -------------------------------------------------------------------------------- /build.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | lombok.core.AnnotationProcessor 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | -------------------------------------------------------------------------------- /buildScripts/ivy-repo/easytesting.org-fest-assert-1.3.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /buildScripts/ivy-repo/easytesting.org-fest-util-1.1.4.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /buildScripts/ivy-repo/eclipse.org-core.runtime-3.6.0.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /buildScripts/ivy-repo/eclipse.org-ecj-3.6.0.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /buildScripts/ivy-repo/eclipse.org-jdt.core-3.6.0.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /buildScripts/ivy-repo/junit.org-junit-4.8.2.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /buildScripts/ivy-repo/projectlombok.org-javac-1.6.0.18.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /buildScripts/ivy-repo/projectlombok.org-lombok-0.10.0-BETA2-HEAD.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 17 | 19 | 20 | -------------------------------------------------------------------------------- /buildScripts/ivy-repo/projectlombok.org-lombok-test-core-0.10.0-BETA2-HEAD.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 17 | 19 | 20 | -------------------------------------------------------------------------------- /buildScripts/ivy-repo/projectlombok.org-spi-0.2.4.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /buildScripts/ivy.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /buildScripts/ivysettings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /readme.txt: -------------------------------------------------------------------------------- 1 | This project contains Lombok extensions that generate JavaBeans "bound" setters. 2 | See LICENSE.txt for the project lombok license. 3 | 4 | HINT: If you'd like to develop lombok in eclipse, run 'ant eclipse' first. It creates the necessary project infrastructure and downloads dependencies. 5 | 6 | Project Author: 7 | 8 | Alex Ruiz 9 | twitter: @alexRuiz 10 | home: http://alexruiz.developerblogs.com -------------------------------------------------------------------------------- /src/core/lombok/GenerateBoundSetter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Created on Nov 30, 2010 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with 5 | * the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on 10 | * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the 11 | * specific language governing permissions and limitations under the License. 12 | * 13 | * Copyright @2010 the original author or authors. 14 | */ 15 | package lombok; 16 | 17 | import static java.lang.annotation.ElementType.FIELD; 18 | import static java.lang.annotation.RetentionPolicy.SOURCE; 19 | import static lombok.AccessLevel.PUBLIC; 20 | 21 | import java.beans.PropertyChangeSupport; 22 | import java.lang.annotation.*; 23 | 24 | import lombok.AccessLevel; 25 | 26 | /** 27 | * Instructs lombok to generate a "bound" setter for an annotated field. 28 | *

29 | * For example, given this class: 30 | * 31 | *

32 |  * public class Person {
33 |  * 
34 |  *   @GenerateBoundSetter private String firstName;
35 |  * }
36 |  * 
37 | * our lombok annotation handlers (for both javac and eclipse) will generate the AST nodes that correspond to this code: 38 | * 39 | *
40 |  * public class Person {
41 |  * 
42 |  *   public static final String PROP_FIRST_NAME = "firstName";
43 |  *   
44 |  *   private String firstName;
45 |  *   
46 |  *   public void setFirstName(String value) {
47 |  *      String oldValue = firstName;
48 |  *      firstName = value;
49 |  *      propertySupport.firePropertyChange(PROP_FIRST_NAME, oldValue, firstName);
50 |  *   }
51 |  * }
52 |  * 
53 | *

54 | *

55 | * Note: The handler for this annotation assumes that the class declaring the annotated field has a 56 | * field of type {@link PropertyChangeSupport} with name "propertySupport." You can either add this 57 | * expected field manually or annotate the class with {@link GenerateJavaBean} to have lombok generate it 58 | * for you. 59 | *

60 | * 61 | * @author Alex Ruiz 62 | */ 63 | @Target(FIELD) @Retention(SOURCE) 64 | public @interface GenerateBoundSetter { 65 | 66 | /** 67 | * If you want your setter to be non-public, you can specify an alternate access level here. 68 | */ 69 | AccessLevel value() default PUBLIC; 70 | } 71 | -------------------------------------------------------------------------------- /src/core/lombok/GenerateJavaBean.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Created on Nov 30, 2010 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with 5 | * the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on 10 | * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the 11 | * specific language governing permissions and limitations under the License. 12 | * 13 | * Copyright @2010 the original author or authors. 14 | */ 15 | package lombok; 16 | 17 | import static java.lang.annotation.ElementType.*; 18 | import static java.lang.annotation.RetentionPolicy.SOURCE; 19 | 20 | import java.lang.annotation.*; 21 | 22 | /** 23 | * Instructs lombok to generate the necessary code to make an annotated Java class a JavaBean. 24 | *

25 | * For example, given this class: 26 | * 27 | *

28 |  * @GenerateJavaBean
29 |  * public class Person {
30 |  * 
31 |  * }
32 |  * 
33 | * our lombok annotation handlers (for both javac and eclipse) will generate the AST nodes that correspond to this code: 34 | * 35 | *
36 |  * public class Person {
37 |  * 
38 |  *   private PropertyChangeSupport propertySupport = new PropertyChangeSupport(this);
39 | 
40 |  *   public void addPropertyChangeListener(PropertyChangeListener listener) {
41 |  *     propertySupport.addPropertyChangeListener(listener);
42 |  *   }
43 |  *
44 |  *   public void removePropertyChangeListener(PropertyChangeListener listener) {
45 |  *     propertySupport.removePropertyChangeListener(listener);
46 |  *   }
47 |  * }
48 |  * 
49 | *

50 | * 51 | * @author Alex Ruiz 52 | */ 53 | @Target(TYPE) @Retention(SOURCE) 54 | public @interface GenerateJavaBean {} 55 | -------------------------------------------------------------------------------- /src/core/lombok/core/util/Arrays.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Created on Dec 6, 2010 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with 5 | * the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on 10 | * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the 11 | * specific language governing permissions and limitations under the License. 12 | * 13 | * Copyright @2010 the original author or authors. 14 | */ 15 | package lombok.core.util; 16 | 17 | import static java.util.Arrays.copyOf; 18 | 19 | /** 20 | * Utilities for arrays. 21 | * 22 | * @author Alex Ruiz 23 | */ 24 | public final class Arrays { 25 | 26 | /** 27 | * Convenience method for creating arrays. 28 | * @param the type of elements of the array. 29 | * @param elements the array, in varargs form. 30 | * @return the given array in varargs form. 31 | */ 32 | public static T[] array(T...elements) { 33 | return elements; 34 | } 35 | 36 | /** 37 | * Returns a copy of the given array. 38 | * @param the type of the given array. 39 | * @param array the given array. 40 | * @return a copy of the given array. 41 | */ 42 | public static T[] copy(T[] array) { 43 | return copyOf(array, array.length); 44 | } 45 | 46 | /** 47 | * Indicates whether the given array has elements or not. 48 | * @param array the given array. 49 | * @return {@code true} if the given array is not {@code null} and contains at least one element; {@code false} 50 | * otherwise. 51 | */ 52 | public static boolean isNotEmpty(Object[] array) { 53 | return array != null && array.length > 0; 54 | } 55 | 56 | private Arrays() {} 57 | } 58 | -------------------------------------------------------------------------------- /src/core/lombok/core/util/AstGeneration.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Created on Dec 1, 2010 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with 5 | * the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on 10 | * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the 11 | * specific language governing permissions and limitations under the License. 12 | * 13 | * Copyright @2010 the original author or authors. 14 | */ 15 | package lombok.core.util; 16 | 17 | import static lombok.AccessLevel.NONE; 18 | import lombok.AccessLevel; 19 | 20 | /** 21 | * Utilities related to AST node generation. 22 | * 23 | * @author Alex Ruiz 24 | */ 25 | public final class AstGeneration { 26 | 27 | /** 28 | * Indicates whether code generation should stop based on the given {@link AccessLevel}. 29 | * @param level the {@code AccessLevel} to evaluate. 30 | * @return {@code true} if the given {@code AccessLevel} is equal to {@link AccessLevel#NONE}; 31 | * {@code false} otherwise. 32 | */ 33 | public static boolean stopAstGeneration(AccessLevel level) { 34 | return level == NONE; 35 | } 36 | 37 | private AstGeneration() {} 38 | } 39 | -------------------------------------------------------------------------------- /src/core/lombok/core/util/ErrorMessages.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Created on Dec 6, 2010 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with 5 | * the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on 10 | * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the 11 | * specific language governing permissions and limitations under the License. 12 | * 13 | * Copyright @2010 the original author or authors. 14 | */ 15 | package lombok.core.util; 16 | 17 | import java.lang.annotation.Annotation; 18 | 19 | /** 20 | * Common error messages. 21 | * 22 | * @author Alex Ruiz 23 | */ 24 | public final class ErrorMessages { 25 | 26 | public static String canBeUsedOnClassOnly(Class annotationType) { 27 | return errorMessage("@%s can be used on classes only", annotationType); 28 | } 29 | 30 | public static String canBeUsedOnFieldOnly(Class annotationType) { 31 | return errorMessage("@%s can be used on fields only", annotationType); 32 | } 33 | 34 | private static String errorMessage(String format, Class annotationType) { 35 | return String.format(format, annotationType.getName()); 36 | } 37 | 38 | private ErrorMessages() {} 39 | } 40 | -------------------------------------------------------------------------------- /src/core/lombok/core/util/Names.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Created on Nov 30, 2010 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with 5 | * the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on 10 | * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the 11 | * specific language governing permissions and limitations under the License. 12 | * 13 | * Copyright @2010 the original author or authors. 14 | */ 15 | package lombok.core.util; 16 | 17 | import static java.lang.Character.*; 18 | import static lombok.core.util.Arrays.array; 19 | 20 | import java.beans.PropertyChangeListener; 21 | import java.beans.PropertyChangeSupport; 22 | 23 | /** 24 | * Utility methods related to names. 25 | * 26 | * @author Alex Ruiz 27 | */ 28 | public final class Names { 29 | 30 | /** Name of the field of type {@link PropertyChangeSupport}. */ 31 | public static final String PROPERTY_SUPPORT_FIELD_NAME = "propertySupport"; 32 | 33 | /** Name of the method "firePropertyChange" in {@link PropertyChangeSupport}. */ 34 | public static final String FIRE_PROPERTY_CHANGE_METHOD_NAME = "firePropertyChange"; 35 | 36 | /** Name of the method argument of type {@link PropertyChangeListener}. */ 37 | public static final String LISTENER_ARG_NAME = "listener"; 38 | 39 | /*** Name of the variable containing the "old" value of a field before it is changed in a setter. */ 40 | public static final String OLD_VALUE_VARIABLE_NAME = "old"; 41 | 42 | /** Names of the "*PropertyChangeListener" methods in {@link PropertyChangeSupport}. */ 43 | public static final String[] PROPERTY_CHANGE_METHOD_NAMES = array("addPropertyChangeListener", 44 | "removePropertyChangeListener"); 45 | 46 | /** 47 | * Splits the name of the class using "\." as the regular expression. For example, {@code java.lang.String} will be 48 | * split into { "java", "lang", "String" }. 49 | * @param type the given class. 50 | * @return the name of the type split using "\." as the regular expression. 51 | */ 52 | public static String[] splitNameOf(Class type) { 53 | return type.getName().split("\\."); 54 | } 55 | 56 | /** 57 | * Creates the name of the constant that holds the name of a property. For example, if the name of a property is 58 | * "firstName," this method will return "PROP_FIRST_NAME." 59 | * @param propertyName the name of the property. 60 | * @return the name of the constant that holds the name of a property. 61 | */ 62 | public static String nameOfConstantBasedOnProperty(String propertyName) { 63 | char[] chars = propertyName.toCharArray(); 64 | StringBuilder b = new StringBuilder(); 65 | b.append("PROP_"); 66 | int charCount = chars.length; 67 | for (int i = 0; i < charCount; i++) { 68 | char c = chars[i]; 69 | if (isUpperCase(c) && i > 0) b.append('_'); 70 | if (isLowerCase(c)) c = toUpperCase(c); 71 | b.append(c); 72 | } 73 | return b.toString(); 74 | } 75 | 76 | private Names() {} 77 | } 78 | -------------------------------------------------------------------------------- /src/eclipse/lombok/eclipse/handlers/BoundSetterHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Created on Dec 6, 2010 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with 5 | * the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on 10 | * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the 11 | * specific language governing permissions and limitations under the License. 12 | * 13 | * Copyright @2010 the original author or authors. 14 | */ 15 | package lombok.eclipse.handlers; 16 | 17 | import static java.lang.reflect.Modifier.*; 18 | import static lombok.core.handlers.TransformationsUtil.*; 19 | import static lombok.core.util.Arrays.*; 20 | import static lombok.core.util.AstGeneration.stopAstGeneration; 21 | import static lombok.core.util.ErrorMessages.canBeUsedOnFieldOnly; 22 | import static lombok.core.util.Names.*; 23 | import static lombok.eclipse.Eclipse.*; 24 | import static lombok.eclipse.handlers.Eclipse.*; 25 | import static lombok.eclipse.handlers.EclipseHandlerUtil.*; 26 | import static lombok.eclipse.handlers.FieldBuilder.newField; 27 | import static lombok.eclipse.handlers.Lombok.newFieldAccessor; 28 | import static lombok.eclipse.handlers.MemberChecks.*; 29 | import static lombok.eclipse.handlers.MethodBuilder.newMethod; 30 | import static org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants.AccStatic; 31 | 32 | import java.beans.PropertyChangeSupport; 33 | import java.util.ArrayList; 34 | import java.util.List; 35 | 36 | import lombok.*; 37 | import lombok.core.AnnotationValues; 38 | import lombok.eclipse.EclipseAnnotationHandler; 39 | import lombok.eclipse.EclipseNode; 40 | import lombok.javac.handlers.JavaBeanHandler; 41 | 42 | import org.eclipse.jdt.internal.compiler.ast.*; 43 | import org.mangosdk.spi.ProviderFor; 44 | 45 | 46 | /** 47 | * Generates a "bound" setter for a field annotated with {@link GenerateBoundSetter}. 48 | *

49 | * For example, given this class: 50 | * 51 | *

 52 |  * public class Person {
 53 |  *
 54 |  *   @GenerateBoundSetter private String firstName;
 55 |  * }
 56 |  * 
57 | * this annotation handler will generate the AST nodes that correspond to this code: 58 | * 59 | *
 60 |  * public class Person {
 61 |  *
 62 |  *   public static final String PROP_FIRST_NAME = "firstName";
 63 |  *
 64 |  *   private String firstName;
 65 |  *
 66 |  *   public void setFirstName(String value) {
 67 |  *      String oldValue = firstName;
 68 |  *      firstName = value;
 69 |  *      propertySupport.firePropertyChange(PROP_FIRST_NAME, oldValue, firstName);
 70 |  *   }
 71 |  * }
 72 |  * 
73 | *

74 | *

75 | * Note: This annotation handler assumes that the class declaring the annotated field has a field 76 | * of type {@link PropertyChangeSupport} with name "propertySupport." You can either add this expected 77 | * field manually or annotate the class with {@link GenerateJavaBean} to have 78 | * {@link JavaBeanHandler} generate it for you. 79 | *

80 | * 81 | * @author Alex Ruiz 82 | */ 83 | @ProviderFor(EclipseAnnotationHandler.class) 84 | public class BoundSetterHandler implements EclipseAnnotationHandler { 85 | 86 | private static final Class TARGET_ANNOTATION_TYPE = GenerateBoundSetter.class; 87 | 88 | /** 89 | * Called when an annotation is found that is likely to match {@link GenerateBoundSetter}. This is were 90 | * AST node generation happens. 91 | * @param annotation the actual annotation. 92 | * @param ast the Eclipse AST node representing the annotation. 93 | * @param astWrapper the lombok AST wrapper around {@code ast}. 94 | * @return {@code true} if this handler successfully handled {@code GenerateBoundSetter}; {@code false} otherwise. 95 | */ 96 | @Override 97 | public boolean handle(AnnotationValues annotation, Annotation ast, EclipseNode astWrapper) { 98 | List fields = new ArrayList(astWrapper.upFromAnnotationToFields()); 99 | EclipseNode mayBeField = astWrapper.up(); 100 | if (mayBeField == null) return false; 101 | if (!isField(mayBeField)) { 102 | astWrapper.addError(canBeUsedOnFieldOnly(TARGET_ANNOTATION_TYPE)); 103 | return true; 104 | } 105 | EclipseNode typeNode = findTypeNodeFrom(mayBeField); 106 | generateSetter(fields, annotation.getInstance(), typeNode); 107 | return true; 108 | } 109 | 110 | private EclipseNode findTypeNodeFrom(EclipseNode node) { 111 | EclipseNode n = node; 112 | while (n != null && !isTypeDeclaration(n)) n = n.up(); 113 | if (!isTypeDeclaration(n)) return null; 114 | return n; 115 | } 116 | 117 | private boolean isTypeDeclaration(EclipseNode node) { 118 | return node != null && node.get() instanceof TypeDeclaration; 119 | } 120 | 121 | private void generateSetter(List fields, GenerateBoundSetter setter, EclipseNode typeNode) { 122 | for (EclipseNode fieldNode : fields) { 123 | String propertyNameFieldName = nameOfConstantBasedOnProperty(fieldNode.getName()); 124 | generatePropertyNameConstant(propertyNameFieldName, fieldNode, typeNode); 125 | generateSetter(propertyNameFieldName, setter, fieldNode); 126 | } 127 | } 128 | 129 | private void generatePropertyNameConstant(String propertyNameFieldName, EclipseNode fieldNode, EclipseNode typeNode) { 130 | // generates: 131 | // public static final String PROP_FIRST_NAME = "firstName"; 132 | String propertyName = fieldNode.getName(); 133 | if (fieldAlreadyExists(propertyNameFieldName, fieldNode)) return; 134 | Expression propertyNameExpression = stringLiteral(propertyName, typeNode.get()); 135 | FieldDeclaration fieldDecl = newField().ofType(String.class) 136 | .withName(propertyNameFieldName) 137 | .withModifiers(PUBLIC | STATIC | FINAL) 138 | .withArgs(propertyNameExpression) 139 | .buildWith(typeNode); 140 | injectField(typeNode, fieldDecl); 141 | } 142 | 143 | private void generateSetter(String propertyNameFieldName, GenerateBoundSetter setter, EclipseNode fieldNode) { 144 | AccessLevel accessLevel = setter.value(); 145 | if (stopAstGeneration(accessLevel)) return; 146 | String setterName = toSetterName(fieldNode.getName()); 147 | if (methodAlreadyExists(setterName, fieldNode)) return; 148 | injectMethod(fieldNode.up(), createSetterDecl(accessLevel, propertyNameFieldName, setterName, fieldNode)); 149 | } 150 | 151 | private MethodDeclaration createSetterDecl(AccessLevel accessLevel, String propertyNameFieldName, String setterName, 152 | EclipseNode fieldNode) { 153 | // public void setFirstName(String value) { 154 | // final String oldValue = firstName; 155 | // firstName = value; 156 | // propertySupport.firePropertyChange(PROP_FIRST_NAME, oldValue, firstName); 157 | // } 158 | FieldDeclaration fieldDecl = (FieldDeclaration) fieldNode.get(); 159 | int accessModifiers = toEclipseModifier(accessLevel)| (fieldDecl.modifiers & AccStatic); 160 | Annotation[] nonNulls = findAnnotations(fieldDecl, NON_NULL_PATTERN); 161 | return newMethod().withModifiers(accessModifiers) 162 | .withName(setterName) 163 | .withReturnType(voidType(fieldNode.get())) 164 | .withParameters(parameters(nonNulls, fieldNode)) 165 | .withBody(body(propertyNameFieldName, fieldNode)) 166 | .buildWith(fieldNode); 167 | } 168 | 169 | private Argument[] parameters(Annotation[] nonNulls, EclipseNode fieldNode) { 170 | FieldDeclaration fieldDecl = (FieldDeclaration) fieldNode.get(); 171 | ASTNode source = fieldNode.get(); 172 | Argument param = argument(fieldDecl.name, copyType(fieldDecl.type, source), 0, source); 173 | Annotation[] copied = copyAnnotations(source, nonNulls); 174 | if (isNotEmpty(copied)) param.annotations = copied; 175 | return array(param); 176 | } 177 | 178 | private Statement[] body(String propertyNameFieldName, EclipseNode fieldNode) { 179 | char[] oldValueName = OLD_VALUE_VARIABLE_NAME.toCharArray(); 180 | Statement[] statements = new Statement[3]; 181 | statements[0] = oldValueVariableDecl(oldValueName, fieldNode); 182 | statements[1] = assignNewValueToFieldDecl(fieldNode); 183 | statements[2] = fireChangeEventMethodDecl(propertyNameFieldName, oldValueName, fieldNode); 184 | return statements; 185 | } 186 | 187 | private Statement oldValueVariableDecl(char[] oldValueName, EclipseNode fieldNode) { 188 | FieldDeclaration varDecl = (FieldDeclaration) fieldNode.get(); 189 | Expression fieldRef = newFieldAccessor(fieldNode); 190 | return localDeclaration(oldValueName, varDecl.type, fieldRef, fieldNode.get()); 191 | } 192 | 193 | private Statement assignNewValueToFieldDecl(EclipseNode fieldNode) { 194 | ASTNode source = fieldNode.get(); 195 | Expression fieldRef = newFieldAccessor(fieldNode); 196 | Expression name = singleNameReference(fieldNode.getName(), source); 197 | return assignment(fieldRef, name, source); 198 | } 199 | 200 | private Statement fireChangeEventMethodDecl(String propertyNameFieldName, char[] oldValueName, EclipseNode fieldNode) { 201 | ASTNode source = fieldNode.get(); 202 | MessageSend fn = messageSend(source); 203 | fn.receiver = singleNameReference(PROPERTY_SUPPORT_FIELD_NAME, source); 204 | fn.selector = FIRE_PROPERTY_CHANGE_METHOD_NAME.toCharArray(); 205 | List arguments = new ArrayList(); 206 | arguments.add(singleNameReference(propertyNameFieldName, source)); 207 | arguments.add(singleNameReference(oldValueName, source)); 208 | arguments.add(newFieldAccessor(fieldNode)); 209 | fn.arguments = arguments.toArray(new Expression[arguments.size()]); 210 | return fn; 211 | } 212 | } 213 | -------------------------------------------------------------------------------- /src/eclipse/lombok/eclipse/handlers/Eclipse.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Created on Dec 6, 2010 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with 5 | * the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on 10 | * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the 11 | * specific language governing permissions and limitations under the License. 12 | * 13 | * Copyright @2010 the original author or authors. 14 | */ 15 | package lombok.eclipse.handlers; 16 | 17 | import static lombok.eclipse.Eclipse.*; 18 | import static org.eclipse.jdt.internal.compiler.ast.TypeReference.baseTypeReference; 19 | import static org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants.AccFinal; 20 | import static org.eclipse.jdt.internal.compiler.lookup.TypeIds.T_void; 21 | 22 | import org.eclipse.jdt.internal.compiler.CompilationResult; 23 | import org.eclipse.jdt.internal.compiler.ast.*; 24 | 25 | /** 26 | * @author Alex Ruiz 27 | */ 28 | final class Eclipse { 29 | 30 | static Argument argument(char[] name, TypeReference tr, int modifiers, ASTNode source) { 31 | Argument argument = new Argument(name, posNom(source), tr, modifiers); 32 | copySourceStartAndEnt(source, argument); 33 | setGeneratedBy(argument, source); 34 | return argument; 35 | } 36 | 37 | static Assignment assignment(Expression lhs, Expression expression, ASTNode source) { 38 | Assignment assignment = new Assignment(lhs, expression, (int)posNom(source)); 39 | copySourceStartAndEnt(source, assignment); 40 | setGeneratedBy(assignment, source); 41 | return assignment; 42 | } 43 | 44 | static LocalDeclaration localDeclaration(char[] name, TypeReference type, Expression initializer, ASTNode source) { 45 | LocalDeclaration decl = new LocalDeclaration(name, source.sourceStart, source.sourceEnd); 46 | decl.modifiers |= AccFinal; 47 | setGeneratedBy(decl, source); 48 | decl.type = copyType(type, source); 49 | setGeneratedBy(decl.type, source); 50 | decl.initialization = initializer; 51 | setGeneratedBy(decl.initialization, source); 52 | return decl; 53 | } 54 | 55 | static MessageSend messageSend(ASTNode source) { 56 | MessageSend messageSend = new MessageSend(); 57 | copySourceStartAndEnt(source, messageSend); 58 | setGeneratedBy(messageSend, source); 59 | return messageSend; 60 | } 61 | 62 | static MethodDeclaration methodDeclaration(CompilationResult compilationResult, ASTNode source) { 63 | MethodDeclaration method = new MethodDeclaration(compilationResult); 64 | copySourceStartAndEnt(source, method); 65 | setGeneratedBy(method, source); 66 | return method; 67 | } 68 | 69 | static TypeReference qualifiedTypeReference(Class type, ASTNode source) { 70 | long p = posNom(source); 71 | return new QualifiedTypeReference(fromQualifiedName(type.getName()), new long[] { p, p, p }); 72 | } 73 | 74 | static Expression referenceForThis(ASTNode source) { 75 | return new ThisReference(source.sourceStart(), source.sourceEnd()); 76 | } 77 | 78 | static Expression singleNameReference(String name, ASTNode source) { 79 | return singleNameReference(name.toCharArray(), source); 80 | } 81 | 82 | static Expression singleNameReference(char[] name, ASTNode source) { 83 | long pos = posNom(source); 84 | return singleNameReference(name, source, pos); 85 | } 86 | 87 | static Expression singleNameReference(char[] name, ASTNode source, long pos) { 88 | SingleNameReference ref = new SingleNameReference(name, pos); 89 | setGeneratedBy(ref, source); 90 | return ref; 91 | } 92 | 93 | private static long posNom(ASTNode source) { 94 | return (long) source.sourceStart << 32 | source.sourceEnd; 95 | } 96 | 97 | static Expression stringLiteral(String s, ASTNode source) { 98 | StringLiteral string = new StringLiteral(s.toCharArray(), source.sourceStart, source.sourceEnd, 0); 99 | setGeneratedBy(string, source); 100 | return string; 101 | } 102 | 103 | static TypeReference voidType(ASTNode source) { 104 | TypeReference type = baseTypeReference(T_void, 0); 105 | copySourceStartAndEnt(source, type); 106 | return type; 107 | } 108 | 109 | private static void copySourceStartAndEnt(ASTNode from, ASTNode to) { 110 | to.sourceStart = from.sourceStart; 111 | to.sourceEnd = from.sourceEnd; 112 | } 113 | 114 | private Eclipse() {} 115 | } 116 | -------------------------------------------------------------------------------- /src/eclipse/lombok/eclipse/handlers/FieldBuilder.java: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | * Created on Dec 6, 2010 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with 6 | * the License. You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on 11 | * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the 12 | * specific language governing permissions and limitations under the License. 13 | * 14 | * Copyright @2010 the original author or authors. 15 | */ 16 | package lombok.eclipse.handlers; 17 | 18 | import static lombok.core.util.Arrays.copy; 19 | import static lombok.eclipse.Eclipse.setGeneratedBy; 20 | import static lombok.eclipse.handlers.Eclipse.qualifiedTypeReference; 21 | import lombok.eclipse.EclipseNode; 22 | 23 | import org.eclipse.jdt.internal.compiler.ast.*; 24 | 25 | /** 26 | * Utility methods related to generation of fields. 27 | * 28 | * @author Alex Ruiz 29 | */ 30 | final class FieldBuilder { 31 | 32 | private static final Expression[] NO_ARGS = new Expression[0]; 33 | 34 | static FieldBuilder newField() { 35 | return new FieldBuilder(); 36 | } 37 | 38 | private Class type; 39 | private String name; 40 | private int modifiers; 41 | private Expression[] args = NO_ARGS; 42 | 43 | FieldBuilder ofType(Class newType) { 44 | type = newType; 45 | return this; 46 | } 47 | 48 | FieldBuilder withName(String newName) { 49 | name = newName; 50 | return this; 51 | } 52 | 53 | FieldBuilder withModifiers(int newModifiers) { 54 | modifiers = newModifiers; 55 | return this; 56 | } 57 | 58 | FieldBuilder withArgs(Expression...newArgs) { 59 | args = copy(newArgs); 60 | return this; 61 | } 62 | 63 | FieldDeclaration buildWith(EclipseNode node) { 64 | ASTNode source = node.get(); 65 | FieldDeclaration fieldDecl = new FieldDeclaration(name.toCharArray(), source.sourceStart, source.sourceEnd); 66 | setGeneratedBy(fieldDecl, source); 67 | fieldDecl.declarationSourceEnd = -1; 68 | fieldDecl.modifiers = modifiers; 69 | fieldDecl.type = qualifiedTypeReference(type, source); 70 | AllocationExpression init = new AllocationExpression(); 71 | setGeneratedBy(init, source); 72 | init.type = qualifiedTypeReference(type, source); 73 | init.arguments = args; 74 | fieldDecl.initialization = init; 75 | return fieldDecl; 76 | } 77 | 78 | private FieldBuilder() {} 79 | } 80 | -------------------------------------------------------------------------------- /src/eclipse/lombok/eclipse/handlers/JavaBeanHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Created on Dec 8, 2010 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with 5 | * the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on 10 | * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the 11 | * specific language governing permissions and limitations under the License. 12 | * 13 | * Copyright @2010 the original author or authors. 14 | */ 15 | package lombok.eclipse.handlers; 16 | 17 | import static java.lang.reflect.Modifier.*; 18 | import static lombok.core.util.Arrays.array; 19 | import static lombok.core.util.ErrorMessages.canBeUsedOnClassOnly; 20 | import static lombok.core.util.Names.*; 21 | import static lombok.eclipse.handlers.Eclipse.*; 22 | import static lombok.eclipse.handlers.EclipseHandlerUtil.*; 23 | import static lombok.eclipse.handlers.FieldBuilder.newField; 24 | import static lombok.eclipse.handlers.MemberChecks.*; 25 | import static lombok.eclipse.handlers.MethodBuilder.newMethod; 26 | 27 | import java.beans.*; 28 | 29 | import lombok.GenerateJavaBean; 30 | import lombok.core.AnnotationValues; 31 | import lombok.eclipse.*; 32 | 33 | import org.eclipse.jdt.internal.compiler.ast.*; 34 | import org.eclipse.jdt.internal.compiler.ast.Statement; 35 | import org.mangosdk.spi.ProviderFor; 36 | 37 | 38 | /** 39 | * Generates basic support for making a class annotated with {@link GenerateJavaBean} a JavaBean. 40 | *

41 | * "Basic" JavaBean support means: 42 | *

    43 | *
  1. Generates a field of type {@link PropertyChangeSupport} with name "propertySupport"
  2. 44 | *
  3. Generates the public method {@code addPropertyChangeListener(PropertyChangeListener)} and 45 | * {@code removePropertyChangeListener(PropertyChangeListener)}
  4. 46 | *
  5. 47 | *
48 | *

49 | *

50 | * For example, given this class: 51 | * 52 | *

 53 |  * @GenerateJavaBean
 54 |  * public class Person {
 55 |  *
 56 |  * }
 57 |  * 
58 | * this annotation handler will generate the AST nodes that correspond to this code: 59 | * 60 | *
 61 |  * public class Person {
 62 |  *
 63 |  *   private PropertyChangeSupport propertySupport = new PropertyChangeSupport(this);
 64 | 
 65 |  *   public void addPropertyChangeListener(PropertyChangeListener listener) {
 66 |  *     propertySupport.addPropertyChangeListener(listener);
 67 |  *   }
 68 |  *
 69 |  *   public void removePropertyChangeListener(PropertyChangeListener listener) {
 70 |  *     propertySupport.removePropertyChangeListener(listener);
 71 |  *   }
 72 |  * }
 73 |  * 
74 | *

75 | * 76 | * @author Alex Ruiz 77 | */ 78 | @ProviderFor(EclipseAnnotationHandler.class) 79 | public class JavaBeanHandler implements EclipseAnnotationHandler { 80 | 81 | private static final Class TARGET_ANNOTATION_TYPE = GenerateJavaBean.class; 82 | 83 | /** 84 | * Called when an annotation is found that is likely to match {@link GenerateJavaBean}. This is were AST 85 | * node generation happens. 86 | * @param annotation the actual annotation. 87 | * @param ast the Eclipse AST node representing the annotation. 88 | * @param astWrapper the lombok AST wrapper around {@code ast}. 89 | * @return {@code true} if this handler successfully handled {@code GenerateJavaBean}; {@code false} otherwise. 90 | */ 91 | @Override 92 | public boolean handle(AnnotationValues annotation, Annotation ast, EclipseNode astWrapper) { 93 | EclipseNode typeNode = astWrapper.up(); 94 | if (typeNode == null) return false; 95 | if (!isClass(typeNode)) { 96 | astWrapper.addError(canBeUsedOnClassOnly(TARGET_ANNOTATION_TYPE)); 97 | return true; 98 | } 99 | generatePropertyChangeSupportField(typeNode); 100 | generateChangeListenerMethods(typeNode); 101 | return true; 102 | } 103 | 104 | private void generatePropertyChangeSupportField(EclipseNode typeNode) { 105 | if (fieldAlreadyExists(PROPERTY_SUPPORT_FIELD_NAME, typeNode)) return; 106 | FieldDeclaration fieldDecl = newField().ofType(PropertyChangeSupport.class) 107 | .withName(PROPERTY_SUPPORT_FIELD_NAME) 108 | .withModifiers(PRIVATE | FINAL) 109 | .withArgs(referenceForThis(typeNode.get())) 110 | .buildWith(typeNode); 111 | injectField(typeNode, fieldDecl); 112 | } 113 | 114 | private void generateChangeListenerMethods(EclipseNode typeNode) { 115 | for (String methodName : PROPERTY_CHANGE_METHOD_NAMES) 116 | generateChangeListenerMethod(methodName, typeNode); 117 | } 118 | 119 | private void generateChangeListenerMethod(String methodName, EclipseNode typeNode) { 120 | MethodDeclaration methodDecl = newMethod().withModifiers(PUBLIC) 121 | .withName(methodName) 122 | .withReturnType(voidType(typeNode.get())) 123 | .withParameters(parameters(typeNode)) 124 | .withBody(body(methodName, typeNode)) 125 | .buildWith(typeNode); 126 | injectMethod(typeNode, methodDecl); 127 | } 128 | 129 | private Argument[] parameters(EclipseNode typeNode) { 130 | ASTNode source = typeNode.get(); 131 | TypeReference type = qualifiedTypeReference(PropertyChangeListener.class, source); 132 | Argument parameter = argument(LISTENER_ARG_NAME.toCharArray(), type, FINAL, source); 133 | return array(parameter); 134 | } 135 | 136 | private Statement[] body(String methodName, EclipseNode typeNode) { 137 | return array(delegateToPropertySupport(methodName, typeNode)); 138 | } 139 | 140 | private Statement delegateToPropertySupport(String methodName, EclipseNode typeNode) { 141 | ASTNode source = typeNode.get(); 142 | MessageSend fn = messageSend(source); 143 | fn.receiver = singleNameReference(PROPERTY_SUPPORT_FIELD_NAME.toCharArray(), source, 0); 144 | fn.selector = methodName.toCharArray(); 145 | fn.arguments = array(singleNameReference(LISTENER_ARG_NAME, source)); 146 | return fn; 147 | } 148 | } 149 | -------------------------------------------------------------------------------- /src/eclipse/lombok/eclipse/handlers/Lombok.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Created on Dec 7, 2010 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with 5 | * the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on 10 | * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the 11 | * specific language governing permissions and limitations under the License. 12 | * 13 | * Copyright @2010 the original author or authors. 14 | */ 15 | package lombok.eclipse.handlers; 16 | 17 | import static lombok.eclipse.handlers.EclipseHandlerUtil.createFieldAccessor; 18 | import static lombok.eclipse.handlers.EclipseHandlerUtil.FieldAccess.ALWAYS_FIELD; 19 | import lombok.eclipse.EclipseNode; 20 | 21 | import org.eclipse.jdt.internal.compiler.ast.Expression; 22 | 23 | /** 24 | * @author Alex Ruiz 25 | */ 26 | public final class Lombok { 27 | 28 | static Expression newFieldAccessor(EclipseNode fieldNode) { 29 | return createFieldAccessor(fieldNode, ALWAYS_FIELD, fieldNode.get()); 30 | } 31 | 32 | private Lombok() {} 33 | } 34 | -------------------------------------------------------------------------------- /src/eclipse/lombok/eclipse/handlers/MemberChecks.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Created on Dec 6, 2010 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with 5 | * the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on 10 | * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the 11 | * specific language governing permissions and limitations under the License. 12 | * 13 | * Copyright @2010 the original author or authors. 14 | */ 15 | package lombok.eclipse.handlers; 16 | 17 | import static lombok.core.AST.Kind.FIELD; 18 | import static org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants.*; 19 | 20 | import static lombok.eclipse.handlers.EclipseHandlerUtil.*; 21 | import static lombok.eclipse.handlers.EclipseHandlerUtil.MemberExistsResult.NOT_EXISTS; 22 | import lombok.eclipse.EclipseNode; 23 | import lombok.eclipse.handlers.EclipseHandlerUtil.MemberExistsResult; 24 | 25 | import org.eclipse.jdt.internal.compiler.ast.*; 26 | 27 | /** 28 | * @author Alex Ruiz 29 | */ 30 | final class MemberChecks { 31 | 32 | static boolean isClass(EclipseNode node) { 33 | ASTNode astNode = node.get(); 34 | if (!(astNode instanceof TypeDeclaration)) return false; 35 | TypeDeclaration classDecl = (TypeDeclaration) astNode; 36 | return (classDecl.modifiers & (AccInterface | AccAnnotation | AccEnum)) == 0; 37 | } 38 | 39 | static boolean isField(EclipseNode node) { 40 | return FIELD.equals(node.getKind()); 41 | } 42 | 43 | static boolean fieldAlreadyExists(String fieldName, EclipseNode node) { 44 | return existsYesOrNo(fieldExists(fieldName, node)); 45 | } 46 | 47 | static boolean methodAlreadyExists(String methodName, EclipseNode node) { 48 | return existsYesOrNo(methodExists(methodName, node)); 49 | } 50 | 51 | private static boolean existsYesOrNo(MemberExistsResult result) { 52 | return !result.equals(NOT_EXISTS); 53 | } 54 | 55 | private MemberChecks() {} 56 | } 57 | -------------------------------------------------------------------------------- /src/eclipse/lombok/eclipse/handlers/MethodBuilder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Created on Dec 6, 2010 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with 5 | * the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on 10 | * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the 11 | * specific language governing permissions and limitations under the License. 12 | * 13 | * Copyright @2010 the original author or authors. 14 | */ 15 | package lombok.eclipse.handlers; 16 | 17 | import static lombok.core.util.Arrays.*; 18 | import static lombok.eclipse.Eclipse.ECLIPSE_DO_NOT_TOUCH_FLAG; 19 | import static lombok.eclipse.handlers.Eclipse.methodDeclaration; 20 | import static lombok.eclipse.handlers.MemberChecks.isField; 21 | import lombok.eclipse.EclipseNode; 22 | 23 | import org.eclipse.jdt.internal.compiler.ast.*; 24 | 25 | /** 26 | * Simplifies creation of methods. 27 | * 28 | * @author Alex Ruiz 29 | */ 30 | class MethodBuilder { 31 | 32 | static MethodBuilder newMethod() { 33 | return new MethodBuilder(); 34 | } 35 | 36 | private int modifiers; 37 | private char[] name; 38 | private TypeReference returnType; 39 | private Argument[] parameters; 40 | private TypeReference[] throwsClauses; 41 | private Annotation[] annotations; 42 | private Statement[] body; 43 | 44 | private MethodBuilder() {} 45 | 46 | MethodBuilder withModifiers(int newModifiers) { 47 | modifiers = newModifiers; 48 | return this; 49 | } 50 | 51 | MethodBuilder withName(String newName) { 52 | name = newName.toCharArray(); 53 | return this; 54 | } 55 | 56 | MethodBuilder withReturnType(TypeReference newReturnType) { 57 | returnType = newReturnType; 58 | return this; 59 | } 60 | 61 | MethodBuilder withParameters(Argument[] newParameters) { 62 | parameters = copy(newParameters); 63 | return this; 64 | } 65 | 66 | MethodBuilder withThrowsClauses(TypeReference[] newThrowsClauses) { 67 | throwsClauses = copy(newThrowsClauses); 68 | return this; 69 | } 70 | 71 | MethodBuilder withBody(Statement[] newBody) { 72 | body = copy(newBody); 73 | return this; 74 | } 75 | 76 | MethodBuilder withAnnotations(Annotation[] newAnnotations) { 77 | annotations = copy(newAnnotations); 78 | return this; 79 | } 80 | 81 | MethodDeclaration buildWith(EclipseNode node) { 82 | TypeDeclaration parent = parentOf(node); 83 | ASTNode source = node.get(); 84 | MethodDeclaration method = methodDeclaration(parent.compilationResult, source); 85 | method.modifiers = modifiers; 86 | method.returnType = returnType; 87 | method.arguments = parameters; 88 | method.selector = name; 89 | method.thrownExceptions = throwsClauses; 90 | method.bits |= ECLIPSE_DO_NOT_TOUCH_FLAG; 91 | method.bodyStart = method.declarationSourceStart = method.sourceStart; 92 | method.bodyEnd = method.declarationSourceEnd = method.sourceEnd; 93 | method.statements = body; 94 | if (isNotEmpty(annotations)) method.annotations = annotations; 95 | return method; 96 | } 97 | 98 | private TypeDeclaration parentOf(EclipseNode node) { 99 | if (isField(node)) return (TypeDeclaration) node.up().get(); 100 | for (EclipseNode child : node.down()) 101 | if (isField(child)) return parentOf(child); 102 | throw new IllegalStateException(String.format("Unable to find type declaration for %s", node)); 103 | } 104 | } 105 | -------------------------------------------------------------------------------- /src/javac/lombok/javac/handlers/BoundSetterHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Created on Nov 30, 2010 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with 5 | * the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on 10 | * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the 11 | * specific language governing permissions and limitations under the License. 12 | * 13 | * Copyright @2010 the original author or authors. 14 | */ 15 | package lombok.javac.handlers; 16 | 17 | import static com.sun.tools.javac.code.Flags.*; 18 | import static lombok.core.handlers.TransformationsUtil.*; 19 | import static lombok.core.util.AstGeneration.stopAstGeneration; 20 | import static lombok.core.util.ErrorMessages.canBeUsedOnFieldOnly; 21 | import static lombok.core.util.Names.*; 22 | import static lombok.javac.handlers.FieldBuilder.newField; 23 | import static lombok.javac.handlers.JCNoType.voidType; 24 | import static lombok.javac.handlers.JavacHandlerUtil.*; 25 | import static lombok.javac.handlers.Lombok.newFieldAccessor; 26 | import static lombok.javac.handlers.MemberChecks.*; 27 | import static lombok.javac.handlers.MethodBuilder.newMethod; 28 | 29 | import java.beans.PropertyChangeSupport; 30 | import java.util.Collection; 31 | 32 | import lombok.*; 33 | import lombok.core.AnnotationValues; 34 | import lombok.javac.JavacAnnotationHandler; 35 | import lombok.javac.JavacNode; 36 | 37 | import org.mangosdk.spi.ProviderFor; 38 | 39 | import com.sun.tools.javac.tree.JCTree.JCAnnotation; 40 | import com.sun.tools.javac.tree.JCTree.JCAssign; 41 | import com.sun.tools.javac.tree.JCTree.JCBlock; 42 | import com.sun.tools.javac.tree.JCTree.JCClassDecl; 43 | import com.sun.tools.javac.tree.JCTree.JCExpression; 44 | import com.sun.tools.javac.tree.JCTree.JCMethodDecl; 45 | import com.sun.tools.javac.tree.JCTree.JCMethodInvocation; 46 | import com.sun.tools.javac.tree.JCTree.JCStatement; 47 | import com.sun.tools.javac.tree.JCTree.JCVariableDecl; 48 | import com.sun.tools.javac.tree.*; 49 | import com.sun.tools.javac.util.List; 50 | import com.sun.tools.javac.util.Name; 51 | 52 | /** 53 | * Generates a "bound" setter for a field annotated with {@link GenerateBoundSetter}. 54 | *

55 | * For example, given this class: 56 | * 57 | *

 58 |  * public class Person {
 59 |  *
 60 |  *   @GenerateBoundSetter private String firstName;
 61 |  * }
 62 |  * 
63 | * this annotation handler will generate the AST nodes that correspond to this code: 64 | * 65 | *
 66 |  * public class Person {
 67 |  *
 68 |  *   public static final String PROP_FIRST_NAME = "firstName";
 69 |  *
 70 |  *   private String firstName;
 71 |  *
 72 |  *   public void setFirstName(String value) {
 73 |  *      String oldValue = firstName;
 74 |  *      firstName = value;
 75 |  *      propertySupport.firePropertyChange(PROP_FIRST_NAME, oldValue, firstName);
 76 |  *   }
 77 |  * }
 78 |  * 
79 | *

80 | *

81 | * Note: This annotation handler assumes that the class declaring the annotated field has a field 82 | * of type {@link PropertyChangeSupport} with name "propertySupport." You can either add this expected 83 | * field manually or annotate the class with {@link GenerateJavaBean} to have 84 | * {@link JavaBeanHandler} generate it for you. 85 | *

86 | * 87 | * @author Alex Ruiz 88 | */ 89 | @ProviderFor(JavacAnnotationHandler.class) 90 | public class BoundSetterHandler implements JavacAnnotationHandler { 91 | 92 | private static final Class TARGET_ANNOTATION_TYPE = GenerateBoundSetter.class; 93 | 94 | /** 95 | * Called when an annotation is found that is likely to match {@link GenerateBoundSetter}. This is were 96 | * AST node generation happens. 97 | * @param annotation the actual annotation. 98 | * @param ast the javac AST node representing the annotation. 99 | * @param astWrapper the lombok AST wrapper around {@code ast}. 100 | * @return {@code true} if this handler successfully handled {@code GenerateBoundSetter}; {@code false} otherwise. 101 | */ 102 | @Override 103 | public boolean handle(AnnotationValues annotation, JCAnnotation ast, JavacNode astWrapper) { 104 | Collection fields = astWrapper.upFromAnnotationToFields(); 105 | markAnnotationAsProcessed(astWrapper, TARGET_ANNOTATION_TYPE); 106 | deleteImportFromCompilationUnit(astWrapper, AccessLevel.class.getName()); 107 | JavacNode mayBeField = astWrapper.up(); 108 | if (mayBeField == null) return false; 109 | if (!isField(mayBeField)) { 110 | astWrapper.addError(canBeUsedOnFieldOnly(TARGET_ANNOTATION_TYPE)); 111 | return true; 112 | } 113 | JavacNode typeNode = findTypeNodeFrom(mayBeField); 114 | generateSetter(fields, annotation.getInstance(), typeNode); 115 | return true; 116 | } 117 | 118 | private JavacNode findTypeNodeFrom(JavacNode node) { 119 | JavacNode n = node; 120 | while (n != null && !isTypeDeclaration(n)) n = n.up(); 121 | if (!isTypeDeclaration(n)) return null; 122 | return n; 123 | } 124 | 125 | private boolean isTypeDeclaration(JavacNode node) { 126 | return node != null && node.get() instanceof JCClassDecl; 127 | } 128 | 129 | private void generateSetter(Collection fields, GenerateBoundSetter setter, JavacNode typeNode) { 130 | for (JavacNode fieldNode : fields) { 131 | String propertyNameFieldName = nameOfConstantBasedOnProperty(fieldNode.getName()); 132 | generatePropertyNameConstant(propertyNameFieldName, fieldNode, typeNode); 133 | generateSetter(propertyNameFieldName, setter, fieldNode); 134 | } 135 | } 136 | 137 | private void generatePropertyNameConstant(String propertyNameFieldName, JavacNode fieldNode, JavacNode typeNode) { 138 | // generates: 139 | // public static final String PROP_FIRST_NAME = "firstName"; 140 | String propertyName = fieldNode.getName(); 141 | if (fieldAlreadyExists(propertyNameFieldName, fieldNode)) return; 142 | JCExpression propertyNameExpression = fieldNode.getTreeMaker().Literal(propertyName); 143 | JCVariableDecl fieldDecl = newField().ofType(String.class) 144 | .withName(propertyNameFieldName) 145 | .withModifiers(PUBLIC | STATIC | FINAL) 146 | .withArgs(propertyNameExpression) 147 | .buildWith(typeNode); 148 | injectField(typeNode, fieldDecl); 149 | } 150 | 151 | private void generateSetter(String propertyNameFieldName, GenerateBoundSetter setter, JavacNode fieldNode) { 152 | AccessLevel accessLevel = setter.value(); 153 | if (stopAstGeneration(accessLevel)) return; 154 | String setterName = toSetterName(fieldNode.getName()); 155 | if (methodAlreadyExists(setterName, fieldNode)) return; 156 | injectMethod(fieldNode.up(), createSetterDecl(accessLevel, propertyNameFieldName, setterName, fieldNode)); 157 | } 158 | 159 | private JCMethodDecl createSetterDecl(AccessLevel accessLevel, String propertyNameFieldName, String setterName, 160 | JavacNode fieldNode) { 161 | // public void setFirstName(String value) { 162 | // final String oldValue = firstName; 163 | // firstName = value; 164 | // propertySupport.firePropertyChange(PROP_FIRST_NAME, oldValue, firstName); 165 | // } 166 | JCVariableDecl fieldDecl = (JCVariableDecl) fieldNode.get(); 167 | long accessModifiers = toJavacModifier(accessLevel) | (fieldDecl.mods.flags & STATIC); 168 | TreeMaker treeMaker = fieldNode.getTreeMaker(); 169 | List nonNulls = findAnnotations(fieldNode, NON_NULL_PATTERN); 170 | return newMethod().withModifiers(accessModifiers) 171 | .withName(setterName) 172 | .withReturnType(treeMaker.Type(voidType())) 173 | .withParameters(parameters(nonNulls, fieldNode)) 174 | .withBody(body(propertyNameFieldName, fieldNode)) 175 | .buildWith(fieldNode); 176 | } 177 | 178 | private List parameters(List nonNulls, JavacNode fieldNode) { 179 | JCVariableDecl fieldDecl = (JCVariableDecl) fieldNode.get(); 180 | TreeMaker treeMaker = fieldNode.getTreeMaker(); 181 | JCVariableDecl param = treeMaker.VarDef(treeMaker.Modifiers(0, nonNulls), fieldDecl.name, fieldDecl.vartype, null); 182 | return List.of(param); 183 | } 184 | 185 | private JCBlock body(String propertyNameFieldName, JavacNode fieldNode) { 186 | Name oldValueName = fieldNode.toName(OLD_VALUE_VARIABLE_NAME); 187 | JCStatement[] statements = new JCStatement[3]; 188 | statements[0] = oldValueVariableDecl(oldValueName, fieldNode); 189 | statements[1] = assignNewValueToFieldDecl(fieldNode); 190 | statements[2] = fireChangeEventMethodDecl(propertyNameFieldName, oldValueName, fieldNode); 191 | return fieldNode.getTreeMaker().Block(0, List.from(statements)); 192 | } 193 | 194 | private JCStatement oldValueVariableDecl(Name oldValueName, JavacNode fieldNode) { 195 | TreeMaker treeMaker = fieldNode.getTreeMaker(); 196 | JCVariableDecl varDecl = (JCVariableDecl) fieldNode.get(); 197 | JCExpression init = newFieldAccessor(fieldNode); 198 | return treeMaker.VarDef(treeMaker.Modifiers(FINAL), oldValueName, varDecl.vartype, init); 199 | } 200 | 201 | private JCStatement assignNewValueToFieldDecl(JavacNode fieldNode) { 202 | JCVariableDecl fieldDecl = (JCVariableDecl) fieldNode.get(); 203 | TreeMaker treeMaker = fieldNode.getTreeMaker(); 204 | JCExpression fieldRef = newFieldAccessor(fieldNode); 205 | JCAssign assign = treeMaker.Assign(fieldRef, treeMaker.Ident(fieldDecl.name)); 206 | return treeMaker.Exec(assign); 207 | } 208 | 209 | private JCStatement fireChangeEventMethodDecl(String propertyNameFieldName, Name oldValueName, JavacNode fieldNode) { 210 | TreeMaker treeMaker = fieldNode.getTreeMaker(); 211 | JCExpression fn = chainDots(treeMaker, fieldNode, PROPERTY_SUPPORT_FIELD_NAME, FIRE_PROPERTY_CHANGE_METHOD_NAME); 212 | List args = List. of(treeMaker.Ident(fieldNode.toName(propertyNameFieldName)), 213 | treeMaker.Ident(oldValueName), 214 | newFieldAccessor(fieldNode)); 215 | JCMethodInvocation m = treeMaker.Apply(List. nil(), fn, args); 216 | return treeMaker.Exec(m); 217 | } 218 | 219 | /** 220 | * Indicates whether this handler requires resolution. 221 | * @return {@code false}. 222 | */ 223 | @Override public boolean isResolutionBased() { 224 | return false; 225 | } 226 | } 227 | -------------------------------------------------------------------------------- /src/javac/lombok/javac/handlers/FieldBuilder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Created on Nov 30, 2010 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with 5 | * the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on 10 | * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the 11 | * specific language governing permissions and limitations under the License. 12 | * 13 | * Copyright @2010 the original author or authors. 14 | */ 15 | package lombok.javac.handlers; 16 | 17 | import static com.sun.tools.javac.util.List.nil; 18 | import static lombok.core.util.Names.splitNameOf; 19 | import static lombok.javac.handlers.JavacHandlerUtil.chainDots; 20 | import lombok.javac.JavacNode; 21 | 22 | import com.sun.tools.javac.tree.JCTree.JCExpression; 23 | import com.sun.tools.javac.tree.JCTree.JCVariableDecl; 24 | import com.sun.tools.javac.tree.*; 25 | import com.sun.tools.javac.util.List; 26 | 27 | /** 28 | * Simplifies creation of fields. 29 | * 30 | * @author Alex Ruiz 31 | */ 32 | class FieldBuilder { 33 | 34 | static FieldBuilder newField() { 35 | return new FieldBuilder(); 36 | } 37 | 38 | private Class type; 39 | private String name; 40 | private long modifiers; 41 | private List args = nil(); 42 | 43 | FieldBuilder ofType(Class newType) { 44 | type = newType; 45 | return this; 46 | } 47 | 48 | FieldBuilder withName(String newName) { 49 | name = newName; 50 | return this; 51 | } 52 | 53 | FieldBuilder withModifiers(long newModifiers) { 54 | modifiers = newModifiers; 55 | return this; 56 | } 57 | 58 | FieldBuilder withArgs(JCExpression... newArgs) { 59 | args = List.from(newArgs); 60 | return this; 61 | } 62 | 63 | JCVariableDecl buildWith(JavacNode node) { 64 | TreeMaker treeMaker = node.getTreeMaker(); 65 | JCExpression classType = chainDots(treeMaker, node, splitNameOf(type)); 66 | JCExpression newVar = treeMaker.NewClass(null, null, classType, args, null); 67 | return treeMaker.VarDef(treeMaker.Modifiers(modifiers), node.toName(name), classType, newVar); 68 | } 69 | 70 | private FieldBuilder() {} 71 | } 72 | -------------------------------------------------------------------------------- /src/javac/lombok/javac/handlers/JCNoType.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Created on Dec 1, 2010 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with 5 | * the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on 10 | * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the 11 | * specific language governing permissions and limitations under the License. 12 | * 13 | * Copyright @2010 the original author or authors. 14 | */ 15 | package lombok.javac.handlers; 16 | 17 | import static com.sun.tools.javac.code.TypeTags.*; 18 | 19 | import javax.lang.model.type.*; 20 | 21 | import com.sun.tools.javac.code.Type; 22 | 23 | /** 24 | * A type to represent "void" and "none." Copied from Lombok. 25 | * 26 | * @author Alex Ruiz 27 | */ 28 | class JCNoType extends Type implements NoType { 29 | 30 | static JCNoType voidType() { 31 | return new JCNoType(VOID); 32 | } 33 | 34 | private JCNoType(int tag) { 35 | super(tag, null); 36 | } 37 | 38 | @Override public TypeKind getKind() { 39 | if (tag == VOID) return TypeKind.VOID; 40 | if (tag == NONE) return TypeKind.NONE; 41 | throw new IllegalStateException("Unexpected tag: " + tag); 42 | } 43 | 44 | @Override public R accept(TypeVisitor v, P p) { 45 | return v.visitNoType(this, p); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/javac/lombok/javac/handlers/JavaBeanHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Created on Dec 3, 2010 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with 5 | * the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on 10 | * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the 11 | * specific language governing permissions and limitations under the License. 12 | * 13 | * Copyright @2010 the original author or authors. 14 | */ 15 | package lombok.javac.handlers; 16 | 17 | import static com.sun.tools.javac.code.Flags.*; 18 | import static lombok.core.util.ErrorMessages.canBeUsedOnClassOnly; 19 | import static lombok.core.util.Names.*; 20 | import static lombok.javac.handlers.FieldBuilder.newField; 21 | import static lombok.javac.handlers.JCNoType.voidType; 22 | import static lombok.javac.handlers.JavacHandlerUtil.*; 23 | import static lombok.javac.handlers.MemberChecks.*; 24 | import static lombok.javac.handlers.MethodBuilder.newMethod; 25 | 26 | import java.beans.*; 27 | 28 | import lombok.GenerateJavaBean; 29 | import lombok.core.AnnotationValues; 30 | import lombok.javac.*; 31 | 32 | import org.mangosdk.spi.ProviderFor; 33 | 34 | import com.sun.tools.javac.tree.JCTree.JCAnnotation; 35 | import com.sun.tools.javac.tree.JCTree.JCBlock; 36 | import com.sun.tools.javac.tree.JCTree.JCExpression; 37 | import com.sun.tools.javac.tree.JCTree.JCMethodDecl; 38 | import com.sun.tools.javac.tree.JCTree.JCStatement; 39 | import com.sun.tools.javac.tree.JCTree.JCVariableDecl; 40 | import com.sun.tools.javac.tree.*; 41 | import com.sun.tools.javac.util.*; 42 | 43 | /** 44 | * Generates basic support for making a class annotated with {@link GenerateJavaBean} a JavaBean. 45 | *

46 | * "Basic" JavaBean support means: 47 | *

    48 | *
  1. Generates a field of type {@link PropertyChangeSupport} with name "propertySupport"
  2. 49 | *
  3. Generates the public method {@code addPropertyChangeListener(PropertyChangeListener)} and 50 | * {@code removePropertyChangeListener(PropertyChangeListener)}
  4. 51 | *
  5. 52 | *
53 | *

54 | *

55 | * For example, given this class: 56 | * 57 | *

 58 |  * @GenerateJavaBean
 59 |  * public class Person {
 60 |  *
 61 |  * }
 62 |  * 
63 | * this annotation handler will generate the AST nodes that correspond to this code: 64 | * 65 | *
 66 |  * public class Person {
 67 |  *
 68 |  *   private PropertyChangeSupport propertySupport = new PropertyChangeSupport(this);
 69 | 
 70 |  *   public void addPropertyChangeListener(PropertyChangeListener listener) {
 71 |  *     propertySupport.addPropertyChangeListener(listener);
 72 |  *   }
 73 |  *
 74 |  *   public void removePropertyChangeListener(PropertyChangeListener listener) {
 75 |  *     propertySupport.removePropertyChangeListener(listener);
 76 |  *   }
 77 |  * }
 78 |  * 
79 | *

80 | * 81 | * @author Alex Ruiz 82 | */ 83 | @ProviderFor(JavacAnnotationHandler.class) 84 | public class JavaBeanHandler implements JavacAnnotationHandler { 85 | 86 | private static final Class TARGET_ANNOTATION_TYPE = GenerateJavaBean.class; 87 | 88 | /** 89 | * Called when an annotation is found that is likely to match {@link GenerateJavaBean}. This is were AST 90 | * node generation happens. 91 | * @param annotation the actual annotation. 92 | * @param ast the javac AST node representing the annotation. 93 | * @param astWrapper the lombok AST wrapper around {@code ast}. 94 | * @return {@code true} if this handler successfully handled {@code GenerateJavaBean}; {@code false} otherwise. 95 | */ 96 | @Override 97 | public boolean handle(AnnotationValues annotation, JCAnnotation ast, JavacNode astWrapper) { 98 | markAnnotationAsProcessed(astWrapper, TARGET_ANNOTATION_TYPE); 99 | JavacNode typeNode = astWrapper.up(); 100 | if (typeNode == null) return false; 101 | if (!isClass(typeNode)) { 102 | astWrapper.addError(canBeUsedOnClassOnly(TARGET_ANNOTATION_TYPE)); 103 | return true; 104 | } 105 | generatePropertyChangeSupportField(typeNode); 106 | generateChangeListenerMethods(typeNode); 107 | return true; 108 | } 109 | 110 | private void generatePropertyChangeSupportField(JavacNode typeNode) { 111 | if (fieldAlreadyExists(PROPERTY_SUPPORT_FIELD_NAME, typeNode)) return; 112 | JCExpression expressionForThis = chainDots(typeNode.getTreeMaker(), typeNode, "this"); 113 | JCVariableDecl fieldDecl = newField().ofType(PropertyChangeSupport.class) 114 | .withName(PROPERTY_SUPPORT_FIELD_NAME) 115 | .withModifiers(PRIVATE | FINAL) 116 | .withArgs(expressionForThis) 117 | .buildWith(typeNode); 118 | injectField(typeNode, fieldDecl); 119 | } 120 | 121 | private void generateChangeListenerMethods(JavacNode typeNode) { 122 | for (String methodName : PROPERTY_CHANGE_METHOD_NAMES) 123 | generateChangeListenerMethod(methodName, typeNode); 124 | } 125 | 126 | private void generateChangeListenerMethod(String methodName, JavacNode typeNode) { 127 | if (methodAlreadyExists(methodName, typeNode)) return; 128 | TreeMaker treeMaker = typeNode.getTreeMaker(); 129 | JCMethodDecl methodDecl = newMethod().withModifiers(PUBLIC) 130 | .withName(methodName) 131 | .withReturnType(treeMaker.Type(voidType())) 132 | .withParameters(parameters(typeNode)) 133 | .withBody(body(methodName, typeNode)) 134 | .buildWith(typeNode); 135 | injectMethod(typeNode, methodDecl); 136 | } 137 | 138 | private List parameters(JavacNode typeNode) { 139 | TreeMaker treeMaker = typeNode.getTreeMaker(); 140 | JCExpression type = chainDots(treeMaker, typeNode, splitNameOf(PropertyChangeListener.class)); 141 | JCVariableDecl parameter = treeMaker.VarDef(treeMaker.Modifiers(FINAL), listenerArgName(typeNode), type, null); 142 | return List.of(parameter); 143 | } 144 | 145 | private JCBlock body(String methodName, JavacNode typeNode) { 146 | TreeMaker treeMaker = typeNode.getTreeMaker(); 147 | JCExpression delegateToPropertySupport = delegateToPropertySupport(methodName, typeNode); 148 | List statements = List. of(treeMaker.Exec(delegateToPropertySupport)); 149 | return treeMaker.Block(0, statements); 150 | } 151 | 152 | private JCExpression delegateToPropertySupport(String methodName, JavacNode typeNode) { 153 | TreeMaker treeMaker = typeNode.getTreeMaker(); 154 | JCExpression fn = chainDots(treeMaker, typeNode, PROPERTY_SUPPORT_FIELD_NAME, methodName); 155 | JCExpression arg = treeMaker.Ident(listenerArgName(typeNode)); 156 | return treeMaker.Apply(List. nil(), fn, List.of(arg)); 157 | } 158 | 159 | private Name listenerArgName(JavacNode typeNode) { 160 | return typeNode.toName(LISTENER_ARG_NAME); 161 | } 162 | 163 | /** 164 | * Indicates whether this handler requires resolution. 165 | * @return {@code false}. 166 | */ 167 | @Override public boolean isResolutionBased() { 168 | return false; 169 | } 170 | } 171 | -------------------------------------------------------------------------------- /src/javac/lombok/javac/handlers/Lombok.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Created on Dec 1, 2010 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with 5 | * the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on 10 | * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the 11 | * specific language governing permissions and limitations under the License. 12 | * 13 | * Copyright @2010 the original author or authors. 14 | */ 15 | package lombok.javac.handlers; 16 | 17 | import static lombok.javac.handlers.JavacHandlerUtil.createFieldAccessor; 18 | import static lombok.javac.handlers.JavacHandlerUtil.FieldAccess.ALWAYS_FIELD; 19 | import lombok.javac.JavacNode; 20 | 21 | import com.sun.tools.javac.tree.JCTree.JCExpression; 22 | 23 | /** 24 | * @author Alex Ruiz 25 | */ 26 | final class Lombok { 27 | 28 | static JCExpression newFieldAccessor(JavacNode fieldNode) { 29 | return createFieldAccessor(fieldNode.getTreeMaker(), fieldNode, ALWAYS_FIELD); 30 | } 31 | 32 | private Lombok() {} 33 | } 34 | -------------------------------------------------------------------------------- /src/javac/lombok/javac/handlers/MemberChecks.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Created on Dec 1, 2010 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with 5 | * the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on 10 | * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the 11 | * specific language governing permissions and limitations under the License. 12 | * 13 | * Copyright @2010 the original author or authors. 14 | */ 15 | package lombok.javac.handlers; 16 | 17 | import static com.sun.tools.javac.code.Flags.*; 18 | import static lombok.core.AST.Kind.FIELD; 19 | import static lombok.javac.handlers.JavacHandlerUtil.*; 20 | import static lombok.javac.handlers.JavacHandlerUtil.MemberExistsResult.NOT_EXISTS; 21 | import lombok.javac.JavacNode; 22 | import lombok.javac.handlers.JavacHandlerUtil.MemberExistsResult; 23 | 24 | import com.sun.tools.javac.tree.JCTree; 25 | import com.sun.tools.javac.tree.JCTree.JCClassDecl; 26 | 27 | /** 28 | * @author Alex Ruiz 29 | */ 30 | final class MemberChecks { 31 | 32 | static boolean isClass(JavacNode node) { 33 | JCTree javacNode = node.get(); 34 | if (!(javacNode instanceof JCClassDecl)) return false; 35 | JCClassDecl classDecl = (JCClassDecl) javacNode; 36 | return (classDecl.mods.flags & (INTERFACE | ENUM | ANNOTATION)) == 0; 37 | } 38 | 39 | static boolean isField(JavacNode node) { 40 | return FIELD.equals(node.getKind()); 41 | } 42 | 43 | static boolean fieldAlreadyExists(String fieldName, JavacNode node) { 44 | return existsYesOrNo(fieldExists(fieldName, node)); 45 | } 46 | 47 | static boolean methodAlreadyExists(String methodName, JavacNode node) { 48 | return existsYesOrNo(methodExists(methodName, node)); 49 | } 50 | 51 | private static boolean existsYesOrNo(MemberExistsResult result) { 52 | return !result.equals(NOT_EXISTS); 53 | } 54 | 55 | private MemberChecks() {} 56 | } 57 | -------------------------------------------------------------------------------- /src/javac/lombok/javac/handlers/MethodBuilder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Created on Dec 1, 2010 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with 5 | * the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on 10 | * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the 11 | * specific language governing permissions and limitations under the License. 12 | * 13 | * Copyright @2010 the original author or authors. 14 | */ 15 | package lombok.javac.handlers; 16 | 17 | import static com.sun.tools.javac.util.List.nil; 18 | import lombok.javac.JavacNode; 19 | 20 | import com.sun.tools.javac.tree.JCTree.JCBlock; 21 | import com.sun.tools.javac.tree.JCTree.JCExpression; 22 | import com.sun.tools.javac.tree.JCTree.JCMethodDecl; 23 | import com.sun.tools.javac.tree.JCTree.JCTypeParameter; 24 | import com.sun.tools.javac.tree.JCTree.JCVariableDecl; 25 | import com.sun.tools.javac.tree.*; 26 | import com.sun.tools.javac.util.List; 27 | 28 | /** 29 | * Simplifies creation of methods. 30 | * 31 | * @author Alex Ruiz 32 | */ 33 | class MethodBuilder { 34 | 35 | static MethodBuilder newMethod() { 36 | return new MethodBuilder(); 37 | } 38 | 39 | private long modifiers; 40 | private String name; 41 | private JCExpression returnType; 42 | private List parameters = nil(); 43 | private List throwsClauses = nil(); 44 | private JCBlock body; 45 | private JCExpression defaultValue; 46 | 47 | private MethodBuilder() {} 48 | 49 | MethodBuilder withModifiers(long newModifiers) { 50 | modifiers = newModifiers; 51 | return this; 52 | } 53 | 54 | MethodBuilder withName(String newName) { 55 | name = newName; 56 | return this; 57 | } 58 | 59 | MethodBuilder withReturnType(JCExpression newReturnType) { 60 | returnType = newReturnType; 61 | return this; 62 | } 63 | 64 | MethodBuilder withParameters(List newParameters) { 65 | parameters = newParameters; 66 | return this; 67 | } 68 | 69 | MethodBuilder withThrowsClauses(List newThrowsClauses) { 70 | throwsClauses = newThrowsClauses; 71 | return this; 72 | } 73 | 74 | MethodBuilder withBody(JCBlock newBody) { 75 | body = newBody; 76 | return this; 77 | } 78 | 79 | MethodBuilder withDefaultValue(JCExpression newDefaultValue) { 80 | defaultValue = newDefaultValue; 81 | return this; 82 | } 83 | 84 | JCMethodDecl buildWith(JavacNode node) { 85 | TreeMaker treeMaker = node.getTreeMaker(); 86 | return treeMaker.MethodDef(treeMaker.Modifiers(modifiers), node.toName(name), returnType, 87 | List. nil(), parameters, throwsClauses, body, defaultValue); 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /test/core/lombok/core/util/Arrays_array_Test.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Created on Dec 9, 2010 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with 5 | * the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on 10 | * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the 11 | * specific language governing permissions and limitations under the License. 12 | * 13 | * Copyright @2010 the original author or authors. 14 | */ 15 | package lombok.core.util; 16 | 17 | import static org.fest.assertions.Assertions.assertThat; 18 | 19 | import org.junit.Test; 20 | 21 | /** 22 | * Tests for {@link Arrays#array(Object...)}. 23 | * 24 | * @author Alex Ruiz 25 | */ 26 | public class Arrays_array_Test { 27 | 28 | @Test public void should_return_array_with_given_elements() { 29 | assertThat(Arrays.array("Yoda", "Luke")).isEqualTo(new String[] { "Yoda", "Luke" }); 30 | } 31 | 32 | @Test public void should_return_same_array_as_the_one_passed() { 33 | Object[] array = { "Yoda" }; 34 | assertThat(Arrays.array(array)).isSameAs(array); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /test/core/lombok/core/util/Arrays_copy_Test.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Created on Dec 9, 2010 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with 5 | * the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on 10 | * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the 11 | * specific language governing permissions and limitations under the License. 12 | * 13 | * Copyright @2010 the original author or authors. 14 | */ 15 | package lombok.core.util; 16 | 17 | import static org.fest.assertions.Assertions.assertThat; 18 | 19 | import org.junit.Test; 20 | 21 | /** 22 | * Tests for {@link Arrays#copy(Object[])}. 23 | * 24 | * @author Alex Ruiz 25 | */ 26 | public class Arrays_copy_Test { 27 | 28 | @Test public void should_copy_array() { 29 | Object[] array = { "Yoda", "Leia" }; 30 | Object[] copy = Arrays.copy(array); 31 | assertThat(copy).isEqualTo(array) 32 | .isNotSameAs(array); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /test/core/lombok/core/util/Arrays_isNotEmpty_Test.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Created on Dec 8, 2010 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with 5 | * the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on 10 | * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the 11 | * specific language governing permissions and limitations under the License. 12 | * 13 | * Copyright @2010 the original author or authors. 14 | */ 15 | package lombok.core.util; 16 | 17 | import static org.fest.assertions.Assertions.assertThat; 18 | import lombok.core.util.Arrays; 19 | 20 | import org.junit.Test; 21 | 22 | /** 23 | * Tests for {@link Arrays#isNotEmpty(Object[])}. 24 | * 25 | * @author Alex Ruiz 26 | */ 27 | public class Arrays_isNotEmpty_Test { 28 | 29 | @Test public void should_return_false_if_array_is_null() { 30 | assertThat(Arrays.isNotEmpty(null)).isFalse(); 31 | } 32 | 33 | @Test public void should_return_false_if_array_is_empty() { 34 | assertThat(Arrays.isNotEmpty(new Object[0])).isFalse(); 35 | } 36 | 37 | @Test public void should_return_true_if_array_is_not_empty() { 38 | assertThat(Arrays.isNotEmpty(new Object[] { "Yoda" })).isTrue(); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /test/core/lombok/core/util/AstGeneration_stopAstGeneration_Test.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Created on Dec 9, 2010 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with 5 | * the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on 10 | * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the 11 | * specific language governing permissions and limitations under the License. 12 | * 13 | * Copyright @2010 the original author or authors. 14 | */ 15 | package lombok.core.util; 16 | 17 | import static lombok.AccessLevel.NONE; 18 | import static org.fest.assertions.Assertions.assertThat; 19 | import lombok.AccessLevel; 20 | 21 | import org.junit.Test; 22 | 23 | /** 24 | * Tests for {@link AstGeneration#stopAstGeneration(AccessLevel)}. 25 | * 26 | * @author Alex Ruiz 27 | */ 28 | public class AstGeneration_stopAstGeneration_Test { 29 | 30 | @Test public void should_return_true_if_AccessLevel_is_NONE() { 31 | assertThat(AstGeneration.stopAstGeneration(NONE)).isTrue(); 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /test/core/lombok/core/util/AstGeneration_stopAstGeneration_with_parameters_Test.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Created on Dec 9, 2010 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with 5 | * the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on 10 | * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the 11 | * specific language governing permissions and limitations under the License. 12 | * 13 | * Copyright @2010 the original author or authors. 14 | */ 15 | package lombok.core.util; 16 | 17 | import static lombok.AccessLevel.*; 18 | import static org.fest.assertions.Assertions.assertThat; 19 | import static org.fest.util.Collections.list; 20 | 21 | import java.util.Collection; 22 | 23 | import lombok.AccessLevel; 24 | 25 | import org.junit.Test; 26 | import org.junit.runner.RunWith; 27 | import org.junit.runners.*; 28 | import org.junit.runners.Parameterized.Parameters; 29 | 30 | /** 31 | * Tests for {@link AstGeneration#stopAstGeneration(AccessLevel)}. 32 | * 33 | * @author Alex Ruiz 34 | */ 35 | @RunWith(Parameterized.class) 36 | public class AstGeneration_stopAstGeneration_with_parameters_Test { 37 | 38 | @Parameters public static Collection parameters() { 39 | return list(new Object[][] { 40 | { PUBLIC }, { MODULE }, { PROTECTED }, { PACKAGE }, { PRIVATE } 41 | }); 42 | } 43 | 44 | private final AccessLevel level; 45 | 46 | public AstGeneration_stopAstGeneration_with_parameters_Test(AccessLevel level) { 47 | this.level = level; 48 | } 49 | 50 | @Test public void should_return_false_if_AccessLevel() { 51 | assertThat(AstGeneration.stopAstGeneration(level)).isFalse(); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /test/core/lombok/core/util/ErrorMessages_canBeUsedOnClassOnly_Test.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Created on Dec 9, 2010 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with 5 | * the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on 10 | * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the 11 | * specific language governing permissions and limitations under the License. 12 | * 13 | * Copyright @2010 the original author or authors. 14 | */ 15 | package lombok.core.util; 16 | 17 | import static org.fest.assertions.Assertions.assertThat; 18 | 19 | import org.junit.Test; 20 | 21 | /** 22 | * Tests for {@link ErrorMessages#canBeUsedOnClassOnly(Class)}. 23 | * 24 | * @author Alex Ruiz 25 | */ 26 | public class ErrorMessages_canBeUsedOnClassOnly_Test { 27 | 28 | @Test public void should_create_error_message() { 29 | String errorMessage = ErrorMessages.canBeUsedOnClassOnly(Override.class); 30 | assertThat(errorMessage).isEqualTo("@java.lang.Override can be used on classes only"); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /test/core/lombok/core/util/ErrorMessages_canBeUsedOnFieldOnly_Test.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Created on Dec 9, 2010 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with 5 | * the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on 10 | * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the 11 | * specific language governing permissions and limitations under the License. 12 | * 13 | * Copyright @2010 the original author or authors. 14 | */ 15 | package lombok.core.util; 16 | 17 | import static org.fest.assertions.Assertions.assertThat; 18 | 19 | import org.junit.Test; 20 | 21 | /** 22 | * Tests for {@link ErrorMessages#canBeUsedOnFieldOnly(Class)}. 23 | * 24 | * @author Alex Ruiz 25 | */ 26 | public class ErrorMessages_canBeUsedOnFieldOnly_Test { 27 | 28 | @Test public void should_create_error_message() { 29 | String errorMessage = ErrorMessages.canBeUsedOnFieldOnly(Override.class); 30 | assertThat(errorMessage).isEqualTo("@java.lang.Override can be used on fields only"); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /test/core/lombok/core/util/Names_nameOfConstantBasedOnProperty_Test.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Created on Dec 10, 2010 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with 5 | * the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on 10 | * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the 11 | * specific language governing permissions and limitations under the License. 12 | * 13 | * Copyright @2010 the original author or authors. 14 | */ 15 | package lombok.core.util; 16 | 17 | import static org.fest.assertions.Assertions.assertThat; 18 | import static org.fest.util.Collections.list; 19 | 20 | import java.util.Collection; 21 | 22 | import org.junit.Test; 23 | import org.junit.runner.RunWith; 24 | import org.junit.runners.Parameterized; 25 | import org.junit.runners.Parameterized.Parameters; 26 | 27 | /** 28 | * Tests for {@link Names#nameOfConstantBasedOnProperty(String)}. 29 | * 30 | * @author Alex Ruiz 31 | */ 32 | @RunWith(Parameterized.class) 33 | public class Names_nameOfConstantBasedOnProperty_Test { 34 | 35 | @Parameters public static Collection parameters() { 36 | return list(new Object[][] { 37 | { "i", "PROP_I" }, 38 | { "helloWorld", "PROP_HELLO_WORLD" }, 39 | { "i9K", "PROP_I9_K" } 40 | }); 41 | } 42 | 43 | private final String propertyName; 44 | private final String constantName; 45 | 46 | public Names_nameOfConstantBasedOnProperty_Test(String propertyName, String constantName) { 47 | this.propertyName = propertyName; 48 | this.constantName = constantName; 49 | } 50 | 51 | @Test public void should_create_name_of_constant_based_on_property_name() { 52 | assertThat(Names.nameOfConstantBasedOnProperty(propertyName)).isEqualTo(constantName); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /test/core/lombok/core/util/Names_splitNameOf_Test.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Created on Dec 9, 2010 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with 5 | * the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on 10 | * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the 11 | * specific language governing permissions and limitations under the License. 12 | * 13 | * Copyright @2010 the original author or authors. 14 | */ 15 | package lombok.core.util; 16 | 17 | import static org.fest.assertions.Assertions.assertThat; 18 | import static org.fest.util.Arrays.array; 19 | 20 | import org.junit.Test; 21 | 22 | /** 23 | * Tests for {@link Names#splitNameOf(Class)}. 24 | * 25 | * @author Alex Ruiz 26 | */ 27 | public class Names_splitNameOf_Test { 28 | 29 | @Test public void should_split_name_of_class() { 30 | assertThat(Names.splitNameOf(String.class)).isEqualTo(array("java", "lang", "String")); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /test/eclipse/lombok/eclipse/handlers/TestWithEcj.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Created on Dec 7, 2010 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with 5 | * the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on 10 | * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the 11 | * specific language governing permissions and limitations under the License. 12 | * 13 | * Copyright @2010 the original author or authors. 14 | */ 15 | package lombok.eclipse.handlers; 16 | 17 | import static lombok.DirectoryRunner.Compiler.ECJ; 18 | 19 | import java.io.File; 20 | 21 | import lombok.*; 22 | import lombok.DirectoryRunner.Compiler; 23 | import lombok.DirectoryRunner.TestParams; 24 | 25 | import org.junit.runner.RunWith; 26 | 27 | /** 28 | * @author Alex Ruiz 29 | */ 30 | @RunWith(DirectoryRunner.class) 31 | public class TestWithEcj implements TestParams { 32 | 33 | @Override public Compiler getCompiler() { 34 | return ECJ; 35 | } 36 | 37 | @Override public boolean printErrors() { 38 | return true; 39 | } 40 | 41 | @Override public File getBeforeDirectory() { 42 | return new File("test/transform/resource/before"); 43 | } 44 | 45 | @Override public File getAfterDirectory() { 46 | return new File("test/transform/resource/after-ecj"); 47 | } 48 | 49 | @Override public File getMessagesDirectory() { 50 | return new File("test/transform/resource/messages-ecj"); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /test/javac/lombok/javac/handlers/TestWithDelombok.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Created on Dec 4, 2010 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with 5 | * the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on 10 | * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the 11 | * specific language governing permissions and limitations under the License. 12 | * 13 | * Copyright @2010 the original author or authors. 14 | */ 15 | package lombok.javac.handlers; 16 | 17 | import static lombok.DirectoryRunner.Compiler.DELOMBOK; 18 | 19 | import java.io.File; 20 | 21 | import lombok.*; 22 | import lombok.DirectoryRunner.Compiler; 23 | import lombok.DirectoryRunner.TestParams; 24 | 25 | import org.junit.runner.RunWith; 26 | 27 | /** 28 | * @author Alex Ruiz 29 | */ 30 | @RunWith(DirectoryRunner.class) 31 | public class TestWithDelombok implements TestParams { 32 | 33 | @Override public Compiler getCompiler() { 34 | return DELOMBOK; 35 | } 36 | 37 | @Override public boolean printErrors() { 38 | return true; 39 | } 40 | 41 | @Override public File getBeforeDirectory() { 42 | return new File("test/transform/resource/before"); 43 | } 44 | 45 | @Override public File getAfterDirectory() { 46 | return new File("test/transform/resource/after-delombok"); 47 | } 48 | 49 | @Override public File getMessagesDirectory() { 50 | return new File("test/transform/resource/messages-delombok"); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /test/transform/resource/after-delombok/CompleteJavaBean.java: -------------------------------------------------------------------------------- 1 | class CompleteJavaBean { 2 | 3 | private final java.beans.PropertyChangeSupport propertySupport = new java.beans.PropertyChangeSupport(this); 4 | public static final java.lang.String PROP_I = "i"; 5 | private int i; 6 | 7 | public void addPropertyChangeListener(final java.beans.PropertyChangeListener listener) { 8 | propertySupport.addPropertyChangeListener(listener); 9 | } 10 | 11 | public void removePropertyChangeListener(final java.beans.PropertyChangeListener listener) { 12 | propertySupport.removePropertyChangeListener(listener); 13 | } 14 | 15 | @java.lang.SuppressWarnings("all") 16 | public void setI(int i) { 17 | final int old = this.i; 18 | this.i = i; 19 | propertySupport.firePropertyChange(PROP_I, old, this.i); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /test/transform/resource/after-delombok/GenerateJavaBeanNotInClass.java: -------------------------------------------------------------------------------- 1 | class GenerateJavaBeanNotInClass { 2 | 3 | private int i; 4 | } 5 | -------------------------------------------------------------------------------- /test/transform/resource/after-delombok/SimpleJavaBean.java: -------------------------------------------------------------------------------- 1 | class SimpleJavaBean { 2 | 3 | int i; 4 | String s; 5 | float f; 6 | Object o; 7 | double d; 8 | private final java.beans.PropertyChangeSupport propertySupport = new java.beans.PropertyChangeSupport(this); 9 | 10 | @java.lang.SuppressWarnings("all") 11 | public void addPropertyChangeListener(final java.beans.PropertyChangeListener listener) { 12 | propertySupport.addPropertyChangeListener(listener); 13 | } 14 | 15 | @java.lang.SuppressWarnings("all") 16 | public void removePropertyChangeListener(final java.beans.PropertyChangeListener listener) { 17 | propertySupport.removePropertyChangeListener(listener); 18 | } 19 | public static final java.lang.String PROP_I = new java.lang.String("i"); 20 | 21 | @java.lang.SuppressWarnings("all") 22 | public void setI(int i) { 23 | final int old = this.i; 24 | this.i = i; 25 | propertySupport.firePropertyChange(PROP_I, old, this.i); 26 | } 27 | public static final java.lang.String PROP_S = new java.lang.String("s"); 28 | 29 | @java.lang.SuppressWarnings("all") 30 | public void setS(String s) { 31 | final String old = this.s; 32 | this.s = s; 33 | propertySupport.firePropertyChange(PROP_S, old, this.s); 34 | } 35 | public static final java.lang.String PROP_F = new java.lang.String("f"); 36 | 37 | @java.lang.SuppressWarnings("all") 38 | protected void setF(float f) { 39 | final float old = this.f; 40 | this.f = f; 41 | propertySupport.firePropertyChange(PROP_F, old, this.f); 42 | } 43 | public static final java.lang.String PROP_O = new java.lang.String("o"); 44 | 45 | @java.lang.SuppressWarnings("all") 46 | void setO(Object o) { 47 | final Object old = this.o; 48 | this.o = o; 49 | propertySupport.firePropertyChange(PROP_O, old, this.o); 50 | } 51 | public static final java.lang.String PROP_D = new java.lang.String("d"); 52 | 53 | @java.lang.SuppressWarnings("all") 54 | private void setD(double d) { 55 | final double old = this.d; 56 | this.d = d; 57 | propertySupport.firePropertyChange(PROP_D, old, this.d); 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /test/transform/resource/after-ecj/CompleteJavaBean.java: -------------------------------------------------------------------------------- 1 | import lombok.GenerateJavaBean; 2 | import lombok.GenerateBoundSetter; 3 | @GenerateJavaBean class CompleteJavaBean { 4 | private final java.beans.PropertyChangeSupport propertySupport = new java.beans.PropertyChangeSupport(this); 5 | public static final java.lang.String PROP_I = "i"; 6 | private @GenerateBoundSetter int i; 7 | () { 8 | } 9 | public @java.lang.SuppressWarnings("all") void setI(int i) { 10 | final int old = this.i; 11 | this.i = i; 12 | propertySupport.firePropertyChange(PROP_I, old, this.i); 13 | } 14 | public @java.lang.SuppressWarnings("all") void addPropertyChangeListener(final java.beans.PropertyChangeListener listener) { 15 | propertySupport.addPropertyChangeListener(listener); 16 | } 17 | public @java.lang.SuppressWarnings("all") void removePropertyChangeListener(final java.beans.PropertyChangeListener listener) { 18 | propertySupport.removePropertyChangeListener(listener); 19 | } 20 | CompleteJavaBean() { 21 | super(); 22 | } 23 | public void addPropertyChangeListener(final java.beans.PropertyChangeListener listener) { 24 | propertySupport.addPropertyChangeListener(listener); 25 | } 26 | public void removePropertyChangeListener(final java.beans.PropertyChangeListener listener) { 27 | propertySupport.removePropertyChangeListener(listener); 28 | } 29 | } -------------------------------------------------------------------------------- /test/transform/resource/after-ecj/GenerateJavaBeanNotInClass.java: -------------------------------------------------------------------------------- 1 | import lombok.GenerateJavaBean; 2 | class GenerateJavaBeanNotInClass { 3 | private @GenerateJavaBean int i; 4 | GenerateJavaBeanNotInClass() { 5 | super(); 6 | } 7 | } -------------------------------------------------------------------------------- /test/transform/resource/after-ecj/SimpleJavaBean.java: -------------------------------------------------------------------------------- 1 | import lombok.AccessLevel; 2 | import lombok.GenerateJavaBean; 3 | import lombok.GenerateBoundSetter; 4 | @GenerateJavaBean class SimpleJavaBean { 5 | @GenerateBoundSetter int i; 6 | @GenerateBoundSetter(AccessLevel.PUBLIC) String s; 7 | @GenerateBoundSetter(AccessLevel.PROTECTED) float f; 8 | @GenerateBoundSetter(AccessLevel.PACKAGE) Object o; 9 | @GenerateBoundSetter(AccessLevel.PRIVATE) double d; 10 | public static final java.lang.String PROP_I = new java.lang.String("i"); 11 | public static final java.lang.String PROP_S = new java.lang.String("s"); 12 | public static final java.lang.String PROP_F = new java.lang.String("f"); 13 | public static final java.lang.String PROP_O = new java.lang.String("o"); 14 | public static final java.lang.String PROP_D = new java.lang.String("d"); 15 | private final java.beans.PropertyChangeSupport propertySupport = new java.beans.PropertyChangeSupport(this); 16 | () { 17 | } 18 | public @java.lang.SuppressWarnings("all") void setI(int i) { 19 | final int old = this.i; 20 | this.i = i; 21 | propertySupport.firePropertyChange(PROP_I, old, this.i); 22 | } 23 | public @java.lang.SuppressWarnings("all") void setS(String s) { 24 | final String old = this.s; 25 | this.s = s; 26 | propertySupport.firePropertyChange(PROP_S, old, this.s); 27 | } 28 | protected @java.lang.SuppressWarnings("all") void setF(float f) { 29 | final float old = this.f; 30 | this.f = f; 31 | propertySupport.firePropertyChange(PROP_F, old, this.f); 32 | } 33 | @java.lang.SuppressWarnings("all") void setO(Object o) { 34 | final Object old = this.o; 35 | this.o = o; 36 | propertySupport.firePropertyChange(PROP_O, old, this.o); 37 | } 38 | private @java.lang.SuppressWarnings("all") void setD(double d) { 39 | final double old = this.d; 40 | this.d = d; 41 | propertySupport.firePropertyChange(PROP_D, old, this.d); 42 | } 43 | public @java.lang.SuppressWarnings("all") void addPropertyChangeListener(final java.beans.PropertyChangeListener listener) { 44 | propertySupport.addPropertyChangeListener(listener); 45 | } 46 | public @java.lang.SuppressWarnings("all") void removePropertyChangeListener(final java.beans.PropertyChangeListener listener) { 47 | propertySupport.removePropertyChangeListener(listener); 48 | } 49 | SimpleJavaBean() { 50 | super(); 51 | } 52 | } -------------------------------------------------------------------------------- /test/transform/resource/before/CompleteJavaBean.java: -------------------------------------------------------------------------------- 1 | import lombok.GenerateJavaBean; 2 | import lombok.GenerateBoundSetter; 3 | 4 | @GenerateJavaBean 5 | class CompleteJavaBean { 6 | 7 | private final java.beans.PropertyChangeSupport propertySupport = new java.beans.PropertyChangeSupport(this); 8 | 9 | public static final java.lang.String PROP_I = "i"; 10 | @GenerateBoundSetter private int i; 11 | 12 | public void addPropertyChangeListener(final java.beans.PropertyChangeListener listener) { 13 | propertySupport.addPropertyChangeListener(listener); 14 | } 15 | 16 | public void removePropertyChangeListener(final java.beans.PropertyChangeListener listener) { 17 | propertySupport.removePropertyChangeListener(listener); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /test/transform/resource/before/GenerateJavaBeanNotInClass.java: -------------------------------------------------------------------------------- 1 | import lombok.GenerateJavaBean; 2 | 3 | class GenerateJavaBeanNotInClass { 4 | @GenerateJavaBean private int i; 5 | } -------------------------------------------------------------------------------- /test/transform/resource/before/SimpleJavaBean.java: -------------------------------------------------------------------------------- 1 | import lombok.AccessLevel; 2 | 3 | import lombok.GenerateJavaBean; 4 | import lombok.GenerateBoundSetter; 5 | 6 | @GenerateJavaBean 7 | class SimpleJavaBean { 8 | @GenerateBoundSetter int i; 9 | @GenerateBoundSetter(AccessLevel.PUBLIC) String s; 10 | @GenerateBoundSetter(AccessLevel.PROTECTED) float f; 11 | @GenerateBoundSetter(AccessLevel.PACKAGE) Object o; 12 | @GenerateBoundSetter(AccessLevel.PRIVATE) double d; 13 | } 14 | -------------------------------------------------------------------------------- /test/transform/resource/messages-delombok/GenerateJavaBeanNotInClass.java.messages: -------------------------------------------------------------------------------- 1 | 4:3 ERROR @lombok.GenerateJavaBean can be used on classes only -------------------------------------------------------------------------------- /test/transform/resource/messages-ecj/GenerateJavaBeanNotInClass.java.messages: -------------------------------------------------------------------------------- 1 | 4 error @lombok.GenerateJavaBean can be used on classes only --------------------------------------------------------------------------------