diff options
331 files changed, 9049 insertions, 2048 deletions
@@ -10,5 +10,6 @@ Robbert Jan Grootjans <grootjans@gmail.com> Roel Spilker <r.spilker@gmail.com> Sander Koning <askoning@gmail.com> Taiki Sugawara <buzz.taiki@gmail.com> +Peter Grant <petercgrant@users.noreply.github.com> By adding your name to this list, you grant full and irrevocable copyright and patent indemnity to Project Lombok and all use of Project Lombok, and you certify that you have the right to do so for all commits you add to Project Lombok. @@ -195,7 +195,7 @@ the common tasks and can be called on to run the main aspects of all the sub-scr </ivy:compile> <mkdir dir="build/lombok/META-INF" /> <mkdir dir="build/lombok/META-INF/services" /> - <echo file="build/lombok/META-INF/services/javax.annotation.processing.Processor">lombok.launch.AnnotationProcessorHider.AnnotationProcessor</echo> + <echo file="build/lombok/META-INF/services/javax.annotation.processing.Processor">lombok.launch.AnnotationProcessorHider$AnnotationProcessor</echo> </target> <target name="dist" description="Builds THE lombok.jar file which contains everything." depends="version, compile"> @@ -215,6 +215,7 @@ the common tasks and can be called on to run the main aspects of all the sub-scr <include name="lombok/experimental/**" /> <include name="lombok/extern/**" /> <include name="lombok/launch/**" /> + <include name="lombok/delombok/ant/Tasks*" /> </fileset> <mappedresources> <fileset dir="build/lombok"> @@ -223,6 +224,7 @@ the common tasks and can be called on to run the main aspects of all the sub-scr <exclude name="lombok/experimental/**" /> <exclude name="lombok/extern/**" /> <exclude name="lombok/launch/**" /> + <exclude name="lombok/delombok/ant/Tasks*" /> </fileset> <firstmatchmapper> <globmapper from="*.class" to="*.SCL.lombok" /> @@ -458,7 +460,7 @@ ${sourceWarning}</echo> <echo>WARNING: If you wish to test JDK8 features in eclipse, there must be a JDK8 installation configured in your eclipse, and it must be called 'JavaSE-1.8'.</echo> </target> - <target name="setupJavaOpenJDK6TestEnvironment" depends="contrib" description="Sets up the test so that 'ant test' will test against OpenJDK6."> + <target name="setupJavaOpenJDK6TestEnvironment" depends="ensureTestDeps, contrib" description="Sets up the test so that 'ant test' will test against OpenJDK6."> <mkdir dir="lib/openJDK6Environment" /> <get src="http://projectlombok.org/ivyrepo/langtools/javac-1.6.0.18.jar" dest="lib/openJDK6Environment/javac6.jar" verbose="true" usetimestamp="true" /> <get src="http://projectlombok.org/ivyrepo/langtools/rt-openjdk6.jar" dest="lib/openJDK6Environment/rt-openjdk6.jar" verbose="true" usetimestamp="true" /> @@ -473,7 +475,7 @@ ${sourceWarning}</echo> <antcall target="-createEclipseLaunchForTestEnvironmentIfEclipseProject" /> </target> - <target name="setupJavaOpenJDK7TestEnvironment" depends="contrib" description="Sets up the test so that 'ant test' will test against OpenJDK7."> + <target name="setupJavaOpenJDK7TestEnvironment" depends="ensureTestDeps, contrib" description="Sets up the test so that 'ant test' will test against OpenJDK7."> <mkdir dir="lib/openJDK7Environment" /> <get src="http://projectlombok.org/ivyrepo/langtools/javac-1.7.0.jar" dest="lib/openJDK7Environment/javac7.jar" verbose="true" usetimestamp="true" /> <get src="http://projectlombok.org/ivyrepo/langtools/rt-openjdk7.jar" dest="lib/openJDK7Environment/rt-openjdk7.jar" verbose="true" usetimestamp="true" /> @@ -488,7 +490,7 @@ ${sourceWarning}</echo> <antcall target="-createEclipseLaunchForTestEnvironmentIfEclipseProject" /> </target> - <target name="setupJavaOracle7TestEnvironment" depends="contrib" description="Sets up the test so that 'ant test' will test against OpenJDK7."> + <target name="setupJavaOracle7TestEnvironment" depends="ensureTestDeps, contrib" description="Sets up the test so that 'ant test' will test against OpenJDK7."> <mkdir dir="lib/oracleJDK7Environment" /> <get src="http://projectlombok.org/ivyrepo/langtools/oracle-jdk7-tools.jar" dest="lib/oracleJDK7Environment/tools.jar" verbose="true" usetimestamp="true" /> <get src="http://projectlombok.org/ivyrepo/langtools/oracle-jdk7-rt.jar" dest="lib/oracleJDK7Environment/rt.jar" verbose="true" usetimestamp="true" /> @@ -503,7 +505,7 @@ ${sourceWarning}</echo> <antcall target="-createEclipseLaunchForTestEnvironmentIfEclipseProject" /> </target> - <target name="setupJavaOracle8TestEnvironment" depends="contrib" description="Sets up the test so that 'ant test' will test against OpenJDK8."> + <target name="setupJavaOracle8TestEnvironment" depends="ensureTestDeps, contrib" description="Sets up the test so that 'ant test' will test against OpenJDK8."> <mkdir dir="lib/oracleJDK8Environment" /> <get src="http://projectlombok.org/ivyrepo/langtools/jdk8-javac.jar" dest="lib/oracleJDK8Environment/javac8.jar" verbose="true" usetimestamp="true" /> <get src="http://projectlombok.org/ivyrepo/langtools/oracle-jdk8-rt.jar" dest="lib/oracleJDK8Environment/rt.jar" verbose="true" usetimestamp="true" /> @@ -556,16 +558,7 @@ You can also create your own by writing a 'testenvironment.properties' file. The <classpath path="build/tests" /> <batchtest> <fileset dir="test/core/src"> - <include name="**/Test*.java" /> - </fileset> - <fileset dir="test/transform/src"> - <include name="**/Test*.java" /> - </fileset> - <fileset dir="test/bytecode/src"> - <include name="**/Test*.java" /> - </fileset> - <fileset dir="test/configuration/src"> - <include name="**/Test*.java" /> + <include name="lombok/RunAllTests.java" /> </fileset> </batchtest> </junit> diff --git a/buildScripts/eclipse-run-tests.template b/buildScripts/eclipse-run-tests.template index b7bc8b0d..7c82c7d8 100644 --- a/buildScripts/eclipse-run-tests.template +++ b/buildScripts/eclipse-run-tests.template @@ -18,6 +18,8 @@ <listEntry value="<?xml version="1.0" encoding="UTF-8" standalone="no"?> <runtimeClasspathEntry containerPath="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.@JAVA_VERSION@" path="1" type="4"/> "/> <listEntry value="<?xml version="1.0" encoding="UTF-8" standalone="no"?> <runtimeClasspathEntry internalArchive="/lombok/@ECJ_LOCATION@" path="3" type="2"/> "/> <listEntry value="<?xml version="1.0" encoding="UTF-8" standalone="no"?> <runtimeClasspathEntry internalArchive="/lombok/@JAVAC_LOCATION@" path="3" type="2"/> "/> + <listEntry value="<?xml version="1.0" encoding="UTF-8" standalone="no"?> <runtimeClasspathEntry internalArchive="/lombok/lib/test/com.google.guava-guava.jar" path="3" type="2"/> "/> + <listEntry value="<?xml version="1.0" encoding="UTF-8" standalone="no"?> <runtimeClasspathEntry internalArchive="/lombok/lib/test/com.google.code.findbugs-findbugs.jar" path="3" type="2"/> "/> <listEntry value="<?xml version="1.0" encoding="UTF-8" standalone="no"?> <runtimeClasspathEntry id="org.eclipse.jdt.launching.classpathentry.defaultClasspath"> <memento exportedEntriesOnly="false" project="lombok"/> </runtimeClasspathEntry> "/> </listAttribute> <booleanAttribute key="org.eclipse.jdt.launching.DEFAULT_CLASSPATH" value="false"/> diff --git a/buildScripts/ivy.xml b/buildScripts/ivy.xml index 1cc249e7..61fbbe2d 100644 --- a/buildScripts/ivy.xml +++ b/buildScripts/ivy.xml @@ -24,7 +24,8 @@ <dependency org="commons-logging" name="commons-logging" rev="1.1.1" conf="test->default; contrib->sources"/> <dependency org="org.slf4j" name="slf4j-api" rev="1.6.1" conf="test->default; contrib->sources"/> <dependency org="org.slf4j" name="slf4j-ext" rev="1.6.1" conf="test->default; contrib->sources"/> - <dependency org="com.googlecode.jarjar" name="jarjar" rev="1.1" conf="buildBase->default" /> + <dependency org="com.google.guava" name="guava" rev="18.0" conf="test->default; contrib->sources" /> + <dependency org="com.google.code.findbugs" name="findbugs" rev="3.0.0" conf="test->master" /> <dependency org="org.apache.ant" name="ant" rev="1.8.1" conf="buildBase->default; contrib->sources" /> <dependency org="projectlombok.org" name="spi" rev="0.2.7" conf="buildBase->build" /> diff --git a/buildScripts/website.ant.xml b/buildScripts/website.ant.xml index 6f54c0fd..b7a86cf3 100644 --- a/buildScripts/website.ant.xml +++ b/buildScripts/website.ant.xml @@ -149,10 +149,13 @@ such as converting the changelog into HTML, and creating javadoc. <param name="transformationName" value="NonNull" /> </antcall> <antcall target="-integrateSnippet"> - <param name="transformationName" value="experimental/Delegate" /> + <param name="transformationName" value="Builder" /> + </antcall> + <antcall target="-integrateSnippet"> + <param name="transformationName" value="Singular-snippet" /> </antcall> <antcall target="-integrateSnippet"> - <param name="transformationName" value="experimental/Builder" /> + <param name="transformationName" value="experimental/Delegate" /> </antcall> <antcall target="-integrateSnippet"> <param name="transformationName" value="experimental/Accessors" /> diff --git a/doc/changelog.markdown b/doc/changelog.markdown index e4a004af..4243a9be 100644 --- a/doc/changelog.markdown +++ b/doc/changelog.markdown @@ -1,8 +1,17 @@ Lombok Changelog ---------------- -### v1.14.9.shadow "<del>Edgy</del> Shadowy Guinea Pig" -* Added a launcher to the lombok boot process which removes the need for `-Xbootclasspath` to be in your `eclipse.ini` file, and removes all non-public API and third party dependencies (such as ASM) from the lombok jar, thus removing them from your IDE's auto complete offerings in any project that uses lombok. For those debugging lombok, the launcher enables hot code replace which makes debugging a lot easier, as previously one was required to shut down the IDE, rebuild the jar, and relaunch. Add `-Dshadow.override.lombok=/path/to/lombok/bin` to the launch target for hot code replace. +### v1.16.1 "Edgy Guinea Pig" +* BUGFIX: The ant `delombok` task was broken starting with v1.16.0. Note that the task def class has been changed; taskdef `lombok.delombok.ant.Tasks$Delombok` instead of the old `lombok.delombok.ant.DelombokTask`. [Issue #775](https://code.google.com/p/projectlombok/issues/detail?id=775). +* BUGFIX: `val` in javac would occasionally fail if used inside inner classes. This is (probably) fixed. [Issue #694](https://code.google.com/p/projectlombok/issues/detail?id=694). +* FEATURE: The config key `lombok.extern.findbugs.addSuppressFBWarnings` can now be used to add findbugs suppress warnings annotations to all code lombok generates. This addresses feature request [Issue #702](https://code.google.com/p/projectlombok/issues/detail?id=702). + +### v1.16.0 "Candid Duck" (January 26th, 2015) +* BUGFIX: `@ExtensionMethod` was broken in Eclipse using java 8. [Issue #742](https://code.google.com/p/projectlombok/issues/detail?id=742), [Issue #747](https://code.google.com/p/projectlombok/issues/detail?id=747) +* BUGFIX: delombok: Using exotic characters in your source files would overzealously backslash-u escape them. Now, all characters are printed unescaped, assuming your chosen encoding can support them. Otherwise, they are escaped. [Issue #759](https://code.google.com/p/projectlombok/issues/detail?id=759) +* PROMOTION: `@Builder` has graduated from experimental to the main package with a few changes (addition of `@Singular`, removal of the `fluent` and `chain` options). The old one still exists and has been deprecated. +* FEATURE: `@Builder` now supports adding the `@Singular` annotation to any field/parameter that represents a collection, which results in a method in the generated builder that takes in one element of that collection and adds it. Lombok takes care of generating the appropriate code to produce a compacted immutable version of the appropriate type. In this version, java.util collections and guava's ImmutableCollections are supported. See the [feature documentation](http://projectlombok.org/features/Builder.html) for more information. +* FEATURE: Added a launcher to the lombok boot process which removes the need for `-Xbootclasspath` to be in your `eclipse.ini` file, and removes all non-public API and third party dependencies (such as ASM) from the lombok jar, thus removing them from your IDE's auto complete offerings in any project that uses lombok. For those debugging lombok, the launcher enables hot code replace which makes debugging a lot easier, as previously one was required to shut down the IDE, rebuild the jar, and relaunch. Add `-Dshadow.override.lombok=/path/to/lombok/bin` to the launch target for hot code replace. ### v1.14.8 (September 15th, 2014) * PERFORMANCE: The configuration system typically hit the filesystem twice per read configuration key instead of hardly ever. This is a continuation of [Issue #682](https://code.google.com/p/projectlombok/issues/detail?id=682). diff --git a/src/core/lombok/Builder.java b/src/core/lombok/Builder.java new file mode 100644 index 00000000..9cbd2d58 --- /dev/null +++ b/src/core/lombok/Builder.java @@ -0,0 +1,121 @@ +/* + * Copyright (C) 2013-2014 The Project Lombok Authors. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +package lombok; + +import static java.lang.annotation.ElementType.*; +import static java.lang.annotation.RetentionPolicy.*; + +import java.lang.annotation.Retention; +import java.lang.annotation.Target; + +/** + * The builder annotation creates a so-called 'builder' aspect to the class that is annotated or the class + * that contains a member which is annotated with {@code @Builder}. + * <p> + * If a member is annotated, it must be either a constructor or a static method. If a class is annotated, + * then a private constructor is generated with all fields as arguments + * (as if {@code @AllArgsConstructor(AccessLevel.PRIVATE)} is present + * on the class), and it is as if this constructor has been annotated with {@code @Builder} instead. + * <p> + * The effect of {@code @Builder} is that an inner class is generated named <code><strong>T</strong>Builder</code>, + * with a private constructor. Instances of <code><strong>T</strong>Builder</code> are made with the static + * method named {@code builder()} which is also generated for you in the class itself (not in the builder class). + * <p> + * The <code><strong>T</strong>Builder</code> class contains 1 method for each parameter of the annotated + * constructor / static method (each field, when annotating a class), which returns the builder itself. + * The builder also has a <code>build()</code> method which returns a completed instance of the original type, + * created by passing all parameters as set via the various other methods in the builder to the constructor + * or static method that was annotated with {@code @Builder}. The return type of this method will be the same + * as the relevant class, unless a static method has been annotated, in which case it'll be equal to the + * return type of that method. + * <p> + * Complete documentation is found at <a href="http://projectlombok.org/features/experimental/Builder.html">the project lombok features page for @Builder</a>. + * <p> + * <p> + * Before: + * + * <pre> + * @Builder + * class Example { + * private int foo; + * private final String bar; + * } + * </pre> + * + * After: + * + * <pre> + * class Example<T> { + * private T foo; + * private final String bar; + * + * private Example(T foo, String bar) { + * this.foo = foo; + * this.bar = bar; + * } + * + * public static <T> ExampleBuilder<T> builder() { + * return new ExampleBuilder<T>(); + * } + * + * public static class ExampleBuilder<T> { + * private T foo; + * private String bar; + * + * private ExampleBuilder() {} + * + * public ExampleBuilder foo(T foo) { + * this.foo = foo; + * return this; + * } + * + * public ExampleBuilder bar(String bar) { + * this.bar = bar; + * return this; + * } + * + * @java.lang.Override public String toString() { + * return "ExampleBuilder(foo = " + foo + ", bar = " + bar + ")"; + * } + * + * public Example build() { + * return new Example(foo, bar); + * } + * } + * } + * </pre> + */ +@Target({TYPE, METHOD, CONSTRUCTOR}) +@Retention(SOURCE) +public @interface Builder { + /** Name of the static method that creates a new builder instance. Default: {@code builder}. */ + String builderMethodName() default "builder"; + + /** Name of the instance method in the builder class that creates an instance of your {@code @Builder}-annotated class. */ + String buildMethodName() default "build"; + + /** Name of the builder class. + * Default for {@code @Builder} on types and constructors: {@code (TypeName)Builder}. + * Default for {@code @Builder} on static methods: {@code (ReturnTypeName)Builder}. + */ + String builderClassName() default ""; +} diff --git a/src/core/lombok/ConfigurationKeys.java b/src/core/lombok/ConfigurationKeys.java index 27507657..6c595504 100644 --- a/src/core/lombok/ConfigurationKeys.java +++ b/src/core/lombok/ConfigurationKeys.java @@ -35,6 +35,24 @@ public class ConfigurationKeys { // ##### main package features ##### + // ----- global ----- + + /** + * lombok configuration: {@code lombok.addGeneratedAnnotation} = {@code true} | {@code false}. + * + * If unset or {@code true}, lombok generates {@code @javax.annotation.Generated("lombok")} on all fields, methods, and types that are generated. + */ + public static final ConfigurationKey<Boolean> ADD_GENERATED_ANNOTATIONS = new ConfigurationKey<Boolean>("lombok.addGeneratedAnnotation", "Generate @javax.annotation.Generated on all generated code (default: true).") {}; + + /** + * lombok configuration: {@code lombok.extern.findbugs.addSuppressFBWarnings} = {@code true} | {@code false}. + * + * If {@code true}, lombok generates {@code edu.umd.cs.findbugs.annotations.SuppressFBWarnings} on all fields, methods, and types that are generated. + * + * NB: If you enable this option, findbugs must be on the source or classpath, or you'll get errors that the type {@code SuppressFBWarnings} cannot be found. + */ + public static final ConfigurationKey<Boolean> ADD_FINDBUGS_SUPPRESSWARNINGS_ANNOTATIONS = new ConfigurationKey<Boolean>("lombok.extern.findbugs.addSuppressFBWarnings", "Generate @edu.umd.cs.findbugs.annotations.SuppressFBWArnings on all generated code (default: false).") {}; + // ----- *ArgsConstructor ----- /** @@ -133,9 +151,9 @@ public class ConfigurationKeys { /** * lombok configuration: {@code lombok.equalsAndHashCode.doNotUseGetters} = {@code true} | {@code false}. * - * For any class without an {@code @EqualsAndHashCode} that explicitly defines the {@code doNotUseGetters} option, this value is used. + * For any class without an {@code @EqualsAndHashCode} that explicitly defines the {@code doNotUseGetters} option, this value is used (default = false). */ - public static final ConfigurationKey<Boolean> EQUALS_AND_HASH_CODE_DO_NOT_USE_GETTERS = new ConfigurationKey<Boolean>("lombok.equalsAndHashCode.doNotUseGetters", "Don't call the getters but use the fields directly in the generated equalsAndHashCode method.") {}; + public static final ConfigurationKey<Boolean> EQUALS_AND_HASH_CODE_DO_NOT_USE_GETTERS = new ConfigurationKey<Boolean>("lombok.equalsAndHashCode.doNotUseGetters", "Don't call the getters but use the fields directly in the generated equalsAndHashCode method (default = false).") {}; /** * lombok configuration: {@code lombok.equalsAndHashCode.flagUsage} = {@code WARNING} | {@code ERROR}. @@ -149,9 +167,9 @@ public class ConfigurationKeys { /** * lombok configuration: {@code lombok.toString.doNotUseGetters} = {@code true} | {@code false}. * - * For any class without an {@code @ToString} that explicitly defines the {@code doNotUseGetters} option, this value is used. + * For any class without an {@code @ToString} that explicitly defines the {@code doNotUseGetters} option, this value is used (default = false). */ - public static final ConfigurationKey<Boolean> TO_STRING_DO_NOT_USE_GETTERS = new ConfigurationKey<Boolean>("lombok.toString.doNotUseGetters", "Don't call the getters but use the fields directly in the generated toString method.") {}; + public static final ConfigurationKey<Boolean> TO_STRING_DO_NOT_USE_GETTERS = new ConfigurationKey<Boolean>("lombok.toString.doNotUseGetters", "Don't call the getters but use the fields directly in the generated toString method (default = false).") {}; /** * lombok configuration: {@code lombok.toString.flagUsage} = {@code WARNING} | {@code ERROR}. @@ -163,9 +181,35 @@ public class ConfigurationKeys { /** * lombok configuration: {@code lombok.toString.includeFieldNames} = {@code true} | {@code false}. * - * For any class without an {@code @ToString} that explicitly defines the {@code includeFieldNames} option, this value is used. + * For any class without an {@code @ToString} that explicitly defines the {@code includeFieldNames} option, this value is used (default = true). */ - public static final ConfigurationKey<Boolean> TO_STRING_INCLUDE_FIELD_NAMES = new ConfigurationKey<Boolean>("lombok.toString.includeFieldNames", "Include the field names in the generated toString method.") {}; + public static final ConfigurationKey<Boolean> TO_STRING_INCLUDE_FIELD_NAMES = new ConfigurationKey<Boolean>("lombok.toString.includeFieldNames", "Include the field names in the generated toString method (default = true).") {}; + + // ----- Builder ----- + + /** + * lombok configuration: {@code lombok.builder.flagUsage} = {@code WARNING} | {@code ERROR}. + * + * If set, <em>any</em> usage of {@code @Builder} results in a warning / error. + */ + public static final ConfigurationKey<FlagUsageType> BUILDER_FLAG_USAGE = new ConfigurationKey<FlagUsageType>("lombok.builder.flagUsage", "Emit a warning or error if @Builder is used.") {}; + + // ----- Singular ----- + + /** + * lombok configuration: {@code lombok.singular.useGuava} = {@code true} | {@code false}. + * + * If explicitly set to {@code true}, guava's {@code ImmutableList} etc are used to implement the immutable collection datatypes generated by @Singular @Builder for fields/parameters of type {@code java.util.List} and such. + * By default, unmodifiable-wrapped versions of {@code java.util} types are used. + */ + public static final ConfigurationKey<Boolean> SINGULAR_USE_GUAVA = new ConfigurationKey<Boolean>("lombok.singular.useGuava", "Generate backing immutable implementations for @Singular on java.util.* types by using guava's ImmutableList, etc. Normally java.util's mutable types are used and wrapped to make them immutable.") {}; + + /** + * lombok configuration: {@code lombok.singular.auto} = {@code true} | {@code false}. + * + * By default or if explicitly set to {@code true}, lombok will attempt to automatically singularize the name of your variable/parameter when using {@code @Singular}; the name is assumed to be written in english, and a plural. If explicitly to {@code false}, you must always specify the singular form; this is especially useful if your identifiers are in a foreign language. + */ + public static final ConfigurationKey<Boolean> SINGULAR_AUTO = new ConfigurationKey<Boolean>("lombok.singular.auto", "If true (default): Automatically singularize the assumed-to-be-plural name of your variable/parameter when using {@code @Singular}.") {}; // ##### Standalones ##### @@ -194,7 +238,7 @@ public class ConfigurationKeys { * * Sets the exception to throw if {@code @NonNull} is applied to a method parameter, and a caller passes in {@code null}. */ - public static final ConfigurationKey<NullCheckExceptionType> NON_NULL_EXCEPTION_TYPE = new ConfigurationKey<NullCheckExceptionType>("lombok.nonNull.exceptionType", "The type of the exception to throw if a passed-in argument is null. Default: NullPointerException.") {}; + public static final ConfigurationKey<NullCheckExceptionType> NON_NULL_EXCEPTION_TYPE = new ConfigurationKey<NullCheckExceptionType>("lombok.nonNull.exceptionType", "The type of the exception to throw if a passed-in argument is null (Default: NullPointerException).") {}; /** * lombok configuration: {@code lombok.nonNull.flagUsage} = {@code WARNING} | {@code ERROR}. @@ -289,7 +333,7 @@ public class ConfigurationKeys { * * If set the various log annotations (which make a log field) will use the stated identifier instead of {@code log} as a name. */ - public static final ConfigurationKey<String> LOG_ANY_FIELD_NAME = new ConfigurationKey<String>("lombok.log.fieldName", "Use this name for the generated logger fields (default: 'log')") {}; + public static final ConfigurationKey<String> LOG_ANY_FIELD_NAME = new ConfigurationKey<String>("lombok.log.fieldName", "Use this name for the generated logger fields (default: 'log').") {}; /** * lombok configuration: {@code lombok.log.fieldIsStatic} = {@code true} | {@code false}. @@ -329,25 +373,16 @@ public class ConfigurationKeys { /** * lombok configuration: {@code lombok.accessors.chain} = {@code true} | {@code false}. * - * For any class without an {@code @Accessors} that explicitly defines the {@code chain} option, this value is used. + * For any class without an {@code @Accessors} that explicitly defines the {@code chain} option, this value is used (default = false). */ - public static final ConfigurationKey<Boolean> ACCESSORS_CHAIN = new ConfigurationKey<Boolean>("lombok.accessors.chain", "Generate setters that return 'this' instead of 'void'.") {}; + public static final ConfigurationKey<Boolean> ACCESSORS_CHAIN = new ConfigurationKey<Boolean>("lombok.accessors.chain", "Generate setters that return 'this' instead of 'void' (default: false).") {}; /** * lombok configuration: {@code lombok.accessors.fluent} = {@code true} | {@code false}. * - * For any class without an {@code @Accessors} that explicitly defines the {@code fluent} option, this value is used. + * For any class without an {@code @Accessors} that explicitly defines the {@code fluent} option, this value is used (default = false). */ - public static final ConfigurationKey<Boolean> ACCESSORS_FLUENT = new ConfigurationKey<Boolean>("lombok.accessors.fluent", "Generate getters and setters using only the field name (no get/set prefix).") {}; - - // ----- Builder ----- - - /** - * lombok configuration: {@code lombok.builder.flagUsage} = {@code WARNING} | {@code ERROR}. - * - * If set, <em>any</em> usage of {@code @Builder} results in a warning / error. - */ - public static final ConfigurationKey<FlagUsageType> BUILDER_FLAG_USAGE = new ConfigurationKey<FlagUsageType>("lombok.builder.flagUsage", "Emit a warning or error if @Builder is used.") {}; + public static final ConfigurationKey<Boolean> ACCESSORS_FLUENT = new ConfigurationKey<Boolean>("lombok.accessors.fluent", "Generate getters and setters using only the field name (no get/set prefix) (default: false).") {}; // ----- ExtensionMethod ----- diff --git a/src/core/lombok/Singular.java b/src/core/lombok/Singular.java new file mode 100644 index 00000000..15dec4a5 --- /dev/null +++ b/src/core/lombok/Singular.java @@ -0,0 +1,38 @@ +/* + * Copyright (C) 2015 The Project Lombok Authors. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +package lombok; + +import static java.lang.annotation.ElementType.*; +import static java.lang.annotation.RetentionPolicy.*; + +import java.lang.annotation.Retention; +import java.lang.annotation.Target; + +/** + * The singular annotation is used together with {@code @Builder} to create single element 'add' methods in the builder for collections. + * <p> + */ +@Target({FIELD, PARAMETER}) +@Retention(SOURCE) +public @interface Singular { + String value() default ""; +} diff --git a/src/core/lombok/bytecode/PostCompilerApp.java b/src/core/lombok/bytecode/PostCompilerApp.java index d2c3157c..5f49bd81 100644 --- a/src/core/lombok/bytecode/PostCompilerApp.java +++ b/src/core/lombok/bytecode/PostCompilerApp.java @@ -98,7 +98,7 @@ public class PostCompilerApp extends LombokApp { byte[] original = readFile(file); byte[] clone = original.clone(); byte[] transformed = PostCompiler.applyTransformations(clone, file.toString(), DiagnosticsReceiver.CONSOLE); - if (clone != transformed && !Arrays.equals(clone, transformed)) { + if (clone != transformed && !Arrays.equals(original, transformed)) { filesTouched++; if (args.verbose) System.out.println("Rewriting " + file.getAbsolutePath()); writeFile(file, transformed); @@ -138,18 +138,24 @@ public class PostCompilerApp extends LombokApp { byte[] buffer = new byte[1024]; ByteArrayOutputStream bytes = new ByteArrayOutputStream(); FileInputStream fileInputStream = new FileInputStream(file); - while (true) { - int read = fileInputStream.read(buffer); - if (read == -1) break; - bytes.write(buffer, 0, read); + try { + while (true) { + int read = fileInputStream.read(buffer); + if (read == -1) break; + bytes.write(buffer, 0, read); + } + } finally { + fileInputStream.close(); } - fileInputStream.close(); return bytes.toByteArray(); } static void writeFile(File file, byte[] transformed) throws IOException { FileOutputStream out = new FileOutputStream(file); - out.write(transformed); - out.close(); + try { + out.write(transformed); + } finally { + out.close(); + } } } diff --git a/src/core/lombok/core/GuavaTypeMap.java b/src/core/lombok/core/GuavaTypeMap.java new file mode 100644 index 00000000..900d2b72 --- /dev/null +++ b/src/core/lombok/core/GuavaTypeMap.java @@ -0,0 +1,58 @@ +/* + * Copyright (C) 2015 The Project Lombok Authors. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +package lombok.core; + +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; + +public final class GuavaTypeMap { + private static final Map<String, String> TYPE_TO_GUAVA_TYPE; static { + Map<String, String> m = new HashMap<String, String>(); + + m.put("java.util.NavigableSet", "ImmutableSortedSet"); + m.put("java.util.NavigableMap", "ImmutableSortedMap"); + m.put("java.util.SortedSet", "ImmutableSortedSet"); + m.put("java.util.SortedMap", "ImmutableSortedMap"); + m.put("java.util.Set", "ImmutableSet"); + m.put("java.util.Map", "ImmutableMap"); + m.put("java.util.Collection", "ImmutableList"); + m.put("java.util.List", "ImmutableList"); + + m.put("com.google.common.collect.ImmutableSet", "ImmutableSet"); + m.put("com.google.common.collect.ImmutableSortedSet", "ImmutableSortedSet"); + m.put("com.google.common.collect.ImmutableMap", "ImmutableMap"); + m.put("com.google.common.collect.ImmutableBiMap", "ImmutableBiMap"); + m.put("com.google.common.collect.ImmutableSortedMap", "ImmutableSortedMap"); + m.put("com.google.common.collect.ImmutableList", "ImmutableList"); + m.put("com.google.common.collect.ImmutableCollection", "ImmutableList"); + + TYPE_TO_GUAVA_TYPE = Collections.unmodifiableMap(m); + } + + public static String getGuavaTypeName(String fqn) { + String target = TYPE_TO_GUAVA_TYPE.get(fqn); + return target != null ? target : "ImmutableList"; + } + + private GuavaTypeMap() {} +} diff --git a/src/core/lombok/core/LombokInternalAliasing.java b/src/core/lombok/core/LombokInternalAliasing.java index 8d6794ae..08764a5c 100644 --- a/src/core/lombok/core/LombokInternalAliasing.java +++ b/src/core/lombok/core/LombokInternalAliasing.java @@ -50,6 +50,7 @@ public class LombokInternalAliasing { Map<String, String> m2 = new HashMap<String, String>(); m2.put("lombok.experimental.Value", "lombok.Value"); + m2.put("lombok.experimental.Builder", "lombok.Builder"); m2.put("lombok.Delegate", "lombok.experimental.Delegate"); ALIASES = Collections.unmodifiableMap(m2); } diff --git a/src/core/lombok/core/Main.java b/src/core/lombok/core/Main.java index 0856d3b3..dc613b0d 100644 --- a/src/core/lombok/core/Main.java +++ b/src/core/lombok/core/Main.java @@ -143,7 +143,7 @@ public class Main { out.println("------------------------------"); } out.println("projectlombok.org " + Version.getFullVersion()); - out.println("Copyright (C) 2009-2012 The Project Lombok Authors."); + out.println("Copyright (C) 2009-2015 The Project Lombok Authors."); out.println("Run 'lombok license' to see the lombok license agreement."); out.println(); out.println("Run lombok without any parameters to start the graphical installer."); diff --git a/src/core/lombok/core/TypeLibrary.java b/src/core/lombok/core/TypeLibrary.java index c0e9dc43..dc557c47 100644 --- a/src/core/lombok/core/TypeLibrary.java +++ b/src/core/lombok/core/TypeLibrary.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2009-2013 The Project Lombok Authors. + * Copyright (C) 2009-2015 The Project Lombok Authors. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -37,6 +37,7 @@ import java.util.Map; public class TypeLibrary { private final Map<String, String> unqualifiedToQualifiedMap; private final String unqualified, qualified; + private boolean locked; public TypeLibrary() { unqualifiedToQualifiedMap = new HashMap<String, String>(); @@ -44,6 +45,10 @@ public class TypeLibrary { qualified = null; } + public void lock() { + this.locked = true; + } + private TypeLibrary(String fqnSingleton) { unqualifiedToQualifiedMap = null; qualified = fqnSingleton; @@ -53,6 +58,7 @@ public class TypeLibrary { } else { unqualified = fqnSingleton.substring(idx + 1); } + locked = true; } public static TypeLibrary createLibraryForSingleType(String fqnSingleton) { @@ -65,6 +71,7 @@ public class TypeLibrary { * @param fullyQualifiedTypeName the FQN type name, such as 'java.lang.String'. */ public void addType(String fullyQualifiedTypeName) { + if (locked) throw new IllegalStateException("locked"); fullyQualifiedTypeName = fullyQualifiedTypeName.replace("$", "."); int idx = fullyQualifiedTypeName.lastIndexOf('.'); if (idx == -1) throw new IllegalArgumentException( diff --git a/src/core/lombok/core/Version.java b/src/core/lombok/core/Version.java index 02bc1af0..b0f12916 100644 --- a/src/core/lombok/core/Version.java +++ b/src/core/lombok/core/Version.java @@ -30,9 +30,9 @@ public class Version { // ** CAREFUL ** - this class must always compile with 0 dependencies (it must not refer to any other sources or libraries). // Note: In 'X.Y.Z', if Z is odd, its a snapshot build built from the repository, so many different 0.10.3 versions can exist, for example. // Official builds always end in an even number. (Since 0.10.2). - private static final String VERSION = "1.14.9.shadow"; + private static final String VERSION = "1.16.1"; private static final String RELEASE_NAME = "Edgy Guinea Pig"; -// private static final String RELEASE_NAME = "Branching Cobra"; +// private static final String RELEASE_NAME = "Candid Duck"; private Version() { //Prevent instantiation diff --git a/src/core/lombok/core/handlers/HandlerUtil.java b/src/core/lombok/core/handlers/HandlerUtil.java index 621d8760..87462921 100644 --- a/src/core/lombok/core/handlers/HandlerUtil.java +++ b/src/core/lombok/core/handlers/HandlerUtil.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2013-2014 The Project Lombok Authors. + * Copyright (C) 2013-2015 The Project Lombok Authors. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -87,6 +87,9 @@ public class HandlerUtil { return true; } + public static String autoSingularize(String plural) { + return Singulars.autoSingularize(plural); + } public static void handleFlagUsage(LombokNode<?, ?, ?> node, ConfigurationKey<FlagUsageType> key, String featureName) { FlagUsageType fut = node.getAst().readConfiguration(key); @@ -303,7 +306,7 @@ public class HandlerUtil { return booleanPrefix + fName.substring(2); } - return buildName(isBoolean ? booleanPrefix : normalPrefix, fName); + return buildAccessorName(isBoolean ? booleanPrefix : normalPrefix, fName); } /** @@ -375,8 +378,8 @@ public class HandlerUtil { if (adhereToFluent && fluent) { names.add(baseName); } else { - names.add(buildName(normalPrefix, baseName)); - if (!normalPrefix.equals(booleanPrefix)) names.add(buildName(booleanPrefix, baseName)); + names.add(buildAccessorName(normalPrefix, baseName)); + if (!normalPrefix.equals(booleanPrefix)) names.add(buildAccessorName(booleanPrefix, baseName)); } } @@ -407,7 +410,7 @@ public class HandlerUtil { * @param suffix Something like {@code running}. * @return prefix + smartly title-cased suffix. For example, {@code setRunning}. */ - private static String buildName(String prefix, String suffix) { + public static String buildAccessorName(String prefix, String suffix) { if (suffix.length() == 0) return prefix; if (prefix.length() == 0) return suffix; diff --git a/src/core/lombok/core/handlers/Singulars.java b/src/core/lombok/core/handlers/Singulars.java new file mode 100644 index 00000000..87895790 --- /dev/null +++ b/src/core/lombok/core/handlers/Singulars.java @@ -0,0 +1,86 @@ +/* + * Copyright (C) 2015 The Project Lombok Authors. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +package lombok.core.handlers; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.util.ArrayList; +import java.util.List; + +public class Singulars { + private static final List<String> SINGULAR_STORE; // intended to be immutable. + + static { + SINGULAR_STORE = new ArrayList<String>(); + + try { + InputStream in = Singulars.class.getResourceAsStream("singulars.txt"); + try { + BufferedReader br = new BufferedReader(new InputStreamReader(in, "UTF-8")); + for (String line = br.readLine(); line != null; line = br.readLine()) { + line = line.trim(); + if (line.startsWith("#") || line.isEmpty()) continue; + if (line.endsWith(" =")) { + SINGULAR_STORE.add(line.substring(0, line.length() - 2)); + SINGULAR_STORE.add(""); + continue; + } + + int idx = line.indexOf(" = "); + SINGULAR_STORE.add(line.substring(0, idx)); + SINGULAR_STORE.add(line.substring(idx + 3)); + } + } finally { + try { + in.close(); + } catch (Throwable ignore) {} + } + } catch (IOException e) { + SINGULAR_STORE.clear(); + } + } + + public static String autoSingularize(String in) { + final int inLen = in.length(); + for (int i = 0; i < SINGULAR_STORE.size(); i+= 2) { + final String lastPart = SINGULAR_STORE.get(i); + final boolean wholeWord = Character.isUpperCase(lastPart.charAt(0)); + final int endingOnly = lastPart.charAt(0) == '-' ? 1 : 0; + final int len = lastPart.length(); + if (inLen < len) continue; + if (!in.regionMatches(true, inLen - len + endingOnly, lastPart, endingOnly, len - endingOnly)) continue; + if (wholeWord && inLen != len && !Character.isUpperCase(in.charAt(inLen - len))) continue; + + String replacement = SINGULAR_STORE.get(i + 1); + if (replacement.equals("!")) return null; + + boolean capitalizeFirst = !replacement.isEmpty() && Character.isUpperCase(in.charAt(inLen - len + endingOnly)); + String pre = in.substring(0, inLen - len + endingOnly); + String post = capitalizeFirst ? Character.toUpperCase(replacement.charAt(0)) + replacement.substring(1) : replacement; + return pre + post; + } + + return null; + } +} diff --git a/src/core/lombok/core/handlers/singulars.txt b/src/core/lombok/core/handlers/singulars.txt new file mode 100644 index 00000000..9976c76c --- /dev/null +++ b/src/core/lombok/core/handlers/singulars.txt @@ -0,0 +1,54 @@ +#Based on https://github.com/rails/rails/blob/efff6c1fd4b9e2e4c9f705a45879373cb34a5b0e/activesupport/lib/active_support/inflections.rb + +quizzes = quiz +matrices = matrix +indices = index +vertices = vertex +statuses = status +aliases = alias +alias = ! +species = ! +Axes = ! +-axes = axe +sexes = sex +Testes = testis +movies = movie +octopodes = octopus +buses = bus +Mice = mouse +Lice = louse +News = ! +# We could add more detail (axemen, boatsmen, boogymen, cavemen, gentlemen, etc, but (A) there's stuff like 'cerumen', and (B) the 'men' ending is common in singulars and other languages.) +# Therefore, the odds of a mistake are too high, so other than these 2 well known cases, so force the explicit singular. +Men = man +Women = woman +minutiae = minutia +shoes = shoe +synopses = synopsis +prognoses = prognosis +theses = thesis +diagnoses = diagnosis +bases = base +analyses = analysis +Crises = crisis +children = child +moves = move +zombies = zombie +-quies = quy +-us = ! +-is = ! +series = ! +-ies = y +-oes = o +hives = hive +-tives = tive +-sses = ss +-ches = ch +-xes = x +-shes = sh +-lves = lf +-rves = rf +-ves = fe +-ss = ! +-us = ! +-s = diff --git a/src/core/lombok/eclipse/handlers/EclipseHandlerUtil.java b/src/core/lombok/eclipse/handlers/EclipseHandlerUtil.java index 8326e1d0..836a51c6 100644 --- a/src/core/lombok/eclipse/handlers/EclipseHandlerUtil.java +++ b/src/core/lombok/eclipse/handlers/EclipseHandlerUtil.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2009-2014 The Project Lombok Authors. + * Copyright (C) 2009-2015 The Project Lombok Authors. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -48,6 +48,7 @@ import lombok.core.TypeResolver; import lombok.core.configuration.NullCheckExceptionType; import lombok.core.debug.ProblemReporter; import lombok.core.handlers.HandlerUtil; +import lombok.eclipse.Eclipse; import lombok.eclipse.EclipseAST; import lombok.eclipse.EclipseNode; import lombok.experimental.Accessors; @@ -143,7 +144,7 @@ public class EclipseHandlerUtil { return getGeneratedBy(node) != null; } - public static ASTNode setGeneratedBy(ASTNode node, ASTNode source) { + public static <T extends ASTNode> T setGeneratedBy(T node, ASTNode source) { ASTNode_generatedBy.set(node, source); return node; } @@ -201,6 +202,7 @@ public class EclipseHandlerUtil { public static void sanityCheckForMethodGeneratingAnnotationsOnBuilderClass(EclipseNode typeNode, EclipseNode errorNode) { List<String> disallowed = null; for (EclipseNode child : typeNode.down()) { + if (child.getKind() != Kind.ANNOTATION) continue; for (Class<? extends java.lang.annotation.Annotation> annType : INVALID_ON_BUILDERS) { if (annotationTypeMatches(annType, child)) { if (disallowed == null) disallowed = new ArrayList<String>(); @@ -298,6 +300,10 @@ public class EclipseHandlerUtil { return new SingleTypeReference(typeName, p); } + public static TypeReference[] copyTypes(TypeReference[] refs) { + return copyTypes(refs, null); + } + /** * Convenience method that creates a new array and copies each TypeReference in the source array via * {@link #copyType(TypeReference, ASTNode)}. @@ -312,6 +318,10 @@ public class EclipseHandlerUtil { return outs; } + public static TypeReference copyType(TypeReference ref) { + return copyType(ref, null); + } + /** * You can't share TypeReference objects or subtle errors start happening. * Unfortunately the TypeReference type hierarchy is complicated and there's no clone @@ -336,22 +346,23 @@ public class EclipseHandlerUtil { } } } + TypeReference typeRef = new ParameterizedQualifiedTypeReference(iRef.tokens, args, iRef.dimensions(), copy(iRef.sourcePositions)); - setGeneratedBy(typeRef, source); + if (source != null) setGeneratedBy(typeRef, source); return typeRef; } if (ref instanceof ArrayQualifiedTypeReference) { ArrayQualifiedTypeReference iRef = (ArrayQualifiedTypeReference) ref; TypeReference typeRef = new ArrayQualifiedTypeReference(iRef.tokens, iRef.dimensions(), copy(iRef.sourcePositions)); - setGeneratedBy(typeRef, source); + if (source != null) setGeneratedBy(typeRef, source); return typeRef; } if (ref instanceof QualifiedTypeReference) { QualifiedTypeReference iRef = (QualifiedTypeReference) ref; TypeReference typeRef = new QualifiedTypeReference(iRef.tokens, copy(iRef.sourcePositions)); - setGeneratedBy(typeRef, source); + if (source != null) setGeneratedBy(typeRef, source); return typeRef; } @@ -368,14 +379,14 @@ public class EclipseHandlerUtil { } TypeReference typeRef = new ParameterizedSingleTypeReference(iRef.token, args, iRef.dimensions(), (long)iRef.sourceStart << 32 | iRef.sourceEnd); - setGeneratedBy(typeRef, source); + if (source != null) setGeneratedBy(typeRef, source); return typeRef; } if (ref instanceof ArrayTypeReference) { ArrayTypeReference iRef = (ArrayTypeReference) ref; TypeReference typeRef = new ArrayTypeReference(iRef.token, iRef.dimensions(), (long)iRef.sourceStart << 32 | iRef.sourceEnd); - setGeneratedBy(typeRef, source); + if (source != null) setGeneratedBy(typeRef, source); return typeRef; } @@ -386,14 +397,14 @@ public class EclipseHandlerUtil { wildcard.sourceStart = original.sourceStart; wildcard.sourceEnd = original.sourceEnd; if (original.bound != null) wildcard.bound = copyType(original.bound, source); - setGeneratedBy(wildcard, source); + if (source != null) setGeneratedBy(wildcard, source); return wildcard; } if (ref instanceof SingleTypeReference) { SingleTypeReference iRef = (SingleTypeReference) ref; TypeReference typeRef = new SingleTypeReference(iRef.token, (long)iRef.sourceStart << 32 | iRef.sourceEnd); - setGeneratedBy(typeRef, source); + if (source != null) setGeneratedBy(typeRef, source); return typeRef; } @@ -401,19 +412,17 @@ public class EclipseHandlerUtil { } public static Annotation[] copyAnnotations(ASTNode source, Annotation[]... allAnnotations) { - boolean allNull = true; - - List<Annotation> result = new ArrayList<Annotation>(); + List<Annotation> result = null; for (Annotation[] annotations : allAnnotations) { if (annotations != null) { - allNull = false; for (Annotation annotation : annotations) { + if (result == null) result = new ArrayList<Annotation>(); result.add(copyAnnotation(annotation, source)); } } } - if (allNull) return null; - return result.toArray(new Annotation[0]); + + return result == null ? null : result.toArray(new Annotation[0]); } public static boolean hasAnnotation(Class<? extends java.lang.annotation.Annotation> type, EclipseNode node) { @@ -444,8 +453,12 @@ public class EclipseHandlerUtil { return typeMatches(type, node, ((Annotation)node.get()).type); } + public static TypeReference cloneSelfType(EclipseNode context) { + return cloneSelfType(context, null); + } + public static TypeReference cloneSelfType(EclipseNode context, ASTNode source) { - int pS = source.sourceStart, pE = source.sourceEnd; + int pS = source == null ? 0 : source.sourceStart, pE = source == null ? 0 : source.sourceEnd; long p = (long)pS << 32 | pE; EclipseNode type = context; TypeReference result = null; @@ -457,7 +470,7 @@ public class EclipseHandlerUtil { int idx = 0; for (TypeParameter param : typeDecl.typeParameters) { TypeReference typeRef = new SingleTypeReference(param.name, (long)param.sourceStart << 32 | param.sourceEnd); - setGeneratedBy(typeRef, source); + if (source != null) setGeneratedBy(typeRef, source); refs[idx++] = typeRef; } result = new ParameterizedSingleTypeReference(typeDecl.name, refs, 0, p); @@ -465,7 +478,7 @@ public class EclipseHandlerUtil { result = new SingleTypeReference(((TypeDeclaration)type.get()).name, p); } } - if (result != null) setGeneratedBy(result, source); + if (result != null && source != null) setGeneratedBy(result, source); return result; } @@ -668,47 +681,39 @@ public class EclipseHandlerUtil { */ public static <A extends java.lang.annotation.Annotation> AnnotationValues<A> createAnnotation(Class<A> type, final EclipseNode annotationNode) { + final Annotation annotation = (Annotation) annotationNode.get(); Map<String, AnnotationValue> values = new HashMap<String, AnnotationValue>(); - final MemberValuePair[] pairs = annotation.memberValuePairs(); - for (Method m : type.getDeclaredMethods()) { - if (!Modifier.isPublic(m.getModifiers())) continue; - String name = m.getName(); + MemberValuePair[] memberValuePairs = annotation.memberValuePairs(); + + if (memberValuePairs != null) for (final MemberValuePair pair : memberValuePairs) { List<String> raws = new ArrayList<String>(); List<Object> expressionValues = new ArrayList<Object>(); List<Object> guesses = new ArrayList<Object>(); - Expression fullExpression = null; Expression[] expressions = null; - if (pairs != null) for (MemberValuePair pair : pairs) { - char[] n = pair.name; - String mName = n == null ? "value" : new String(pair.name); - if (mName.equals(name)) fullExpression = pair.value; + char[] n = pair.name; + String mName = (n == null || n.length == 0) ? "value" : new String(pair.name); + final Expression rhs = pair.value; + if (rhs instanceof ArrayInitializer) { + expressions = ((ArrayInitializer)rhs).expressions; + } else if (rhs != null) { + expressions = new Expression[] { rhs }; } - - boolean isExplicit = fullExpression != null; - - if (isExplicit) { - if (fullExpression instanceof ArrayInitializer) { - expressions = ((ArrayInitializer)fullExpression).expressions; - } else expressions = new Expression[] { fullExpression }; - if (expressions != null) for (Expression ex : expressions) { - StringBuffer sb = new StringBuffer(); - ex.print(0, sb); - raws.add(sb.toString()); - expressionValues.add(ex); - guesses.add(calculateValue(ex)); - } + if (expressions != null) for (Expression ex : expressions) { + StringBuffer sb = new StringBuffer(); + ex.print(0, sb); + raws.add(sb.toString()); + expressionValues.add(ex); + guesses.add(calculateValue(ex)); } - final Expression fullExpr = fullExpression; final Expression[] exprs = expressions; - - values.put(name, new AnnotationValue(annotationNode, raws, expressionValues, guesses, isExplicit) { + values.put(mName, new AnnotationValue(annotationNode, raws, expressionValues, guesses, true) { @Override public void setError(String message, int valueIdx) { Expression ex; - if (valueIdx == -1) ex = fullExpr; + if (valueIdx == -1) ex = rhs; else ex = exprs != null ? exprs[valueIdx] : null; if (ex == null) ex = annotation; @@ -721,7 +726,7 @@ public class EclipseHandlerUtil { @Override public void setWarning(String message, int valueIdx) { Expression ex; - if (valueIdx == -1) ex = fullExpr; + if (valueIdx == -1) ex = rhs; else ex = exprs != null ? exprs[valueIdx] : null; if (ex == null) ex = annotation; @@ -734,6 +739,21 @@ public class EclipseHandlerUtil { }); } + for (Method m : type.getDeclaredMethods()) { + if (!Modifier.isPublic(m.getModifiers())) continue; + String name = m.getName(); + if (!values.containsKey(name)) { + values.put(name, new AnnotationValue(annotationNode, new ArrayList<String>(), new ArrayList<Object>(), new ArrayList<Object>(), false) { + @Override public void setError(String message, int valueIdx) { + annotationNode.addError(message); + } + @Override public void setWarning(String message, int valueIdx) { + annotationNode.addWarning(message); + } + }); + } + } + return new AnnotationValues<A>(type, values, annotationNode); } @@ -865,7 +885,7 @@ public class EclipseHandlerUtil { } static Expression createFieldAccessor(EclipseNode field, FieldAccess fieldAccess, ASTNode source) { - int pS = source.sourceStart, pE = source.sourceEnd; + int pS = source == null ? 0 : source.sourceStart, pE = source == null ? 0 : source.sourceEnd; long p = (long)pS << 32 | pE; boolean lookForGetter = lookForGetter(field, fieldAccess); @@ -881,14 +901,17 @@ public class EclipseHandlerUtil { ref.receiver = new SingleNameReference(((TypeDeclaration)containerNode.get()).name, p); } else { Expression smallRef = new FieldReference(field.getName().toCharArray(), p); - setGeneratedBy(smallRef, source); + if (source != null) setGeneratedBy(smallRef, source); return smallRef; } } else { ref.receiver = new ThisReference(pS, pE); } - setGeneratedBy(ref, source); - setGeneratedBy(ref.receiver, source); + + if (source != null) { + setGeneratedBy(ref, source); + setGeneratedBy(ref.receiver, source); + } return ref; } @@ -1191,8 +1214,9 @@ public class EclipseHandlerUtil { * Inserts a field into an existing type. The type must represent a {@code TypeDeclaration}. * The field carries the @{@link SuppressWarnings}("all") annotation. */ - public static EclipseNode injectFieldSuppressWarnings(EclipseNode type, FieldDeclaration field) { - field.annotations = createSuppressWarningsAll(field, field.annotations); + public static EclipseNode injectFieldAndMarkGenerated(EclipseNode type, FieldDeclaration field) { + field.annotations = addSuppressWarningsAll(type, field, field.annotations); + field.annotations = addGenerated(type, field, field.annotations); return injectField(type, field); } @@ -1237,7 +1261,8 @@ public class EclipseHandlerUtil { * Inserts a method into an existing type. The type must represent a {@code TypeDeclaration}. */ public static EclipseNode injectMethod(EclipseNode type, AbstractMethodDeclaration method) { - method.annotations = createSuppressWarningsAll(method, method.annotations); + method.annotations = addSuppressWarningsAll(type, method, method.annotations); + method.annotations = addGenerated(type, method, method.annotations); TypeDeclaration parent = (TypeDeclaration) type.get(); if (parent.methods == null) { @@ -1279,9 +1304,10 @@ public class EclipseHandlerUtil { * @param type New type (class, interface, etc) to inject. */ public static EclipseNode injectType(final EclipseNode typeNode, final TypeDeclaration type) { - type.annotations = createSuppressWarningsAll(type, type.annotations); + type.annotations = addSuppressWarningsAll(typeNode, type, type.annotations); + type.annotations = addGenerated(typeNode, type, type.annotations); TypeDeclaration parent = (TypeDeclaration) typeNode.get(); - + if (parent.memberTypes == null) { parent.memberTypes = new TypeDeclaration[] { type }; } else { @@ -1295,8 +1321,31 @@ public class EclipseHandlerUtil { } private static final char[] ALL = "all".toCharArray(); + private static final char[] JUSTIFICATION = "justification".toCharArray(); + private static final char[] GENERATED_CODE = "generated code".toCharArray(); + private static final char[] LOMBOK = "lombok".toCharArray(); + private static final char[][] JAVAX_ANNOTATION_GENERATED = Eclipse.fromQualifiedName("javax.annotation.Generated"); + private static final char[][] EDU_UMD_CS_FINDBUGS_ANNOTATIONS_SUPPRESSFBWARNINGS = Eclipse.fromQualifiedName("edu.umd.cs.findbugs.annotations.SuppressFBWarnings"); + + public static Annotation[] addSuppressWarningsAll(EclipseNode node, ASTNode source, Annotation[] originalAnnotationArray) { + Annotation[] anns = addAnnotation(source, originalAnnotationArray, TypeConstants.JAVA_LANG_SUPPRESSWARNINGS, new StringLiteral(ALL, 0, 0, 0)); + + if (Boolean.TRUE.equals(node.getAst().readConfiguration(ConfigurationKeys.ADD_FINDBUGS_SUPPRESSWARNINGS_ANNOTATIONS))) { + MemberValuePair mvp = new MemberValuePair(JUSTIFICATION, 0, 0, new StringLiteral(GENERATED_CODE, 0, 0, 0)); + anns = addAnnotation(source, anns, EDU_UMD_CS_FINDBUGS_ANNOTATIONS_SUPPRESSFBWARNINGS, mvp); + } + + return anns; + } + + public static Annotation[] addGenerated(EclipseNode node, ASTNode source, Annotation[] originalAnnotationArray) { + if (Boolean.FALSE.equals(node.getAst().readConfiguration(ConfigurationKeys.ADD_GENERATED_ANNOTATIONS))) return originalAnnotationArray; + return addAnnotation(source, originalAnnotationArray, JAVAX_ANNOTATION_GENERATED, new StringLiteral(LOMBOK, 0, 0, 0)); + } - public static Annotation[] createSuppressWarningsAll(ASTNode source, Annotation[] originalAnnotationArray) { + private static Annotation[] addAnnotation(ASTNode source, Annotation[] originalAnnotationArray, char[][] annotationTypeFqn, ASTNode arg) { + char[] simpleName = annotationTypeFqn[annotationTypeFqn.length - 1]; + if (originalAnnotationArray != null) for (Annotation ann : originalAnnotationArray) { char[] lastToken = null; @@ -1307,20 +1356,41 @@ public class EclipseHandlerUtil { lastToken = ((SingleTypeReference) ann.type).token; } - if (lastToken != null && new String(lastToken).equals("SuppressWarnings")) return originalAnnotationArray; + if (lastToken != null && Arrays.equals(simpleName, lastToken)) return originalAnnotationArray; } int pS = source.sourceStart, pE = source.sourceEnd; long p = (long)pS << 32 | pE; - long[] poss = new long[3]; + long[] poss = new long[annotationTypeFqn.length]; Arrays.fill(poss, p); - QualifiedTypeReference suppressWarningsType = new QualifiedTypeReference(TypeConstants.JAVA_LANG_SUPPRESSWARNINGS, poss); - setGeneratedBy(suppressWarningsType, source); - SingleMemberAnnotation ann = new SingleMemberAnnotation(suppressWarningsType, pS); - ann.declarationSourceEnd = pE; - ann.memberValue = new StringLiteral(ALL, pS, pE, 0); + QualifiedTypeReference qualifiedType = new QualifiedTypeReference(annotationTypeFqn, poss); + setGeneratedBy(qualifiedType, source); + Annotation ann; + if (arg instanceof Expression) { + SingleMemberAnnotation sma = new SingleMemberAnnotation(qualifiedType, pS); + sma.declarationSourceEnd = pE; + arg.sourceStart = pS; + arg.sourceEnd = pE; + sma.memberValue = (Expression) arg; + setGeneratedBy(sma.memberValue, source); + ann = sma; + } else if (arg instanceof MemberValuePair) { + NormalAnnotation na = new NormalAnnotation(qualifiedType, pS); + na.declarationSourceEnd = pE; + arg.sourceStart = pS; + arg.sourceEnd = pE; + na.memberValuePairs = new MemberValuePair[] {(MemberValuePair) arg}; + setGeneratedBy(na.memberValuePairs[0], source); + setGeneratedBy(na.memberValuePairs[0].value, source); + na.memberValuePairs[0].value.sourceStart = pS; + na.memberValuePairs[0].value.sourceEnd = pE; + ann = na; + } else { + MarkerAnnotation ma = new MarkerAnnotation(qualifiedType, pS); + ma.declarationSourceEnd = pE; + ann = ma; + } setGeneratedBy(ann, source); - setGeneratedBy(ann.memberValue, source); if (originalAnnotationArray == null) return new Annotation[] { ann }; Annotation[] newAnnotationArray = new Annotation[originalAnnotationArray.length + 1]; System.arraycopy(originalAnnotationArray, 0, newAnnotationArray, 0, originalAnnotationArray.length); @@ -1489,7 +1559,7 @@ public class EclipseHandlerUtil { * with eclipse versions before 3.7. */ public static IntLiteral makeIntLiteral(char[] token, ASTNode source) { - int pS = source.sourceStart, pE = source.sourceEnd; + int pS = source == null ? 0 : source.sourceStart, pE = source == null ? 0 : source.sourceEnd; IntLiteral result; try { if (intLiteralConstructor != null) { @@ -1504,7 +1574,8 @@ public class EclipseHandlerUtil { } catch (InstantiationException e) { throw Lombok.sneakyThrow(e); } - setGeneratedBy(result, source); + + if (source != null) setGeneratedBy(result, source); return result; } diff --git a/src/core/lombok/eclipse/handlers/EclipseSingularsRecipes.java b/src/core/lombok/eclipse/handlers/EclipseSingularsRecipes.java new file mode 100644 index 00000000..4cb41d4f --- /dev/null +++ b/src/core/lombok/eclipse/handlers/EclipseSingularsRecipes.java @@ -0,0 +1,345 @@ +/* + * Copyright (C) 2015 The Project Lombok Authors. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +package lombok.eclipse.handlers; + +import static lombok.eclipse.handlers.EclipseHandlerUtil.*; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.eclipse.jdt.internal.compiler.ast.ASTNode; +import org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration; +import org.eclipse.jdt.internal.compiler.ast.ConditionalExpression; +import org.eclipse.jdt.internal.compiler.ast.EqualExpression; +import org.eclipse.jdt.internal.compiler.ast.Expression; +import org.eclipse.jdt.internal.compiler.ast.FieldDeclaration; +import org.eclipse.jdt.internal.compiler.ast.FieldReference; +import org.eclipse.jdt.internal.compiler.ast.IntLiteral; +import org.eclipse.jdt.internal.compiler.ast.MessageSend; +import org.eclipse.jdt.internal.compiler.ast.NullLiteral; +import org.eclipse.jdt.internal.compiler.ast.OperatorIds; +import org.eclipse.jdt.internal.compiler.ast.ParameterizedQualifiedTypeReference; +import org.eclipse.jdt.internal.compiler.ast.ParameterizedSingleTypeReference; +import org.eclipse.jdt.internal.compiler.ast.QualifiedTypeReference; +import org.eclipse.jdt.internal.compiler.ast.SingleTypeReference; +import org.eclipse.jdt.internal.compiler.ast.Statement; +import org.eclipse.jdt.internal.compiler.ast.ThisReference; +import org.eclipse.jdt.internal.compiler.ast.TypeReference; +import org.eclipse.jdt.internal.compiler.ast.Wildcard; +import org.eclipse.jdt.internal.compiler.lookup.ClassScope; +import org.eclipse.jdt.internal.compiler.lookup.MethodScope; +import org.eclipse.jdt.internal.compiler.lookup.TypeConstants; + +import lombok.core.LombokImmutableList; +import lombok.core.SpiLoadUtil; +import lombok.core.TypeLibrary; +import lombok.eclipse.EclipseNode; + +public class EclipseSingularsRecipes { + private static final EclipseSingularsRecipes INSTANCE = new EclipseSingularsRecipes(); + private final Map<String, EclipseSingularizer> singularizers = new HashMap<String, EclipseSingularizer>(); + private final TypeLibrary singularizableTypes = new TypeLibrary(); + + private EclipseSingularsRecipes() { + try { + loadAll(singularizableTypes, singularizers); + singularizableTypes.lock(); + } catch (IOException e) { + System.err.println("Lombok's @Singularizable feature is broken due to misconfigured SPI files: " + e); + } + } + + private static void loadAll(TypeLibrary library, Map<String, EclipseSingularizer> map) throws IOException { + for (EclipseSingularizer handler : SpiLoadUtil.findServices(EclipseSingularizer.class, EclipseSingularizer.class.getClassLoader())) { + for (String type : handler.getSupportedTypes()) { + EclipseSingularizer existingSingularizer = map.get(type); + if (existingSingularizer != null) { + EclipseSingularizer toKeep = existingSingularizer.getClass().getName().compareTo(handler.getClass().getName()) > 0 ? handler : existingSingularizer; + System.err.println("Multiple singularizers found for type " + type + "; the alphabetically first class is used: " + toKeep.getClass().getName()); + map.put(type, toKeep); + } else { + map.put(type, handler); + library.addType(type); + } + } + } + } + + public static EclipseSingularsRecipes get() { + return INSTANCE; + } + + public String toQualified(String typeReference) { + return singularizableTypes.toQualified(typeReference); + } + + public EclipseSingularizer getSingularizer(String fqn) { + return singularizers.get(fqn); + } + + public static final class SingularData { + private final EclipseNode annotation; + private final char[] singularName; + private final char[] pluralName; + private final List<TypeReference> typeArgs; + private final String targetFqn; + private final EclipseSingularizer singularizer; + private final ASTNode source; + + public SingularData(EclipseNode annotation, char[] singularName, char[] pluralName, List<TypeReference> typeArgs, String targetFqn, EclipseSingularizer singularizer, ASTNode source) { + this.annotation = annotation; + this.singularName = singularName; + this.pluralName = pluralName; + this.typeArgs = typeArgs; + this.targetFqn = targetFqn; + this.singularizer = singularizer; + this.source = source; + } + + public void setGeneratedByRecursive(ASTNode target) { + SetGeneratedByVisitor visitor = new SetGeneratedByVisitor(source); + + if (target instanceof AbstractMethodDeclaration) { + ((AbstractMethodDeclaration) target).traverse(visitor, (ClassScope) null); + } else if (target instanceof FieldDeclaration) { + ((FieldDeclaration) target).traverse(visitor, (MethodScope) null); + } else { + target.traverse(visitor, null); + } + } + + public EclipseNode getAnnotation() { + return annotation; + } + + public char[] getSingularName() { + return singularName; + } + + public char[] getPluralName() { + return pluralName; + } + + public List<TypeReference> getTypeArgs() { + return typeArgs; + } + + public String getTargetFqn() { + return targetFqn; + } + + public EclipseSingularizer getSingularizer() { + return singularizer; + } + + public String getTargetSimpleType() { + int idx = targetFqn.lastIndexOf("."); + return idx == -1 ? targetFqn : targetFqn.substring(idx + 1); + } + } + + public static abstract class EclipseSingularizer { + protected static final long[] NULL_POSS = {0L}; + public abstract LombokImmutableList<String> getSupportedTypes(); + + /** Checks if any of the to-be-generated nodes (fields, methods) already exist. If so, errors on these (singulars don't support manually writing some of it, and returns true). */ + public boolean checkForAlreadyExistingNodesAndGenerateError(EclipseNode builderType, SingularData data) { + for (EclipseNode child : builderType.down()) { + switch (child.getKind()) { + case FIELD: { + FieldDeclaration fd = (FieldDeclaration) child.get(); + char[] name = fd.name; + if (name == null) continue; + if (getGeneratedBy(fd) != null) continue; + for (char[] fieldToBeGenerated : listFieldsToBeGenerated(data, builderType)) { + if (!Arrays.equals(name, fieldToBeGenerated)) continue; + child.addError("Manually adding a field that @Singular @Builder would generate is not supported. If you want to manually manage the builder aspect for this field/parameter, don't use @Singular."); + return true; + } + break; + } + case METHOD: { + AbstractMethodDeclaration method = (AbstractMethodDeclaration) child.get(); + char[] name = method.selector; + if (name == null) continue; + if (getGeneratedBy(method) != null) continue; + for (char[] methodToBeGenerated : listMethodsToBeGenerated(data, builderType)) { + if (!Arrays.equals(name, methodToBeGenerated)) continue; + child.addError("Manually adding a method that @Singular @Builder would generate is not supported. If you want to manually manage the builder aspect for this field/parameter, don't use @Singular."); + return true; + } + break; + }} + } + + return false; + } + + public List<char[]> listFieldsToBeGenerated(SingularData data, EclipseNode builderType) { + return Collections.singletonList(data.pluralName); + } + + public List<char[]> listMethodsToBeGenerated(SingularData data, EclipseNode builderType) { + char[] p = data.pluralName; + char[] s = data.singularName; + if (Arrays.equals(p, s)) return Collections.singletonList(p); + return Arrays.asList(p, s); + } + + public abstract List<EclipseNode> generateFields(SingularData data, EclipseNode builderType); + public abstract void generateMethods(SingularData data, EclipseNode builderType, boolean fluent, boolean chain); + public abstract void appendBuildCode(SingularData data, EclipseNode builderType, List<Statement> statements, char[] targetVariableName); + + public boolean requiresCleaning() { + try { + return !getClass().getMethod("appendCleaningCode", SingularData.class, EclipseNode.class, List.class).getDeclaringClass().equals(EclipseSingularizer.class); + } catch (NoSuchMethodException e) { + return false; + } + } + + public void appendCleaningCode(SingularData data, EclipseNode builderType, List<Statement> statements) { + } + + // -- Utility methods -- + + /** + * Adds the requested number of type arguments to the provided type, copying each argument in {@code typeArgs}. If typeArgs is too long, the extra elements are ignored. + * If {@code typeArgs} is null or too short, {@code java.lang.Object} will be substituted for each missing type argument. + * + * @param count The number of type arguments requested. + * @param addExtends If {@code true}, all bounds are either '? extends X' or just '?'. If false, the reverse is applied, and '? extends Foo' is converted to Foo, '?' to Object, etc. + * @param node Some node in the same AST. Just used to obtain makers and contexts and such. + * @param type The type to add generics to. + * @param typeArgs the list of type args to clone. + * @param source The source annotation that is the root cause of this code generation. + */ + protected TypeReference addTypeArgs(int count, boolean addExtends, EclipseNode node, TypeReference type, List<TypeReference> typeArgs) { + TypeReference[] clonedAndFixedArgs = createTypeArgs(count, addExtends, node, typeArgs); + if (type instanceof SingleTypeReference) { + type = new ParameterizedSingleTypeReference(((SingleTypeReference) type).token, clonedAndFixedArgs, 0, 0L); + } else if (type instanceof QualifiedTypeReference) { + QualifiedTypeReference qtr = (QualifiedTypeReference) type; + TypeReference[][] trs = new TypeReference[qtr.tokens.length][]; + trs[qtr.tokens.length - 1] = clonedAndFixedArgs; + type = new ParameterizedQualifiedTypeReference(((QualifiedTypeReference) type).tokens, trs, 0, NULL_POSS); + } else { + node.addError("Don't know how to clone-and-parameterize type: " + type); + } + + return type; + } + + protected TypeReference[] createTypeArgs(int count, boolean addExtends, EclipseNode node, List<TypeReference> typeArgs) { + if (count < 0) throw new IllegalArgumentException("count is negative"); + if (count == 0) return null; + List<TypeReference> arguments = new ArrayList<TypeReference>(); + + if (typeArgs != null) for (TypeReference orig : typeArgs) { + Wildcard wildcard = orig instanceof Wildcard ? (Wildcard) orig : null; + if (!addExtends) { + if (wildcard != null && (wildcard.kind == Wildcard.UNBOUND || wildcard.kind == Wildcard.SUPER)) { + arguments.add(new QualifiedTypeReference(TypeConstants.JAVA_LANG_OBJECT, NULL_POSS)); + } else if (wildcard != null && wildcard.kind == Wildcard.EXTENDS) { + try { + arguments.add(copyType(wildcard.bound)); + } catch (Exception e) { + arguments.add(new QualifiedTypeReference(TypeConstants.JAVA_LANG_OBJECT, NULL_POSS)); + } + } else { + arguments.add(copyType(orig)); + } + } else { + if (wildcard != null && (wildcard.kind == Wildcard.UNBOUND || wildcard.kind == Wildcard.SUPER)) { + Wildcard w = new Wildcard(Wildcard.UNBOUND); + arguments.add(w); + } else if (wildcard != null && wildcard.kind == Wildcard.EXTENDS) { + arguments.add(copyType(orig)); + } else { + Wildcard w = new Wildcard(Wildcard.EXTENDS); + w.bound = copyType(orig); + arguments.add(w); + } + } + if (--count == 0) break; + } + + while (count-- > 0) { + if (addExtends) { + arguments.add(new Wildcard(Wildcard.UNBOUND)); + } else { + arguments.add(new QualifiedTypeReference(TypeConstants.JAVA_LANG_OBJECT, NULL_POSS)); + } + } + + if (arguments.isEmpty()) return null; + return arguments.toArray(new TypeReference[arguments.size()]); + } + + private static final char[] SIZE_TEXT = new char[] {'s', 'i', 'z', 'e'}; + + /** Generates 'this.<em>name</em>.size()' as an expression; if nullGuard is true, it's this.name == null ? 0 : this.name.size(). */ + protected Expression getSize(EclipseNode builderType, char[] name, boolean nullGuard) { + MessageSend invoke = new MessageSend(); + ThisReference thisRef = new ThisReference(0, 0); + FieldReference thisDotName = new FieldReference(name, 0L); + thisDotName.receiver = thisRef; + invoke.receiver = thisDotName; + invoke.selector = SIZE_TEXT; + if (!nullGuard) return invoke; + + ThisReference cdnThisRef = new ThisReference(0, 0); + FieldReference cdnThisDotName = new FieldReference(name, 0L); + cdnThisDotName.receiver = cdnThisRef; + NullLiteral nullLiteral = new NullLiteral(0, 0); + EqualExpression isNull = new EqualExpression(cdnThisDotName, nullLiteral, OperatorIds.EQUAL_EQUAL); + IntLiteral zeroLiteral = makeIntLiteral(new char[] {'0'}, null); + ConditionalExpression conditional = new ConditionalExpression(isNull, zeroLiteral, invoke); + return conditional; + } + + protected TypeReference cloneParamType(int index, List<TypeReference> typeArgs, EclipseNode builderType) { + if (typeArgs != null && typeArgs.size() > index) { + TypeReference originalType = typeArgs.get(index); + if (originalType instanceof Wildcard) { + Wildcard wOriginalType = (Wildcard) originalType; + if (wOriginalType.kind == Wildcard.EXTENDS) { + try { + return copyType(wOriginalType.bound); + } catch (Exception e) { + // fallthrough + } + } + } else { + return copyType(originalType); + } + } + + return new QualifiedTypeReference(TypeConstants.JAVA_LANG_OBJECT, NULL_POSS); + } + } +} diff --git a/src/core/lombok/eclipse/handlers/HandleBuilder.java b/src/core/lombok/eclipse/handlers/HandleBuilder.java index 522501f6..45f4342e 100644 --- a/src/core/lombok/eclipse/handlers/HandleBuilder.java +++ b/src/core/lombok/eclipse/handlers/HandleBuilder.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2013-2014 The Project Lombok Authors. + * Copyright (C) 2013-2015 The Project Lombok Authors. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -32,50 +32,87 @@ import java.util.List; import org.eclipse.jdt.internal.compiler.ast.ASTNode; import org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration; +import org.eclipse.jdt.internal.compiler.ast.AbstractVariableDeclaration; import org.eclipse.jdt.internal.compiler.ast.AllocationExpression; import org.eclipse.jdt.internal.compiler.ast.Annotation; import org.eclipse.jdt.internal.compiler.ast.Argument; +import org.eclipse.jdt.internal.compiler.ast.Assignment; import org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration; import org.eclipse.jdt.internal.compiler.ast.ConstructorDeclaration; import org.eclipse.jdt.internal.compiler.ast.Expression; +import org.eclipse.jdt.internal.compiler.ast.FalseLiteral; import org.eclipse.jdt.internal.compiler.ast.FieldDeclaration; +import org.eclipse.jdt.internal.compiler.ast.FieldReference; +import org.eclipse.jdt.internal.compiler.ast.IfStatement; import org.eclipse.jdt.internal.compiler.ast.MessageSend; import org.eclipse.jdt.internal.compiler.ast.MethodDeclaration; +import org.eclipse.jdt.internal.compiler.ast.OperatorIds; +import org.eclipse.jdt.internal.compiler.ast.ParameterizedQualifiedTypeReference; import org.eclipse.jdt.internal.compiler.ast.ParameterizedSingleTypeReference; import org.eclipse.jdt.internal.compiler.ast.QualifiedTypeReference; import org.eclipse.jdt.internal.compiler.ast.ReturnStatement; import org.eclipse.jdt.internal.compiler.ast.SingleNameReference; import org.eclipse.jdt.internal.compiler.ast.SingleTypeReference; import org.eclipse.jdt.internal.compiler.ast.Statement; +import org.eclipse.jdt.internal.compiler.ast.ThisReference; +import org.eclipse.jdt.internal.compiler.ast.TrueLiteral; import org.eclipse.jdt.internal.compiler.ast.TypeDeclaration; import org.eclipse.jdt.internal.compiler.ast.TypeParameter; import org.eclipse.jdt.internal.compiler.ast.TypeReference; +import org.eclipse.jdt.internal.compiler.ast.UnaryExpression; import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants; import org.eclipse.jdt.internal.compiler.lookup.ClassScope; +import org.eclipse.jdt.internal.compiler.lookup.MethodScope; import org.eclipse.jdt.internal.compiler.lookup.TypeConstants; +import org.eclipse.jdt.internal.compiler.lookup.TypeIds; import org.mangosdk.spi.ProviderFor; import lombok.AccessLevel; +import lombok.Builder; import lombok.ConfigurationKeys; +import lombok.Singular; import lombok.core.AST.Kind; +import lombok.core.handlers.HandlerUtil; import lombok.core.AnnotationValues; import lombok.core.HandlerPriority; import lombok.eclipse.Eclipse; import lombok.eclipse.EclipseAnnotationHandler; import lombok.eclipse.EclipseNode; +import lombok.eclipse.handlers.EclipseSingularsRecipes.EclipseSingularizer; +import lombok.eclipse.handlers.EclipseSingularsRecipes.SingularData; import lombok.eclipse.handlers.HandleConstructor.SkipIfConstructorExists; -import lombok.experimental.Builder; import lombok.experimental.NonFinal; @ProviderFor(EclipseAnnotationHandler.class) @HandlerPriority(-1024) //-2^10; to ensure we've picked up @FieldDefault's changes (-2048) but @Value hasn't removed itself yet (-512), so that we can error on presence of it on the builder classes. public class HandleBuilder extends EclipseAnnotationHandler<Builder> { - @Override public void handle(AnnotationValues<Builder> annotation, Annotation ast, EclipseNode annotationNode) { - handleExperimentalFlagUsage(annotationNode, ConfigurationKeys.BUILDER_FLAG_USAGE, "@Builder"); + private static final char[] CLEAN_FIELD_NAME = "$lombokUnclean".toCharArray(); + private static final char[] CLEAN_METHOD_NAME = "$lombokClean".toCharArray(); + + private static final boolean toBoolean(Object expr, boolean defaultValue) { + if (expr == null) return defaultValue; + if (expr instanceof FalseLiteral) return false; + if (expr instanceof TrueLiteral) return true; + return ((Boolean) expr).booleanValue(); + } + + private static class BuilderFieldData { + TypeReference type; + char[] name; + SingularData singularData; + List<EclipseNode> createdFields = new ArrayList<EclipseNode>(); + } + + @Override public void handle(AnnotationValues<Builder> annotation, Annotation ast, EclipseNode annotationNode) { long p = (long) ast.sourceStart << 32 | ast.sourceEnd; Builder builderInstance = annotation.getInstance(); + + // These exist just to support the 'old' lombok.experimental.Builder, which had these properties. lombok.Builder no longer has them. + boolean fluent = toBoolean(annotation.getActualExpression("fluent"), true); + boolean chain = toBoolean(annotation.getActualExpression("chain"), true); + String builderMethodName = builderInstance.builderMethodName(); String buildMethodName = builderInstance.buildMethodName(); String builderClassName = builderInstance.builderClassName(); @@ -92,21 +129,21 @@ public class HandleBuilder extends EclipseAnnotationHandler<Builder> { EclipseNode parent = annotationNode.up(); - List<TypeReference> typesOfParameters = new ArrayList<TypeReference>(); - List<char[]> namesOfParameters = new ArrayList<char[]>(); + List<BuilderFieldData> builderFields = new ArrayList<BuilderFieldData>(); TypeReference returnType; TypeParameter[] typeParams; TypeReference[] thrownExceptions; char[] nameOfStaticBuilderMethod; EclipseNode tdParent; - AbstractMethodDeclaration fillParametersFrom = null; + EclipseNode fillParametersFrom = parent.get() instanceof AbstractMethodDeclaration ? parent : null; + boolean addCleaning = false; if (parent.get() instanceof TypeDeclaration) { tdParent = parent; TypeDeclaration td = (TypeDeclaration) tdParent.get(); - List<EclipseNode> fields = new ArrayList<EclipseNode>(); + List<EclipseNode> allFields = new ArrayList<EclipseNode>(); @SuppressWarnings("deprecation") boolean valuePresent = (hasAnnotation(lombok.Value.class, parent) || hasAnnotation(lombok.experimental.Value.class, parent)); for (EclipseNode fieldNode : HandleConstructor.findAllFields(tdParent)) { @@ -115,12 +152,15 @@ public class HandleBuilder extends EclipseAnnotationHandler<Builder> { // non-final fields final, but @Value's handler hasn't done this yet, so we have to do this math ourselves. // Value will only skip making a field final if it has an explicit @NonFinal annotation, so we check for that. if (fd.initialization != null && valuePresent && !hasAnnotation(NonFinal.class, fieldNode)) continue; - namesOfParameters.add(removePrefixFromField(fieldNode)); - typesOfParameters.add(fd.type); - fields.add(fieldNode); + BuilderFieldData bfd = new BuilderFieldData(); + bfd.name = removePrefixFromField(fieldNode); + bfd.type = fd.type; + bfd.singularData = getSingularData(fieldNode, ast); + builderFields.add(bfd); + allFields.add(fieldNode); } - new HandleConstructor().generateConstructor(tdParent, AccessLevel.PACKAGE, fields, null, SkipIfConstructorExists.I_AM_BUILDER, null, + new HandleConstructor().generateConstructor(tdParent, AccessLevel.PACKAGE, allFields, null, SkipIfConstructorExists.I_AM_BUILDER, null, Collections.<Annotation>emptyList(), annotationNode); returnType = namePlusTypeParamsToTypeReference(td.name, td.typeParameters, p); @@ -137,7 +177,6 @@ public class HandleBuilder extends EclipseAnnotationHandler<Builder> { tdParent = parent.up(); TypeDeclaration td = (TypeDeclaration) tdParent.get(); - fillParametersFrom = cd; returnType = namePlusTypeParamsToTypeReference(td.name, td.typeParameters, p); typeParams = td.typeParameters; thrownExceptions = cd.thrownExceptions; @@ -150,7 +189,6 @@ public class HandleBuilder extends EclipseAnnotationHandler<Builder> { annotationNode.addError("@Builder is only supported on types, constructors, and static methods."); return; } - fillParametersFrom = md; returnType = copyType(md.returnType, ast); typeParams = md.typeParameters; thrownExceptions = md.thrownExceptions; @@ -190,9 +228,14 @@ public class HandleBuilder extends EclipseAnnotationHandler<Builder> { } if (fillParametersFrom != null) { - if (fillParametersFrom.arguments != null) for (Argument a : fillParametersFrom.arguments) { - namesOfParameters.add(a.name); - typesOfParameters.add(a.type); + for (EclipseNode param : fillParametersFrom.down()) { + if (param.getKind() != Kind.ARGUMENT) continue; + BuilderFieldData bfd = new BuilderFieldData(); + Argument arg = (Argument) param.get(); + bfd.name = arg.name; + bfd.type = arg.type; + bfd.singularData = getSingularData(param, ast); + builderFields.add(bfd); } } @@ -201,12 +244,36 @@ public class HandleBuilder extends EclipseAnnotationHandler<Builder> { builderType = makeBuilderClass(tdParent, builderClassName, typeParams, ast); } else { sanityCheckForMethodGeneratingAnnotationsOnBuilderClass(builderType, annotationNode); + /* generate errors for @Singular BFDs that have one already defined node. */ { + for (BuilderFieldData bfd : builderFields) { + SingularData sd = bfd.singularData; + if (sd == null) continue; + EclipseSingularizer singularizer = sd.getSingularizer(); + if (singularizer == null) continue; + if (singularizer.checkForAlreadyExistingNodesAndGenerateError(builderType, sd)) { + bfd.singularData = null; + } + } + } + } + + for (BuilderFieldData bfd : builderFields) { + if (bfd.singularData != null && bfd.singularData.getSingularizer() != null) { + if (bfd.singularData.getSingularizer().requiresCleaning()) { + addCleaning = true; + break; + } + } } - List<EclipseNode> fieldNodes = addFieldsToBuilder(builderType, namesOfParameters, typesOfParameters, ast); - List<AbstractMethodDeclaration> newMethods = new ArrayList<AbstractMethodDeclaration>(); - for (EclipseNode fieldNode : fieldNodes) { - MethodDeclaration newMethod = makeSetterMethodForBuilder(builderType, fieldNode, annotationNode, builderInstance.fluent(), builderInstance.chain()); - if (newMethod != null) newMethods.add(newMethod); + + generateBuilderFields(builderType, builderFields, ast); + if (addCleaning) { + FieldDeclaration cleanDecl = new FieldDeclaration(CLEAN_FIELD_NAME, 0, -1); + cleanDecl.declarationSourceEnd = -1; + cleanDecl.modifiers = ClassFileConstants.AccPrivate; + cleanDecl.type = TypeReference.baseTypeReference(TypeIds.T_boolean, 0); + System.out.println("INJECTING: cleaning"); + injectField(builderType, cleanDecl); } if (constructorExists(builderType) == MemberExistsResult.NOT_EXISTS) { @@ -216,128 +283,183 @@ public class HandleBuilder extends EclipseAnnotationHandler<Builder> { if (cd != null) injectMethod(builderType, cd); } - for (AbstractMethodDeclaration newMethod : newMethods) injectMethod(builderType, newMethod); + for (BuilderFieldData bfd : builderFields) { + makeSetterMethodsForBuilder(builderType, bfd, annotationNode, fluent, chain); + } + if (methodExists(buildMethodName, builderType, -1) == MemberExistsResult.NOT_EXISTS) { - MethodDeclaration md = generateBuildMethod(buildMethodName, nameOfStaticBuilderMethod, returnType, namesOfParameters, builderType, ast, thrownExceptions); + MethodDeclaration md = generateBuildMethod(buildMethodName, nameOfStaticBuilderMethod, returnType, builderFields, builderType, thrownExceptions, addCleaning, ast); if (md != null) injectMethod(builderType, md); } if (methodExists("toString", builderType, 0) == MemberExistsResult.NOT_EXISTS) { + List<EclipseNode> fieldNodes = new ArrayList<EclipseNode>(); + for (BuilderFieldData bfd : builderFields) { + fieldNodes.addAll(bfd.createdFields); + } MethodDeclaration md = HandleToString.createToString(builderType, fieldNodes, true, false, ast, FieldAccess.ALWAYS_FIELD); if (md != null) injectMethod(builderType, md); } + if (addCleaning) { + MethodDeclaration cleanMethod = generateCleanMethod(builderFields, builderType, ast); + if (cleanMethod != null) injectMethod(builderType, cleanMethod); + } + if (methodExists(builderMethodName, tdParent, -1) == MemberExistsResult.NOT_EXISTS) { MethodDeclaration md = generateBuilderMethod(builderMethodName, builderClassName, tdParent, typeParams, ast); if (md != null) injectMethod(tdParent, md); } } - public MethodDeclaration generateBuilderMethod(String builderMethodName, String builderClassName, EclipseNode type, TypeParameter[] typeParams, ASTNode source) { - int pS = source.sourceStart, pE = source.sourceEnd; - long p = (long) pS << 32 | pE; + private MethodDeclaration generateCleanMethod(List<BuilderFieldData> builderFields, EclipseNode builderType, ASTNode source) { + List<Statement> statements = new ArrayList<Statement>(); - MethodDeclaration out = new MethodDeclaration( - ((CompilationUnitDeclaration) type.top().get()).compilationResult); - out.selector = builderMethodName.toCharArray(); - out.modifiers = ClassFileConstants.AccPublic | ClassFileConstants.AccStatic; - out.bits |= ECLIPSE_DO_NOT_TOUCH_FLAG; - out.returnType = namePlusTypeParamsToTypeReference(builderClassName.toCharArray(), typeParams, p); - out.typeParameters = copyTypeParams(typeParams, source); - AllocationExpression invoke = new AllocationExpression(); - invoke.type = namePlusTypeParamsToTypeReference(builderClassName.toCharArray(), typeParams, p); - out.statements = new Statement[] {new ReturnStatement(invoke, pS, pE)}; + for (BuilderFieldData bfd : builderFields) { + if (bfd.singularData != null && bfd.singularData.getSingularizer() != null) { + bfd.singularData.getSingularizer().appendCleaningCode(bfd.singularData, builderType, statements); + } + } - out.traverse(new SetGeneratedByVisitor(source), ((TypeDeclaration) type.get()).scope); - return out; + FieldReference thisUnclean = new FieldReference(CLEAN_FIELD_NAME, 0); + thisUnclean.receiver = new ThisReference(0, 0); + statements.add(new Assignment(thisUnclean, new FalseLiteral(0, 0), 0)); + MethodDeclaration decl = new MethodDeclaration(((CompilationUnitDeclaration) builderType.top().get()).compilationResult); + decl.selector = CLEAN_METHOD_NAME; + decl.modifiers = ClassFileConstants.AccPrivate; + decl.bits |= ECLIPSE_DO_NOT_TOUCH_FLAG; + decl.returnType = TypeReference.baseTypeReference(TypeIds.T_void, 0); + decl.statements = statements.toArray(new Statement[0]); + decl.traverse(new SetGeneratedByVisitor(source), (ClassScope) null); + return decl; } - public MethodDeclaration generateBuildMethod(String name, char[] staticName, TypeReference returnType, List<char[]> fieldNames, EclipseNode type, ASTNode source, TypeReference[] thrownExceptions) { - int pS = source.sourceStart, pE = source.sourceEnd; - long p = (long) pS << 32 | pE; - + public MethodDeclaration generateBuildMethod(String name, char[] staticName, TypeReference returnType, List<BuilderFieldData> builderFields, EclipseNode type, TypeReference[] thrownExceptions, boolean addCleaning, ASTNode source) { MethodDeclaration out = new MethodDeclaration( ((CompilationUnitDeclaration) type.top().get()).compilationResult); + out.bits |= ECLIPSE_DO_NOT_TOUCH_FLAG; + List<Statement> statements = new ArrayList<Statement>(); + + if (addCleaning) { + FieldReference thisUnclean = new FieldReference(CLEAN_FIELD_NAME, 0); + thisUnclean.receiver = new ThisReference(0, 0); + Expression notClean = new UnaryExpression(thisUnclean, OperatorIds.NOT); + MessageSend invokeClean = new MessageSend(); + invokeClean.selector = CLEAN_METHOD_NAME; + statements.add(new IfStatement(notClean, invokeClean, 0, 0)); + } + + for (BuilderFieldData bfd : builderFields) { + if (bfd.singularData != null && bfd.singularData.getSingularizer() != null) { + bfd.singularData.getSingularizer().appendBuildCode(bfd.singularData, type, statements, bfd.name); + } + } + + List<Expression> args = new ArrayList<Expression>(); + for (BuilderFieldData bfd : builderFields) { + args.add(new SingleNameReference(bfd.name, 0L)); + } + + if (addCleaning) { + FieldReference thisUnclean = new FieldReference(CLEAN_FIELD_NAME, 0); + thisUnclean.receiver = new ThisReference(0, 0); + statements.add(new Assignment(thisUnclean, new TrueLiteral(0, 0), 0)); + } out.modifiers = ClassFileConstants.AccPublic; - TypeDeclaration typeDecl = (TypeDeclaration) type.get(); out.selector = name.toCharArray(); - out.thrownExceptions = copyTypes(thrownExceptions, source); + out.thrownExceptions = copyTypes(thrownExceptions); out.bits |= ECLIPSE_DO_NOT_TOUCH_FLAG; out.returnType = returnType; - List<Expression> assigns = new ArrayList<Expression>(); - for (char[] fieldName : fieldNames) { - SingleNameReference nameRef = new SingleNameReference(fieldName, p); - assigns.add(nameRef); - } - - Statement statement; - if (staticName == null) { AllocationExpression allocationStatement = new AllocationExpression(); - allocationStatement.type = copyType(out.returnType, source); - allocationStatement.arguments = assigns.isEmpty() ? null : assigns.toArray(new Expression[assigns.size()]); - statement = new ReturnStatement(allocationStatement, (int)(p >> 32), (int)p); + allocationStatement.type = copyType(out.returnType); + allocationStatement.arguments = args.isEmpty() ? null : args.toArray(new Expression[args.size()]); + statements.add(new ReturnStatement(allocationStatement, 0, 0)); } else { MessageSend invoke = new MessageSend(); invoke.selector = staticName; - invoke.receiver = new SingleNameReference(type.up().getName().toCharArray(), p); + invoke.receiver = new SingleNameReference(type.up().getName().toCharArray(), 0); TypeParameter[] tps = ((TypeDeclaration) type.get()).typeParameters; if (tps != null) { TypeReference[] trs = new TypeReference[tps.length]; for (int i = 0; i < trs.length; i++) { - trs[i] = new SingleTypeReference(tps[i].name, p); + trs[i] = new SingleTypeReference(tps[i].name, 0); } invoke.typeArguments = trs; } - invoke.arguments = assigns.isEmpty() ? null : assigns.toArray(new Expression[assigns.size()]); + invoke.arguments = args.isEmpty() ? null : args.toArray(new Expression[args.size()]); if (returnType instanceof SingleTypeReference && Arrays.equals(TypeConstants.VOID, ((SingleTypeReference) returnType).token)) { - statement = invoke; + statements.add(invoke); } else { - statement = new ReturnStatement(invoke, (int)(p >> 32), (int)p); + statements.add(new ReturnStatement(invoke, 0, 0)); } } + out.statements = statements.isEmpty() ? null : statements.toArray(new Statement[statements.size()]); + out.traverse(new SetGeneratedByVisitor(source), (ClassScope) null); + return out; + } + + public MethodDeclaration generateBuilderMethod(String builderMethodName, String builderClassName, EclipseNode type, TypeParameter[] typeParams, ASTNode source) { + int pS = source.sourceStart, pE = source.sourceEnd; + long p = (long) pS << 32 | pE; - out.statements = new Statement[] { statement }; + MethodDeclaration out = new MethodDeclaration( + ((CompilationUnitDeclaration) type.top().get()).compilationResult); + out.selector = builderMethodName.toCharArray(); + out.modifiers = ClassFileConstants.AccPublic | ClassFileConstants.AccStatic; + out.bits |= ECLIPSE_DO_NOT_TOUCH_FLAG; + out.returnType = namePlusTypeParamsToTypeReference(builderClassName.toCharArray(), typeParams, p); + out.typeParameters = copyTypeParams(typeParams, source); + AllocationExpression invoke = new AllocationExpression(); + invoke.type = namePlusTypeParamsToTypeReference(builderClassName.toCharArray(), typeParams, p); + out.statements = new Statement[] {new ReturnStatement(invoke, pS, pE)}; - out.traverse(new SetGeneratedByVisitor(source), typeDecl.scope); + out.traverse(new SetGeneratedByVisitor(source), ((TypeDeclaration) type.get()).scope); return out; } - public List<EclipseNode> addFieldsToBuilder(EclipseNode builderType, List<char[]> namesOfParameters, List<TypeReference> typesOfParameters, ASTNode source) { - int len = namesOfParameters.size(); - TypeDeclaration td = (TypeDeclaration) builderType.get(); - FieldDeclaration[] existing = td.fields; - if (existing == null) existing = new FieldDeclaration[0]; - - List<EclipseNode> out = new ArrayList<EclipseNode>(); + public void generateBuilderFields(EclipseNode builderType, List<BuilderFieldData> builderFields, ASTNode source) { + List<EclipseNode> existing = new ArrayList<EclipseNode>(); + for (EclipseNode child : builderType.down()) { + if (child.getKind() == Kind.FIELD) existing.add(child); + } top: - for (int i = len - 1; i >= 0; i--) { - char[] name = namesOfParameters.get(i); - for (FieldDeclaration exists : existing) { - if (Arrays.equals(exists.name, name)) { - out.add(builderType.getNodeFor(exists)); - continue top; + for (BuilderFieldData bfd : builderFields) { + if (bfd.singularData != null && bfd.singularData.getSingularizer() != null) { + bfd.createdFields.addAll(bfd.singularData.getSingularizer().generateFields(bfd.singularData, builderType)); + } else { + for (EclipseNode exists : existing) { + char[] n = ((FieldDeclaration) exists.get()).name; + if (Arrays.equals(n, bfd.name)) { + bfd.createdFields.add(exists); + continue top; + } } + + FieldDeclaration fd = new FieldDeclaration(bfd.name, 0, 0); + fd.bits |= Eclipse.ECLIPSE_DO_NOT_TOUCH_FLAG; + fd.modifiers = ClassFileConstants.AccPrivate; + fd.type = copyType(bfd.type); + fd.traverse(new SetGeneratedByVisitor(source), (MethodScope) null); + bfd.createdFields.add(injectField(builderType, fd)); } - TypeReference fieldReference = copyType(typesOfParameters.get(i), source); - FieldDeclaration newField = new FieldDeclaration(name, 0, 0); - newField.bits |= Eclipse.ECLIPSE_DO_NOT_TOUCH_FLAG; - newField.modifiers = ClassFileConstants.AccPrivate; - newField.type = fieldReference; - out.add(injectField(builderType, newField)); } - - Collections.reverse(out); - - return out; } private static final AbstractMethodDeclaration[] EMPTY = {}; - public MethodDeclaration makeSetterMethodForBuilder(EclipseNode builderType, EclipseNode fieldNode, EclipseNode sourceNode, boolean fluent, boolean chain) { + public void makeSetterMethodsForBuilder(EclipseNode builderType, BuilderFieldData bfd, EclipseNode sourceNode, boolean fluent, boolean chain) { + if (bfd.singularData == null || bfd.singularData.getSingularizer() == null) { + makeSimpleSetterMethodForBuilder(builderType, bfd.createdFields.get(0), sourceNode, fluent, chain); + } else { + bfd.singularData.getSingularizer().generateMethods(bfd.singularData, builderType, fluent, chain); + } + } + + private void makeSimpleSetterMethodForBuilder(EclipseNode builderType, EclipseNode fieldNode, EclipseNode sourceNode, boolean fluent, boolean chain) { TypeDeclaration td = (TypeDeclaration) builderType.get(); AbstractMethodDeclaration[] existing = td.methods; if (existing == null) existing = EMPTY; @@ -348,14 +470,14 @@ public class HandleBuilder extends EclipseAnnotationHandler<Builder> { for (int i = 0; i < len; i++) { if (!(existing[i] instanceof MethodDeclaration)) continue; char[] existingName = existing[i].selector; - if (Arrays.equals(name, existingName)) return null; + if (Arrays.equals(name, existingName)) return; } - boolean isBoolean = isBoolean(fd.type); - String setterName = fluent ? fieldNode.getName() : toSetterName(builderType.getAst(), null, fieldNode.getName(), isBoolean); + String setterName = fluent ? fieldNode.getName() : HandlerUtil.buildAccessorName("set", fieldNode.getName()); - return HandleSetter.createSetter(td, fieldNode, setterName, chain, ClassFileConstants.AccPublic, + MethodDeclaration setter = HandleSetter.createSetter(td, fieldNode, setterName, chain, ClassFileConstants.AccPublic, sourceNode, Collections.<Annotation>emptyList(), Collections.<Annotation>emptyList()); + injectMethod(builderType, setter); } public EclipseNode findInnerClass(EclipseNode parent, String name) { @@ -378,4 +500,64 @@ public class HandleBuilder extends EclipseAnnotationHandler<Builder> { builder.traverse(new SetGeneratedByVisitor(source), (ClassScope) null); return injectType(tdParent, builder); } + + /** + * Returns the explicitly requested singular annotation on this node (field + * or parameter), or null if there's no {@code @Singular} annotation on it. + * + * @param node The node (field or method param) to inspect for its name and potential {@code @Singular} annotation. + */ + private SingularData getSingularData(EclipseNode node, ASTNode source) { + for (EclipseNode child : node.down()) { + if (child.getKind() == Kind.ANNOTATION && annotationTypeMatches(Singular.class, child)) { + char[] pluralName = node.getKind() == Kind.FIELD ? removePrefixFromField(node) : ((AbstractVariableDeclaration) node.get()).name; + AnnotationValues<Singular> ann = createAnnotation(Singular.class, child); + String explicitSingular = ann.getInstance().value(); + if (explicitSingular.isEmpty()) { + if (Boolean.FALSE.equals(node.getAst().readConfiguration(ConfigurationKeys.SINGULAR_AUTO))) { + node.addError("The singular must be specified explicitly (e.g. @Singular(\"task\")) because auto singularization is disabled."); + explicitSingular = new String(pluralName); + } else { + explicitSingular = autoSingularize(node.getName()); + if (explicitSingular == null) { + node.addError("Can't singularize this name; please specify the singular explicitly (i.e. @Singular(\"sheep\"))"); + explicitSingular = new String(pluralName); + } + } + } + char[] singularName = explicitSingular.toCharArray(); + + TypeReference type = ((AbstractVariableDeclaration) node.get()).type; + TypeReference[] typeArgs = null; + String typeName; + if (type instanceof ParameterizedSingleTypeReference) { + typeArgs = ((ParameterizedSingleTypeReference) type).typeArguments; + typeName = new String(((ParameterizedSingleTypeReference) type).token); + } else if (type instanceof ParameterizedQualifiedTypeReference) { + TypeReference[][] tr = ((ParameterizedQualifiedTypeReference) type).typeArguments; + if (tr != null) typeArgs = tr[tr.length - 1]; + char[][] tokens = ((ParameterizedQualifiedTypeReference) type).tokens; + StringBuilder sb = new StringBuilder(); + for (int i = 0; i < tokens.length; i++) { + if (i > 0) sb.append("."); + sb.append(tokens[i]); + } + typeName = sb.toString(); + } else { + typeName = type.toString(); + } + + String targetFqn = EclipseSingularsRecipes.get().toQualified(typeName); + EclipseSingularizer singularizer = EclipseSingularsRecipes.get().getSingularizer(targetFqn); + if (singularizer == null) { + node.addError("Lombok does not know how to create the singular-form builder methods for type '" + typeName + "'; they won't be generated."); + return null; + } + + return new SingularData(child, singularName, pluralName, typeArgs == null ? Collections.<TypeReference>emptyList() : Arrays.asList(typeArgs), targetFqn, singularizer, source); + } + } + + return null; + } } diff --git a/src/core/lombok/eclipse/handlers/HandleConstructor.java b/src/core/lombok/eclipse/handlers/HandleConstructor.java index b72d000f..5bcc803a 100644 --- a/src/core/lombok/eclipse/handlers/HandleConstructor.java +++ b/src/core/lombok/eclipse/handlers/HandleConstructor.java @@ -33,6 +33,7 @@ import java.util.List; import lombok.AccessLevel; import lombok.AllArgsConstructor; +import lombok.Builder; import lombok.ConfigurationKeys; import lombok.NoArgsConstructor; import lombok.RequiredArgsConstructor; @@ -40,7 +41,6 @@ import lombok.core.AST.Kind; import lombok.core.AnnotationValues; import lombok.eclipse.EclipseAnnotationHandler; import lombok.eclipse.EclipseNode; -import lombok.experimental.Builder; import org.eclipse.jdt.internal.compiler.ast.ASTNode; import org.eclipse.jdt.internal.compiler.ast.AllocationExpression; @@ -333,8 +333,7 @@ public class HandleConstructor { Statement nullCheck = generateNullCheck(field, sourceNode); if (nullCheck != null) nullChecks.add(nullCheck); } - Annotation[] copiedAnnotations = copyAnnotations(source, nonNulls, nullables); - if (copiedAnnotations.length != 0) parameter.annotations = copiedAnnotations; + parameter.annotations = copyAnnotations(source, nonNulls, nullables); params.add(parameter); } @@ -348,10 +347,9 @@ public class HandleConstructor { constructorProperties = createConstructorProperties(source, fields); } - Annotation[] copiedAnnotations = copyAnnotations(source, + constructor.annotations = copyAnnotations(source, onConstructor.toArray(new Annotation[0]), constructorProperties); - if (copiedAnnotations.length != 0) constructor.annotations = copiedAnnotations; } constructor.traverse(new SetGeneratedByVisitor(source), typeDeclaration.scope); @@ -396,9 +394,7 @@ public class HandleConstructor { assigns.add(nameRef); Argument parameter = new Argument(field.name, fieldPos, copyType(field.type, source), Modifier.FINAL); - - Annotation[] copiedAnnotations = copyAnnotations(source, findAnnotations(field, NON_NULL_PATTERN), findAnnotations(field, NULLABLE_PATTERN)); - if (copiedAnnotations.length != 0) parameter.annotations = copiedAnnotations; + parameter.annotations = copyAnnotations(source, findAnnotations(field, NON_NULL_PATTERN), findAnnotations(field, NULLABLE_PATTERN)); params.add(parameter); } diff --git a/src/core/lombok/eclipse/handlers/HandleEqualsAndHashCode.java b/src/core/lombok/eclipse/handlers/HandleEqualsAndHashCode.java index e1b02051..7e2ff513 100644 --- a/src/core/lombok/eclipse/handlers/HandleEqualsAndHashCode.java +++ b/src/core/lombok/eclipse/handlers/HandleEqualsAndHashCode.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2009-2014 The Project Lombok Authors. + * Copyright (C) 2009-2015 The Project Lombok Authors. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -561,7 +561,6 @@ public class HandleEqualsAndHashCode extends EclipseAnnotationHandler<EqualsAndH } NameReference oRef = new SingleNameReference(new char[] { 'o' }, p); setGeneratedBy(oRef, source); - other.annotations = createSuppressWarningsAll(source, null); other.initialization = makeCastExpression(oRef, targetType, source); statements.add(other); } diff --git a/src/core/lombok/eclipse/handlers/HandleGetter.java b/src/core/lombok/eclipse/handlers/HandleGetter.java index 031fff82..14f2fb72 100644 --- a/src/core/lombok/eclipse/handlers/HandleGetter.java +++ b/src/core/lombok/eclipse/handlers/HandleGetter.java @@ -270,14 +270,12 @@ public class HandleGetter extends EclipseAnnotationHandler<Getter> { deprecated = new Annotation[] { generateDeprecatedAnnotation(source) }; } - Annotation[] copiedAnnotations = copyAnnotations(source, + method.annotations = copyAnnotations(source, onMethod.toArray(new Annotation[0]), findAnnotations(field, NON_NULL_PATTERN), findAnnotations(field, NULLABLE_PATTERN), findDelegatesAndMarkAsHandled(fieldNode), deprecated); - - if (copiedAnnotations.length != 0) method.annotations = copiedAnnotations; } method.traverse(new SetGeneratedByVisitor(source), parent.scope); diff --git a/src/core/lombok/eclipse/handlers/HandleSetter.java b/src/core/lombok/eclipse/handlers/HandleSetter.java index c22af676..1fcf751d 100644 --- a/src/core/lombok/eclipse/handlers/HandleSetter.java +++ b/src/core/lombok/eclipse/handlers/HandleSetter.java @@ -216,10 +216,7 @@ public class HandleSetter extends EclipseAnnotationHandler<Setter> { if (isFieldDeprecated(fieldNode)) { deprecated = new Annotation[] { generateDeprecatedAnnotation(source) }; } - Annotation[] copiedAnnotations = copyAnnotations(source, onMethod.toArray(new Annotation[0]), deprecated); - if (copiedAnnotations.length != 0) { - method.annotations = copiedAnnotations; - } + method.annotations = copyAnnotations(source, onMethod.toArray(new Annotation[0]), deprecated); Argument param = new Argument(field.name, p, copyType(field.type, source), Modifier.FINAL); param.sourceStart = pS; param.sourceEnd = pE; method.arguments = new Argument[] { param }; @@ -252,9 +249,7 @@ public class HandleSetter extends EclipseAnnotationHandler<Setter> { statements.add(returnThis); } method.statements = statements.toArray(new Statement[0]); - - Annotation[] copiedAnnotationsParam = copyAnnotations(source, nonNulls, nullables, onParam.toArray(new Annotation[0])); - if (copiedAnnotationsParam.length != 0) param.annotations = copiedAnnotationsParam; + param.annotations = copyAnnotations(source, nonNulls, nullables, onParam.toArray(new Annotation[0])); method.traverse(new SetGeneratedByVisitor(source), parent.scope); return method; diff --git a/src/core/lombok/eclipse/handlers/HandleWither.java b/src/core/lombok/eclipse/handlers/HandleWither.java index 8b038676..29a6edb7 100644 --- a/src/core/lombok/eclipse/handlers/HandleWither.java +++ b/src/core/lombok/eclipse/handlers/HandleWither.java @@ -127,8 +127,8 @@ public class HandleWither extends EclipseAnnotationHandler<Wither> { AccessLevel level = annotation.getInstance().value(); if (level == AccessLevel.NONE || node == null) return; - List<Annotation> onMethod = unboxAndRemoveAnnotationParameter(ast, "onMethod", "@Setter(onMethod=", annotationNode); - List<Annotation> onParam = unboxAndRemoveAnnotationParameter(ast, "onParam", "@Setter(onParam=", annotationNode); + List<Annotation> onMethod = unboxAndRemoveAnnotationParameter(ast, "onMethod", "@Wither(onMethod=", annotationNode); + List<Annotation> onParam = unboxAndRemoveAnnotationParameter(ast, "onParam", "@Wither(onParam=", annotationNode); switch (node.getKind()) { case FIELD: @@ -227,10 +227,7 @@ public class HandleWither extends EclipseAnnotationHandler<Wither> { if (isFieldDeprecated(fieldNode)) { deprecated = new Annotation[] { generateDeprecatedAnnotation(source) }; } - Annotation[] copiedAnnotations = copyAnnotations(source, onMethod.toArray(new Annotation[0]), deprecated); - if (copiedAnnotations.length != 0) { - method.annotations = copiedAnnotations; - } + method.annotations = copyAnnotations(source, onMethod.toArray(new Annotation[0]), deprecated); Argument param = new Argument(field.name, p, copyType(field.type, source), Modifier.FINAL); param.sourceStart = pS; param.sourceEnd = pE; method.arguments = new Argument[] { param }; @@ -283,8 +280,7 @@ public class HandleWither extends EclipseAnnotationHandler<Wither> { method.statements = statements.toArray(new Statement[0]); - Annotation[] copiedAnnotationsParam = copyAnnotations(source, nonNulls, nullables, onParam.toArray(new Annotation[0])); - if (copiedAnnotationsParam.length != 0) param.annotations = copiedAnnotationsParam; + param.annotations = copyAnnotations(source, nonNulls, nullables, onParam.toArray(new Annotation[0])); method.traverse(new SetGeneratedByVisitor(source), parent.scope); return method; diff --git a/src/core/lombok/eclipse/handlers/SetGeneratedByVisitor.java b/src/core/lombok/eclipse/handlers/SetGeneratedByVisitor.java index 7217a396..df839a94 100644 --- a/src/core/lombok/eclipse/handlers/SetGeneratedByVisitor.java +++ b/src/core/lombok/eclipse/handlers/SetGeneratedByVisitor.java @@ -23,6 +23,8 @@ package lombok.eclipse.handlers; import static lombok.eclipse.handlers.EclipseHandlerUtil.*; +import java.util.Arrays; + import org.eclipse.jdt.internal.compiler.ASTVisitor; import org.eclipse.jdt.internal.compiler.ast.AND_AND_Expression; import org.eclipse.jdt.internal.compiler.ast.ASTNode; @@ -128,881 +130,802 @@ public final class SetGeneratedByVisitor extends ASTVisitor { private static final long INT_TO_LONG_MASK = 0x00000000FFFFFFFFL; private final ASTNode source; - private final int newSourceStart; - private final int newSourceEnd; + private final int sourceStart; + private final int sourceEnd; + private final long sourcePos; public SetGeneratedByVisitor(ASTNode source) { this.source = source; - this.newSourceStart = this.source.sourceStart; - this.newSourceEnd = this.source.sourceEnd; + this.sourceStart = this.source.sourceStart; + this.sourceEnd = this.source.sourceEnd; + this.sourcePos = (long)sourceStart << 32 | (sourceEnd & INT_TO_LONG_MASK); } - private void applyOffset(JavadocAllocationExpression node) { - applyOffsetExpression(node); - node.memberStart = newSourceStart; - node.tagSourceEnd = newSourceEnd; - node.tagSourceStart = newSourceStart; + private void fixPositions(JavadocAllocationExpression node) { + node.sourceEnd = sourceEnd; + node.sourceStart = sourceStart; + node.statementEnd = sourceEnd; + node.memberStart = sourceStart; + node.tagSourceEnd = sourceEnd; + node.tagSourceStart = sourceStart; } - private void applyOffset(JavadocMessageSend node) { - applyOffsetMessageSend(node); - node.tagSourceEnd = newSourceEnd; - node.tagSourceStart = newSourceStart; + private void fixPositions(JavadocMessageSend node) { + node.sourceEnd = sourceEnd; + node.sourceStart = sourceStart; + node.statementEnd = sourceEnd; + node.nameSourcePosition = sourcePos; + node.tagSourceEnd = sourceEnd; + node.tagSourceStart = sourceStart; } - private void applyOffset(JavadocSingleNameReference node) { - applyOffsetExpression(node); - node.tagSourceEnd = newSourceEnd; - node.tagSourceStart = newSourceStart; + private void fixPositions(JavadocSingleNameReference node) { + node.sourceEnd = sourceEnd; + node.sourceStart = sourceStart; + node.statementEnd = sourceEnd; + node.tagSourceEnd = sourceEnd; + node.tagSourceStart = sourceStart; } - private void applyOffset(JavadocSingleTypeReference node) { - applyOffsetExpression(node); - node.tagSourceEnd = newSourceEnd; - node.tagSourceStart = newSourceStart; + private void fixPositions(JavadocSingleTypeReference node) { + node.sourceEnd = sourceEnd; + node.sourceStart = sourceStart; + node.statementEnd = sourceEnd; + node.tagSourceEnd = sourceEnd; + node.tagSourceStart = sourceStart; } - private void applyOffset(JavadocFieldReference node) { - applyOffsetFieldReference(node); - node.tagSourceEnd = newSourceEnd; - node.tagSourceStart = newSourceStart; + private void fixPositions(JavadocFieldReference node) { + node.sourceEnd = sourceEnd; + node.sourceStart = sourceStart; + node.statementEnd = sourceEnd; + node.nameSourcePosition = sourcePos; + node.tagSourceEnd = sourceEnd; + node.tagSourceStart = sourceStart; + } + + private void fixPositions(JavadocArrayQualifiedTypeReference node) { + node.sourceEnd = sourceEnd; + node.sourceStart = sourceStart; + node.statementEnd = sourceEnd; + if (node.sourcePositions == null || node.sourcePositions.length != node.tokens.length) node.sourcePositions = new long[node.tokens.length]; + Arrays.fill(node.sourcePositions, sourcePos); + node.tagSourceEnd = sourceEnd; + node.tagSourceStart = sourceStart; + } + + private void fixPositions(JavadocQualifiedTypeReference node) { + node.sourceEnd = sourceEnd; + node.sourceStart = sourceStart; + node.statementEnd = sourceEnd; + if (node.sourcePositions == null || node.sourcePositions.length != node.tokens.length) node.sourcePositions = new long[node.tokens.length]; + Arrays.fill(node.sourcePositions, sourcePos); + node.tagSourceEnd = sourceEnd; + node.tagSourceStart = sourceStart; + } + + private void fixPositions(Annotation node) { + node.sourceEnd = sourceEnd; + node.sourceStart = sourceStart; + node.statementEnd = sourceEnd; + node.declarationSourceEnd = sourceEnd; } - - private void applyOffset(JavadocArrayQualifiedTypeReference node) { - applyOffsetQualifiedTypeReference(node); - node.tagSourceEnd = newSourceEnd; - node.tagSourceStart = newSourceStart; + + private void fixPositions(ArrayTypeReference node) { + node.sourceEnd = sourceEnd; + node.sourceStart = sourceStart; + node.statementEnd = sourceEnd; + node.originalSourceEnd = sourceEnd; } - private void applyOffset(JavadocQualifiedTypeReference node) { - applyOffsetQualifiedTypeReference(node); - node.tagSourceEnd = newSourceEnd; - node.tagSourceStart = newSourceStart; + private void fixPositions(AbstractMethodDeclaration node) { + node.sourceEnd = sourceEnd; + node.sourceStart = sourceStart; + node.bodyEnd = sourceEnd; + node.bodyStart = sourceStart; + node.declarationSourceEnd = sourceEnd; + node.declarationSourceStart = sourceStart; + node.modifiersSourceStart = sourceStart; } - private void applyOffset(Annotation node) { - applyOffsetExpression(node); - node.declarationSourceEnd = newSourceEnd; + private void fixPositions(Javadoc node) { + node.sourceEnd = sourceEnd; + node.sourceStart = sourceStart; + node.valuePositions = sourceStart; } - private void applyOffset(ArrayTypeReference node) { - applyOffsetExpression(node); - node.originalSourceEnd = newSourceEnd; + private void fixPositions(Initializer node) { + node.sourceEnd = sourceEnd; + node.sourceStart = sourceStart; + node.declarationEnd = sourceEnd; + node.declarationSourceEnd = sourceEnd; + node.declarationSourceStart = sourceStart; + node.modifiersSourceStart = sourceStart; + node.endPart1Position = sourceEnd; + node.endPart2Position = sourceEnd; + node.bodyStart = sourceStart; + node.bodyEnd = sourceEnd; } - - private void applyOffset(AbstractMethodDeclaration node) { - applyOffsetASTNode(node); - node.bodyEnd = newSourceEnd; - node.bodyStart = newSourceStart; - node.declarationSourceEnd = newSourceEnd; - node.declarationSourceStart = newSourceStart; - node.modifiersSourceStart = newSourceStart; + + private void fixPositions(TypeDeclaration node) { + node.sourceEnd = sourceEnd; + node.sourceStart = sourceStart; + node.bodyEnd = sourceEnd; + node.bodyStart = sourceStart; + node.declarationSourceEnd = sourceEnd; + node.declarationSourceStart = sourceStart; + node.modifiersSourceStart = sourceStart; } - private void applyOffset(Javadoc node) { - applyOffsetASTNode(node); - node.valuePositions = newSourceStart; - for (int i = 0; i < node.inheritedPositions.length; i++) { - node.inheritedPositions[i] = recalcSourcePosition(node.inheritedPositions[i]); - } + private void fixPositions(ImportReference node) { + node.sourceEnd = sourceEnd; + node.sourceStart = sourceStart; + node.declarationEnd = sourceEnd; + node.declarationSourceEnd = sourceEnd; + node.declarationSourceStart = sourceStart; + if (node.sourcePositions == null || node.sourcePositions.length != node.tokens.length) node.sourcePositions = new long[node.tokens.length]; + Arrays.fill(node.sourcePositions, sourcePos); } - - private void applyOffset(Initializer node) { - applyOffsetFieldDeclaration(node); - node.bodyStart = newSourceStart; - node.bodyEnd = newSourceEnd; - } - - private void applyOffset(TypeDeclaration node) { - applyOffsetASTNode(node); - node.bodyEnd = newSourceEnd; - node.bodyStart = newSourceStart; - node.declarationSourceEnd = newSourceEnd; - node.declarationSourceStart = newSourceStart; - node.modifiersSourceStart = newSourceStart; - } - - private void applyOffset(ImportReference node) { - applyOffsetASTNode(node); - node.declarationEnd = newSourceEnd; - node.declarationSourceEnd = newSourceEnd; - node.declarationSourceStart = newSourceStart; - for (int i = 0; i < node.sourcePositions.length; i++) { - node.sourcePositions[i] = recalcSourcePosition(node.sourcePositions[i]); - } + + private void fixPositions(ASTNode node) { + node.sourceEnd = sourceEnd; + node.sourceStart = sourceStart; } - - private void applyOffsetASTNode(ASTNode node) { - node.sourceEnd = newSourceEnd; - node.sourceStart = newSourceStart; + + private void fixPositions(SwitchStatement node) { + node.sourceEnd = sourceEnd; + node.sourceStart = sourceStart; + node.blockStart = sourceStart; } - - private void applyOffsetExpression(Expression node) { - applyOffsetASTNode(node); -// if (node.statementEnd != -1) { - node.statementEnd = newSourceEnd; -// } + + private void fixPositions(Expression node) { + node.sourceEnd = sourceEnd; + node.sourceStart = sourceStart; + node.statementEnd = sourceEnd; } - - private void applyOffsetVariable(AbstractVariableDeclaration node) { - applyOffsetASTNode(node); - node.declarationEnd = newSourceEnd; - node.declarationSourceEnd = newSourceEnd; - node.declarationSourceStart = newSourceStart; - node.modifiersSourceStart = newSourceStart; + + private void fixPositions(AbstractVariableDeclaration node) { + node.sourceEnd = sourceEnd; + node.sourceStart = sourceStart; + node.declarationEnd = sourceEnd; + node.declarationSourceEnd = sourceEnd; + node.declarationSourceStart = sourceStart; + node.modifiersSourceStart = sourceStart; } - private void applyOffsetFieldDeclaration(FieldDeclaration node) { - applyOffsetVariable(node); - node.endPart1Position = newSourceEnd; - node.endPart2Position = newSourceEnd; + private void fixPositions(FieldDeclaration node) { + node.sourceEnd = sourceEnd; + node.sourceStart = sourceStart; + node.declarationEnd = sourceEnd; + node.declarationSourceEnd = sourceEnd; + node.declarationSourceStart = sourceStart; + node.modifiersSourceStart = sourceStart; + node.endPart1Position = sourceEnd; + node.endPart2Position = sourceEnd; } - private void applyOffsetFieldReference(FieldReference node) { - applyOffsetExpression(node); - node.nameSourcePosition = recalcSourcePosition(node.nameSourcePosition); + private void fixPositions(FieldReference node) { + node.sourceEnd = sourceEnd; + node.sourceStart = sourceStart; + node.statementEnd = sourceEnd; + node.nameSourcePosition = sourcePos; } - private void applyOffsetMessageSend(MessageSend node) { - applyOffsetExpression(node); - node.nameSourcePosition = recalcSourcePosition(node.nameSourcePosition); + private void fixPositions(MessageSend node) { + node.sourceEnd = sourceEnd; + node.sourceStart = sourceStart; + node.statementEnd = sourceEnd; + node.nameSourcePosition = sourcePos; } - private void applyOffsetQualifiedNameReference(QualifiedNameReference node) { - applyOffsetExpression(node); - for (int i = 0; i < node.sourcePositions.length; i++) { - node.sourcePositions[i] = recalcSourcePosition(node.sourcePositions[i]); - } + private void fixPositions(QualifiedNameReference node) { + node.sourceEnd = sourceEnd; + node.sourceStart = sourceStart; + node.statementEnd = sourceEnd; + if (node.sourcePositions == null || node.sourcePositions.length != node.tokens.length) node.sourcePositions = new long[node.tokens.length]; + Arrays.fill(node.sourcePositions, sourcePos); } - private void applyOffsetQualifiedTypeReference(QualifiedTypeReference node) { - applyOffsetExpression(node); - for (int i = 0; i < node.sourcePositions.length; i++) { - node.sourcePositions[i] = recalcSourcePosition(node.sourcePositions[i]); - } - } - - /** See {@link FieldReference#nameSourcePosition} for explanation */ - private long recalcSourcePosition(long sourcePosition) { -// long start = (sourcePosition >>> 32); -// long end = (sourcePosition & 0x00000000FFFFFFFFL); -// start = newSourceStart; -// end = newSourceStart; -// return ((start<<32)+end); - return ((long)newSourceStart << 32) | (newSourceEnd & INT_TO_LONG_MASK); + private void fixPositions(QualifiedTypeReference node) { + node.sourceEnd = sourceEnd; + node.sourceStart = sourceStart; + node.statementEnd = sourceEnd; + if (node.sourcePositions == null || node.sourcePositions.length != node.tokens.length) node.sourcePositions = new long[node.tokens.length]; + Arrays.fill(node.sourcePositions, sourcePos); } @Override public boolean visit(AllocationExpression node, BlockScope scope) { - setGeneratedBy(node, source); - applyOffsetExpression(node); + fixPositions(setGeneratedBy(node, source)); return super.visit(node, scope); } - + @Override public boolean visit(AND_AND_Expression node, BlockScope scope) { - setGeneratedBy(node, source); - applyOffsetExpression(node); + fixPositions(setGeneratedBy(node, source)); return super.visit(node, scope); } @Override public boolean visit(AnnotationMethodDeclaration node, ClassScope classScope) { - setGeneratedBy(node, source); - applyOffset(node); + fixPositions(setGeneratedBy(node, source)); return super.visit(node, classScope); } @Override public boolean visit(Argument node, BlockScope scope) { - setGeneratedBy(node, source); - applyOffsetVariable(node); + fixPositions(setGeneratedBy(node, source)); return super.visit(node, scope); } @Override public boolean visit(Argument node, ClassScope scope) { - setGeneratedBy(node, source); - applyOffsetVariable(node); + fixPositions(setGeneratedBy(node, source)); return super.visit(node, scope); } @Override public boolean visit(ArrayAllocationExpression node, BlockScope scope) { - setGeneratedBy(node, source); - applyOffsetExpression(node); + fixPositions(setGeneratedBy(node, source)); return super.visit(node, scope); } @Override public boolean visit(ArrayInitializer node, BlockScope scope) { - setGeneratedBy(node, source); - applyOffsetExpression(node); + fixPositions(setGeneratedBy(node, source)); return super.visit(node, scope); } @Override public boolean visit(ArrayQualifiedTypeReference node, BlockScope scope) { - setGeneratedBy(node, source); - applyOffsetQualifiedTypeReference(node); + fixPositions(setGeneratedBy(node, source)); return super.visit(node, scope); } @Override public boolean visit(ArrayQualifiedTypeReference node, ClassScope scope) { - setGeneratedBy(node, source); - applyOffsetQualifiedTypeReference(node); + fixPositions(setGeneratedBy(node, source)); return super.visit(node, scope); } @Override public boolean visit(ArrayReference node, BlockScope scope) { - setGeneratedBy(node, source); - applyOffsetExpression(node); + fixPositions(setGeneratedBy(node, source)); return super.visit(node, scope); } @Override public boolean visit(ArrayTypeReference node, BlockScope scope) { - setGeneratedBy(node, source); - applyOffset(node); + fixPositions(setGeneratedBy(node, source)); return super.visit(node, scope); } @Override public boolean visit(ArrayTypeReference node, ClassScope scope) { - setGeneratedBy(node, source); - applyOffset(node); + fixPositions(setGeneratedBy(node, source)); return super.visit(node, scope); } @Override public boolean visit(AssertStatement node, BlockScope scope) { - setGeneratedBy(node, source); - applyOffsetASTNode(node); + fixPositions(setGeneratedBy(node, source)); return super.visit(node, scope); } @Override public boolean visit(Assignment node, BlockScope scope) { - setGeneratedBy(node, source); - applyOffsetExpression(node); + fixPositions(setGeneratedBy(node, source)); return super.visit(node, scope); } @Override public boolean visit(BinaryExpression node, BlockScope scope) { - setGeneratedBy(node, source); - applyOffsetExpression(node); + fixPositions(setGeneratedBy(node, source)); return super.visit(node, scope); } @Override public boolean visit(Block node, BlockScope scope) { - setGeneratedBy(node, source); - applyOffsetASTNode(node); + fixPositions(setGeneratedBy(node, source)); return super.visit(node, scope); } @Override public boolean visit(BreakStatement node, BlockScope scope) { - setGeneratedBy(node, source); - applyOffsetASTNode(node); + fixPositions(setGeneratedBy(node, source)); return super.visit(node, scope); } @Override public boolean visit(CaseStatement node, BlockScope scope) { - setGeneratedBy(node, source); - applyOffsetASTNode(node); + fixPositions(setGeneratedBy(node, source)); return super.visit(node, scope); } @Override public boolean visit(CastExpression node, BlockScope scope) { - setGeneratedBy(node, source); - applyOffsetExpression(node); + fixPositions(setGeneratedBy(node, source)); return super.visit(node, scope); } @Override public boolean visit(CharLiteral node, BlockScope scope) { - setGeneratedBy(node, source); - applyOffsetExpression(node); + fixPositions(setGeneratedBy(node, source)); return super.visit(node, scope); } @Override public boolean visit(ClassLiteralAccess node, BlockScope scope) { - setGeneratedBy(node, source); - applyOffsetExpression(node); + fixPositions(setGeneratedBy(node, source)); return super.visit(node, scope); } @Override public boolean visit(Clinit node, ClassScope scope) { - setGeneratedBy(node, source); - applyOffset(node); + fixPositions(setGeneratedBy(node, source)); return super.visit(node, scope); } @Override public boolean visit(CompilationUnitDeclaration node, CompilationUnitScope scope) { - setGeneratedBy(node, source); - applyOffsetASTNode(node); + fixPositions(setGeneratedBy(node, source)); return super.visit(node, scope); } @Override public boolean visit(CompoundAssignment node, BlockScope scope) { - setGeneratedBy(node, source); - applyOffsetExpression(node); + fixPositions(setGeneratedBy(node, source)); return super.visit(node, scope); } @Override public boolean visit(ConditionalExpression node, BlockScope scope) { - setGeneratedBy(node, source); - applyOffsetExpression(node); + fixPositions(setGeneratedBy(node, source)); return super.visit(node, scope); } @Override public boolean visit(ConstructorDeclaration node, ClassScope scope) { - setGeneratedBy(node, source); - applyOffset(node); + fixPositions(setGeneratedBy(node, source)); return super.visit(node, scope); } @Override public boolean visit(ContinueStatement node, BlockScope scope) { - setGeneratedBy(node, source); - applyOffsetASTNode(node); + fixPositions(setGeneratedBy(node, source)); return super.visit(node, scope); } @Override public boolean visit(DoStatement node, BlockScope scope) { - setGeneratedBy(node, source); - applyOffsetASTNode(node); + fixPositions(setGeneratedBy(node, source)); return super.visit(node, scope); } @Override public boolean visit(DoubleLiteral node, BlockScope scope) { - setGeneratedBy(node, source); - applyOffsetExpression(node); + fixPositions(setGeneratedBy(node, source)); return super.visit(node, scope); } @Override public boolean visit(EmptyStatement node, BlockScope scope) { - setGeneratedBy(node, source); - applyOffsetASTNode(node); + fixPositions(setGeneratedBy(node, source)); return super.visit(node, scope); } @Override public boolean visit(EqualExpression node, BlockScope scope) { - setGeneratedBy(node, source); - applyOffsetExpression(node); + fixPositions(setGeneratedBy(node, source)); return super.visit(node, scope); } @Override public boolean visit(ExplicitConstructorCall node, BlockScope scope) { - setGeneratedBy(node, source); - applyOffsetASTNode(node); + fixPositions(setGeneratedBy(node, source)); return super.visit(node, scope); } @Override public boolean visit(ExtendedStringLiteral node, BlockScope scope) { - setGeneratedBy(node, source); - applyOffsetExpression(node); + fixPositions(setGeneratedBy(node, source)); return super.visit(node, scope); } @Override public boolean visit(FalseLiteral node, BlockScope scope) { - setGeneratedBy(node, source); - applyOffsetExpression(node); + fixPositions(setGeneratedBy(node, source)); return super.visit(node, scope); } @Override public boolean visit(FieldDeclaration node, MethodScope scope) { - setGeneratedBy(node, source); - applyOffsetFieldDeclaration(node); + fixPositions(setGeneratedBy(node, source)); return super.visit(node, scope); } @Override public boolean visit(FieldReference node, BlockScope scope) { - setGeneratedBy(node, source); - applyOffsetFieldReference(node); + fixPositions(setGeneratedBy(node, source)); return super.visit(node, scope); } @Override public boolean visit(FieldReference node, ClassScope scope) { - setGeneratedBy(node, source); - applyOffsetFieldReference(node); + fixPositions(setGeneratedBy(node, source)); return super.visit(node, scope); } @Override public boolean visit(FloatLiteral node, BlockScope scope) { - setGeneratedBy(node, source); - applyOffsetExpression(node); + fixPositions(setGeneratedBy(node, source)); return super.visit(node, scope); } @Override public boolean visit(ForeachStatement node, BlockScope scope) { - setGeneratedBy(node, source); - applyOffsetASTNode(node); + fixPositions(setGeneratedBy(node, source)); return super.visit(node, scope); } @Override public boolean visit(ForStatement node, BlockScope scope) { - setGeneratedBy(node, source); - applyOffsetASTNode(node); + fixPositions(setGeneratedBy(node, source)); return super.visit(node, scope); } @Override public boolean visit(IfStatement node, BlockScope scope) { - setGeneratedBy(node, source); - applyOffsetASTNode(node); + fixPositions(setGeneratedBy(node, source)); return super.visit(node, scope); } @Override public boolean visit(ImportReference node, CompilationUnitScope scope) { - setGeneratedBy(node, source); - applyOffset(node); + fixPositions(setGeneratedBy(node, source)); return super.visit(node, scope); } @Override public boolean visit(Initializer node, MethodScope scope) { - setGeneratedBy(node, source); - applyOffset(node); + fixPositions(setGeneratedBy(node, source)); return super.visit(node, scope); } @Override public boolean visit(InstanceOfExpression node, BlockScope scope) { - setGeneratedBy(node, source); - applyOffsetExpression(node); + fixPositions(setGeneratedBy(node, source)); return super.visit(node, scope); } @Override public boolean visit(IntLiteral node, BlockScope scope) { - setGeneratedBy(node, source); - applyOffsetExpression(node); + fixPositions(setGeneratedBy(node, source)); return super.visit(node, scope); } @Override public boolean visit(Javadoc node, BlockScope scope) { - setGeneratedBy(node, source); - applyOffset(node); + fixPositions(setGeneratedBy(node, source)); return super.visit(node, scope); } @Override public boolean visit(Javadoc node, ClassScope scope) { - setGeneratedBy(node, source); - applyOffset(node); + fixPositions(setGeneratedBy(node, source)); return super.visit(node, scope); } @Override public boolean visit(JavadocAllocationExpression node, BlockScope scope) { - setGeneratedBy(node, source); - applyOffset(node); + fixPositions(setGeneratedBy(node, source)); return super.visit(node, scope); } @Override public boolean visit(JavadocAllocationExpression node, ClassScope scope) { - setGeneratedBy(node, source); - applyOffset(node); + fixPositions(setGeneratedBy(node, source)); return super.visit(node, scope); } @Override public boolean visit(JavadocArgumentExpression node, BlockScope scope) { - setGeneratedBy(node, source); - applyOffsetExpression(node); + fixPositions(setGeneratedBy(node, source)); return super.visit(node, scope); } @Override public boolean visit(JavadocArgumentExpression node, ClassScope scope) { - setGeneratedBy(node, source); - applyOffsetExpression(node); + fixPositions(setGeneratedBy(node, source)); return super.visit(node, scope); } @Override public boolean visit(JavadocArrayQualifiedTypeReference node, BlockScope scope) { - setGeneratedBy(node, source); - applyOffset(node); + fixPositions(setGeneratedBy(node, source)); return super.visit(node, scope); } @Override public boolean visit(JavadocArrayQualifiedTypeReference node, ClassScope scope) { - setGeneratedBy(node, source); - applyOffset(node); + fixPositions(setGeneratedBy(node, source)); return super.visit(node, scope); } @Override public boolean visit(JavadocArraySingleTypeReference node, BlockScope scope) { - setGeneratedBy(node, source); - applyOffset(node); + fixPositions(setGeneratedBy(node, source)); return super.visit(node, scope); } @Override public boolean visit(JavadocArraySingleTypeReference node, ClassScope scope) { - setGeneratedBy(node, source); - applyOffset(node); + fixPositions(setGeneratedBy(node, source)); return super.visit(node, scope); } @Override public boolean visit(JavadocFieldReference node, BlockScope scope) { - setGeneratedBy(node, source); - applyOffset(node); + fixPositions(setGeneratedBy(node, source)); return super.visit(node, scope); } @Override public boolean visit(JavadocFieldReference node, ClassScope scope) { - setGeneratedBy(node, source); - applyOffset(node); + fixPositions(setGeneratedBy(node, source)); return super.visit(node, scope); } @Override public boolean visit(JavadocImplicitTypeReference node, BlockScope scope) { - setGeneratedBy(node, source); - applyOffsetExpression(node); + fixPositions(setGeneratedBy(node, source)); return super.visit(node, scope); } @Override public boolean visit(JavadocImplicitTypeReference node, ClassScope scope) { - setGeneratedBy(node, source); - applyOffsetExpression(node); + fixPositions(setGeneratedBy(node, source)); return super.visit(node, scope); } @Override public boolean visit(JavadocMessageSend node, BlockScope scope) { - setGeneratedBy(node, source); - applyOffset(node); + fixPositions(setGeneratedBy(node, source)); return super.visit(node, scope); } @Override public boolean visit(JavadocMessageSend node, ClassScope scope) { - setGeneratedBy(node, source); - applyOffset(node); + fixPositions(setGeneratedBy(node, source)); return super.visit(node, scope); } @Override public boolean visit(JavadocQualifiedTypeReference node, BlockScope scope) { - setGeneratedBy(node, source); - applyOffset(node); + fixPositions(setGeneratedBy(node, source)); return super.visit(node, scope); } @Override public boolean visit(JavadocQualifiedTypeReference node, ClassScope scope) { - setGeneratedBy(node, source); - applyOffset(node); + fixPositions(setGeneratedBy(node, source)); return super.visit(node, scope); } @Override public boolean visit(JavadocReturnStatement node, BlockScope scope) { - setGeneratedBy(node, source); - applyOffsetASTNode(node); + fixPositions(setGeneratedBy(node, source)); return super.visit(node, scope); } @Override public boolean visit(JavadocReturnStatement node, ClassScope scope) { - setGeneratedBy(node, source); - applyOffsetASTNode(node); + fixPositions(setGeneratedBy(node, source)); return super.visit(node, scope); } @Override public boolean visit(JavadocSingleNameReference node, BlockScope scope) { - setGeneratedBy(node, source); - applyOffset(node); + fixPositions(setGeneratedBy(node, source)); return super.visit(node, scope); } @Override public boolean visit(JavadocSingleNameReference node, ClassScope scope) { - setGeneratedBy(node, source); - applyOffset(node); + fixPositions(setGeneratedBy(node, source)); return super.visit(node, scope); } @Override public boolean visit(JavadocSingleTypeReference node, BlockScope scope) { - setGeneratedBy(node, source); - applyOffset(node); + fixPositions(setGeneratedBy(node, source)); return super.visit(node, scope); } @Override public boolean visit(JavadocSingleTypeReference node, ClassScope scope) { - setGeneratedBy(node, source); - applyOffset(node); + fixPositions(setGeneratedBy(node, source)); return super.visit(node, scope); } @Override public boolean visit(LabeledStatement node, BlockScope scope) { - setGeneratedBy(node, source); - applyOffsetASTNode(node); + fixPositions(setGeneratedBy(node, source)); return super.visit(node, scope); } @Override public boolean visit(LocalDeclaration node, BlockScope scope) { - setGeneratedBy(node, source); - applyOffsetVariable(node); + fixPositions(setGeneratedBy(node, source)); return super.visit(node, scope); } @Override public boolean visit(LongLiteral node, BlockScope scope) { - setGeneratedBy(node, source); - applyOffsetExpression(node); + fixPositions(setGeneratedBy(node, source)); return super.visit(node, scope); } @Override public boolean visit(MarkerAnnotation node, BlockScope scope) { - setGeneratedBy(node, source); - applyOffset(node); + fixPositions(setGeneratedBy(node, source)); return super.visit(node, scope); } @Override public boolean visit(MemberValuePair node, BlockScope scope) { - setGeneratedBy(node, source); - applyOffsetASTNode(node); + fixPositions(setGeneratedBy(node, source)); return super.visit(node, scope); } @Override public boolean visit(MessageSend node, BlockScope scope) { - setGeneratedBy(node, source); - applyOffsetMessageSend(node); + fixPositions(setGeneratedBy(node, source)); return super.visit(node, scope); } @Override public boolean visit(MethodDeclaration node, ClassScope scope) { - setGeneratedBy(node, source); - applyOffset(node); + fixPositions(setGeneratedBy(node, source)); return super.visit(node, scope); } @Override public boolean visit(StringLiteralConcatenation node, BlockScope scope) { - setGeneratedBy(node, source); - applyOffsetExpression(node); + fixPositions(setGeneratedBy(node, source)); return super.visit(node, scope); } @Override public boolean visit(NormalAnnotation node, BlockScope scope) { - setGeneratedBy(node, source); - applyOffset(node); + fixPositions(setGeneratedBy(node, source)); return super.visit(node, scope); } @Override public boolean visit(NullLiteral node, BlockScope scope) { - setGeneratedBy(node, source); - applyOffsetExpression(node); + fixPositions(setGeneratedBy(node, source)); return super.visit(node, scope); } @Override public boolean visit(OR_OR_Expression node, BlockScope scope) { - setGeneratedBy(node, source); - applyOffsetExpression(node); + fixPositions(setGeneratedBy(node, source)); return super.visit(node, scope); } @Override public boolean visit(ParameterizedQualifiedTypeReference node, BlockScope scope) { - setGeneratedBy(node, source); - applyOffsetQualifiedTypeReference(node); + fixPositions(setGeneratedBy(node, source)); return super.visit(node, scope); } @Override public boolean visit(ParameterizedQualifiedTypeReference node, ClassScope scope) { - setGeneratedBy(node, source); - applyOffsetQualifiedTypeReference(node); + fixPositions(setGeneratedBy(node, source)); return super.visit(node, scope); } @Override public boolean visit(ParameterizedSingleTypeReference node, BlockScope scope) { - setGeneratedBy(node, source); - applyOffset(node); + fixPositions(setGeneratedBy(node, source)); return super.visit(node, scope); } @Override public boolean visit(ParameterizedSingleTypeReference node, ClassScope scope) { - setGeneratedBy(node, source); - applyOffset(node); + fixPositions(setGeneratedBy(node, source)); return super.visit(node, scope); } @Override public boolean visit(PostfixExpression node, BlockScope scope) { - setGeneratedBy(node, source); - applyOffsetExpression(node); + fixPositions(setGeneratedBy(node, source)); return super.visit(node, scope); } @Override public boolean visit(PrefixExpression node, BlockScope scope) { - setGeneratedBy(node, source); - applyOffsetExpression(node); + fixPositions(setGeneratedBy(node, source)); return super.visit(node, scope); } @Override public boolean visit(QualifiedAllocationExpression node, BlockScope scope) { - setGeneratedBy(node, source); - applyOffsetExpression(node); + fixPositions(setGeneratedBy(node, source)); return super.visit(node, scope); } @Override public boolean visit(QualifiedNameReference node, BlockScope scope) { - setGeneratedBy(node, source); - applyOffsetQualifiedNameReference(node); + fixPositions(setGeneratedBy(node, source)); return super.visit(node, scope); } @Override public boolean visit(QualifiedNameReference node, ClassScope scope) { - setGeneratedBy(node, source); - applyOffsetExpression(node); + fixPositions(setGeneratedBy(node, source)); return super.visit(node, scope); } @Override public boolean visit(QualifiedSuperReference node, BlockScope scope) { - setGeneratedBy(node, source); - applyOffsetExpression(node); + fixPositions(setGeneratedBy(node, source)); return super.visit(node, scope); } @Override public boolean visit(QualifiedSuperReference node, ClassScope scope) { - setGeneratedBy(node, source); - applyOffsetExpression(node); + fixPositions(setGeneratedBy(node, source)); return super.visit(node, scope); } @Override public boolean visit(QualifiedThisReference node, BlockScope scope) { - setGeneratedBy(node, source); - applyOffsetExpression(node); + fixPositions(setGeneratedBy(node, source)); return super.visit(node, scope); } @Override public boolean visit(QualifiedThisReference node, ClassScope scope) { - setGeneratedBy(node, source); - applyOffsetExpression(node); + fixPositions(setGeneratedBy(node, source)); return super.visit(node, scope); } @Override public boolean visit(QualifiedTypeReference node, BlockScope scope) { - setGeneratedBy(node, source); - applyOffsetQualifiedTypeReference(node); + fixPositions(setGeneratedBy(node, source)); return super.visit(node, scope); } @Override public boolean visit(QualifiedTypeReference node, ClassScope scope) { - setGeneratedBy(node, source); - applyOffsetQualifiedTypeReference(node); + fixPositions(setGeneratedBy(node, source)); return super.visit(node, scope); } @Override public boolean visit(ReturnStatement node, BlockScope scope) { - setGeneratedBy(node, source); - applyOffsetASTNode(node); + fixPositions(setGeneratedBy(node, source)); return super.visit(node, scope); } @Override public boolean visit(SingleMemberAnnotation node, BlockScope scope) { - setGeneratedBy(node, source); - applyOffset(node); + fixPositions(setGeneratedBy(node, source)); return super.visit(node, scope); } @Override public boolean visit(SingleNameReference node, BlockScope scope) { - setGeneratedBy(node, source); - applyOffsetExpression(node); + fixPositions(setGeneratedBy(node, source)); return super.visit(node, scope); } @Override public boolean visit(SingleNameReference node, ClassScope scope) { - setGeneratedBy(node, source); - applyOffsetExpression(node); + fixPositions(setGeneratedBy(node, source)); return super.visit(node, scope); } @Override public boolean visit(SingleTypeReference node, BlockScope scope) { - setGeneratedBy(node, source); - applyOffsetExpression(node); + fixPositions(setGeneratedBy(node, source)); return super.visit(node, scope); } @Override public boolean visit(SingleTypeReference node, ClassScope scope) { - setGeneratedBy(node, source); - applyOffsetExpression(node); + fixPositions(setGeneratedBy(node, source)); return super.visit(node, scope); } @Override public boolean visit(StringLiteral node, BlockScope scope) { - setGeneratedBy(node, source); - applyOffsetExpression(node); + fixPositions(setGeneratedBy(node, source)); return super.visit(node, scope); } @Override public boolean visit(SuperReference node, BlockScope scope) { - setGeneratedBy(node, source); - applyOffsetExpression(node); + fixPositions(setGeneratedBy(node, source)); return super.visit(node, scope); } @Override public boolean visit(SwitchStatement node, BlockScope scope) { - setGeneratedBy(node, source); - applyOffsetASTNode(node); - node.blockStart = newSourceStart; + fixPositions(setGeneratedBy(node, source)); return super.visit(node, scope); } @Override public boolean visit(SynchronizedStatement node, BlockScope scope) { - setGeneratedBy(node, source); - applyOffsetASTNode(node); + fixPositions(setGeneratedBy(node, source)); return super.visit(node, scope); } @Override public boolean visit(ThisReference node, BlockScope scope) { - setGeneratedBy(node, source); - applyOffsetExpression(node); + fixPositions(setGeneratedBy(node, source)); return super.visit(node, scope); } @Override public boolean visit(ThisReference node, ClassScope scope) { - setGeneratedBy(node, source); + fixPositions(setGeneratedBy(node, source)); return super.visit(node, scope); } @Override public boolean visit(ThrowStatement node, BlockScope scope) { - setGeneratedBy(node, source); - applyOffsetASTNode(node); + fixPositions(setGeneratedBy(node, source)); return super.visit(node, scope); } @Override public boolean visit(TrueLiteral node, BlockScope scope) { - setGeneratedBy(node, source); - applyOffsetExpression(node); + fixPositions(setGeneratedBy(node, source)); return super.visit(node, scope); } @Override public boolean visit(TryStatement node, BlockScope scope) { - setGeneratedBy(node, source); - applyOffsetASTNode(node); + fixPositions(setGeneratedBy(node, source)); return super.visit(node, scope); } @Override public boolean visit(TypeDeclaration node, BlockScope scope) { - setGeneratedBy(node, source); - applyOffset(node); + fixPositions(setGeneratedBy(node, source)); return super.visit(node, scope); } @Override public boolean visit(TypeDeclaration node, ClassScope scope) { - setGeneratedBy(node, source); - applyOffset(node); + fixPositions(setGeneratedBy(node, source)); return super.visit(node, scope); } @Override public boolean visit(TypeDeclaration node, CompilationUnitScope scope) { - setGeneratedBy(node, source); - applyOffset(node); + fixPositions(setGeneratedBy(node, source)); return super.visit(node, scope); } @Override public boolean visit(TypeParameter node, BlockScope scope) { - setGeneratedBy(node, source); - applyOffsetVariable(node); + fixPositions(setGeneratedBy(node, source)); return super.visit(node, scope); } @Override public boolean visit(TypeParameter node, ClassScope scope) { - setGeneratedBy(node, source); - applyOffsetVariable(node); + fixPositions(setGeneratedBy(node, source)); return super.visit(node, scope); } @Override public boolean visit(UnaryExpression node, BlockScope scope) { - setGeneratedBy(node, source); - applyOffsetExpression(node); + fixPositions(setGeneratedBy(node, source)); return super.visit(node, scope); } @Override public boolean visit(WhileStatement node, BlockScope scope) { - setGeneratedBy(node, source); - applyOffsetASTNode(node); + fixPositions(setGeneratedBy(node, source)); return super.visit(node, scope); } @Override public boolean visit(Wildcard node, BlockScope scope) { - setGeneratedBy(node, source); - applyOffsetExpression(node); + fixPositions(setGeneratedBy(node, source)); return super.visit(node, scope); } @Override public boolean visit(Wildcard node, ClassScope scope) { - setGeneratedBy(node, source); - applyOffsetExpression(node); + fixPositions(setGeneratedBy(node, source)); return super.visit(node, scope); } }
\ No newline at end of file diff --git a/src/core/lombok/eclipse/handlers/singulars/EclipseGuavaMapSingularizer.java b/src/core/lombok/eclipse/handlers/singulars/EclipseGuavaMapSingularizer.java new file mode 100644 index 00000000..95fd8935 --- /dev/null +++ b/src/core/lombok/eclipse/handlers/singulars/EclipseGuavaMapSingularizer.java @@ -0,0 +1,45 @@ +/* + * Copyright (C) 2015 The Project Lombok Authors. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +package lombok.eclipse.handlers.singulars; + +import org.mangosdk.spi.ProviderFor; + +import lombok.core.LombokImmutableList; +import lombok.eclipse.handlers.EclipseSingularsRecipes.EclipseSingularizer; + +@ProviderFor(EclipseSingularizer.class) +public class EclipseGuavaMapSingularizer extends EclipseGuavaSingularizer { + // TODO cgcc.ImmutableMultimap, cgcc.ImmutableListMultimap, cgcc.ImmutableSetMultimap + // TODO cgcc.ImmutableClassToInstanceMap + // TODO cgcc.ImmutableRangeMap + + @Override public LombokImmutableList<String> getSupportedTypes() { + return LombokImmutableList.of( + "com.google.common.collect.ImmutableMap", + "com.google.common.collect.ImmutableBiMap", + "com.google.common.collect.ImmutableSortedMap"); + } + + @Override protected boolean isMap() { + return true; + } +} diff --git a/src/core/lombok/eclipse/handlers/singulars/EclipseGuavaSetListSingularizer.java b/src/core/lombok/eclipse/handlers/singulars/EclipseGuavaSetListSingularizer.java new file mode 100644 index 00000000..bc2893bf --- /dev/null +++ b/src/core/lombok/eclipse/handlers/singulars/EclipseGuavaSetListSingularizer.java @@ -0,0 +1,45 @@ +/* + * Copyright (C) 2015 The Project Lombok Authors. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +package lombok.eclipse.handlers.singulars; + +import org.mangosdk.spi.ProviderFor; + +import lombok.core.LombokImmutableList; +import lombok.eclipse.handlers.EclipseSingularsRecipes.EclipseSingularizer; + +@ProviderFor(EclipseSingularizer.class) +public class EclipseGuavaSetListSingularizer extends EclipseGuavaSingularizer { + // TODO com.google.common.collect.ImmutableTable + // TODO com.google.common.collect.ImmutableRangeSet + // TODO com.google.common.collect.ImmutableMultiset and com.google.common.collect.ImmutableSortedMultiset + @Override public LombokImmutableList<String> getSupportedTypes() { + return LombokImmutableList.of( + "com.google.common.collect.ImmutableCollection", + "com.google.common.collect.ImmutableList", + "com.google.common.collect.ImmutableSet", + "com.google.common.collect.ImmutableSortedSet"); + } + + @Override protected boolean isMap() { + return false; + } +} diff --git a/src/core/lombok/eclipse/handlers/singulars/EclipseGuavaSingularizer.java b/src/core/lombok/eclipse/handlers/singulars/EclipseGuavaSingularizer.java new file mode 100644 index 00000000..3b2ca875 --- /dev/null +++ b/src/core/lombok/eclipse/handlers/singulars/EclipseGuavaSingularizer.java @@ -0,0 +1,247 @@ +/* + * Copyright (C) 2015 The Project Lombok Authors. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +package lombok.eclipse.handlers.singulars; + +import static lombok.eclipse.Eclipse.*; +import static lombok.eclipse.handlers.EclipseHandlerUtil.*; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +import lombok.core.GuavaTypeMap; +import lombok.core.handlers.HandlerUtil; +import lombok.eclipse.EclipseNode; +import lombok.eclipse.handlers.EclipseSingularsRecipes.EclipseSingularizer; +import lombok.eclipse.handlers.EclipseSingularsRecipes.SingularData; + +import org.eclipse.jdt.internal.compiler.ast.Argument; +import org.eclipse.jdt.internal.compiler.ast.Assignment; +import org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration; +import org.eclipse.jdt.internal.compiler.ast.ConditionalExpression; +import org.eclipse.jdt.internal.compiler.ast.EqualExpression; +import org.eclipse.jdt.internal.compiler.ast.Expression; +import org.eclipse.jdt.internal.compiler.ast.FieldDeclaration; +import org.eclipse.jdt.internal.compiler.ast.FieldReference; +import org.eclipse.jdt.internal.compiler.ast.IfStatement; +import org.eclipse.jdt.internal.compiler.ast.LocalDeclaration; +import org.eclipse.jdt.internal.compiler.ast.MessageSend; +import org.eclipse.jdt.internal.compiler.ast.MethodDeclaration; +import org.eclipse.jdt.internal.compiler.ast.NullLiteral; +import org.eclipse.jdt.internal.compiler.ast.OperatorIds; +import org.eclipse.jdt.internal.compiler.ast.QualifiedNameReference; +import org.eclipse.jdt.internal.compiler.ast.QualifiedTypeReference; +import org.eclipse.jdt.internal.compiler.ast.ReturnStatement; +import org.eclipse.jdt.internal.compiler.ast.SingleNameReference; +import org.eclipse.jdt.internal.compiler.ast.Statement; +import org.eclipse.jdt.internal.compiler.ast.ThisReference; +import org.eclipse.jdt.internal.compiler.ast.TypeReference; +import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants; +import org.eclipse.jdt.internal.compiler.lookup.TypeConstants; +import org.eclipse.jdt.internal.compiler.lookup.TypeIds; + +abstract class EclipseGuavaSingularizer extends EclipseSingularizer { + protected static final char[][] JAVA_UTIL_MAP = { + {'j', 'a', 'v', 'a'}, {'u', 't', 'i', 'l'}, {'M', 'a', 'p'} + }; + + protected String getSimpleTargetTypeName(SingularData data) { + return GuavaTypeMap.getGuavaTypeName(data.getTargetFqn()); + } + + protected char[] getBuilderMethodName(SingularData data) { + String simpleTypeName = getSimpleTargetTypeName(data); + if ("ImmutableSortedSet".equals(simpleTypeName) || "ImmutableSortedMap".equals(simpleTypeName)) return "naturalOrder".toCharArray(); + return "builder".toCharArray(); + } + + protected abstract boolean isMap(); + + protected char[][] makeGuavaTypeName(String simpleName, boolean addBuilder) { + char[][] tokenizedName = new char[addBuilder ? 6 : 5][]; + tokenizedName[0] = new char[] {'c', 'o', 'm'}; + tokenizedName[1] = new char[] {'g', 'o', 'o', 'g', 'l', 'e'}; + tokenizedName[2] = new char[] {'c', 'o', 'm', 'm', 'o', 'n'}; + tokenizedName[3] = new char[] {'c', 'o', 'l', 'l', 'e', 'c', 't'}; + tokenizedName[4] = simpleName.toCharArray(); + if (addBuilder) tokenizedName[5] = new char[] { 'B', 'u', 'i', 'l', 'd', 'e', 'r'}; + return tokenizedName; + } + + @Override public List<EclipseNode> generateFields(SingularData data, EclipseNode builderType) { + char[][] tokenizedName = makeGuavaTypeName(getSimpleTargetTypeName(data), true); + TypeReference type = new QualifiedTypeReference(tokenizedName, NULL_POSS); + type = addTypeArgs(isMap() ? 2 : 1, false, builderType, type, data.getTypeArgs()); + + FieldDeclaration buildField = new FieldDeclaration(data.getPluralName(), 0, -1); + buildField.bits |= ECLIPSE_DO_NOT_TOUCH_FLAG; + buildField.modifiers = ClassFileConstants.AccPrivate; + buildField.declarationSourceEnd = -1; + buildField.type = type; + data.setGeneratedByRecursive(buildField); + return Collections.singletonList(injectField(builderType, buildField)); + } + + @Override public void generateMethods(SingularData data, EclipseNode builderType, boolean fluent, boolean chain) { + TypeReference returnType = chain ? cloneSelfType(builderType) : TypeReference.baseTypeReference(TypeIds.T_void, 0); + Statement returnStatement = chain ? new ReturnStatement(new ThisReference(0, 0), 0, 0) : null; + generateSingularMethod(returnType, returnStatement, data, builderType, fluent); + + returnType = chain ? cloneSelfType(builderType) : TypeReference.baseTypeReference(TypeIds.T_void, 0); + returnStatement = chain ? new ReturnStatement(new ThisReference(0, 0), 0, 0) : null; + generatePluralMethod(returnType, returnStatement, data, builderType, fluent); + } + + void generateSingularMethod(TypeReference returnType, Statement returnStatement, SingularData data, EclipseNode builderType, boolean fluent) { + boolean mapMode = isMap(); + char[] keyName = !mapMode ? data.getSingularName() : (new String(data.getSingularName()) + "$key").toCharArray(); + char[] valueName = !mapMode ? null : (new String(data.getSingularName()) + "$value").toCharArray(); + + MethodDeclaration md = new MethodDeclaration(((CompilationUnitDeclaration) builderType.top().get()).compilationResult); + md.bits |= ECLIPSE_DO_NOT_TOUCH_FLAG; + md.modifiers = ClassFileConstants.AccPublic; + + List<Statement> statements = new ArrayList<Statement>(); + statements.add(createConstructBuilderVarIfNeeded(data, builderType)); + + FieldReference thisDotField = new FieldReference(data.getPluralName(), 0L); + thisDotField.receiver = new ThisReference(0, 0); + MessageSend thisDotFieldDotAdd = new MessageSend(); + if (mapMode) { + thisDotFieldDotAdd.arguments = new Expression[] { + new SingleNameReference(keyName, 0L), + new SingleNameReference(valueName, 0L)}; + } else { + thisDotFieldDotAdd.arguments = new Expression[] {new SingleNameReference(keyName, 0L)}; + } + thisDotFieldDotAdd.receiver = thisDotField; + thisDotFieldDotAdd.selector = (mapMode ? "put" : "add").toCharArray(); + statements.add(thisDotFieldDotAdd); + if (returnStatement != null) statements.add(returnStatement); + md.statements = statements.toArray(new Statement[statements.size()]); + + if (mapMode) { + TypeReference keyType = cloneParamType(0, data.getTypeArgs(), builderType); + Argument keyParam = new Argument(keyName, 0, keyType, 0); + TypeReference valueType = cloneParamType(1, data.getTypeArgs(), builderType); + Argument valueParam = new Argument(valueName, 0, valueType, 0); + md.arguments = new Argument[] {keyParam, valueParam}; + } else { + TypeReference paramType = cloneParamType(0, data.getTypeArgs(), builderType); + Argument param = new Argument(keyName, 0, paramType, 0); + md.arguments = new Argument[] {param}; + } + md.returnType = returnType; + md.selector = fluent ? data.getSingularName() : HandlerUtil.buildAccessorName(mapMode ? "put" : "add", new String(data.getSingularName())).toCharArray(); + + data.setGeneratedByRecursive(md); + injectMethod(builderType, md); + } + + void generatePluralMethod(TypeReference returnType, Statement returnStatement, SingularData data, EclipseNode builderType, boolean fluent) { + boolean mapMode = isMap(); + + MethodDeclaration md = new MethodDeclaration(((CompilationUnitDeclaration) builderType.top().get()).compilationResult); + md.bits |= ECLIPSE_DO_NOT_TOUCH_FLAG; + md.modifiers = ClassFileConstants.AccPublic; + + List<Statement> statements = new ArrayList<Statement>(); + statements.add(createConstructBuilderVarIfNeeded(data, builderType)); + + FieldReference thisDotField = new FieldReference(data.getPluralName(), 0L); + thisDotField.receiver = new ThisReference(0, 0); + MessageSend thisDotFieldDotAddAll = new MessageSend(); + thisDotFieldDotAddAll.arguments = new Expression[] {new SingleNameReference(data.getPluralName(), 0L)}; + thisDotFieldDotAddAll.receiver = thisDotField; + thisDotFieldDotAddAll.selector = (mapMode ? "putAll" : "addAll").toCharArray(); + statements.add(thisDotFieldDotAddAll); + if (returnStatement != null) statements.add(returnStatement); + + md.statements = statements.toArray(new Statement[statements.size()]); + + TypeReference paramType; + if (mapMode) { + paramType = new QualifiedTypeReference(JAVA_UTIL_MAP, NULL_POSS); + paramType = addTypeArgs(2, true, builderType, paramType, data.getTypeArgs()); + } else { + paramType = new QualifiedTypeReference(TypeConstants.JAVA_LANG_ITERABLE, NULL_POSS); + paramType = addTypeArgs(1, true, builderType, paramType, data.getTypeArgs()); + } + Argument param = new Argument(data.getPluralName(), 0, paramType, 0); + md.arguments = new Argument[] {param}; + md.returnType = returnType; + md.selector = fluent ? data.getPluralName() : HandlerUtil.buildAccessorName(mapMode ? "putAll" : "addAll", new String(data.getPluralName())).toCharArray(); + + data.setGeneratedByRecursive(md); + injectMethod(builderType, md); + } + + @Override public void appendBuildCode(SingularData data, EclipseNode builderType, List<Statement> statements, char[] targetVariableName) { + boolean mapMode = isMap(); + TypeReference varType = new QualifiedTypeReference(fromQualifiedName(data.getTargetFqn()), NULL_POSS); + varType = addTypeArgs(mapMode ? 2 : 1, false, builderType, varType, data.getTypeArgs()); + + MessageSend emptyInvoke; { + //ImmutableX.of() + emptyInvoke = new MessageSend(); + emptyInvoke.selector = new char[] {'o', 'f'}; + emptyInvoke.receiver = new QualifiedNameReference(makeGuavaTypeName(getSimpleTargetTypeName(data), false), NULL_POSS, 0, 0); + emptyInvoke.typeArguments = createTypeArgs(mapMode ? 2 : 1, false, builderType, data.getTypeArgs()); + } + + MessageSend invokeBuild; { + //this.pluralName.build(); + invokeBuild = new MessageSend(); + invokeBuild.selector = new char[] {'b', 'u', 'i', 'l', 'd'}; + FieldReference thisDotField = new FieldReference(data.getPluralName(), 0L); + thisDotField.receiver = new ThisReference(0, 0); + invokeBuild.receiver = thisDotField; + } + + Expression isNull; { + //this.pluralName == null + FieldReference thisDotField = new FieldReference(data.getPluralName(), 0L); + thisDotField.receiver = new ThisReference(0, 0); + isNull = new EqualExpression(thisDotField, new NullLiteral(0, 0), OperatorIds.EQUAL_EQUAL); + } + + Expression init = new ConditionalExpression(isNull, emptyInvoke, invokeBuild); + LocalDeclaration varDefStat = new LocalDeclaration(data.getPluralName(), 0, 0); + varDefStat.type = varType; + varDefStat.initialization = init; + statements.add(varDefStat); + } + + protected Statement createConstructBuilderVarIfNeeded(SingularData data, EclipseNode builderType) { + FieldReference thisDotField = new FieldReference(data.getPluralName(), 0L); + thisDotField.receiver = new ThisReference(0, 0); + FieldReference thisDotField2 = new FieldReference(data.getPluralName(), 0L); + thisDotField2.receiver = new ThisReference(0, 0); + Expression cond = new EqualExpression(thisDotField, new NullLiteral(0, 0), OperatorIds.EQUAL_EQUAL); + + MessageSend createBuilderInvoke = new MessageSend(); + char[][] tokenizedName = makeGuavaTypeName(getSimpleTargetTypeName(data), false); + createBuilderInvoke.receiver = new QualifiedNameReference(tokenizedName, NULL_POSS, 0, 0); + createBuilderInvoke.selector = getBuilderMethodName(data); + return new IfStatement(cond, new Assignment(thisDotField2, createBuilderInvoke, 0), 0, 0); + } +} diff --git a/src/core/lombok/eclipse/handlers/singulars/EclipseJavaUtilListSetSingularizer.java b/src/core/lombok/eclipse/handlers/singulars/EclipseJavaUtilListSetSingularizer.java new file mode 100644 index 00000000..1d1c4dbd --- /dev/null +++ b/src/core/lombok/eclipse/handlers/singulars/EclipseJavaUtilListSetSingularizer.java @@ -0,0 +1,158 @@ +/* + * Copyright (C) 2015 The Project Lombok Authors. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +package lombok.eclipse.handlers.singulars; + +import static lombok.eclipse.Eclipse.ECLIPSE_DO_NOT_TOUCH_FLAG; +import static lombok.eclipse.handlers.EclipseHandlerUtil.*; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +import lombok.core.handlers.HandlerUtil; +import lombok.eclipse.EclipseNode; +import lombok.eclipse.handlers.EclipseSingularsRecipes.SingularData; + +import org.eclipse.jdt.internal.compiler.ast.Argument; +import org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration; +import org.eclipse.jdt.internal.compiler.ast.Expression; +import org.eclipse.jdt.internal.compiler.ast.FieldDeclaration; +import org.eclipse.jdt.internal.compiler.ast.FieldReference; +import org.eclipse.jdt.internal.compiler.ast.MessageSend; +import org.eclipse.jdt.internal.compiler.ast.MethodDeclaration; +import org.eclipse.jdt.internal.compiler.ast.QualifiedTypeReference; +import org.eclipse.jdt.internal.compiler.ast.ReturnStatement; +import org.eclipse.jdt.internal.compiler.ast.SingleNameReference; +import org.eclipse.jdt.internal.compiler.ast.Statement; +import org.eclipse.jdt.internal.compiler.ast.ThisReference; +import org.eclipse.jdt.internal.compiler.ast.TypeReference; +import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants; +import org.eclipse.jdt.internal.compiler.lookup.TypeConstants; +import org.eclipse.jdt.internal.compiler.lookup.TypeIds; + +abstract class EclipseJavaUtilListSetSingularizer extends EclipseJavaUtilSingularizer { + @Override public List<char[]> listFieldsToBeGenerated(SingularData data, EclipseNode builderType) { + if (useGuavaInstead(builderType)) { + return guavaListSetSingularizer.listFieldsToBeGenerated(data, builderType); + } + + return super.listFieldsToBeGenerated(data, builderType); + } + + @Override public List<char[]> listMethodsToBeGenerated(SingularData data, EclipseNode builderType) { + if (useGuavaInstead(builderType)) { + return guavaListSetSingularizer.listMethodsToBeGenerated(data, builderType); + } + + return super.listMethodsToBeGenerated(data, builderType); + } + + @Override public List<EclipseNode> generateFields(SingularData data, EclipseNode builderType) { + if (useGuavaInstead(builderType)) { + return guavaListSetSingularizer.generateFields(data, builderType); + } + + TypeReference type = new QualifiedTypeReference(JAVA_UTIL_ARRAYLIST, NULL_POSS); + type = addTypeArgs(1, false, builderType, type, data.getTypeArgs()); + + FieldDeclaration buildField = new FieldDeclaration(data.getPluralName(), 0, -1); + buildField.bits |= ECLIPSE_DO_NOT_TOUCH_FLAG; + buildField.modifiers = ClassFileConstants.AccPrivate; + buildField.declarationSourceEnd = -1; + buildField.type = type; + data.setGeneratedByRecursive(buildField); + return Collections.singletonList(injectField(builderType, buildField)); + } + + @Override public void generateMethods(SingularData data, EclipseNode builderType, boolean fluent, boolean chain) { + if (useGuavaInstead(builderType)) { + guavaListSetSingularizer.generateMethods(data, builderType, fluent, chain); + return; + } + + TypeReference returnType = chain ? cloneSelfType(builderType) : TypeReference.baseTypeReference(TypeIds.T_void, 0); + Statement returnStatement = chain ? new ReturnStatement(new ThisReference(0, 0), 0, 0) : null; + generateSingularMethod(returnType, returnStatement, data, builderType, fluent); + + returnType = chain ? cloneSelfType(builderType) : TypeReference.baseTypeReference(TypeIds.T_void, 0); + returnStatement = chain ? new ReturnStatement(new ThisReference(0, 0), 0, 0) : null; + generatePluralMethod(returnType, returnStatement, data, builderType, fluent); + } + + void generateSingularMethod(TypeReference returnType, Statement returnStatement, SingularData data, EclipseNode builderType, boolean fluent) { + MethodDeclaration md = new MethodDeclaration(((CompilationUnitDeclaration) builderType.top().get()).compilationResult); + md.bits |= ECLIPSE_DO_NOT_TOUCH_FLAG; + md.modifiers = ClassFileConstants.AccPublic; + + List<Statement> statements = new ArrayList<Statement>(); + statements.add(createConstructBuilderVarIfNeeded(data, builderType, false)); + + FieldReference thisDotField = new FieldReference(data.getPluralName(), 0L); + thisDotField.receiver = new ThisReference(0, 0); + MessageSend thisDotFieldDotAdd = new MessageSend(); + thisDotFieldDotAdd.arguments = new Expression[] {new SingleNameReference(data.getSingularName(), 0L)}; + thisDotFieldDotAdd.receiver = thisDotField; + thisDotFieldDotAdd.selector = "add".toCharArray(); + statements.add(thisDotFieldDotAdd); + if (returnStatement != null) statements.add(returnStatement); + + md.statements = statements.toArray(new Statement[statements.size()]); + TypeReference paramType = cloneParamType(0, data.getTypeArgs(), builderType); + Argument param = new Argument(data.getSingularName(), 0, paramType, 0); + md.arguments = new Argument[] {param}; + md.returnType = returnType; + md.selector = fluent ? data.getSingularName() : HandlerUtil.buildAccessorName("add", new String(data.getSingularName())).toCharArray(); + + data.setGeneratedByRecursive(md); + injectMethod(builderType, md); + } + + void generatePluralMethod(TypeReference returnType, Statement returnStatement, SingularData data, EclipseNode builderType, boolean fluent) { + MethodDeclaration md = new MethodDeclaration(((CompilationUnitDeclaration) builderType.top().get()).compilationResult); + md.bits |= ECLIPSE_DO_NOT_TOUCH_FLAG; + md.modifiers = ClassFileConstants.AccPublic; + + List<Statement> statements = new ArrayList<Statement>(); + statements.add(createConstructBuilderVarIfNeeded(data, builderType, false)); + + FieldReference thisDotField = new FieldReference(data.getPluralName(), 0L); + thisDotField.receiver = new ThisReference(0, 0); + MessageSend thisDotFieldDotAddAll = new MessageSend(); + thisDotFieldDotAddAll.arguments = new Expression[] {new SingleNameReference(data.getPluralName(), 0L)}; + thisDotFieldDotAddAll.receiver = thisDotField; + thisDotFieldDotAddAll.selector = "addAll".toCharArray(); + statements.add(thisDotFieldDotAddAll); + if (returnStatement != null) statements.add(returnStatement); + + md.statements = statements.toArray(new Statement[statements.size()]); + + TypeReference paramType = new QualifiedTypeReference(TypeConstants.JAVA_UTIL_COLLECTION, NULL_POSS); + paramType = addTypeArgs(1, true, builderType, paramType, data.getTypeArgs()); + Argument param = new Argument(data.getPluralName(), 0, paramType, 0); + md.arguments = new Argument[] {param}; + md.returnType = returnType; + md.selector = fluent ? data.getPluralName() : HandlerUtil.buildAccessorName("addAll", new String(data.getPluralName())).toCharArray(); + + data.setGeneratedByRecursive(md); + injectMethod(builderType, md); + } +} diff --git a/src/core/lombok/eclipse/handlers/singulars/EclipseJavaUtilListSingularizer.java b/src/core/lombok/eclipse/handlers/singulars/EclipseJavaUtilListSingularizer.java new file mode 100644 index 00000000..576115b0 --- /dev/null +++ b/src/core/lombok/eclipse/handlers/singulars/EclipseJavaUtilListSingularizer.java @@ -0,0 +1,129 @@ +/* + * Copyright (C) 2015 The Project Lombok Authors. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +package lombok.eclipse.handlers.singulars; + +import static lombok.eclipse.handlers.EclipseHandlerUtil.makeIntLiteral; + +import java.util.ArrayList; +import java.util.List; + +import lombok.core.LombokImmutableList; +import lombok.eclipse.Eclipse; +import lombok.eclipse.EclipseNode; +import lombok.eclipse.handlers.EclipseSingularsRecipes.EclipseSingularizer; +import lombok.eclipse.handlers.EclipseSingularsRecipes.SingularData; + +import org.eclipse.jdt.internal.compiler.ast.AllocationExpression; +import org.eclipse.jdt.internal.compiler.ast.Assignment; +import org.eclipse.jdt.internal.compiler.ast.BreakStatement; +import org.eclipse.jdt.internal.compiler.ast.CaseStatement; +import org.eclipse.jdt.internal.compiler.ast.Expression; +import org.eclipse.jdt.internal.compiler.ast.FieldReference; +import org.eclipse.jdt.internal.compiler.ast.LocalDeclaration; +import org.eclipse.jdt.internal.compiler.ast.MessageSend; +import org.eclipse.jdt.internal.compiler.ast.QualifiedNameReference; +import org.eclipse.jdt.internal.compiler.ast.QualifiedTypeReference; +import org.eclipse.jdt.internal.compiler.ast.SingleNameReference; +import org.eclipse.jdt.internal.compiler.ast.Statement; +import org.eclipse.jdt.internal.compiler.ast.SwitchStatement; +import org.eclipse.jdt.internal.compiler.ast.ThisReference; +import org.eclipse.jdt.internal.compiler.ast.TypeReference; +import org.mangosdk.spi.ProviderFor; + + +@ProviderFor(EclipseSingularizer.class) +public class EclipseJavaUtilListSingularizer extends EclipseJavaUtilListSetSingularizer { + @Override public LombokImmutableList<String> getSupportedTypes() { + return LombokImmutableList.of("java.util.List", "java.util.Collection", "java.lang.Iterable"); + } + + @Override public void appendBuildCode(SingularData data, EclipseNode builderType, List<Statement> statements, char[] targetVariableName) { + if (useGuavaInstead(builderType)) { + guavaListSetSingularizer.appendBuildCode(data, builderType, statements, targetVariableName); + return; + } + + List<Statement> switchContents = new ArrayList<Statement>(); + + /* case 0: (empty) break; */ { + switchContents.add(new CaseStatement(makeIntLiteral(new char[] {'0'}, null), 0, 0)); + MessageSend invoke = new MessageSend(); + invoke.receiver = new QualifiedNameReference(JAVA_UTIL_COLLECTIONS, NULL_POSS, 0, 0); + invoke.selector = "emptyList".toCharArray(); + switchContents.add(new Assignment(new SingleNameReference(data.getPluralName(), 0), invoke, 0)); + switchContents.add(new BreakStatement(null, 0, 0)); + } + + /* case 1: (singleton) break; */ { + switchContents.add(new CaseStatement(makeIntLiteral(new char[] {'1'}, null), 0, 0)); + FieldReference thisDotField = new FieldReference(data.getPluralName(), 0L); + thisDotField.receiver = new ThisReference(0, 0); + MessageSend thisDotFieldGet0 = new MessageSend(); + thisDotFieldGet0.receiver = thisDotField; + thisDotFieldGet0.selector = new char[] {'g', 'e', 't'}; + thisDotFieldGet0.arguments = new Expression[] {makeIntLiteral(new char[] {'0'}, null)}; + + Expression[] args = new Expression[] {thisDotFieldGet0}; + MessageSend invoke = new MessageSend(); + invoke.receiver = new QualifiedNameReference(JAVA_UTIL_COLLECTIONS, NULL_POSS, 0, 0); + invoke.selector = "singletonList".toCharArray(); + invoke.arguments = args; + switchContents.add(new Assignment(new SingleNameReference(data.getPluralName(), 0), invoke, 0)); + switchContents.add(new BreakStatement(null, 0, 0)); + } + + /* default: Create by passing builder field to constructor. */ { + switchContents.add(new CaseStatement(null, 0, 0)); + + Expression argToUnmodifiable; + /* new j.u.ArrayList<Generics>(this.pluralName); */ { + FieldReference thisDotPluralName = new FieldReference(data.getPluralName(), 0L); + thisDotPluralName.receiver = new ThisReference(0, 0); + TypeReference targetTypeExpr = new QualifiedTypeReference(JAVA_UTIL_ARRAYLIST, NULL_POSS); + targetTypeExpr = addTypeArgs(1, false, builderType, targetTypeExpr, data.getTypeArgs()); + AllocationExpression constructorCall = new AllocationExpression(); + constructorCall.type = targetTypeExpr; + constructorCall.arguments = new Expression[] {thisDotPluralName}; + argToUnmodifiable = constructorCall; + } + + /* pluralname = Collections.unmodifiableList(-newlist-); */ { + MessageSend unmodInvoke = new MessageSend(); + unmodInvoke.receiver = new QualifiedNameReference(JAVA_UTIL_COLLECTIONS, NULL_POSS, 0, 0); + unmodInvoke.selector = "unmodifiableList".toCharArray(); + unmodInvoke.arguments = new Expression[] {argToUnmodifiable}; + switchContents.add(new Assignment(new SingleNameReference(data.getPluralName(), 0), unmodInvoke, 0)); + } + } + + SwitchStatement switchStat = new SwitchStatement(); + switchStat.statements = switchContents.toArray(new Statement[switchContents.size()]); + switchStat.expression = getSize(builderType, data.getPluralName(), true); + + TypeReference localShadowerType = new QualifiedTypeReference(Eclipse.fromQualifiedName(data.getTargetFqn()), NULL_POSS); + localShadowerType = addTypeArgs(1, false, builderType, localShadowerType, data.getTypeArgs()); + LocalDeclaration varDefStat = new LocalDeclaration(data.getPluralName(), 0, 0); + varDefStat.type = localShadowerType; + statements.add(varDefStat); + statements.add(switchStat); + } +} diff --git a/src/core/lombok/eclipse/handlers/singulars/EclipseJavaUtilMapSingularizer.java b/src/core/lombok/eclipse/handlers/singulars/EclipseJavaUtilMapSingularizer.java new file mode 100644 index 00000000..640bd396 --- /dev/null +++ b/src/core/lombok/eclipse/handlers/singulars/EclipseJavaUtilMapSingularizer.java @@ -0,0 +1,270 @@ +/* + * Copyright (C) 2015 The Project Lombok Authors. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +package lombok.eclipse.handlers.singulars; + +import static lombok.eclipse.Eclipse.*; +import static lombok.eclipse.handlers.EclipseHandlerUtil.*; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; + +import org.eclipse.jdt.internal.compiler.ast.Argument; +import org.eclipse.jdt.internal.compiler.ast.Block; +import org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration; +import org.eclipse.jdt.internal.compiler.ast.Expression; +import org.eclipse.jdt.internal.compiler.ast.FieldDeclaration; +import org.eclipse.jdt.internal.compiler.ast.FieldReference; +import org.eclipse.jdt.internal.compiler.ast.ForeachStatement; +import org.eclipse.jdt.internal.compiler.ast.LocalDeclaration; +import org.eclipse.jdt.internal.compiler.ast.MessageSend; +import org.eclipse.jdt.internal.compiler.ast.MethodDeclaration; +import org.eclipse.jdt.internal.compiler.ast.QualifiedTypeReference; +import org.eclipse.jdt.internal.compiler.ast.ReturnStatement; +import org.eclipse.jdt.internal.compiler.ast.SingleNameReference; +import org.eclipse.jdt.internal.compiler.ast.Statement; +import org.eclipse.jdt.internal.compiler.ast.ThisReference; +import org.eclipse.jdt.internal.compiler.ast.TypeReference; +import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants; +import org.eclipse.jdt.internal.compiler.lookup.TypeIds; +import org.mangosdk.spi.ProviderFor; + +import lombok.core.LombokImmutableList; +import lombok.core.handlers.HandlerUtil; +import lombok.eclipse.EclipseNode; +import lombok.eclipse.handlers.EclipseSingularsRecipes.EclipseSingularizer; +import lombok.eclipse.handlers.EclipseSingularsRecipes.SingularData; + +@ProviderFor(EclipseSingularizer.class) +public class EclipseJavaUtilMapSingularizer extends EclipseJavaUtilSingularizer { + @Override public LombokImmutableList<String> getSupportedTypes() { + return LombokImmutableList.of("java.util.Map", "java.util.SortedMap", "java.util.NavigableMap"); + } + + @Override public List<char[]> listFieldsToBeGenerated(SingularData data, EclipseNode builderType) { + if (useGuavaInstead(builderType)) { + return guavaMapSingularizer.listFieldsToBeGenerated(data, builderType); + } + + char[] p = data.getPluralName(); + int len = p.length; + char[] k = new char[len + 4]; + char[] v = new char[len + 6]; + System.arraycopy(p, 0, k, 0, len); + System.arraycopy(p, 0, v, 0, len); + k[len] = '$'; + k[len + 1] = 'k'; + k[len + 2] = 'e'; + k[len + 3] = 'y'; + v[len] = '$'; + v[len + 1] = 'v'; + v[len + 2] = 'a'; + v[len + 3] = 'l'; + v[len + 4] = 'u'; + v[len + 5] = 'e'; + return Arrays.asList(k, v); + } + + @Override public List<char[]> listMethodsToBeGenerated(SingularData data, EclipseNode builderType) { + if (useGuavaInstead(builderType)) { + return guavaMapSingularizer.listFieldsToBeGenerated(data, builderType); + } else { + return super.listMethodsToBeGenerated(data, builderType); + } + } + + @Override public List<EclipseNode> generateFields(SingularData data, EclipseNode builderType) { + if (useGuavaInstead(builderType)) { + return guavaMapSingularizer.generateFields(data, builderType); + } + + char[] keyName = (new String(data.getPluralName()) + "$key").toCharArray(); + char[] valueName = (new String(data.getPluralName()) + "$value").toCharArray(); + FieldDeclaration buildKeyField; { + TypeReference type = new QualifiedTypeReference(JAVA_UTIL_ARRAYLIST, NULL_POSS); + type = addTypeArgs(1, false, builderType, type, data.getTypeArgs()); + buildKeyField = new FieldDeclaration(keyName, 0, -1); + buildKeyField.bits |= ECLIPSE_DO_NOT_TOUCH_FLAG; + buildKeyField.modifiers = ClassFileConstants.AccPrivate; + buildKeyField.declarationSourceEnd = -1; + buildKeyField.type = type; + } + FieldDeclaration buildValueField; { + TypeReference type = new QualifiedTypeReference(JAVA_UTIL_ARRAYLIST, NULL_POSS); + List<TypeReference> tArgs = data.getTypeArgs(); + if (tArgs != null && tArgs.size() > 1) tArgs = Collections.singletonList(tArgs.get(1)); + else tArgs = Collections.emptyList(); + type = addTypeArgs(1, false, builderType, type, tArgs); + buildValueField = new FieldDeclaration(valueName, 0, -1); + buildValueField.bits |= ECLIPSE_DO_NOT_TOUCH_FLAG; + buildValueField.modifiers = ClassFileConstants.AccPrivate; + buildValueField.declarationSourceEnd = -1; + buildValueField.type = type; + } + data.setGeneratedByRecursive(buildKeyField); + data.setGeneratedByRecursive(buildValueField); + EclipseNode keyFieldNode = injectField(builderType, buildKeyField); + EclipseNode valueFieldNode = injectField(builderType, buildValueField); + return Arrays.asList(keyFieldNode, valueFieldNode); + } + + @Override public void generateMethods(SingularData data, EclipseNode builderType, boolean fluent, boolean chain) { + if (useGuavaInstead(builderType)) { + guavaMapSingularizer.generateMethods(data, builderType, fluent, chain); + return; + } + + TypeReference returnType = chain ? cloneSelfType(builderType) : TypeReference.baseTypeReference(TypeIds.T_void, 0); + Statement returnStatement = chain ? new ReturnStatement(new ThisReference(0, 0), 0, 0) : null; + generateSingularMethod(returnType, returnStatement, data, builderType, fluent); + + returnType = chain ? cloneSelfType(builderType) : TypeReference.baseTypeReference(TypeIds.T_void, 0); + returnStatement = chain ? new ReturnStatement(new ThisReference(0, 0), 0, 0) : null; + generatePluralMethod(returnType, returnStatement, data, builderType, fluent); + } + + private void generateSingularMethod(TypeReference returnType, Statement returnStatement, SingularData data, EclipseNode builderType, boolean fluent) { + MethodDeclaration md = new MethodDeclaration(((CompilationUnitDeclaration) builderType.top().get()).compilationResult); + md.bits |= ECLIPSE_DO_NOT_TOUCH_FLAG; + md.modifiers = ClassFileConstants.AccPublic; + + List<Statement> statements = new ArrayList<Statement>(); + statements.add(createConstructBuilderVarIfNeeded(data, builderType, true)); + + String sN = new String(data.getSingularName()); + String pN = new String(data.getPluralName()); + char[] keyParamName = (sN + "Key").toCharArray(); + char[] valueParamName = (sN + "Value").toCharArray(); + char[] keyFieldName = (pN + "$key").toCharArray(); + char[] valueFieldName = (pN + "$value").toCharArray(); + + /* this.pluralname$key.add(singularnameKey); */ { + FieldReference thisDotKeyField = new FieldReference(keyFieldName, 0L); + thisDotKeyField.receiver = new ThisReference(0, 0); + MessageSend thisDotKeyFieldDotAdd = new MessageSend(); + thisDotKeyFieldDotAdd.arguments = new Expression[] {new SingleNameReference(keyParamName, 0L)}; + thisDotKeyFieldDotAdd.receiver = thisDotKeyField; + thisDotKeyFieldDotAdd.selector = "add".toCharArray(); + statements.add(thisDotKeyFieldDotAdd); + } + + /* this.pluralname$value.add(singularnameValue); */ { + FieldReference thisDotValueField = new FieldReference(valueFieldName, 0L); + thisDotValueField.receiver = new ThisReference(0, 0); + MessageSend thisDotValueFieldDotAdd = new MessageSend(); + thisDotValueFieldDotAdd.arguments = new Expression[] {new SingleNameReference(valueParamName, 0L)}; + thisDotValueFieldDotAdd.receiver = thisDotValueField; + thisDotValueFieldDotAdd.selector = "add".toCharArray(); + statements.add(thisDotValueFieldDotAdd); + } + if (returnStatement != null) statements.add(returnStatement); + + md.statements = statements.toArray(new Statement[statements.size()]); + TypeReference keyParamType = cloneParamType(0, data.getTypeArgs(), builderType); + Argument keyParam = new Argument(keyParamName, 0, keyParamType, 0); + TypeReference valueParamType = cloneParamType(1, data.getTypeArgs(), builderType); + Argument valueParam = new Argument(valueParamName, 0, valueParamType, 0); + md.arguments = new Argument[] {keyParam, valueParam}; + md.returnType = returnType; + md.selector = fluent ? data.getSingularName() : HandlerUtil.buildAccessorName("put", new String(data.getSingularName())).toCharArray(); + + data.setGeneratedByRecursive(md); + injectMethod(builderType, md); + } + + private void generatePluralMethod(TypeReference returnType, Statement returnStatement, SingularData data, EclipseNode builderType, boolean fluent) { + MethodDeclaration md = new MethodDeclaration(((CompilationUnitDeclaration) builderType.top().get()).compilationResult); + md.bits |= ECLIPSE_DO_NOT_TOUCH_FLAG; + md.modifiers = ClassFileConstants.AccPublic; + + String pN = new String(data.getPluralName()); + char[] keyFieldName = (pN + "$key").toCharArray(); + char[] valueFieldName = (pN + "$value").toCharArray(); + + List<Statement> statements = new ArrayList<Statement>(); + statements.add(createConstructBuilderVarIfNeeded(data, builderType, true)); + + char[] entryName = "$lombokEntry".toCharArray(); + + TypeReference forEachType = new QualifiedTypeReference(JAVA_UTIL_MAP_ENTRY, NULL_POSS); + forEachType = addTypeArgs(2, true, builderType, forEachType, data.getTypeArgs()); + + MessageSend keyArg = new MessageSend(); + keyArg.receiver = new SingleNameReference(entryName, 0L); + keyArg.selector = "getKey".toCharArray(); + MessageSend addKey = new MessageSend(); + FieldReference thisDotKeyField = new FieldReference(keyFieldName, 0L); + thisDotKeyField.receiver = new ThisReference(0, 0); + addKey.receiver = thisDotKeyField; + addKey.selector = new char[] {'a', 'd', 'd'}; + addKey.arguments = new Expression[] {keyArg}; + + MessageSend valueArg = new MessageSend(); + valueArg.receiver = new SingleNameReference(entryName, 0L); + valueArg.selector = "getValue".toCharArray(); + MessageSend addValue = new MessageSend(); + FieldReference thisDotValueField = new FieldReference(valueFieldName, 0L); + thisDotValueField.receiver = new ThisReference(0, 0); + addValue.receiver = thisDotValueField; + addValue.selector = new char[] {'a', 'd', 'd'}; + addValue.arguments = new Expression[] {valueArg}; + + LocalDeclaration elementVariable = new LocalDeclaration(entryName, 0, 0); + elementVariable.type = forEachType; + ForeachStatement forEach = new ForeachStatement(elementVariable, 0); + MessageSend invokeEntrySet = new MessageSend(); + invokeEntrySet.selector = new char[] { 'e', 'n', 't', 'r', 'y', 'S', 'e', 't'}; + invokeEntrySet.receiver = new SingleNameReference(data.getPluralName(), 0L); + forEach.collection = invokeEntrySet; + Block forEachContent = new Block(0); + forEachContent.statements = new Statement[] {addKey, addValue}; + forEach.action = forEachContent; + statements.add(forEach); + if (returnStatement != null) statements.add(returnStatement); + + md.statements = statements.toArray(new Statement[statements.size()]); + + TypeReference paramType = new QualifiedTypeReference(JAVA_UTIL_MAP, NULL_POSS); + paramType = addTypeArgs(2, true, builderType, paramType, data.getTypeArgs()); + Argument param = new Argument(data.getPluralName(), 0, paramType, 0); + md.arguments = new Argument[] {param}; + md.returnType = returnType; + md.selector = fluent ? data.getPluralName() : HandlerUtil.buildAccessorName("putAll", new String(data.getPluralName())).toCharArray(); + + data.setGeneratedByRecursive(md); + injectMethod(builderType, md); + } + + @Override public void appendBuildCode(SingularData data, EclipseNode builderType, List<Statement> statements, char[] targetVariableName) { + if (useGuavaInstead(builderType)) { + guavaMapSingularizer.appendBuildCode(data, builderType, statements, targetVariableName); + return; + } + + if (data.getTargetFqn().equals("java.util.Map")) { + statements.addAll(createJavaUtilSetMapInitialCapacitySwitchStatements(data, builderType, true, "emptyMap", "singletonMap", "LinkedHashMap")); + } else { + statements.addAll(createJavaUtilSimpleCreationAndFillStatements(data, builderType, true, true, false, true, "TreeMap")); + } + } +} diff --git a/src/core/lombok/eclipse/handlers/singulars/EclipseJavaUtilSetSingularizer.java b/src/core/lombok/eclipse/handlers/singulars/EclipseJavaUtilSetSingularizer.java new file mode 100644 index 00000000..2d16eae0 --- /dev/null +++ b/src/core/lombok/eclipse/handlers/singulars/EclipseJavaUtilSetSingularizer.java @@ -0,0 +1,52 @@ +/* + * Copyright (C) 2015 The Project Lombok Authors. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +package lombok.eclipse.handlers.singulars; + +import java.util.List; + +import lombok.core.LombokImmutableList; +import lombok.eclipse.EclipseNode; +import lombok.eclipse.handlers.EclipseSingularsRecipes.EclipseSingularizer; +import lombok.eclipse.handlers.EclipseSingularsRecipes.SingularData; + +import org.eclipse.jdt.internal.compiler.ast.Statement; +import org.mangosdk.spi.ProviderFor; + +@ProviderFor(EclipseSingularizer.class) +public class EclipseJavaUtilSetSingularizer extends EclipseJavaUtilListSetSingularizer { + @Override public LombokImmutableList<String> getSupportedTypes() { + return LombokImmutableList.of("java.util.Set", "java.util.SortedSet", "java.util.NavigableSet"); + } + + @Override public void appendBuildCode(SingularData data, EclipseNode builderType, List<Statement> statements, char[] targetVariableName) { + if (useGuavaInstead(builderType)) { + guavaListSetSingularizer.appendBuildCode(data, builderType, statements, targetVariableName); + return; + } + + if (data.getTargetFqn().equals("java.util.Set")) { + statements.addAll(createJavaUtilSetMapInitialCapacitySwitchStatements(data, builderType, false, "emptySet", "singleton", "LinkedHashSet")); + } else { + statements.addAll(createJavaUtilSimpleCreationAndFillStatements(data, builderType, false, true, false, true, "TreeSet")); + } + } +} diff --git a/src/core/lombok/eclipse/handlers/singulars/EclipseJavaUtilSingularizer.java b/src/core/lombok/eclipse/handlers/singulars/EclipseJavaUtilSingularizer.java new file mode 100644 index 00000000..6661f4af --- /dev/null +++ b/src/core/lombok/eclipse/handlers/singulars/EclipseJavaUtilSingularizer.java @@ -0,0 +1,300 @@ +/* + * Copyright (C) 2015 The Project Lombok Authors. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +package lombok.eclipse.handlers.singulars; + +import static lombok.eclipse.Eclipse.*; +import static lombok.eclipse.handlers.EclipseHandlerUtil.*; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; + +import org.eclipse.jdt.internal.compiler.ast.AllocationExpression; +import org.eclipse.jdt.internal.compiler.ast.Assignment; +import org.eclipse.jdt.internal.compiler.ast.BinaryExpression; +import org.eclipse.jdt.internal.compiler.ast.Block; +import org.eclipse.jdt.internal.compiler.ast.BreakStatement; +import org.eclipse.jdt.internal.compiler.ast.CaseStatement; +import org.eclipse.jdt.internal.compiler.ast.ConditionalExpression; +import org.eclipse.jdt.internal.compiler.ast.EqualExpression; +import org.eclipse.jdt.internal.compiler.ast.Expression; +import org.eclipse.jdt.internal.compiler.ast.FieldReference; +import org.eclipse.jdt.internal.compiler.ast.ForStatement; +import org.eclipse.jdt.internal.compiler.ast.IfStatement; +import org.eclipse.jdt.internal.compiler.ast.IntLiteral; +import org.eclipse.jdt.internal.compiler.ast.LocalDeclaration; +import org.eclipse.jdt.internal.compiler.ast.MessageSend; +import org.eclipse.jdt.internal.compiler.ast.NullLiteral; +import org.eclipse.jdt.internal.compiler.ast.OperatorIds; +import org.eclipse.jdt.internal.compiler.ast.PostfixExpression; +import org.eclipse.jdt.internal.compiler.ast.QualifiedNameReference; +import org.eclipse.jdt.internal.compiler.ast.QualifiedTypeReference; +import org.eclipse.jdt.internal.compiler.ast.SingleNameReference; +import org.eclipse.jdt.internal.compiler.ast.Statement; +import org.eclipse.jdt.internal.compiler.ast.SwitchStatement; +import org.eclipse.jdt.internal.compiler.ast.ThisReference; +import org.eclipse.jdt.internal.compiler.ast.TypeReference; +import org.eclipse.jdt.internal.compiler.lookup.TypeConstants; +import org.eclipse.jdt.internal.compiler.lookup.TypeIds; + +import lombok.ConfigurationKeys; +import lombok.eclipse.EclipseNode; +import lombok.eclipse.handlers.EclipseSingularsRecipes.EclipseSingularizer; +import lombok.eclipse.handlers.EclipseSingularsRecipes.SingularData; + +abstract class EclipseJavaUtilSingularizer extends EclipseSingularizer { + protected static final char[][] JAVA_UTIL_ARRAYLIST = { + {'j', 'a', 'v', 'a'}, {'u', 't', 'i', 'l'}, {'A', 'r', 'r', 'a', 'y', 'L', 'i', 's', 't'} + }; + + protected static final char[][] JAVA_UTIL_LIST = { + {'j', 'a', 'v', 'a'}, {'u', 't', 'i', 'l'}, {'L', 'i', 's', 't'} + }; + + protected static final char[][] JAVA_UTIL_MAP = { + {'j', 'a', 'v', 'a'}, {'u', 't', 'i', 'l'}, {'M', 'a', 'p'} + }; + + protected static final char[][] JAVA_UTIL_MAP_ENTRY = { + {'j', 'a', 'v', 'a'}, {'u', 't', 'i', 'l'}, {'M', 'a', 'p'}, {'E', 'n', 't', 'r', 'y'} + }; + + protected static final char[][] JAVA_UTIL_COLLECTIONS = { + {'j', 'a', 'v', 'a'}, {'u', 't', 'i', 'l'}, {'C', 'o', 'l', 'l', 'e', 'c', 't', 'i', 'o', 'n', 's'} + }; + + protected final EclipseSingularizer guavaListSetSingularizer = new EclipseGuavaSetListSingularizer(); + protected final EclipseSingularizer guavaMapSingularizer = new EclipseGuavaMapSingularizer(); + + protected boolean useGuavaInstead(EclipseNode node) { + return Boolean.TRUE.equals(node.getAst().readConfiguration(ConfigurationKeys.SINGULAR_USE_GUAVA)); + } + + protected List<Statement> createJavaUtilSetMapInitialCapacitySwitchStatements(SingularData data, EclipseNode builderType, boolean mapMode, String emptyCollectionMethod, String singletonCollectionMethod, String targetType) { + List<Statement> switchContents = new ArrayList<Statement>(); + char[] keyName = mapMode ? (new String(data.getPluralName()) + "$key").toCharArray() : data.getPluralName(); + + if (emptyCollectionMethod != null) { // case 0: (empty); break; + switchContents.add(new CaseStatement(makeIntLiteral(new char[] {'0'}, null), 0, 0)); + + /* pluralName = java.util.Collections.emptyCollectionMethod(); */ { + MessageSend invoke = new MessageSend(); + invoke.receiver = new QualifiedNameReference(JAVA_UTIL_COLLECTIONS, NULL_POSS, 0, 0); + invoke.selector = emptyCollectionMethod.toCharArray(); + switchContents.add(new Assignment(new SingleNameReference(data.getPluralName(), 0), invoke, 0)); + } + + switchContents.add(new BreakStatement(null, 0, 0)); + } + + if (singletonCollectionMethod != null) { // case 1: (singleton); break; + switchContents.add(new CaseStatement(makeIntLiteral(new char[] {'1'}, null), 0, 0)); + /* !mapMode: pluralName = java.util.Collections.singletonCollectionMethod(this.pluralName.get(0)); + mapMode: pluralName = java.util.Collections.singletonCollectionMethod(this.pluralName$key.get(0), this.pluralName$value.get(0)); */ { + FieldReference thisDotKey = new FieldReference(keyName, 0L); + thisDotKey.receiver = new ThisReference(0, 0); + MessageSend thisDotKeyGet0 = new MessageSend(); + thisDotKeyGet0.receiver = thisDotKey; + thisDotKeyGet0.selector = new char[] {'g', 'e', 't'}; + thisDotKeyGet0.arguments = new Expression[] {makeIntLiteral(new char[] {'0'}, null)}; + + Expression[] args; + if (mapMode) { + char[] valueName = (new String(data.getPluralName()) + "$value").toCharArray(); + FieldReference thisDotValue = new FieldReference(valueName, 0L); + thisDotValue.receiver = new ThisReference(0, 0); + MessageSend thisDotValueGet0 = new MessageSend(); + thisDotValueGet0.receiver = thisDotValue; + thisDotValueGet0.selector = new char[] {'g', 'e', 't'}; + thisDotValueGet0.arguments = new Expression[] {makeIntLiteral(new char[] {'0'}, null)}; + args = new Expression[] {thisDotKeyGet0, thisDotValueGet0}; + } else { + args = new Expression[] {thisDotKeyGet0}; + } + + MessageSend invoke = new MessageSend(); + invoke.receiver = new QualifiedNameReference(JAVA_UTIL_COLLECTIONS, NULL_POSS, 0, 0); + invoke.selector = singletonCollectionMethod.toCharArray(); + invoke.arguments = args; + switchContents.add(new Assignment(new SingleNameReference(data.getPluralName(), 0), invoke, 0)); + } + switchContents.add(new BreakStatement(null, 0, 0)); + } + + { // default: + switchContents.add(new CaseStatement(null, 0, 0)); + switchContents.addAll(createJavaUtilSimpleCreationAndFillStatements(data, builderType, mapMode, false, true, emptyCollectionMethod == null, targetType)); + } + + SwitchStatement switchStat = new SwitchStatement(); + switchStat.statements = switchContents.toArray(new Statement[switchContents.size()]); + switchStat.expression = getSize(builderType, keyName, true); + + TypeReference localShadowerType = new QualifiedTypeReference(fromQualifiedName(data.getTargetFqn()), NULL_POSS); + localShadowerType = addTypeArgs(mapMode ? 2 : 1, false, builderType, localShadowerType, data.getTypeArgs()); + LocalDeclaration varDefStat = new LocalDeclaration(data.getPluralName(), 0, 0); + varDefStat.type = localShadowerType; + return Arrays.asList(varDefStat, switchStat); + } + + protected List<Statement> createJavaUtilSimpleCreationAndFillStatements(SingularData data, EclipseNode builderType, boolean mapMode, boolean defineVar, boolean addInitialCapacityArg, boolean nullGuard, String targetType) { + char[] varName = mapMode ? (new String(data.getPluralName()) + "$key").toCharArray() : data.getPluralName(); + + Statement createStat; { + // pluralName = new java.util.TargetType(initialCap); + Expression[] constructorArgs = null; + if (addInitialCapacityArg) { + // this.varName.size() < MAX_POWER_OF_2 ? 1 + this.varName.size() + (this.varName.size() - 3) / 3 : Integer.MAX_VALUE; + // lessThanCutOff = this.varName.size() < MAX_POWER_OF_2 + Expression lessThanCutoff = new BinaryExpression(getSize(builderType, varName, nullGuard), makeIntLiteral("0x40000000".toCharArray(), null), OperatorIds.LESS); + FieldReference integerMaxValue = new FieldReference("MAX_VALUE".toCharArray(), 0L); + integerMaxValue.receiver = new QualifiedNameReference(TypeConstants.JAVA_LANG_INTEGER, NULL_POSS, 0, 0); + Expression sizeFormulaLeft = new BinaryExpression(makeIntLiteral(new char[] {'1'}, null), getSize(builderType, varName, nullGuard), OperatorIds.PLUS); + Expression sizeFormulaRightLeft = new BinaryExpression(getSize(builderType, varName, nullGuard), makeIntLiteral(new char[] {'3'}, null), OperatorIds.MINUS); + Expression sizeFormulaRight = new BinaryExpression(sizeFormulaRightLeft, makeIntLiteral(new char[] {'3'}, null), OperatorIds.DIVIDE); + Expression sizeFormula = new BinaryExpression(sizeFormulaLeft, sizeFormulaRight, OperatorIds.PLUS); + Expression cond = new ConditionalExpression(lessThanCutoff, sizeFormula, integerMaxValue); + constructorArgs = new Expression[] {cond}; + } + + TypeReference targetTypeRef = new QualifiedTypeReference(new char[][] {TypeConstants.JAVA, TypeConstants.UTIL, targetType.toCharArray()}, NULL_POSS); + targetTypeRef = addTypeArgs(mapMode ? 2 : 1, false, builderType, targetTypeRef, data.getTypeArgs()); + AllocationExpression constructorCall = new AllocationExpression(); + constructorCall.type = targetTypeRef; + constructorCall.arguments = constructorArgs; + + if (defineVar) { + TypeReference localShadowerType = new QualifiedTypeReference(fromQualifiedName(data.getTargetFqn()), NULL_POSS); + localShadowerType = addTypeArgs(mapMode ? 2 : 1, false, builderType, localShadowerType, data.getTypeArgs()); + LocalDeclaration localShadowerDecl = new LocalDeclaration(data.getPluralName(), 0, 0); + localShadowerDecl.type = localShadowerType; + localShadowerDecl.initialization = constructorCall; + createStat = localShadowerDecl; + } else { + createStat = new Assignment(new SingleNameReference(data.getPluralName(), 0L), constructorCall, 0); + } + } + + Statement fillStat; { + if (mapMode) { + // for (int $i = 0; $i < this.pluralname$key.size(); i++) pluralname.put(this.pluralname$key.get($i), this.pluralname$value.get($i)); + char[] iVar = new char[] {'$', 'i'}; + MessageSend pluralnameDotPut = new MessageSend(); + pluralnameDotPut.selector = new char[] {'p', 'u', 't'}; + pluralnameDotPut.receiver = new SingleNameReference(data.getPluralName(), 0L); + FieldReference thisDotKey = new FieldReference(varName, 0L); + thisDotKey.receiver = new ThisReference(0, 0); + FieldReference thisDotValue = new FieldReference((new String(data.getPluralName()) + "$value").toCharArray(), 0L); + thisDotValue.receiver = new ThisReference(0, 0); + MessageSend keyArg = new MessageSend(); + keyArg.receiver = thisDotKey; + keyArg.arguments = new Expression[] {new SingleNameReference(iVar, 0L)}; + keyArg.selector = new char[] {'g', 'e', 't'}; + MessageSend valueArg = new MessageSend(); + valueArg.receiver = thisDotValue; + valueArg.arguments = new Expression[] {new SingleNameReference(iVar, 0L)}; + valueArg.selector = new char[] {'g', 'e', 't'}; + pluralnameDotPut.arguments = new Expression[] {keyArg, valueArg}; + + LocalDeclaration forInit = new LocalDeclaration(iVar, 0, 0); + forInit.type = TypeReference.baseTypeReference(TypeIds.T_int, 0); + forInit.initialization = makeIntLiteral(new char[] {'0'}, null); + Expression checkExpr = new BinaryExpression(new SingleNameReference(iVar, 0L), getSize(builderType, varName, nullGuard), OperatorIds.LESS); + Expression incrementExpr = new PostfixExpression(new SingleNameReference(iVar, 0L), IntLiteral.One, OperatorIds.PLUS, 0); + fillStat = new ForStatement(new Statement[] {forInit}, checkExpr, new Statement[] {incrementExpr}, pluralnameDotPut, true, 0, 0); + } else { + // pluralname.addAll(this.pluralname); + MessageSend pluralnameDotAddAll = new MessageSend(); + pluralnameDotAddAll.selector = new char[] {'a', 'd', 'd', 'A', 'l', 'l'}; + pluralnameDotAddAll.receiver = new SingleNameReference(data.getPluralName(), 0L); + FieldReference thisDotPluralname = new FieldReference(varName, 0L); + thisDotPluralname.receiver = new ThisReference(0, 0); + pluralnameDotAddAll.arguments = new Expression[] {thisDotPluralname}; + fillStat = pluralnameDotAddAll; + } + + if (nullGuard) { + FieldReference thisDotField = new FieldReference(varName, 0L); + thisDotField.receiver = new ThisReference(0, 0); + Expression cond = new EqualExpression(thisDotField, new NullLiteral(0, 0), OperatorIds.NOT_EQUAL); + fillStat = new IfStatement(cond, fillStat, 0, 0); + } + } + + Statement unmodifiableStat; { + // pluralname = Collections.unmodifiableInterfaceType(pluralname); + Expression arg = new SingleNameReference(data.getPluralName(), 0L); + MessageSend invoke = new MessageSend(); + invoke.arguments = new Expression[] {arg}; + invoke.selector = ("unmodifiable" + data.getTargetSimpleType()).toCharArray(); + invoke.receiver = new QualifiedNameReference(JAVA_UTIL_COLLECTIONS, NULL_POSS, 0, 0); + unmodifiableStat = new Assignment(new SingleNameReference(data.getPluralName(), 0L), invoke, 0); + } + + return Arrays.asList(createStat, fillStat, unmodifiableStat); + } + + protected Statement createConstructBuilderVarIfNeeded(SingularData data, EclipseNode builderType, boolean mapMode) { + char[] v1Name, v2Name; + if (mapMode) { + String n = new String(data.getPluralName()); + v1Name = (n + "$key").toCharArray(); + v2Name = (n + "$value").toCharArray(); + } else { + v1Name = data.getPluralName(); + v2Name = null; + } + + FieldReference thisDotField = new FieldReference(v1Name, 0L); + thisDotField.receiver = new ThisReference(0, 0); + Expression cond = new EqualExpression(thisDotField, new NullLiteral(0, 0), OperatorIds.EQUAL_EQUAL); + + thisDotField = new FieldReference(v1Name, 0L); + thisDotField.receiver = new ThisReference(0, 0); + TypeReference v1Type = new QualifiedTypeReference(JAVA_UTIL_ARRAYLIST, NULL_POSS); + v1Type = addTypeArgs(1, false, builderType, v1Type, data.getTypeArgs()); + AllocationExpression constructArrayList = new AllocationExpression(); + constructArrayList.type = v1Type; + Assignment initV1 = new Assignment(thisDotField, constructArrayList, 0); + Statement thenPart; + if (mapMode) { + thisDotField = new FieldReference(v2Name, 0L); + thisDotField.receiver = new ThisReference(0, 0); + TypeReference v2Type = new QualifiedTypeReference(JAVA_UTIL_ARRAYLIST, NULL_POSS); + List<TypeReference> tArgs = data.getTypeArgs(); + if (tArgs != null && tArgs.size() > 1) tArgs = Collections.singletonList(tArgs.get(1)); + else tArgs = Collections.emptyList(); + v2Type = addTypeArgs(1, false, builderType, v2Type, tArgs); + constructArrayList = new AllocationExpression(); + constructArrayList.type = v2Type; + Assignment initV2 = new Assignment(thisDotField, constructArrayList, 0); + Block b = new Block(0); + b.statements = new Statement[] {initV1, initV2}; + thenPart = b; + } else { + thenPart = initV1; + } + + return new IfStatement(cond, thenPart, 0, 0); + } +} diff --git a/src/core/lombok/experimental/Builder.java b/src/core/lombok/experimental/Builder.java index 1300e7d3..7d89109f 100644 --- a/src/core/lombok/experimental/Builder.java +++ b/src/core/lombok/experimental/Builder.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2013 The Project Lombok Authors. + * Copyright (C) 2013-2014 The Project Lombok Authors. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -103,9 +103,12 @@ import java.lang.annotation.Target; * } * } * </pre> + * + * @deprecated {@link lombok.Builder} has been promoted to the main package, so use that one instead. */ @Target({TYPE, METHOD, CONSTRUCTOR}) @Retention(SOURCE) +@Deprecated public @interface Builder { /** Name of the static method that creates a new builder instance. Default: {@code builder}. */ String builderMethodName() default "builder"; diff --git a/src/core/lombok/javac/JavacNode.java b/src/core/lombok/javac/JavacNode.java index 6eef36eb..727692ac 100644 --- a/src/core/lombok/javac/JavacNode.java +++ b/src/core/lombok/javac/JavacNode.java @@ -66,40 +66,40 @@ public class JavacNode extends lombok.core.LombokNode<JavacAST, JavacNode, JCTre public void traverse(JavacASTVisitor visitor) { switch (this.getKind()) { case COMPILATION_UNIT: - visitor.visitCompilationUnit(this, (JCCompilationUnit)get()); + visitor.visitCompilationUnit(this, (JCCompilationUnit) get()); ast.traverseChildren(visitor, this); - visitor.endVisitCompilationUnit(this, (JCCompilationUnit)get()); + visitor.endVisitCompilationUnit(this, (JCCompilationUnit) get()); break; case TYPE: - visitor.visitType(this, (JCClassDecl)get()); + visitor.visitType(this, (JCClassDecl) get()); ast.traverseChildren(visitor, this); - visitor.endVisitType(this, (JCClassDecl)get()); + visitor.endVisitType(this, (JCClassDecl) get()); break; case FIELD: - visitor.visitField(this, (JCVariableDecl)get()); + visitor.visitField(this, (JCVariableDecl) get()); ast.traverseChildren(visitor, this); - visitor.endVisitField(this, (JCVariableDecl)get()); + visitor.endVisitField(this, (JCVariableDecl) get()); break; case METHOD: - visitor.visitMethod(this, (JCMethodDecl)get()); + visitor.visitMethod(this, (JCMethodDecl) get()); ast.traverseChildren(visitor, this); - visitor.endVisitMethod(this, (JCMethodDecl)get()); + visitor.endVisitMethod(this, (JCMethodDecl) get()); break; case INITIALIZER: - visitor.visitInitializer(this, (JCBlock)get()); + visitor.visitInitializer(this, (JCBlock) get()); ast.traverseChildren(visitor, this); - visitor.endVisitInitializer(this, (JCBlock)get()); + visitor.endVisitInitializer(this, (JCBlock) get()); break; case ARGUMENT: JCMethodDecl parentMethod = (JCMethodDecl) up().get(); - visitor.visitMethodArgument(this, (JCVariableDecl)get(), parentMethod); + visitor.visitMethodArgument(this, (JCVariableDecl) get(), parentMethod); ast.traverseChildren(visitor, this); - visitor.endVisitMethodArgument(this, (JCVariableDecl)get(), parentMethod); + visitor.endVisitMethodArgument(this, (JCVariableDecl) get(), parentMethod); break; case LOCAL: - visitor.visitLocal(this, (JCVariableDecl)get()); + visitor.visitLocal(this, (JCVariableDecl) get()); ast.traverseChildren(visitor, this); - visitor.endVisitLocal(this, (JCVariableDecl)get()); + visitor.endVisitLocal(this, (JCVariableDecl) get()); break; case STATEMENT: visitor.visitStatement(this, get()); @@ -109,21 +109,21 @@ public class JavacNode extends lombok.core.LombokNode<JavacAST, JavacNode, JCTre case ANNOTATION: switch (up().getKind()) { case TYPE: - visitor.visitAnnotationOnType((JCClassDecl)up().get(), this, (JCAnnotation)get()); + visitor.visitAnnotationOnType((JCClassDecl) up().get(), this, (JCAnnotation) get()); break; case FIELD: - visitor.visitAnnotationOnField((JCVariableDecl)up().get(), this, (JCAnnotation)get()); + visitor.visitAnnotationOnField((JCVariableDecl) up().get(), this, (JCAnnotation) get()); break; case METHOD: - visitor.visitAnnotationOnMethod((JCMethodDecl)up().get(), this, (JCAnnotation)get()); + visitor.visitAnnotationOnMethod((JCMethodDecl) up().get(), this, (JCAnnotation) get()); break; case ARGUMENT: - JCVariableDecl argument = (JCVariableDecl)up().get(); - JCMethodDecl method = (JCMethodDecl)up().up().get(); - visitor.visitAnnotationOnMethodArgument(argument, method, this, (JCAnnotation)get()); + JCVariableDecl argument = (JCVariableDecl) up().get(); + JCMethodDecl method = (JCMethodDecl) up().up().get(); + visitor.visitAnnotationOnMethodArgument(argument, method, this, (JCAnnotation) get()); break; case LOCAL: - visitor.visitAnnotationOnLocal((JCVariableDecl)up().get(), this, (JCAnnotation)get()); + visitor.visitAnnotationOnLocal((JCVariableDecl) up().get(), this, (JCAnnotation) get()); break; default: throw new AssertionError("Annotion not expected as child of a " + up().getKind()); @@ -138,9 +138,9 @@ public class JavacNode extends lombok.core.LombokNode<JavacAST, JavacNode, JCTre @Override public String getName() { final Name n; - if (node instanceof JCClassDecl) n = ((JCClassDecl)node).name; - else if (node instanceof JCMethodDecl) n = ((JCMethodDecl)node).name; - else if (node instanceof JCVariableDecl) n = ((JCVariableDecl)node).name; + if (node instanceof JCClassDecl) n = ((JCClassDecl) node).name; + else if (node instanceof JCMethodDecl) n = ((JCMethodDecl) node).name; + else if (node instanceof JCVariableDecl) n = ((JCVariableDecl) node).name; else n = null; return n == null ? null : n.toString(); diff --git a/src/core/lombok/javac/JavacResolution.java b/src/core/lombok/javac/JavacResolution.java index 23d7d482..6231735c 100644 --- a/src/core/lombok/javac/JavacResolution.java +++ b/src/core/lombok/javac/JavacResolution.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2011-2014 The Project Lombok Authors. + * Copyright (C) 2011-2015 The Project Lombok Authors. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -24,6 +24,7 @@ package lombok.javac; import static lombok.javac.Javac.*; import static lombok.javac.JavacTreeMaker.TypeTag.typeTag; +import java.lang.reflect.Field; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.util.ArrayDeque; @@ -98,7 +99,7 @@ public class JavacResolution { @Override public void visitClassDef(JCClassDecl tree) { if (copyAt != null) return; - env = enter.getClassEnv(tree.sym); + if (tree.sym != null) env = enter.getClassEnv(tree.sym); } @Override public void visitMethodDef(JCMethodDecl tree) { @@ -138,16 +139,64 @@ public class JavacResolution { EnvFinder finder = new EnvFinder(node.getContext()); while (!stack.isEmpty()) stack.pop().accept(finder); - TreeMirrorMaker mirrorMaker = new TreeMirrorMaker(node.getTreeMaker()); + TreeMirrorMaker mirrorMaker = new TreeMirrorMaker(node.getTreeMaker(), node.getContext()); JCTree copy = mirrorMaker.copy(finder.copyAt()); - attrib(copy, finder.get()); + memberEnterAndAttribute(copy, finder.get(), node.getContext()); return mirrorMaker.getOriginalToCopyMap(); } finally { messageSuppressor.enableLoggers(); } } + private static Field memberEnterDotEnv; + + private static Field getMemberEnterDotEnv() { + if (memberEnterDotEnv != null) return memberEnterDotEnv; + try { + Field f = MemberEnter.class.getDeclaredField("env"); + f.setAccessible(true); + memberEnterDotEnv = f; + } catch (NoSuchFieldException e) { + return null; + } + + return memberEnterDotEnv; + } + + @SuppressWarnings("unchecked") + private static Env<AttrContext> getEnvOfMemberEnter(MemberEnter memberEnter) { + Field f = getMemberEnterDotEnv(); + try { + return (Env<AttrContext>) f.get(memberEnter); + } catch (Exception e) { + return null; + } + } + + private static void setEnvOfMemberEnter(MemberEnter memberEnter, Env<AttrContext> env) { + Field f = getMemberEnterDotEnv(); + try { + f.set(memberEnter, env); + } catch (Exception e) { + return; + } + } + + private void memberEnterAndAttribute(JCTree copy, Env<AttrContext> env, Context context) { + MemberEnter memberEnter = MemberEnter.instance(context); + Env<AttrContext> oldEnv = getEnvOfMemberEnter(memberEnter); + setEnvOfMemberEnter(memberEnter, env); + try { + copy.accept(memberEnter); + } catch (Exception ignore) { + // intentionally ignored; usually even if this step fails, val will work (but not for val in method local inner classes and anonymous inner classes). + } finally { + setEnvOfMemberEnter(memberEnter, oldEnv); + } + attrib(copy, env); + } + public void resolveClassMember(JavacNode node) { ArrayDeque<JCTree> stack = new ArrayDeque<JCTree>(); @@ -241,7 +290,7 @@ public class JavacResolution { Type type0 = type; while (type0 instanceof ArrayType) { dims++; - type0 = ((ArrayType)type0).elemtype; + type0 = ((ArrayType) type0).elemtype; } JCExpression result = typeToJCTree0(type0, ast, allowCompound, allowVoid); diff --git a/src/core/lombok/javac/apt/EmptyLombokFileObject.java b/src/core/lombok/javac/apt/EmptyLombokFileObject.java index 7298e920..5a3a7def 100644 --- a/src/core/lombok/javac/apt/EmptyLombokFileObject.java +++ b/src/core/lombok/javac/apt/EmptyLombokFileObject.java @@ -19,7 +19,6 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ - package lombok.javac.apt; import java.io.ByteArrayInputStream; diff --git a/src/core/lombok/javac/apt/Processor.java b/src/core/lombok/javac/apt/Processor.java index ce4d75ff..9979a066 100644 --- a/src/core/lombok/javac/apt/Processor.java +++ b/src/core/lombok/javac/apt/Processor.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2009-2012 The Project Lombok Authors. + * Copyright (C) 2009-2015 The Project Lombok Authors. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal diff --git a/src/core/lombok/javac/handlers/HandleBuilder.java b/src/core/lombok/javac/handlers/HandleBuilder.java index 1885b8b4..4f7f79d9 100644 --- a/src/core/lombok/javac/handlers/HandleBuilder.java +++ b/src/core/lombok/javac/handlers/HandleBuilder.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2013-2014 The Project Lombok Authors. + * Copyright (C) 2013-2015 The Project Lombok Authors. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -21,8 +21,8 @@ */ package lombok.javac.handlers; +import java.lang.annotation.Annotation; import java.util.ArrayList; -import java.util.Collections; import org.mangosdk.spi.ProviderFor; @@ -34,6 +34,8 @@ import com.sun.tools.javac.tree.JCTree.JCClassDecl; import com.sun.tools.javac.tree.JCTree.JCExpression; import com.sun.tools.javac.tree.JCTree.JCFieldAccess; import com.sun.tools.javac.tree.JCTree.JCIdent; +import com.sun.tools.javac.tree.JCTree.JCIf; +import com.sun.tools.javac.tree.JCTree.JCLiteral; import com.sun.tools.javac.tree.JCTree.JCMethodDecl; import com.sun.tools.javac.tree.JCTree.JCModifiers; import com.sun.tools.javac.tree.JCTree.JCPrimitiveTypeTree; @@ -46,16 +48,21 @@ import com.sun.tools.javac.util.ListBuffer; import com.sun.tools.javac.util.Name; import lombok.AccessLevel; +import lombok.Builder; import lombok.ConfigurationKeys; +import lombok.Singular; import lombok.core.AST.Kind; import lombok.core.AnnotationValues; import lombok.core.HandlerPriority; -import lombok.experimental.Builder; +import lombok.core.handlers.HandlerUtil; import lombok.experimental.NonFinal; +import lombok.javac.Javac; import lombok.javac.JavacAnnotationHandler; import lombok.javac.JavacNode; import lombok.javac.JavacTreeMaker; import lombok.javac.handlers.HandleConstructor.SkipIfConstructorExists; +import lombok.javac.handlers.JavacSingularsRecipes.JavacSingularizer; +import lombok.javac.handlers.JavacSingularsRecipes.SingularData; import static lombok.core.handlers.HandlerUtil.*; import static lombok.javac.handlers.JavacHandlerUtil.*; import static lombok.javac.Javac.*; @@ -64,10 +71,27 @@ import static lombok.javac.JavacTreeMaker.TypeTag.*; @ProviderFor(JavacAnnotationHandler.class) @HandlerPriority(-1024) //-2^10; to ensure we've picked up @FieldDefault's changes (-2048) but @Value hasn't removed itself yet (-512), so that we can error on presence of it on the builder classes. public class HandleBuilder extends JavacAnnotationHandler<Builder> { - @Override public void handle(AnnotationValues<Builder> annotation, JCAnnotation ast, JavacNode annotationNode) { - handleExperimentalFlagUsage(annotationNode, ConfigurationKeys.BUILDER_FLAG_USAGE, "@Builder"); + private static final boolean toBoolean(Object expr, boolean defaultValue) { + if (expr == null) return defaultValue; + if (expr instanceof JCLiteral) return ((Integer) ((JCLiteral) expr).value) != 0; + return ((Boolean) expr).booleanValue(); + } + + private static class BuilderFieldData { + JCExpression type; + Name name; + SingularData singularData; + java.util.List<JavacNode> createdFields = new ArrayList<JavacNode>(); + } + + @Override public void handle(AnnotationValues<Builder> annotation, JCAnnotation ast, JavacNode annotationNode) { Builder builderInstance = annotation.getInstance(); + + // These exist just to support the 'old' lombok.experimental.Builder, which had these properties. lombok.Builder no longer has them. + boolean fluent = toBoolean(annotation.getActualExpression("fluent"), true); + boolean chain = toBoolean(annotation.getActualExpression("chain"), true); + String builderMethodName = builderInstance.builderMethodName(); String buildMethodName = builderInstance.buildMethodName(); String builderClassName = builderInstance.builderClassName(); @@ -82,20 +106,21 @@ public class HandleBuilder extends JavacAnnotationHandler<Builder> { if (!checkName("builderClassName", builderClassName, annotationNode)) return; } - deleteAnnotationIfNeccessary(annotationNode, Builder.class); - deleteImportFromCompilationUnit(annotationNode, "lombok.experimental.Builder"); + @SuppressWarnings("deprecation") + Class<? extends Annotation> oldExperimentalBuilder = lombok.experimental.Builder.class; + deleteAnnotationIfNeccessary(annotationNode, Builder.class, oldExperimentalBuilder); JavacNode parent = annotationNode.up(); - java.util.List<JCExpression> typesOfParameters = new ArrayList<JCExpression>(); - java.util.List<Name> namesOfParameters = new ArrayList<Name>(); + java.util.List<BuilderFieldData> builderFields = new ArrayList<BuilderFieldData>(); JCExpression returnType; List<JCTypeParameter> typeParams = List.nil(); List<JCExpression> thrownExceptions = List.nil(); Name nameOfStaticBuilderMethod; JavacNode tdParent; - JCMethodDecl fillParametersFrom = parent.get() instanceof JCMethodDecl ? ((JCMethodDecl) parent.get()) : null; + JavacNode fillParametersFrom = parent.get() instanceof JCMethodDecl ? parent : null; + boolean addCleaning = false; if (parent.get() instanceof JCClassDecl) { tdParent = parent; @@ -109,12 +134,14 @@ public class HandleBuilder extends JavacAnnotationHandler<Builder> { // non-final fields final, but @Value's handler hasn't done this yet, so we have to do this math ourselves. // Value will only skip making a field final if it has an explicit @NonFinal annotation, so we check for that. if (fd.init != null && valuePresent && !hasAnnotation(NonFinal.class, fieldNode)) continue; - namesOfParameters.add(removePrefixFromField(fieldNode)); - typesOfParameters.add(fd.vartype); + BuilderFieldData bfd = new BuilderFieldData(); + bfd.name = removePrefixFromField(fieldNode); + bfd.type = fd.vartype; + bfd.singularData = getSingularData(fieldNode); + builderFields.add(bfd); allFields.append(fieldNode); } - new HandleConstructor().generateConstructor(tdParent, AccessLevel.PACKAGE, List.<JCAnnotation>nil(), allFields.toList(), null, SkipIfConstructorExists.I_AM_BUILDER, null, annotationNode); returnType = namePlusTypeParamsToTypeReference(tdParent.getTreeMaker(), td.name, td.typarams); @@ -123,28 +150,31 @@ public class HandleBuilder extends JavacAnnotationHandler<Builder> { nameOfStaticBuilderMethod = null; if (builderClassName.isEmpty()) builderClassName = td.name.toString() + "Builder"; } else if (fillParametersFrom != null && fillParametersFrom.getName().toString().equals("<init>")) { - if (!fillParametersFrom.typarams.isEmpty()) { + JCMethodDecl jmd = (JCMethodDecl) fillParametersFrom.get(); + if (!jmd.typarams.isEmpty()) { annotationNode.addError("@Builder is not supported on constructors with constructor type parameters."); return; } + tdParent = parent.up(); JCClassDecl td = (JCClassDecl) tdParent.get(); returnType = namePlusTypeParamsToTypeReference(tdParent.getTreeMaker(), td.name, td.typarams); typeParams = td.typarams; - thrownExceptions = fillParametersFrom.thrown; + thrownExceptions = jmd.thrown; nameOfStaticBuilderMethod = null; if (builderClassName.isEmpty()) builderClassName = td.name.toString() + "Builder"; } else if (fillParametersFrom != null) { tdParent = parent.up(); JCClassDecl td = (JCClassDecl) tdParent.get(); - if ((fillParametersFrom.mods.flags & Flags.STATIC) == 0) { + JCMethodDecl jmd = (JCMethodDecl) fillParametersFrom.get(); + if ((jmd.mods.flags & Flags.STATIC) == 0) { annotationNode.addError("@Builder is only supported on types, constructors, and static methods."); return; } - returnType = fillParametersFrom.restype; - typeParams = fillParametersFrom.typarams; - thrownExceptions = fillParametersFrom.thrown; - nameOfStaticBuilderMethod = fillParametersFrom.name; + returnType = jmd.restype; + typeParams = jmd.typarams; + thrownExceptions = jmd.thrown; + nameOfStaticBuilderMethod = jmd.name; if (builderClassName.isEmpty()) { if (returnType instanceof JCTypeApply) { returnType = ((JCTypeApply) returnType).clazz; @@ -179,9 +209,14 @@ public class HandleBuilder extends JavacAnnotationHandler<Builder> { } if (fillParametersFrom != null) { - for (JCVariableDecl param : fillParametersFrom.params) { - namesOfParameters.add(param.name); - typesOfParameters.add(param.vartype); + for (JavacNode param : fillParametersFrom.down()) { + if (param.getKind() != Kind.ARGUMENT) continue; + BuilderFieldData bfd = new BuilderFieldData(); + JCVariableDecl raw = (JCVariableDecl) param.get(); + bfd.name = raw.name; + bfd.type = raw.vartype; + bfd.singularData = getSingularData(param); + builderFields.add(bfd); } } @@ -190,12 +225,34 @@ public class HandleBuilder extends JavacAnnotationHandler<Builder> { builderType = makeBuilderClass(tdParent, builderClassName, typeParams, ast); } else { sanityCheckForMethodGeneratingAnnotationsOnBuilderClass(builderType, annotationNode); + /* generate errors for @Singular BFDs that have one already defined node. */ { + for (BuilderFieldData bfd : builderFields) { + SingularData sd = bfd.singularData; + if (sd == null) continue; + JavacSingularizer singularizer = sd.getSingularizer(); + if (singularizer == null) continue; + if (singularizer.checkForAlreadyExistingNodesAndGenerateError(builderType, sd)) { + bfd.singularData = null; + } + } + } + + } + + for (BuilderFieldData bfd : builderFields) { + if (bfd.singularData != null && bfd.singularData.getSingularizer() != null) { + if (bfd.singularData.getSingularizer().requiresCleaning()) { + addCleaning = true; + break; + } + } } - java.util.List<JavacNode> fieldNodes = addFieldsToBuilder(builderType, namesOfParameters, typesOfParameters, ast); - java.util.List<JCMethodDecl> newMethods = new ArrayList<JCMethodDecl>(); - for (JavacNode fieldNode : fieldNodes) { - JCMethodDecl newMethod = makeSetterMethodForBuilder(builderType, fieldNode, annotationNode, builderInstance.fluent(), builderInstance.chain()); - if (newMethod != null) newMethods.add(newMethod); + + generateBuilderFields(builderType, builderFields, ast); + if (addCleaning) { + JavacTreeMaker maker = builderType.getTreeMaker(); + JCVariableDecl uncleanField = maker.VarDef(maker.Modifiers(Flags.PRIVATE), builderType.toName("$lombokUnclean"), maker.TypeIdent(CTC_BOOLEAN), null); + injectField(builderType, uncleanField); } if (constructorExists(builderType) == MemberExistsResult.NOT_EXISTS) { @@ -203,38 +260,93 @@ public class HandleBuilder extends JavacAnnotationHandler<Builder> { if (cd != null) injectMethod(builderType, cd); } - for (JCMethodDecl newMethod : newMethods) injectMethod(builderType, newMethod); + for (BuilderFieldData bfd : builderFields) { + makeSetterMethodsForBuilder(builderType, bfd, annotationNode, fluent, chain); + } if (methodExists(buildMethodName, builderType, -1) == MemberExistsResult.NOT_EXISTS) { - JCMethodDecl md = generateBuildMethod(buildMethodName, nameOfStaticBuilderMethod, returnType, namesOfParameters, builderType, thrownExceptions); + JCMethodDecl md = generateBuildMethod(buildMethodName, nameOfStaticBuilderMethod, returnType, builderFields, builderType, thrownExceptions, ast, addCleaning); if (md != null) injectMethod(builderType, md); } if (methodExists("toString", builderType, 0) == MemberExistsResult.NOT_EXISTS) { + java.util.List<JavacNode> fieldNodes = new ArrayList<JavacNode>(); + for (BuilderFieldData bfd : builderFields) { + fieldNodes.addAll(bfd.createdFields); + } JCMethodDecl md = HandleToString.createToString(builderType, fieldNodes, true, false, FieldAccess.ALWAYS_FIELD, ast); if (md != null) injectMethod(builderType, md); } + if (addCleaning) injectMethod(builderType, generateCleanMethod(builderFields, builderType, ast)); + if (methodExists(builderMethodName, tdParent, -1) == MemberExistsResult.NOT_EXISTS) { JCMethodDecl md = generateBuilderMethod(builderMethodName, builderClassName, tdParent, typeParams); + recursiveSetGeneratedBy(md, ast, annotationNode.getContext()); if (md != null) injectMethod(tdParent, md); } + + recursiveSetGeneratedBy(builderType.get(), ast, annotationNode.getContext()); } - public JCMethodDecl generateBuildMethod(String name, Name staticName, JCExpression returnType, java.util.List<Name> fieldNames, JavacNode type, List<JCExpression> thrownExceptions) { + private JCMethodDecl generateCleanMethod(java.util.List<BuilderFieldData> builderFields, JavacNode type, JCTree source) { + JavacTreeMaker maker = type.getTreeMaker(); + ListBuffer<JCStatement> statements = new ListBuffer<JCStatement>(); + + for (BuilderFieldData bfd : builderFields) { + if (bfd.singularData != null && bfd.singularData.getSingularizer() != null) { + bfd.singularData.getSingularizer().appendCleaningCode(bfd.singularData, type, source, statements); + } + } + + statements.append(maker.Exec(maker.Assign(maker.Select(maker.Ident(type.toName("this")), type.toName("$lombokUnclean")), maker.Literal(CTC_BOOLEAN, false)))); + JCBlock body = maker.Block(0, statements.toList()); + return maker.MethodDef(maker.Modifiers(Flags.PUBLIC), type.toName("$lombokClean"), maker.Type(Javac.createVoidType(maker, CTC_VOID)), List.<JCTypeParameter>nil(), List.<JCVariableDecl>nil(), List.<JCExpression>nil(), body, null); + /* + * if (shouldReturnThis) { + methodType = cloneSelfType(field); + } + + if (methodType == null) { + //WARNING: Do not use field.getSymbolTable().voidType - that field has gone through non-backwards compatible API changes within javac1.6. + methodType = treeMaker.Type(Javac.createVoidType(treeMaker, CTC_VOID)); + shouldReturnThis = false; + } + + */ + } + + private JCMethodDecl generateBuildMethod(String name, Name staticName, JCExpression returnType, java.util.List<BuilderFieldData> builderFields, JavacNode type, List<JCExpression> thrownExceptions, JCTree source, boolean addCleaning) { JavacTreeMaker maker = type.getTreeMaker(); JCExpression call; - JCStatement statement; + ListBuffer<JCStatement> statements = new ListBuffer<JCStatement>(); + + if (addCleaning) { + JCExpression notClean = maker.Unary(CTC_NOT, maker.Select(maker.Ident(type.toName("this")), type.toName("$lombokUnclean"))); + JCStatement invokeClean = maker.Exec(maker.Apply(List.<JCExpression>nil(), maker.Ident(type.toName("$lombokClean")), List.<JCExpression>nil())); + JCIf ifUnclean = maker.If(notClean, invokeClean, null); + statements.append(ifUnclean); + } + + for (BuilderFieldData bfd : builderFields) { + if (bfd.singularData != null && bfd.singularData.getSingularizer() != null) { + bfd.singularData.getSingularizer().appendBuildCode(bfd.singularData, type, source, statements, bfd.name); + } + } ListBuffer<JCExpression> args = new ListBuffer<JCExpression>(); - for (Name n : fieldNames) { - args.append(maker.Ident(n)); + for (BuilderFieldData bfd : builderFields) { + args.append(maker.Ident(bfd.name)); + } + + if (addCleaning) { + statements.append(maker.Exec(maker.Assign(maker.Select(maker.Ident(type.toName("this")), type.toName("$lombokUnclean")), maker.Literal(CTC_BOOLEAN, true)))); } if (staticName == null) { call = maker.NewClass(null, List.<JCExpression>nil(), returnType, args.toList(), null); - statement = maker.Return(call); + statements.append(maker.Return(call)); } else { ListBuffer<JCExpression> typeParams = new ListBuffer<JCExpression>(); for (JCTypeParameter tp : ((JCClassDecl) type.get()).typarams) { @@ -244,13 +356,13 @@ public class HandleBuilder extends JavacAnnotationHandler<Builder> { JCExpression fn = maker.Select(maker.Ident(((JCClassDecl) type.up().get()).name), staticName); call = maker.Apply(typeParams.toList(), fn, args.toList()); if (returnType instanceof JCPrimitiveTypeTree && CTC_VOID.equals(typeTag(returnType))) { - statement = maker.Exec(call); + statements.append(maker.Exec(call)); } else { - statement = maker.Return(call); + statements.append(maker.Return(call)); } } - JCBlock body = maker.Block(0, List.<JCStatement>of(statement)); + JCBlock body = maker.Block(0, statements.toList()); return maker.MethodDef(maker.Modifiers(Flags.PUBLIC), type.toName(name), returnType, List.<JCTypeParameter>nil(), List.<JCVariableDecl>nil(), thrownExceptions, body, null); } @@ -270,50 +382,56 @@ public class HandleBuilder extends JavacAnnotationHandler<Builder> { return maker.MethodDef(maker.Modifiers(Flags.STATIC | Flags.PUBLIC), type.toName(builderMethodName), namePlusTypeParamsToTypeReference(maker, type.toName(builderClassName), typeParams), copyTypeParams(maker, typeParams), List.<JCVariableDecl>nil(), List.<JCExpression>nil(), body, null); } - public java.util.List<JavacNode> addFieldsToBuilder(JavacNode builderType, java.util.List<Name> namesOfParameters, java.util.List<JCExpression> typesOfParameters, JCTree source) { - int len = namesOfParameters.size(); + public void generateBuilderFields(JavacNode builderType, java.util.List<BuilderFieldData> builderFields, JCTree source) { + int len = builderFields.size(); java.util.List<JavacNode> existing = new ArrayList<JavacNode>(); for (JavacNode child : builderType.down()) { if (child.getKind() == Kind.FIELD) existing.add(child); } - java.util.List<JavacNode>out = new ArrayList<JavacNode>(); - top: for (int i = len - 1; i >= 0; i--) { - Name name = namesOfParameters.get(i); - for (JavacNode exists : existing) { - Name n = ((JCVariableDecl) exists.get()).name; - if (n.equals(name)) { - out.add(exists); - continue top; + BuilderFieldData bfd = builderFields.get(i); + if (bfd.singularData != null && bfd.singularData.getSingularizer() != null) { + bfd.createdFields.addAll(bfd.singularData.getSingularizer().generateFields(bfd.singularData, builderType, source)); + } else { + for (JavacNode exists : existing) { + Name n = ((JCVariableDecl) exists.get()).name; + if (n.equals(bfd.name)) { + bfd.createdFields.add(exists); + continue top; + } } + JavacTreeMaker maker = builderType.getTreeMaker(); + JCModifiers mods = maker.Modifiers(Flags.PRIVATE); + JCVariableDecl newField = maker.VarDef(mods, bfd.name, cloneType(maker, bfd.type, source, builderType.getContext()), null); + bfd.createdFields.add(injectField(builderType, newField)); } - JavacTreeMaker maker = builderType.getTreeMaker(); - JCModifiers mods = maker.Modifiers(Flags.PRIVATE); - JCVariableDecl newField = maker.VarDef(mods, name, cloneType(maker, typesOfParameters.get(i), source, builderType.getContext()), null); - out.add(injectField(builderType, newField)); } - - Collections.reverse(out); - return out; } + public void makeSetterMethodsForBuilder(JavacNode builderType, BuilderFieldData fieldNode, JavacNode source, boolean fluent, boolean chain) { + if (fieldNode.singularData == null || fieldNode.singularData.getSingularizer() == null) { + makeSimpleSetterMethodForBuilder(builderType, fieldNode.createdFields.get(0), source, fluent, chain); + } else { + fieldNode.singularData.getSingularizer().generateMethods(fieldNode.singularData, builderType, source.get(), fluent, chain); + } + } - public JCMethodDecl makeSetterMethodForBuilder(JavacNode builderType, JavacNode fieldNode, JavacNode source, boolean fluent, boolean chain) { + private void makeSimpleSetterMethodForBuilder(JavacNode builderType, JavacNode fieldNode, JavacNode source, boolean fluent, boolean chain) { Name fieldName = ((JCVariableDecl) fieldNode.get()).name; for (JavacNode child : builderType.down()) { if (child.getKind() != Kind.METHOD) continue; Name existingName = ((JCMethodDecl) child.get()).name; - if (existingName.equals(fieldName)) return null; + if (existingName.equals(fieldName)) return; } - boolean isBoolean = isBoolean(fieldNode); - String setterName = fluent ? fieldNode.getName() : toSetterName(builderType.getAst(), null, fieldNode.getName(), isBoolean); + String setterName = fluent ? fieldNode.getName() : HandlerUtil.buildAccessorName("set", fieldNode.getName()); - JavacTreeMaker maker = builderType.getTreeMaker(); - return HandleSetter.createSetter(Flags.PUBLIC, fieldNode, maker, setterName, chain, source, List.<JCAnnotation>nil(), List.<JCAnnotation>nil()); + JavacTreeMaker maker = fieldNode.getTreeMaker(); + JCMethodDecl newMethod = HandleSetter.createSetter(Flags.PUBLIC, fieldNode, maker, setterName, chain, source, List.<JCAnnotation>nil(), List.<JCAnnotation>nil()); + injectMethod(builderType, newMethod); } public JavacNode findInnerClass(JavacNode parent, String name) { @@ -331,4 +449,59 @@ public class HandleBuilder extends JavacAnnotationHandler<Builder> { JCClassDecl builder = maker.ClassDef(mods, tdParent.toName(builderClassName), copyTypeParams(maker, typeParams), null, List.<JCExpression>nil(), List.<JCTree>nil()); return injectType(tdParent, builder); } + + /** + * Returns the explicitly requested singular annotation on this node (field + * or parameter), or null if there's no {@code @Singular} annotation on it. + * + * @param node The node (field or method param) to inspect for its name and potential {@code @Singular} annotation. + */ + private SingularData getSingularData(JavacNode node) { + for (JavacNode child : node.down()) { + if (child.getKind() == Kind.ANNOTATION && annotationTypeMatches(Singular.class, child)) { + Name pluralName = node.getKind() == Kind.FIELD ? removePrefixFromField(node) : ((JCVariableDecl) node.get()).name; + AnnotationValues<Singular> ann = createAnnotation(Singular.class, child); + deleteAnnotationIfNeccessary(child, Singular.class); + String explicitSingular = ann.getInstance().value(); + if (explicitSingular.isEmpty()) { + if (Boolean.FALSE.equals(node.getAst().readConfiguration(ConfigurationKeys.SINGULAR_AUTO))) { + node.addError("The singular must be specified explicitly (e.g. @Singular(\"task\")) because auto singularization is disabled."); + explicitSingular = pluralName.toString(); + } else { + explicitSingular = autoSingularize(node.getName()); + if (explicitSingular == null) { + node.addError("Can't singularize this name; please specify the singular explicitly (i.e. @Singular(\"sheep\"))"); + explicitSingular = pluralName.toString(); + } + } + } + Name singularName = node.toName(explicitSingular); + + JCExpression type = null; + if (node.get() instanceof JCVariableDecl) { + type = ((JCVariableDecl) node.get()).vartype; + } + + String name = null; + List<JCExpression> typeArgs = List.nil(); + if (type instanceof JCTypeApply) { + typeArgs = ((JCTypeApply) type).arguments; + type = ((JCTypeApply) type).clazz; + } + + name = type.toString(); + + String targetFqn = JavacSingularsRecipes.get().toQualified(name); + JavacSingularizer singularizer = JavacSingularsRecipes.get().getSingularizer(targetFqn); + if (singularizer == null) { + node.addError("Lombok does not know how to create the singular-form builder methods for type '" + name + "'; they won't be generated."); + return null; + } + + return new SingularData(child, singularName, pluralName, typeArgs, targetFqn, singularizer); + } + } + + return null; + } } diff --git a/src/core/lombok/javac/handlers/HandleConstructor.java b/src/core/lombok/javac/handlers/HandleConstructor.java index 6043d1cb..c5b309c2 100644 --- a/src/core/lombok/javac/handlers/HandleConstructor.java +++ b/src/core/lombok/javac/handlers/HandleConstructor.java @@ -25,13 +25,13 @@ import static lombok.core.handlers.HandlerUtil.*; import static lombok.javac.handlers.JavacHandlerUtil.*; import lombok.AccessLevel; import lombok.AllArgsConstructor; +import lombok.Builder; import lombok.ConfigurationKeys; import lombok.NoArgsConstructor; import lombok.RequiredArgsConstructor; import lombok.core.AnnotationValues; import lombok.core.AST.Kind; import lombok.delombok.LombokOptionsFactory; -import lombok.experimental.Builder; import lombok.javac.JavacAnnotationHandler; import lombok.javac.JavacNode; import lombok.javac.JavacTreeMaker; diff --git a/src/core/lombok/javac/handlers/HandleLog.java b/src/core/lombok/javac/handlers/HandleLog.java index ee7268f7..06b7c7ef 100644 --- a/src/core/lombok/javac/handlers/HandleLog.java +++ b/src/core/lombok/javac/handlers/HandleLog.java @@ -105,7 +105,7 @@ public class HandleLog { maker.Modifiers(Flags.PRIVATE | Flags.FINAL | (useStatic ? Flags.STATIC : 0)), typeNode.toName(logFieldName), loggerType, factoryMethodCall), source, typeNode.getContext()); - injectFieldSuppressWarnings(typeNode, fieldDecl); + injectFieldAndMarkGenerated(typeNode, fieldDecl); return true; } diff --git a/src/core/lombok/javac/handlers/HandleSynchronized.java b/src/core/lombok/javac/handlers/HandleSynchronized.java index fb6678e6..20e85d7e 100644 --- a/src/core/lombok/javac/handlers/HandleSynchronized.java +++ b/src/core/lombok/javac/handlers/HandleSynchronized.java @@ -99,7 +99,7 @@ public class HandleSynchronized extends JavacAnnotationHandler<Synchronized> { JCVariableDecl fieldDecl = recursiveSetGeneratedBy(maker.VarDef( maker.Modifiers(Flags.PRIVATE | Flags.FINAL | (isStatic ? Flags.STATIC : 0)), methodNode.toName(lockName), objectType, newObjectArray), ast, context); - injectFieldSuppressWarnings(methodNode.up(), fieldDecl); + injectFieldAndMarkGenerated(methodNode.up(), fieldDecl); } if (method.body == null) return; diff --git a/src/core/lombok/javac/handlers/HandleVal.java b/src/core/lombok/javac/handlers/HandleVal.java index 0230e1b0..9eadd750 100644 --- a/src/core/lombok/javac/handlers/HandleVal.java +++ b/src/core/lombok/javac/handlers/HandleVal.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2010-2014 The Project Lombok Authors. + * Copyright (C) 2010-2015 The Project Lombok Authors. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -35,6 +35,7 @@ import lombok.javac.ResolutionResetNeeded; import org.mangosdk.spi.ProviderFor; import com.sun.tools.javac.code.Flags; +import com.sun.tools.javac.code.Symtab; import com.sun.tools.javac.code.Type; import com.sun.tools.javac.tree.JCTree; import com.sun.tools.javac.tree.JCTree.JCAnnotation; @@ -110,6 +111,16 @@ public class HandleVal extends JavacASTAdapter { } } else { type = local.init.type; + if (type.isErroneous()) { + try { + JavacResolution resolver = new JavacResolution(localNode.getContext()); + local.type = Symtab.instance(localNode.getContext()).unknownType; + type = ((JCExpression) resolver.resolveMethodMember(localNode).get(local.init)).type; + } catch (RuntimeException e) { + System.err.println("Exception while resolving: " + localNode); + throw e; + } + } } } else { if (rhsOfEnhancedForLoop.type == null) { diff --git a/src/core/lombok/javac/handlers/HandleWither.java b/src/core/lombok/javac/handlers/HandleWither.java index 8a7b49b2..5de18686 100644 --- a/src/core/lombok/javac/handlers/HandleWither.java +++ b/src/core/lombok/javac/handlers/HandleWither.java @@ -129,8 +129,8 @@ public class HandleWither extends JavacAnnotationHandler<Wither> { if (level == AccessLevel.NONE || node == null) return; - List<JCAnnotation> onMethod = unboxAndRemoveAnnotationParameter(ast, "onMethod", "@Setter(onMethod=", annotationNode); - List<JCAnnotation> onParam = unboxAndRemoveAnnotationParameter(ast, "onParam", "@Setter(onParam=", annotationNode); + List<JCAnnotation> onMethod = unboxAndRemoveAnnotationParameter(ast, "onMethod", "@Wither(onMethod=", annotationNode); + List<JCAnnotation> onParam = unboxAndRemoveAnnotationParameter(ast, "onParam", "@Wither(onParam=", annotationNode); switch (node.getKind()) { case FIELD: diff --git a/src/core/lombok/javac/handlers/JavacHandlerUtil.java b/src/core/lombok/javac/handlers/JavacHandlerUtil.java index 6413e8ef..a073ac0d 100644 --- a/src/core/lombok/javac/handlers/JavacHandlerUtil.java +++ b/src/core/lombok/javac/handlers/JavacHandlerUtil.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2009-2014 The Project Lombok Authors. + * Copyright (C) 2009-2015 The Project Lombok Authors. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -41,6 +41,7 @@ import lombok.Data; import lombok.Getter; import lombok.core.AST.Kind; import lombok.core.AnnotationValues; +import lombok.core.LombokImmutableList; import lombok.core.AnnotationValues.AnnotationValue; import lombok.core.TypeResolver; import lombok.core.configuration.NullCheckExceptionType; @@ -68,7 +69,6 @@ import com.sun.tools.javac.tree.JCTree.JCExpressionStatement; import com.sun.tools.javac.tree.JCTree.JCFieldAccess; import com.sun.tools.javac.tree.JCTree.JCIdent; import com.sun.tools.javac.tree.JCTree.JCImport; -import com.sun.tools.javac.tree.JCTree.JCLiteral; import com.sun.tools.javac.tree.JCTree.JCMethodDecl; import com.sun.tools.javac.tree.JCTree.JCMethodInvocation; import com.sun.tools.javac.tree.JCTree.JCModifiers; @@ -242,51 +242,45 @@ public class JavacHandlerUtil { Map<String, AnnotationValue> values = new HashMap<String, AnnotationValue>(); JCAnnotation anno = (JCAnnotation) node.get(); List<JCExpression> arguments = anno.getArguments(); - for (Method m : type.getDeclaredMethods()) { - if (!Modifier.isPublic(m.getModifiers())) continue; - String name = m.getName(); + + for (JCExpression arg : arguments) { + String mName; + JCExpression rhs; java.util.List<String> raws = new ArrayList<String>(); java.util.List<Object> guesses = new ArrayList<Object>(); java.util.List<Object> expressions = new ArrayList<Object>(); final java.util.List<DiagnosticPosition> positions = new ArrayList<DiagnosticPosition>(); - boolean isExplicit = false; - for (JCExpression arg : arguments) { - String mName; - JCExpression rhs; - - if (arg instanceof JCAssign) { - JCAssign assign = (JCAssign) arg; - mName = assign.lhs.toString(); - rhs = assign.rhs; - } else { - rhs = arg; - mName = "value"; - } - - if (!mName.equals(name)) continue; - isExplicit = true; - if (rhs instanceof JCNewArray) { - List<JCExpression> elems = ((JCNewArray)rhs).elems; - for (JCExpression inner : elems) { - raws.add(inner.toString()); - expressions.add(inner); - guesses.add(calculateGuess(inner)); - positions.add(inner.pos()); - } - } else { - raws.add(rhs.toString()); - expressions.add(rhs); - guesses.add(calculateGuess(rhs)); - positions.add(rhs.pos()); + if (arg instanceof JCAssign) { + JCAssign assign = (JCAssign) arg; + mName = assign.lhs.toString(); + rhs = assign.rhs; + } else { + rhs = arg; + mName = "value"; + } + + if (rhs instanceof JCNewArray) { + List<JCExpression> elems = ((JCNewArray)rhs).elems; + for (JCExpression inner : elems) { + raws.add(inner.toString()); + expressions.add(inner); + guesses.add(calculateGuess(inner)); + positions.add(inner.pos()); } + } else { + raws.add(rhs.toString()); + expressions.add(rhs); + guesses.add(calculateGuess(rhs)); + positions.add(rhs.pos()); } - values.put(name, new AnnotationValue(node, raws, expressions, guesses, isExplicit) { + values.put(mName, new AnnotationValue(node, raws, expressions, guesses, true) { @Override public void setError(String message, int valueIdx) { if (valueIdx < 0) node.addError(message); else node.addError(message, positions.get(valueIdx)); } + @Override public void setWarning(String message, int valueIdx) { if (valueIdx < 0) node.addWarning(message); else node.addWarning(message, positions.get(valueIdx)); @@ -294,6 +288,21 @@ public class JavacHandlerUtil { }); } + for (Method m : type.getDeclaredMethods()) { + if (!Modifier.isPublic(m.getModifiers())) continue; + String name = m.getName(); + if (!values.containsKey(name)) { + values.put(name, new AnnotationValue(node, new ArrayList<String>(), new ArrayList<Object>(), new ArrayList<Object>(), false) { + @Override public void setError(String message, int valueIdx) { + node.addError(message); + } + @Override public void setWarning(String message, int valueIdx) { + node.addWarning(message); + } + }); + } + } + return new AnnotationValues<A>(type, values, node); } @@ -445,9 +454,9 @@ public class JavacHandlerUtil { return HandlerUtil.shouldReturnThis0(accessors, field.getAst()); } - public static JCExpression cloneSelfType(JavacNode field) { - JavacNode typeNode = field; - JavacTreeMaker maker = field.getTreeMaker(); + public static JCExpression cloneSelfType(JavacNode childOfType) { + JavacNode typeNode = childOfType; + JavacTreeMaker maker = childOfType.getTreeMaker(); while (typeNode != null && typeNode.getKind() != Kind.TYPE) typeNode = typeNode.up(); if (typeNode != null && typeNode.get() instanceof JCClassDecl) { JCClassDecl type = (JCClassDecl) typeNode.get(); @@ -808,7 +817,7 @@ public class JavacHandlerUtil { * The field carries the @{@link SuppressWarnings}("all") annotation. * Also takes care of updating the JavacAST. */ - public static void injectFieldSuppressWarnings(JavacNode typeNode, JCVariableDecl field) { + public static void injectFieldAndMarkGenerated(JavacNode typeNode, JCVariableDecl field) { injectField(typeNode, field, true); } @@ -821,10 +830,13 @@ public class JavacHandlerUtil { return injectField(typeNode, field, false); } - private static JavacNode injectField(JavacNode typeNode, JCVariableDecl field, boolean addSuppressWarnings) { + private static JavacNode injectField(JavacNode typeNode, JCVariableDecl field, boolean addGenerated) { JCClassDecl type = (JCClassDecl) typeNode.get(); - if (addSuppressWarnings) addSuppressWarningsAll(field.mods, typeNode, field.pos, getGeneratedBy(field), typeNode.getContext()); + if (addGenerated) { + addSuppressWarningsAll(field.mods, typeNode, field.pos, getGeneratedBy(field), typeNode.getContext()); + addGenerated(field.mods, typeNode, field.pos, getGeneratedBy(field), typeNode.getContext()); + } List<JCTree> insertAfter = null; List<JCTree> insertBefore = type.defs; @@ -883,6 +895,7 @@ public class JavacHandlerUtil { } addSuppressWarningsAll(method.mods, typeNode, method.pos, getGeneratedBy(method), typeNode.getContext()); + addGenerated(method.mods, typeNode, method.pos, getGeneratedBy(method), typeNode.getContext()); type.defs = type.defs.append(method); typeNode.add(method, Kind.METHOD); @@ -898,6 +911,7 @@ public class JavacHandlerUtil { public static JavacNode injectType(JavacNode typeNode, final JCClassDecl type) { JCClassDecl typeDecl = (JCClassDecl) typeNode.get(); addSuppressWarningsAll(type.mods, typeNode, type.pos, getGeneratedBy(type), typeNode.getContext()); + addGenerated(type.mods, typeNode, type.pos, getGeneratedBy(type), typeNode.getContext()); typeDecl.defs = typeDecl.defs.append(type); return typeNode.add(type, Kind.TYPE); } @@ -938,20 +952,52 @@ public class JavacHandlerUtil { public static void addSuppressWarningsAll(JCModifiers mods, JavacNode node, int pos, JCTree source, Context context) { if (!LombokOptionsFactory.getDelombokOptions(context).getFormatPreferences().generateSuppressWarnings()) return; + addAnnotation(mods, node, pos, source, context, "java.lang.SuppressWarnings", node.getTreeMaker().Literal("all")); + + if (Boolean.TRUE.equals(node.getAst().readConfiguration(ConfigurationKeys.ADD_FINDBUGS_SUPPRESSWARNINGS_ANNOTATIONS))) { + JavacTreeMaker maker = node.getTreeMaker(); + JCExpression arg = maker.Assign(maker.Ident(node.toName("justification")), maker.Literal("generated code")); + addAnnotation(mods, node, pos, source, context, "edu.umd.cs.findbugs.annotations.SuppressFBWarnings", arg); + } + } + + public static void addGenerated(JCModifiers mods, JavacNode node, int pos, JCTree source, Context context) { + if (!LombokOptionsFactory.getDelombokOptions(context).getFormatPreferences().generateGenerated()) return; + + if (!Boolean.FALSE.equals(node.getAst().readConfiguration(ConfigurationKeys.ADD_GENERATED_ANNOTATIONS))) { + addAnnotation(mods, node, pos, source, context, "javax.annotation.Generated", node.getTreeMaker().Literal("lombok")); + } + } + + private static void addAnnotation(JCModifiers mods, JavacNode node, int pos, JCTree source, Context context, String annotationTypeFqn, JCExpression arg) { + boolean isJavaLangBased; + String simpleName; { + int idx = annotationTypeFqn.lastIndexOf('.'); + simpleName = idx == -1 ? annotationTypeFqn : annotationTypeFqn.substring(idx + 1); + + isJavaLangBased = idx == 9 && annotationTypeFqn.regionMatches(0, "java.lang.", 0, 10); + } + for (JCAnnotation ann : mods.annotations) { JCTree annType = ann.getAnnotationType(); Name lastPart = null; if (annType instanceof JCIdent) lastPart = ((JCIdent) annType).name; else if (annType instanceof JCFieldAccess) lastPart = ((JCFieldAccess) annType).name; - if (lastPart != null && lastPart.contentEquals("SuppressWarnings")) return; + if (lastPart != null && lastPart.contentEquals(simpleName)) return; } JavacTreeMaker maker = node.getTreeMaker(); - JCExpression suppressWarningsType = genJavaLangTypeRef(node, "SuppressWarnings"); - JCLiteral allLiteral = maker.Literal("all"); - suppressWarningsType.pos = pos; - allLiteral.pos = pos; - JCAnnotation annotation = recursiveSetGeneratedBy(maker.Annotation(suppressWarningsType, List.<JCExpression>of(allLiteral)), source, context); + JCExpression annType = isJavaLangBased ? genJavaLangTypeRef(node, simpleName) : chainDotsString(node, annotationTypeFqn); + annType.pos = pos; + if (arg != null) { + arg.pos = pos; + if (arg instanceof JCAssign) { + ((JCAssign) arg).lhs.pos = pos; + ((JCAssign) arg).rhs.pos = pos; + } + } + List<JCExpression> argList = arg != null ? List.of(arg) : List.<JCExpression>nil(); + JCAnnotation annotation = recursiveSetGeneratedBy(maker.Annotation(annType, argList), source, context); annotation.pos = pos; mods.annotations = mods.annotations.append(annotation); } @@ -985,6 +1031,17 @@ public class JavacHandlerUtil { return chainDots(node, -1, null, null, elems); } + public static JCExpression chainDots(JavacNode node, LombokImmutableList<String> elems) { + assert elems != null; + + JavacTreeMaker maker = node.getTreeMaker(); + JCExpression e = null; + for (String elem : elems) { + if (e == null) e = maker.Ident(node.toName(elem)); + else e = maker.Select(e, node.toName(elem)); + } + return e; + } /** * In javac, dotted access of any kind, from {@code java.lang.String} to {@code var.methodName} * is represented by a fold-left of {@code Select} nodes with the leftmost string represented by @@ -1013,7 +1070,6 @@ public class JavacHandlerUtil { return e; } - /** * In javac, dotted access of any kind, from {@code java.lang.String} to {@code var.methodName} diff --git a/src/core/lombok/javac/handlers/JavacSingularsRecipes.java b/src/core/lombok/javac/handlers/JavacSingularsRecipes.java new file mode 100644 index 00000000..7fca01ae --- /dev/null +++ b/src/core/lombok/javac/handlers/JavacSingularsRecipes.java @@ -0,0 +1,300 @@ +/* + * Copyright (C) 2015 The Project Lombok Authors. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +package lombok.javac.handlers; + +import static lombok.javac.Javac.*; +import static lombok.javac.handlers.JavacHandlerUtil.*; + +import java.io.IOException; +import java.util.Arrays; +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; + +import lombok.core.LombokImmutableList; +import lombok.core.SpiLoadUtil; +import lombok.core.TypeLibrary; +import lombok.javac.JavacNode; +import lombok.javac.JavacTreeMaker; + +import com.sun.source.tree.Tree.Kind; +import com.sun.tools.javac.code.BoundKind; +import com.sun.tools.javac.tree.JCTree; +import com.sun.tools.javac.tree.JCTree.JCExpression; +import com.sun.tools.javac.tree.JCTree.JCMethodDecl; +import com.sun.tools.javac.tree.JCTree.JCStatement; +import com.sun.tools.javac.tree.JCTree.JCVariableDecl; +import com.sun.tools.javac.tree.JCTree.JCWildcard; +import com.sun.tools.javac.util.Context; +import com.sun.tools.javac.util.List; +import com.sun.tools.javac.util.ListBuffer; +import com.sun.tools.javac.util.Name; + +public class JavacSingularsRecipes { + private static final JavacSingularsRecipes INSTANCE = new JavacSingularsRecipes(); + private final Map<String, JavacSingularizer> singularizers = new HashMap<String, JavacSingularizer>(); + private final TypeLibrary singularizableTypes = new TypeLibrary(); + + private JavacSingularsRecipes() { + try { + loadAll(singularizableTypes, singularizers); + singularizableTypes.lock(); + } catch (IOException e) { + System.err.println("Lombok's @Singularizable feature is broken due to misconfigured SPI files: " + e); + } + } + + private static void loadAll(TypeLibrary library, Map<String, JavacSingularizer> map) throws IOException { + for (JavacSingularizer handler : SpiLoadUtil.findServices(JavacSingularizer.class, JavacSingularizer.class.getClassLoader())) { + for (String type : handler.getSupportedTypes()) { + JavacSingularizer existingSingularizer = map.get(type); + if (existingSingularizer != null) { + JavacSingularizer toKeep = existingSingularizer.getClass().getName().compareTo(handler.getClass().getName()) > 0 ? handler : existingSingularizer; + System.err.println("Multiple singularizers found for type " + type + "; the alphabetically first class is used: " + toKeep.getClass().getName()); + map.put(type, toKeep); + } else { + map.put(type, handler); + library.addType(type); + } + } + } + } + + public static JavacSingularsRecipes get() { + return INSTANCE; + } + + public String toQualified(String typeReference) { + return singularizableTypes.toQualified(typeReference); + } + + public JavacSingularizer getSingularizer(String fqn) { + return singularizers.get(fqn); + } + + public static final class SingularData { + private final JavacNode annotation; + private final Name singularName; + private final Name pluralName; + private final List<JCExpression> typeArgs; + private final String targetFqn; + private final JavacSingularizer singularizer; + + public SingularData(JavacNode annotation, Name singularName, Name pluralName, List<JCExpression> typeArgs, String targetFqn, JavacSingularizer singularizer) { + this.annotation = annotation; + this.singularName = singularName; + this.pluralName = pluralName; + this.typeArgs = typeArgs; + this.targetFqn = targetFqn; + this.singularizer = singularizer; + } + + public JavacNode getAnnotation() { + return annotation; + } + + public Name getSingularName() { + return singularName; + } + + public Name getPluralName() { + return pluralName; + } + + public List<JCExpression> getTypeArgs() { + return typeArgs; + } + + public String getTargetFqn() { + return targetFqn; + } + + public JavacSingularizer getSingularizer() { + return singularizer; + } + + public String getTargetSimpleType() { + int idx = targetFqn.lastIndexOf("."); + return idx == -1 ? targetFqn : targetFqn.substring(idx + 1); + } + } + + public static abstract class JavacSingularizer { + public abstract LombokImmutableList<String> getSupportedTypes(); + + /** Checks if any of the to-be-generated nodes (fields, methods) already exist. If so, errors on these (singulars don't support manually writing some of it, and returns true). */ + public boolean checkForAlreadyExistingNodesAndGenerateError(JavacNode builderType, SingularData data) { + for (JavacNode child : builderType.down()) { + switch (child.getKind()) { + case FIELD: { + JCVariableDecl field = (JCVariableDecl) child.get(); + Name name = field.name; + if (name == null) break; + if (getGeneratedBy(field) != null) continue; + for (Name fieldToBeGenerated : listFieldsToBeGenerated(data, builderType)) { + if (!fieldToBeGenerated.equals(name)) continue; + child.addError("Manually adding a field that @Singular @Builder would generate is not supported. If you want to manually manage the builder aspect for this field/parameter, don't use @Singular."); + return true; + } + break; + } + case METHOD: { + JCMethodDecl method = (JCMethodDecl) child.get(); + Name name = method.name; + if (name == null) break; + if (getGeneratedBy(method) != null) continue; + for (Name methodToBeGenerated : listMethodsToBeGenerated(data, builderType)) { + if (!methodToBeGenerated.equals(name)) continue; + child.addError("Manually adding a method that @Singular @Builder would generate is not supported. If you want to manually manage the builder aspect for this field/parameter, don't use @Singular."); + return true; + } + break; + }} + } + + return false; + } + + public java.util.List<Name> listFieldsToBeGenerated(SingularData data, JavacNode builderType) { + return Collections.singletonList(data.pluralName); + } + + public java.util.List<Name> listMethodsToBeGenerated(SingularData data, JavacNode builderType) { + Name p = data.pluralName; + Name s = data.singularName; + if (p.equals(s)) return Collections.singletonList(p); + return Arrays.asList(p, s); + } + + public abstract java.util.List<JavacNode> generateFields(SingularData data, JavacNode builderType, JCTree source); + public abstract void generateMethods(SingularData data, JavacNode builderType, JCTree source, boolean fluent, boolean chain); + public abstract void appendBuildCode(SingularData data, JavacNode builderType, JCTree source, ListBuffer<JCStatement> statements, Name targetVariableName); + + public boolean requiresCleaning() { + try { + return !getClass().getMethod("appendCleaningCode", SingularData.class, JavacNode.class, JCTree.class, ListBuffer.class).getDeclaringClass().equals(JavacSingularizer.class); + } catch (NoSuchMethodException e) { + return false; + } + } + + public void appendCleaningCode(SingularData data, JavacNode builderType, JCTree source, ListBuffer<JCStatement> statements) { + } + + // -- Utility methods -- + + /** + * Adds the requested number of type arguments to the provided type, copying each argument in {@code typeArgs}. If typeArgs is too long, the extra elements are ignored. + * If {@code typeArgs} is null or too short, {@code java.lang.Object} will be substituted for each missing type argument. + * + * @param count The number of type arguments requested. + * @param addExtends If {@code true}, all bounds are either '? extends X' or just '?'. If false, the reverse is applied, and '? extends Foo' is converted to Foo, '?' to Object, etc. + * @param node Some node in the same AST. Just used to obtain makers and contexts and such. + * @param type The type to add generics to. + * @param typeArgs the list of type args to clone. + * @param source The source annotation that is the root cause of this code generation. + */ + protected JCExpression addTypeArgs(int count, boolean addExtends, JavacNode node, JCExpression type, List<JCExpression> typeArgs, JCTree source) { + JavacTreeMaker maker = node.getTreeMaker(); + List<JCExpression> clonedAndFixedTypeArgs = createTypeArgs(count, addExtends, node, typeArgs, source); + + return maker.TypeApply(type, clonedAndFixedTypeArgs); + } + + protected List<JCExpression> createTypeArgs(int count, boolean addExtends, JavacNode node, List<JCExpression> typeArgs, JCTree source) { + JavacTreeMaker maker = node.getTreeMaker(); + Context context = node.getContext(); + + if (count < 0) throw new IllegalArgumentException("count is negative"); + if (count == 0) return List.nil(); + ListBuffer<JCExpression> arguments = new ListBuffer<JCExpression>(); + + if (typeArgs != null) for (JCExpression orig : typeArgs) { + if (!addExtends) { + if (orig.getKind() == Kind.UNBOUNDED_WILDCARD || orig.getKind() == Kind.SUPER_WILDCARD) { + arguments.append(genJavaLangTypeRef(node, "Object")); + } else if (orig.getKind() == Kind.EXTENDS_WILDCARD) { + JCExpression inner; + try { + inner = (JCExpression) ((JCWildcard) orig).inner; + } catch (Exception e) { + inner = genJavaLangTypeRef(node, "Object"); + } + arguments.append(cloneType(maker, inner, source, context)); + } else { + arguments.append(cloneType(maker, orig, source, context)); + } + } else { + if (orig.getKind() == Kind.UNBOUNDED_WILDCARD || orig.getKind() == Kind.SUPER_WILDCARD) { + arguments.append(maker.Wildcard(maker.TypeBoundKind(BoundKind.UNBOUND), null)); + } else if (orig.getKind() == Kind.EXTENDS_WILDCARD) { + arguments.append(cloneType(maker, orig, source, context)); + } else { + arguments.append(maker.Wildcard(maker.TypeBoundKind(BoundKind.EXTENDS), cloneType(maker, orig, source, context))); + } + } + if (--count == 0) break; + } + + while (count-- > 0) { + if (addExtends) { + arguments.append(maker.Wildcard(maker.TypeBoundKind(BoundKind.UNBOUND), null)); + } else { + arguments.append(genJavaLangTypeRef(node, "Object")); + } + } + + return arguments.toList(); + } + + /** Generates 'this.<em>name</em>.size()' as an expression; if nullGuard is true, it's this.name == null ? 0 : this.name.size(). */ + protected JCExpression getSize(JavacTreeMaker maker, JavacNode builderType, Name name, boolean nullGuard) { + Name thisName = builderType.toName("this"); + JCExpression fn = maker.Select(maker.Select(maker.Ident(thisName), name), builderType.toName("size")); + JCExpression sizeInvoke = maker.Apply(List.<JCExpression>nil(), fn, List.<JCExpression>nil()); + if (nullGuard) { + JCExpression isNull = maker.Binary(CTC_EQUAL, maker.Select(maker.Ident(thisName), name), maker.Literal(CTC_BOT, 0)); + return maker.Conditional(isNull, maker.Literal(CTC_INT, 0), sizeInvoke); + } + return sizeInvoke; + } + + protected JCExpression cloneParamType(int index, JavacTreeMaker maker, List<JCExpression> typeArgs, JavacNode builderType, JCTree source) { + if (typeArgs == null || typeArgs.size() <= index) { + return genJavaLangTypeRef(builderType, "Object"); + } else { + JCExpression originalType = typeArgs.get(index); + if (originalType.getKind() == Kind.UNBOUNDED_WILDCARD || originalType.getKind() == Kind.SUPER_WILDCARD) { + return genJavaLangTypeRef(builderType, "Object"); + } else if (originalType.getKind() == Kind.EXTENDS_WILDCARD) { + try { + return cloneType(maker, (JCExpression) ((JCWildcard) originalType).inner, source, builderType.getContext()); + } catch (Exception e) { + return genJavaLangTypeRef(builderType, "Object"); + } + } else { + return cloneType(maker, originalType, source, builderType.getContext()); + } + } + } + } +} diff --git a/src/core/lombok/javac/handlers/singulars/JavacGuavaMapSingularizer.java b/src/core/lombok/javac/handlers/singulars/JavacGuavaMapSingularizer.java new file mode 100644 index 00000000..0700e2e5 --- /dev/null +++ b/src/core/lombok/javac/handlers/singulars/JavacGuavaMapSingularizer.java @@ -0,0 +1,45 @@ +/* + * Copyright (C) 2015 The Project Lombok Authors. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +package lombok.javac.handlers.singulars; + +import lombok.core.LombokImmutableList; +import lombok.javac.handlers.JavacSingularsRecipes.JavacSingularizer; + +import org.mangosdk.spi.ProviderFor; + +@ProviderFor(JavacSingularizer.class) +public class JavacGuavaMapSingularizer extends JavacGuavaSingularizer { + // TODO cgcc.ImmutableMultimap, cgcc.ImmutableListMultimap, cgcc.ImmutableSetMultimap + // TODO cgcc.ImmutableClassToInstanceMap + // TODO cgcc.ImmutableRangeMap + + @Override public LombokImmutableList<String> getSupportedTypes() { + return LombokImmutableList.of( + "com.google.common.collect.ImmutableMap", + "com.google.common.collect.ImmutableBiMap", + "com.google.common.collect.ImmutableSortedMap"); + } + + @Override protected boolean isMap() { + return true; + } +} diff --git a/src/core/lombok/javac/handlers/singulars/JavacGuavaSetListSingularizer.java b/src/core/lombok/javac/handlers/singulars/JavacGuavaSetListSingularizer.java new file mode 100644 index 00000000..2e404ca8 --- /dev/null +++ b/src/core/lombok/javac/handlers/singulars/JavacGuavaSetListSingularizer.java @@ -0,0 +1,45 @@ +/* + * Copyright (C) 2015 The Project Lombok Authors. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +package lombok.javac.handlers.singulars; + +import lombok.core.LombokImmutableList; +import lombok.javac.handlers.JavacSingularsRecipes.JavacSingularizer; + +import org.mangosdk.spi.ProviderFor; + +@ProviderFor(JavacSingularizer.class) +public class JavacGuavaSetListSingularizer extends JavacGuavaSingularizer { + // TODO com.google.common.collect.ImmutableTable + // TODO com.google.common.collect.ImmutableRangeSet + // TODO com.google.common.collect.ImmutableMultiset and com.google.common.collect.ImmutableSortedMultiset + @Override public LombokImmutableList<String> getSupportedTypes() { + return LombokImmutableList.of( + "com.google.common.collect.ImmutableCollection", + "com.google.common.collect.ImmutableList", + "com.google.common.collect.ImmutableSet", + "com.google.common.collect.ImmutableSortedSet"); + } + + @Override protected boolean isMap() { + return false; + } +} diff --git a/src/core/lombok/javac/handlers/singulars/JavacGuavaSingularizer.java b/src/core/lombok/javac/handlers/singulars/JavacGuavaSingularizer.java new file mode 100644 index 00000000..e23837dc --- /dev/null +++ b/src/core/lombok/javac/handlers/singulars/JavacGuavaSingularizer.java @@ -0,0 +1,194 @@ +/* + * Copyright (C) 2015 The Project Lombok Authors. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +package lombok.javac.handlers.singulars; + +import static lombok.javac.Javac.*; +import static lombok.javac.handlers.JavacHandlerUtil.*; + +import java.util.Collections; + +import lombok.core.GuavaTypeMap; +import lombok.core.handlers.HandlerUtil; +import lombok.javac.JavacNode; +import lombok.javac.JavacTreeMaker; +import lombok.javac.handlers.JavacHandlerUtil; +import lombok.javac.handlers.JavacSingularsRecipes.JavacSingularizer; +import lombok.javac.handlers.JavacSingularsRecipes.SingularData; + +import com.sun.tools.javac.code.Flags; +import com.sun.tools.javac.tree.JCTree; +import com.sun.tools.javac.tree.JCTree.JCBlock; +import com.sun.tools.javac.tree.JCTree.JCExpression; +import com.sun.tools.javac.tree.JCTree.JCMethodDecl; +import com.sun.tools.javac.tree.JCTree.JCModifiers; +import com.sun.tools.javac.tree.JCTree.JCStatement; +import com.sun.tools.javac.tree.JCTree.JCTypeParameter; +import com.sun.tools.javac.tree.JCTree.JCVariableDecl; +import com.sun.tools.javac.util.List; +import com.sun.tools.javac.util.ListBuffer; +import com.sun.tools.javac.util.Name; + +abstract class JavacGuavaSingularizer extends JavacSingularizer { + protected String getSimpleTargetTypeName(SingularData data) { + return GuavaTypeMap.getGuavaTypeName(data.getTargetFqn()); + } + + protected String getBuilderMethodName(SingularData data) { + String simpleTypeName = getSimpleTargetTypeName(data); + if ("ImmutableSortedSet".equals(simpleTypeName) || "ImmutableSortedMap".equals(simpleTypeName)) return "naturalOrder"; + return "builder"; + } + + protected abstract boolean isMap(); + + @Override public java.util.List<JavacNode> generateFields(SingularData data, JavacNode builderType, JCTree source) { + JavacTreeMaker maker = builderType.getTreeMaker(); + JCExpression type = JavacHandlerUtil.chainDots(builderType, "com", "google", "common", "collect", getSimpleTargetTypeName(data), "Builder"); + type = addTypeArgs(isMap() ? 2 : 1, false, builderType, type, data.getTypeArgs(), source); + + JCVariableDecl buildField = maker.VarDef(maker.Modifiers(Flags.PRIVATE), data.getPluralName(), type, null); + return Collections.singletonList(injectField(builderType, buildField)); + } + + @Override public void generateMethods(SingularData data, JavacNode builderType, JCTree source, boolean fluent, boolean chain) { + JavacTreeMaker maker = builderType.getTreeMaker(); + JCExpression returnType = chain ? cloneSelfType(builderType) : maker.Type(createVoidType(maker, CTC_VOID)); + JCStatement returnStatement = chain ? maker.Return(maker.Ident(builderType.toName("this"))) : null; + generateSingularMethod(maker, returnType, returnStatement, data, builderType, source, fluent); + + returnType = chain ? cloneSelfType(builderType) : maker.Type(createVoidType(maker, CTC_VOID)); + returnStatement = chain ? maker.Return(maker.Ident(builderType.toName("this"))) : null; + generatePluralMethod(maker, returnType, returnStatement, data, builderType, source, fluent); + } + + void generateSingularMethod(JavacTreeMaker maker, JCExpression returnType, JCStatement returnStatement, SingularData data, JavacNode builderType, JCTree source, boolean fluent) { + List<JCTypeParameter> typeParams = List.nil(); + List<JCExpression> thrown = List.nil(); + boolean mapMode = isMap(); + + Name keyName = !mapMode ? data.getSingularName() : builderType.toName(data.getSingularName() + "$key"); + Name valueName = !mapMode ? null : builderType.toName(data.getSingularName() + "$value"); + + JCModifiers mods = maker.Modifiers(Flags.PUBLIC); + ListBuffer<JCStatement> statements = new ListBuffer<JCStatement>(); + statements.append(createConstructBuilderVarIfNeeded(maker, data, builderType, mapMode, source)); + JCExpression thisDotFieldDotAdd = chainDots(builderType, "this", data.getPluralName().toString(), mapMode ? "put" : "add"); + List<JCExpression> invokeAddExpr; + if (mapMode) { + invokeAddExpr = List.<JCExpression>of(maker.Ident(keyName), maker.Ident(valueName)); + } else { + invokeAddExpr = List.<JCExpression>of(maker.Ident(keyName)); + } + JCExpression invokeAdd = maker.Apply(List.<JCExpression>nil(), thisDotFieldDotAdd, invokeAddExpr); + statements.append(maker.Exec(invokeAdd)); + if (returnStatement != null) statements.append(returnStatement); + JCBlock body = maker.Block(0, statements.toList()); + Name methodName = data.getSingularName(); + long paramFlags = JavacHandlerUtil.addFinalIfNeeded(Flags.PARAMETER, builderType.getContext()); + if (!fluent) methodName = builderType.toName(HandlerUtil.buildAccessorName(mapMode ? "put" : "add", methodName.toString())); + List<JCVariableDecl> params; + if (mapMode) { + JCExpression keyType = cloneParamType(0, maker, data.getTypeArgs(), builderType, source); + JCExpression valueType = cloneParamType(1, maker, data.getTypeArgs(), builderType, source); + JCVariableDecl paramKey = maker.VarDef(maker.Modifiers(paramFlags), keyName, keyType, null); + JCVariableDecl paramValue = maker.VarDef(maker.Modifiers(paramFlags), valueName, valueType, null); + params = List.of(paramKey, paramValue); + } else { + JCExpression paramType = cloneParamType(0, maker, data.getTypeArgs(), builderType, source); + params = List.of(maker.VarDef(maker.Modifiers(paramFlags), data.getSingularName(), paramType, null)); + } + JCMethodDecl method = maker.MethodDef(mods, methodName, returnType, typeParams, params, thrown, body, null); + injectMethod(builderType, method); + } + + protected void generatePluralMethod(JavacTreeMaker maker, JCExpression returnType, JCStatement returnStatement, SingularData data, JavacNode builderType, JCTree source, boolean fluent) { + List<JCTypeParameter> typeParams = List.nil(); + List<JCExpression> thrown = List.nil(); + boolean mapMode = isMap(); + + JCModifiers mods = maker.Modifiers(Flags.PUBLIC); + ListBuffer<JCStatement> statements = new ListBuffer<JCStatement>(); + statements.append(createConstructBuilderVarIfNeeded(maker, data, builderType, mapMode, source)); + JCExpression thisDotFieldDotAddAll = chainDots(builderType, "this", data.getPluralName().toString(), mapMode ? "putAll" : "addAll"); + JCExpression invokeAddAll = maker.Apply(List.<JCExpression>nil(), thisDotFieldDotAddAll, List.<JCExpression>of(maker.Ident(data.getPluralName()))); + statements.append(maker.Exec(invokeAddAll)); + if (returnStatement != null) statements.append(returnStatement); + JCBlock body = maker.Block(0, statements.toList()); + Name methodName = data.getPluralName(); + long paramFlags = JavacHandlerUtil.addFinalIfNeeded(Flags.PARAMETER, builderType.getContext()); + if (!fluent) methodName = builderType.toName(HandlerUtil.buildAccessorName(mapMode ? "putAll" : "addAll", methodName.toString())); + JCExpression paramType; + if (mapMode) { + paramType = chainDots(builderType, "java", "util", "Map"); + } else { + paramType = genJavaLangTypeRef(builderType, "Iterable"); + } + paramType = addTypeArgs(mapMode ? 2 : 1, true, builderType, paramType, data.getTypeArgs(), source); + JCVariableDecl param = maker.VarDef(maker.Modifiers(paramFlags), data.getPluralName(), paramType, null); + JCMethodDecl method = maker.MethodDef(mods, methodName, returnType, typeParams, List.of(param), thrown, body, null); + injectMethod(builderType, method); + } + + @Override public void appendBuildCode(SingularData data, JavacNode builderType, JCTree source, ListBuffer<JCStatement> statements, Name targetVariableName) { + JavacTreeMaker maker = builderType.getTreeMaker(); + List<JCExpression> jceBlank = List.nil(); + boolean mapMode = isMap(); + + JCExpression varType = chainDotsString(builderType, data.getTargetFqn()); + varType = addTypeArgs(mapMode ? 2 : 1, false, builderType, varType, data.getTypeArgs(), source); + + JCExpression empty; { + //ImmutableX.of() + JCExpression emptyMethod = chainDots(builderType, "com", "google", "common", "collect", getSimpleTargetTypeName(data), "of"); + List<JCExpression> invokeTypeArgs = createTypeArgs(mapMode ? 2 : 1, false, builderType, data.getTypeArgs(), source); + empty = maker.Apply(invokeTypeArgs, emptyMethod, jceBlank); + } + + JCExpression invokeBuild; { + //this.pluralName.build(); + invokeBuild = maker.Apply(jceBlank, chainDots(builderType, "this", data.getPluralName().toString(), "build"), jceBlank); + } + + JCExpression isNull; { + //this.pluralName == null + isNull = maker.Binary(CTC_EQUAL, maker.Select(maker.Ident(builderType.toName("this")), data.getPluralName()), maker.Literal(CTC_BOT, null)); + } + + JCExpression init = maker.Conditional(isNull, empty, invokeBuild); // this.pluralName == null ? ImmutableX.of() : this.pluralName.build() + + JCStatement jcs = maker.VarDef(maker.Modifiers(0), data.getPluralName(), varType, init); + statements.append(jcs); + } + + protected JCStatement createConstructBuilderVarIfNeeded(JavacTreeMaker maker, SingularData data, JavacNode builderType, boolean mapMode, JCTree source) { + List<JCExpression> jceBlank = List.nil(); + + JCExpression thisDotField = maker.Select(maker.Ident(builderType.toName("this")), data.getPluralName()); + JCExpression thisDotField2 = maker.Select(maker.Ident(builderType.toName("this")), data.getPluralName()); + JCExpression cond = maker.Binary(CTC_EQUAL, thisDotField, maker.Literal(CTC_BOT, null)); + + JCExpression create = maker.Apply(jceBlank, chainDots(builderType, "com", "google", "common", "collect", getSimpleTargetTypeName(data), getBuilderMethodName(data)), jceBlank); + JCStatement thenPart = maker.Exec(maker.Assign(thisDotField2, create)); + + return maker.If(cond, thenPart, null); + } +} diff --git a/src/core/lombok/javac/handlers/singulars/JavacJavaUtilListSetSingularizer.java b/src/core/lombok/javac/handlers/singulars/JavacJavaUtilListSetSingularizer.java new file mode 100644 index 00000000..6f8ff705 --- /dev/null +++ b/src/core/lombok/javac/handlers/singulars/JavacJavaUtilListSetSingularizer.java @@ -0,0 +1,138 @@ +/* + * Copyright (C) 2015 The Project Lombok Authors. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +package lombok.javac.handlers.singulars; + +import static lombok.javac.Javac.*; +import static lombok.javac.handlers.JavacHandlerUtil.*; + +import java.util.Collections; + +import lombok.core.handlers.HandlerUtil; +import lombok.javac.JavacNode; +import lombok.javac.JavacTreeMaker; +import lombok.javac.handlers.JavacHandlerUtil; +import lombok.javac.handlers.JavacSingularsRecipes.SingularData; + +import com.sun.tools.javac.code.Flags; +import com.sun.tools.javac.tree.JCTree; +import com.sun.tools.javac.tree.JCTree.JCBlock; +import com.sun.tools.javac.tree.JCTree.JCExpression; +import com.sun.tools.javac.tree.JCTree.JCMethodDecl; +import com.sun.tools.javac.tree.JCTree.JCModifiers; +import com.sun.tools.javac.tree.JCTree.JCStatement; +import com.sun.tools.javac.tree.JCTree.JCTypeParameter; +import com.sun.tools.javac.tree.JCTree.JCVariableDecl; +import com.sun.tools.javac.util.List; +import com.sun.tools.javac.util.ListBuffer; +import com.sun.tools.javac.util.Name; + +abstract class JavacJavaUtilListSetSingularizer extends JavacJavaUtilSingularizer { + @Override public java.util.List<Name> listFieldsToBeGenerated(SingularData data, JavacNode builderType) { + if (useGuavaInstead(builderType)) { + return guavaListSetSingularizer.listFieldsToBeGenerated(data, builderType); + } + + return super.listFieldsToBeGenerated(data, builderType); + } + + @Override public java.util.List<Name> listMethodsToBeGenerated(SingularData data, JavacNode builderType) { + if (useGuavaInstead(builderType)) { + return guavaListSetSingularizer.listMethodsToBeGenerated(data, builderType); + } + + return super.listMethodsToBeGenerated(data, builderType); + } + + @Override public java.util.List<JavacNode> generateFields(SingularData data, JavacNode builderType, JCTree source) { + if (useGuavaInstead(builderType)) { + return guavaListSetSingularizer.generateFields(data, builderType, source); + } + + JavacTreeMaker maker = builderType.getTreeMaker(); + JCExpression type = JavacHandlerUtil.chainDots(builderType, "java", "util", "ArrayList"); + type = addTypeArgs(1, false, builderType, type, data.getTypeArgs(), source); + + JCVariableDecl buildField = maker.VarDef(maker.Modifiers(Flags.PRIVATE), data.getPluralName(), type, null); + return Collections.singletonList(injectField(builderType, buildField)); + } + + @Override public void generateMethods(SingularData data, JavacNode builderType, JCTree source, boolean fluent, boolean chain) { + if (useGuavaInstead(builderType)) { + guavaListSetSingularizer.generateMethods(data, builderType, source, fluent, chain); + return; + } + + JavacTreeMaker maker = builderType.getTreeMaker(); + Name thisName = builderType.toName("this"); + + JCExpression returnType = chain ? cloneSelfType(builderType) : maker.Type(createVoidType(maker, CTC_VOID)); + JCStatement returnStatement = chain ? maker.Return(maker.Ident(thisName)) : null; + generateSingularMethod(maker, returnType, returnStatement, data, builderType, source, fluent); + + returnType = chain ? cloneSelfType(builderType) : maker.Type(createVoidType(maker, CTC_VOID)); + returnStatement = chain ? maker.Return(maker.Ident(thisName)) : null; + generatePluralMethod(maker, returnType, returnStatement, data, builderType, source, fluent); + } + + void generateSingularMethod(JavacTreeMaker maker, JCExpression returnType, JCStatement returnStatement, SingularData data, JavacNode builderType, JCTree source, boolean fluent) { + List<JCTypeParameter> typeParams = List.nil(); + List<JCExpression> thrown = List.nil(); + + JCModifiers mods = maker.Modifiers(Flags.PUBLIC); + ListBuffer<JCStatement> statements = new ListBuffer<JCStatement>(); + statements.append(createConstructBuilderVarIfNeeded(maker, data, builderType, false, source)); + JCExpression thisDotFieldDotAdd = chainDots(builderType, "this", data.getPluralName().toString(), "add"); + JCExpression invokeAdd = maker.Apply(List.<JCExpression>nil(), thisDotFieldDotAdd, List.<JCExpression>of(maker.Ident(data.getSingularName()))); + statements.append(maker.Exec(invokeAdd)); + if (returnStatement != null) statements.append(returnStatement); + JCBlock body = maker.Block(0, statements.toList()); + Name name = data.getSingularName(); + long paramFlags = JavacHandlerUtil.addFinalIfNeeded(Flags.PARAMETER, builderType.getContext()); + if (!fluent) name = builderType.toName(HandlerUtil.buildAccessorName("add", name.toString())); + JCExpression paramType = cloneParamType(0, maker, data.getTypeArgs(), builderType, source); + JCVariableDecl param = maker.VarDef(maker.Modifiers(paramFlags), data.getSingularName(), paramType, null); + JCMethodDecl method = maker.MethodDef(mods, name, returnType, typeParams, List.of(param), thrown, body, null); + injectMethod(builderType, method); + } + + void generatePluralMethod(JavacTreeMaker maker, JCExpression returnType, JCStatement returnStatement, SingularData data, JavacNode builderType, JCTree source, boolean fluent) { + List<JCTypeParameter> typeParams = List.nil(); + List<JCExpression> thrown = List.nil(); + + JCModifiers mods = maker.Modifiers(Flags.PUBLIC); + ListBuffer<JCStatement> statements = new ListBuffer<JCStatement>(); + statements.append(createConstructBuilderVarIfNeeded(maker, data, builderType, false, source)); + JCExpression thisDotFieldDotAdd = chainDots(builderType, "this", data.getPluralName().toString(), "addAll"); + JCExpression invokeAdd = maker.Apply(List.<JCExpression>nil(), thisDotFieldDotAdd, List.<JCExpression>of(maker.Ident(data.getPluralName()))); + statements.append(maker.Exec(invokeAdd)); + if (returnStatement != null) statements.append(returnStatement); + JCBlock body = maker.Block(0, statements.toList()); + Name name = data.getPluralName(); + long paramFlags = JavacHandlerUtil.addFinalIfNeeded(Flags.PARAMETER, builderType.getContext()); + if (!fluent) name = builderType.toName(HandlerUtil.buildAccessorName("addAll", name.toString())); + JCExpression paramType = chainDots(builderType, "java", "util", "Collection"); + paramType = addTypeArgs(1, true, builderType, paramType, data.getTypeArgs(), source); + JCVariableDecl param = maker.VarDef(maker.Modifiers(paramFlags), data.getPluralName(), paramType, null); + JCMethodDecl method = maker.MethodDef(mods, name, returnType, typeParams, List.of(param), thrown, body, null); + injectMethod(builderType, method); + } +} diff --git a/src/core/lombok/javac/handlers/singulars/JavacJavaUtilListSingularizer.java b/src/core/lombok/javac/handlers/singulars/JavacJavaUtilListSingularizer.java new file mode 100644 index 00000000..9ec77e78 --- /dev/null +++ b/src/core/lombok/javac/handlers/singulars/JavacJavaUtilListSingularizer.java @@ -0,0 +1,120 @@ +/* + * Copyright (C) 2015 The Project Lombok Authors. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +package lombok.javac.handlers.singulars; + +import static lombok.javac.Javac.*; +import static lombok.javac.handlers.JavacHandlerUtil.*; + +import org.mangosdk.spi.ProviderFor; + +import lombok.core.LombokImmutableList; +import lombok.javac.JavacNode; +import lombok.javac.JavacTreeMaker; +import lombok.javac.handlers.JavacSingularsRecipes.JavacSingularizer; +import lombok.javac.handlers.JavacSingularsRecipes.SingularData; + +import com.sun.tools.javac.tree.JCTree; +import com.sun.tools.javac.tree.JCTree.JCCase; +import com.sun.tools.javac.tree.JCTree.JCExpression; +import com.sun.tools.javac.tree.JCTree.JCStatement; +import com.sun.tools.javac.util.List; +import com.sun.tools.javac.util.ListBuffer; +import com.sun.tools.javac.util.Name; + +@ProviderFor(JavacSingularizer.class) +public class JavacJavaUtilListSingularizer extends JavacJavaUtilListSetSingularizer { + @Override public LombokImmutableList<String> getSupportedTypes() { + return LombokImmutableList.of("java.util.List", "java.util.Collection", "java.lang.Iterable"); + } + + @Override public void appendBuildCode(SingularData data, JavacNode builderType, JCTree source, ListBuffer<JCStatement> statements, Name targetVariableName) { + if (useGuavaInstead(builderType)) { + guavaListSetSingularizer.appendBuildCode(data, builderType, source, statements, targetVariableName); + return; + } + + JavacTreeMaker maker = builderType.getTreeMaker(); + List<JCExpression> jceBlank = List.nil(); + ListBuffer<JCCase> cases = new ListBuffer<JCCase>(); + + /* case 0: (empty); break; */ { + JCStatement assignStat; { + // pluralName = java.util.Collections.emptyList(); + JCExpression invoke = maker.Apply(jceBlank, chainDots(builderType, "java", "util", "Collections", "emptyList"), jceBlank); + assignStat = maker.Exec(maker.Assign(maker.Ident(data.getPluralName()), invoke)); + } + JCStatement breakStat = maker.Break(null); + JCCase emptyCase = maker.Case(maker.Literal(CTC_INT, 0), List.of(assignStat, breakStat)); + cases.append(emptyCase); + } + + /* case 1: (singletonList); break; */ { + JCStatement assignStat; { + // pluralName = java.util.Collections.singletonList(this.pluralName.get(0)); + JCExpression zeroLiteral = maker.Literal(CTC_INT, 0); + JCExpression arg = maker.Apply(jceBlank, chainDots(builderType, "this", data.getPluralName().toString(), "get"), List.of(zeroLiteral)); + List<JCExpression> args = List.of(arg); + JCExpression invoke = maker.Apply(jceBlank, chainDots(builderType, "java", "util", "Collections", "singletonList"), args); + assignStat = maker.Exec(maker.Assign(maker.Ident(data.getPluralName()), invoke)); + } + JCStatement breakStat = maker.Break(null); + JCCase singletonCase = maker.Case(maker.Literal(CTC_INT, 1), List.of(assignStat, breakStat)); + cases.append(singletonCase); + } + + /* default: Create with right size, then addAll */ { + List<JCStatement> defStats = createListCopy(maker, data, builderType, source); + JCCase defaultCase = maker.Case(null, defStats); + cases.append(defaultCase); + } + + JCStatement switchStat = maker.Switch(getSize(maker, builderType, data.getPluralName(), true), cases.toList()); + JCExpression localShadowerType = chainDotsString(builderType, data.getTargetFqn()); + localShadowerType = addTypeArgs(1, false, builderType, localShadowerType, data.getTypeArgs(), source); + JCStatement varDefStat = maker.VarDef(maker.Modifiers(0), data.getPluralName(), localShadowerType, null); + statements.append(varDefStat); + statements.append(switchStat); + } + + private List<JCStatement> createListCopy(JavacTreeMaker maker, SingularData data, JavacNode builderType, JCTree source) { + List<JCExpression> jceBlank = List.nil(); + Name thisName = builderType.toName("this"); + + JCExpression argToUnmodifiable; { + // new java.util.ArrayList<Generics>(this.pluralName); + List<JCExpression> constructorArgs = List.nil(); + JCExpression thisDotPluralName = maker.Select(maker.Ident(thisName), data.getPluralName()); + constructorArgs = List.<JCExpression>of(thisDotPluralName); + JCExpression targetTypeExpr = chainDots(builderType, "java", "util", "ArrayList"); + targetTypeExpr = addTypeArgs(1, false, builderType, targetTypeExpr, data.getTypeArgs(), source); + argToUnmodifiable = maker.NewClass(null, jceBlank, targetTypeExpr, constructorArgs, null); + } + + JCStatement unmodifiableStat; { + // pluralname = Collections.unmodifiableInterfaceType(-newlist-); + JCExpression invoke = maker.Apply(jceBlank, chainDots(builderType, "java", "util", "Collections", "unmodifiableList"), List.of(argToUnmodifiable)); + unmodifiableStat = maker.Exec(maker.Assign(maker.Ident(data.getPluralName()), invoke)); + } + + return List.of(unmodifiableStat); + } +} diff --git a/src/core/lombok/javac/handlers/singulars/JavacJavaUtilMapSingularizer.java b/src/core/lombok/javac/handlers/singulars/JavacJavaUtilMapSingularizer.java new file mode 100644 index 00000000..ed91698d --- /dev/null +++ b/src/core/lombok/javac/handlers/singulars/JavacJavaUtilMapSingularizer.java @@ -0,0 +1,198 @@ +/* + * Copyright (C) 2015 The Project Lombok Authors. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +package lombok.javac.handlers.singulars; + +import static lombok.javac.Javac.*; +import static lombok.javac.handlers.JavacHandlerUtil.*; + +import java.util.Arrays; + +import lombok.core.LombokImmutableList; +import lombok.core.handlers.HandlerUtil; +import lombok.javac.JavacNode; +import lombok.javac.JavacTreeMaker; +import lombok.javac.handlers.JavacHandlerUtil; +import lombok.javac.handlers.JavacSingularsRecipes.JavacSingularizer; +import lombok.javac.handlers.JavacSingularsRecipes.SingularData; + +import org.mangosdk.spi.ProviderFor; + +import com.sun.tools.javac.code.Flags; +import com.sun.tools.javac.tree.JCTree; +import com.sun.tools.javac.tree.JCTree.JCBlock; +import com.sun.tools.javac.tree.JCTree.JCExpression; +import com.sun.tools.javac.tree.JCTree.JCMethodDecl; +import com.sun.tools.javac.tree.JCTree.JCModifiers; +import com.sun.tools.javac.tree.JCTree.JCStatement; +import com.sun.tools.javac.tree.JCTree.JCTypeParameter; +import com.sun.tools.javac.tree.JCTree.JCVariableDecl; +import com.sun.tools.javac.util.List; +import com.sun.tools.javac.util.ListBuffer; +import com.sun.tools.javac.util.Name; + +@ProviderFor(JavacSingularizer.class) +public class JavacJavaUtilMapSingularizer extends JavacJavaUtilSingularizer { + @Override public LombokImmutableList<String> getSupportedTypes() { + return LombokImmutableList.of("java.util.Map", "java.util.SortedMap", "java.util.NavigableMap"); + } + + @Override public java.util.List<Name> listFieldsToBeGenerated(SingularData data, JavacNode builderType) { + if (useGuavaInstead(builderType)) { + return guavaMapSingularizer.listFieldsToBeGenerated(data, builderType); + } + + String p = data.getPluralName().toString(); + return Arrays.asList(builderType.toName(p + "$key"), builderType.toName(p + "$value")); + } + + @Override public java.util.List<Name> listMethodsToBeGenerated(SingularData data, JavacNode builderType) { + if (useGuavaInstead(builderType)) { + return guavaMapSingularizer.listMethodsToBeGenerated(data, builderType); + } + + return super.listMethodsToBeGenerated(data, builderType); + } + + @Override public java.util.List<JavacNode> generateFields(SingularData data, JavacNode builderType, JCTree source) { + if (useGuavaInstead(builderType)) { + return guavaMapSingularizer.generateFields(data, builderType, source); + } + + JavacTreeMaker maker = builderType.getTreeMaker(); + + JCVariableDecl buildKeyField; { + JCExpression type = JavacHandlerUtil.chainDots(builderType, "java", "util", "ArrayList"); + type = addTypeArgs(1, false, builderType, type, data.getTypeArgs(), source); + buildKeyField = maker.VarDef(maker.Modifiers(Flags.PRIVATE), builderType.toName(data.getPluralName() + "$key"), type, null); + } + + JCVariableDecl buildValueField; { + JCExpression type = JavacHandlerUtil.chainDots(builderType, "java", "util", "ArrayList"); + List<JCExpression> tArgs = data.getTypeArgs(); + if (tArgs != null && tArgs.size() > 1) tArgs = tArgs.tail; + else tArgs = List.nil(); + type = addTypeArgs(1, false, builderType, type, tArgs, source); + buildValueField = maker.VarDef(maker.Modifiers(Flags.PRIVATE), builderType.toName(data.getPluralName() + "$value"), type, null); + } + + JavacNode valueFieldNode = injectField(builderType, buildValueField); + JavacNode keyFieldNode = injectField(builderType, buildKeyField); + + return Arrays.asList(keyFieldNode, valueFieldNode); + } + + @Override public void generateMethods(SingularData data, JavacNode builderType, JCTree source, boolean fluent, boolean chain) { + if (useGuavaInstead(builderType)) { + guavaMapSingularizer.generateMethods(data, builderType, source, fluent, chain); + return; + } + + JavacTreeMaker maker = builderType.getTreeMaker(); + + JCExpression returnType = chain ? cloneSelfType(builderType) : maker.Type(createVoidType(maker, CTC_VOID)); + JCStatement returnStatement = chain ? maker.Return(maker.Ident(builderType.toName("this"))) : null; + generateSingularMethod(maker, returnType, returnStatement, data, builderType, source, fluent); + + returnType = chain ? cloneSelfType(builderType) : maker.Type(createVoidType(maker, CTC_VOID)); + returnStatement = chain ? maker.Return(maker.Ident(builderType.toName("this"))) : null; + generatePluralMethod(maker, returnType, returnStatement, data, builderType, source, fluent); + } + + private void generateSingularMethod(JavacTreeMaker maker, JCExpression returnType, JCStatement returnStatement, SingularData data, JavacNode builderType, JCTree source, boolean fluent) { + List<JCTypeParameter> typeParams = List.nil(); + List<JCExpression> thrown = List.nil(); + JCModifiers mods = maker.Modifiers(Flags.PUBLIC); + ListBuffer<JCStatement> statements = new ListBuffer<JCStatement>(); + statements.append(createConstructBuilderVarIfNeeded(maker, data, builderType, true, source)); + Name keyName = builderType.toName(data.getSingularName().toString() + "Key"); + Name valueName = builderType.toName(data.getSingularName().toString() + "Value"); + /* this.pluralname$key.add(singularnameKey); */ { + JCExpression thisDotKeyFieldDotAdd = chainDots(builderType, "this", data.getPluralName() + "$key", "add"); + JCExpression invokeAdd = maker.Apply(List.<JCExpression>nil(), thisDotKeyFieldDotAdd, List.<JCExpression>of(maker.Ident(keyName))); + statements.append(maker.Exec(invokeAdd)); + } + /* this.pluralname$value.add(singularnameValue); */ { + JCExpression thisDotValueFieldDotAdd = chainDots(builderType, "this", data.getPluralName() + "$value", "add"); + JCExpression invokeAdd = maker.Apply(List.<JCExpression>nil(), thisDotValueFieldDotAdd, List.<JCExpression>of(maker.Ident(valueName))); + statements.append(maker.Exec(invokeAdd)); + } + if (returnStatement != null) statements.append(returnStatement); + JCBlock body = maker.Block(0, statements.toList()); + long paramFlags = JavacHandlerUtil.addFinalIfNeeded(Flags.PARAMETER, builderType.getContext()); + + Name name = data.getSingularName(); + if (!fluent) name = builderType.toName(HandlerUtil.buildAccessorName("put", name.toString())); + JCExpression paramTypeKey = cloneParamType(0, maker, data.getTypeArgs(), builderType, source); + JCExpression paramTypeValue = cloneParamType(1, maker, data.getTypeArgs(), builderType, source); + JCVariableDecl paramKey = maker.VarDef(maker.Modifiers(paramFlags), keyName, paramTypeKey, null); + JCVariableDecl paramValue = maker.VarDef(maker.Modifiers(paramFlags), valueName, paramTypeValue, null); + JCMethodDecl method = maker.MethodDef(mods, name, returnType, typeParams, List.of(paramKey, paramValue), thrown, body, null); + injectMethod(builderType, method); + } + + private void generatePluralMethod(JavacTreeMaker maker, JCExpression returnType, JCStatement returnStatement, SingularData data, JavacNode builderType, JCTree source, boolean fluent) { + List<JCTypeParameter> typeParams = List.nil(); + List<JCExpression> jceBlank = List.nil(); + JCModifiers mods = maker.Modifiers(Flags.PUBLIC); + ListBuffer<JCStatement> statements = new ListBuffer<JCStatement>(); + statements.append(createConstructBuilderVarIfNeeded(maker, data, builderType, true, source)); + long paramFlags = JavacHandlerUtil.addFinalIfNeeded(Flags.PARAMETER, builderType.getContext()); + long baseFlags = JavacHandlerUtil.addFinalIfNeeded(0, builderType.getContext()); + Name entryName = builderType.toName("$lombokEntry"); + + JCExpression forEachType = chainDots(builderType, "java", "util", "Map", "Entry"); + forEachType = addTypeArgs(2, true, builderType, forEachType, data.getTypeArgs(), source); + JCExpression keyArg = maker.Apply(List.<JCExpression>nil(), maker.Select(maker.Ident(entryName), builderType.toName("getKey")), List.<JCExpression>nil()); + JCExpression valueArg = maker.Apply(List.<JCExpression>nil(), maker.Select(maker.Ident(entryName), builderType.toName("getValue")), List.<JCExpression>nil()); + JCExpression addKey = maker.Apply(List.<JCExpression>nil(), chainDots(builderType, "this", data.getPluralName() + "$key", "add"), List.of(keyArg)); + JCExpression addValue = maker.Apply(List.<JCExpression>nil(), chainDots(builderType, "this", data.getPluralName() + "$value", "add"), List.of(valueArg)); + JCBlock forEachBody = maker.Block(0, List.<JCStatement>of(maker.Exec(addKey), maker.Exec(addValue))); + JCExpression entrySetInvocation = maker.Apply(jceBlank, maker.Select(maker.Ident(data.getPluralName()), builderType.toName("entrySet")), jceBlank); + JCStatement forEach = maker.ForeachLoop(maker.VarDef(maker.Modifiers(baseFlags), entryName, forEachType, null), entrySetInvocation, forEachBody); + statements.append(forEach); + + if (returnStatement != null) statements.append(returnStatement); + JCBlock body = maker.Block(0, statements.toList()); + Name name = data.getPluralName(); + if (!fluent) name = builderType.toName(HandlerUtil.buildAccessorName("putAll", name.toString())); + JCExpression paramType = chainDots(builderType, "java", "util", "Map"); + paramType = addTypeArgs(2, true, builderType, paramType, data.getTypeArgs(), source); + JCVariableDecl param = maker.VarDef(maker.Modifiers(paramFlags), data.getPluralName(), paramType, null); + JCMethodDecl method = maker.MethodDef(mods, name, returnType, typeParams, List.of(param), jceBlank, body, null); + injectMethod(builderType, method); + } + + @Override public void appendBuildCode(SingularData data, JavacNode builderType, JCTree source, ListBuffer<JCStatement> statements, Name targetVariableName) { + if (useGuavaInstead(builderType)) { + guavaMapSingularizer.appendBuildCode(data, builderType, source, statements, targetVariableName); + return; + } + + JavacTreeMaker maker = builderType.getTreeMaker(); + + if (data.getTargetFqn().equals("java.util.Map")) { + statements.appendList(createJavaUtilSetMapInitialCapacitySwitchStatements(maker, data, builderType, true, "emptyMap", "singletonMap", "LinkedHashMap", source)); + } else { + statements.appendList(createJavaUtilSimpleCreationAndFillStatements(maker, data, builderType, true, true, false, true, "TreeMap", source)); + } + } +} diff --git a/src/core/lombok/javac/handlers/singulars/JavacJavaUtilSetSingularizer.java b/src/core/lombok/javac/handlers/singulars/JavacJavaUtilSetSingularizer.java new file mode 100644 index 00000000..317233cb --- /dev/null +++ b/src/core/lombok/javac/handlers/singulars/JavacJavaUtilSetSingularizer.java @@ -0,0 +1,57 @@ +/* + * Copyright (C) 2015 The Project Lombok Authors. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +package lombok.javac.handlers.singulars; + +import org.mangosdk.spi.ProviderFor; + +import lombok.core.LombokImmutableList; +import lombok.javac.JavacNode; +import lombok.javac.JavacTreeMaker; +import lombok.javac.handlers.JavacSingularsRecipes.JavacSingularizer; +import lombok.javac.handlers.JavacSingularsRecipes.SingularData; + +import com.sun.tools.javac.tree.JCTree; +import com.sun.tools.javac.tree.JCTree.JCStatement; +import com.sun.tools.javac.util.ListBuffer; +import com.sun.tools.javac.util.Name; + +@ProviderFor(JavacSingularizer.class) +public class JavacJavaUtilSetSingularizer extends JavacJavaUtilListSetSingularizer { + @Override public LombokImmutableList<String> getSupportedTypes() { + return LombokImmutableList.of("java.util.Set", "java.util.SortedSet", "java.util.NavigableSet"); + } + + @Override public void appendBuildCode(SingularData data, JavacNode builderType, JCTree source, ListBuffer<JCStatement> statements, Name targetVariableName) { + if (useGuavaInstead(builderType)) { + guavaListSetSingularizer.appendBuildCode(data, builderType, source, statements, targetVariableName); + return; + } + + JavacTreeMaker maker = builderType.getTreeMaker(); + + if (data.getTargetFqn().equals("java.util.Set")) { + statements.appendList(createJavaUtilSetMapInitialCapacitySwitchStatements(maker, data, builderType, false, "emptySet", "singleton", "LinkedHashSet", source)); + } else { + statements.appendList(createJavaUtilSimpleCreationAndFillStatements(maker, data, builderType, false, true, false, true, "TreeSet", source)); + } + } +} diff --git a/src/core/lombok/javac/handlers/singulars/JavacJavaUtilSingularizer.java b/src/core/lombok/javac/handlers/singulars/JavacJavaUtilSingularizer.java new file mode 100644 index 00000000..f419a014 --- /dev/null +++ b/src/core/lombok/javac/handlers/singulars/JavacJavaUtilSingularizer.java @@ -0,0 +1,193 @@ +/* + * Copyright (C) 2015 The Project Lombok Authors. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +package lombok.javac.handlers.singulars; + +import static lombok.javac.Javac.*; +import static lombok.javac.handlers.JavacHandlerUtil.*; + +import com.sun.tools.javac.tree.JCTree; +import com.sun.tools.javac.tree.JCTree.JCCase; +import com.sun.tools.javac.tree.JCTree.JCExpression; +import com.sun.tools.javac.tree.JCTree.JCStatement; +import com.sun.tools.javac.util.List; +import com.sun.tools.javac.util.ListBuffer; +import com.sun.tools.javac.util.Name; + +import lombok.ConfigurationKeys; +import lombok.javac.JavacNode; +import lombok.javac.JavacTreeMaker; +import lombok.javac.handlers.JavacSingularsRecipes.JavacSingularizer; +import lombok.javac.handlers.JavacSingularsRecipes.SingularData; + +abstract class JavacJavaUtilSingularizer extends JavacSingularizer { + protected final JavacSingularizer guavaListSetSingularizer = new JavacGuavaSetListSingularizer(); + protected final JavacSingularizer guavaMapSingularizer = new JavacGuavaMapSingularizer(); + + protected boolean useGuavaInstead(JavacNode node) { + return Boolean.TRUE.equals(node.getAst().readConfiguration(ConfigurationKeys.SINGULAR_USE_GUAVA)); + } + + protected List<JCStatement> createJavaUtilSetMapInitialCapacitySwitchStatements(JavacTreeMaker maker, SingularData data, JavacNode builderType, boolean mapMode, String emptyCollectionMethod, String singletonCollectionMethod, String targetType, JCTree source) { + List<JCExpression> jceBlank = List.nil(); + ListBuffer<JCCase> cases = new ListBuffer<JCCase>(); + + if (emptyCollectionMethod != null) { // case 0: (empty); break; + JCStatement assignStat; { + // pluralName = java.util.Collections.emptyCollectionMethod(); + JCExpression invoke = maker.Apply(jceBlank, chainDots(builderType, "java", "util", "Collections", emptyCollectionMethod), jceBlank); + assignStat = maker.Exec(maker.Assign(maker.Ident(data.getPluralName()), invoke)); + } + JCStatement breakStat = maker.Break(null); + JCCase emptyCase = maker.Case(maker.Literal(CTC_INT, 0), List.of(assignStat, breakStat)); + cases.append(emptyCase); + } + + if (singletonCollectionMethod != null) { // case 1: (singleton); break; + JCStatement assignStat; { + // !mapMode: pluralName = java.util.Collections.singletonCollectionMethod(this.pluralName.get(0)); + // mapMode: pluralName = java.util.Collections.singletonCollectionMethod(this.pluralName$key.get(0), this.pluralName$value.get(0)); + JCExpression zeroLiteral = maker.Literal(CTC_INT, 0); + JCExpression arg = maker.Apply(jceBlank, chainDots(builderType, "this", data.getPluralName() + (mapMode ? "$key" : ""), "get"), List.of(zeroLiteral)); + List<JCExpression> args; + if (mapMode) { + JCExpression zeroLiteralClone = maker.Literal(CTC_INT, 0); + JCExpression arg2 = maker.Apply(jceBlank, chainDots(builderType, "this", data.getPluralName() + (mapMode ? "$value" : ""), "get"), List.of(zeroLiteralClone)); + args = List.of(arg, arg2); + } else { + args = List.of(arg); + } + JCExpression invoke = maker.Apply(jceBlank, chainDots(builderType, "java", "util", "Collections", singletonCollectionMethod), args); + assignStat = maker.Exec(maker.Assign(maker.Ident(data.getPluralName()), invoke)); + } + JCStatement breakStat = maker.Break(null); + JCCase singletonCase = maker.Case(maker.Literal(CTC_INT, 1), List.of(assignStat, breakStat)); + cases.append(singletonCase); + } + + { // default: + List<JCStatement> statements = createJavaUtilSimpleCreationAndFillStatements(maker, data, builderType, mapMode, false, true, emptyCollectionMethod == null, targetType, source); + JCCase defaultCase = maker.Case(null, statements); + cases.append(defaultCase); + } + + JCStatement switchStat = maker.Switch(getSize(maker, builderType, mapMode ? builderType.toName(data.getPluralName() + "$key") : data.getPluralName(), true), cases.toList()); + JCExpression localShadowerType = chainDotsString(builderType, data.getTargetFqn()); + localShadowerType = addTypeArgs(mapMode ? 2 : 1, false, builderType, localShadowerType, data.getTypeArgs(), source); + JCStatement varDefStat = maker.VarDef(maker.Modifiers(0), data.getPluralName(), localShadowerType, null); + return List.of(varDefStat, switchStat); + } + + protected JCStatement createConstructBuilderVarIfNeeded(JavacTreeMaker maker, SingularData data, JavacNode builderType, boolean mapMode, JCTree source) { + List<JCExpression> jceBlank = List.nil(); + + Name v1Name = mapMode ? builderType.toName(data.getPluralName() + "$key") : data.getPluralName(); + Name v2Name = mapMode ? builderType.toName(data.getPluralName() + "$value") : null; + JCExpression thisDotField = maker.Select(maker.Ident(builderType.toName("this")), v1Name); + JCExpression cond = maker.Binary(CTC_EQUAL, thisDotField, maker.Literal(CTC_BOT, null)); + thisDotField = maker.Select(maker.Ident(builderType.toName("this")), v1Name); + JCExpression v1Type = chainDots(builderType, "java", "util", "ArrayList"); + v1Type = addTypeArgs(1, false, builderType, v1Type, data.getTypeArgs(), source); + JCExpression constructArrayList = maker.NewClass(null, jceBlank, v1Type, jceBlank, null); + JCStatement initV1 = maker.Exec(maker.Assign(thisDotField, constructArrayList)); + JCStatement thenPart; + if (mapMode) { + thisDotField = maker.Select(maker.Ident(builderType.toName("this")), v2Name); + JCExpression v2Type = chainDots(builderType, "java", "util", "ArrayList"); + List<JCExpression> tArgs = data.getTypeArgs(); + if (tArgs != null && tArgs.tail != null) tArgs = tArgs.tail; + else tArgs = List.nil(); + v2Type = addTypeArgs(1, false, builderType, v2Type, tArgs, source); + constructArrayList = maker.NewClass(null, jceBlank, v2Type, jceBlank, null); + JCStatement initV2 = maker.Exec(maker.Assign(thisDotField, constructArrayList)); + thenPart = maker.Block(0, List.of(initV1, initV2)); + } else { + thenPart = initV1; + } + return maker.If(cond, thenPart, null); + } + + protected List<JCStatement> createJavaUtilSimpleCreationAndFillStatements(JavacTreeMaker maker, SingularData data, JavacNode builderType, boolean mapMode, boolean defineVar, boolean addInitialCapacityArg, boolean nullGuard, String targetType, JCTree source) { + List<JCExpression> jceBlank = List.nil(); + Name thisName = builderType.toName("this"); + + JCStatement createStat; { + // pluralName = new java.util.TargetType(initialCap); + List<JCExpression> constructorArgs = List.nil(); + if (addInitialCapacityArg) { + Name varName = mapMode ? builderType.toName(data.getPluralName() + "$key") : data.getPluralName(); + // this.varName.size() < MAX_POWER_OF_2 ? 1 + this.varName.size() + (this.varName.size() - 3) / 3 : Integer.MAX_VALUE; + // lessThanCutOff = this.varName.size() < MAX_POWER_OF_2 + JCExpression lessThanCutoff = maker.Binary(CTC_LESS_THAN, getSize(maker, builderType, varName, nullGuard), maker.Literal(CTC_INT, 0x40000000)); + JCExpression integerMaxValue = genJavaLangTypeRef(builderType, "Integer", "MAX_VALUE"); + JCExpression sizeFormulaLeft = maker.Binary(CTC_PLUS, maker.Literal(CTC_INT, 1), getSize(maker, builderType, varName, nullGuard)); + JCExpression sizeFormulaRightLeft = maker.Binary(CTC_MINUS, getSize(maker, builderType, varName, nullGuard), maker.Literal(CTC_INT, 3)); + JCExpression sizeFormulaRight = maker.Binary(CTC_DIV, sizeFormulaRightLeft, maker.Literal(CTC_INT, 3)); + JCExpression sizeFormula = maker.Binary(CTC_PLUS, sizeFormulaLeft, sizeFormulaRight); + constructorArgs = List.<JCExpression>of(maker.Conditional(lessThanCutoff, sizeFormula, integerMaxValue)); + } + + JCExpression targetTypeExpr = chainDots(builderType, "java", "util", targetType); + targetTypeExpr = addTypeArgs(mapMode ? 2 : 1, false, builderType, targetTypeExpr, data.getTypeArgs(), source); + JCExpression constructorCall = maker.NewClass(null, jceBlank, targetTypeExpr, constructorArgs, null); + if (defineVar) { + JCExpression localShadowerType = chainDotsString(builderType, data.getTargetFqn()); + localShadowerType = addTypeArgs(mapMode ? 2 : 1, false, builderType, localShadowerType, data.getTypeArgs(), source); + createStat = maker.VarDef(maker.Modifiers(0), data.getPluralName(), localShadowerType, constructorCall); + } else { + createStat = maker.Exec(maker.Assign(maker.Ident(data.getPluralName()), constructorCall)); + } + } + + JCStatement fillStat; { + if (mapMode) { + // for (int $i = 0; $i < this.pluralname$key.size(); i++) pluralname.put(this.pluralname$key.get($i), this.pluralname$value.get($i)); + Name ivar = builderType.toName("$i"); + Name keyVarName = builderType.toName(data.getPluralName() + "$key"); + JCExpression pluralnameDotPut = maker.Select(maker.Ident(data.getPluralName()), builderType.toName("put")); + JCExpression arg1 = maker.Apply(jceBlank, chainDots(builderType, "this", data.getPluralName() + "$key", "get"), List.<JCExpression>of(maker.Ident(ivar))); + JCExpression arg2 = maker.Apply(jceBlank, chainDots(builderType, "this", data.getPluralName() + "$value", "get"), List.<JCExpression>of(maker.Ident(ivar))); + JCStatement putStatement = maker.Exec(maker.Apply(jceBlank, pluralnameDotPut, List.of(arg1, arg2))); + JCStatement forInit = maker.VarDef(maker.Modifiers(0), ivar, maker.TypeIdent(CTC_INT), maker.Literal(CTC_INT, 0)); + JCExpression checkExpr = maker.Binary(CTC_LESS_THAN, maker.Ident(ivar), getSize(maker, builderType, keyVarName, nullGuard)); + JCExpression incrementExpr = maker.Unary(CTC_POSTINC, maker.Ident(ivar)); + fillStat = maker.ForLoop(List.of(forInit), checkExpr, List.of(maker.Exec(incrementExpr)), putStatement); + } else { + // pluralname.addAll(this.pluralname); + JCExpression thisDotPluralName = maker.Select(maker.Ident(thisName), data.getPluralName()); + fillStat = maker.Exec(maker.Apply(jceBlank, maker.Select(maker.Ident(data.getPluralName()), builderType.toName("addAll")), List.of(thisDotPluralName))); + } + if (nullGuard) { + JCExpression thisDotField = maker.Select(maker.Ident(thisName), mapMode ? builderType.toName(data.getPluralName() + "$key") : data.getPluralName()); + JCExpression nullCheck = maker.Binary(CTC_NOT_EQUAL, thisDotField, maker.Literal(CTC_BOT, null)); + fillStat = maker.If(nullCheck, fillStat, null); + } + } + JCStatement unmodifiableStat; { + // pluralname = Collections.unmodifiableInterfaceType(pluralname); + JCExpression arg = maker.Ident(data.getPluralName()); + JCExpression invoke = maker.Apply(jceBlank, chainDots(builderType, "java", "util", "Collections", "unmodifiable" + data.getTargetSimpleType()), List.of(arg)); + unmodifiableStat = maker.Exec(maker.Assign(maker.Ident(data.getPluralName()), invoke)); + } + + return List.of(createStat, fillStat, unmodifiableStat); + } +} diff --git a/src/delombok/lombok/delombok/Delombok.java b/src/delombok/lombok/delombok/Delombok.java index f64e36a1..514fc2ec 100644 --- a/src/delombok/lombok/delombok/Delombok.java +++ b/src/delombok/lombok/delombok/Delombok.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2009-2010 The Project Lombok Authors. + * Copyright (C) 2009-2015 The Project Lombok Authors. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -204,7 +204,7 @@ public class Delombok { System.out.println(indentAndWordbreak(e.getValue(), 4, 70)); } System.out.println("Example: -f indent:4 -f emptyLines:indent"); - System.out.println("The '-f pretty' option is shorthand for '-f suppressWarnings:skip -f danceAroundIdeChecks:skip -f generateDelombokComment:skip -f javaLangAsFQN:skip'"); + System.out.println("The '-f pretty' option is shorthand for '-f suppressWarnings:skip -f generated:skip -f danceAroundIdeChecks:skip -f generateDelombokComment:skip -f javaLangAsFQN:skip'"); System.exit(0); return; } @@ -301,6 +301,7 @@ public class Delombok { if (prettyEnabled) { if (!formatPrefs.containsKey("suppresswarnings")) formatPrefs.put("suppresswarnings", "skip"); + if (!formatPrefs.containsKey("generated")) formatPrefs.put("generated", "skip"); if (!formatPrefs.containsKey("dancearoundidechecks")) formatPrefs.put("dancearoundidechecks", "skip"); if (!formatPrefs.containsKey("generatedelombokcomment")) formatPrefs.put("generatedelombokcomment", "skip"); if (!formatPrefs.containsKey("javalangasfqn")) formatPrefs.put("javalangasfqn", "skip"); @@ -509,7 +510,7 @@ public class Delombok { DelombokResult result = new DelombokResult(catcher.getComments(unit), unit, force || options.isChanged(unit), fps); if (verbose) feedback.printf("File: %s [%s]\n", unit.sourcefile.getName(), result.isChanged() ? "delomboked" : "unchanged"); Writer rawWriter; - if (presetWriter != null) rawWriter = presetWriter; + if (presetWriter != null) rawWriter = createUnicodeEscapeWriter(presetWriter); else if (output == null) rawWriter = createStandardOutWriter(); else rawWriter = createFileWriter(output, baseMap.get(unit), unit.sourcefile.toUri()); BufferedWriter writer = new BufferedWriter(rawWriter); @@ -605,6 +606,10 @@ public class Delombok { return createUnicodeEscapeWriter(System.out); } + private Writer createUnicodeEscapeWriter(Writer writer) { + return new UnicodeEscapeWriter(writer, charset); + } + private Writer createUnicodeEscapeWriter(OutputStream out) { return new UnicodeEscapeWriter(new OutputStreamWriter(out, charset), charset); } diff --git a/src/delombok/lombok/delombok/FormatPreferences.java b/src/delombok/lombok/delombok/FormatPreferences.java index 9bd668a5..5ba3b8cd 100644 --- a/src/delombok/lombok/delombok/FormatPreferences.java +++ b/src/delombok/lombok/delombok/FormatPreferences.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2013 The Project Lombok Authors. + * Copyright (C) 2013-2015 The Project Lombok Authors. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -33,6 +33,7 @@ public final class FormatPreferences { private final boolean generateConstructorProperties; private final boolean generateSuppressWarnings, danceAroundIdeChecks, generateDelombokComment, javaLangAsFqn; final Map<String, String> rawMap; + private final boolean generateGenerated; static final Map<String, String> KEYS; @@ -42,7 +43,8 @@ public final class FormatPreferences { keys.put("emptyLines", "Either 'indent' or 'blank'. indent means: Indent an empty line to the right level. Default: 'blank'"); keys.put("finalParams", "Either 'generate' or 'skip'. generate means: All lombok-generated methods set all parameters to final. Default: 'generate'"); keys.put("constructorProperties", "Either 'generate' or 'skip'. generate means: All lombok-generated constructors with 1 or more arguments get an @ConstructorProperties annotation. Default: 'generate'"); - keys.put("suppressWarnings", "Either 'generate' or 'skip'. generate means: All lombok-generated methods get a @SuppressWarnings annotation. Default: 'generate'"); + keys.put("suppressWarnings", "Either 'generate' or 'skip'. generate means: All lombok-generated methods, types, and fields get a @SuppressWarnings annotation. Default: 'generate'"); + keys.put("generated", "Either 'generate' or 'skip'. generate means: All lombok-generated methods, types, and fields get a @Generated(\"lombok\") annotation. Default: 'generate'"); keys.put("danceAroundIdeChecks", "Either 'generate' or 'skip'. generate means: Lombok will intentionally obfuscate some generated code to avoid IDE warnings. Default: 'generate'"); keys.put("generateDelombokComment", "Either 'generate' or 'skip'. generate means: Any file modified by delombok will have a comment stating this at the top. Default: 'generate'"); keys.put("javaLangAsFQN", "Either 'generate' or 'skip'. generate means: Any generated reference to java.lang classes are prefixed with `java.lang.`. Default: 'generate'"); @@ -82,6 +84,7 @@ public final class FormatPreferences { this.generateFinalParams = unrollBoolean(preferences, "finalParams", "generate", "skip", true); this.generateConstructorProperties = unrollBoolean(preferences, "constructorProperties", "generate", "skip", true); this.generateSuppressWarnings = unrollBoolean(preferences, "suppressWarnings", "generate", "skip", true); + this.generateGenerated = unrollBoolean(preferences, "generated", "generate", "skip", true); this.danceAroundIdeChecks = unrollBoolean(preferences, "danceAroundIdeChecks", "generate", "skip", true); this.generateDelombokComment = unrollBoolean(preferences, "generateDelombokComment", "generate", "skip", true); this.javaLangAsFqn = unrollBoolean(preferences, "javaLangAsFQN", "generate", "skip", true); @@ -112,6 +115,10 @@ public final class FormatPreferences { return generateSuppressWarnings; } + public boolean generateGenerated() { + return generateGenerated; + } + public boolean generateFinalParams() { return generateFinalParams; } @@ -131,4 +138,8 @@ public final class FormatPreferences { public boolean generateConstructorProperties() { return generateConstructorProperties; } + + @Override public String toString() { + return rawMap.toString(); + } } diff --git a/src/delombok/lombok/delombok/PrettyCommentsPrinter.java b/src/delombok/lombok/delombok/PrettyCommentsPrinter.java index 9dd7e40e..72a8ff59 100644 --- a/src/delombok/lombok/delombok/PrettyCommentsPrinter.java +++ b/src/delombok/lombok/delombok/PrettyCommentsPrinter.java @@ -104,7 +104,6 @@ import com.sun.tools.javac.tree.JCTree.LetExpr; import com.sun.tools.javac.tree.JCTree.TypeBoundKind; import com.sun.tools.javac.tree.TreeInfo; import com.sun.tools.javac.tree.TreeScanner; -import com.sun.tools.javac.util.Convert; import com.sun.tools.javac.util.List; import com.sun.tools.javac.util.Name; import com.sun.tools.javac.util.Position; @@ -209,7 +208,6 @@ public class PrettyCommentsPrinter extends JCTree.Visitor { private void consumeComments(int until, JCTree tree) throws IOException { boolean prevNewLine = onNewLine; - boolean found = false; CommentInfo head = comments.head; while (comments.nonEmpty() && head.pos < until) { printComment(head); @@ -355,7 +353,7 @@ public class PrettyCommentsPrinter extends JCTree.Visitor { } needsSpace = false; - out.write(Convert.escapeUnicode(s.toString())); + out.write(s.toString()); onNewLine = false; aligned = false; @@ -1413,16 +1411,51 @@ public class PrettyCommentsPrinter extends JCTree.Visitor { else if (CTC_FLOAT.equals(typeTag)) print(tree.value + "F"); else if (CTC_DOUBLE.equals(typeTag)) print(tree.value.toString()); else if (CTC_CHAR.equals(typeTag)) { - print("\'" + Convert.quote(String.valueOf((char)((Number)tree.value).intValue())) + "\'"); + print("\'" + quoteChar((char)((Number)tree.value).intValue()) + "\'"); } else if (CTC_BOOLEAN.equals(typeTag)) print(((Number)tree.value).intValue() == 1 ? "true" : "false"); else if (CTC_BOT.equals(typeTag)) print("null"); - else print("\"" + Convert.quote(tree.value.toString()) + "\""); + else print("\"" + quoteChars(tree.value.toString()) + "\""); } catch (IOException e) { throw new UncheckedIOException(e); } } + public static String quoteChars(String s) { + StringBuilder buf = new StringBuilder(); + for (int i = 0; i < s.length(); i++) { + buf.append(quoteChar(s.charAt(i))); + } + return buf.toString(); + } + + /** + * Escapes a character if it has an escape sequence or is non-printable + * ASCII. Leaves non-ASCII characters alone. + */ + public static String quoteChar(char ch) { + switch (ch) { + case '\b': + return "\\b"; + case '\f': + return "\\f"; + case '\n': + return "\\n"; + case '\r': + return "\\r"; + case '\t': + return "\\t"; + case '\'': + return "\\'"; + case '\"': + return "\\\""; + case '\\': + return "\\\\"; + default: + return ch < 32 ? String.format("\\%03o", (int) ch) : String.valueOf(ch); + } + } + public void visitTypeIdent(JCPrimitiveTypeTree tree) { TypeTag typetag = typeTag(tree); try { diff --git a/src/delombok/lombok/delombok/UnicodeEscapeWriter.java b/src/delombok/lombok/delombok/UnicodeEscapeWriter.java index 95b55078..9c2ef190 100644 --- a/src/delombok/lombok/delombok/UnicodeEscapeWriter.java +++ b/src/delombok/lombok/delombok/UnicodeEscapeWriter.java @@ -63,6 +63,6 @@ public class UnicodeEscapeWriter extends Writer { } protected void writeUnicodeEscape(char c) throws IOException { - writer.write("\\u" + Integer.toHexString(c)); + writer.write(String.format("\\u%04x", (int) c)); } }
\ No newline at end of file diff --git a/src/delombok/lombok/delombok/ant/DelombokTask.java b/src/delombok/lombok/delombok/ant/DelombokTask.java index d5c17fe7..06bbe3e0 100644 --- a/src/delombok/lombok/delombok/ant/DelombokTask.java +++ b/src/delombok/lombok/delombok/ant/DelombokTask.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2009 The Project Lombok Authors. + * Copyright (C) 2009-2015 The Project Lombok Authors. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -22,142 +22,189 @@ package lombok.delombok.ant; import java.io.File; -import java.io.IOException; -import java.nio.charset.UnsupportedCharsetException; +import java.lang.reflect.Field; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.lang.reflect.Modifier; import java.util.ArrayList; -import java.util.Iterator; import java.util.List; -import lombok.delombok.Delombok; -import lombok.delombok.Delombok.InvalidFormatOptionException; +import lombok.Lombok; import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.Location; import org.apache.tools.ant.Task; import org.apache.tools.ant.types.FileSet; import org.apache.tools.ant.types.Path; import org.apache.tools.ant.types.Reference; -import org.apache.tools.ant.types.resources.FileResource; -public class DelombokTask extends Task { - private File fromDir, toDir; - private Path classpath; - private Path sourcepath; - private boolean verbose; - private String encoding; - private Path path; - private List<Format> formatOptions = new ArrayList<Format>(); - - public void setClasspath(Path classpath) { - if (this.classpath == null) { - this.classpath = classpath; - } else { - this.classpath.append(classpath); +@SuppressWarnings("unused") // we use reflection to transfer fields. +class Tasks { + public static class Format { + private String value; + + @Override public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((value == null) ? 0 : value.hashCode()); + return result; } - } - - public Path createClasspath() { - if (classpath == null) { - classpath = new Path(getProject()); + + @Override public boolean equals(Object obj) { + if (this == obj) return true; + if (obj == null) return false; + if (getClass() != obj.getClass()) return false; + Format other = (Format) obj; + if (value == null) { + if (other.value != null) return false; + } else if (!value.equals(other.value)) return false; + return true; } - return classpath.createPath(); - } - - public void setClasspathRef(Reference r) { - createClasspath().setRefid(r); - } - - public void setSourcepath(Path sourcepath) { - if (this.sourcepath == null) { - this.sourcepath = sourcepath; - } else { - this.sourcepath.append(sourcepath); + + @Override public String toString() { + return "FormatOption [value=" + value + "]"; } - } - - public Path createSourcepath() { - if (sourcepath == null) { - sourcepath = new Path(getProject()); + + public String getValue() { + return value; + } + + public void setValue(String value) { + this.value = value; } - return sourcepath.createPath(); - } - - public void setSourcepathRef(Reference r) { - createSourcepath().setRefid(r); - } - - public void setFrom(File dir) { - this.fromDir = dir; - } - - public void setTo(File dir) { - this.toDir = dir; - } - - public void setVerbose(boolean verbose) { - this.verbose = verbose; - } - - public void setEncoding(String encoding) { - this.encoding = encoding; - } - - public void addFileset(FileSet set) { - if (path == null) path = new Path(getProject()); - path.add(set); - } - - public void addFormat(Format format) { - formatOptions.add(format); } - @Override - public void execute() throws BuildException { - if (fromDir == null && path == null) throw new BuildException("Either 'from' attribute, or nested <fileset> tags are required."); - if (fromDir != null && path != null) throw new BuildException("You can't specify both 'from' attribute and nested filesets. You need one or the other."); - if (toDir == null) throw new BuildException("The to attribute is required."); - - Delombok delombok = new Delombok(); - if (verbose) delombok.setVerbose(true); - try { - if (encoding != null) delombok.setCharset(encoding); - } catch (UnsupportedCharsetException e) { - throw new BuildException("Unknown charset: " + encoding, getLocation()); - } - - if (classpath != null) delombok.setClasspath(classpath.toString()); - if (sourcepath != null) delombok.setSourcepath(sourcepath.toString()); - - try { - List<String> fo = new ArrayList<String>(); - for (Format f : formatOptions) { - String v = f.getValue(); - if (v == null) throw new BuildException("'value' property required for <format>"); - fo.add(v); + public static class Delombok extends Task { + private File fromDir, toDir; + private Path classpath; + private Path sourcepath; + private boolean verbose; + private String encoding; + private Path path; + private List<Format> formatOptions = new ArrayList<Format>(); + + public void setClasspath(Path classpath) { + if (this.classpath == null) { + this.classpath = classpath; + } else { + this.classpath.append(classpath); + } + } + + public Path createClasspath() { + if (classpath == null) { + classpath = new Path(getProject()); } - delombok.setFormatPreferences(Delombok.formatOptionsToMap(fo)); - } catch (InvalidFormatOptionException e) { - throw new BuildException(e.getMessage() + " Run java -jar lombok.jar --format-help for detailed format help."); - } - - delombok.setOutput(toDir); - try { - if (fromDir != null) delombok.addDirectory(fromDir); - else { - Iterator<?> it = path.iterator(); - while (it.hasNext()) { - FileResource fileResource = (FileResource) it.next(); - File baseDir = fileResource.getBaseDir(); - if (baseDir == null) { - File file = fileResource.getFile(); - delombok.addFile(file.getParentFile(), file.getName()); + return classpath.createPath(); + } + + public void setClasspathRef(Reference r) { + createClasspath().setRefid(r); + } + + public void setSourcepath(Path sourcepath) { + if (this.sourcepath == null) { + this.sourcepath = sourcepath; + } else { + this.sourcepath.append(sourcepath); + } + } + + public Path createSourcepath() { + if (sourcepath == null) { + sourcepath = new Path(getProject()); + } + return sourcepath.createPath(); + } + + public void setSourcepathRef(Reference r) { + createSourcepath().setRefid(r); + } + + public void setFrom(File dir) { + this.fromDir = dir; + } + + public void setTo(File dir) { + this.toDir = dir; + } + + public void setVerbose(boolean verbose) { + this.verbose = verbose; + } + + public void setEncoding(String encoding) { + this.encoding = encoding; + } + + public void addFileset(FileSet set) { + if (path == null) path = new Path(getProject()); + path.add(set); + } + + public Format createFormat() { + return new Format(); + } + + public void addFormat(Format format) { + formatOptions.add(format); + } + + private static ClassLoader shadowLoader; + + public static Class<?> shadowLoadClass(String name) { + try { + if (shadowLoader == null) { + try { + Class.forName("lombok.core.LombokNode"); + // If we get here, then lombok is already available. + shadowLoader = Delombok.class.getClassLoader(); + } catch (ClassNotFoundException e) { + // If we get here, it isn't, and we should use the shadowloader. + Class<?> launcherMain = Class.forName("lombok.launch.Main"); + Method m = launcherMain.getDeclaredMethod("createShadowClassLoader"); + m.setAccessible(true); + shadowLoader = (ClassLoader) m.invoke(null); + } + } + + return Class.forName(name, true, shadowLoader); + } catch (Exception e) { + throw Lombok.sneakyThrow(e); + } + } + + @Override + public void execute() throws BuildException { + Location loc = getLocation(); + + try { + Object instance = shadowLoadClass("lombok.delombok.ant.DelombokTaskImpl").newInstance(); + for(Field selfField : getClass().getDeclaredFields()) { + if (selfField.isSynthetic() || Modifier.isStatic(selfField.getModifiers())) continue; + Field otherField = instance.getClass().getDeclaredField(selfField.getName()); + otherField.setAccessible(true); + selfField.setAccessible(true); + if (selfField.getName().equals("formatOptions")) { + List<String> rep = new ArrayList<String>(); + for (Format f : formatOptions) { + if (f.getValue() == null) throw new BuildException("'value' property required for <format>"); + rep.add(f.getValue()); + } + otherField.set(instance, rep); } else { - delombok.addFile(baseDir, fileResource.getName()); + otherField.set(instance, selfField.get(this)); } } + + Method m = instance.getClass().getMethod("execute", Location.class); + m.setAccessible(true); + m.invoke(instance, loc); + } catch (InvocationTargetException e) { + throw Lombok.sneakyThrow(e.getCause()); + } catch (Exception e) { + throw Lombok.sneakyThrow(e); } - delombok.delombok(); - } catch (IOException e) { - throw new BuildException("I/O problem during delombok", e, getLocation()); } } } diff --git a/src/delombok/lombok/delombok/ant/DelombokTaskImpl.java b/src/delombok/lombok/delombok/ant/DelombokTaskImpl.java new file mode 100644 index 00000000..470819cd --- /dev/null +++ b/src/delombok/lombok/delombok/ant/DelombokTaskImpl.java @@ -0,0 +1,91 @@ +/* + * Copyright (C) 2009-2015 The Project Lombok Authors. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +package lombok.delombok.ant; + +import java.io.File; +import java.io.IOException; +import java.nio.charset.UnsupportedCharsetException; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +import lombok.delombok.Delombok; +import lombok.delombok.Delombok.InvalidFormatOptionException; + +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.Location; +import org.apache.tools.ant.types.Path; +import org.apache.tools.ant.types.resources.FileResource; + +public class DelombokTaskImpl { + private File fromDir, toDir; + private Path classpath; + private Path sourcepath; + private boolean verbose; + private String encoding; + private Path path; + private List<String> formatOptions = new ArrayList<String>(); + + public void execute(Location location) throws BuildException { + if (fromDir == null && path == null) throw new BuildException("Either 'from' attribute, or nested <fileset> tags are required."); + if (fromDir != null && path != null) throw new BuildException("You can't specify both 'from' attribute and nested filesets. You need one or the other."); + if (toDir == null) throw new BuildException("The to attribute is required."); + + Delombok delombok = new Delombok(); + if (verbose) delombok.setVerbose(true); + try { + if (encoding != null) delombok.setCharset(encoding); + } catch (UnsupportedCharsetException e) { + throw new BuildException("Unknown charset: " + encoding, location); + } + + if (classpath != null) delombok.setClasspath(classpath.toString()); + if (sourcepath != null) delombok.setSourcepath(sourcepath.toString()); + + try { + delombok.setFormatPreferences(Delombok.formatOptionsToMap(formatOptions)); + } catch (InvalidFormatOptionException e) { + throw new BuildException(e.getMessage() + " Run java -jar lombok.jar --format-help for detailed format help."); + } + + delombok.setOutput(toDir); + try { + if (fromDir != null) delombok.addDirectory(fromDir); + else { + Iterator<?> it = path.iterator(); + while (it.hasNext()) { + FileResource fileResource = (FileResource) it.next(); + File baseDir = fileResource.getBaseDir(); + if (baseDir == null) { + File file = fileResource.getFile(); + delombok.addFile(file.getParentFile(), file.getName()); + } else { + delombok.addFile(baseDir, fileResource.getName()); + } + } + } + delombok.delombok(); + } catch (IOException e) { + throw new BuildException("I/O problem during delombok", e, location); + } + } +} diff --git a/src/delombok/lombok/delombok/ant/Format.java b/src/delombok/lombok/delombok/ant/Format.java deleted file mode 100644 index bb2b5e87..00000000 --- a/src/delombok/lombok/delombok/ant/Format.java +++ /dev/null @@ -1,35 +0,0 @@ -package lombok.delombok.ant; - -public class Format { - private String value; - - @Override public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + ((value == null) ? 0 : value.hashCode()); - return result; - } - - @Override public boolean equals(Object obj) { - if (this == obj) return true; - if (obj == null) return false; - if (getClass() != obj.getClass()) return false; - Format other = (Format) obj; - if (value == null) { - if (other.value != null) return false; - } else if (!value.equals(other.value)) return false; - return true; - } - - @Override public String toString() { - return "FormatOption [value=" + value + "]"; - } - - public String getValue() { - return value; - } - - public void setValue(String value) { - this.value = value; - } -} diff --git a/src/eclipseAgent/lombok/eclipse/agent/EclipsePatcher.java b/src/eclipseAgent/lombok/eclipse/agent/EclipsePatcher.java index 96f253f2..efc7ce94 100644 --- a/src/eclipseAgent/lombok/eclipse/agent/EclipsePatcher.java +++ b/src/eclipseAgent/lombok/eclipse/agent/EclipsePatcher.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2009-2012 The Project Lombok Authors. + * Copyright (C) 2009-2015 The Project Lombok Authors. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -76,9 +76,6 @@ public class EclipsePatcher implements AgentLauncher.AgentLaunchable { sm.registerTransformer(instrumentation); if (!ecjOnly) { EclipseLoaderPatcher.patchEquinoxLoaders(sm, launchingContext); - } - - if (!ecjOnly) { patchCatchReparse(sm); patchIdentifierEndReparse(sm); patchRetrieveEllipsisStartPosition(sm); @@ -112,7 +109,7 @@ public class EclipsePatcher implements AgentLauncher.AgentLaunchable { sm.addScript(ScriptBuilder.wrapMethodCall() .target(new MethodTarget("org.eclipse.jdt.internal.compiler.SourceElementNotifier", "notifySourceElementRequestor", "void", "org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration", "org.eclipse.jdt.internal.compiler.ast.TypeDeclaration", "org.eclipse.jdt.internal.compiler.ast.ImportReference")) .methodToWrap(new Hook("org.eclipse.jdt.internal.compiler.util.HashtableOfObjectToInt", "get", "int", "java.lang.Object")) - .wrapMethod(new Hook("lombok.eclipse.agent.PatchFixes", "getSourceEndFixed", "int", "int", "org.eclipse.jdt.internal.compiler.ast.ASTNode")) + .wrapMethod(new Hook("lombok.launch.PatchFixesHider$PatchFixes", "getSourceEndFixed", "int", "int", "org.eclipse.jdt.internal.compiler.ast.ASTNode")) .requestExtra(StackRequest.PARAM1) .transplant().build()); @@ -125,7 +122,7 @@ public class EclipsePatcher implements AgentLauncher.AgentLaunchable { "org.eclipse.jdt.core.dom.MethodDeclaration" )) .methodToWrap(new Hook("org.eclipse.jface.text.IDocument", "get", "java.lang.String", "int", "int")) - .wrapMethod(new Hook("lombok.eclipse.agent.PatchFixes", "getRealMethodDeclarationSource", "java.lang.String", "java.lang.String", "java.lang.Object", "org.eclipse.jdt.core.dom.MethodDeclaration")) + .wrapMethod(new Hook("lombok.launch.PatchFixesHider$PatchFixes", "getRealMethodDeclarationSource", "java.lang.String", "java.lang.String", "java.lang.Object", "org.eclipse.jdt.core.dom.MethodDeclaration")) .requestExtra(StackRequest.THIS, StackRequest.PARAM4) .transplant().build()); @@ -134,20 +131,20 @@ public class EclipsePatcher implements AgentLauncher.AgentLaunchable { .target(new MethodTarget("org.eclipse.jdt.internal.corext.refactoring.structure.ExtractInterfaceProcessor", "createMemberDeclarations")) .target(new MethodTarget("org.eclipse.jdt.internal.corext.refactoring.structure.ExtractInterfaceProcessor", "createMethodComments")) .methodToReplace(new Hook("org.eclipse.jdt.internal.corext.refactoring.structure.ASTNodeSearchUtil", "getMethodDeclarationNode", "org.eclipse.jdt.core.dom.MethodDeclaration", "org.eclipse.jdt.core.IMethod", "org.eclipse.jdt.core.dom.CompilationUnit")) - .replacementMethod(new Hook("lombok.eclipse.agent.PatchFixes", "getRealMethodDeclarationNode", "org.eclipse.jdt.core.dom.MethodDeclaration", "org.eclipse.jdt.core.IMethod", "org.eclipse.jdt.core.dom.CompilationUnit")) + .replacementMethod(new Hook("lombok.launch.PatchFixesHider$PatchFixes", "getRealMethodDeclarationNode", "org.eclipse.jdt.core.dom.MethodDeclaration", "org.eclipse.jdt.core.IMethod", "org.eclipse.jdt.core.dom.CompilationUnit")) .transplant().build()); /* Do not add @Override's for generated methods */ sm.addScript(ScriptBuilder.exitEarly() .target(new MethodTarget("org.eclipse.jdt.core.dom.rewrite.ListRewrite", "insertFirst")) - .decisionMethod(new Hook("lombok.eclipse.agent.PatchFixes", "isListRewriteOnGeneratedNode", "boolean", "org.eclipse.jdt.core.dom.rewrite.ListRewrite")) + .decisionMethod(new Hook("lombok.launch.PatchFixesHider$PatchFixes", "isListRewriteOnGeneratedNode", "boolean", "org.eclipse.jdt.core.dom.rewrite.ListRewrite")) .request(StackRequest.THIS) .transplant().build()); /* Do not add comments for generated methods */ sm.addScript(ScriptBuilder.exitEarly() .target(new MethodTarget("org.eclipse.jdt.internal.corext.refactoring.structure.ExtractInterfaceProcessor", "createMethodComment")) - .decisionMethod(new Hook("lombok.eclipse.agent.PatchFixes", "isGenerated", "boolean", "org.eclipse.jdt.core.dom.ASTNode")) + .decisionMethod(new Hook("lombok.launch.PatchFixesHider$PatchFixes", "isGenerated", "boolean", "org.eclipse.jdt.core.dom.ASTNode")) .request(StackRequest.PARAM2) .transplant().build()); } @@ -160,7 +157,7 @@ public class EclipsePatcher implements AgentLauncher.AgentLaunchable { */ sm.addScript(ScriptBuilder.wrapReturnValue() .target(new MethodTarget("org.eclipse.core.internal.runtime.Product", "getProperty", "java.lang.String", "java.lang.String")) - .wrapMethod(new Hook("lombok.eclipse.agent.PatchFixes", "addLombokNotesToEclipseAboutDialog", "java.lang.String", "java.lang.String", "java.lang.String")) + .wrapMethod(new Hook("lombok.launch.PatchFixesHider$LombokDeps", "addLombokNotesToEclipseAboutDialog", "java.lang.String", "java.lang.String", "java.lang.String")) .request(StackRequest.RETURN_VALUE, StackRequest.PARAM1) .transplant().build()); } @@ -173,8 +170,8 @@ public class EclipsePatcher implements AgentLauncher.AgentLaunchable { .target(new MethodTarget("org.eclipse.jdt.internal.ui.search.OccurrencesFinder", "addUsage")) .target(new MethodTarget("org.eclipse.jdt.internal.ui.search.OccurrencesFinder", "addWrite")) .target(new MethodTarget("org.eclipse.jdt.internal.ui.javaeditor.SemanticHighlightingReconciler$PositionCollector", "visit", "boolean", "org.eclipse.jdt.core.dom.SimpleName")) - .decisionMethod(new Hook("lombok.eclipse.agent.PatchFixes", "isGenerated", "boolean", "org.eclipse.jdt.core.dom.ASTNode")) - .valueMethod(new Hook("lombok.eclipse.agent.PatchFixes", "returnFalse", "boolean", "java.lang.Object")) + .decisionMethod(new Hook("lombok.launch.PatchFixesHider$PatchFixes", "isGenerated", "boolean", "org.eclipse.jdt.core.dom.ASTNode")) + .valueMethod(new Hook("lombok.launch.PatchFixesHider$PatchFixes", "returnFalse", "boolean", "java.lang.Object")) .request(StackRequest.PARAM1) .build()); } @@ -199,9 +196,9 @@ public class EclipsePatcher implements AgentLauncher.AgentLaunchable { .target(new MethodTarget("org.eclipse.jdt.internal.corext.fix.CodeStyleFix$CodeStyleVisitor", "visit", "boolean", "org.eclipse.jdt.core.dom.QualifiedName")) .target(new MethodTarget("org.eclipse.jdt.internal.corext.fix.CodeStyleFix$CodeStyleVisitor", "visit", "boolean", "org.eclipse.jdt.core.dom.SimpleName")) // if a generated node has children we can just ignore them as well; - .decisionMethod(new Hook("lombok.eclipse.agent.PatchFixes", "isGenerated", "boolean", "org.eclipse.jdt.core.dom.ASTNode")) + .decisionMethod(new Hook("lombok.launch.PatchFixesHider$PatchFixes", "isGenerated", "boolean", "org.eclipse.jdt.core.dom.ASTNode")) .request(StackRequest.PARAM1) - .valueMethod(new Hook("lombok.eclipse.agent.PatchFixes", "returnFalse", "boolean", "java.lang.Object")) + .valueMethod(new Hook("lombok.launch.PatchFixesHider$PatchFixes", "returnFalse", "boolean", "java.lang.Object")) .build()); } @@ -209,7 +206,7 @@ public class EclipsePatcher implements AgentLauncher.AgentLaunchable { sm.addScript(ScriptBuilder.replaceMethodCall() .target(new MethodTarget("org.eclipse.jdt.internal.core.dom.rewrite.ASTRewriteAnalyzer$ListRewriter", "rewriteList")) .methodToReplace(new Hook("org.eclipse.jdt.internal.core.dom.rewrite.RewriteEvent", "getChildren", "org.eclipse.jdt.internal.core.dom.rewrite.RewriteEvent[]")) - .replacementMethod(new Hook("lombok.eclipse.agent.PatchFixes", "listRewriteHandleGeneratedMethods", "org.eclipse.jdt.internal.core.dom.rewrite.RewriteEvent[]", "org.eclipse.jdt.internal.core.dom.rewrite.RewriteEvent")) + .replacementMethod(new Hook("lombok.launch.PatchFixesHider$PatchFixes", "listRewriteHandleGeneratedMethods", "org.eclipse.jdt.internal.core.dom.rewrite.RewriteEvent[]", "org.eclipse.jdt.internal.core.dom.rewrite.RewriteEvent")) .build()); } @@ -221,37 +218,37 @@ public class EclipsePatcher implements AgentLauncher.AgentLaunchable { sm.addScript(ScriptBuilder.wrapMethodCall() .target(new MethodTarget("org.eclipse.jdt.internal.core.SortElementsOperation$2", "visit", "boolean", "org.eclipse.jdt.core.dom.CompilationUnit")) .methodToWrap(new Hook("org.eclipse.jdt.core.dom.CompilationUnit", "types", "java.util.List")) - .wrapMethod(new Hook("lombok.eclipse.agent.PatchFixes", "removeGeneratedNodes", "java.util.List", "java.util.List")) + .wrapMethod(new Hook("lombok.launch.PatchFixesHider$PatchFixes", "removeGeneratedNodes", "java.util.List", "java.util.List")) .transplant().build()); sm.addScript(ScriptBuilder.wrapMethodCall() .target(new MethodTarget("org.eclipse.jdt.internal.core.SortElementsOperation$2", "visit", "boolean", "org.eclipse.jdt.core.dom.AnnotationTypeDeclaration")) .methodToWrap(new Hook("org.eclipse.jdt.core.dom.AnnotationTypeDeclaration", "bodyDeclarations", "java.util.List")) - .wrapMethod(new Hook("lombok.eclipse.agent.PatchFixes", "removeGeneratedNodes", "java.util.List", "java.util.List")) + .wrapMethod(new Hook("lombok.launch.PatchFixesHider$PatchFixes", "removeGeneratedNodes", "java.util.List", "java.util.List")) .transplant().build()); sm.addScript(ScriptBuilder.wrapMethodCall() .target(new MethodTarget("org.eclipse.jdt.internal.core.SortElementsOperation$2", "visit", "boolean", "org.eclipse.jdt.core.dom.AnonymousClassDeclaration")) .methodToWrap(new Hook("org.eclipse.jdt.core.dom.AnonymousClassDeclaration", "bodyDeclarations", "java.util.List")) - .wrapMethod(new Hook("lombok.eclipse.agent.PatchFixes", "removeGeneratedNodes", "java.util.List", "java.util.List")) + .wrapMethod(new Hook("lombok.launch.PatchFixesHider$PatchFixes", "removeGeneratedNodes", "java.util.List", "java.util.List")) .transplant().build()); sm.addScript(ScriptBuilder.wrapMethodCall() .target(new MethodTarget("org.eclipse.jdt.internal.core.SortElementsOperation$2", "visit", "boolean", "org.eclipse.jdt.core.dom.TypeDeclaration")) .methodToWrap(new Hook("org.eclipse.jdt.core.dom.TypeDeclaration", "bodyDeclarations", "java.util.List")) - .wrapMethod(new Hook("lombok.eclipse.agent.PatchFixes", "removeGeneratedNodes", "java.util.List", "java.util.List")) + .wrapMethod(new Hook("lombok.launch.PatchFixesHider$PatchFixes", "removeGeneratedNodes", "java.util.List", "java.util.List")) .transplant().build()); sm.addScript(ScriptBuilder.wrapMethodCall() .target(new MethodTarget("org.eclipse.jdt.internal.core.SortElementsOperation$2", "visit", "boolean", "org.eclipse.jdt.core.dom.EnumDeclaration")) .methodToWrap(new Hook("org.eclipse.jdt.core.dom.EnumDeclaration", "bodyDeclarations", "java.util.List")) - .wrapMethod(new Hook("lombok.eclipse.agent.PatchFixes", "removeGeneratedNodes", "java.util.List", "java.util.List")) + .wrapMethod(new Hook("lombok.launch.PatchFixesHider$PatchFixes", "removeGeneratedNodes", "java.util.List", "java.util.List")) .transplant().build()); sm.addScript(ScriptBuilder.wrapMethodCall() .target(new MethodTarget("org.eclipse.jdt.internal.core.SortElementsOperation$2", "visit", "boolean", "org.eclipse.jdt.core.dom.EnumDeclaration")) .methodToWrap(new Hook("org.eclipse.jdt.core.dom.EnumDeclaration", "enumConstants", "java.util.List")) - .wrapMethod(new Hook("lombok.eclipse.agent.PatchFixes", "removeGeneratedNodes", "java.util.List", "java.util.List")) + .wrapMethod(new Hook("lombok.launch.PatchFixesHider$PatchFixes", "removeGeneratedNodes", "java.util.List", "java.util.List")) .transplant().build()); } @@ -259,7 +256,7 @@ public class EclipsePatcher implements AgentLauncher.AgentLaunchable { sm.addScript(ScriptBuilder.replaceMethodCall() .target(new MethodTarget("org.eclipse.jdt.internal.core.dom.rewrite.ASTRewriteAnalyzer", "visit")) .methodToReplace(new Hook("org.eclipse.jdt.internal.core.dom.rewrite.TokenScanner", "getTokenEndOffset", "int", "int", "int")) - .replacementMethod(new Hook("lombok.eclipse.agent.PatchFixes", "getTokenEndOffsetFixed", "int", "org.eclipse.jdt.internal.core.dom.rewrite.TokenScanner", "int", "int", "java.lang.Object")) + .replacementMethod(new Hook("lombok.launch.PatchFixesHider$PatchFixes", "getTokenEndOffsetFixed", "int", "org.eclipse.jdt.internal.core.dom.rewrite.TokenScanner", "int", "int", "java.lang.Object")) .requestExtra(StackRequest.PARAM1) .transplant() .build()); @@ -271,7 +268,7 @@ public class EclipsePatcher implements AgentLauncher.AgentLaunchable { .target(new MethodTarget("org.eclipse.jdt.internal.core.builder.IncrementalImageBuilder", "writeClassFileContents")) .target(new MethodTarget("org.eclipse.jdt.internal.core.builder.AbstractImageBuilder", "writeClassFileContents")) .methodToWrap(new Hook("org.eclipse.jdt.internal.compiler.ClassFile", "getBytes", "byte[]")) - .wrapMethod(new Hook("lombok.eclipse.agent.PatchFixes", "runPostCompiler", "byte[]", "byte[]", "java.lang.String")) + .wrapMethod(new Hook("lombok.launch.PatchFixesHider$LombokDeps", "runPostCompiler", "byte[]", "byte[]", "java.lang.String")) .requestExtra(StackRequest.PARAM3) .build()); } @@ -280,24 +277,22 @@ public class EclipsePatcher implements AgentLauncher.AgentLaunchable { sm.addScript(ScriptBuilder.wrapMethodCall() .target(new MethodTarget("org.eclipse.jdt.internal.compiler.tool.EclipseCompilerImpl", "outputClassFiles")) .methodToWrap(new Hook("javax.tools.JavaFileObject", "openOutputStream", "java.io.OutputStream")) - .wrapMethod(new Hook("lombok.eclipse.agent.PatchFixes", "runPostCompiler", "java.io.OutputStream", "java.io.OutputStream")) - .transplant() - .build()); + .wrapMethod(new Hook("lombok.launch.PatchFixesHider$LombokDeps", "runPostCompiler", "java.io.OutputStream", "java.io.OutputStream")) + .transplant().build()); sm.addScript(ScriptBuilder.wrapMethodCall() .target(new MethodTarget("org.eclipse.jdt.internal.compiler.util.Util", "writeToDisk")) .methodToWrap(new Hook("java.io.BufferedOutputStream", "<init>", "void", "java.io.OutputStream", "int")) - .wrapMethod(new Hook("lombok.eclipse.agent.PatchFixes", "runPostCompiler", "java.io.BufferedOutputStream", "java.io.BufferedOutputStream", "java.lang.String", "java.lang.String")) + .wrapMethod(new Hook("lombok.launch.PatchFixesHider$LombokDeps", "runPostCompiler", "java.io.BufferedOutputStream", "java.io.BufferedOutputStream", "java.lang.String", "java.lang.String")) .requestExtra(StackRequest.PARAM2, StackRequest.PARAM3) - .transplant() - .build()); + .transplant().build()); } private static void patchHideGeneratedNodes(ScriptManager sm) { sm.addScript(ScriptBuilder.wrapReturnValue() .target(new MethodTarget("org.eclipse.jdt.internal.corext.dom.LinkedNodeFinder", "findByNode")) .target(new MethodTarget("org.eclipse.jdt.internal.corext.dom.LinkedNodeFinder", "findByBinding")) - .wrapMethod(new Hook("lombok.eclipse.agent.PatchFixes", "removeGeneratedSimpleNames", "org.eclipse.jdt.core.dom.SimpleName[]", + .wrapMethod(new Hook("lombok.launch.PatchFixesHider$PatchFixes", "removeGeneratedSimpleNames", "org.eclipse.jdt.core.dom.SimpleName[]", "org.eclipse.jdt.core.dom.SimpleName[]")) .request(StackRequest.RETURN_VALUE).build()); @@ -317,22 +312,22 @@ public class EclipsePatcher implements AgentLauncher.AgentLaunchable { sm.addScript(ScriptBuilder.exitEarly() .target(new MethodTarget("org.eclipse.jdt.core.dom.rewrite.ASTRewrite", "replace")) .target(new MethodTarget("org.eclipse.jdt.core.dom.rewrite.ASTRewrite", "remove")) - .decisionMethod(new Hook("lombok.eclipse.agent.PatchFixes", "skipRewritingGeneratedNodes", "boolean", + .decisionMethod(new Hook("lombok.launch.PatchFixesHider$PatchFixes", "skipRewritingGeneratedNodes", "boolean", "org.eclipse.jdt.core.dom.ASTNode")) .transplant().request(StackRequest.PARAM1).build()); sm.addScript(ScriptBuilder.wrapMethodCall() .target(new MethodTarget("org.eclipse.jdt.internal.corext.refactoring.rename.RenameTypeProcessor", "addConstructorRenames")) .methodToWrap(new Hook("org.eclipse.jdt.core.IType", "getMethods", "org.eclipse.jdt.core.IMethod[]")) - .wrapMethod(new Hook("lombok.eclipse.agent.PatchFixes", "removeGeneratedMethods", "org.eclipse.jdt.core.IMethod[]", + .wrapMethod(new Hook("lombok.launch.PatchFixesHider$PatchFixes", "removeGeneratedMethods", "org.eclipse.jdt.core.IMethod[]", "org.eclipse.jdt.core.IMethod[]")) .transplant().build()); sm.addScript(ScriptBuilder.exitEarly() .target(new MethodTarget("org.eclipse.jdt.internal.corext.refactoring.rename.TempOccurrenceAnalyzer", "visit", "boolean", "org.eclipse.jdt.core.dom.SimpleName")) .target(new MethodTarget("org.eclipse.jdt.internal.corext.refactoring.rename.RenameAnalyzeUtil$ProblemNodeFinder$NameNodeVisitor", "visit", "boolean", "org.eclipse.jdt.core.dom.SimpleName")) - .decisionMethod(new Hook("lombok.eclipse.agent.PatchFixes", "isGenerated", "boolean", "org.eclipse.jdt.core.dom.ASTNode")) - .valueMethod(new Hook("lombok.eclipse.agent.PatchFixes", "returnTrue", "boolean", "java.lang.Object")) + .decisionMethod(new Hook("lombok.launch.PatchFixesHider$PatchFixes", "isGenerated", "boolean", "org.eclipse.jdt.core.dom.ASTNode")) + .valueMethod(new Hook("lombok.launch.PatchFixesHider$PatchFixes", "returnTrue", "boolean", "java.lang.Object")) .request(StackRequest.PARAM1) .transplant().build()); } @@ -340,21 +335,21 @@ public class EclipsePatcher implements AgentLauncher.AgentLaunchable { private static void patchCatchReparse(ScriptManager sm) { sm.addScript(ScriptBuilder.wrapReturnValue() .target(new MethodTarget("org.eclipse.jdt.core.dom.ASTConverter", "retrieveStartingCatchPosition")) - .wrapMethod(new Hook("lombok.eclipse.agent.PatchFixes", "fixRetrieveStartingCatchPosition", "int", "int", "int")) + .wrapMethod(new Hook("lombok.launch.PatchFixesHider$PatchFixes", "fixRetrieveStartingCatchPosition", "int", "int", "int")) .transplant().request(StackRequest.RETURN_VALUE, StackRequest.PARAM1).build()); } private static void patchIdentifierEndReparse(ScriptManager sm) { sm.addScript(ScriptBuilder.wrapReturnValue() .target(new MethodTarget("org.eclipse.jdt.core.dom.ASTConverter", "retrieveIdentifierEndPosition")) - .wrapMethod(new Hook("lombok.eclipse.agent.PatchFixes", "fixRetrieveIdentifierEndPosition", "int", "int", "int")) + .wrapMethod(new Hook("lombok.launch.PatchFixesHider$PatchFixes", "fixRetrieveIdentifierEndPosition", "int", "int", "int")) .transplant().request(StackRequest.RETURN_VALUE, StackRequest.PARAM2).build()); } private static void patchRetrieveEllipsisStartPosition(ScriptManager sm) { sm.addScript(ScriptBuilder.wrapReturnValue() .target(new MethodTarget("org.eclipse.jdt.core.dom.ASTConverter", "retrieveEllipsisStartPosition")) - .wrapMethod(new Hook("lombok.eclipse.agent.PatchFixes", "fixRetrieveEllipsisStartPosition", "int", "int", "int")) + .wrapMethod(new Hook("lombok.launch.PatchFixesHider$PatchFixes", "fixRetrieveEllipsisStartPosition", "int", "int", "int")) .transplant().request(StackRequest.RETURN_VALUE, StackRequest.PARAM2).build()); } @@ -362,7 +357,7 @@ public class EclipsePatcher implements AgentLauncher.AgentLaunchable { sm.addScript(ScriptBuilder.wrapReturnValue() .target(new MethodTarget("org.eclipse.jdt.core.dom.ASTConverter", "retrieveRightBraceOrSemiColonPosition")) .target(new MethodTarget("org.eclipse.jdt.core.dom.ASTConverter", "retrieveRightBrace")) - .wrapMethod(new Hook("lombok.eclipse.agent.PatchFixes", "fixRetrieveRightBraceOrSemiColonPosition", "int", "int", "int")) + .wrapMethod(new Hook("lombok.launch.PatchFixesHider$PatchFixes", "fixRetrieveRightBraceOrSemiColonPosition", "int", "int", "int")) .transplant().request(StackRequest.RETURN_VALUE, StackRequest.PARAM2).build()); } @@ -394,14 +389,14 @@ public class EclipsePatcher implements AgentLauncher.AgentLaunchable { return Collections.singleton("org.eclipse.jdt.core.dom.ASTConverter"); } }).request(StackRequest.PARAM1, StackRequest.RETURN_VALUE) - .wrapMethod(new Hook("lombok.eclipse.agent.PatchFixes", "setIsGeneratedFlag", "void", + .wrapMethod(new Hook("lombok.launch.PatchFixesHider$PatchFixes", "setIsGeneratedFlag", "void", "org.eclipse.jdt.core.dom.ASTNode", "org.eclipse.jdt.internal.compiler.ast.ASTNode")) .transplant().build()); sm.addScript(ScriptBuilder.wrapReturnValue() .target(new MethodTarget("org.eclipse.jdt.core.dom.ASTConverter", "convert", "org.eclipse.jdt.core.dom.ASTNode", "boolean", "org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration")) .request(StackRequest.PARAM2, StackRequest.RETURN_VALUE) - .wrapMethod(new Hook("lombok.eclipse.agent.PatchFixes", "setIsGeneratedFlag", "void", + .wrapMethod(new Hook("lombok.launch.PatchFixesHider$PatchFixes", "setIsGeneratedFlag", "void", "org.eclipse.jdt.core.dom.ASTNode", "org.eclipse.jdt.internal.compiler.ast.ASTNode")) .transplant().build()); @@ -419,7 +414,7 @@ public class EclipsePatcher implements AgentLauncher.AgentLaunchable { .target(new MethodTarget("org.eclipse.jdt.core.dom.ASTConverter", "convertToVariableDeclarationStatement", "org.eclipse.jdt.core.dom.VariableDeclarationStatement", "org.eclipse.jdt.internal.compiler.ast.LocalDeclaration")) /* Targets above are only patched because the resulting dom nodes should be marked if generated. */ .request(StackRequest.PARAM1, StackRequest.RETURN_VALUE) - .wrapMethod(new Hook("lombok.eclipse.agent.PatchFixes", "setIsGeneratedFlag", "void", + .wrapMethod(new Hook("lombok.launch.PatchFixesHider$PatchFixes", "setIsGeneratedFlag", "void", "org.eclipse.jdt.core.dom.ASTNode", "org.eclipse.jdt.internal.compiler.ast.ASTNode")) .transplant().build()); @@ -441,7 +436,7 @@ public class EclipsePatcher implements AgentLauncher.AgentLaunchable { } }).methodToWrap(new Hook("org.eclipse.jdt.core.dom.SimpleName", "<init>", "void", "org.eclipse.jdt.core.dom.AST")) .requestExtra(StackRequest.PARAM1) - .wrapMethod(new Hook("lombok.eclipse.agent.PatchFixes", "setIsGeneratedFlagForName", "void", + .wrapMethod(new Hook("lombok.launch.PatchFixesHider$PatchFixes", "setIsGeneratedFlagForName", "void", "org.eclipse.jdt.core.dom.Name", "java.lang.Object")) .transplant().build()); @@ -449,7 +444,7 @@ public class EclipsePatcher implements AgentLauncher.AgentLaunchable { .target(new MethodTarget("org.eclipse.jdt.core.dom.ASTConverter", "convert", "org.eclipse.jdt.core.dom.ASTNode", "boolean", "org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration")) .methodToWrap(new Hook("org.eclipse.jdt.core.dom.SimpleName", "<init>", "void", "org.eclipse.jdt.core.dom.AST")) .requestExtra(StackRequest.PARAM2) - .wrapMethod(new Hook("lombok.eclipse.agent.PatchFixes", "setIsGeneratedFlagForName", "void", + .wrapMethod(new Hook("lombok.launch.PatchFixesHider$PatchFixes", "setIsGeneratedFlagForName", "void", "org.eclipse.jdt.core.dom.Name", "java.lang.Object")) .transplant().build()); @@ -458,7 +453,7 @@ public class EclipsePatcher implements AgentLauncher.AgentLaunchable { .target(new MethodTarget("org.eclipse.jdt.core.dom.ASTConverter", "setQualifiedNameNameAndSourceRanges", "org.eclipse.jdt.core.dom.QualifiedName", "char[][]", "long[]", "int", "org.eclipse.jdt.internal.compiler.ast.ASTNode")) .methodToWrap(new Hook("org.eclipse.jdt.core.dom.SimpleName", "<init>", "void", "org.eclipse.jdt.core.dom.AST")) .requestExtra(StackRequest.PARAM4) - .wrapMethod(new Hook("lombok.eclipse.agent.PatchFixes", "setIsGeneratedFlagForName", "void", + .wrapMethod(new Hook("lombok.launch.PatchFixesHider$PatchFixes", "setIsGeneratedFlagForName", "void", "org.eclipse.jdt.core.dom.Name", "java.lang.Object")) .transplant().build()); @@ -466,7 +461,7 @@ public class EclipsePatcher implements AgentLauncher.AgentLaunchable { .target(new MethodTarget("org.eclipse.jdt.core.dom.ASTConverter", "setQualifiedNameNameAndSourceRanges", "org.eclipse.jdt.core.dom.QualifiedName", "char[][]", "long[]", "int", "org.eclipse.jdt.internal.compiler.ast.ASTNode")) .methodToWrap(new Hook("org.eclipse.jdt.core.dom.QualifiedName", "<init>", "void", "org.eclipse.jdt.core.dom.AST")) .requestExtra(StackRequest.PARAM4) - .wrapMethod(new Hook("lombok.eclipse.agent.PatchFixes", "setIsGeneratedFlagForName", "void", + .wrapMethod(new Hook("lombok.launch.PatchFixesHider$PatchFixes", "setIsGeneratedFlagForName", "void", "org.eclipse.jdt.core.dom.Name", "java.lang.Object")) .transplant().build()); @@ -474,7 +469,7 @@ public class EclipsePatcher implements AgentLauncher.AgentLaunchable { .target(new MethodTarget("org.eclipse.jdt.core.dom.ASTConverter", "setQualifiedNameNameAndSourceRanges", "org.eclipse.jdt.core.dom.QualifiedName", "char[][]", "long[]", "org.eclipse.jdt.internal.compiler.ast.ASTNode")) .methodToWrap(new Hook("org.eclipse.jdt.core.dom.SimpleName", "<init>", "void", "org.eclipse.jdt.core.dom.AST")) .requestExtra(StackRequest.PARAM3) - .wrapMethod(new Hook("lombok.eclipse.agent.PatchFixes", "setIsGeneratedFlagForName", "void", + .wrapMethod(new Hook("lombok.launch.PatchFixesHider$PatchFixes", "setIsGeneratedFlagForName", "void", "org.eclipse.jdt.core.dom.Name", "java.lang.Object")) .transplant().build()); @@ -482,7 +477,7 @@ public class EclipsePatcher implements AgentLauncher.AgentLaunchable { .target(new MethodTarget("org.eclipse.jdt.core.dom.ASTConverter", "setQualifiedNameNameAndSourceRanges", "org.eclipse.jdt.core.dom.QualifiedName", "char[][]", "long[]", "org.eclipse.jdt.internal.compiler.ast.ASTNode")) .methodToWrap(new Hook("org.eclipse.jdt.core.dom.QualifiedName", "<init>", "void", "org.eclipse.jdt.core.dom.AST")) .requestExtra(StackRequest.PARAM3) - .wrapMethod(new Hook("lombok.eclipse.agent.PatchFixes", "setIsGeneratedFlagForName", "void", + .wrapMethod(new Hook("lombok.launch.PatchFixesHider$PatchFixes", "setIsGeneratedFlagForName", "void", "org.eclipse.jdt.core.dom.Name", "java.lang.Object")) .transplant().build()); } @@ -493,7 +488,7 @@ public class EclipsePatcher implements AgentLauncher.AgentLaunchable { .target(new MethodTarget(PARSER_SIG, "parse", "void", "org.eclipse.jdt.internal.compiler.ast.MethodDeclaration", "org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration")) - .decisionMethod(new Hook("lombok.eclipse.agent.PatchFixes", "checkBit24", "boolean", "java.lang.Object")) + .decisionMethod(new Hook("lombok.launch.PatchFixesHider$PatchFixes", "checkBit24", "boolean", "java.lang.Object")) .transplant() .request(StackRequest.PARAM1).build()); @@ -501,7 +496,7 @@ public class EclipsePatcher implements AgentLauncher.AgentLaunchable { .target(new MethodTarget(PARSER_SIG, "parse", "void", "org.eclipse.jdt.internal.compiler.ast.ConstructorDeclaration", "org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration", "boolean")) - .decisionMethod(new Hook("lombok.eclipse.agent.PatchFixes", "checkBit24", "boolean", "java.lang.Object")) + .decisionMethod(new Hook("lombok.launch.PatchFixesHider$PatchFixes", "checkBit24", "boolean", "java.lang.Object")) .transplant() .request(StackRequest.PARAM1).build()); @@ -510,7 +505,7 @@ public class EclipsePatcher implements AgentLauncher.AgentLaunchable { "org.eclipse.jdt.internal.compiler.ast.Initializer", "org.eclipse.jdt.internal.compiler.ast.TypeDeclaration", "org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration")) - .decisionMethod(new Hook("lombok.eclipse.agent.PatchFixes", "checkBit24", "boolean", "java.lang.Object")) + .decisionMethod(new Hook("lombok.launch.PatchFixesHider$PatchFixes", "checkBit24", "boolean", "java.lang.Object")) .transplant() .request(StackRequest.PARAM1).build()); } @@ -526,12 +521,12 @@ public class EclipsePatcher implements AgentLauncher.AgentLaunchable { sm.addScript(ScriptBuilder.wrapReturnValue() .target(new MethodTarget(PARSER_SIG, "getMethodBodies", "void", CUD_SIG)) - .wrapMethod(new Hook("lombok.eclipse.TransformEclipseAST", "transform", "void", PARSER_SIG, CUD_SIG)) + .wrapMethod(new Hook("lombok.launch.PatchFixesHider$Transform", "transform", "void", PARSER_SIG, CUD_SIG)) .request(StackRequest.THIS, StackRequest.PARAM1).build()); sm.addScript(ScriptBuilder.wrapReturnValue() .target(new MethodTarget(PARSER_SIG, "endParse", CUD_SIG, "int")) - .wrapMethod(new Hook("lombok.eclipse.TransformEclipseAST", "transform_swapped", "void", CUD_SIG, PARSER_SIG)) + .wrapMethod(new Hook("lombok.launch.PatchFixesHider$Transform", "transform_swapped", "void", CUD_SIG, PARSER_SIG)) .request(StackRequest.THIS, StackRequest.RETURN_VALUE).build()); } @@ -547,7 +542,7 @@ public class EclipsePatcher implements AgentLauncher.AgentLaunchable { sm.addScript(ScriptBuilder.exitEarly() .target(new MethodTarget(CLASSSCOPE_SIG, "buildFieldsAndMethods", "void")) .request(StackRequest.THIS) - .decisionMethod(new Hook("lombok.eclipse.agent.PatchDelegatePortal", "handleDelegateForType", "boolean", "java.lang.Object")) + .decisionMethod(new Hook("lombok.launch.PatchFixesHider$Delegate", "handleDelegateForType", "boolean", "java.lang.Object")) .build()); } @@ -577,24 +572,24 @@ public class EclipsePatcher implements AgentLauncher.AgentLaunchable { sm.addScript(ScriptBuilder.wrapReturnValue() .target(new MethodTarget(PARSER_SIG, "consumeExitVariableWithInitialization", "void")) .request(StackRequest.THIS) - .wrapMethod(new Hook("lombok.eclipse.agent.PatchValEclipsePortal", "copyInitializationOfLocalDeclaration", "void", "java.lang.Object")) + .wrapMethod(new Hook("lombok.launch.PatchFixesHider$ValPortal", "copyInitializationOfLocalDeclaration", "void", "java.lang.Object")) .build()); sm.addScript(ScriptBuilder.wrapReturnValue() .target(new MethodTarget(PARSER_SIG, "consumeEnhancedForStatementHeader", "void")) .request(StackRequest.THIS) - .wrapMethod(new Hook("lombok.eclipse.agent.PatchValEclipsePortal", "copyInitializationOfForEachIterable", "void", "java.lang.Object")) + .wrapMethod(new Hook("lombok.launch.PatchFixesHider$ValPortal", "copyInitializationOfForEachIterable", "void", "java.lang.Object")) .build()); sm.addScript(ScriptBuilder.wrapReturnValue() .target(new MethodTarget(ASTCONVERTER_SIG, "setModifiers", "void", VARIABLEDECLARATIONSTATEMENT_SIG, LOCALDECLARATION_SIG)) - .wrapMethod(new Hook("lombok.eclipse.agent.PatchValEclipsePortal", "addFinalAndValAnnotationToVariableDeclarationStatement", + .wrapMethod(new Hook("lombok.launch.PatchFixesHider$ValPortal", "addFinalAndValAnnotationToVariableDeclarationStatement", "void", "java.lang.Object", "java.lang.Object", "java.lang.Object")) .request(StackRequest.THIS, StackRequest.PARAM1, StackRequest.PARAM2).build()); sm.addScript(ScriptBuilder.wrapReturnValue() .target(new MethodTarget(ASTCONVERTER_SIG, "setModifiers", "void", SINGLEVARIABLEDECLARATION_SIG, LOCALDECLARATION_SIG)) - .wrapMethod(new Hook("lombok.eclipse.agent.PatchValEclipsePortal", "addFinalAndValAnnotationToSingleVariableDeclaration", + .wrapMethod(new Hook("lombok.launch.PatchFixesHider$ValPortal", "addFinalAndValAnnotationToSingleVariableDeclaration", "void", "java.lang.Object", "java.lang.Object", "java.lang.Object")) .request(StackRequest.THIS, StackRequest.PARAM1, StackRequest.PARAM2).build()); } @@ -609,26 +604,26 @@ public class EclipsePatcher implements AgentLauncher.AgentLaunchable { sm.addScript(ScriptBuilder.exitEarly() .target(new MethodTarget(LOCALDECLARATION_SIG, "resolve", "void", BLOCKSCOPE_SIG)) .request(StackRequest.THIS, StackRequest.PARAM1) - .decisionMethod(new Hook("lombok.eclipse.agent.PatchVal", "handleValForLocalDeclaration", "boolean", LOCALDECLARATION_SIG, BLOCKSCOPE_SIG)) + .decisionMethod(new Hook("lombok.launch.PatchFixesHider$Val", "handleValForLocalDeclaration", "boolean", LOCALDECLARATION_SIG, BLOCKSCOPE_SIG)) .build()); sm.addScript(ScriptBuilder.replaceMethodCall() .target(new MethodTarget(LOCALDECLARATION_SIG, "resolve", "void", BLOCKSCOPE_SIG)) .methodToReplace(new Hook(EXPRESSION_SIG, "resolveType", TYPEBINDING_SIG, BLOCKSCOPE_SIG)) .requestExtra(StackRequest.THIS) - .replacementMethod(new Hook("lombok.eclipse.agent.PatchVal", "skipResolveInitializerIfAlreadyCalled2", TYPEBINDING_SIG, EXPRESSION_SIG, BLOCKSCOPE_SIG, LOCALDECLARATION_SIG)) + .replacementMethod(new Hook("lombok.launch.PatchFixesHider$Val", "skipResolveInitializerIfAlreadyCalled2", TYPEBINDING_SIG, EXPRESSION_SIG, BLOCKSCOPE_SIG, LOCALDECLARATION_SIG)) .build()); sm.addScript(ScriptBuilder.replaceMethodCall() .target(new MethodTarget(FOREACHSTATEMENT_SIG, "resolve", "void", BLOCKSCOPE_SIG)) .methodToReplace(new Hook(EXPRESSION_SIG, "resolveType", TYPEBINDING_SIG, BLOCKSCOPE_SIG)) - .replacementMethod(new Hook("lombok.eclipse.agent.PatchVal", "skipResolveInitializerIfAlreadyCalled", TYPEBINDING_SIG, EXPRESSION_SIG, BLOCKSCOPE_SIG)) + .replacementMethod(new Hook("lombok.launch.PatchFixesHider$Val", "skipResolveInitializerIfAlreadyCalled", TYPEBINDING_SIG, EXPRESSION_SIG, BLOCKSCOPE_SIG)) .build()); sm.addScript(ScriptBuilder.exitEarly() .target(new MethodTarget(FOREACHSTATEMENT_SIG, "resolve", "void", BLOCKSCOPE_SIG)) .request(StackRequest.THIS, StackRequest.PARAM1) - .decisionMethod(new Hook("lombok.eclipse.agent.PatchVal", "handleValForForEach", "boolean", FOREACHSTATEMENT_SIG, BLOCKSCOPE_SIG)) + .decisionMethod(new Hook("lombok.launch.PatchFixesHider$Val", "handleValForForEach", "boolean", FOREACHSTATEMENT_SIG, BLOCKSCOPE_SIG)) .build()); } @@ -639,7 +634,7 @@ public class EclipsePatcher implements AgentLauncher.AgentLaunchable { sm.addScript(ScriptBuilder.wrapReturnValue() .target(new MethodTarget(SOURCE_TYPE_CONVERTER_SIG, "convertAnnotations", ANNOTATION_SIG + "[]", I_ANNOTATABLE_SIG)) - .wrapMethod(new Hook("lombok.eclipse.agent.PatchFixes", "convertAnnotations", ANNOTATION_SIG + "[]", ANNOTATION_SIG + "[]", I_ANNOTATABLE_SIG)) + .wrapMethod(new Hook("lombok.launch.PatchFixesHider$PatchFixes", "convertAnnotations", ANNOTATION_SIG + "[]", ANNOTATION_SIG + "[]", I_ANNOTATABLE_SIG)) .request(StackRequest.PARAM1, StackRequest.RETURN_VALUE).build()); } @@ -657,7 +652,7 @@ public class EclipsePatcher implements AgentLauncher.AgentLaunchable { } private static void patchExtensionMethod(ScriptManager sm, boolean ecj) { - final String PATCH_EXTENSIONMETHOD = "lombok.eclipse.agent.PatchExtensionMethod"; + final String PATCH_EXTENSIONMETHOD = "lombok.launch.PatchFixesHider$ExtensionMethod"; final String PATCH_EXTENSIONMETHOD_COMPLETIONPROPOSAL_PORTAL = "lombok.eclipse.agent.PatchExtensionMethodCompletionProposalPortal"; final String MESSAGE_SEND_SIG = "org.eclipse.jdt.internal.compiler.ast.MessageSend"; final String TYPE_BINDING_SIG = "org.eclipse.jdt.internal.compiler.lookup.TypeBinding"; diff --git a/src/eclipseAgent/lombok/eclipse/agent/PatchExtensionMethod.java b/src/eclipseAgent/lombok/eclipse/agent/PatchExtensionMethod.java index 44adb333..ca0933fb 100644 --- a/src/eclipseAgent/lombok/eclipse/agent/PatchExtensionMethod.java +++ b/src/eclipseAgent/lombok/eclipse/agent/PatchExtensionMethod.java @@ -227,8 +227,11 @@ public class PatchExtensionMethod { if (argument.resolvedType != null) argumentTypes.add(argument.resolvedType); // TODO: Instead of just skipping nulls entirely, there is probably a 'unresolved type' placeholder. THAT is what we ought to be adding here! } + Expression[] originalArgs = methodCall.arguments; + methodCall.arguments = arguments.toArray(new Expression[0]); MethodBinding fixedBinding = scope.getMethod(extensionMethod.declaringClass, methodCall.selector, argumentTypes.toArray(new TypeBinding[0]), methodCall); if (fixedBinding instanceof ProblemMethodBinding) { + methodCall.arguments = originalArgs; if (fixedBinding.declaringClass != null) { scope.problemReporter().invalidMethod(methodCall, fixedBinding); } @@ -247,7 +250,6 @@ public class PatchExtensionMethod { arg.implicitConversion = TypeIds.UNBOXING | (id + (id << 4)); // magic see TypeIds } } - methodCall.arguments = arguments.toArray(new Expression[0]); methodCall.receiver = createNameRef(extensionMethod.declaringClass, methodCall); methodCall.actualReceiverType = extensionMethod.declaringClass; diff --git a/src/eclipseAgent/lombok/eclipse/agent/PatchFixes.java b/src/eclipseAgent/lombok/eclipse/agent/PatchFixes.java deleted file mode 100644 index d1c668a0..00000000 --- a/src/eclipseAgent/lombok/eclipse/agent/PatchFixes.java +++ /dev/null @@ -1,384 +0,0 @@ -/* - * Copyright (C) 2010-2013 The Project Lombok Authors. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ -package lombok.eclipse.agent; - -import java.io.BufferedOutputStream; -import java.io.IOException; -import java.io.OutputStream; -import java.lang.reflect.Field; -import java.util.ArrayList; -import java.util.List; -import java.util.Stack; - -import lombok.core.DiagnosticsReceiver; -import lombok.core.PostCompiler; -import lombok.core.Version; -import lombok.eclipse.EclipseAugments; - -import org.eclipse.core.runtime.CoreException; -import org.eclipse.jdt.core.IAnnotatable; -import org.eclipse.jdt.core.IAnnotation; -import org.eclipse.jdt.core.IMethod; -import org.eclipse.jdt.core.IType; -import org.eclipse.jdt.core.JavaModelException; -import org.eclipse.jdt.core.dom.MethodDeclaration; -import org.eclipse.jdt.core.dom.SimpleName; -import org.eclipse.jdt.internal.compiler.ast.Annotation; -import org.eclipse.jdt.internal.core.dom.rewrite.NodeRewriteEvent; -import org.eclipse.jdt.internal.core.dom.rewrite.RewriteEvent; -import org.eclipse.jdt.internal.core.dom.rewrite.TokenScanner; -import org.eclipse.jdt.internal.corext.refactoring.structure.ASTNodeSearchUtil; - -public class PatchFixes { - public static String addLombokNotesToEclipseAboutDialog(String origReturnValue, String key) { - if ("aboutText".equals(key)) { - return origReturnValue + "\n\nLombok " + Version.getFullVersion() + " is installed. http://projectlombok.org/"; - } - - return origReturnValue; - } - - public static boolean isGenerated(org.eclipse.jdt.core.dom.ASTNode node) { - boolean result = false; - try { - result = ((Boolean)node.getClass().getField("$isGenerated").get(node)).booleanValue(); - if (!result && node.getParent() != null && node.getParent() instanceof org.eclipse.jdt.core.dom.QualifiedName) - result = isGenerated(node.getParent()); - } catch (Exception e) { - // better to assume it isn't generated - } - return result; - } - - public static boolean isListRewriteOnGeneratedNode(org.eclipse.jdt.core.dom.rewrite.ListRewrite rewrite) { - return isGenerated(rewrite.getParent()); - } - - public static boolean returnFalse(java.lang.Object object) { - return false; - } - - public static boolean returnTrue(java.lang.Object object) { - return true; - } - - @java.lang.SuppressWarnings({"unchecked", "rawtypes"}) public static java.util.List removeGeneratedNodes(java.util.List list) { - try { - java.util.List realNodes = new java.util.ArrayList(list.size()); - for (java.lang.Object node : list) { - if(!isGenerated(((org.eclipse.jdt.core.dom.ASTNode)node))) { - realNodes.add(node); - } - } - return realNodes; - } catch (Exception e) { - } - return list; - } - - public static java.lang.String getRealMethodDeclarationSource(java.lang.String original, Object processor, org.eclipse.jdt.core.dom.MethodDeclaration declaration) throws Exception { - if (!isGenerated(declaration)) return original; - - List<org.eclipse.jdt.core.dom.Annotation> annotations = new ArrayList<org.eclipse.jdt.core.dom.Annotation>(); - for (Object modifier : declaration.modifiers()) { - if (modifier instanceof org.eclipse.jdt.core.dom.Annotation) { - org.eclipse.jdt.core.dom.Annotation annotation = (org.eclipse.jdt.core.dom.Annotation)modifier; - String qualifiedAnnotationName = annotation.resolveTypeBinding().getQualifiedName(); - if (!"java.lang.Override".equals(qualifiedAnnotationName) && !"java.lang.SuppressWarnings".equals(qualifiedAnnotationName)) annotations.add(annotation); - } - } - - StringBuilder signature = new StringBuilder(); - addAnnotations(annotations, signature); - - if ((Boolean)processor.getClass().getDeclaredField("fPublic").get(processor)) signature.append("public "); - if ((Boolean)processor.getClass().getDeclaredField("fAbstract").get(processor)) signature.append("abstract "); - - signature - .append(declaration.getReturnType2().toString()) - .append(" ").append(declaration.getName().getFullyQualifiedName()) - .append("("); - - boolean first = true; - for (Object parameter : declaration.parameters()) { - if (!first) signature.append(", "); - first = false; - // We should also add the annotations of the parameters - signature.append(parameter); - } - - signature.append(");"); - return signature.toString(); - } - - // part of getRealMethodDeclarationSource(...) - public static void addAnnotations(List<org.eclipse.jdt.core.dom.Annotation> annotations, StringBuilder signature) { - /* - * We SHOULD be able to handle the following cases: - * @Override - * @Override() - * @SuppressWarnings("all") - * @SuppressWarnings({"all", "unused"}) - * @SuppressWarnings(value = "all") - * @SuppressWarnings(value = {"all", "unused"}) - * @EqualsAndHashCode(callSuper=true, of="id") - * - * Currently, we only seem to correctly support: - * @Override - * @Override() N.B. We lose the parentheses here, since there are no values. No big deal. - * @SuppressWarnings("all") - */ - for (org.eclipse.jdt.core.dom.Annotation annotation : annotations) { - List<String> values = new ArrayList<String>(); - if (annotation.isSingleMemberAnnotation()) { - org.eclipse.jdt.core.dom.SingleMemberAnnotation smAnn = (org.eclipse.jdt.core.dom.SingleMemberAnnotation) annotation; - values.add(smAnn.getValue().toString()); - } else if (annotation.isNormalAnnotation()) { - org.eclipse.jdt.core.dom.NormalAnnotation normalAnn = (org.eclipse.jdt.core.dom.NormalAnnotation) annotation; - for (Object value : normalAnn.values()) values.add(value.toString()); - } - - signature.append("@").append(annotation.resolveTypeBinding().getQualifiedName()); - if (!values.isEmpty()) { - signature.append("("); - boolean first = true; - for (String string : values) { - if (!first) signature.append(", "); - first = false; - signature.append('"').append(string).append('"'); - } - signature.append(")"); - } - signature.append(" "); - } - } - - public static org.eclipse.jdt.core.dom.MethodDeclaration getRealMethodDeclarationNode(org.eclipse.jdt.core.IMethod sourceMethod, org.eclipse.jdt.core.dom.CompilationUnit cuUnit) throws JavaModelException { - MethodDeclaration methodDeclarationNode = ASTNodeSearchUtil.getMethodDeclarationNode(sourceMethod, cuUnit); - if (isGenerated(methodDeclarationNode)) { - IType declaringType = sourceMethod.getDeclaringType(); - Stack<IType> typeStack = new Stack<IType>(); - while (declaringType != null) { - typeStack.push(declaringType); - declaringType = declaringType.getDeclaringType(); - } - - IType rootType = typeStack.pop(); - org.eclipse.jdt.core.dom.AbstractTypeDeclaration typeDeclaration = findTypeDeclaration(rootType, cuUnit.types()); - while (!typeStack.isEmpty() && typeDeclaration != null) { - typeDeclaration = findTypeDeclaration(typeStack.pop(), typeDeclaration.bodyDeclarations()); - } - - if (typeStack.isEmpty() && typeDeclaration != null) { - String methodName = sourceMethod.getElementName(); - for (Object declaration : typeDeclaration.bodyDeclarations()) { - if (declaration instanceof org.eclipse.jdt.core.dom.MethodDeclaration) { - org.eclipse.jdt.core.dom.MethodDeclaration methodDeclaration = (org.eclipse.jdt.core.dom.MethodDeclaration) declaration; - if (methodDeclaration.getName().toString().equals(methodName)) { - return methodDeclaration; - } - } - } - } - } - return methodDeclarationNode; - } - - // part of getRealMethodDeclarationNode - public static org.eclipse.jdt.core.dom.AbstractTypeDeclaration findTypeDeclaration(IType searchType, List<?> nodes) { - for (Object object : nodes) { - if (object instanceof org.eclipse.jdt.core.dom.AbstractTypeDeclaration) { - org.eclipse.jdt.core.dom.AbstractTypeDeclaration typeDeclaration = (org.eclipse.jdt.core.dom.AbstractTypeDeclaration) object; - if (typeDeclaration.getName().toString().equals(searchType.getElementName())) - return typeDeclaration; - } - } - return null; - } - - public static int getSourceEndFixed(int sourceEnd, org.eclipse.jdt.internal.compiler.ast.ASTNode node) throws Exception { - if (sourceEnd == -1) { - org.eclipse.jdt.internal.compiler.ast.ASTNode object = (org.eclipse.jdt.internal.compiler.ast.ASTNode)node.getClass().getField("$generatedBy").get(node); - if (object != null) { - return object.sourceEnd; - } - } - return sourceEnd; - } - - public static int fixRetrieveStartingCatchPosition(int original, int start) { - return original == -1 ? start : original; - } - - public static int fixRetrieveIdentifierEndPosition(int original, int end) { - return original == -1 ? end : original; - } - - public static int fixRetrieveEllipsisStartPosition(int original, int end) { - return original == -1 ? end : original; - } - - public static int fixRetrieveRightBraceOrSemiColonPosition(int original, int end) { -// return original; - return original == -1 ? end : original; // Need to fix: see issue 325. - } - - public static final int ALREADY_PROCESSED_FLAG = 0x800000; //Bit 24 - - public static boolean checkBit24(Object node) throws Exception { - int bits = (Integer)(node.getClass().getField("bits").get(node)); - return (bits & ALREADY_PROCESSED_FLAG) != 0; - } - - public static boolean skipRewritingGeneratedNodes(org.eclipse.jdt.core.dom.ASTNode node) throws Exception { - return ((Boolean)node.getClass().getField("$isGenerated").get(node)).booleanValue(); - } - - public static void setIsGeneratedFlag(org.eclipse.jdt.core.dom.ASTNode domNode, - org.eclipse.jdt.internal.compiler.ast.ASTNode internalNode) throws Exception { - if (internalNode == null || domNode == null) return; - boolean isGenerated = EclipseAugments.ASTNode_generatedBy.get(internalNode) != null; - if (isGenerated) domNode.getClass().getField("$isGenerated").set(domNode, true); - } - - public static void setIsGeneratedFlagForName(org.eclipse.jdt.core.dom.Name name, Object internalNode) throws Exception { - if (internalNode instanceof org.eclipse.jdt.internal.compiler.ast.ASTNode) { - if (EclipseAugments.ASTNode_generatedBy.get((org.eclipse.jdt.internal.compiler.ast.ASTNode) internalNode) != null) { - name.getClass().getField("$isGenerated").set(name, true); - } - } - } - - public static RewriteEvent[] listRewriteHandleGeneratedMethods(RewriteEvent parent) { - RewriteEvent[] children = parent.getChildren(); - List<RewriteEvent> newChildren = new ArrayList<RewriteEvent>(); - List<RewriteEvent> modifiedChildren = new ArrayList<RewriteEvent>(); - for (int i=0; i<children.length; i++) { - RewriteEvent child = children[i]; - boolean isGenerated = isGenerated( (org.eclipse.jdt.core.dom.ASTNode)child.getOriginalValue() ); - if (isGenerated) { - if ((child.getChangeKind() == RewriteEvent.REPLACED || child.getChangeKind() == RewriteEvent.REMOVED) - && child.getOriginalValue() instanceof org.eclipse.jdt.core.dom.MethodDeclaration - && child.getNewValue() != null - ) { - modifiedChildren.add(new NodeRewriteEvent(null, child.getNewValue())); - } - } else { - newChildren.add(child); - } - } - // Since Eclipse doesn't honor the "insert at specified location" for already existing members, - // we'll just add them last - newChildren.addAll(modifiedChildren); - return newChildren.toArray(new RewriteEvent[newChildren.size()]); - } - - public static int getTokenEndOffsetFixed(TokenScanner scanner, int token, int startOffset, Object domNode) throws CoreException { - boolean isGenerated = false; - try { - isGenerated = (Boolean) domNode.getClass().getField("$isGenerated").get(domNode); - } catch (Exception e) { - // If this fails, better to break some refactor scripts than to crash eclipse. - } - if (isGenerated) return -1; - return scanner.getTokenEndOffset(token, startOffset); - } - - public static IMethod[] removeGeneratedMethods(IMethod[] methods) throws Exception { - List<IMethod> result = new ArrayList<IMethod>(); - for (IMethod m : methods) { - if (m.getNameRange().getLength() > 0 && !m.getNameRange().equals(m.getSourceRange())) result.add(m); - } - return result.size() == methods.length ? methods : result.toArray(new IMethod[result.size()]); - } - - public static SimpleName[] removeGeneratedSimpleNames(SimpleName[] in) throws Exception { - Field f = SimpleName.class.getField("$isGenerated"); - - int count = 0; - for (int i = 0; i < in.length; i++) { - if (in[i] == null || !((Boolean)f.get(in[i])).booleanValue()) count++; - } - if (count == in.length) return in; - SimpleName[] newSimpleNames = new SimpleName[count]; - count = 0; - for (int i = 0; i < in.length; i++) { - if (in[i] == null || !((Boolean)f.get(in[i])).booleanValue()) newSimpleNames[count++] = in[i]; - } - return newSimpleNames; - } - - public static byte[] runPostCompiler(byte[] bytes, String fileName) { - byte[] transformed = PostCompiler.applyTransformations(bytes, fileName, DiagnosticsReceiver.CONSOLE); - return transformed == null ? bytes : transformed; - } - - public static OutputStream runPostCompiler(OutputStream out) throws IOException { - return PostCompiler.wrapOutputStream(out, "TEST", DiagnosticsReceiver.CONSOLE); - } - - public static BufferedOutputStream runPostCompiler(BufferedOutputStream out, String path, String name) throws IOException { - String fileName = path + "/" + name; - return new BufferedOutputStream(PostCompiler.wrapOutputStream(out, fileName, DiagnosticsReceiver.CONSOLE)); - } - - public static Annotation[] convertAnnotations(Annotation[] out, IAnnotatable annotatable) { - IAnnotation[] in; - - try { - in = annotatable.getAnnotations(); - } catch (Exception e) { - return out; - } - - if (out == null) return null; - int toWrite = 0; - - for (int idx = 0; idx < out.length; idx++) { - String oName = new String(out[idx].type.getLastToken()); - boolean found = false; - for (IAnnotation i : in) { - String name = i.getElementName(); - int li = name.lastIndexOf('.'); - if (li > -1) name = name.substring(li + 1); - if (name.equals(oName)) { - found = true; - break; - } - } - if (!found) out[idx] = null; - else toWrite++; - } - - Annotation[] replace = out; - if (toWrite < out.length) { - replace = new Annotation[toWrite]; - int idx = 0; - for (int i = 0; i < out.length; i++) { - if (out[i] == null) continue; - replace[idx++] = out[i]; - } - } - - return replace; - } -} diff --git a/src/eclipseAgent/lombok/eclipse/agent/PatchFixesShadowLoaded.java b/src/eclipseAgent/lombok/eclipse/agent/PatchFixesShadowLoaded.java new file mode 100644 index 00000000..6685b6bb --- /dev/null +++ b/src/eclipseAgent/lombok/eclipse/agent/PatchFixesShadowLoaded.java @@ -0,0 +1,53 @@ +/* + * Copyright (C) 2015 The Project Lombok Authors. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +package lombok.eclipse.agent; + +import java.io.BufferedOutputStream; +import java.io.IOException; +import java.io.OutputStream; + +import lombok.core.DiagnosticsReceiver; +import lombok.core.PostCompiler; +import lombok.core.Version; + +public class PatchFixesShadowLoaded { + public static String addLombokNotesToEclipseAboutDialog(String origReturnValue, String key) { + if ("aboutText".equals(key)) { + return origReturnValue + "\n\nLombok " + Version.getFullVersion() + " is installed. http://projectlombok.org/"; + } + return origReturnValue; + } + + public static byte[] runPostCompiler(byte[] bytes, String fileName) { + byte[] transformed = PostCompiler.applyTransformations(bytes, fileName, DiagnosticsReceiver.CONSOLE); + return transformed == null ? bytes : transformed; + } + + public static OutputStream runPostCompiler(OutputStream out) throws IOException { + return PostCompiler.wrapOutputStream(out, "TEST", DiagnosticsReceiver.CONSOLE); + } + + public static BufferedOutputStream runPostCompiler(BufferedOutputStream out, String path, String name) throws IOException { + String fileName = path + "/" + name; + return new BufferedOutputStream(PostCompiler.wrapOutputStream(out, fileName, DiagnosticsReceiver.CONSOLE)); + } +} diff --git a/src/eclipseAgent/lombok/eclipse/agent/PatchVal.java b/src/eclipseAgent/lombok/eclipse/agent/PatchVal.java index e734dceb..30574ea6 100644 --- a/src/eclipseAgent/lombok/eclipse/agent/PatchVal.java +++ b/src/eclipseAgent/lombok/eclipse/agent/PatchVal.java @@ -128,7 +128,14 @@ public class PatchVal { if (!isVal(local.type, scope)) return false; - if (new Throwable().getStackTrace()[2].getClassName().contains("ForStatement")) return false; + StackTraceElement[] st = new Throwable().getStackTrace(); + for (int i = 0; i < st.length - 2 && i < 10; i++) { + if (st[i].getClassName().equals("lombok.launch.PatchFixesHider$Val")) { + if (st[i + 1].getClassName().equals("org.eclipse.jdt.internal.compiler.ast.LocalDeclaration") && + st[i + 2].getClassName().equals("org.eclipse.jdt.internal.compiler.ast.ForStatement")) return false; + break; + } + } Expression init = local.initialization; if (init == null && Reflection.initCopyField != null) { diff --git a/src/eclipseAgent/lombok/launch/PatchFixesHider.java b/src/eclipseAgent/lombok/launch/PatchFixesHider.java new file mode 100644 index 00000000..2472ca3c --- /dev/null +++ b/src/eclipseAgent/lombok/launch/PatchFixesHider.java @@ -0,0 +1,600 @@ +/* + * Copyright (C) 2010-2015 The Project Lombok Authors. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +package lombok.launch; + +import java.io.BufferedOutputStream; +import java.io.IOException; +import java.io.OutputStream; +import java.lang.reflect.Field; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.util.ArrayList; +import java.util.List; +import java.util.Stack; + +import lombok.eclipse.EclipseAugments; + +import org.eclipse.core.runtime.CoreException; +import org.eclipse.jdt.core.IAnnotatable; +import org.eclipse.jdt.core.IAnnotation; +import org.eclipse.jdt.core.IMethod; +import org.eclipse.jdt.core.IType; +import org.eclipse.jdt.core.JavaModelException; +import org.eclipse.jdt.core.dom.MethodDeclaration; +import org.eclipse.jdt.core.dom.SimpleName; +import org.eclipse.jdt.internal.compiler.ast.Annotation; +import org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration; +import org.eclipse.jdt.internal.compiler.ast.Expression; +import org.eclipse.jdt.internal.compiler.ast.ForeachStatement; +import org.eclipse.jdt.internal.compiler.ast.LocalDeclaration; +import org.eclipse.jdt.internal.compiler.ast.MessageSend; +import org.eclipse.jdt.internal.compiler.lookup.BlockScope; +import org.eclipse.jdt.internal.compiler.lookup.MethodBinding; +import org.eclipse.jdt.internal.compiler.lookup.TypeBinding; +import org.eclipse.jdt.internal.compiler.parser.Parser; +import org.eclipse.jdt.internal.compiler.problem.ProblemReporter; +import org.eclipse.jdt.internal.core.dom.rewrite.NodeRewriteEvent; +import org.eclipse.jdt.internal.core.dom.rewrite.RewriteEvent; +import org.eclipse.jdt.internal.core.dom.rewrite.TokenScanner; +import org.eclipse.jdt.internal.corext.refactoring.structure.ASTNodeSearchUtil; + +/** These contain a mix of the following: + * <ul> + * <li> 'dependency free' method wrappers that cross the shadowloader barrier. + * <li> methods that directly patch, <em>but</em>, these should ALWAYS be transplanted. + * </ul> + * + * <strong>This class lives on the outside of the shadowloader barrier, and as a consequence, cannot access any other lombok code except other + * code in the {@code lombok.launch} package!</strong>. + * <p> + * This class is package private with lots of public inner static classes. This hides all of them from IDE autocomplete dialogs and such but at the JVM + * level the inner static class are just plain public, which is important, because calls to the contents of these inner static classes are injected into + * various eclipse classes verbatim, and if they weren't public, the verifier wouldn't accept it. + */ +final class PatchFixesHider { + + /** These utility methods are only used 'internally', but because of transplant methods, the class (and its methods) still have to be public! */ + public static final class Util { + private static ClassLoader shadowLoader; + + public static Class<?> shadowLoadClass(String name) { + try { + if (shadowLoader == null) { + try { + Class.forName("lombok.core.LombokNode"); + // If we get here, then lombok is already available. + shadowLoader = Util.class.getClassLoader(); + } catch (ClassNotFoundException e) { + // If we get here, it isn't, and we should use the shadowloader. + shadowLoader = Main.createShadowClassLoader(); + } + } + + return Class.forName(name, true, shadowLoader); + } catch (ClassNotFoundException e) { + throw sneakyThrow(e); + } + } + + public static Method findMethod(Class<?> type, String name, Class<?>... parameterTypes) { + try { + return type.getDeclaredMethod(name, parameterTypes); + } catch (NoSuchMethodException e) { + throw sneakyThrow(e); + } + } + + public static Object invokeMethod(Method method, Object... args) { + try { + return method.invoke(null, args); + } catch (IllegalAccessException e) { + throw sneakyThrow(e); + } catch (InvocationTargetException e) { + throw sneakyThrow(e.getCause()); + } + } + + private static RuntimeException sneakyThrow(Throwable t) { + if (t == null) throw new NullPointerException("t"); + Util.<RuntimeException>sneakyThrow0(t); + return null; + } + + @SuppressWarnings("unchecked") + private static <T extends Throwable> void sneakyThrow0(Throwable t) throws T { + throw (T)t; + } + } + + /** Contains patch fixes that are dependent on lombok internals. */ + public static final class LombokDeps { + public static final Method ADD_LOMBOK_NOTES; + public static final Method POST_COMPILER_BYTES_STRING; + public static final Method POST_COMPILER_OUTPUTSTREAM; + public static final Method POST_COMPILER_BUFFEREDOUTPUTSTREAM_STRING_STRING; + + static { + Class<?> shadowed = Util.shadowLoadClass("lombok.eclipse.agent.PatchFixesShadowLoaded"); + ADD_LOMBOK_NOTES = Util.findMethod(shadowed, "addLombokNotesToEclipseAboutDialog", String.class, String.class); + POST_COMPILER_BYTES_STRING = Util.findMethod(shadowed, "runPostCompiler", byte[].class, String.class); + POST_COMPILER_OUTPUTSTREAM = Util.findMethod(shadowed, "runPostCompiler", OutputStream.class); + POST_COMPILER_BUFFEREDOUTPUTSTREAM_STRING_STRING = Util.findMethod(shadowed, "runPostCompiler", BufferedOutputStream.class, String.class, String.class); + } + + public static String addLombokNotesToEclipseAboutDialog(String origReturnValue, String key) { + return (String) Util.invokeMethod(LombokDeps.ADD_LOMBOK_NOTES, origReturnValue, key); + } + + public static byte[] runPostCompiler(byte[] bytes, String fileName) { + return (byte[]) Util.invokeMethod(LombokDeps.POST_COMPILER_BYTES_STRING, bytes, fileName); + } + + public static OutputStream runPostCompiler(OutputStream out) throws IOException { + return (OutputStream) Util.invokeMethod(LombokDeps.POST_COMPILER_OUTPUTSTREAM, out); + } + + public static BufferedOutputStream runPostCompiler(BufferedOutputStream out, String path, String name) throws IOException { + return (BufferedOutputStream) Util.invokeMethod(LombokDeps.POST_COMPILER_BUFFEREDOUTPUTSTREAM_STRING_STRING, out, path, name); + } + } + + public static final class Transform { + private static final Method TRANSFORM; + private static final Method TRANSFORM_SWAPPED; + + static { + Class<?> shadowed = Util.shadowLoadClass("lombok.eclipse.TransformEclipseAST"); + TRANSFORM = Util.findMethod(shadowed, "transform", Parser.class, CompilationUnitDeclaration.class); + TRANSFORM_SWAPPED = Util.findMethod(shadowed, "transform_swapped", CompilationUnitDeclaration.class, Parser.class); + } + + public static void transform(Parser parser, CompilationUnitDeclaration ast) throws IOException { + Util.invokeMethod(TRANSFORM, parser, ast); + } + + public static void transform_swapped(CompilationUnitDeclaration ast, Parser parser) throws IOException { + Util.invokeMethod(TRANSFORM_SWAPPED, ast, parser); + } + } + + /** Contains patch code to support {@code @Delegate} */ + public static final class Delegate { + private static final Method HANDLE_DELEGATE_FOR_TYPE; + + static { + Class<?> shadowed = Util.shadowLoadClass("lombok.eclipse.agent.PatchDelegatePortal"); + HANDLE_DELEGATE_FOR_TYPE = Util.findMethod(shadowed, "handleDelegateForType", Object.class); + } + + public static boolean handleDelegateForType(Object classScope) { + return (Boolean) Util.invokeMethod(HANDLE_DELEGATE_FOR_TYPE, classScope); + } + } + + /** Contains patch code to support {@code val} (eclipse specific) */ + public static final class ValPortal { + private static final Method COPY_INITIALIZATION_OF_FOR_EACH_ITERABLE; + private static final Method COPY_INITIALIZATION_OF_LOCAL_DECLARATION; + private static final Method ADD_FINAL_AND_VAL_ANNOTATION_TO_VARIABLE_DECLARATION_STATEMENT; + private static final Method ADD_FINAL_AND_VAL_ANNOTATION_TO_SINGLE_VARIABLE_DECLARATION; + + static { + Class<?> shadowed = Util.shadowLoadClass("lombok.eclipse.agent.PatchValEclipsePortal"); + COPY_INITIALIZATION_OF_FOR_EACH_ITERABLE = Util.findMethod(shadowed, "copyInitializationOfForEachIterable", Object.class); + COPY_INITIALIZATION_OF_LOCAL_DECLARATION = Util.findMethod(shadowed, "copyInitializationOfLocalDeclaration", Object.class); + ADD_FINAL_AND_VAL_ANNOTATION_TO_VARIABLE_DECLARATION_STATEMENT = Util.findMethod(shadowed, "addFinalAndValAnnotationToVariableDeclarationStatement", Object.class, Object.class, Object.class); + ADD_FINAL_AND_VAL_ANNOTATION_TO_SINGLE_VARIABLE_DECLARATION = Util.findMethod(shadowed, "addFinalAndValAnnotationToSingleVariableDeclaration", Object.class, Object.class, Object.class); + } + + public static void copyInitializationOfForEachIterable(Object parser) { + Util.invokeMethod(COPY_INITIALIZATION_OF_FOR_EACH_ITERABLE, parser); + } + + public static void copyInitializationOfLocalDeclaration(Object parser) { + Util.invokeMethod(COPY_INITIALIZATION_OF_LOCAL_DECLARATION, parser); + } + + public static void addFinalAndValAnnotationToVariableDeclarationStatement(Object converter, Object out, Object in) { + Util.invokeMethod(ADD_FINAL_AND_VAL_ANNOTATION_TO_VARIABLE_DECLARATION_STATEMENT, converter, out, in); + } + + public static void addFinalAndValAnnotationToSingleVariableDeclaration(Object converter, Object out, Object in) { + Util.invokeMethod(ADD_FINAL_AND_VAL_ANNOTATION_TO_SINGLE_VARIABLE_DECLARATION, converter, out, in); + } + } + + /** Contains patch code to support {@code val} (eclipse and ecj) */ + public static final class Val { + private static final Method SKIP_RESOLVE_INITIALIZER_IF_ALREADY_CALLED; + private static final Method SKIP_RESOLVE_INITIALIZER_IF_ALREADY_CALLED2; + private static final Method HANDLE_VAL_FOR_LOCAL_DECLARATION; + private static final Method HANDLE_VAL_FOR_FOR_EACH; + + static { + Class<?> shadowed = Util.shadowLoadClass("lombok.eclipse.agent.PatchVal"); + SKIP_RESOLVE_INITIALIZER_IF_ALREADY_CALLED = Util.findMethod(shadowed, "skipResolveInitializerIfAlreadyCalled", Expression.class, BlockScope.class); + SKIP_RESOLVE_INITIALIZER_IF_ALREADY_CALLED2 = Util.findMethod(shadowed, "skipResolveInitializerIfAlreadyCalled2", Expression.class, BlockScope.class, LocalDeclaration.class); + HANDLE_VAL_FOR_LOCAL_DECLARATION = Util.findMethod(shadowed, "handleValForLocalDeclaration", LocalDeclaration.class, BlockScope.class); + HANDLE_VAL_FOR_FOR_EACH = Util.findMethod(shadowed, "handleValForForEach", ForeachStatement.class, BlockScope.class); + } + + public static TypeBinding skipResolveInitializerIfAlreadyCalled(Expression expr, BlockScope scope) { + return (TypeBinding) Util.invokeMethod(SKIP_RESOLVE_INITIALIZER_IF_ALREADY_CALLED, expr, scope); + } + + public static TypeBinding skipResolveInitializerIfAlreadyCalled2(Expression expr, BlockScope scope, LocalDeclaration decl) { + return (TypeBinding) Util.invokeMethod(SKIP_RESOLVE_INITIALIZER_IF_ALREADY_CALLED2, expr, scope, decl); + } + + public static boolean handleValForLocalDeclaration(LocalDeclaration local, BlockScope scope) { + return (Boolean) Util.invokeMethod(HANDLE_VAL_FOR_LOCAL_DECLARATION, local, scope); + } + + public static boolean handleValForForEach(ForeachStatement forEach, BlockScope scope) { + return (Boolean) Util.invokeMethod(HANDLE_VAL_FOR_FOR_EACH, forEach, scope); + } + } + + /** Contains patch code to support {@code @ExtensionMethod} */ + public static final class ExtensionMethod { + private static final Method RESOLVE_TYPE; + private static final Method ERROR_NO_METHOD_FOR; + private static final Method INVALID_METHOD; + + static { + Class<?> shadowed = Util.shadowLoadClass("lombok.eclipse.agent.PatchExtensionMethod"); + RESOLVE_TYPE = Util.findMethod(shadowed, "resolveType", TypeBinding.class, MessageSend.class, BlockScope.class); + ERROR_NO_METHOD_FOR = Util.findMethod(shadowed, "errorNoMethodFor", ProblemReporter.class, MessageSend.class, TypeBinding.class, TypeBinding[].class); + INVALID_METHOD = Util.findMethod(shadowed, "invalidMethod", ProblemReporter.class, MessageSend.class, MethodBinding.class); + } + + public static TypeBinding resolveType(TypeBinding resolvedType, MessageSend methodCall, BlockScope scope) { + return (TypeBinding) Util.invokeMethod(RESOLVE_TYPE, resolvedType, methodCall, scope); + } + + public static void errorNoMethodFor(ProblemReporter problemReporter, MessageSend messageSend, TypeBinding recType, TypeBinding[] params) { + Util.invokeMethod(ERROR_NO_METHOD_FOR, problemReporter, messageSend, recType, params); + } + + public static void invalidMethod(ProblemReporter problemReporter, MessageSend messageSend, MethodBinding method) { + Util.invokeMethod(INVALID_METHOD, problemReporter, messageSend, method); + } + } + + /** + * Contains a mix of methods: ecj only, ecj+eclipse, and eclipse only. As a consequence, _EVERY_ method from here used for ecj MUST be + * transplanted, as ecj itself cannot load this class (signatures refer to things that don't exist in ecj-only mode). + * <p> + * Because of usage of transplant(), a bunch of these contain direct code and don't try to cross the shadowloader barrier. + */ + public static final class PatchFixes { + public static boolean isGenerated(org.eclipse.jdt.core.dom.ASTNode node) { + boolean result = false; + try { + result = ((Boolean)node.getClass().getField("$isGenerated").get(node)).booleanValue(); + if (!result && node.getParent() != null && node.getParent() instanceof org.eclipse.jdt.core.dom.QualifiedName) { + result = isGenerated(node.getParent()); + } + } catch (Exception e) { + // better to assume it isn't generated + } + return result; + } + + public static boolean isListRewriteOnGeneratedNode(org.eclipse.jdt.core.dom.rewrite.ListRewrite rewrite) { + return isGenerated(rewrite.getParent()); + } + + public static boolean returnFalse(java.lang.Object object) { + return false; + } + + public static boolean returnTrue(java.lang.Object object) { + return true; + } + + @java.lang.SuppressWarnings({"unchecked", "rawtypes"}) public static java.util.List removeGeneratedNodes(java.util.List list) { + try { + java.util.List realNodes = new java.util.ArrayList(list.size()); + for (java.lang.Object node : list) { + if(!isGenerated(((org.eclipse.jdt.core.dom.ASTNode)node))) { + realNodes.add(node); + } + } + return realNodes; + } catch (Exception e) { + } + return list; + } + + public static java.lang.String getRealMethodDeclarationSource(java.lang.String original, Object processor, org.eclipse.jdt.core.dom.MethodDeclaration declaration) throws Exception { + if (!isGenerated(declaration)) return original; + + List<org.eclipse.jdt.core.dom.Annotation> annotations = new ArrayList<org.eclipse.jdt.core.dom.Annotation>(); + for (Object modifier : declaration.modifiers()) { + if (modifier instanceof org.eclipse.jdt.core.dom.Annotation) { + org.eclipse.jdt.core.dom.Annotation annotation = (org.eclipse.jdt.core.dom.Annotation)modifier; + String qualifiedAnnotationName = annotation.resolveTypeBinding().getQualifiedName(); + if (!"java.lang.Override".equals(qualifiedAnnotationName) && !"java.lang.SuppressWarnings".equals(qualifiedAnnotationName)) annotations.add(annotation); + } + } + + StringBuilder signature = new StringBuilder(); + addAnnotations(annotations, signature); + + if ((Boolean)processor.getClass().getDeclaredField("fPublic").get(processor)) signature.append("public "); + if ((Boolean)processor.getClass().getDeclaredField("fAbstract").get(processor)) signature.append("abstract "); + + signature + .append(declaration.getReturnType2().toString()) + .append(" ").append(declaration.getName().getFullyQualifiedName()) + .append("("); + + boolean first = true; + for (Object parameter : declaration.parameters()) { + if (!first) signature.append(", "); + first = false; + // We should also add the annotations of the parameters + signature.append(parameter); + } + + signature.append(");"); + return signature.toString(); + } + + // part of getRealMethodDeclarationSource(...) + public static void addAnnotations(List<org.eclipse.jdt.core.dom.Annotation> annotations, StringBuilder signature) { + /* + * We SHOULD be able to handle the following cases: + * @Override + * @Override() + * @SuppressWarnings("all") + * @SuppressWarnings({"all", "unused"}) + * @SuppressWarnings(value = "all") + * @SuppressWarnings(value = {"all", "unused"}) + * @EqualsAndHashCode(callSuper=true, of="id") + * + * Currently, we only seem to correctly support: + * @Override + * @Override() N.B. We lose the parentheses here, since there are no values. No big deal. + * @SuppressWarnings("all") + */ + for (org.eclipse.jdt.core.dom.Annotation annotation : annotations) { + List<String> values = new ArrayList<String>(); + if (annotation.isSingleMemberAnnotation()) { + org.eclipse.jdt.core.dom.SingleMemberAnnotation smAnn = (org.eclipse.jdt.core.dom.SingleMemberAnnotation) annotation; + values.add(smAnn.getValue().toString()); + } else if (annotation.isNormalAnnotation()) { + org.eclipse.jdt.core.dom.NormalAnnotation normalAnn = (org.eclipse.jdt.core.dom.NormalAnnotation) annotation; + for (Object value : normalAnn.values()) values.add(value.toString()); + } + + signature.append("@").append(annotation.resolveTypeBinding().getQualifiedName()); + if (!values.isEmpty()) { + signature.append("("); + boolean first = true; + for (String string : values) { + if (!first) signature.append(", "); + first = false; + signature.append('"').append(string).append('"'); + } + signature.append(")"); + } + signature.append(" "); + } + } + + public static org.eclipse.jdt.core.dom.MethodDeclaration getRealMethodDeclarationNode(org.eclipse.jdt.core.IMethod sourceMethod, org.eclipse.jdt.core.dom.CompilationUnit cuUnit) throws JavaModelException { + MethodDeclaration methodDeclarationNode = ASTNodeSearchUtil.getMethodDeclarationNode(sourceMethod, cuUnit); + if (isGenerated(methodDeclarationNode)) { + IType declaringType = sourceMethod.getDeclaringType(); + Stack<IType> typeStack = new Stack<IType>(); + while (declaringType != null) { + typeStack.push(declaringType); + declaringType = declaringType.getDeclaringType(); + } + + IType rootType = typeStack.pop(); + org.eclipse.jdt.core.dom.AbstractTypeDeclaration typeDeclaration = findTypeDeclaration(rootType, cuUnit.types()); + while (!typeStack.isEmpty() && typeDeclaration != null) { + typeDeclaration = findTypeDeclaration(typeStack.pop(), typeDeclaration.bodyDeclarations()); + } + + if (typeStack.isEmpty() && typeDeclaration != null) { + String methodName = sourceMethod.getElementName(); + for (Object declaration : typeDeclaration.bodyDeclarations()) { + if (declaration instanceof org.eclipse.jdt.core.dom.MethodDeclaration) { + org.eclipse.jdt.core.dom.MethodDeclaration methodDeclaration = (org.eclipse.jdt.core.dom.MethodDeclaration) declaration; + if (methodDeclaration.getName().toString().equals(methodName)) { + return methodDeclaration; + } + } + } + } + } + return methodDeclarationNode; + } + + // part of getRealMethodDeclarationNode + public static org.eclipse.jdt.core.dom.AbstractTypeDeclaration findTypeDeclaration(IType searchType, List<?> nodes) { + for (Object object : nodes) { + if (object instanceof org.eclipse.jdt.core.dom.AbstractTypeDeclaration) { + org.eclipse.jdt.core.dom.AbstractTypeDeclaration typeDeclaration = (org.eclipse.jdt.core.dom.AbstractTypeDeclaration) object; + if (typeDeclaration.getName().toString().equals(searchType.getElementName())) + return typeDeclaration; + } + } + return null; + } + + public static int getSourceEndFixed(int sourceEnd, org.eclipse.jdt.internal.compiler.ast.ASTNode node) throws Exception { + if (sourceEnd == -1) { + org.eclipse.jdt.internal.compiler.ast.ASTNode object = (org.eclipse.jdt.internal.compiler.ast.ASTNode)node.getClass().getField("$generatedBy").get(node); + if (object != null) { + return object.sourceEnd; + } + } + return sourceEnd; + } + + public static int fixRetrieveStartingCatchPosition(int original, int start) { + return original == -1 ? start : original; + } + + public static int fixRetrieveIdentifierEndPosition(int original, int end) { + return original == -1 ? end : original; + } + + public static int fixRetrieveEllipsisStartPosition(int original, int end) { + return original == -1 ? end : original; + } + + public static int fixRetrieveRightBraceOrSemiColonPosition(int original, int end) { + return original == -1 ? end : original; // Need to fix: see issue 325. + } + + public static final int ALREADY_PROCESSED_FLAG = 0x800000; //Bit 24 + + public static boolean checkBit24(Object node) throws Exception { + int bits = (Integer)(node.getClass().getField("bits").get(node)); + return (bits & ALREADY_PROCESSED_FLAG) != 0; + } + + public static boolean skipRewritingGeneratedNodes(org.eclipse.jdt.core.dom.ASTNode node) throws Exception { + return ((Boolean) node.getClass().getField("$isGenerated").get(node)).booleanValue(); + } + + public static void setIsGeneratedFlag(org.eclipse.jdt.core.dom.ASTNode domNode, + org.eclipse.jdt.internal.compiler.ast.ASTNode internalNode) throws Exception { + + if (internalNode == null || domNode == null) return; + boolean isGenerated = EclipseAugments.ASTNode_generatedBy.get(internalNode) != null; + if (isGenerated) domNode.getClass().getField("$isGenerated").set(domNode, true); + } + + public static void setIsGeneratedFlagForName(org.eclipse.jdt.core.dom.Name name, Object internalNode) throws Exception { + if (internalNode instanceof org.eclipse.jdt.internal.compiler.ast.ASTNode) { + boolean isGenerated = EclipseAugments.ASTNode_generatedBy.get((org.eclipse.jdt.internal.compiler.ast.ASTNode) internalNode) != null; + if (isGenerated) name.getClass().getField("$isGenerated").set(name, true); + } + } + + public static RewriteEvent[] listRewriteHandleGeneratedMethods(RewriteEvent parent) { + RewriteEvent[] children = parent.getChildren(); + List<RewriteEvent> newChildren = new ArrayList<RewriteEvent>(); + List<RewriteEvent> modifiedChildren = new ArrayList<RewriteEvent>(); + for (int i = 0; i < children.length; i++) { + RewriteEvent child = children[i]; + boolean isGenerated = isGenerated((org.eclipse.jdt.core.dom.ASTNode) child.getOriginalValue()); + if (isGenerated) { + boolean isReplacedOrRemoved = child.getChangeKind() == RewriteEvent.REPLACED || child.getChangeKind() == RewriteEvent.REMOVED; + boolean convertingFromMethod = child.getOriginalValue() instanceof org.eclipse.jdt.core.dom.MethodDeclaration; + if (isReplacedOrRemoved && convertingFromMethod && child.getNewValue() != null) { + modifiedChildren.add(new NodeRewriteEvent(null, child.getNewValue())); + } + } else { + newChildren.add(child); + } + } + // Since Eclipse doesn't honor the "insert at specified location" for already existing members, + // we'll just add them last + newChildren.addAll(modifiedChildren); + return newChildren.toArray(new RewriteEvent[newChildren.size()]); + } + + public static int getTokenEndOffsetFixed(TokenScanner scanner, int token, int startOffset, Object domNode) throws CoreException { + boolean isGenerated = false; + try { + isGenerated = (Boolean) domNode.getClass().getField("$isGenerated").get(domNode); + } catch (Exception e) { + // If this fails, better to break some refactor scripts than to crash eclipse. + } + if (isGenerated) return -1; + return scanner.getTokenEndOffset(token, startOffset); + } + + public static IMethod[] removeGeneratedMethods(IMethod[] methods) throws Exception { + List<IMethod> result = new ArrayList<IMethod>(); + for (IMethod m : methods) { + if (m.getNameRange().getLength() > 0 && !m.getNameRange().equals(m.getSourceRange())) result.add(m); + } + return result.size() == methods.length ? methods : result.toArray(new IMethod[result.size()]); + } + + public static SimpleName[] removeGeneratedSimpleNames(SimpleName[] in) throws Exception { + Field f = SimpleName.class.getField("$isGenerated"); + + int count = 0; + for (int i = 0; i < in.length; i++) { + if (in[i] == null || !((Boolean)f.get(in[i])).booleanValue()) count++; + } + if (count == in.length) return in; + SimpleName[] newSimpleNames = new SimpleName[count]; + count = 0; + for (int i = 0; i < in.length; i++) { + if (in[i] == null || !((Boolean)f.get(in[i])).booleanValue()) newSimpleNames[count++] = in[i]; + } + return newSimpleNames; + } + + public static Annotation[] convertAnnotations(Annotation[] out, IAnnotatable annotatable) { + IAnnotation[] in; + + try { + in = annotatable.getAnnotations(); + } catch (Exception e) { + return out; + } + + if (out == null) return null; + int toWrite = 0; + + for (int idx = 0; idx < out.length; idx++) { + String oName = new String(out[idx].type.getLastToken()); + boolean found = false; + for (IAnnotation i : in) { + String name = i.getElementName(); + int li = name.lastIndexOf('.'); + if (li > -1) name = name.substring(li + 1); + if (name.equals(oName)) { + found = true; + break; + } + } + if (!found) out[idx] = null; + else toWrite++; + } + + Annotation[] replace = out; + if (toWrite < out.length) { + replace = new Annotation[toWrite]; + int idx = 0; + for (int i = 0; i < out.length; i++) { + if (out[i] == null) continue; + replace[idx++] = out[i]; + } + } + + return replace; + } + } +} diff --git a/src/installer/lombok/installer/InstallerGUI.java b/src/installer/lombok/installer/InstallerGUI.java index 41832e5d..6b8a58ab 100644 --- a/src/installer/lombok/installer/InstallerGUI.java +++ b/src/installer/lombok/installer/InstallerGUI.java @@ -101,6 +101,7 @@ public class InstallerGUI { public InstallerGUI() { appWindow = new JFrame(String.format("Project Lombok v%s - Installer", Version.getVersion())); + appWindow.setLocationByPlatform(true); appWindow.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); appWindow.setResizable(false); appWindow.setIconImage(Toolkit.getDefaultToolkit().getImage(Installer.class.getResource("lombokIcon.png"))); diff --git a/src/launch/lombok/launch/ShadowClassLoader.java b/src/launch/lombok/launch/ShadowClassLoader.java index 79809b2f..b883bd71 100644 --- a/src/launch/lombok/launch/ShadowClassLoader.java +++ b/src/launch/lombok/launch/ShadowClassLoader.java @@ -211,24 +211,26 @@ class ShadowClassLoader extends ClassLoader { if (!location.isFile() || !location.canRead()) return null; - String absolutePath; { + File absoluteFile; { try { - absolutePath = location.getCanonicalPath(); + absoluteFile = location.getCanonicalFile(); } catch (Exception e) { - absolutePath = location.getAbsolutePath(); + absoluteFile = location.getAbsoluteFile(); } } - List<String> jarContents = getOrMakeJarListing(absolutePath); + List<String> jarContents = getOrMakeJarListing(absoluteFile.getAbsolutePath()); + + String absoluteUri = absoluteFile.toURI().toString(); try { if (jarContents.contains(altName)) { - return new URI("jar:file:" + absolutePath + "!/" + altName).toURL(); + return new URI("jar:" + absoluteUri + "!/" + altName).toURL(); } } catch (Exception e) {} try { if (jarContents.contains(name)) { - return new URI("jar:file:" + absolutePath + "!/" + name).toURL(); + return new URI("jar:" + absoluteUri + "!/" + name).toURL(); } } catch(Exception e) {} diff --git a/src/utils/lombok/core/LombokImmutableList.java b/src/utils/lombok/core/LombokImmutableList.java index e0e1136c..4603f2ad 100644 --- a/src/utils/lombok/core/LombokImmutableList.java +++ b/src/utils/lombok/core/LombokImmutableList.java @@ -80,6 +80,12 @@ public final class LombokImmutableList<T> implements Iterable<T> { return copyOf(list); } + public static <T> LombokImmutableList<T> copyOf(T[] array) { + Object[] content = new Object[array.length]; + System.arraycopy(array, 0, content, 0, array.length); + return new LombokImmutableList<T>(content); + } + private LombokImmutableList(Object[] content) { this.content = content; } diff --git a/src/utils/lombok/javac/Javac.java b/src/utils/lombok/javac/Javac.java index e207c44a..003281ad 100644 --- a/src/utils/lombok/javac/Javac.java +++ b/src/utils/lombok/javac/Javac.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2009-2013 The Project Lombok Authors. + * Copyright (C) 2009-2015 The Project Lombok Authors. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -162,9 +162,16 @@ public class Javac { public static final TypeTag CTC_VOID = typeTag("VOID"); public static final TypeTag CTC_NONE = typeTag("NONE"); public static final TypeTag CTC_BOT = typeTag("BOT"); + public static final TypeTag CTC_ERROR = typeTag("ERROR"); + public static final TypeTag CTC_UNKNOWN = typeTag("UNKNOWN"); + public static final TypeTag CTC_UNDETVAR = typeTag("UNDETVAR"); public static final TypeTag CTC_CLASS = typeTag("CLASS"); public static final TreeTag CTC_NOT_EQUAL = treeTag("NE"); + public static final TreeTag CTC_LESS_THAN = treeTag("LT"); + public static final TreeTag CTC_GREATER_THAN = treeTag("GT"); + public static final TreeTag CTC_LESS_OR_EQUAL= treeTag("LE"); + public static final TreeTag CTC_GREATER_OR_EQUAL = treeTag("GE"); public static final TreeTag CTC_POS = treeTag("POS"); public static final TreeTag CTC_NEG = treeTag("NEG"); public static final TreeTag CTC_NOT = treeTag("NOT"); @@ -172,10 +179,14 @@ public class Javac { public static final TreeTag CTC_BITXOR = treeTag("BITXOR"); public static final TreeTag CTC_UNSIGNED_SHIFT_RIGHT = treeTag("USR"); public static final TreeTag CTC_MUL = treeTag("MUL"); + public static final TreeTag CTC_DIV = treeTag("DIV"); public static final TreeTag CTC_PLUS = treeTag("PLUS"); + public static final TreeTag CTC_MINUS = treeTag("MINUS"); public static final TreeTag CTC_EQUAL = treeTag("EQ"); public static final TreeTag CTC_PREINC = treeTag("PREINC"); public static final TreeTag CTC_PREDEC = treeTag("PREDEC"); + public static final TreeTag CTC_POSTINC = treeTag("POSTINC"); + public static final TreeTag CTC_POSTDEC = treeTag("POSTDEC"); private static final Method getExtendsClause, getEndPosition, storeEnd; diff --git a/src/utils/lombok/javac/TreeMirrorMaker.java b/src/utils/lombok/javac/TreeMirrorMaker.java index 23ec2406..093839d7 100644 --- a/src/utils/lombok/javac/TreeMirrorMaker.java +++ b/src/utils/lombok/javac/TreeMirrorMaker.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2010-2011 The Project Lombok Authors. + * Copyright (C) 2010-2015 The Project Lombok Authors. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -26,11 +26,19 @@ import java.util.IdentityHashMap; import java.util.Iterator; import java.util.Map; +import static lombok.javac.Javac.*; +import lombok.javac.JavacTreeMaker.TypeTag; + +import com.sun.source.tree.ClassTree; import com.sun.source.tree.LabeledStatementTree; +import com.sun.source.tree.NewClassTree; import com.sun.source.tree.VariableTree; import com.sun.tools.javac.tree.JCTree; +import com.sun.tools.javac.tree.JCTree.JCClassDecl; +import com.sun.tools.javac.tree.JCTree.JCNewClass; import com.sun.tools.javac.tree.JCTree.JCVariableDecl; import com.sun.tools.javac.tree.TreeCopier; +import com.sun.tools.javac.util.Context; import com.sun.tools.javac.util.List; /** @@ -46,7 +54,7 @@ import com.sun.tools.javac.util.List; public class TreeMirrorMaker extends TreeCopier<Void> { private final IdentityHashMap<JCTree, JCTree> originalToCopy = new IdentityHashMap<JCTree, JCTree>(); - public TreeMirrorMaker(JavacTreeMaker maker) { + public TreeMirrorMaker(JavacTreeMaker maker, Context context) { super(maker.getUnderlyingTreeMaker()); } @@ -86,11 +94,27 @@ public class TreeMirrorMaker extends TreeCopier<Void> { return Collections.unmodifiableMap(originalToCopy); } - // Fix for NPE in HandleVal. See http://code.google.com/p/projectlombok/issues/detail?id=205 - // Maybe this should be done elsewhere... + // Monitor issue 205 and issue 694 when making changes here. @Override public JCTree visitVariable(VariableTree node, Void p) { + JCVariableDecl original = node instanceof JCVariableDecl ? (JCVariableDecl) node : null; JCVariableDecl copy = (JCVariableDecl) super.visitVariable(node, p); - copy.sym = ((JCVariableDecl) node).sym; + if (original == null) return copy; + + copy.sym = original.sym; + if (copy.sym != null) copy.type = original.type; + if (copy.type != null) { + boolean wipeSymAndType = copy.type.isErroneous(); + if (!wipeSymAndType) { + TypeTag typeTag = TypeTag.typeTag(copy.type); + wipeSymAndType = (CTC_NONE.equals(typeTag) || CTC_ERROR.equals(typeTag) || CTC_UNKNOWN.equals(typeTag) || CTC_UNDETVAR.equals(typeTag)); + } + + if (wipeSymAndType) { + copy.sym = null; + copy.type = null; + } + } + return copy; } @@ -99,4 +123,14 @@ public class TreeMirrorMaker extends TreeCopier<Void> { @Override public JCTree visitLabeledStatement(LabeledStatementTree node, Void p) { return node.getStatement().accept(this, p); } + + @Override public JCTree visitNewClass(NewClassTree node, Void p) { + JCNewClass copy = (JCNewClass) super.visitNewClass(node, p); + return copy; + } + + @Override public JCTree visitClass(ClassTree node, Void p) { + JCClassDecl copy = (JCClassDecl) super.visitClass(node, p); + return copy; + } } diff --git a/test/configuration/resource/configurationRoot/out.txt b/test/configuration/resource/configurationRoot/out.txt index 625115a4..de219694 100644 --- a/test/configuration/resource/configurationRoot/out.txt +++ b/test/configuration/resource/configurationRoot/out.txt @@ -8,7 +8,7 @@ lombok.accessors.flagUsage = ERROR # BASE/d1/d11/lombok.config: # 3: lombok.accessors.flagUsage = ERROR -# Generate setters that return 'this' instead of 'void'. +# Generate setters that return 'this' instead of 'void' (default: false). lombok.accessors.chain = false # BASE/d1/lombok.config: # <'lombok.accessors.chain' not mentioned> @@ -24,7 +24,7 @@ lombok.accessors.prefix += f # BASE/d1/d11/lombok.config: # 4: lombok.accessors.prefix += f -# Use this name for the generated logger fields (default: 'log') +# Use this name for the generated logger fields (default: 'log'). clear lombok.log.fieldName @@ -43,7 +43,7 @@ lombok.accessors.flagUsage = ERROR # BASE/d1/d11/d111/lombok.config: # <'lombok.accessors.flagUsage' not mentioned> -# Generate setters that return 'this' instead of 'void'. +# Generate setters that return 'this' instead of 'void' (default: false). clear lombok.accessors.chain # BASE/d1/lombok.config: # <'lombok.accessors.chain' not mentioned> @@ -66,7 +66,7 @@ lombok.accessors.prefix += m_ # BASE/d1/d11/d111/lombok.config: # 2: lombok.accessors.prefix += m_ -# Use this name for the generated logger fields (default: 'log') +# Use this name for the generated logger fields (default: 'log'). clear lombok.log.fieldName @@ -75,7 +75,7 @@ Configuration for 'BASE/d1/d12'. # Emit a warning or error if @Accessors is used. clear lombok.accessors.flagUsage -# Generate setters that return 'this' instead of 'void'. +# Generate setters that return 'this' instead of 'void' (default: false). lombok.accessors.chain = true # BASE/d1/lombok.config: # <'lombok.accessors.chain' not mentioned> @@ -86,5 +86,5 @@ lombok.accessors.chain = true # Strip this field prefix, like 'f' or 'm_', from the names of generated getters and setters. clear lombok.accessors.prefix -# Use this name for the generated logger fields (default: 'log') +# Use this name for the generated logger fields (default: 'log'). clear lombok.log.fieldName
\ No newline at end of file diff --git a/test/core/src/lombok/AbstractRunTests.java b/test/core/src/lombok/AbstractRunTests.java index a1f535b4..4e1c83dd 100644 --- a/test/core/src/lombok/AbstractRunTests.java +++ b/test/core/src/lombok/AbstractRunTests.java @@ -35,6 +35,7 @@ import java.util.Collection; import java.util.Iterator; import java.util.LinkedHashSet; import java.util.List; +import java.util.Map; import org.junit.Assert; @@ -75,7 +76,7 @@ public abstract class AbstractRunTests { } }); - transformCode(messages, writer, file); + transformCode(messages, writer, file, sourceDirectives.getSpecifiedEncoding(), sourceDirectives.getFormatPreferences()); compare(file.getName(), expected, writer.toString(), messages, params.printErrors(), sourceDirectives.isSkipCompareContent() || expected.isSkipCompareContent()); return true; @@ -97,7 +98,7 @@ public abstract class AbstractRunTests { return 8; } - protected abstract void transformCode(Collection<CompilerMessage> messages, StringWriter result, File file) throws Throwable; + protected abstract void transformCode(Collection<CompilerMessage> messages, StringWriter result, File file, String encoding, Map<String, String> formatPreferences) throws Throwable; protected String readFile(File file) throws IOException { BufferedReader reader; diff --git a/test/core/src/lombok/LombokTestSource.java b/test/core/src/lombok/LombokTestSource.java index 402001e9..c686bf19 100644 --- a/test/core/src/lombok/LombokTestSource.java +++ b/test/core/src/lombok/LombokTestSource.java @@ -29,7 +29,9 @@ import java.io.IOException; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.Collections; +import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -45,11 +47,13 @@ public class LombokTestSource { private final File file; private final String content; private final LombokImmutableList<CompilerMessageMatcher> messages; + private final Map<String, String> formatPreferences; private final boolean ignore; private final boolean skipCompareContent; private final int versionLowerLimit, versionUpperLimit; private final ConfigurationResolver configuration; - + private final String specifiedEncoding; + public boolean versionWithinLimit(int version) { return version >= versionLowerLimit && version <= versionUpperLimit; } @@ -74,10 +78,18 @@ public class LombokTestSource { return skipCompareContent; } + public String getSpecifiedEncoding() { + return specifiedEncoding; + } + public ConfigurationResolver getConfiguration() { return configuration; } + public Map<String, String> getFormatPreferences() { + return formatPreferences; + } + private static final Pattern VERSION_STYLE_1 = Pattern.compile("^(\\d+)$"); private static final Pattern VERSION_STYLE_2 = Pattern.compile("^\\:(\\d+)$"); private static final Pattern VERSION_STYLE_3 = Pattern.compile("^(\\d+):$"); @@ -123,6 +135,8 @@ public class LombokTestSource { int versionUpper = Integer.MAX_VALUE; boolean ignore = false; boolean skipCompareContent = false; + String encoding = null; + Map<String, String> formats = new HashMap<String, String>(); for (String directive : directives) { directive = directive.trim(); @@ -154,10 +168,27 @@ public class LombokTestSource { continue; } + if (lc.startsWith("encoding:")) { + encoding = directive.substring(9).trim(); + continue; + } + + if (lc.startsWith("format:")) { + String formatLine = directive.substring(7).trim(); + int idx = formatLine.indexOf('='); + if (idx == -1) throw new IllegalArgumentException("To add a format directive, use: \"//FORMAT: javaLangAsFQN = skip\""); + String key = formatLine.substring(0, idx).trim(); + String value = formatLine.substring(idx + 1).trim(); + formats.put(key.toLowerCase(), value); + continue; + } + + if (lc.startsWith("issue ")) continue; + Assert.fail("Directive line \"" + directive + "\" in '" + file.getAbsolutePath() + "' invalid: unrecognized directive."); throw new RuntimeException(); } - + this.specifiedEncoding = encoding; this.versionLowerLimit = versionLower; this.versionUpperLimit = versionUpper; this.ignore = ignore; @@ -169,6 +200,7 @@ public class LombokTestSource { }; this.configuration = new BubblingConfigurationResolver(Collections.singleton(StringConfigurationSource.forString(conf, reporter, file.getAbsolutePath()))); + this.formatPreferences = Collections.unmodifiableMap(formats); } public static LombokTestSource readDirectives(File file) throws IOException { @@ -194,13 +226,17 @@ public class LombokTestSource { } public static LombokTestSource read(File sourceFolder, File messagesFolder, String fileName) throws IOException { + return read0(sourceFolder, messagesFolder, fileName, "UTF-8"); + } + + private static LombokTestSource read0(File sourceFolder, File messagesFolder, String fileName, String encoding) throws IOException { StringBuilder content = null; List<String> directives = new ArrayList<String>(); File sourceFile = new File(sourceFolder, fileName); if (sourceFile.exists()) { @Cleanup val rawIn = new FileInputStream(sourceFile); - BufferedReader in = new BufferedReader(new InputStreamReader(rawIn, "UTF-8")); + BufferedReader in = new BufferedReader(new InputStreamReader(rawIn, encoding)); for (String i = in.readLine(); i != null; i = in.readLine()) { if (content != null) { content.append(i).append("\n"); @@ -234,6 +270,15 @@ public class LombokTestSource { } } - return new LombokTestSource(sourceFile, content.toString(), messages, directives); + LombokTestSource source = new LombokTestSource(sourceFile, content.toString(), messages, directives); + String specifiedEncoding = source.getSpecifiedEncoding(); + + // The source file has an 'encoding' header to test encoding issues. Of course, reading the encoding header + // requires knowing the encoding of the file first. In practice we get away with it, because UTF-8 and US-ASCII are compatible enough. + // The fix is therefore to read in as UTF-8 initially, and if the file requests that it should be read as another encoding, toss it all + // and reread that way. + + if (specifiedEncoding == null || specifiedEncoding.equalsIgnoreCase(encoding)) return source; + return read0(sourceFolder, messagesFolder, fileName, specifiedEncoding); } } diff --git a/test/core/src/lombok/RunAllTests.java b/test/core/src/lombok/RunAllTests.java index 9f56b45b..1ca76af5 100644 --- a/test/core/src/lombok/RunAllTests.java +++ b/test/core/src/lombok/RunAllTests.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2011-2014 The Project Lombok Authors. + * Copyright (C) 2011-2015 The Project Lombok Authors. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -26,6 +26,6 @@ import org.junit.runners.Suite; import org.junit.runners.Suite.SuiteClasses; @RunWith(Suite.class) -@SuiteClasses({lombok.transform.RunTransformTests.class, lombok.bytecode.RunBytecodeTests.class, lombok.core.configuration.RunConfigurationTests.class}) +@SuiteClasses({lombok.transform.RunTransformTests.class, lombok.bytecode.RunBytecodeTests.class, lombok.core.configuration.RunConfigurationTests.class, lombok.core.RunCoreTests.class}) public class RunAllTests { } diff --git a/test/core/src/lombok/RunTestsViaDelombok.java b/test/core/src/lombok/RunTestsViaDelombok.java index 6a08642b..8ec41ef1 100644 --- a/test/core/src/lombok/RunTestsViaDelombok.java +++ b/test/core/src/lombok/RunTestsViaDelombok.java @@ -25,6 +25,7 @@ import java.io.File; import java.io.StringWriter; import java.util.Collection; import java.util.Locale; +import java.util.Map; import lombok.delombok.Delombok; import lombok.javac.CapturingDiagnosticListener; @@ -34,10 +35,11 @@ public class RunTestsViaDelombok extends AbstractRunTests { private Delombok delombok = new Delombok(); @Override - public void transformCode(Collection<CompilerMessage> messages, StringWriter result, final File file) throws Throwable { + public void transformCode(Collection<CompilerMessage> messages, StringWriter result, final File file, String encoding, Map<String, String> formatPreferences) throws Throwable { delombok.setVerbose(false); delombok.setForceProcess(true); - delombok.setCharset("UTF-8"); + delombok.setCharset(encoding == null ? "UTF-8" : encoding); + delombok.setFormatPreferences(formatPreferences); delombok.setDiagnosticsListener(new CapturingDiagnosticListener(file, messages)); diff --git a/test/core/src/lombok/RunTestsViaEcj.java b/test/core/src/lombok/RunTestsViaEcj.java index f4584493..272ed8b7 100644 --- a/test/core/src/lombok/RunTestsViaEcj.java +++ b/test/core/src/lombok/RunTestsViaEcj.java @@ -93,7 +93,7 @@ public class RunTestsViaEcj extends AbstractRunTests { } @Override - public void transformCode(Collection<CompilerMessage> messages, StringWriter result, File file) throws Throwable { + public void transformCode(Collection<CompilerMessage> messages, StringWriter result, File file, String encoding, Map<String, String> formatPreferences) throws Throwable { final AtomicReference<CompilationResult> compilationResult_ = new AtomicReference<CompilationResult>(); final AtomicReference<CompilationUnitDeclaration> compilationUnit_ = new AtomicReference<CompilationUnitDeclaration>(); ICompilerRequestor bitbucketRequestor = new ICompilerRequestor() { @@ -103,7 +103,7 @@ public class RunTestsViaEcj extends AbstractRunTests { }; String source = readFile(file); - final CompilationUnit sourceUnit = new CompilationUnit(source.toCharArray(), file.getName(), "UTF-8"); + final CompilationUnit sourceUnit = new CompilationUnit(source.toCharArray(), file.getName(), encoding == null ? "UTF-8" : encoding); Compiler ecjCompiler = new Compiler(createFileSystem(file), ecjErrorHandlingPolicy(), ecjCompilerOptions(), bitbucketRequestor, new DefaultProblemFactory(Locale.ENGLISH)) { @Override protected synchronized void addCompilationUnit(ICompilationUnit inUnit, CompilationUnitDeclaration parsedUnit) { @@ -112,8 +112,6 @@ public class RunTestsViaEcj extends AbstractRunTests { } }; - // TODO: Create a configuration based on confLines and set this up so that this compile run will use them. - ecjCompiler.compile(new ICompilationUnit[] {sourceUnit}); CompilationResult compilationResult = compilationResult_.get(); @@ -137,12 +135,15 @@ public class RunTestsViaEcj extends AbstractRunTests { i.remove(); } } + classpath.add("bin"); classpath.add("dist/lombok.jar"); classpath.add("lib/test/commons-logging-commons-logging.jar"); classpath.add("lib/test/org.slf4j-slf4j-api.jar"); classpath.add("lib/test/org.slf4j-slf4j-ext.jar"); classpath.add("lib/test/log4j-log4j.jar"); classpath.add("lib/test/org.apache.logging.log4j-log4j-api.jar"); + classpath.add("lib/test/com.google.guava-guava.jar"); + classpath.add("lib/test/com.google.code.findbugs-findbugs.jar"); return new FileSystem(classpath.toArray(new String[0]), new String[] {file.getAbsolutePath()}, "UTF-8"); } } diff --git a/test/core/src/lombok/core/RunCoreTests.java b/test/core/src/lombok/core/RunCoreTests.java new file mode 100644 index 00000000..8ac7cf81 --- /dev/null +++ b/test/core/src/lombok/core/RunCoreTests.java @@ -0,0 +1,31 @@ +/* + * Copyright (C) 2015 The Project Lombok Authors. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +package lombok.core; + +import org.junit.runner.RunWith; +import org.junit.runners.Suite; +import org.junit.runners.Suite.SuiteClasses; + +@RunWith(Suite.class) +@SuiteClasses({TestSingulars.class}) +public class RunCoreTests { +} diff --git a/test/core/src/lombok/core/TestSingulars.java b/test/core/src/lombok/core/TestSingulars.java new file mode 100644 index 00000000..1134af08 --- /dev/null +++ b/test/core/src/lombok/core/TestSingulars.java @@ -0,0 +1,52 @@ +/* + * Copyright (C) 2015 The Project Lombok Authors. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +package lombok.core; + +import static lombok.core.handlers.Singulars.autoSingularize; +import static org.junit.Assert.assertEquals; + +import org.junit.Test; + +public class TestSingulars { + @Test + public void testSingulars() { + assertEquals(null, autoSingularize("axes")); + assertEquals("adjective", autoSingularize("adjectives")); + assertEquals("bus", autoSingularize("buses")); + assertEquals("octopus", autoSingularize("octopodes")); + assertEquals(null, autoSingularize("octopi")); + assertEquals("elf", autoSingularize("elves")); + assertEquals("jack", autoSingularize("jacks")); + assertEquals("colloquy", autoSingularize("colloquies")); + assertEquals(null, autoSingularize("series")); + assertEquals("man", autoSingularize("men")); + assertEquals(null, autoSingularize("highwaymen")); + assertEquals("caveMan", autoSingularize("caveMen")); + assertEquals(null, autoSingularize("jackss")); + assertEquals(null, autoSingularize("virus")); + assertEquals("quiz", autoSingularize("quizzes")); + assertEquals("database", autoSingularize("databases")); + assertEquals("dataBase", autoSingularize("dataBases")); + assertEquals("Query", autoSingularize("Queries")); + assertEquals("Movie", autoSingularize("Movies")); + } +} diff --git a/test/transform/resource/after-delombok/Accessors.java b/test/transform/resource/after-delombok/Accessors.java index 0d15fe43..3346bacb 100644 --- a/test/transform/resource/after-delombok/Accessors.java +++ b/test/transform/resource/after-delombok/Accessors.java @@ -1,10 +1,12 @@ class AccessorsFluent { private String fieldName = ""; @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public String fieldName() { return this.fieldName; } @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public AccessorsFluent fieldName(final String fieldName) { this.fieldName = fieldName; return this; @@ -14,14 +16,17 @@ class AccessorsFluentOnClass { private String fieldName = ""; private String otherFieldWithOverride = ""; @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public String fieldName() { return this.fieldName; } @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public String getOtherFieldWithOverride() { return this.otherFieldWithOverride; } @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public AccessorsFluentOnClass fieldName(final String fieldName) { this.fieldName = fieldName; return this; @@ -30,6 +35,7 @@ class AccessorsFluentOnClass { class AccessorsChain { private boolean isRunning; @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public AccessorsChain setRunning(final boolean isRunning) { this.isRunning = isRunning; return this; @@ -39,6 +45,7 @@ class AccessorsPrefix { private String fieldName; private String fActualField; @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public void setActualField(final String fActualField) { this.fActualField = fActualField; } @@ -47,10 +54,12 @@ class AccessorsPrefix2 { private String fieldName; private String fActualField; @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public void setFieldName(final String fieldName) { this.fieldName = fieldName; } @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public void setActualField(final String fActualField) { this.fActualField = fActualField; } @@ -62,11 +71,13 @@ class AccessorsPrefix3 { } @java.lang.Override @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public java.lang.String toString() { return "AccessorsPrefix3(fName=" + this.getName() + ")"; } @java.lang.Override @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public boolean equals(final java.lang.Object o) { if (o == this) return true; if (!(o instanceof AccessorsPrefix3)) return false; @@ -78,11 +89,13 @@ class AccessorsPrefix3 { return true; } @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") protected boolean canEqual(final java.lang.Object other) { return other instanceof AccessorsPrefix3; } @java.lang.Override @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public int hashCode() { final int PRIME = 59; int result = 1; @@ -94,6 +107,7 @@ class AccessorsPrefix3 { class AccessorsFluentGenerics<T extends Number> { private String name; @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public AccessorsFluentGenerics<T> name(final String name) { this.name = name; return this; @@ -102,6 +116,7 @@ class AccessorsFluentGenerics<T extends Number> { class AccessorsFluentNoChaining { private String name; @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public void name(final String name) { this.name = name; } @@ -109,6 +124,7 @@ class AccessorsFluentNoChaining { class AccessorsFluentStatic<T extends Number> { private static String name; @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public static void name(final String name) { AccessorsFluentStatic.name = name; } diff --git a/test/transform/resource/after-delombok/AccessorsConfiguration.java b/test/transform/resource/after-delombok/AccessorsConfiguration.java index fd60b152..84a686c8 100644 --- a/test/transform/resource/after-delombok/AccessorsConfiguration.java +++ b/test/transform/resource/after-delombok/AccessorsConfiguration.java @@ -1,10 +1,12 @@ class AccessorsConfiguration { private String m_FieldName = ""; @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public String fieldName() { return this.m_FieldName; } @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public void fieldName(final String m_FieldName) { this.m_FieldName = m_FieldName; } @@ -12,6 +14,7 @@ class AccessorsConfiguration { class AccessorsConfiguration2 { private String m_FieldName = ""; @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public void setM_FieldName(final String m_FieldName) { this.m_FieldName = m_FieldName; } @@ -19,6 +22,7 @@ class AccessorsConfiguration2 { class AccessorsConfiguration3 { private String fFieldName = ""; @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public AccessorsConfiguration3 setFieldName(final String fFieldName) { this.fFieldName = fFieldName; return this; diff --git a/test/transform/resource/after-delombok/BuilderChainAndFluent.java b/test/transform/resource/after-delombok/BuilderChainAndFluent.java index d4975bff..244df7db 100644 --- a/test/transform/resource/after-delombok/BuilderChainAndFluent.java +++ b/test/transform/resource/after-delombok/BuilderChainAndFluent.java @@ -1,30 +1,37 @@ class BuilderChainAndFluent { private final int yes; @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") BuilderChainAndFluent(final int yes) { this.yes = yes; } @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public static class BuilderChainAndFluentBuilder { private int yes; @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") BuilderChainAndFluentBuilder() { } @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public void setYes(final int yes) { this.yes = yes; } @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public BuilderChainAndFluent build() { return new BuilderChainAndFluent(yes); } @java.lang.Override @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public java.lang.String toString() { return "BuilderChainAndFluent.BuilderChainAndFluentBuilder(yes=" + this.yes + ")"; } } @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public static BuilderChainAndFluentBuilder builder() { return new BuilderChainAndFluentBuilder(); } diff --git a/test/transform/resource/after-delombok/BuilderComplex.java b/test/transform/resource/after-delombok/BuilderComplex.java index 3c97f92a..21ff89cb 100644 --- a/test/transform/resource/after-delombok/BuilderComplex.java +++ b/test/transform/resource/after-delombok/BuilderComplex.java @@ -3,45 +3,54 @@ class BuilderComplex { private static <T extends Number> void testVoidWithGenerics(T number, int arg2, String arg3, BuilderComplex selfRef) { } @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public static class VoidBuilder<T extends Number> { private T number; private int arg2; private String arg3; private BuilderComplex selfRef; @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") VoidBuilder() { } @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public VoidBuilder<T> number(final T number) { this.number = number; return this; } @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public VoidBuilder<T> arg2(final int arg2) { this.arg2 = arg2; return this; } @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public VoidBuilder<T> arg3(final String arg3) { this.arg3 = arg3; return this; } @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public VoidBuilder<T> selfRef(final BuilderComplex selfRef) { this.selfRef = selfRef; return this; } @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public void execute() { BuilderComplex.<T>testVoidWithGenerics(number, arg2, arg3, selfRef); } @java.lang.Override @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public java.lang.String toString() { return "BuilderComplex.VoidBuilder(number=" + this.number + ", arg2=" + this.arg2 + ", arg3=" + this.arg3 + ", selfRef=" + this.selfRef + ")"; } } @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public static <T extends Number> VoidBuilder<T> builder() { return new VoidBuilder<T>(); } diff --git a/test/transform/resource/after-delombok/BuilderSimple.java b/test/transform/resource/after-delombok/BuilderSimple.java index 11c0e58c..f1b6b3bc 100644 --- a/test/transform/resource/after-delombok/BuilderSimple.java +++ b/test/transform/resource/after-delombok/BuilderSimple.java @@ -5,38 +5,46 @@ class BuilderSimple<T> { private List<T> also; private int $butNotMe; @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") BuilderSimple(final int yes, final List<T> also) { this.yes = yes; this.also = also; } @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public static class BuilderSimpleBuilder<T> { private int yes; private List<T> also; @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") BuilderSimpleBuilder() { } @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public BuilderSimpleBuilder<T> yes(final int yes) { this.yes = yes; return this; } @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public BuilderSimpleBuilder<T> also(final List<T> also) { this.also = also; return this; } @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public BuilderSimple<T> build() { return new BuilderSimple<T>(yes, also); } @java.lang.Override @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public java.lang.String toString() { return "BuilderSimple.BuilderSimpleBuilder(yes=" + this.yes + ", also=" + this.also + ")"; } } @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public static <T> BuilderSimpleBuilder<T> builder() { return new BuilderSimpleBuilder<T>(); } diff --git a/test/transform/resource/after-delombok/BuilderSingularGuavaListsSets.java b/test/transform/resource/after-delombok/BuilderSingularGuavaListsSets.java new file mode 100644 index 00000000..21659de1 --- /dev/null +++ b/test/transform/resource/after-delombok/BuilderSingularGuavaListsSets.java @@ -0,0 +1,107 @@ +import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableCollection; +import com.google.common.collect.ImmutableSet; +import com.google.common.collect.ImmutableSortedSet; +class BuilderSingularGuavaListsSets<T> { + private ImmutableList<T> cards; + private ImmutableCollection<? extends Number> frogs; + @SuppressWarnings("all") + private ImmutableSet rawSet; + private ImmutableSortedSet<String> passes; + @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") + BuilderSingularGuavaListsSets(final ImmutableList<T> cards, final ImmutableCollection<? extends Number> frogs, final ImmutableSet rawSet, final ImmutableSortedSet<String> passes) { + this.cards = cards; + this.frogs = frogs; + this.rawSet = rawSet; + this.passes = passes; + } + @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") + public static class BuilderSingularGuavaListsSetsBuilder<T> { + private com.google.common.collect.ImmutableList.Builder<T> cards; + private com.google.common.collect.ImmutableList.Builder<Number> frogs; + private com.google.common.collect.ImmutableSet.Builder<java.lang.Object> rawSet; + private com.google.common.collect.ImmutableSortedSet.Builder<String> passes; + @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") + BuilderSingularGuavaListsSetsBuilder() { + } + @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") + public BuilderSingularGuavaListsSetsBuilder<T> card(final T card) { + if (this.cards == null) this.cards = com.google.common.collect.ImmutableList.builder(); + this.cards.add(card); + return this; + } + @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") + public BuilderSingularGuavaListsSetsBuilder<T> cards(final java.lang.Iterable<? extends T> cards) { + if (this.cards == null) this.cards = com.google.common.collect.ImmutableList.builder(); + this.cards.addAll(cards); + return this; + } + @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") + public BuilderSingularGuavaListsSetsBuilder<T> frog(final Number frog) { + if (this.frogs == null) this.frogs = com.google.common.collect.ImmutableList.builder(); + this.frogs.add(frog); + return this; + } + @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") + public BuilderSingularGuavaListsSetsBuilder<T> frogs(final java.lang.Iterable<? extends Number> frogs) { + if (this.frogs == null) this.frogs = com.google.common.collect.ImmutableList.builder(); + this.frogs.addAll(frogs); + return this; + } + @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") + public BuilderSingularGuavaListsSetsBuilder<T> rawSet(final java.lang.Object rawSet) { + if (this.rawSet == null) this.rawSet = com.google.common.collect.ImmutableSet.builder(); + this.rawSet.add(rawSet); + return this; + } + @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") + public BuilderSingularGuavaListsSetsBuilder<T> rawSet(final java.lang.Iterable<?> rawSet) { + if (this.rawSet == null) this.rawSet = com.google.common.collect.ImmutableSet.builder(); + this.rawSet.addAll(rawSet); + return this; + } + @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") + public BuilderSingularGuavaListsSetsBuilder<T> pass(final String pass) { + if (this.passes == null) this.passes = com.google.common.collect.ImmutableSortedSet.naturalOrder(); + this.passes.add(pass); + return this; + } + @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") + public BuilderSingularGuavaListsSetsBuilder<T> passes(final java.lang.Iterable<? extends String> passes) { + if (this.passes == null) this.passes = com.google.common.collect.ImmutableSortedSet.naturalOrder(); + this.passes.addAll(passes); + return this; + } + @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") + public BuilderSingularGuavaListsSets<T> build() { + com.google.common.collect.ImmutableList<T> cards = this.cards == null ? com.google.common.collect.ImmutableList.<T>of() : this.cards.build(); + com.google.common.collect.ImmutableCollection<Number> frogs = this.frogs == null ? com.google.common.collect.ImmutableList.<Number>of() : this.frogs.build(); + com.google.common.collect.ImmutableSet<java.lang.Object> rawSet = this.rawSet == null ? com.google.common.collect.ImmutableSet.<java.lang.Object>of() : this.rawSet.build(); + com.google.common.collect.ImmutableSortedSet<String> passes = this.passes == null ? com.google.common.collect.ImmutableSortedSet.<String>of() : this.passes.build(); + return new BuilderSingularGuavaListsSets<T>(cards, frogs, rawSet, passes); + } + @java.lang.Override + @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") + public java.lang.String toString() { + return "BuilderSingularGuavaListsSets.BuilderSingularGuavaListsSetsBuilder(cards=" + this.cards + ", frogs=" + this.frogs + ", rawSet=" + this.rawSet + ", passes=" + this.passes + ")"; + } + } + @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") + public static <T> BuilderSingularGuavaListsSetsBuilder<T> builder() { + return new BuilderSingularGuavaListsSetsBuilder<T>(); + } +}
\ No newline at end of file diff --git a/test/transform/resource/after-delombok/BuilderSingularGuavaMaps.java b/test/transform/resource/after-delombok/BuilderSingularGuavaMaps.java new file mode 100644 index 00000000..fe5c65d2 --- /dev/null +++ b/test/transform/resource/after-delombok/BuilderSingularGuavaMaps.java @@ -0,0 +1,88 @@ +import com.google.common.collect.ImmutableMap; +import com.google.common.collect.ImmutableBiMap; +import com.google.common.collect.ImmutableSortedMap; +class BuilderSingularGuavaMaps<K, V> { + private ImmutableMap<K, V> battleaxes; + private ImmutableSortedMap<Integer, ? extends V> vertices; + @SuppressWarnings("all") + private ImmutableBiMap rawMap; + @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") + BuilderSingularGuavaMaps(final ImmutableMap<K, V> battleaxes, final ImmutableSortedMap<Integer, ? extends V> vertices, final ImmutableBiMap rawMap) { + this.battleaxes = battleaxes; + this.vertices = vertices; + this.rawMap = rawMap; + } + @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") + public static class BuilderSingularGuavaMapsBuilder<K, V> { + private com.google.common.collect.ImmutableMap.Builder<K, V> battleaxes; + private com.google.common.collect.ImmutableSortedMap.Builder<Integer, V> vertices; + private com.google.common.collect.ImmutableBiMap.Builder<java.lang.Object, java.lang.Object> rawMap; + @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") + BuilderSingularGuavaMapsBuilder() { + } + @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") + public BuilderSingularGuavaMapsBuilder<K, V> battleaxe(final K battleaxe$key, final V battleaxe$value) { + if (this.battleaxes == null) this.battleaxes = com.google.common.collect.ImmutableMap.builder(); + this.battleaxes.put(battleaxe$key, battleaxe$value); + return this; + } + @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") + public BuilderSingularGuavaMapsBuilder<K, V> battleaxes(final java.util.Map<? extends K, ? extends V> battleaxes) { + if (this.battleaxes == null) this.battleaxes = com.google.common.collect.ImmutableMap.builder(); + this.battleaxes.putAll(battleaxes); + return this; + } + @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") + public BuilderSingularGuavaMapsBuilder<K, V> vertex(final Integer vertex$key, final V vertex$value) { + if (this.vertices == null) this.vertices = com.google.common.collect.ImmutableSortedMap.naturalOrder(); + this.vertices.put(vertex$key, vertex$value); + return this; + } + @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") + public BuilderSingularGuavaMapsBuilder<K, V> vertices(final java.util.Map<? extends Integer, ? extends V> vertices) { + if (this.vertices == null) this.vertices = com.google.common.collect.ImmutableSortedMap.naturalOrder(); + this.vertices.putAll(vertices); + return this; + } + @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") + public BuilderSingularGuavaMapsBuilder<K, V> rawMap(final java.lang.Object rawMap$key, final java.lang.Object rawMap$value) { + if (this.rawMap == null) this.rawMap = com.google.common.collect.ImmutableBiMap.builder(); + this.rawMap.put(rawMap$key, rawMap$value); + return this; + } + @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") + public BuilderSingularGuavaMapsBuilder<K, V> rawMap(final java.util.Map<?, ?> rawMap) { + if (this.rawMap == null) this.rawMap = com.google.common.collect.ImmutableBiMap.builder(); + this.rawMap.putAll(rawMap); + return this; + } + @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") + public BuilderSingularGuavaMaps<K, V> build() { + com.google.common.collect.ImmutableMap<K, V> battleaxes = this.battleaxes == null ? com.google.common.collect.ImmutableMap.<K, V>of() : this.battleaxes.build(); + com.google.common.collect.ImmutableSortedMap<Integer, V> vertices = this.vertices == null ? com.google.common.collect.ImmutableSortedMap.<Integer, V>of() : this.vertices.build(); + com.google.common.collect.ImmutableBiMap<java.lang.Object, java.lang.Object> rawMap = this.rawMap == null ? com.google.common.collect.ImmutableBiMap.<java.lang.Object, java.lang.Object>of() : this.rawMap.build(); + return new BuilderSingularGuavaMaps<K, V>(battleaxes, vertices, rawMap); + } + @java.lang.Override + @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") + public java.lang.String toString() { + return "BuilderSingularGuavaMaps.BuilderSingularGuavaMapsBuilder(battleaxes=" + this.battleaxes + ", vertices=" + this.vertices + ", rawMap=" + this.rawMap + ")"; + } + } + @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") + public static <K, V> BuilderSingularGuavaMapsBuilder<K, V> builder() { + return new BuilderSingularGuavaMapsBuilder<K, V>(); + } +}
\ No newline at end of file diff --git a/test/transform/resource/after-delombok/BuilderSingularLists.java b/test/transform/resource/after-delombok/BuilderSingularLists.java new file mode 100644 index 00000000..d33b8674 --- /dev/null +++ b/test/transform/resource/after-delombok/BuilderSingularLists.java @@ -0,0 +1,117 @@ +import java.util.List; +import java.util.Collection; +class BuilderSingularLists<T> { + private List<T> children; + private Collection<? extends Number> scarves; + @SuppressWarnings("all") + private List rawList; + @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") + BuilderSingularLists(final List<T> children, final Collection<? extends Number> scarves, final List rawList) { + this.children = children; + this.scarves = scarves; + this.rawList = rawList; + } + @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") + public static class BuilderSingularListsBuilder<T> { + private java.util.ArrayList<T> children; + private java.util.ArrayList<Number> scarves; + private java.util.ArrayList<java.lang.Object> rawList; + @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") + BuilderSingularListsBuilder() { + } + @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") + public BuilderSingularListsBuilder<T> child(final T child) { + if (this.children == null) this.children = new java.util.ArrayList<T>(); + this.children.add(child); + return this; + } + @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") + public BuilderSingularListsBuilder<T> children(final java.util.Collection<? extends T> children) { + if (this.children == null) this.children = new java.util.ArrayList<T>(); + this.children.addAll(children); + return this; + } + @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") + public BuilderSingularListsBuilder<T> scarf(final Number scarf) { + if (this.scarves == null) this.scarves = new java.util.ArrayList<Number>(); + this.scarves.add(scarf); + return this; + } + @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") + public BuilderSingularListsBuilder<T> scarves(final java.util.Collection<? extends Number> scarves) { + if (this.scarves == null) this.scarves = new java.util.ArrayList<Number>(); + this.scarves.addAll(scarves); + return this; + } + @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") + public BuilderSingularListsBuilder<T> rawList(final java.lang.Object rawList) { + if (this.rawList == null) this.rawList = new java.util.ArrayList<java.lang.Object>(); + this.rawList.add(rawList); + return this; + } + @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") + public BuilderSingularListsBuilder<T> rawList(final java.util.Collection<?> rawList) { + if (this.rawList == null) this.rawList = new java.util.ArrayList<java.lang.Object>(); + this.rawList.addAll(rawList); + return this; + } + @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") + public BuilderSingularLists<T> build() { + java.util.List<T> children; + switch (this.children == null ? 0 : this.children.size()) { + case 0: + children = java.util.Collections.emptyList(); + break; + case 1: + children = java.util.Collections.singletonList(this.children.get(0)); + break; + default: + children = java.util.Collections.unmodifiableList(new java.util.ArrayList<T>(this.children)); + } + java.util.Collection<Number> scarves; + switch (this.scarves == null ? 0 : this.scarves.size()) { + case 0: + scarves = java.util.Collections.emptyList(); + break; + case 1: + scarves = java.util.Collections.singletonList(this.scarves.get(0)); + break; + default: + scarves = java.util.Collections.unmodifiableList(new java.util.ArrayList<Number>(this.scarves)); + } + java.util.List<java.lang.Object> rawList; + switch (this.rawList == null ? 0 : this.rawList.size()) { + case 0: + rawList = java.util.Collections.emptyList(); + break; + case 1: + rawList = java.util.Collections.singletonList(this.rawList.get(0)); + break; + default: + rawList = java.util.Collections.unmodifiableList(new java.util.ArrayList<java.lang.Object>(this.rawList)); + } + return new BuilderSingularLists<T>(children, scarves, rawList); + } + @java.lang.Override + @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") + public java.lang.String toString() { + return "BuilderSingularLists.BuilderSingularListsBuilder(children=" + this.children + ", scarves=" + this.scarves + ", rawList=" + this.rawList + ")"; + } + } + @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") + public static <T> BuilderSingularListsBuilder<T> builder() { + return new BuilderSingularListsBuilder<T>(); + } +} diff --git a/test/transform/resource/after-delombok/BuilderSingularMaps.java b/test/transform/resource/after-delombok/BuilderSingularMaps.java new file mode 100644 index 00000000..753abfec --- /dev/null +++ b/test/transform/resource/after-delombok/BuilderSingularMaps.java @@ -0,0 +1,173 @@ +import java.util.Map; +import java.util.SortedMap; +class BuilderSingularMaps<K, V> { + private Map<K, V> women; + private SortedMap<K, ? extends Number> men; + @SuppressWarnings("all") + private Map rawMap; + private Map<String, V> stringMap; + @SuppressWarnings("all") + BuilderSingularMaps(Map<K, V> women, SortedMap<K, ? extends Number> men, Map rawMap, Map<String, V> stringMap) { + this.women = women; + this.men = men; + this.rawMap = rawMap; + this.stringMap = stringMap; + } + @SuppressWarnings("all") + public static class BuilderSingularMapsBuilder<K, V> { + private java.util.ArrayList<K> women$key; + private java.util.ArrayList<V> women$value; + private java.util.ArrayList<K> men$key; + private java.util.ArrayList<Number> men$value; + private java.util.ArrayList<Object> rawMap$key; + private java.util.ArrayList<Object> rawMap$value; + private java.util.ArrayList<String> stringMap$key; + private java.util.ArrayList<V> stringMap$value; + @SuppressWarnings("all") + BuilderSingularMapsBuilder() { + } + @SuppressWarnings("all") + public BuilderSingularMapsBuilder<K, V> woman(K womanKey, V womanValue) { + if (this.women$key == null) { + this.women$key = new java.util.ArrayList<K>(); + this.women$value = new java.util.ArrayList<V>(); + } + this.women$key.add(womanKey); + this.women$value.add(womanValue); + return this; + } + @SuppressWarnings("all") + public BuilderSingularMapsBuilder<K, V> women(java.util.Map<? extends K, ? extends V> women) { + if (this.women$key == null) { + this.women$key = new java.util.ArrayList<K>(); + this.women$value = new java.util.ArrayList<V>(); + } + for (java.util.Map.Entry<? extends K, ? extends V> $lombokEntry : women.entrySet()) { + this.women$key.add($lombokEntry.getKey()); + this.women$value.add($lombokEntry.getValue()); + } + return this; + } + @SuppressWarnings("all") + public BuilderSingularMapsBuilder<K, V> man(K manKey, Number manValue) { + if (this.men$key == null) { + this.men$key = new java.util.ArrayList<K>(); + this.men$value = new java.util.ArrayList<Number>(); + } + this.men$key.add(manKey); + this.men$value.add(manValue); + return this; + } + @SuppressWarnings("all") + public BuilderSingularMapsBuilder<K, V> men(java.util.Map<? extends K, ? extends Number> men) { + if (this.men$key == null) { + this.men$key = new java.util.ArrayList<K>(); + this.men$value = new java.util.ArrayList<Number>(); + } + for (java.util.Map.Entry<? extends K, ? extends Number> $lombokEntry : men.entrySet()) { + this.men$key.add($lombokEntry.getKey()); + this.men$value.add($lombokEntry.getValue()); + } + return this; + } + @SuppressWarnings("all") + public BuilderSingularMapsBuilder<K, V> rawMap(Object rawMapKey, Object rawMapValue) { + if (this.rawMap$key == null) { + this.rawMap$key = new java.util.ArrayList<Object>(); + this.rawMap$value = new java.util.ArrayList<Object>(); + } + this.rawMap$key.add(rawMapKey); + this.rawMap$value.add(rawMapValue); + return this; + } + @SuppressWarnings("all") + public BuilderSingularMapsBuilder<K, V> rawMap(java.util.Map<?, ?> rawMap) { + if (this.rawMap$key == null) { + this.rawMap$key = new java.util.ArrayList<Object>(); + this.rawMap$value = new java.util.ArrayList<Object>(); + } + for (java.util.Map.Entry<?, ?> $lombokEntry : rawMap.entrySet()) { + this.rawMap$key.add($lombokEntry.getKey()); + this.rawMap$value.add($lombokEntry.getValue()); + } + return this; + } + @SuppressWarnings("all") + public BuilderSingularMapsBuilder<K, V> stringMap(String stringMapKey, V stringMapValue) { + if (this.stringMap$key == null) { + this.stringMap$key = new java.util.ArrayList<String>(); + this.stringMap$value = new java.util.ArrayList<V>(); + } + this.stringMap$key.add(stringMapKey); + this.stringMap$value.add(stringMapValue); + return this; + } + @SuppressWarnings("all") + public BuilderSingularMapsBuilder<K, V> stringMap(java.util.Map<? extends String, ? extends V> stringMap) { + if (this.stringMap$key == null) { + this.stringMap$key = new java.util.ArrayList<String>(); + this.stringMap$value = new java.util.ArrayList<V>(); + } + for (java.util.Map.Entry<? extends String, ? extends V> $lombokEntry : stringMap.entrySet()) { + this.stringMap$key.add($lombokEntry.getKey()); + this.stringMap$value.add($lombokEntry.getValue()); + } + return this; + } + @SuppressWarnings("all") + public BuilderSingularMaps<K, V> build() { + java.util.Map<K, V> women; + switch (this.women$key == null ? 0 : this.women$key.size()) { + case 0: + women = java.util.Collections.emptyMap(); + break; + case 1: + women = java.util.Collections.singletonMap(this.women$key.get(0), this.women$value.get(0)); + break; + default: + women = new java.util.LinkedHashMap<K, V>(this.women$key.size() < 1073741824 ? 1 + this.women$key.size() + (this.women$key.size() - 3) / 3 : Integer.MAX_VALUE); + for (int $i = 0; $i < this.women$key.size(); $i++) women.put(this.women$key.get($i), this.women$value.get($i)); + women = java.util.Collections.unmodifiableMap(women); + } + java.util.SortedMap<K, Number> men = new java.util.TreeMap<K, Number>(); + if (this.men$key != null) for (int $i = 0; $i < (this.men$key == null ? 0 : this.men$key.size()); $i++) men.put(this.men$key.get($i), this.men$value.get($i)); + men = java.util.Collections.unmodifiableSortedMap(men); + java.util.Map<Object, Object> rawMap; + switch (this.rawMap$key == null ? 0 : this.rawMap$key.size()) { + case 0: + rawMap = java.util.Collections.emptyMap(); + break; + case 1: + rawMap = java.util.Collections.singletonMap(this.rawMap$key.get(0), this.rawMap$value.get(0)); + break; + default: + rawMap = new java.util.LinkedHashMap<Object, Object>(this.rawMap$key.size() < 1073741824 ? 1 + this.rawMap$key.size() + (this.rawMap$key.size() - 3) / 3 : Integer.MAX_VALUE); + for (int $i = 0; $i < this.rawMap$key.size(); $i++) rawMap.put(this.rawMap$key.get($i), this.rawMap$value.get($i)); + rawMap = java.util.Collections.unmodifiableMap(rawMap); + } + java.util.Map<String, V> stringMap; + switch (this.stringMap$key == null ? 0 : this.stringMap$key.size()) { + case 0: + stringMap = java.util.Collections.emptyMap(); + break; + case 1: + stringMap = java.util.Collections.singletonMap(this.stringMap$key.get(0), this.stringMap$value.get(0)); + break; + default: + stringMap = new java.util.LinkedHashMap<String, V>(this.stringMap$key.size() < 1073741824 ? 1 + this.stringMap$key.size() + (this.stringMap$key.size() - 3) / 3 : Integer.MAX_VALUE); + for (int $i = 0; $i < this.stringMap$key.size(); $i++) stringMap.put(this.stringMap$key.get($i), this.stringMap$value.get($i)); + stringMap = java.util.Collections.unmodifiableMap(stringMap); + } + return new BuilderSingularMaps<K, V>(women, men, rawMap, stringMap); + } + @Override + @SuppressWarnings("all") + public String toString() { + return "BuilderSingularMaps.BuilderSingularMapsBuilder(women$key=" + this.women$key + ", women$value=" + this.women$value + ", men$key=" + this.men$key + ", men$value=" + this.men$value + ", rawMap$key=" + this.rawMap$key + ", rawMap$value=" + this.rawMap$value + ", stringMap$key=" + this.stringMap$key + ", stringMap$value=" + this.stringMap$value + ")"; + } + } + @SuppressWarnings("all") + public static <K, V> BuilderSingularMapsBuilder<K, V> builder() { + return new BuilderSingularMapsBuilder<K, V>(); + } +} diff --git a/test/transform/resource/after-delombok/BuilderSingularNoAutosingularize.java b/test/transform/resource/after-delombok/BuilderSingularNoAutosingularize.java new file mode 100644 index 00000000..ca985275 --- /dev/null +++ b/test/transform/resource/after-delombok/BuilderSingularNoAutosingularize.java @@ -0,0 +1,115 @@ +import java.util.List; +class BuilderSingularNoAutosingularize { + private List<String> things; + private List<String> widgets; + private List<String> items; + @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") + BuilderSingularNoAutosingularize(final List<String> things, final List<String> widgets, final List<String> items) { + this.things = things; + this.widgets = widgets; + this.items = items; + } + @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") + public static class BuilderSingularNoAutosingularizeBuilder { + private java.util.ArrayList<String> things; + private java.util.ArrayList<String> widgets; + private java.util.ArrayList<String> items; + @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") + BuilderSingularNoAutosingularizeBuilder() { + } + @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") + public BuilderSingularNoAutosingularizeBuilder things(final String things) { + if (this.things == null) this.things = new java.util.ArrayList<String>(); + this.things.add(things); + return this; + } + @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") + public BuilderSingularNoAutosingularizeBuilder things(final java.util.Collection<? extends String> things) { + if (this.things == null) this.things = new java.util.ArrayList<String>(); + this.things.addAll(things); + return this; + } + @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") + public BuilderSingularNoAutosingularizeBuilder widget(final String widget) { + if (this.widgets == null) this.widgets = new java.util.ArrayList<String>(); + this.widgets.add(widget); + return this; + } + @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") + public BuilderSingularNoAutosingularizeBuilder widgets(final java.util.Collection<? extends String> widgets) { + if (this.widgets == null) this.widgets = new java.util.ArrayList<String>(); + this.widgets.addAll(widgets); + return this; + } + @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") + public BuilderSingularNoAutosingularizeBuilder items(final String items) { + if (this.items == null) this.items = new java.util.ArrayList<String>(); + this.items.add(items); + return this; + } + @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") + public BuilderSingularNoAutosingularizeBuilder items(final java.util.Collection<? extends String> items) { + if (this.items == null) this.items = new java.util.ArrayList<String>(); + this.items.addAll(items); + return this; + } + @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") + public BuilderSingularNoAutosingularize build() { + java.util.List<String> things; + switch (this.things == null ? 0 : this.things.size()) { + case 0: + things = java.util.Collections.emptyList(); + break; + case 1: + things = java.util.Collections.singletonList(this.things.get(0)); + break; + default: + things = java.util.Collections.unmodifiableList(new java.util.ArrayList<String>(this.things)); + } + java.util.List<String> widgets; + switch (this.widgets == null ? 0 : this.widgets.size()) { + case 0: + widgets = java.util.Collections.emptyList(); + break; + case 1: + widgets = java.util.Collections.singletonList(this.widgets.get(0)); + break; + default: + widgets = java.util.Collections.unmodifiableList(new java.util.ArrayList<String>(this.widgets)); + } + java.util.List<String> items; + switch (this.items == null ? 0 : this.items.size()) { + case 0: + items = java.util.Collections.emptyList(); + break; + case 1: + items = java.util.Collections.singletonList(this.items.get(0)); + break; + default: + items = java.util.Collections.unmodifiableList(new java.util.ArrayList<String>(this.items)); + } + return new BuilderSingularNoAutosingularize(things, widgets, items); + } + @java.lang.Override + @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") + public java.lang.String toString() { + return "BuilderSingularNoAutosingularize.BuilderSingularNoAutosingularizeBuilder(things=" + this.things + ", widgets=" + this.widgets + ", items=" + this.items + ")"; + } + } + @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") + public static BuilderSingularNoAutosingularizeBuilder builder() { + return new BuilderSingularNoAutosingularizeBuilder(); + } +}
\ No newline at end of file diff --git a/test/transform/resource/after-delombok/BuilderSingularRedirectToGuava.java b/test/transform/resource/after-delombok/BuilderSingularRedirectToGuava.java new file mode 100644 index 00000000..27ed2535 --- /dev/null +++ b/test/transform/resource/after-delombok/BuilderSingularRedirectToGuava.java @@ -0,0 +1,87 @@ +import java.util.Set; +import java.util.NavigableMap; +import java.util.Collection; +class BuilderSingularRedirectToGuava { + private Set<String> dangerMice; + private NavigableMap<Integer, Number> things; + private Collection<Class<?>> doohickeys; + @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") + BuilderSingularRedirectToGuava(final Set<String> dangerMice, final NavigableMap<Integer, Number> things, final Collection<Class<?>> doohickeys) { + this.dangerMice = dangerMice; + this.things = things; + this.doohickeys = doohickeys; + } + @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") + public static class BuilderSingularRedirectToGuavaBuilder { + private com.google.common.collect.ImmutableSet.Builder<String> dangerMice; + private com.google.common.collect.ImmutableSortedMap.Builder<Integer, Number> things; + private com.google.common.collect.ImmutableList.Builder<Class<?>> doohickeys; + @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") + BuilderSingularRedirectToGuavaBuilder() { + } + @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") + public BuilderSingularRedirectToGuavaBuilder dangerMouse(final String dangerMouse) { + if (this.dangerMice == null) this.dangerMice = com.google.common.collect.ImmutableSet.builder(); + this.dangerMice.add(dangerMouse); + return this; + } + @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") + public BuilderSingularRedirectToGuavaBuilder dangerMice(final java.lang.Iterable<? extends String> dangerMice) { + if (this.dangerMice == null) this.dangerMice = com.google.common.collect.ImmutableSet.builder(); + this.dangerMice.addAll(dangerMice); + return this; + } + @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") + public BuilderSingularRedirectToGuavaBuilder thing(final Integer thing$key, final Number thing$value) { + if (this.things == null) this.things = com.google.common.collect.ImmutableSortedMap.naturalOrder(); + this.things.put(thing$key, thing$value); + return this; + } + @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") + public BuilderSingularRedirectToGuavaBuilder things(final java.util.Map<? extends Integer, ? extends Number> things) { + if (this.things == null) this.things = com.google.common.collect.ImmutableSortedMap.naturalOrder(); + this.things.putAll(things); + return this; + } + @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") + public BuilderSingularRedirectToGuavaBuilder doohickey(final Class<?> doohickey) { + if (this.doohickeys == null) this.doohickeys = com.google.common.collect.ImmutableList.builder(); + this.doohickeys.add(doohickey); + return this; + } + @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") + public BuilderSingularRedirectToGuavaBuilder doohickeys(final java.lang.Iterable<? extends Class<?>> doohickeys) { + if (this.doohickeys == null) this.doohickeys = com.google.common.collect.ImmutableList.builder(); + this.doohickeys.addAll(doohickeys); + return this; + } + @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") + public BuilderSingularRedirectToGuava build() { + java.util.Set<String> dangerMice = this.dangerMice == null ? com.google.common.collect.ImmutableSet.<String>of() : this.dangerMice.build(); + java.util.NavigableMap<Integer, Number> things = this.things == null ? com.google.common.collect.ImmutableSortedMap.<Integer, Number>of() : this.things.build(); + java.util.Collection<Class<?>> doohickeys = this.doohickeys == null ? com.google.common.collect.ImmutableList.<Class<?>>of() : this.doohickeys.build(); + return new BuilderSingularRedirectToGuava(dangerMice, things, doohickeys); + } + @java.lang.Override + @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") + public java.lang.String toString() { + return "BuilderSingularRedirectToGuava.BuilderSingularRedirectToGuavaBuilder(dangerMice=" + this.dangerMice + ", things=" + this.things + ", doohickeys=" + this.doohickeys + ")"; + } + } + @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") + public static BuilderSingularRedirectToGuavaBuilder builder() { + return new BuilderSingularRedirectToGuavaBuilder(); + } +}
\ No newline at end of file diff --git a/test/transform/resource/after-delombok/BuilderSingularSets.java b/test/transform/resource/after-delombok/BuilderSingularSets.java new file mode 100644 index 00000000..8e410897 --- /dev/null +++ b/test/transform/resource/after-delombok/BuilderSingularSets.java @@ -0,0 +1,143 @@ +import java.util.Set; +import java.util.SortedSet; +class BuilderSingularSets<T> { + private Set<T> dangerMice; + private SortedSet<? extends Number> octopodes; + @SuppressWarnings("all") + private Set rawSet; + private Set<String> stringSet; + @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") + BuilderSingularSets(final Set<T> dangerMice, final SortedSet<? extends Number> octopodes, final Set rawSet, final Set<String> stringSet) { + this.dangerMice = dangerMice; + this.octopodes = octopodes; + this.rawSet = rawSet; + this.stringSet = stringSet; + } + @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") + public static class BuilderSingularSetsBuilder<T> { + private java.util.ArrayList<T> dangerMice; + private java.util.ArrayList<Number> octopodes; + private java.util.ArrayList<java.lang.Object> rawSet; + private java.util.ArrayList<String> stringSet; + @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") + BuilderSingularSetsBuilder() { + } + @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") + public BuilderSingularSetsBuilder<T> dangerMouse(final T dangerMouse) { + if (this.dangerMice == null) this.dangerMice = new java.util.ArrayList<T>(); + this.dangerMice.add(dangerMouse); + return this; + } + @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") + public BuilderSingularSetsBuilder<T> dangerMice(final java.util.Collection<? extends T> dangerMice) { + if (this.dangerMice == null) this.dangerMice = new java.util.ArrayList<T>(); + this.dangerMice.addAll(dangerMice); + return this; + } + @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") + public BuilderSingularSetsBuilder<T> octopus(final Number octopus) { + if (this.octopodes == null) this.octopodes = new java.util.ArrayList<Number>(); + this.octopodes.add(octopus); + return this; + } + @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") + public BuilderSingularSetsBuilder<T> octopodes(final java.util.Collection<? extends Number> octopodes) { + if (this.octopodes == null) this.octopodes = new java.util.ArrayList<Number>(); + this.octopodes.addAll(octopodes); + return this; + } + @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") + public BuilderSingularSetsBuilder<T> rawSet(final java.lang.Object rawSet) { + if (this.rawSet == null) this.rawSet = new java.util.ArrayList<java.lang.Object>(); + this.rawSet.add(rawSet); + return this; + } + @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") + public BuilderSingularSetsBuilder<T> rawSet(final java.util.Collection<?> rawSet) { + if (this.rawSet == null) this.rawSet = new java.util.ArrayList<java.lang.Object>(); + this.rawSet.addAll(rawSet); + return this; + } + @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") + public BuilderSingularSetsBuilder<T> stringSet(final String stringSet) { + if (this.stringSet == null) this.stringSet = new java.util.ArrayList<String>(); + this.stringSet.add(stringSet); + return this; + } + @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") + public BuilderSingularSetsBuilder<T> stringSet(final java.util.Collection<? extends String> stringSet) { + if (this.stringSet == null) this.stringSet = new java.util.ArrayList<String>(); + this.stringSet.addAll(stringSet); + return this; + } + @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") + public BuilderSingularSets<T> build() { + java.util.Set<T> dangerMice; + switch (this.dangerMice == null ? 0 : this.dangerMice.size()) { + case 0: + dangerMice = java.util.Collections.emptySet(); + break; + case 1: + dangerMice = java.util.Collections.singleton(this.dangerMice.get(0)); + break; + default: + dangerMice = new java.util.LinkedHashSet<T>(this.dangerMice.size() < 1073741824 ? 1 + this.dangerMice.size() + (this.dangerMice.size() - 3) / 3 : java.lang.Integer.MAX_VALUE); + dangerMice.addAll(this.dangerMice); + dangerMice = java.util.Collections.unmodifiableSet(dangerMice); + } + java.util.SortedSet<Number> octopodes = new java.util.TreeSet<Number>(); + if (this.octopodes != null) octopodes.addAll(this.octopodes); + octopodes = java.util.Collections.unmodifiableSortedSet(octopodes); + java.util.Set<java.lang.Object> rawSet; + switch (this.rawSet == null ? 0 : this.rawSet.size()) { + case 0: + rawSet = java.util.Collections.emptySet(); + break; + case 1: + rawSet = java.util.Collections.singleton(this.rawSet.get(0)); + break; + default: + rawSet = new java.util.LinkedHashSet<java.lang.Object>(this.rawSet.size() < 1073741824 ? 1 + this.rawSet.size() + (this.rawSet.size() - 3) / 3 : java.lang.Integer.MAX_VALUE); + rawSet.addAll(this.rawSet); + rawSet = java.util.Collections.unmodifiableSet(rawSet); + } + java.util.Set<String> stringSet; + switch (this.stringSet == null ? 0 : this.stringSet.size()) { + case 0: + stringSet = java.util.Collections.emptySet(); + break; + case 1: + stringSet = java.util.Collections.singleton(this.stringSet.get(0)); + break; + default: + stringSet = new java.util.LinkedHashSet<String>(this.stringSet.size() < 1073741824 ? 1 + this.stringSet.size() + (this.stringSet.size() - 3) / 3 : java.lang.Integer.MAX_VALUE); + stringSet.addAll(this.stringSet); + stringSet = java.util.Collections.unmodifiableSet(stringSet); + } + return new BuilderSingularSets<T>(dangerMice, octopodes, rawSet, stringSet); + } + @java.lang.Override + @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") + public java.lang.String toString() { + return "BuilderSingularSets.BuilderSingularSetsBuilder(dangerMice=" + this.dangerMice + ", octopodes=" + this.octopodes + ", rawSet=" + this.rawSet + ", stringSet=" + this.stringSet + ")"; + } + } + @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") + public static <T> BuilderSingularSetsBuilder<T> builder() { + return new BuilderSingularSetsBuilder<T>(); + } +}
\ No newline at end of file diff --git a/test/transform/resource/after-delombok/BuilderWithAccessors.java b/test/transform/resource/after-delombok/BuilderWithAccessors.java index 503c33be..74914453 100644 --- a/test/transform/resource/after-delombok/BuilderWithAccessors.java +++ b/test/transform/resource/after-delombok/BuilderWithAccessors.java @@ -4,6 +4,7 @@ class BuilderWithAccessors { private int _foo; private int __bar; @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") BuilderWithAccessors(final int plower, final int upper, final int foo, final int _bar) { this.plower = plower; this.pUpper = upper; @@ -11,6 +12,7 @@ class BuilderWithAccessors { this.__bar = _bar; } @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public static class BuilderWithAccessorsBuilder { private int plower; private int upper; @@ -18,47 +20,62 @@ class BuilderWithAccessors { private int _bar; @java.lang.SuppressWarnings("all") + + @javax.annotation.Generated("lombok") BuilderWithAccessorsBuilder() { } @java.lang.SuppressWarnings("all") + + @javax.annotation.Generated("lombok") public BuilderWithAccessorsBuilder plower(final int plower) { this.plower = plower; return this; } @java.lang.SuppressWarnings("all") + + @javax.annotation.Generated("lombok") public BuilderWithAccessorsBuilder upper(final int upper) { this.upper = upper; return this; } @java.lang.SuppressWarnings("all") + + @javax.annotation.Generated("lombok") public BuilderWithAccessorsBuilder foo(final int foo) { this.foo = foo; return this; } @java.lang.SuppressWarnings("all") + + @javax.annotation.Generated("lombok") public BuilderWithAccessorsBuilder _bar(final int _bar) { this._bar = _bar; return this; } @java.lang.SuppressWarnings("all") + + @javax.annotation.Generated("lombok") public BuilderWithAccessors build() { return new BuilderWithAccessors(plower, upper, foo, _bar); } @java.lang.Override @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public java.lang.String toString() { return "BuilderWithAccessors.BuilderWithAccessorsBuilder(plower=" + this.plower + ", upper=" + this.upper + ", foo=" + this.foo + ", _bar=" + this._bar + ")"; } } @java.lang.SuppressWarnings("all") + + @javax.annotation.Generated("lombok") public static BuilderWithAccessorsBuilder builder() { return new BuilderWithAccessorsBuilder(); } diff --git a/test/transform/resource/after-delombok/BuilderWithExistingBuilderClass.java b/test/transform/resource/after-delombok/BuilderWithExistingBuilderClass.java index 1d40dbfa..38d0eb2c 100644 --- a/test/transform/resource/after-delombok/BuilderWithExistingBuilderClass.java +++ b/test/transform/resource/after-delombok/BuilderWithExistingBuilderClass.java @@ -9,29 +9,35 @@ class BuilderWithExistingBuilderClass<T, K extends Number> { public void arg2(boolean arg) { } @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") BuilderWithExistingBuilderClassBuilder() { } @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public BuilderWithExistingBuilderClassBuilder<Z> arg1(final Z arg1) { this.arg1 = arg1; return this; } @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public BuilderWithExistingBuilderClassBuilder<Z> arg3(final String arg3) { this.arg3 = arg3; return this; } @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public BuilderWithExistingBuilderClass build() { return BuilderWithExistingBuilderClass.<Z>staticMethod(arg1, arg2, arg3); } @java.lang.Override @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public java.lang.String toString() { return "BuilderWithExistingBuilderClass.BuilderWithExistingBuilderClassBuilder(arg1=" + this.arg1 + ", arg2=" + this.arg2 + ", arg3=" + this.arg3 + ")"; } } @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public static <Z extends Number> BuilderWithExistingBuilderClassBuilder<Z> builder() { return new BuilderWithExistingBuilderClassBuilder<Z>(); } diff --git a/test/transform/resource/after-delombok/ClassNamedAfterGetter.java b/test/transform/resource/after-delombok/ClassNamedAfterGetter.java index 769aaf7c..793ec097 100644 --- a/test/transform/resource/after-delombok/ClassNamedAfterGetter.java +++ b/test/transform/resource/after-delombok/ClassNamedAfterGetter.java @@ -1,6 +1,7 @@ class GetFoo { private int foo; @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public int getFoo() { return this.foo; } diff --git a/test/transform/resource/after-delombok/CommentsInterspersed.java b/test/transform/resource/after-delombok/CommentsInterspersed.java index 833f2ce0..a1da2c3d 100644 --- a/test/transform/resource/after-delombok/CommentsInterspersed.java +++ b/test/transform/resource/after-delombok/CommentsInterspersed.java @@ -12,6 +12,7 @@ public class CommentsInterspersed { javascript; }-*/ @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public String getTest() { return this.test; } diff --git a/test/transform/resource/after-delombok/ConflictingStaticConstructorNames.java b/test/transform/resource/after-delombok/ConflictingStaticConstructorNames.java index ae0c46bc..a47fa244 100644 --- a/test/transform/resource/after-delombok/ConflictingStaticConstructorNames.java +++ b/test/transform/resource/after-delombok/ConflictingStaticConstructorNames.java @@ -1,6 +1,7 @@ class ConflictingStaticConstructorNames { @java.lang.Override @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public boolean equals(final java.lang.Object o) { if (o == this) return true; if (!(o instanceof ConflictingStaticConstructorNames)) return false; @@ -9,21 +10,25 @@ class ConflictingStaticConstructorNames { return true; } @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") protected boolean canEqual(final java.lang.Object other) { return other instanceof ConflictingStaticConstructorNames; } @java.lang.Override @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public int hashCode() { int result = 1; return result; } @java.lang.Override @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public java.lang.String toString() { return "ConflictingStaticConstructorNames()"; } @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public ConflictingStaticConstructorNames() { } }
\ No newline at end of file diff --git a/test/transform/resource/after-delombok/Constructors.java b/test/transform/resource/after-delombok/Constructors.java index 4ffdc62b..466ae9ee 100644 --- a/test/transform/resource/after-delombok/Constructors.java +++ b/test/transform/resource/after-delombok/Constructors.java @@ -3,6 +3,7 @@ class RequiredArgsConstructor1 { String name; @java.beans.ConstructorProperties({"x"}) @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public RequiredArgsConstructor1(final int x) { this.x = x; } @@ -12,6 +13,7 @@ class RequiredArgsConstructorAccess { String name; @java.beans.ConstructorProperties({"x"}) @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") protected RequiredArgsConstructorAccess(final int x) { this.x = x; } @@ -20,10 +22,12 @@ class RequiredArgsConstructorStaticName { final int x; String name; @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") private RequiredArgsConstructorStaticName(final int x) { this.x = x; } @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public static RequiredArgsConstructorStaticName staticname(final int x) { return new RequiredArgsConstructorStaticName(x); } @@ -34,6 +38,7 @@ class RequiredArgsConstructorWithAnnotations { @java.beans.ConstructorProperties({"x"}) @Deprecated @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public RequiredArgsConstructorWithAnnotations(final int x) { this.x = x; } @@ -43,6 +48,7 @@ class AllArgsConstructor1 { String name; @java.beans.ConstructorProperties({"x", "name"}) @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public AllArgsConstructor1(final int x, final String name) { this.x = x; this.name = name; @@ -52,6 +58,7 @@ class NoArgsConstructor1 { int x; String name; @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public NoArgsConstructor1() { } } @@ -59,10 +66,12 @@ class RequiredArgsConstructorStaticNameGenerics<T extends Number> { final T x; String name; @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") private RequiredArgsConstructorStaticNameGenerics(final T x) { this.x = x; } @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public static <T extends Number> RequiredArgsConstructorStaticNameGenerics<T> of(final T x) { return new RequiredArgsConstructorStaticNameGenerics<T>(x); } @@ -71,10 +80,12 @@ class RequiredArgsConstructorStaticNameGenerics2<T extends Number> { final Class<T> x; String name; @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") private RequiredArgsConstructorStaticNameGenerics2(final Class<T> x) { this.x = x; } @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public static <T extends Number> RequiredArgsConstructorStaticNameGenerics2<T> of(final Class<T> x) { return new RequiredArgsConstructorStaticNameGenerics2<T>(x); } @@ -82,6 +93,7 @@ class RequiredArgsConstructorStaticNameGenerics2<T extends Number> { class AllArgsConstructorPackageAccess { final String x; @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") AllArgsConstructorPackageAccess(final String x) { this.x = x; } diff --git a/test/transform/resource/after-delombok/ConstructorsConfiguration.java b/test/transform/resource/after-delombok/ConstructorsConfiguration.java index 5bec3ae3..effc51b8 100644 --- a/test/transform/resource/after-delombok/ConstructorsConfiguration.java +++ b/test/transform/resource/after-delombok/ConstructorsConfiguration.java @@ -1,6 +1,7 @@ class ConstructorsConfiguration { int x; @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public ConstructorsConfiguration(final int x) { this.x = x; } @@ -9,6 +10,7 @@ class ConstructorsConfigurationExplicit { int x; @java.beans.ConstructorProperties({"x"}) @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public ConstructorsConfigurationExplicit(final int x) { this.x = x; } diff --git a/test/transform/resource/after-delombok/ConstructorsWithAccessors.java b/test/transform/resource/after-delombok/ConstructorsWithAccessors.java index 9937c7ee..43c0ea66 100644 --- a/test/transform/resource/after-delombok/ConstructorsWithAccessors.java +++ b/test/transform/resource/after-delombok/ConstructorsWithAccessors.java @@ -6,6 +6,7 @@ class ConstructorsWithAccessors { @java.beans.ConstructorProperties({"plower", "upper", "huh", "_huh2"}) @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public ConstructorsWithAccessors(final int plower, final int upper, final int huh, final int _huh2) { this.plower = plower; this.pUpper = upper; diff --git a/test/transform/resource/after-delombok/DataConfiguration.java b/test/transform/resource/after-delombok/DataConfiguration.java index 230083ec..b83204b8 100644 --- a/test/transform/resource/after-delombok/DataConfiguration.java +++ b/test/transform/resource/after-delombok/DataConfiguration.java @@ -1,15 +1,18 @@ class DataConfiguration { final int x; @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public DataConfiguration(final int x) { this.x = x; } @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public int getX() { return this.x; } @java.lang.Override @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public boolean equals(final java.lang.Object o) { if (o == this) return true; if (!(o instanceof DataConfiguration)) return false; @@ -19,11 +22,13 @@ class DataConfiguration { return true; } @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") protected boolean canEqual(final java.lang.Object other) { return other instanceof DataConfiguration; } @java.lang.Override @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public int hashCode() { final int PRIME = 59; int result = 1; @@ -32,6 +37,7 @@ class DataConfiguration { } @java.lang.Override @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public java.lang.String toString() { return "DataConfiguration(x=" + this.getX() + ")"; } diff --git a/test/transform/resource/after-delombok/DataExtended.java b/test/transform/resource/after-delombok/DataExtended.java index 6a5e7fa2..25180429 100644 --- a/test/transform/resource/after-delombok/DataExtended.java +++ b/test/transform/resource/after-delombok/DataExtended.java @@ -1,18 +1,22 @@ class DataExtended { int x; @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public DataExtended() { } @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public int getX() { return this.x; } @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public void setX(final int x) { this.x = x; } @java.lang.Override @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public boolean equals(final java.lang.Object o) { if (o == this) return true; if (!(o instanceof DataExtended)) return false; @@ -22,11 +26,13 @@ class DataExtended { return true; } @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") protected boolean canEqual(final java.lang.Object other) { return other instanceof DataExtended; } @java.lang.Override @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public int hashCode() { final int PRIME = 59; int result = 1; @@ -35,6 +41,7 @@ class DataExtended { } @java.lang.Override @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public java.lang.String toString() { return "DataExtended(x=" + this.x + ")"; } diff --git a/test/transform/resource/after-delombok/DataIgnore.java b/test/transform/resource/after-delombok/DataIgnore.java index 922de01b..0d40a5a8 100644 --- a/test/transform/resource/after-delombok/DataIgnore.java +++ b/test/transform/resource/after-delombok/DataIgnore.java @@ -3,15 +3,18 @@ class DataIgnore { String $name; @java.beans.ConstructorProperties({"x"}) @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public DataIgnore(final int x) { this.x = x; } @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public int getX() { return this.x; } @java.lang.Override @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public boolean equals(final java.lang.Object o) { if (o == this) return true; if (!(o instanceof DataIgnore)) return false; @@ -21,11 +24,13 @@ class DataIgnore { return true; } @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") protected boolean canEqual(final java.lang.Object other) { return other instanceof DataIgnore; } @java.lang.Override @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public int hashCode() { final int PRIME = 59; int result = 1; @@ -34,6 +39,7 @@ class DataIgnore { } @java.lang.Override @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public java.lang.String toString() { return "DataIgnore(x=" + this.getX() + ")"; } diff --git a/test/transform/resource/after-delombok/DataOnEnum.java b/test/transform/resource/after-delombok/DataOnEnum.java index 5cfe8823..b3cd7967 100644 --- a/test/transform/resource/after-delombok/DataOnEnum.java +++ b/test/transform/resource/after-delombok/DataOnEnum.java @@ -2,15 +2,18 @@ public enum DataOnEnum { A("hello"); private final String someField; @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public String getSomeField() { return this.someField; } @java.lang.Override @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public java.lang.String toString() { return "DataOnEnum(someField=" + this.getSomeField() + ")"; } @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") private DataOnEnum(final String someField) { this.someField = someField; } diff --git a/test/transform/resource/after-delombok/DataOnLocalClass.java b/test/transform/resource/after-delombok/DataOnLocalClass.java index 5d73e584..57f04bf3 100644 --- a/test/transform/resource/after-delombok/DataOnLocalClass.java +++ b/test/transform/resource/after-delombok/DataOnLocalClass.java @@ -4,23 +4,28 @@ class DataOnLocalClass1 { final int x; String name; @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public Local(final int x) { this.x = x; } @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public int getX() { return this.x; } @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public String getName() { return this.name; } @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public void setName(final String name) { this.name = name; } @java.lang.Override @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public boolean equals(final java.lang.Object o) { if (o == this) return true; if (!(o instanceof Local)) return false; @@ -33,11 +38,13 @@ class DataOnLocalClass1 { return true; } @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") protected boolean canEqual(final java.lang.Object other) { return other instanceof Local; } @java.lang.Override @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public int hashCode() { final int PRIME = 59; int result = 1; @@ -48,6 +55,7 @@ class DataOnLocalClass1 { } @java.lang.Override @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public java.lang.String toString() { return "Local(x=" + this.getX() + ", name=" + this.getName() + ")"; } @@ -62,6 +70,7 @@ class DataOnLocalClass2 { @lombok.NonNull String name; @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public InnerLocal(@lombok.NonNull final String name) { if (name == null) { throw new java.lang.NullPointerException("name"); @@ -70,10 +79,12 @@ class DataOnLocalClass2 { } @lombok.NonNull @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public String getName() { return this.name; } @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public void setName(@lombok.NonNull final String name) { if (name == null) { throw new java.lang.NullPointerException("name"); @@ -82,6 +93,7 @@ class DataOnLocalClass2 { } @java.lang.Override @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public boolean equals(final java.lang.Object o) { if (o == this) return true; if (!(o instanceof Local.InnerLocal)) return false; @@ -93,11 +105,13 @@ class DataOnLocalClass2 { return true; } @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") protected boolean canEqual(final java.lang.Object other) { return other instanceof Local.InnerLocal; } @java.lang.Override @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public int hashCode() { final int PRIME = 59; int result = 1; @@ -107,20 +121,24 @@ class DataOnLocalClass2 { } @java.lang.Override @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public java.lang.String toString() { return "Local.InnerLocal(name=" + this.getName() + ")"; } } @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public Local(final int x) { this.x = x; } @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public int getX() { return this.x; } @java.lang.Override @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public boolean equals(final java.lang.Object o) { if (o == this) return true; if (!(o instanceof Local)) return false; @@ -130,11 +148,13 @@ class DataOnLocalClass2 { return true; } @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") protected boolean canEqual(final java.lang.Object other) { return other instanceof Local; } @java.lang.Override @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public int hashCode() { final int PRIME = 59; int result = 1; @@ -143,6 +163,7 @@ class DataOnLocalClass2 { } @java.lang.Override @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public java.lang.String toString() { return "Local(x=" + this.getX() + ")"; } diff --git a/test/transform/resource/after-delombok/DataPlain.java b/test/transform/resource/after-delombok/DataPlain.java index 8988dc6f..4ddb9414 100644 --- a/test/transform/resource/after-delombok/DataPlain.java +++ b/test/transform/resource/after-delombok/DataPlain.java @@ -3,23 +3,28 @@ class Data1 { String name; @java.beans.ConstructorProperties({"x"}) @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public Data1(final int x) { this.x = x; } @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public int getX() { return this.x; } @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public String getName() { return this.name; } @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public void setName(final String name) { this.name = name; } @java.lang.Override @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public boolean equals(final java.lang.Object o) { if (o == this) return true; if (!(o instanceof Data1)) return false; @@ -32,11 +37,13 @@ class Data1 { return true; } @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") protected boolean canEqual(final java.lang.Object other) { return other instanceof Data1; } @java.lang.Override @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public int hashCode() { final int PRIME = 59; int result = 1; @@ -47,6 +54,7 @@ class Data1 { } @java.lang.Override @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public java.lang.String toString() { return "Data1(x=" + this.getX() + ", name=" + this.getName() + ")"; } @@ -56,23 +64,28 @@ class Data2 { String name; @java.beans.ConstructorProperties({"x"}) @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public Data2(final int x) { this.x = x; } @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public int getX() { return this.x; } @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public String getName() { return this.name; } @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public void setName(final String name) { this.name = name; } @java.lang.Override @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public boolean equals(final java.lang.Object o) { if (o == this) return true; if (!(o instanceof Data2)) return false; @@ -85,11 +98,13 @@ class Data2 { return true; } @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") protected boolean canEqual(final java.lang.Object other) { return other instanceof Data2; } @java.lang.Override @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public int hashCode() { final int PRIME = 59; int result = 1; @@ -100,6 +115,7 @@ class Data2 { } @java.lang.Override @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public java.lang.String toString() { return "Data2(x=" + this.getX() + ", name=" + this.getName() + ")"; } @@ -109,23 +125,28 @@ final class Data3 { String name; @java.beans.ConstructorProperties({"x"}) @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public Data3(final int x) { this.x = x; } @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public int getX() { return this.x; } @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public String getName() { return this.name; } @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public void setName(final String name) { this.name = name; } @java.lang.Override @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public boolean equals(final java.lang.Object o) { if (o == this) return true; if (!(o instanceof Data3)) return false; @@ -138,6 +159,7 @@ final class Data3 { } @java.lang.Override @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public int hashCode() { final int PRIME = 59; int result = 1; @@ -148,6 +170,7 @@ final class Data3 { } @java.lang.Override @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public java.lang.String toString() { return "Data3(x=" + this.getX() + ", name=" + this.getName() + ")"; } @@ -157,20 +180,24 @@ final class Data4 extends java.util.Timer { Data4() { } @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public int getX() { return this.x; } @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public void setX(final int x) { this.x = x; } @java.lang.Override @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public java.lang.String toString() { return "Data4(x=" + this.getX() + ")"; } @java.lang.Override @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public boolean equals(final java.lang.Object o) { if (o == this) return true; if (!(o instanceof Data4)) return false; @@ -181,11 +208,13 @@ final class Data4 extends java.util.Timer { return true; } @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") protected boolean canEqual(final java.lang.Object other) { return other instanceof Data4; } @java.lang.Override @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public int hashCode() { final int PRIME = 59; int result = 1; @@ -196,10 +225,12 @@ final class Data4 extends java.util.Timer { } class Data5 { @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public Data5() { } @java.lang.Override @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public boolean equals(final java.lang.Object o) { if (o == this) return true; if (!(o instanceof Data5)) return false; @@ -208,27 +239,32 @@ class Data5 { return true; } @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") protected boolean canEqual(final java.lang.Object other) { return other instanceof Data5; } @java.lang.Override @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public int hashCode() { int result = 1; return result; } @java.lang.Override @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public java.lang.String toString() { return "Data5()"; } } final class Data6 { @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public Data6() { } @java.lang.Override @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public boolean equals(final java.lang.Object o) { if (o == this) return true; if (!(o instanceof Data6)) return false; @@ -236,12 +272,14 @@ final class Data6 { } @java.lang.Override @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public int hashCode() { int result = 1; return result; } @java.lang.Override @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public java.lang.String toString() { return "Data6()"; } diff --git a/test/transform/resource/after-delombok/DataWithGetter.java b/test/transform/resource/after-delombok/DataWithGetter.java index 91f392ec..232f783b 100644 --- a/test/transform/resource/after-delombok/DataWithGetter.java +++ b/test/transform/resource/after-delombok/DataWithGetter.java @@ -4,19 +4,23 @@ class DataWithGetter { private final String z; @java.beans.ConstructorProperties({"z"}) @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public DataWithGetter(final String z) { this.z = z; } @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public void setX(final int x) { this.x = x; } @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public void setY(final int y) { this.y = y; } @java.lang.Override @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public boolean equals(final java.lang.Object o) { if (o == this) return true; if (!(o instanceof DataWithGetter)) return false; @@ -30,11 +34,13 @@ class DataWithGetter { return true; } @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") protected boolean canEqual(final java.lang.Object other) { return other instanceof DataWithGetter; } @java.lang.Override @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public int hashCode() { final int PRIME = 59; int result = 1; @@ -46,18 +52,22 @@ class DataWithGetter { } @java.lang.Override @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public java.lang.String toString() { return "DataWithGetter(x=" + this.getX() + ", y=" + this.getY() + ", z=" + this.getZ() + ")"; } @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public int getX() { return this.x; } @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public int getY() { return this.y; } @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public String getZ() { return this.z; } diff --git a/test/transform/resource/after-delombok/DataWithGetterNone.java b/test/transform/resource/after-delombok/DataWithGetterNone.java index 5986ee9f..9e1fb60a 100644 --- a/test/transform/resource/after-delombok/DataWithGetterNone.java +++ b/test/transform/resource/after-delombok/DataWithGetterNone.java @@ -4,19 +4,23 @@ class DataWithGetterNone { private final String z; @java.beans.ConstructorProperties({"z"}) @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public DataWithGetterNone(final String z) { this.z = z; } @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public void setX(final int x) { this.x = x; } @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public void setY(final int y) { this.y = y; } @java.lang.Override @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public boolean equals(final java.lang.Object o) { if (o == this) return true; if (!(o instanceof DataWithGetterNone)) return false; @@ -30,11 +34,13 @@ class DataWithGetterNone { return true; } @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") protected boolean canEqual(final java.lang.Object other) { return other instanceof DataWithGetterNone; } @java.lang.Override @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public int hashCode() { final int PRIME = 59; int result = 1; @@ -46,6 +52,7 @@ class DataWithGetterNone { } @java.lang.Override @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public java.lang.String toString() { return "DataWithGetterNone(x=" + this.x + ", y=" + this.y + ", z=" + this.z + ")"; } diff --git a/test/transform/resource/after-delombok/DelegateOnGetter.java b/test/transform/resource/after-delombok/DelegateOnGetter.java index e8d01a49..5b5090e9 100644 --- a/test/transform/resource/after-delombok/DelegateOnGetter.java +++ b/test/transform/resource/after-delombok/DelegateOnGetter.java @@ -5,6 +5,7 @@ class DelegateOnGetter { int getInt(); } @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public Bar getBar() { java.lang.Object value = this.bar.get(); if (value == null) { @@ -26,10 +27,12 @@ class DelegateOnGetter { return (Bar)(value == this.bar ? null : value); } @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public void setList(final java.util.ArrayList<java.lang.String> list) { this.getBar().setList(list); } @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public int getInt() { return this.getBar().getInt(); } diff --git a/test/transform/resource/after-delombok/DelegateOnGetterNone.java b/test/transform/resource/after-delombok/DelegateOnGetterNone.java index 9f9411f4..c4de4f88 100644 --- a/test/transform/resource/after-delombok/DelegateOnGetterNone.java +++ b/test/transform/resource/after-delombok/DelegateOnGetterNone.java @@ -5,10 +5,12 @@ class DelegateOnGetterNone { int getInt(); } @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public void setList(final java.util.ArrayList<java.lang.String> list) { this.bar.setList(list); } @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public int getInt() { return this.bar.getInt(); } diff --git a/test/transform/resource/after-delombok/DelegateOnMethods.java b/test/transform/resource/after-delombok/DelegateOnMethods.java index b900f140..5082d961 100644 --- a/test/transform/resource/after-delombok/DelegateOnMethods.java +++ b/test/transform/resource/after-delombok/DelegateOnMethods.java @@ -6,6 +6,8 @@ abstract class DelegateOnMethods { } @java.lang.SuppressWarnings("all") + + @javax.annotation.Generated("lombok") public void bar(final java.util.ArrayList<java.lang.String> list) { this.getBar().bar(list); } diff --git a/test/transform/resource/after-delombok/DelegateTypesAndExcludes.java b/test/transform/resource/after-delombok/DelegateTypesAndExcludes.java index 3f6f555d..00a157f1 100644 --- a/test/transform/resource/after-delombok/DelegateTypesAndExcludes.java +++ b/test/transform/resource/after-delombok/DelegateTypesAndExcludes.java @@ -24,11 +24,15 @@ class DelegatePlain { } @java.lang.SuppressWarnings("all") + + @javax.annotation.Generated("lombok") public void bar(final java.util.ArrayList<java.lang.String> list) { this.bar.bar(list); } @java.lang.SuppressWarnings("all") + + @javax.annotation.Generated("lombok") public void foo() { this.foo.foo(); } diff --git a/test/transform/resource/after-delombok/DelegateWithDeprecated.java b/test/transform/resource/after-delombok/DelegateWithDeprecated.java index f7bd1e6d..6a7651db 100644 --- a/test/transform/resource/after-delombok/DelegateWithDeprecated.java +++ b/test/transform/resource/after-delombok/DelegateWithDeprecated.java @@ -11,15 +11,18 @@ class DelegateWithDeprecated { } @java.lang.Deprecated @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public void deprecatedAnnotation() { this.bar.deprecatedAnnotation(); } @java.lang.Deprecated @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public void deprecatedComment() { this.bar.deprecatedComment(); } @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public void notDeprecated() { this.bar.notDeprecated(); } diff --git a/test/transform/resource/after-delombok/EncodingUsAscii.java b/test/transform/resource/after-delombok/EncodingUsAscii.java new file mode 100644 index 00000000..4d2b169f --- /dev/null +++ b/test/transform/resource/after-delombok/EncodingUsAscii.java @@ -0,0 +1,10 @@ +//ENCODING: US-ASCII +class EncodingUsAscii { + String foo\u0e51\u0e51 = "\016\t\b "; + @java.lang.Override + @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") + public java.lang.String toString() { + return "EncodingUsAscii(foo\u0e51\u0e51=" + this.foo\u0e51\u0e51 + ")"; + } +}
\ No newline at end of file diff --git a/test/transform/resource/after-delombok/EncodingUtf8.java b/test/transform/resource/after-delombok/EncodingUtf8.java new file mode 100644 index 00000000..b1a7dcd3 --- /dev/null +++ b/test/transform/resource/after-delombok/EncodingUtf8.java @@ -0,0 +1,9 @@ +class EncodingUtf8 { + String foo๑๑ = "\016\t\b "; + @java.lang.Override + @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") + public java.lang.String toString() { + return "EncodingUtf8(foo๑๑=" + this.foo๑๑ + ")"; + } +}
\ No newline at end of file diff --git a/test/transform/resource/after-delombok/EqualsAndHashCode.java b/test/transform/resource/after-delombok/EqualsAndHashCode.java index 02ca2c42..a15b71b0 100644 --- a/test/transform/resource/after-delombok/EqualsAndHashCode.java +++ b/test/transform/resource/after-delombok/EqualsAndHashCode.java @@ -6,6 +6,7 @@ class EqualsAndHashCode { String b; @java.lang.Override @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public boolean equals(final java.lang.Object o) { if (o == this) return true; if (!(o instanceof EqualsAndHashCode)) return false; @@ -23,11 +24,13 @@ class EqualsAndHashCode { return true; } @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") protected boolean canEqual(final java.lang.Object other) { return other instanceof EqualsAndHashCode; } @java.lang.Override @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public int hashCode() { final int PRIME = 59; int result = 1; @@ -49,6 +52,7 @@ final class EqualsAndHashCode2 { boolean b; @java.lang.Override @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public boolean equals(final java.lang.Object o) { if (o == this) return true; if (!(o instanceof EqualsAndHashCode2)) return false; @@ -62,6 +66,7 @@ final class EqualsAndHashCode2 { } @java.lang.Override @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public int hashCode() { final int PRIME = 59; int result = 1; @@ -78,6 +83,7 @@ final class EqualsAndHashCode2 { final class EqualsAndHashCode3 extends EqualsAndHashCode { @java.lang.Override @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public boolean equals(final java.lang.Object o) { if (o == this) return true; if (!(o instanceof EqualsAndHashCode3)) return false; @@ -86,11 +92,13 @@ final class EqualsAndHashCode3 extends EqualsAndHashCode { return true; } @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") protected boolean canEqual(final java.lang.Object other) { return other instanceof EqualsAndHashCode3; } @java.lang.Override @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public int hashCode() { int result = 1; return result; @@ -99,6 +107,7 @@ final class EqualsAndHashCode3 extends EqualsAndHashCode { class EqualsAndHashCode4 extends EqualsAndHashCode { @java.lang.Override @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public boolean equals(final java.lang.Object o) { if (o == this) return true; if (!(o instanceof EqualsAndHashCode4)) return false; @@ -108,11 +117,13 @@ class EqualsAndHashCode4 extends EqualsAndHashCode { return true; } @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") protected boolean canEqual(final java.lang.Object other) { return other instanceof EqualsAndHashCode4; } @java.lang.Override @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public int hashCode() { final int PRIME = 59; int result = 1; diff --git a/test/transform/resource/after-delombok/EqualsAndHashCodeWithExistingMethods.java b/test/transform/resource/after-delombok/EqualsAndHashCodeWithExistingMethods.java index ac189f42..5c9316b4 100644 --- a/test/transform/resource/after-delombok/EqualsAndHashCodeWithExistingMethods.java +++ b/test/transform/resource/after-delombok/EqualsAndHashCodeWithExistingMethods.java @@ -17,6 +17,7 @@ final class EqualsAndHashCodeWithExistingMethods3 extends EqualsAndHashCodeWithE } @java.lang.Override @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public boolean equals(final java.lang.Object o) { if (o == this) return true; if (!(o instanceof EqualsAndHashCodeWithExistingMethods3)) return false; @@ -28,6 +29,7 @@ final class EqualsAndHashCodeWithExistingMethods3 extends EqualsAndHashCodeWithE } @java.lang.Override @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public int hashCode() { final int PRIME = 59; int result = 1; diff --git a/test/transform/resource/after-delombok/EqualsAndHashCodeWithOnParam.java b/test/transform/resource/after-delombok/EqualsAndHashCodeWithOnParam.java index d8d8b025..733959b0 100644 --- a/test/transform/resource/after-delombok/EqualsAndHashCodeWithOnParam.java +++ b/test/transform/resource/after-delombok/EqualsAndHashCodeWithOnParam.java @@ -9,6 +9,7 @@ class EqualsAndHashCodeWithOnParam { String b; @java.lang.Override @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public boolean equals(@Nullable final java.lang.Object o) { if (o == this) return true; if (!(o instanceof EqualsAndHashCodeWithOnParam)) return false; @@ -26,11 +27,13 @@ class EqualsAndHashCodeWithOnParam { return true; } @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") protected boolean canEqual(@Nullable final java.lang.Object other) { return other instanceof EqualsAndHashCodeWithOnParam; } @java.lang.Override @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public int hashCode() { final int PRIME = 59; int result = 1; diff --git a/test/transform/resource/after-delombok/GenerateSuppressFBWarnings.java b/test/transform/resource/after-delombok/GenerateSuppressFBWarnings.java new file mode 100644 index 00000000..377145e4 --- /dev/null +++ b/test/transform/resource/after-delombok/GenerateSuppressFBWarnings.java @@ -0,0 +1,9 @@ +class GenerateSuppressFBWarnings { + int y; + @java.lang.SuppressWarnings("all") + @edu.umd.cs.findbugs.annotations.SuppressFBWarnings(justification = "generated code") + @javax.annotation.Generated("lombok") + public int getY() { + return this.y; + } +}
\ No newline at end of file diff --git a/test/transform/resource/after-delombok/GetterAccessLevel.java b/test/transform/resource/after-delombok/GetterAccessLevel.java index 6d977d87..217c77a9 100644 --- a/test/transform/resource/after-delombok/GetterAccessLevel.java +++ b/test/transform/resource/after-delombok/GetterAccessLevel.java @@ -11,38 +11,47 @@ class GetterAccessLevel { String publicString; String value; @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") private boolean isPrivate() { return this.isPrivate; } @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") boolean isPackage() { return this.isPackage; } @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") protected boolean isProtected() { return this.isProtected; } @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public boolean isPublic() { return this.isPublic; } @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") private String getPrivateString() { return this.privateString; } @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") String getPackageString() { return this.packageString; } @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") protected String getProtectedString() { return this.protectedString; } @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public String getPublicString() { return this.publicString; } @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public String getValue() { return this.value; } diff --git a/test/transform/resource/after-delombok/GetterAlreadyExists.java b/test/transform/resource/after-delombok/GetterAlreadyExists.java index 8389ae31..a45df1a9 100644 --- a/test/transform/resource/after-delombok/GetterAlreadyExists.java +++ b/test/transform/resource/after-delombok/GetterAlreadyExists.java @@ -4,6 +4,7 @@ class Getter1 { return true; } @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public boolean isFoo() { return this.foo; } @@ -26,6 +27,7 @@ class Getter4 { return null; } @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public String getFoo() { return this.foo; } @@ -36,6 +38,7 @@ class Getter5 { return null; } @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public String getFoo() { return this.foo; } @@ -52,6 +55,7 @@ class Getter7 { return false; } @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public String getFoo() { return this.foo; } @@ -62,6 +66,7 @@ class Getter8 { return false; } @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public String getFoo() { return this.foo; } @@ -78,6 +83,7 @@ class Getter10 { return false; } @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public boolean isFoo() { return this.foo; } @@ -100,6 +106,7 @@ class Getter13 { return false; } @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public String getFoo() { return this.foo; } @@ -110,6 +117,7 @@ class Getter14 { return false; } @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public String getFoo() { return this.foo; } @@ -126,6 +134,7 @@ class Getter16 { return ""; } @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public String getFoo() { return this.foo; } @@ -136,6 +145,7 @@ class Getter17 { return ""; } @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public String getFoo() { return this.foo; } diff --git a/test/transform/resource/after-delombok/GetterBoolean.java b/test/transform/resource/after-delombok/GetterBoolean.java index 42b4319d..49b52483 100644 --- a/test/transform/resource/after-delombok/GetterBoolean.java +++ b/test/transform/resource/after-delombok/GetterBoolean.java @@ -3,14 +3,17 @@ class Getter { boolean isBar; boolean hasBaz; @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public boolean isFoo() { return this.foo; } @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public boolean isBar() { return this.isBar; } @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public boolean isHasBaz() { return this.hasBaz; } @@ -21,6 +24,7 @@ class MoreGetter { return true; } @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public boolean isFoo() { return this.foo; } diff --git a/test/transform/resource/after-delombok/GetterDeprecated.java b/test/transform/resource/after-delombok/GetterDeprecated.java index 09ea9929..d9d09e6c 100644 --- a/test/transform/resource/after-delombok/GetterDeprecated.java +++ b/test/transform/resource/after-delombok/GetterDeprecated.java @@ -7,6 +7,7 @@ class GetterDeprecated { int javadoc; @java.lang.Deprecated @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public int getAnnotation() { return this.annotation; } @@ -15,6 +16,7 @@ class GetterDeprecated { */ @java.lang.Deprecated @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public int getJavadoc() { return this.javadoc; } diff --git a/test/transform/resource/after-delombok/GetterEnum.java b/test/transform/resource/after-delombok/GetterEnum.java index 3c6e6e0c..841325c0 100644 --- a/test/transform/resource/after-delombok/GetterEnum.java +++ b/test/transform/resource/after-delombok/GetterEnum.java @@ -3,15 +3,18 @@ enum GetterEnum { private final int id; private final String name; @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") private GetterEnum(final int id, final String name) { this.id = id; this.name = name; } @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public int getId() { return this.id; } @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public String getName() { return this.name; } diff --git a/test/transform/resource/after-delombok/GetterLazy.java b/test/transform/resource/after-delombok/GetterLazy.java index 4f6f2c03..9c7db37b 100644 --- a/test/transform/resource/after-delombok/GetterLazy.java +++ b/test/transform/resource/after-delombok/GetterLazy.java @@ -3,6 +3,7 @@ class GetterLazy { } private final java.util.concurrent.atomic.AtomicReference<java.lang.Object> fieldName = new java.util.concurrent.atomic.AtomicReference<java.lang.Object>(); @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public ValueType getFieldName() { java.lang.Object value = this.fieldName.get(); if (value == null) { diff --git a/test/transform/resource/after-delombok/GetterLazyBoolean.java b/test/transform/resource/after-delombok/GetterLazyBoolean.java index f684fc07..f9a42e66 100644 --- a/test/transform/resource/after-delombok/GetterLazyBoolean.java +++ b/test/transform/resource/after-delombok/GetterLazyBoolean.java @@ -6,6 +6,7 @@ class GetterLazyBoolean { } @java.lang.Override @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public boolean equals(final java.lang.Object o) { if (o == this) return true; if (!(o instanceof GetterLazyBoolean)) return false; @@ -15,11 +16,13 @@ class GetterLazyBoolean { return true; } @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") protected boolean canEqual(final java.lang.Object other) { return other instanceof GetterLazyBoolean; } @java.lang.Override @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public int hashCode() { final int PRIME = 59; int result = 1; @@ -28,10 +31,12 @@ class GetterLazyBoolean { } @java.lang.Override @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public java.lang.String toString() { return "GetterLazyBoolean(booleanValue=" + this.isBooleanValue() + ")"; } @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public boolean isBooleanValue() { java.lang.Object value = this.booleanValue.get(); if (value == null) { @@ -47,6 +52,7 @@ class GetterLazyBoolean { return (java.lang.Boolean)value; } @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public boolean isOtherBooleanValue() { java.lang.Object value = this.otherBooleanValue.get(); if (value == null) { diff --git a/test/transform/resource/after-delombok/GetterLazyEahcToString.java b/test/transform/resource/after-delombok/GetterLazyEahcToString.java index 65c63fba..c89b2980 100644 --- a/test/transform/resource/after-delombok/GetterLazyEahcToString.java +++ b/test/transform/resource/after-delombok/GetterLazyEahcToString.java @@ -5,6 +5,7 @@ class GetterLazyEahcToString { @java.lang.Override @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public boolean equals(final java.lang.Object o) { if (o == this) return true; if (!(o instanceof GetterLazyEahcToString)) return false; @@ -20,12 +21,15 @@ class GetterLazyEahcToString { } @java.lang.SuppressWarnings("all") + + @javax.annotation.Generated("lombok") protected boolean canEqual(final java.lang.Object other) { return other instanceof GetterLazyEahcToString; } @java.lang.Override @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public int hashCode() { final int PRIME = 59; int result = 1; @@ -38,11 +42,14 @@ class GetterLazyEahcToString { @java.lang.Override @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public java.lang.String toString() { return "GetterLazyEahcToString(value=" + this.getValue() + ", value2=" + this.value2 + ")"; } @java.lang.SuppressWarnings("all") + + @javax.annotation.Generated("lombok") public String getValue() { java.lang.Object value = this.value.get(); if (value == null) { @@ -59,6 +66,8 @@ class GetterLazyEahcToString { } @java.lang.SuppressWarnings("all") + + @javax.annotation.Generated("lombok") public String getValue2() { return this.value2; } diff --git a/test/transform/resource/after-delombok/GetterLazyInvalid.java b/test/transform/resource/after-delombok/GetterLazyInvalid.java index 25963921..311b7e4a 100644 --- a/test/transform/resource/after-delombok/GetterLazyInvalid.java +++ b/test/transform/resource/after-delombok/GetterLazyInvalid.java @@ -13,6 +13,7 @@ class GetterLazyInvalidNone { class GetterLazyInvalidClass { private final String fieldName = ""; @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public String getFieldName() { return this.fieldName; } diff --git a/test/transform/resource/after-delombok/GetterLazyNative.java b/test/transform/resource/after-delombok/GetterLazyNative.java index eb31991a..50e3ff2b 100644 --- a/test/transform/resource/after-delombok/GetterLazyNative.java +++ b/test/transform/resource/after-delombok/GetterLazyNative.java @@ -9,6 +9,7 @@ class GetterLazyNative { private final java.util.concurrent.atomic.AtomicReference<java.lang.Object> charField = new java.util.concurrent.atomic.AtomicReference<java.lang.Object>(); private final java.util.concurrent.atomic.AtomicReference<java.lang.Object> intArrayField = new java.util.concurrent.atomic.AtomicReference<java.lang.Object>(); @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public boolean isBooleanField() { java.lang.Object value = this.booleanField.get(); if (value == null) { @@ -24,6 +25,7 @@ class GetterLazyNative { return (java.lang.Boolean)value; } @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public byte getByteField() { java.lang.Object value = this.byteField.get(); if (value == null) { @@ -39,6 +41,7 @@ class GetterLazyNative { return (java.lang.Byte)value; } @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public short getShortField() { java.lang.Object value = this.shortField.get(); if (value == null) { @@ -54,6 +57,7 @@ class GetterLazyNative { return (java.lang.Short)value; } @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public int getIntField() { java.lang.Object value = this.intField.get(); if (value == null) { @@ -69,6 +73,7 @@ class GetterLazyNative { return (java.lang.Integer)value; } @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public long getLongField() { java.lang.Object value = this.longField.get(); if (value == null) { @@ -84,6 +89,7 @@ class GetterLazyNative { return (java.lang.Long)value; } @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public float getFloatField() { java.lang.Object value = this.floatField.get(); if (value == null) { @@ -99,6 +105,7 @@ class GetterLazyNative { return (java.lang.Float)value; } @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public double getDoubleField() { java.lang.Object value = this.doubleField.get(); if (value == null) { @@ -114,6 +121,7 @@ class GetterLazyNative { return (java.lang.Double)value; } @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public char getCharField() { java.lang.Object value = this.charField.get(); if (value == null) { @@ -129,6 +137,7 @@ class GetterLazyNative { return (java.lang.Character)value; } @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public int[] getIntArrayField() { java.lang.Object value = this.intArrayField.get(); if (value == null) { diff --git a/test/transform/resource/after-delombok/GetterNone.java b/test/transform/resource/after-delombok/GetterNone.java index 11b4fd09..743ff468 100644 --- a/test/transform/resource/after-delombok/GetterNone.java +++ b/test/transform/resource/after-delombok/GetterNone.java @@ -2,6 +2,7 @@ class GetterNone { int i; int foo; @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public int getI() { return this.i; } diff --git a/test/transform/resource/after-delombok/GetterOnClass.java b/test/transform/resource/after-delombok/GetterOnClass.java index bd15ce35..a509f5cb 100644 --- a/test/transform/resource/after-delombok/GetterOnClass.java +++ b/test/transform/resource/after-delombok/GetterOnClass.java @@ -2,6 +2,7 @@ class GetterOnClass1 { boolean isNone; boolean isPublic; @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public boolean isPublic() { return this.isPublic; } @@ -11,10 +12,12 @@ class GetterOnClass2 { boolean isProtected; boolean isPackage; @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") protected boolean isProtected() { return this.isProtected; } @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") boolean isPackage() { return this.isPackage; } @@ -23,6 +26,7 @@ class GetterOnClass3 { boolean isNone; boolean isPackage; @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") boolean isPackage() { return this.isPackage; } @@ -31,6 +35,7 @@ class GetterOnClass4 { boolean isNone; boolean isPrivate; @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") private boolean isPrivate() { return this.isPrivate; } @@ -39,6 +44,7 @@ class GetterOnClass5 { boolean isNone; boolean isPublic; @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public boolean isPublic() { return this.isPublic; } @@ -48,11 +54,13 @@ class GetterOnClass6 { @lombok.NonNull String nonNull; @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public String getCouldBeNull() { return this.couldBeNull; } @lombok.NonNull @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public String getNonNull() { return this.nonNull; } diff --git a/test/transform/resource/after-delombok/GetterOnMethod.java b/test/transform/resource/after-delombok/GetterOnMethod.java index 4a5b3622..37ae83a4 100644 --- a/test/transform/resource/after-delombok/GetterOnMethod.java +++ b/test/transform/resource/after-delombok/GetterOnMethod.java @@ -6,18 +6,21 @@ class GetterOnMethod { } @Deprecated @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public int getI() { return this.i; } @java.lang.Deprecated @Test @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public int getJ() { return this.j; } @java.lang.Deprecated @Test @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public int getK() { return this.k; } diff --git a/test/transform/resource/after-delombok/GetterOnMethodErrors.java b/test/transform/resource/after-delombok/GetterOnMethodErrors.java index 86813bd2..094f989a 100644 --- a/test/transform/resource/after-delombok/GetterOnMethodErrors.java +++ b/test/transform/resource/after-delombok/GetterOnMethodErrors.java @@ -3,6 +3,7 @@ class PlaceFillerToMakeSurePositionIsRelevant { class GetterOnMethodErrors { private int test; @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public int getTest() { return this.test; } diff --git a/test/transform/resource/after-delombok/GetterOnMethodErrors2.java b/test/transform/resource/after-delombok/GetterOnMethodErrors2.java index 639022d0..3114d23d 100644 --- a/test/transform/resource/after-delombok/GetterOnMethodErrors2.java +++ b/test/transform/resource/after-delombok/GetterOnMethodErrors2.java @@ -10,38 +10,46 @@ class GetterOnMethodErrors2 { public @interface Test { } @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public int getBad1() { return this.bad1; } @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public int getBad2() { return this.bad2; } @Deprecated @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public int getBad3() { return this.bad3; } @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public int getBad4() { return this.bad4; } @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public int getGood1() { return this.good1; } @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public int getGood2() { return this.good2; } @Deprecated @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public int getGood3() { return this.good3; } @Deprecated @Test @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public int getGood4() { return this.good4; } diff --git a/test/transform/resource/after-delombok/GetterOnStatic.java b/test/transform/resource/after-delombok/GetterOnStatic.java index 99e63e05..34c2dba1 100644 --- a/test/transform/resource/after-delombok/GetterOnStatic.java +++ b/test/transform/resource/after-delombok/GetterOnStatic.java @@ -2,10 +2,12 @@ class Getter { static boolean foo; static int bar; @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public static boolean isFoo() { return Getter.foo; } @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public static int getBar() { return Getter.bar; } diff --git a/test/transform/resource/after-delombok/GetterPlain.java b/test/transform/resource/after-delombok/GetterPlain.java index 359d46e2..1cdfef8f 100644 --- a/test/transform/resource/after-delombok/GetterPlain.java +++ b/test/transform/resource/after-delombok/GetterPlain.java @@ -2,10 +2,12 @@ class GetterPlain { int i; int foo; @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public int getI() { return this.i; } @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public int getFoo() { return this.foo; } diff --git a/test/transform/resource/after-delombok/GetterSetterJavadoc.java b/test/transform/resource/after-delombok/GetterSetterJavadoc.java index 7a782434..f4f04fa1 100644 --- a/test/transform/resource/after-delombok/GetterSetterJavadoc.java +++ b/test/transform/resource/after-delombok/GetterSetterJavadoc.java @@ -4,6 +4,7 @@ class GetterSetterJavadoc1 { */ private int fieldName; @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public GetterSetterJavadoc1() { } /** @@ -12,6 +13,7 @@ class GetterSetterJavadoc1 { * @return Sky is blue1 */ @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public int getFieldName() { return this.fieldName; } @@ -21,11 +23,13 @@ class GetterSetterJavadoc1 { * @param fieldName Hello, World1 */ @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public void setFieldName(final int fieldName) { this.fieldName = fieldName; } @java.lang.Override @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public boolean equals(final java.lang.Object o) { if (o == this) return true; if (!(o instanceof GetterSetterJavadoc1)) return false; @@ -35,11 +39,13 @@ class GetterSetterJavadoc1 { return true; } @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") protected boolean canEqual(final java.lang.Object other) { return other instanceof GetterSetterJavadoc1; } @java.lang.Override @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public int hashCode() { final int PRIME = 59; int result = 1; @@ -48,6 +54,7 @@ class GetterSetterJavadoc1 { } @java.lang.Override @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public java.lang.String toString() { return "GetterSetterJavadoc1(fieldName=" + this.getFieldName() + ")"; } @@ -63,6 +70,7 @@ class GetterSetterJavadoc2 { * @return Sky is blue2 */ @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public int getFieldName() { return this.fieldName; } @@ -72,6 +80,7 @@ class GetterSetterJavadoc2 { * @param fieldName Hello, World2 */ @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public void setFieldName(final int fieldName) { this.fieldName = fieldName; } @@ -86,6 +95,7 @@ class GetterSetterJavadoc3 { * @return Sky is blue3 */ @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public int getFieldName() { return this.fieldName; } @@ -94,6 +104,7 @@ class GetterSetterJavadoc3 { * @param fieldName Hello, World3 */ @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public void setFieldName(final int fieldName) { this.fieldName = fieldName; } diff --git a/test/transform/resource/after-delombok/GetterWithDollar.java b/test/transform/resource/after-delombok/GetterWithDollar.java index 520f4ea5..21e5fac8 100644 --- a/test/transform/resource/after-delombok/GetterWithDollar.java +++ b/test/transform/resource/after-delombok/GetterWithDollar.java @@ -1,6 +1,7 @@ class GetterWithDollar1 { int $i; @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public int get$i() { return this.$i; } @@ -9,10 +10,12 @@ class GetterWithDollar2 { int $i; int i; @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public int get$i() { return this.$i; } @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public int getI() { return this.i; } diff --git a/test/transform/resource/after-delombok/InjectField.java b/test/transform/resource/after-delombok/InjectField.java index 59896400..55390a60 100644 --- a/test/transform/resource/after-delombok/InjectField.java +++ b/test/transform/resource/after-delombok/InjectField.java @@ -5,10 +5,14 @@ enum InjectField1 { B; @java.lang.SuppressWarnings("all") + + @javax.annotation.Generated("lombok") private static final java.util.logging.Logger log = java.util.logging.Logger.getLogger(InjectField1.class.getName()); @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") private final java.lang.Object $lock = new java.lang.Object[0]; @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") private static final java.lang.Object $LOCK = new java.lang.Object[0]; private static final String LOG_MESSAGE = "static initializer"; @@ -36,8 +40,10 @@ enum InjectField1 { class InjectField2 { @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") private static final java.util.logging.Logger log = java.util.logging.Logger.getLogger(InjectField2.class.getName()); @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") private final java.lang.Object $lock = new java.lang.Object[0]; private static final String LOG_MESSAGE = "static initializer"; @@ -55,6 +61,7 @@ class InjectField2 { class InjectField3 { @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") private static final java.util.logging.Logger log = java.util.logging.Logger.getLogger(InjectField3.class.getName()); static { log.log(Level.FINE, "static initializer"); diff --git a/test/transform/resource/after-delombok/LoggerCommons.java b/test/transform/resource/after-delombok/LoggerCommons.java index 32ace53a..85ad75b7 100644 --- a/test/transform/resource/after-delombok/LoggerCommons.java +++ b/test/transform/resource/after-delombok/LoggerCommons.java @@ -1,12 +1,15 @@ class LoggerCommons { @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") private static final org.apache.commons.logging.Log log = org.apache.commons.logging.LogFactory.getLog(LoggerCommons.class); } class LoggerCommonsWithImport { @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") private static final org.apache.commons.logging.Log log = org.apache.commons.logging.LogFactory.getLog(LoggerCommonsWithImport.class); } class LoggerCommonsWithDifferentName { @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") private static final org.apache.commons.logging.Log log = org.apache.commons.logging.LogFactory.getLog("DifferentName"); }
\ No newline at end of file diff --git a/test/transform/resource/after-delombok/LoggerConfig.java b/test/transform/resource/after-delombok/LoggerConfig.java index ba955638..fcfb118f 100644 --- a/test/transform/resource/after-delombok/LoggerConfig.java +++ b/test/transform/resource/after-delombok/LoggerConfig.java @@ -1,4 +1,5 @@ class LoggerWithConfig { @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") private final org.slf4j.Logger myLogger = org.slf4j.LoggerFactory.getLogger(LoggerWithConfig.class); }
\ No newline at end of file diff --git a/test/transform/resource/after-delombok/LoggerJul.java b/test/transform/resource/after-delombok/LoggerJul.java index ad119777..eabfb94a 100644 --- a/test/transform/resource/after-delombok/LoggerJul.java +++ b/test/transform/resource/after-delombok/LoggerJul.java @@ -1,12 +1,15 @@ class LoggerJul { @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") private static final java.util.logging.Logger log = java.util.logging.Logger.getLogger(LoggerJul.class.getName()); } class LoggerJulWithImport { @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") private static final java.util.logging.Logger log = java.util.logging.Logger.getLogger(LoggerJulWithImport.class.getName()); } class LoggerJulWithDifferentName { @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") private static final java.util.logging.Logger log = java.util.logging.Logger.getLogger("DifferentName"); }
\ No newline at end of file diff --git a/test/transform/resource/after-delombok/LoggerLog4j.java b/test/transform/resource/after-delombok/LoggerLog4j.java index 99eac34f..39667670 100644 --- a/test/transform/resource/after-delombok/LoggerLog4j.java +++ b/test/transform/resource/after-delombok/LoggerLog4j.java @@ -1,12 +1,15 @@ class LoggerLog4j { @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") private static final org.apache.log4j.Logger log = org.apache.log4j.Logger.getLogger(LoggerLog4j.class); } class LoggerLog4jWithImport { @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") private static final org.apache.log4j.Logger log = org.apache.log4j.Logger.getLogger(LoggerLog4jWithImport.class); } class LoggerLog4jWithDifferentName { @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") private static final org.apache.log4j.Logger log = org.apache.log4j.Logger.getLogger("DifferentName"); }
\ No newline at end of file diff --git a/test/transform/resource/after-delombok/LoggerLog4j2.java b/test/transform/resource/after-delombok/LoggerLog4j2.java index 8473134b..4d1ef01f 100644 --- a/test/transform/resource/after-delombok/LoggerLog4j2.java +++ b/test/transform/resource/after-delombok/LoggerLog4j2.java @@ -1,12 +1,15 @@ class LoggerLog4j2 { @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") private static final org.apache.logging.log4j.Logger log = org.apache.logging.log4j.LogManager.getLogger(LoggerLog4j2.class); } class LoggerLog4j2WithImport { @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") private static final org.apache.logging.log4j.Logger log = org.apache.logging.log4j.LogManager.getLogger(LoggerLog4j2WithImport.class); } class LoggerLog4j2WithDifferentName { @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") private static final org.apache.logging.log4j.Logger log = org.apache.logging.log4j.LogManager.getLogger("DifferentName"); }
\ No newline at end of file diff --git a/test/transform/resource/after-delombok/LoggerSlf4j.java b/test/transform/resource/after-delombok/LoggerSlf4j.java index 3c6e6d2f..91109145 100644 --- a/test/transform/resource/after-delombok/LoggerSlf4j.java +++ b/test/transform/resource/after-delombok/LoggerSlf4j.java @@ -1,19 +1,23 @@ class LoggerSlf4j { @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") private static final org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(LoggerSlf4j.class); } class LoggerSlf4jWithImport { @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") private static final org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(LoggerSlf4jWithImport.class); } class LoggerSlf4jOuter { static class Inner { @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") private static final org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(Inner.class); } } class LoggerSlf4jWithDifferentLoggerName { @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") private static final org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger("DifferentLogger"); }
\ No newline at end of file diff --git a/test/transform/resource/after-delombok/LoggerSlf4jTypes.java b/test/transform/resource/after-delombok/LoggerSlf4jTypes.java index 5ea59924..e987d807 100644 --- a/test/transform/resource/after-delombok/LoggerSlf4jTypes.java +++ b/test/transform/resource/after-delombok/LoggerSlf4jTypes.java @@ -5,16 +5,19 @@ interface LoggerSlf4jTypesInterface { enum LoggerSlf4jTypesEnum { ; @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") private static final org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(LoggerSlf4jTypesEnum.class); } enum LoggerSlf4jTypesEnumWithElement { FOO; @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") private static final org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(LoggerSlf4jTypesEnumWithElement.class); } interface LoggerSlf4jTypesInterfaceOuter { class Inner { @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") private static final org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(Inner.class); } }
\ No newline at end of file diff --git a/test/transform/resource/after-delombok/LoggerSlf4jWithPackage.java b/test/transform/resource/after-delombok/LoggerSlf4jWithPackage.java index b82ed6ec..8a1d543f 100644 --- a/test/transform/resource/after-delombok/LoggerSlf4jWithPackage.java +++ b/test/transform/resource/after-delombok/LoggerSlf4jWithPackage.java @@ -1,11 +1,13 @@ package before; class LoggerSlf4jWithPackage { @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") private static final org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(LoggerSlf4jWithPackage.class); } class LoggerSlf4jWithPackageOuter { static class Inner { @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") private static final org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(Inner.class); } } diff --git a/test/transform/resource/after-delombok/LoggerXSlf4j.java b/test/transform/resource/after-delombok/LoggerXSlf4j.java index d0654b51..ec1c3e4e 100644 --- a/test/transform/resource/after-delombok/LoggerXSlf4j.java +++ b/test/transform/resource/after-delombok/LoggerXSlf4j.java @@ -1,12 +1,15 @@ class LoggerXSlf4j { @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") private static final org.slf4j.ext.XLogger log = org.slf4j.ext.XLoggerFactory.getXLogger(LoggerXSlf4j.class); } class LoggerXSlf4jWithImport { @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") private static final org.slf4j.ext.XLogger log = org.slf4j.ext.XLoggerFactory.getXLogger(LoggerXSlf4jWithImport.class); } class LoggerXSlf4jWithDifferentName { @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") private static final org.slf4j.ext.XLogger log = org.slf4j.ext.XLoggerFactory.getXLogger("DifferentName"); }
\ No newline at end of file diff --git a/test/transform/resource/after-delombok/MixGetterVal.java b/test/transform/resource/after-delombok/MixGetterVal.java index abc60d56..ee747e2a 100644 --- a/test/transform/resource/after-delombok/MixGetterVal.java +++ b/test/transform/resource/after-delombok/MixGetterVal.java @@ -9,6 +9,7 @@ class MixGetterVal { m(a); } @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public int getX() { return this.x; } diff --git a/test/transform/resource/after-delombok/MultiFieldGetter.java b/test/transform/resource/after-delombok/MultiFieldGetter.java index ed84f4ed..8ed250e1 100644 --- a/test/transform/resource/after-delombok/MultiFieldGetter.java +++ b/test/transform/resource/after-delombok/MultiFieldGetter.java @@ -2,10 +2,12 @@ class MultiFieldGetter { int x; int y; @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") protected int getX() { return this.x; } @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") protected int getY() { return this.y; } @@ -14,10 +16,12 @@ class MultiFieldGetter2 { int x; int y; @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") int getX() { return this.x; } @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") int getY() { return this.y; } diff --git a/test/transform/resource/after-delombok/NonNullPlain.java b/test/transform/resource/after-delombok/NonNullPlain.java index b7d27ef3..52a80c1a 100644 --- a/test/transform/resource/after-delombok/NonNullPlain.java +++ b/test/transform/resource/after-delombok/NonNullPlain.java @@ -12,6 +12,7 @@ class NonNullPlain { } @java.beans.ConstructorProperties({"i", "s"}) @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public NonNullPlain(@lombok.NonNull final int i, @lombok.NonNull final String s) { if (s == null) { throw new java.lang.NullPointerException("s"); @@ -21,23 +22,28 @@ class NonNullPlain { } @lombok.NonNull @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public int getI() { return this.i; } @lombok.NonNull @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public String getS() { return this.s; } @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public Object getO() { return this.o; } @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public void setI(@lombok.NonNull final int i) { this.i = i; } @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public void setS(@lombok.NonNull final String s) { if (s == null) { throw new java.lang.NullPointerException("s"); @@ -45,6 +51,7 @@ class NonNullPlain { this.s = s; } @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public void setO(final Object o) { this.o = o; } diff --git a/test/transform/resource/after-delombok/NonNullWithAlternateException.java b/test/transform/resource/after-delombok/NonNullWithAlternateException.java index 686a1219..9b606076 100644 --- a/test/transform/resource/after-delombok/NonNullWithAlternateException.java +++ b/test/transform/resource/after-delombok/NonNullWithAlternateException.java @@ -8,6 +8,7 @@ public class NonNullWithAlternateException { System.out.println(arg); } @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public void setTest(@lombok.NonNull final String test) { if (test == null) { throw new java.lang.IllegalArgumentException("test is null"); diff --git a/test/transform/resource/after-delombok/SetterAccessLevel.java b/test/transform/resource/after-delombok/SetterAccessLevel.java index 45df2b35..0bf20cd7 100644 --- a/test/transform/resource/after-delombok/SetterAccessLevel.java +++ b/test/transform/resource/after-delombok/SetterAccessLevel.java @@ -6,22 +6,27 @@ class SetterAccessLevel { boolean isPublic; boolean value; @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") private void setPrivate(final boolean isPrivate) { this.isPrivate = isPrivate; } @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") void setPackage(final boolean isPackage) { this.isPackage = isPackage; } @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") protected void setProtected(final boolean isProtected) { this.isProtected = isProtected; } @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public void setPublic(final boolean isPublic) { this.isPublic = isPublic; } @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public void setValue(final boolean value) { this.value = value; } diff --git a/test/transform/resource/after-delombok/SetterAlreadyExists.java b/test/transform/resource/after-delombok/SetterAlreadyExists.java index 5bfc1f83..52e0ca10 100644 --- a/test/transform/resource/after-delombok/SetterAlreadyExists.java +++ b/test/transform/resource/after-delombok/SetterAlreadyExists.java @@ -23,6 +23,7 @@ class Setter5 { void setFoo() { } @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public void setFoo(final String foo) { this.foo = foo; } @@ -32,6 +33,7 @@ class Setter6 { void setFoo(String foo, int x) { } @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public void setFoo(final String foo) { this.foo = foo; } diff --git a/test/transform/resource/after-delombok/SetterDeprecated.java b/test/transform/resource/after-delombok/SetterDeprecated.java index 72a609ad..7e984c6d 100644 --- a/test/transform/resource/after-delombok/SetterDeprecated.java +++ b/test/transform/resource/after-delombok/SetterDeprecated.java @@ -7,6 +7,7 @@ class SetterDeprecated { int javadoc; @java.lang.Deprecated @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public void setAnnotation(final int annotation) { this.annotation = annotation; } @@ -15,6 +16,7 @@ class SetterDeprecated { */ @java.lang.Deprecated @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public void setJavadoc(final int javadoc) { this.javadoc = javadoc; } diff --git a/test/transform/resource/after-delombok/SetterOnClass.java b/test/transform/resource/after-delombok/SetterOnClass.java index 7077c492..eaf57def 100644 --- a/test/transform/resource/after-delombok/SetterOnClass.java +++ b/test/transform/resource/after-delombok/SetterOnClass.java @@ -2,6 +2,7 @@ class SetterOnClass1 { boolean isNone; boolean isPublic; @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public void setPublic(final boolean isPublic) { this.isPublic = isPublic; } @@ -11,10 +12,12 @@ class SetterOnClass2 { boolean isProtected; boolean isPackage; @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") protected void setProtected(final boolean isProtected) { this.isProtected = isProtected; } @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") void setPackage(final boolean isPackage) { this.isPackage = isPackage; } @@ -23,6 +26,7 @@ class SetterOnClass3 { boolean isNone; boolean isPackage; @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") void setPackage(final boolean isPackage) { this.isPackage = isPackage; } @@ -31,6 +35,7 @@ class SetterOnClass4 { boolean isNone; boolean isPrivate; @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") private void setPrivate(final boolean isPrivate) { this.isPrivate = isPrivate; } @@ -39,6 +44,7 @@ class SetterOnClass5 { boolean isNone; boolean isPublic; @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public void setPublic(final boolean isPublic) { this.isPublic = isPublic; } @@ -48,10 +54,12 @@ class SetterOnClass6 { @lombok.NonNull String nonNull; @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public void setCouldBeNull(final String couldBeNull) { this.couldBeNull = couldBeNull; } @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public void setNonNull(@lombok.NonNull final String nonNull) { if (nonNull == null) { throw new java.lang.NullPointerException("nonNull"); diff --git a/test/transform/resource/after-delombok/SetterOnMethodOnParam.java b/test/transform/resource/after-delombok/SetterOnMethodOnParam.java index 555bf698..c166f936 100644 --- a/test/transform/resource/after-delombok/SetterOnMethodOnParam.java +++ b/test/transform/resource/after-delombok/SetterOnMethodOnParam.java @@ -6,18 +6,21 @@ class SetterOnMethodOnParam { } @Deprecated @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public void setI(final int i) { this.i = i; } @java.lang.Deprecated @Test @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public void setJ(@Test final int j) { this.j = j; } @java.lang.Deprecated @Test @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public void setK(@Test final int k) { this.k = k; } diff --git a/test/transform/resource/after-delombok/SetterOnStatic.java b/test/transform/resource/after-delombok/SetterOnStatic.java index 7ef68362..a1947b36 100644 --- a/test/transform/resource/after-delombok/SetterOnStatic.java +++ b/test/transform/resource/after-delombok/SetterOnStatic.java @@ -2,10 +2,12 @@ class Setter { static boolean foo; static int bar; @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public static void setFoo(final boolean foo) { Setter.foo = foo; } @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public static void setBar(final int bar) { Setter.bar = bar; } diff --git a/test/transform/resource/after-delombok/SetterPlain.java b/test/transform/resource/after-delombok/SetterPlain.java index 39aa7b61..3f55bd21 100644 --- a/test/transform/resource/after-delombok/SetterPlain.java +++ b/test/transform/resource/after-delombok/SetterPlain.java @@ -2,10 +2,12 @@ class SetterPlain { int i; int foo; @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public void setI(final int i) { this.i = i; } @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public void setFoo(final int foo) { this.foo = foo; } diff --git a/test/transform/resource/after-delombok/SetterWithDollar.java b/test/transform/resource/after-delombok/SetterWithDollar.java index 974efdcd..3bdafa1b 100644 --- a/test/transform/resource/after-delombok/SetterWithDollar.java +++ b/test/transform/resource/after-delombok/SetterWithDollar.java @@ -2,6 +2,8 @@ class SetterWithDollar1 { int $i; @java.lang.SuppressWarnings("all") + + @javax.annotation.Generated("lombok") public void set$i(final int $i) { this.$i = $i; } @@ -11,10 +13,13 @@ class SetterWithDollar2 { int i; @java.lang.SuppressWarnings("all") + + @javax.annotation.Generated("lombok") public void set$i(final int $i) { this.$i = $i; } @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public void setI(final int i) { this.i = i; } diff --git a/test/transform/resource/after-delombok/SimpleTypeResolution.java b/test/transform/resource/after-delombok/SimpleTypeResolution.java index c6e08d70..1e45bb79 100644 --- a/test/transform/resource/after-delombok/SimpleTypeResolution.java +++ b/test/transform/resource/after-delombok/SimpleTypeResolution.java @@ -5,6 +5,7 @@ class SimpleTypeResolutionFail { class SimpleTypeResolutionSuccess { private int x; @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public int getX() { return this.x; } diff --git a/test/transform/resource/after-delombok/SynchronizedPlain.java b/test/transform/resource/after-delombok/SynchronizedPlain.java index 1a065085..f0082faf 100644 --- a/test/transform/resource/after-delombok/SynchronizedPlain.java +++ b/test/transform/resource/after-delombok/SynchronizedPlain.java @@ -1,5 +1,6 @@ class SynchronizedPlain1 { @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") private final java.lang.Object $lock = new java.lang.Object[0]; void test() { synchronized (this.$lock) { @@ -14,6 +15,7 @@ class SynchronizedPlain1 { } class SynchronizedPlain2 { @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") private static final java.lang.Object $LOCK = new java.lang.Object[0]; static void test() { synchronized (SynchronizedPlain2.$LOCK) { diff --git a/test/transform/resource/after-delombok/ToStringConfiguration.java b/test/transform/resource/after-delombok/ToStringConfiguration.java index 035ecdb2..c44f8b75 100644 --- a/test/transform/resource/after-delombok/ToStringConfiguration.java +++ b/test/transform/resource/after-delombok/ToStringConfiguration.java @@ -2,10 +2,12 @@ class ToStringConfiguration { int x; @java.lang.Override @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public java.lang.String toString() { return "ToStringConfiguration(" + this.x + ")"; } @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public int getX() { return this.x; } @@ -14,6 +16,7 @@ class ToStringConfiguration2 { int x; @java.lang.Override @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public java.lang.String toString() { return "ToStringConfiguration2(x=" + this.x + ")"; } @@ -22,10 +25,12 @@ class ToStringConfiguration3 { int x; @java.lang.Override @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public java.lang.String toString() { return "ToStringConfiguration3(" + this.getX() + ")"; } @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public int getX() { return this.x; } diff --git a/test/transform/resource/after-delombok/ToStringInner.java b/test/transform/resource/after-delombok/ToStringInner.java index 7b1d5e21..e8cea8fd 100644 --- a/test/transform/resource/after-delombok/ToStringInner.java +++ b/test/transform/resource/after-delombok/ToStringInner.java @@ -5,6 +5,7 @@ class ToStringOuter { int y; @java.lang.Override @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public java.lang.String toString() { return "ToStringOuter.ToStringInner(y=" + this.y + ")"; } @@ -13,6 +14,7 @@ class ToStringOuter { int y; @java.lang.Override @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public java.lang.String toString() { return "ToStringOuter.ToStringStaticInner(y=" + this.y + ")"; } @@ -22,6 +24,7 @@ class ToStringOuter { String name; @java.lang.Override @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public java.lang.String toString() { return "ToStringOuter.ToStringMiddle.ToStringMoreInner(name=" + this.name + ")"; } @@ -30,6 +33,7 @@ class ToStringOuter { @java.lang.Override @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public java.lang.String toString() { return "ToStringOuter(x=" + this.x + ", name=" + this.name + ")"; } diff --git a/test/transform/resource/after-delombok/ToStringPlain.java b/test/transform/resource/after-delombok/ToStringPlain.java index e6f3db7a..a4265575 100644 --- a/test/transform/resource/after-delombok/ToStringPlain.java +++ b/test/transform/resource/after-delombok/ToStringPlain.java @@ -3,6 +3,7 @@ class ToString1 { String name; @java.lang.Override @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public java.lang.String toString() { return "ToString1(x=" + this.x + ", name=" + this.name + ")"; } @@ -12,6 +13,7 @@ class ToString2 { String name; @java.lang.Override @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public java.lang.String toString() { return "ToString2(x=" + this.x + ", name=" + this.name + ")"; } diff --git a/test/transform/resource/after-delombok/Tolerate.java b/test/transform/resource/after-delombok/Tolerate.java index fbb42f1b..387739af 100644 --- a/test/transform/resource/after-delombok/Tolerate.java +++ b/test/transform/resource/after-delombok/Tolerate.java @@ -10,11 +10,15 @@ class Tolerate { } @java.lang.SuppressWarnings("all") + + @javax.annotation.Generated("lombok") public void setPattern(final Pattern pattern) { this.pattern = pattern; } @java.lang.SuppressWarnings("all") + + @javax.annotation.Generated("lombok") public Pattern getPattern() { return this.pattern; } @@ -32,17 +36,22 @@ class Tolerate2 { } @java.lang.SuppressWarnings("all") + + @javax.annotation.Generated("lombok") public Pattern getPattern() { return this.pattern; } @java.lang.SuppressWarnings("all") + + @javax.annotation.Generated("lombok") public Tolerate2 withPattern(final Pattern pattern) { return this.pattern == pattern ? this : new Tolerate2(pattern); } @java.beans.ConstructorProperties({"pattern"}) @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public Tolerate2(final Pattern pattern) { this.pattern = pattern; } diff --git a/test/transform/resource/after-delombok/TrickyTypeResolution.java b/test/transform/resource/after-delombok/TrickyTypeResolution.java index 9a5aae16..6badfbf4 100644 --- a/test/transform/resource/after-delombok/TrickyTypeResolution.java +++ b/test/transform/resource/after-delombok/TrickyTypeResolution.java @@ -14,6 +14,7 @@ class TrickyDoNothing2 { class TrickySuccess { int x; @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public int getX() { return this.x; } diff --git a/test/transform/resource/after-delombok/ValAnonymousSubclassWithGenerics.java b/test/transform/resource/after-delombok/ValAnonymousSubclassWithGenerics.java new file mode 100644 index 00000000..25a9e0ce --- /dev/null +++ b/test/transform/resource/after-delombok/ValAnonymousSubclassWithGenerics.java @@ -0,0 +1,18 @@ +import java.util.*; +public class ValAnonymousSubclassWithGenerics { + Object object = new Object(){ + void foo() { + final int j = 1; + } + }; + void bar() { + final int k = super.hashCode(); + int x = k; + } + java.util.List<String> names = new java.util.ArrayList<String>(){ + public String get(int i) { + final java.lang.String result = super.get(i); + return result; + } + }; +} diff --git a/test/transform/resource/after-delombok/ValWithLocalClasses.java b/test/transform/resource/after-delombok/ValWithLocalClasses.java new file mode 100644 index 00000000..b739b10e --- /dev/null +++ b/test/transform/resource/after-delombok/ValWithLocalClasses.java @@ -0,0 +1,11 @@ +class ValWithLocalClasses1 { + { + final ValWithLocalClasses2 f2 = new ValWithLocalClasses2(){ + }; + } +} +class ValWithLocalClasses2 { + { + final int f3 = 0; + } +} diff --git a/test/transform/resource/after-delombok/ValueExperimental.java b/test/transform/resource/after-delombok/ValueExperimental.java index 77a48ec9..20e7a9f4 100644 --- a/test/transform/resource/after-delombok/ValueExperimental.java +++ b/test/transform/resource/after-delombok/ValueExperimental.java @@ -1,9 +1,11 @@ final class ValueExperimental1 { @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public ValueExperimental1() { } @java.lang.Override @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public boolean equals(final java.lang.Object o) { if (o == this) return true; if (!(o instanceof ValueExperimental1)) return false; @@ -11,22 +13,26 @@ final class ValueExperimental1 { } @java.lang.Override @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public int hashCode() { int result = 1; return result; } @java.lang.Override @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public java.lang.String toString() { return "ValueExperimental1()"; } } final class ValueExperimental2 { @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public ValueExperimental2() { } @java.lang.Override @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public boolean equals(final java.lang.Object o) { if (o == this) return true; if (!(o instanceof ValueExperimental2)) return false; @@ -34,12 +40,14 @@ final class ValueExperimental2 { } @java.lang.Override @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public int hashCode() { int result = 1; return result; } @java.lang.Override @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public java.lang.String toString() { return "ValueExperimental2()"; } diff --git a/test/transform/resource/after-delombok/ValueExperimentalStarImport.java b/test/transform/resource/after-delombok/ValueExperimentalStarImport.java index 6911f260..ea9c4600 100644 --- a/test/transform/resource/after-delombok/ValueExperimentalStarImport.java +++ b/test/transform/resource/after-delombok/ValueExperimentalStarImport.java @@ -1,11 +1,13 @@ import lombok.experimental.*; final class ValueExperimentalStarImport { @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public ValueExperimentalStarImport() { } @java.lang.Override @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public boolean equals(final java.lang.Object o) { if (o == this) return true; if (!(o instanceof ValueExperimentalStarImport)) return false; @@ -13,12 +15,14 @@ final class ValueExperimentalStarImport { } @java.lang.Override @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public int hashCode() { int result = 1; return result; } @java.lang.Override @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public java.lang.String toString() { return "ValueExperimentalStarImport()"; } diff --git a/test/transform/resource/after-delombok/ValuePlain.java b/test/transform/resource/after-delombok/ValuePlain.java index 64e5b9b9..09c301d2 100644 --- a/test/transform/resource/after-delombok/ValuePlain.java +++ b/test/transform/resource/after-delombok/ValuePlain.java @@ -3,20 +3,24 @@ final class Value1 { private final String name; @java.beans.ConstructorProperties({"x", "name"}) @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public Value1(final int x, final String name) { this.x = x; this.name = name; } @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public int getX() { return this.x; } @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public String getName() { return this.name; } @java.lang.Override @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public boolean equals(final java.lang.Object o) { if (o == this) return true; if (!(o instanceof Value1)) return false; @@ -29,6 +33,7 @@ final class Value1 { } @java.lang.Override @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public int hashCode() { final int PRIME = 59; int result = 1; @@ -39,6 +44,7 @@ final class Value1 { } @java.lang.Override @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public java.lang.String toString() { return "Value1(x=" + this.getX() + ", name=" + this.getName() + ")"; } @@ -48,20 +54,24 @@ class Value2 { private final String name; @java.beans.ConstructorProperties({"x", "name"}) @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public Value2(final int x, final String name) { this.x = x; this.name = name; } @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public int getX() { return this.x; } @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public String getName() { return this.name; } @java.lang.Override @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public boolean equals(final java.lang.Object o) { if (o == this) return true; if (!(o instanceof Value2)) return false; @@ -74,11 +84,13 @@ class Value2 { return true; } @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") protected boolean canEqual(final java.lang.Object other) { return other instanceof Value2; } @java.lang.Override @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public int hashCode() { final int PRIME = 59; int result = 1; @@ -89,6 +101,7 @@ class Value2 { } @java.lang.Override @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public java.lang.String toString() { return "Value2(x=" + this.getX() + ", name=" + this.getName() + ")"; } @@ -98,20 +111,24 @@ final class Value3 { private final int y; @java.beans.ConstructorProperties({"x", "y"}) @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public Value3(final int x, final int y) { this.x = x; this.y = y; } @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public int getX() { return this.x; } @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public int getY() { return this.y; } @java.lang.Override @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public boolean equals(final java.lang.Object o) { if (o == this) return true; if (!(o instanceof Value3)) return false; @@ -122,6 +139,7 @@ final class Value3 { } @java.lang.Override @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public int hashCode() { final int PRIME = 59; int result = 1; @@ -131,6 +149,7 @@ final class Value3 { } @java.lang.Override @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public java.lang.String toString() { return "Value3(x=" + this.getX() + ", y=" + this.getY() + ")"; } diff --git a/test/transform/resource/after-delombok/WitherAccessLevel.java b/test/transform/resource/after-delombok/WitherAccessLevel.java index 963f6972..7ec03215 100644 --- a/test/transform/resource/after-delombok/WitherAccessLevel.java +++ b/test/transform/resource/after-delombok/WitherAccessLevel.java @@ -8,22 +8,27 @@ class WitherAccessLevel { WitherAccessLevel(boolean isNone, boolean isPrivate, boolean isPackage, boolean isProtected, boolean isPublic, boolean value) { } @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") private WitherAccessLevel withPrivate(final boolean isPrivate) { return this.isPrivate == isPrivate ? this : new WitherAccessLevel(this.isNone, isPrivate, this.isPackage, this.isProtected, this.isPublic, this.value); } @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") WitherAccessLevel withPackage(final boolean isPackage) { return this.isPackage == isPackage ? this : new WitherAccessLevel(this.isNone, this.isPrivate, isPackage, this.isProtected, this.isPublic, this.value); } @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") protected WitherAccessLevel withProtected(final boolean isProtected) { return this.isProtected == isProtected ? this : new WitherAccessLevel(this.isNone, this.isPrivate, this.isPackage, isProtected, this.isPublic, this.value); } @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public WitherAccessLevel withPublic(final boolean isPublic) { return this.isPublic == isPublic ? this : new WitherAccessLevel(this.isNone, this.isPrivate, this.isPackage, this.isProtected, isPublic, this.value); } @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public WitherAccessLevel withValue(final boolean value) { return this.value == value ? this : new WitherAccessLevel(this.isNone, this.isPrivate, this.isPackage, this.isProtected, this.isPublic, value); } diff --git a/test/transform/resource/after-delombok/WitherAlreadyExists.java b/test/transform/resource/after-delombok/WitherAlreadyExists.java index be41f6bc..48dda94d 100644 --- a/test/transform/resource/after-delombok/WitherAlreadyExists.java +++ b/test/transform/resource/after-delombok/WitherAlreadyExists.java @@ -33,6 +33,7 @@ class Wither5 { Wither5(String foo) { } @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public Wither5 withFoo(final String foo) { return this.foo == foo ? this : new Wither5(foo); } @@ -44,6 +45,7 @@ class Wither6 { Wither6(String foo) { } @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public Wither6 withFoo(final String foo) { return this.foo == foo ? this : new Wither6(foo); } diff --git a/test/transform/resource/after-delombok/WitherAndAllArgsConstructor.java b/test/transform/resource/after-delombok/WitherAndAllArgsConstructor.java index 7607dce4..2ffd310c 100644 --- a/test/transform/resource/after-delombok/WitherAndAllArgsConstructor.java +++ b/test/transform/resource/after-delombok/WitherAndAllArgsConstructor.java @@ -6,6 +6,7 @@ class WitherAndAllArgsConstructor<T, J extends T, L extends java.lang.Number> { final int z; @java.beans.ConstructorProperties({"test", "test2", "y", "z"}) @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public WitherAndAllArgsConstructor(final J test, final java.util.List<L> test2, final int y, final int z) { this.test = test; this.test2 = test2; @@ -13,10 +14,12 @@ class WitherAndAllArgsConstructor<T, J extends T, L extends java.lang.Number> { this.z = z; } @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public WitherAndAllArgsConstructor<T, J, L> withTest(final J test) { return this.test == test ? this : new WitherAndAllArgsConstructor<T, J, L>(test, this.test2, this.y, this.z); } @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public WitherAndAllArgsConstructor<T, J, L> withTest2(final java.util.List<L> test2) { return this.test2 == test2 ? this : new WitherAndAllArgsConstructor<T, J, L>(this.test, test2, this.y, this.z); } diff --git a/test/transform/resource/after-delombok/WitherDeprecated.java b/test/transform/resource/after-delombok/WitherDeprecated.java index 29192012..712bd603 100644 --- a/test/transform/resource/after-delombok/WitherDeprecated.java +++ b/test/transform/resource/after-delombok/WitherDeprecated.java @@ -9,6 +9,7 @@ class WitherDeprecated { } @java.lang.Deprecated @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public WitherDeprecated withAnnotation(final int annotation) { return this.annotation == annotation ? this : new WitherDeprecated(annotation, this.javadoc); } @@ -17,6 +18,7 @@ class WitherDeprecated { */ @java.lang.Deprecated @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public WitherDeprecated withJavadoc(final int javadoc) { return this.javadoc == javadoc ? this : new WitherDeprecated(this.annotation, javadoc); } diff --git a/test/transform/resource/after-delombok/WitherOnClass.java b/test/transform/resource/after-delombok/WitherOnClass.java index 45d0c4b5..ae352d33 100644 --- a/test/transform/resource/after-delombok/WitherOnClass.java +++ b/test/transform/resource/after-delombok/WitherOnClass.java @@ -4,6 +4,7 @@ class WitherOnClass1 { WitherOnClass1(boolean isNone, boolean isPublic) { } @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public WitherOnClass1 withPublic(final boolean isPublic) { return this.isPublic == isPublic ? this : new WitherOnClass1(this.isNone, isPublic); } @@ -15,10 +16,12 @@ class WitherOnClass2 { WitherOnClass2(boolean isNone, boolean isProtected, boolean isPackage) { } @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") protected WitherOnClass2 withProtected(final boolean isProtected) { return this.isProtected == isProtected ? this : new WitherOnClass2(this.isNone, isProtected, this.isPackage); } @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") WitherOnClass2 withPackage(final boolean isPackage) { return this.isPackage == isPackage ? this : new WitherOnClass2(this.isNone, this.isProtected, isPackage); } @@ -30,10 +33,12 @@ class WitherOnClass3 { WitherOnClass3(String couldBeNull, String nonNull) { } @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public WitherOnClass3 withCouldBeNull(final String couldBeNull) { return this.couldBeNull == couldBeNull ? this : new WitherOnClass3(couldBeNull, this.nonNull); } @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public WitherOnClass3 withNonNull(@lombok.NonNull final String nonNull) { if (nonNull == null) { throw new java.lang.NullPointerException("nonNull"); @@ -48,6 +53,7 @@ class WitherOnClass4 { this.fY = y; } @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public WitherOnClass4 withY(final int fY) { return this.fY == fY ? this : new WitherOnClass4(fY); } diff --git a/test/transform/resource/after-delombok/WitherPlain.java b/test/transform/resource/after-delombok/WitherPlain.java index a2e947bd..548ff299 100644 --- a/test/transform/resource/after-delombok/WitherPlain.java +++ b/test/transform/resource/after-delombok/WitherPlain.java @@ -6,10 +6,12 @@ class WitherPlain { this.foo = foo; } @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public WitherPlain withI(final int i) { return this.i == i ? this : new WitherPlain(i, this.foo); } @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public WitherPlain withFoo(final int foo) { return this.foo == foo ? this : new WitherPlain(this.i, foo); } diff --git a/test/transform/resource/after-delombok/WitherWithGenerics.java b/test/transform/resource/after-delombok/WitherWithGenerics.java index 98bbd04d..fd466559 100644 --- a/test/transform/resource/after-delombok/WitherWithGenerics.java +++ b/test/transform/resource/after-delombok/WitherWithGenerics.java @@ -6,14 +6,17 @@ class WitherWithGenerics<T, J extends T, L extends java.lang.Number> { public WitherWithGenerics(J test, java.util.List<L> test2, java.util.List<? extends L> test3) { } @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public WitherWithGenerics<T, J, L> withTest(final J test) { return this.test == test ? this : new WitherWithGenerics<T, J, L>(test, this.test2, this.test3); } @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public WitherWithGenerics<T, J, L> withTest2(final java.util.List<L> test2) { return this.test2 == test2 ? this : new WitherWithGenerics<T, J, L>(this.test, test2, this.test3); } @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") public WitherWithGenerics<T, J, L> withTest3(final java.util.List<? extends L> test3) { return this.test3 == test3 ? this : new WitherWithGenerics<T, J, L>(this.test, this.test2, test3); } diff --git a/test/transform/resource/after-ecj/Accessors.java b/test/transform/resource/after-ecj/Accessors.java index 6b8976d0..1b50c97e 100644 --- a/test/transform/resource/after-ecj/Accessors.java +++ b/test/transform/resource/after-ecj/Accessors.java @@ -3,10 +3,10 @@ class AccessorsFluent { AccessorsFluent() { super(); } - public @java.lang.SuppressWarnings("all") String fieldName() { + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") String fieldName() { return this.fieldName; } - public @java.lang.SuppressWarnings("all") AccessorsFluent fieldName(final String fieldName) { + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") AccessorsFluent fieldName(final String fieldName) { this.fieldName = fieldName; return this; } @@ -17,14 +17,14 @@ class AccessorsFluent { AccessorsFluentOnClass() { super(); } - public @java.lang.SuppressWarnings("all") AccessorsFluentOnClass fieldName(final String fieldName) { + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") AccessorsFluentOnClass fieldName(final String fieldName) { this.fieldName = fieldName; return this; } - public @java.lang.SuppressWarnings("all") String fieldName() { + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") String fieldName() { return this.fieldName; } - public @java.lang.SuppressWarnings("all") String getOtherFieldWithOverride() { + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") String getOtherFieldWithOverride() { return this.otherFieldWithOverride; } } @@ -33,7 +33,7 @@ class AccessorsChain { AccessorsChain() { super(); } - public @java.lang.SuppressWarnings("all") AccessorsChain setRunning(final boolean isRunning) { + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") AccessorsChain setRunning(final boolean isRunning) { this.isRunning = isRunning; return this; } @@ -44,7 +44,7 @@ class AccessorsChain { AccessorsPrefix() { super(); } - public @java.lang.SuppressWarnings("all") void setActualField(final String fActualField) { + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") void setActualField(final String fActualField) { this.fActualField = fActualField; } } @@ -54,10 +54,10 @@ class AccessorsChain { AccessorsPrefix2() { super(); } - public @java.lang.SuppressWarnings("all") void setFieldName(final String fieldName) { + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") void setFieldName(final String fieldName) { this.fieldName = fieldName; } - public @java.lang.SuppressWarnings("all") void setActualField(final String fActualField) { + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") void setActualField(final String fActualField) { this.fActualField = fActualField; } } @@ -69,15 +69,15 @@ class AccessorsChain { private String getName() { return fName; } - public @java.lang.Override @java.lang.SuppressWarnings("all") java.lang.String toString() { + public @java.lang.Override @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") java.lang.String toString() { return (("AccessorsPrefix3(fName=" + this.getName()) + ")"); } - public @java.lang.Override @java.lang.SuppressWarnings("all") boolean equals(final java.lang.Object o) { + public @java.lang.Override @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") boolean equals(final java.lang.Object o) { if ((o == this)) return true; if ((! (o instanceof AccessorsPrefix3))) return false; - final @java.lang.SuppressWarnings("all") AccessorsPrefix3 other = (AccessorsPrefix3) o; + final AccessorsPrefix3 other = (AccessorsPrefix3) o; if ((! other.canEqual((java.lang.Object) this))) return false; final java.lang.Object this$fName = this.getName(); @@ -86,10 +86,10 @@ class AccessorsChain { return false; return true; } - protected @java.lang.SuppressWarnings("all") boolean canEqual(final java.lang.Object other) { + protected @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") boolean canEqual(final java.lang.Object other) { return (other instanceof AccessorsPrefix3); } - public @java.lang.Override @java.lang.SuppressWarnings("all") int hashCode() { + public @java.lang.Override @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") int hashCode() { final int PRIME = 59; int result = 1; final java.lang.Object $fName = this.getName(); @@ -102,7 +102,7 @@ class AccessorsFluentGenerics<T extends Number> { AccessorsFluentGenerics() { super(); } - public @java.lang.SuppressWarnings("all") AccessorsFluentGenerics<T> name(final String name) { + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") AccessorsFluentGenerics<T> name(final String name) { this.name = name; return this; } @@ -112,7 +112,7 @@ class AccessorsFluentNoChaining { AccessorsFluentNoChaining() { super(); } - public @java.lang.SuppressWarnings("all") void name(final String name) { + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") void name(final String name) { this.name = name; } } @@ -123,7 +123,7 @@ class AccessorsFluentStatic<T extends Number> { AccessorsFluentStatic() { super(); } - public static @java.lang.SuppressWarnings("all") void name(final String name) { + public static @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") void name(final String name) { AccessorsFluentStatic.name = name; } } diff --git a/test/transform/resource/after-ecj/AccessorsConfiguration.java b/test/transform/resource/after-ecj/AccessorsConfiguration.java index 6678e020..fdf2ff85 100644 --- a/test/transform/resource/after-ecj/AccessorsConfiguration.java +++ b/test/transform/resource/after-ecj/AccessorsConfiguration.java @@ -3,10 +3,10 @@ class AccessorsConfiguration { AccessorsConfiguration() { super(); } - public @java.lang.SuppressWarnings("all") String fieldName() { + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") String fieldName() { return this.m_FieldName; } - public @java.lang.SuppressWarnings("all") void fieldName(final String m_FieldName) { + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") void fieldName(final String m_FieldName) { this.m_FieldName = m_FieldName; } } @@ -15,7 +15,7 @@ class AccessorsConfiguration { AccessorsConfiguration2() { super(); } - public @java.lang.SuppressWarnings("all") void setM_FieldName(final String m_FieldName) { + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") void setM_FieldName(final String m_FieldName) { this.m_FieldName = m_FieldName; } } @@ -24,7 +24,7 @@ class AccessorsConfiguration { AccessorsConfiguration3() { super(); } - public @java.lang.SuppressWarnings("all") AccessorsConfiguration3 setFieldName(final String fFieldName) { + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") AccessorsConfiguration3 setFieldName(final String fFieldName) { this.fFieldName = fFieldName; return this; } diff --git a/test/transform/resource/after-ecj/BuilderChainAndFluent.java b/test/transform/resource/after-ecj/BuilderChainAndFluent.java index 6a307105..888c6239 100644 --- a/test/transform/resource/after-ecj/BuilderChainAndFluent.java +++ b/test/transform/resource/after-ecj/BuilderChainAndFluent.java @@ -1,25 +1,25 @@ @lombok.experimental.Builder(fluent = false,chain = false) class BuilderChainAndFluent { - public static @java.lang.SuppressWarnings("all") class BuilderChainAndFluentBuilder { + public static @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") class BuilderChainAndFluentBuilder { private int yes; - @java.lang.SuppressWarnings("all") BuilderChainAndFluentBuilder() { + @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") BuilderChainAndFluentBuilder() { super(); } - public @java.lang.SuppressWarnings("all") void setYes(final int yes) { + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") void setYes(final int yes) { this.yes = yes; } - public @java.lang.SuppressWarnings("all") BuilderChainAndFluent build() { + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") BuilderChainAndFluent build() { return new BuilderChainAndFluent(yes); } - public @java.lang.Override @java.lang.SuppressWarnings("all") java.lang.String toString() { + public @java.lang.Override @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") java.lang.String toString() { return (("BuilderChainAndFluent.BuilderChainAndFluentBuilder(yes=" + this.yes) + ")"); } } private final int yes; - @java.lang.SuppressWarnings("all") BuilderChainAndFluent(final int yes) { + @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") BuilderChainAndFluent(final int yes) { super(); this.yes = yes; } - public static @java.lang.SuppressWarnings("all") BuilderChainAndFluentBuilder builder() { + public static @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") BuilderChainAndFluentBuilder builder() { return new BuilderChainAndFluentBuilder(); } } diff --git a/test/transform/resource/after-ecj/BuilderComplex.java b/test/transform/resource/after-ecj/BuilderComplex.java index 19aeb043..d7546879 100644 --- a/test/transform/resource/after-ecj/BuilderComplex.java +++ b/test/transform/resource/after-ecj/BuilderComplex.java @@ -1,34 +1,34 @@ import java.util.List; import lombok.experimental.Builder; class BuilderComplex { - public static @java.lang.SuppressWarnings("all") class VoidBuilder<T extends Number> { + public static @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") class VoidBuilder<T extends Number> { private T number; private int arg2; private String arg3; private BuilderComplex selfRef; - @java.lang.SuppressWarnings("all") VoidBuilder() { + @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") VoidBuilder() { super(); } - public @java.lang.SuppressWarnings("all") VoidBuilder<T> number(final T number) { + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") VoidBuilder<T> number(final T number) { this.number = number; return this; } - public @java.lang.SuppressWarnings("all") VoidBuilder<T> arg2(final int arg2) { + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") VoidBuilder<T> arg2(final int arg2) { this.arg2 = arg2; return this; } - public @java.lang.SuppressWarnings("all") VoidBuilder<T> arg3(final String arg3) { + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") VoidBuilder<T> arg3(final String arg3) { this.arg3 = arg3; return this; } - public @java.lang.SuppressWarnings("all") VoidBuilder<T> selfRef(final BuilderComplex selfRef) { + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") VoidBuilder<T> selfRef(final BuilderComplex selfRef) { this.selfRef = selfRef; return this; } - public @java.lang.SuppressWarnings("all") void execute() { + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") void execute() { BuilderComplex.<T>testVoidWithGenerics(number, arg2, arg3, selfRef); } - public @java.lang.Override @java.lang.SuppressWarnings("all") java.lang.String toString() { + public @java.lang.Override @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") java.lang.String toString() { return (((((((("BuilderComplex.VoidBuilder(number=" + this.number) + ", arg2=") + this.arg2) + ", arg3=") + this.arg3) + ", selfRef=") + this.selfRef) + ")"); } } @@ -37,7 +37,7 @@ class BuilderComplex { } private static @Builder(buildMethodName = "execute") <T extends Number>void testVoidWithGenerics(T number, int arg2, String arg3, BuilderComplex selfRef) { } - public static @java.lang.SuppressWarnings("all") <T extends Number>VoidBuilder<T> builder() { + public static @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") <T extends Number>VoidBuilder<T> builder() { return new VoidBuilder<T>(); } } diff --git a/test/transform/resource/after-ecj/BuilderSimple.java b/test/transform/resource/after-ecj/BuilderSimple.java index 85db360d..41240a94 100644 --- a/test/transform/resource/after-ecj/BuilderSimple.java +++ b/test/transform/resource/after-ecj/BuilderSimple.java @@ -1,23 +1,23 @@ import java.util.List; @lombok.experimental.Builder class BuilderSimple<T> { - public static @java.lang.SuppressWarnings("all") class BuilderSimpleBuilder<T> { + public static @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") class BuilderSimpleBuilder<T> { private int yes; private List<T> also; - @java.lang.SuppressWarnings("all") BuilderSimpleBuilder() { + @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") BuilderSimpleBuilder() { super(); } - public @java.lang.SuppressWarnings("all") BuilderSimpleBuilder<T> yes(final int yes) { + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") BuilderSimpleBuilder<T> yes(final int yes) { this.yes = yes; return this; } - public @java.lang.SuppressWarnings("all") BuilderSimpleBuilder<T> also(final List<T> also) { + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") BuilderSimpleBuilder<T> also(final List<T> also) { this.also = also; return this; } - public @java.lang.SuppressWarnings("all") BuilderSimple<T> build() { + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") BuilderSimple<T> build() { return new BuilderSimple<T>(yes, also); } - public @java.lang.Override @java.lang.SuppressWarnings("all") java.lang.String toString() { + public @java.lang.Override @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") java.lang.String toString() { return (((("BuilderSimple.BuilderSimpleBuilder(yes=" + this.yes) + ", also=") + this.also) + ")"); } } @@ -25,12 +25,12 @@ import java.util.List; private final int yes; private List<T> also; private int $butNotMe; - @java.lang.SuppressWarnings("all") BuilderSimple(final int yes, final List<T> also) { + @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") BuilderSimple(final int yes, final List<T> also) { super(); this.yes = yes; this.also = also; } - public static @java.lang.SuppressWarnings("all") <T>BuilderSimpleBuilder<T> builder() { + public static @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") <T>BuilderSimpleBuilder<T> builder() { return new BuilderSimpleBuilder<T>(); } } diff --git a/test/transform/resource/after-ecj/BuilderSingularGuavaListsSets.java b/test/transform/resource/after-ecj/BuilderSingularGuavaListsSets.java new file mode 100644 index 00000000..0a04da34 --- /dev/null +++ b/test/transform/resource/after-ecj/BuilderSingularGuavaListsSets.java @@ -0,0 +1,88 @@ +import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableCollection; +import com.google.common.collect.ImmutableSet; +import com.google.common.collect.ImmutableSortedSet; +import lombok.Singular; +@lombok.Builder class BuilderSingularGuavaListsSets<T> { + public static @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") class BuilderSingularGuavaListsSetsBuilder<T> { + private com.google.common.collect.ImmutableList.Builder<T> cards; + private com.google.common.collect.ImmutableList.Builder<Number> frogs; + private com.google.common.collect.ImmutableSet.Builder<java.lang.Object> rawSet; + private com.google.common.collect.ImmutableSortedSet.Builder<String> passes; + @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") BuilderSingularGuavaListsSetsBuilder() { + super(); + } + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") BuilderSingularGuavaListsSetsBuilder<T> card(T card) { + if ((this.cards == null)) + this.cards = com.google.common.collect.ImmutableList.builder(); + this.cards.add(card); + return this; + } + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") BuilderSingularGuavaListsSetsBuilder<T> cards(java.lang.Iterable<? extends T> cards) { + if ((this.cards == null)) + this.cards = com.google.common.collect.ImmutableList.builder(); + this.cards.addAll(cards); + return this; + } + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") BuilderSingularGuavaListsSetsBuilder<T> frog(Number frog) { + if ((this.frogs == null)) + this.frogs = com.google.common.collect.ImmutableList.builder(); + this.frogs.add(frog); + return this; + } + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") BuilderSingularGuavaListsSetsBuilder<T> frogs(java.lang.Iterable<? extends Number> frogs) { + if ((this.frogs == null)) + this.frogs = com.google.common.collect.ImmutableList.builder(); + this.frogs.addAll(frogs); + return this; + } + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") BuilderSingularGuavaListsSetsBuilder<T> rawSet(java.lang.Object rawSet) { + if ((this.rawSet == null)) + this.rawSet = com.google.common.collect.ImmutableSet.builder(); + this.rawSet.add(rawSet); + return this; + } + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") BuilderSingularGuavaListsSetsBuilder<T> rawSet(java.lang.Iterable<?> rawSet) { + if ((this.rawSet == null)) + this.rawSet = com.google.common.collect.ImmutableSet.builder(); + this.rawSet.addAll(rawSet); + return this; + } + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") BuilderSingularGuavaListsSetsBuilder<T> pass(String pass) { + if ((this.passes == null)) + this.passes = com.google.common.collect.ImmutableSortedSet.naturalOrder(); + this.passes.add(pass); + return this; + } + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") BuilderSingularGuavaListsSetsBuilder<T> passes(java.lang.Iterable<? extends String> passes) { + if ((this.passes == null)) + this.passes = com.google.common.collect.ImmutableSortedSet.naturalOrder(); + this.passes.addAll(passes); + return this; + } + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") BuilderSingularGuavaListsSets<T> build() { + com.google.common.collect.ImmutableList<T> cards = ((this.cards == null) ? com.google.common.collect.ImmutableList.<T>of() : this.cards.build()); + com.google.common.collect.ImmutableCollection<Number> frogs = ((this.frogs == null) ? com.google.common.collect.ImmutableList.<Number>of() : this.frogs.build()); + com.google.common.collect.ImmutableSet<java.lang.Object> rawSet = ((this.rawSet == null) ? com.google.common.collect.ImmutableSet.<java.lang.Object>of() : this.rawSet.build()); + com.google.common.collect.ImmutableSortedSet<String> passes = ((this.passes == null) ? com.google.common.collect.ImmutableSortedSet.<String>of() : this.passes.build()); + return new BuilderSingularGuavaListsSets<T>(cards, frogs, rawSet, passes); + } + public @java.lang.Override @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") java.lang.String toString() { + return (((((((("BuilderSingularGuavaListsSets.BuilderSingularGuavaListsSetsBuilder(cards=" + this.cards) + ", frogs=") + this.frogs) + ", rawSet=") + this.rawSet) + ", passes=") + this.passes) + ")"); + } + } + private @Singular ImmutableList<T> cards; + private @Singular ImmutableCollection<? extends Number> frogs; + private @SuppressWarnings("all") @Singular("rawSet") ImmutableSet rawSet; + private @Singular ImmutableSortedSet<String> passes; + @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") BuilderSingularGuavaListsSets(final ImmutableList<T> cards, final ImmutableCollection<? extends Number> frogs, final ImmutableSet rawSet, final ImmutableSortedSet<String> passes) { + super(); + this.cards = cards; + this.frogs = frogs; + this.rawSet = rawSet; + this.passes = passes; + } + public static @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") <T>BuilderSingularGuavaListsSetsBuilder<T> builder() { + return new BuilderSingularGuavaListsSetsBuilder<T>(); + } +} diff --git a/test/transform/resource/after-ecj/BuilderSingularGuavaMaps.java b/test/transform/resource/after-ecj/BuilderSingularGuavaMaps.java new file mode 100644 index 00000000..3696c794 --- /dev/null +++ b/test/transform/resource/after-ecj/BuilderSingularGuavaMaps.java @@ -0,0 +1,71 @@ +import com.google.common.collect.ImmutableMap; +import com.google.common.collect.ImmutableBiMap; +import com.google.common.collect.ImmutableSortedMap; +import lombok.Singular; +@lombok.Builder class BuilderSingularGuavaMaps<K, V> { + public static @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") class BuilderSingularGuavaMapsBuilder<K, V> { + private com.google.common.collect.ImmutableMap.Builder<K, V> battleaxes; + private com.google.common.collect.ImmutableSortedMap.Builder<Integer, V> vertices; + private com.google.common.collect.ImmutableBiMap.Builder<java.lang.Object, java.lang.Object> rawMap; + @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") BuilderSingularGuavaMapsBuilder() { + super(); + } + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") BuilderSingularGuavaMapsBuilder<K, V> battleaxe(K battleaxe$key, V battleaxe$value) { + if ((this.battleaxes == null)) + this.battleaxes = com.google.common.collect.ImmutableMap.builder(); + this.battleaxes.put(battleaxe$key, battleaxe$value); + return this; + } + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") BuilderSingularGuavaMapsBuilder<K, V> battleaxes(java.util.Map<? extends K, ? extends V> battleaxes) { + if ((this.battleaxes == null)) + this.battleaxes = com.google.common.collect.ImmutableMap.builder(); + this.battleaxes.putAll(battleaxes); + return this; + } + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") BuilderSingularGuavaMapsBuilder<K, V> vertex(Integer vertex$key, V vertex$value) { + if ((this.vertices == null)) + this.vertices = com.google.common.collect.ImmutableSortedMap.naturalOrder(); + this.vertices.put(vertex$key, vertex$value); + return this; + } + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") BuilderSingularGuavaMapsBuilder<K, V> vertices(java.util.Map<? extends Integer, ? extends V> vertices) { + if ((this.vertices == null)) + this.vertices = com.google.common.collect.ImmutableSortedMap.naturalOrder(); + this.vertices.putAll(vertices); + return this; + } + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") BuilderSingularGuavaMapsBuilder<K, V> rawMap(java.lang.Object rawMap$key, java.lang.Object rawMap$value) { + if ((this.rawMap == null)) + this.rawMap = com.google.common.collect.ImmutableBiMap.builder(); + this.rawMap.put(rawMap$key, rawMap$value); + return this; + } + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") BuilderSingularGuavaMapsBuilder<K, V> rawMap(java.util.Map<?, ?> rawMap) { + if ((this.rawMap == null)) + this.rawMap = com.google.common.collect.ImmutableBiMap.builder(); + this.rawMap.putAll(rawMap); + return this; + } + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") BuilderSingularGuavaMaps<K, V> build() { + com.google.common.collect.ImmutableMap<K, V> battleaxes = ((this.battleaxes == null) ? com.google.common.collect.ImmutableMap.<K, V>of() : this.battleaxes.build()); + com.google.common.collect.ImmutableSortedMap<Integer, V> vertices = ((this.vertices == null) ? com.google.common.collect.ImmutableSortedMap.<Integer, V>of() : this.vertices.build()); + com.google.common.collect.ImmutableBiMap<java.lang.Object, java.lang.Object> rawMap = ((this.rawMap == null) ? com.google.common.collect.ImmutableBiMap.<java.lang.Object, java.lang.Object>of() : this.rawMap.build()); + return new BuilderSingularGuavaMaps<K, V>(battleaxes, vertices, rawMap); + } + public @java.lang.Override @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") java.lang.String toString() { + return (((((("BuilderSingularGuavaMaps.BuilderSingularGuavaMapsBuilder(battleaxes=" + this.battleaxes) + ", vertices=") + this.vertices) + ", rawMap=") + this.rawMap) + ")"); + } + } + private @Singular ImmutableMap<K, V> battleaxes; + private @Singular ImmutableSortedMap<Integer, ? extends V> vertices; + private @SuppressWarnings("all") @Singular("rawMap") ImmutableBiMap rawMap; + @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") BuilderSingularGuavaMaps(final ImmutableMap<K, V> battleaxes, final ImmutableSortedMap<Integer, ? extends V> vertices, final ImmutableBiMap rawMap) { + super(); + this.battleaxes = battleaxes; + this.vertices = vertices; + this.rawMap = rawMap; + } + public static @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") <K, V>BuilderSingularGuavaMapsBuilder<K, V> builder() { + return new BuilderSingularGuavaMapsBuilder<K, V>(); + } +} diff --git a/test/transform/resource/after-ecj/BuilderSingularLists.java b/test/transform/resource/after-ecj/BuilderSingularLists.java new file mode 100644 index 00000000..bbba29f4 --- /dev/null +++ b/test/transform/resource/after-ecj/BuilderSingularLists.java @@ -0,0 +1,101 @@ +import java.util.List; +import java.util.Collection; + +import lombok.Singular; +@lombok.Builder class BuilderSingularLists<T> { + public static @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") class BuilderSingularListsBuilder<T> { + private java.util.ArrayList<T> children; + private java.util.ArrayList<Number> scarves; + private java.util.ArrayList<java.lang.Object> rawList; + @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") BuilderSingularListsBuilder() { + super(); + } + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") BuilderSingularListsBuilder<T> child(T child) { + if ((this.children == null)) + this.children = new java.util.ArrayList<T>(); + this.children.add(child); + return this; + } + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") BuilderSingularListsBuilder<T> children(java.util.Collection<? extends T> children) { + if ((this.children == null)) + this.children = new java.util.ArrayList<T>(); + this.children.addAll(children); + return this; + } + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") BuilderSingularListsBuilder<T> scarf(Number scarf) { + if ((this.scarves == null)) + this.scarves = new java.util.ArrayList<Number>(); + this.scarves.add(scarf); + return this; + } + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") BuilderSingularListsBuilder<T> scarves(java.util.Collection<? extends Number> scarves) { + if ((this.scarves == null)) + this.scarves = new java.util.ArrayList<Number>(); + this.scarves.addAll(scarves); + return this; + } + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") BuilderSingularListsBuilder<T> rawList(java.lang.Object rawList) { + if ((this.rawList == null)) + this.rawList = new java.util.ArrayList<java.lang.Object>(); + this.rawList.add(rawList); + return this; + } + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") BuilderSingularListsBuilder<T> rawList(java.util.Collection<?> rawList) { + if ((this.rawList == null)) + this.rawList = new java.util.ArrayList<java.lang.Object>(); + this.rawList.addAll(rawList); + return this; + } + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") BuilderSingularLists<T> build() { + java.util.List<T> children; + switch (((this.children == null) ? 0 : this.children.size())) { + case 0 : + children = java.util.Collections.emptyList(); + break; + case 1 : + children = java.util.Collections.singletonList(this.children.get(0)); + break; + default : + children = java.util.Collections.unmodifiableList(new java.util.ArrayList<T>(this.children)); + } + java.util.Collection<Number> scarves; + switch (((this.scarves == null) ? 0 : this.scarves.size())) { + case 0 : + scarves = java.util.Collections.emptyList(); + break; + case 1 : + scarves = java.util.Collections.singletonList(this.scarves.get(0)); + break; + default : + scarves = java.util.Collections.unmodifiableList(new java.util.ArrayList<Number>(this.scarves)); + } + java.util.List<java.lang.Object> rawList; + switch (((this.rawList == null) ? 0 : this.rawList.size())) { + case 0 : + rawList = java.util.Collections.emptyList(); + break; + case 1 : + rawList = java.util.Collections.singletonList(this.rawList.get(0)); + break; + default : + rawList = java.util.Collections.unmodifiableList(new java.util.ArrayList<java.lang.Object>(this.rawList)); + } + return new BuilderSingularLists<T>(children, scarves, rawList); + } + public @java.lang.Override @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") java.lang.String toString() { + return (((((("BuilderSingularLists.BuilderSingularListsBuilder(children=" + this.children) + ", scarves=") + this.scarves) + ", rawList=") + this.rawList) + ")"); + } + } + private @Singular List<T> children; + private @Singular Collection<? extends Number> scarves; + private @SuppressWarnings("all") @Singular("rawList") List rawList; + @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") BuilderSingularLists(final List<T> children, final Collection<? extends Number> scarves, final List rawList) { + super(); + this.children = children; + this.scarves = scarves; + this.rawList = rawList; + } + public static @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") <T>BuilderSingularListsBuilder<T> builder() { + return new BuilderSingularListsBuilder<T>(); + } +}
\ No newline at end of file diff --git a/test/transform/resource/after-ecj/BuilderSingularMaps.java b/test/transform/resource/after-ecj/BuilderSingularMaps.java new file mode 100644 index 00000000..c439cd2a --- /dev/null +++ b/test/transform/resource/after-ecj/BuilderSingularMaps.java @@ -0,0 +1,177 @@ +import java.util.Map; +import java.util.SortedMap; +import lombok.Singular; +@lombok.Builder class BuilderSingularMaps<K, V> { + public static @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") class BuilderSingularMapsBuilder<K, V> { + private java.util.ArrayList<K> women$key; + private java.util.ArrayList<V> women$value; + private java.util.ArrayList<K> men$key; + private java.util.ArrayList<Number> men$value; + private java.util.ArrayList<java.lang.Object> rawMap$key; + private java.util.ArrayList<java.lang.Object> rawMap$value; + private java.util.ArrayList<String> stringMap$key; + private java.util.ArrayList<V> stringMap$value; + @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") BuilderSingularMapsBuilder() { + super(); + } + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") BuilderSingularMapsBuilder<K, V> woman(K womanKey, V womanValue) { + if ((this.women$key == null)) + { + this.women$key = new java.util.ArrayList<K>(); + this.women$value = new java.util.ArrayList<V>(); + } + this.women$key.add(womanKey); + this.women$value.add(womanValue); + return this; + } + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") BuilderSingularMapsBuilder<K, V> women(java.util.Map<? extends K, ? extends V> women) { + if ((this.women$key == null)) + { + this.women$key = new java.util.ArrayList<K>(); + this.women$value = new java.util.ArrayList<V>(); + } + for (java.util.Map.Entry<? extends K, ? extends V> $lombokEntry : women.entrySet()) + { + this.women$key.add($lombokEntry.getKey()); + this.women$value.add($lombokEntry.getValue()); + } + return this; + } + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") BuilderSingularMapsBuilder<K, V> man(K manKey, Number manValue) { + if ((this.men$key == null)) + { + this.men$key = new java.util.ArrayList<K>(); + this.men$value = new java.util.ArrayList<Number>(); + } + this.men$key.add(manKey); + this.men$value.add(manValue); + return this; + } + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") BuilderSingularMapsBuilder<K, V> men(java.util.Map<? extends K, ? extends Number> men) { + if ((this.men$key == null)) + { + this.men$key = new java.util.ArrayList<K>(); + this.men$value = new java.util.ArrayList<Number>(); + } + for (java.util.Map.Entry<? extends K, ? extends Number> $lombokEntry : men.entrySet()) + { + this.men$key.add($lombokEntry.getKey()); + this.men$value.add($lombokEntry.getValue()); + } + return this; + } + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") BuilderSingularMapsBuilder<K, V> rawMap(java.lang.Object rawMapKey, java.lang.Object rawMapValue) { + if ((this.rawMap$key == null)) + { + this.rawMap$key = new java.util.ArrayList<java.lang.Object>(); + this.rawMap$value = new java.util.ArrayList<java.lang.Object>(); + } + this.rawMap$key.add(rawMapKey); + this.rawMap$value.add(rawMapValue); + return this; + } + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") BuilderSingularMapsBuilder<K, V> rawMap(java.util.Map<?, ?> rawMap) { + if ((this.rawMap$key == null)) + { + this.rawMap$key = new java.util.ArrayList<java.lang.Object>(); + this.rawMap$value = new java.util.ArrayList<java.lang.Object>(); + } + for (java.util.Map.Entry<?, ?> $lombokEntry : rawMap.entrySet()) + { + this.rawMap$key.add($lombokEntry.getKey()); + this.rawMap$value.add($lombokEntry.getValue()); + } + return this; + } + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") BuilderSingularMapsBuilder<K, V> stringMap(String stringMapKey, V stringMapValue) { + if ((this.stringMap$key == null)) + { + this.stringMap$key = new java.util.ArrayList<String>(); + this.stringMap$value = new java.util.ArrayList<V>(); + } + this.stringMap$key.add(stringMapKey); + this.stringMap$value.add(stringMapValue); + return this; + } + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") BuilderSingularMapsBuilder<K, V> stringMap(java.util.Map<? extends String, ? extends V> stringMap) { + if ((this.stringMap$key == null)) + { + this.stringMap$key = new java.util.ArrayList<String>(); + this.stringMap$value = new java.util.ArrayList<V>(); + } + for (java.util.Map.Entry<? extends String, ? extends V> $lombokEntry : stringMap.entrySet()) + { + this.stringMap$key.add($lombokEntry.getKey()); + this.stringMap$value.add($lombokEntry.getValue()); + } + return this; + } + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") BuilderSingularMaps<K, V> build() { + java.util.Map<K, V> women; + switch (((this.women$key == null) ? 0 : this.women$key.size())) { + case 0 : + women = java.util.Collections.emptyMap(); + break; + case 1 : + women = java.util.Collections.singletonMap(this.women$key.get(0), this.women$value.get(0)); + break; + default : + women = new java.util.LinkedHashMap<K, V>(((this.women$key.size() < 0x40000000) ? ((1 + this.women$key.size()) + ((this.women$key.size() - 3) / 3)) : java.lang.Integer.MAX_VALUE)); + for (int $i = 0;; ($i < this.women$key.size()); $i ++) + women.put(this.women$key.get($i), this.women$value.get($i)); + women = java.util.Collections.unmodifiableMap(women); + } + java.util.SortedMap<K, Number> men = new java.util.TreeMap<K, Number>(); + if ((this.men$key != null)) + for (int $i = 0;; ($i < ((this.men$key == null) ? 0 : this.men$key.size())); $i ++) + men.put(this.men$key.get($i), this.men$value.get($i)); + men = java.util.Collections.unmodifiableSortedMap(men); + java.util.Map<java.lang.Object, java.lang.Object> rawMap; + switch (((this.rawMap$key == null) ? 0 : this.rawMap$key.size())) { + case 0 : + rawMap = java.util.Collections.emptyMap(); + break; + case 1 : + rawMap = java.util.Collections.singletonMap(this.rawMap$key.get(0), this.rawMap$value.get(0)); + break; + default : + rawMap = new java.util.LinkedHashMap<java.lang.Object, java.lang.Object>(((this.rawMap$key.size() < 0x40000000) ? ((1 + this.rawMap$key.size()) + ((this.rawMap$key.size() - 3) / 3)) : java.lang.Integer.MAX_VALUE)); + for (int $i = 0;; ($i < this.rawMap$key.size()); $i ++) + rawMap.put(this.rawMap$key.get($i), this.rawMap$value.get($i)); + rawMap = java.util.Collections.unmodifiableMap(rawMap); + } + java.util.Map<String, V> stringMap; + switch (((this.stringMap$key == null) ? 0 : this.stringMap$key.size())) { + case 0 : + stringMap = java.util.Collections.emptyMap(); + break; + case 1 : + stringMap = java.util.Collections.singletonMap(this.stringMap$key.get(0), this.stringMap$value.get(0)); + break; + default : + stringMap = new java.util.LinkedHashMap<String, V>(((this.stringMap$key.size() < 0x40000000) ? ((1 + this.stringMap$key.size()) + ((this.stringMap$key.size() - 3) / 3)) : java.lang.Integer.MAX_VALUE)); + for (int $i = 0;; ($i < this.stringMap$key.size()); $i ++) + stringMap.put(this.stringMap$key.get($i), this.stringMap$value.get($i)); + stringMap = java.util.Collections.unmodifiableMap(stringMap); + } + return new BuilderSingularMaps<K, V>(women, men, rawMap, stringMap); + } + public @java.lang.Override @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") java.lang.String toString() { + return (((((((((((((((("BuilderSingularMaps.BuilderSingularMapsBuilder(women$key=" + this.women$key) + ", women$value=") + this.women$value) + ", men$key=") + this.men$key) + ", men$value=") + this.men$value) + ", rawMap$key=") + this.rawMap$key) + ", rawMap$value=") + this.rawMap$value) + ", stringMap$key=") + this.stringMap$key) + ", stringMap$value=") + this.stringMap$value) + ")"); + } + } + private @Singular Map<K, V> women; + private @Singular SortedMap<K, ? extends Number> men; + private @SuppressWarnings("all") @Singular("rawMap") Map rawMap; + private @Singular("stringMap") Map<String, V> stringMap; + @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") BuilderSingularMaps(final Map<K, V> women, final SortedMap<K, ? extends Number> men, final Map rawMap, final Map<String, V> stringMap) { + super(); + this.women = women; + this.men = men; + this.rawMap = rawMap; + this.stringMap = stringMap; + } + public static @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") <K, V>BuilderSingularMapsBuilder<K, V> builder() { + return new BuilderSingularMapsBuilder<K, V>(); + } +}
\ No newline at end of file diff --git a/test/transform/resource/after-ecj/BuilderSingularNoAutosingularize.java b/test/transform/resource/after-ecj/BuilderSingularNoAutosingularize.java new file mode 100644 index 00000000..47d91593 --- /dev/null +++ b/test/transform/resource/after-ecj/BuilderSingularNoAutosingularize.java @@ -0,0 +1,99 @@ +import java.util.List; +import lombok.Singular; +@lombok.Builder class BuilderSingularNoAutosingularize { + public static @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") class BuilderSingularNoAutosingularizeBuilder { + private java.util.ArrayList<String> things; + private java.util.ArrayList<String> widgets; + private java.util.ArrayList<String> items; + @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") BuilderSingularNoAutosingularizeBuilder() { + super(); + } + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") BuilderSingularNoAutosingularizeBuilder things(String things) { + if ((this.things == null)) + this.things = new java.util.ArrayList<String>(); + this.things.add(things); + return this; + } + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") BuilderSingularNoAutosingularizeBuilder things(java.util.Collection<? extends String> things) { + if ((this.things == null)) + this.things = new java.util.ArrayList<String>(); + this.things.addAll(things); + return this; + } + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") BuilderSingularNoAutosingularizeBuilder widget(String widget) { + if ((this.widgets == null)) + this.widgets = new java.util.ArrayList<String>(); + this.widgets.add(widget); + return this; + } + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") BuilderSingularNoAutosingularizeBuilder widgets(java.util.Collection<? extends String> widgets) { + if ((this.widgets == null)) + this.widgets = new java.util.ArrayList<String>(); + this.widgets.addAll(widgets); + return this; + } + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") BuilderSingularNoAutosingularizeBuilder items(String items) { + if ((this.items == null)) + this.items = new java.util.ArrayList<String>(); + this.items.add(items); + return this; + } + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") BuilderSingularNoAutosingularizeBuilder items(java.util.Collection<? extends String> items) { + if ((this.items == null)) + this.items = new java.util.ArrayList<String>(); + this.items.addAll(items); + return this; + } + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") BuilderSingularNoAutosingularize build() { + java.util.List<String> things; + switch (((this.things == null) ? 0 : this.things.size())) { + case 0 : + things = java.util.Collections.emptyList(); + break; + case 1 : + things = java.util.Collections.singletonList(this.things.get(0)); + break; + default : + things = java.util.Collections.unmodifiableList(new java.util.ArrayList<String>(this.things)); + } + java.util.List<String> widgets; + switch (((this.widgets == null) ? 0 : this.widgets.size())) { + case 0 : + widgets = java.util.Collections.emptyList(); + break; + case 1 : + widgets = java.util.Collections.singletonList(this.widgets.get(0)); + break; + default : + widgets = java.util.Collections.unmodifiableList(new java.util.ArrayList<String>(this.widgets)); + } + java.util.List<String> items; + switch (((this.items == null) ? 0 : this.items.size())) { + case 0 : + items = java.util.Collections.emptyList(); + break; + case 1 : + items = java.util.Collections.singletonList(this.items.get(0)); + break; + default : + items = java.util.Collections.unmodifiableList(new java.util.ArrayList<String>(this.items)); + } + return new BuilderSingularNoAutosingularize(things, widgets, items); + } + public @java.lang.Override @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") java.lang.String toString() { + return (((((("BuilderSingularNoAutosingularize.BuilderSingularNoAutosingularizeBuilder(things=" + this.things) + ", widgets=") + this.widgets) + ", items=") + this.items) + ")"); + } + } + private @Singular List<String> things; + private @Singular("widget") List<String> widgets; + private @Singular List<String> items; + @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") BuilderSingularNoAutosingularize(final List<String> things, final List<String> widgets, final List<String> items) { + super(); + this.things = things; + this.widgets = widgets; + this.items = items; + } + public static @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") BuilderSingularNoAutosingularizeBuilder builder() { + return new BuilderSingularNoAutosingularizeBuilder(); + } +} diff --git a/test/transform/resource/after-ecj/BuilderSingularRedirectToGuava.java b/test/transform/resource/after-ecj/BuilderSingularRedirectToGuava.java new file mode 100644 index 00000000..01ccecb4 --- /dev/null +++ b/test/transform/resource/after-ecj/BuilderSingularRedirectToGuava.java @@ -0,0 +1,71 @@ +import java.util.Set; +import java.util.NavigableMap; +import java.util.Collection; +import lombok.Singular; +@lombok.Builder class BuilderSingularRedirectToGuava { + public static @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") class BuilderSingularRedirectToGuavaBuilder { + private com.google.common.collect.ImmutableSet.Builder<String> dangerMice; + private com.google.common.collect.ImmutableSortedMap.Builder<Integer, Number> things; + private com.google.common.collect.ImmutableList.Builder<Class<?>> doohickeys; + @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") BuilderSingularRedirectToGuavaBuilder() { + super(); + } + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") BuilderSingularRedirectToGuavaBuilder dangerMouse(String dangerMouse) { + if ((this.dangerMice == null)) + this.dangerMice = com.google.common.collect.ImmutableSet.builder(); + this.dangerMice.add(dangerMouse); + return this; + } + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") BuilderSingularRedirectToGuavaBuilder dangerMice(java.lang.Iterable<? extends String> dangerMice) { + if ((this.dangerMice == null)) + this.dangerMice = com.google.common.collect.ImmutableSet.builder(); + this.dangerMice.addAll(dangerMice); + return this; + } + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") BuilderSingularRedirectToGuavaBuilder thing(Integer thing$key, Number thing$value) { + if ((this.things == null)) + this.things = com.google.common.collect.ImmutableSortedMap.naturalOrder(); + this.things.put(thing$key, thing$value); + return this; + } + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") BuilderSingularRedirectToGuavaBuilder things(java.util.Map<? extends Integer, ? extends Number> things) { + if ((this.things == null)) + this.things = com.google.common.collect.ImmutableSortedMap.naturalOrder(); + this.things.putAll(things); + return this; + } + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") BuilderSingularRedirectToGuavaBuilder doohickey(Class<?> doohickey) { + if ((this.doohickeys == null)) + this.doohickeys = com.google.common.collect.ImmutableList.builder(); + this.doohickeys.add(doohickey); + return this; + } + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") BuilderSingularRedirectToGuavaBuilder doohickeys(java.lang.Iterable<? extends Class<?>> doohickeys) { + if ((this.doohickeys == null)) + this.doohickeys = com.google.common.collect.ImmutableList.builder(); + this.doohickeys.addAll(doohickeys); + return this; + } + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") BuilderSingularRedirectToGuava build() { + java.util.Set<String> dangerMice = ((this.dangerMice == null) ? com.google.common.collect.ImmutableSet.<String>of() : this.dangerMice.build()); + java.util.NavigableMap<Integer, Number> things = ((this.things == null) ? com.google.common.collect.ImmutableSortedMap.<Integer, Number>of() : this.things.build()); + java.util.Collection<Class<?>> doohickeys = ((this.doohickeys == null) ? com.google.common.collect.ImmutableList.<Class<?>>of() : this.doohickeys.build()); + return new BuilderSingularRedirectToGuava(dangerMice, things, doohickeys); + } + public @java.lang.Override @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") java.lang.String toString() { + return (((((("BuilderSingularRedirectToGuava.BuilderSingularRedirectToGuavaBuilder(dangerMice=" + this.dangerMice) + ", things=") + this.things) + ", doohickeys=") + this.doohickeys) + ")"); + } + } + private @Singular Set<String> dangerMice; + private @Singular NavigableMap<Integer, Number> things; + private @Singular Collection<Class<?>> doohickeys; + @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") BuilderSingularRedirectToGuava(final Set<String> dangerMice, final NavigableMap<Integer, Number> things, final Collection<Class<?>> doohickeys) { + super(); + this.dangerMice = dangerMice; + this.things = things; + this.doohickeys = doohickeys; + } + public static @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") BuilderSingularRedirectToGuavaBuilder builder() { + return new BuilderSingularRedirectToGuavaBuilder(); + } +}
\ No newline at end of file diff --git a/test/transform/resource/after-ecj/BuilderSingularSets.java b/test/transform/resource/after-ecj/BuilderSingularSets.java new file mode 100644 index 00000000..749d8439 --- /dev/null +++ b/test/transform/resource/after-ecj/BuilderSingularSets.java @@ -0,0 +1,125 @@ +import java.util.Set; +import java.util.SortedSet; +import lombok.Singular; +@lombok.Builder class BuilderSingularSets<T> { + public static @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") class BuilderSingularSetsBuilder<T> { + private java.util.ArrayList<T> dangerMice; + private java.util.ArrayList<Number> octopodes; + private java.util.ArrayList<java.lang.Object> rawSet; + private java.util.ArrayList<String> stringSet; + @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") BuilderSingularSetsBuilder() { + super(); + } + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") BuilderSingularSetsBuilder<T> dangerMouse(T dangerMouse) { + if ((this.dangerMice == null)) + this.dangerMice = new java.util.ArrayList<T>(); + this.dangerMice.add(dangerMouse); + return this; + } + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") BuilderSingularSetsBuilder<T> dangerMice(java.util.Collection<? extends T> dangerMice) { + if ((this.dangerMice == null)) + this.dangerMice = new java.util.ArrayList<T>(); + this.dangerMice.addAll(dangerMice); + return this; + } + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") BuilderSingularSetsBuilder<T> octopus(Number octopus) { + if ((this.octopodes == null)) + this.octopodes = new java.util.ArrayList<Number>(); + this.octopodes.add(octopus); + return this; + } + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") BuilderSingularSetsBuilder<T> octopodes(java.util.Collection<? extends Number> octopodes) { + if ((this.octopodes == null)) + this.octopodes = new java.util.ArrayList<Number>(); + this.octopodes.addAll(octopodes); + return this; + } + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") BuilderSingularSetsBuilder<T> rawSet(java.lang.Object rawSet) { + if ((this.rawSet == null)) + this.rawSet = new java.util.ArrayList<java.lang.Object>(); + this.rawSet.add(rawSet); + return this; + } + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") BuilderSingularSetsBuilder<T> rawSet(java.util.Collection<?> rawSet) { + if ((this.rawSet == null)) + this.rawSet = new java.util.ArrayList<java.lang.Object>(); + this.rawSet.addAll(rawSet); + return this; + } + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") BuilderSingularSetsBuilder<T> stringSet(String stringSet) { + if ((this.stringSet == null)) + this.stringSet = new java.util.ArrayList<String>(); + this.stringSet.add(stringSet); + return this; + } + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") BuilderSingularSetsBuilder<T> stringSet(java.util.Collection<? extends String> stringSet) { + if ((this.stringSet == null)) + this.stringSet = new java.util.ArrayList<String>(); + this.stringSet.addAll(stringSet); + return this; + } + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") BuilderSingularSets<T> build() { + java.util.Set<T> dangerMice; + switch (((this.dangerMice == null) ? 0 : this.dangerMice.size())) { + case 0 : + dangerMice = java.util.Collections.emptySet(); + break; + case 1 : + dangerMice = java.util.Collections.singleton(this.dangerMice.get(0)); + break; + default : + dangerMice = new java.util.LinkedHashSet<T>(((this.dangerMice.size() < 0x40000000) ? ((1 + this.dangerMice.size()) + ((this.dangerMice.size() - 3) / 3)) : java.lang.Integer.MAX_VALUE)); + dangerMice.addAll(this.dangerMice); + dangerMice = java.util.Collections.unmodifiableSet(dangerMice); + } + java.util.SortedSet<Number> octopodes = new java.util.TreeSet<Number>(); + if ((this.octopodes != null)) + octopodes.addAll(this.octopodes); + octopodes = java.util.Collections.unmodifiableSortedSet(octopodes); + java.util.Set<java.lang.Object> rawSet; + switch (((this.rawSet == null) ? 0 : this.rawSet.size())) { + case 0 : + rawSet = java.util.Collections.emptySet(); + break; + case 1 : + rawSet = java.util.Collections.singleton(this.rawSet.get(0)); + break; + default : + rawSet = new java.util.LinkedHashSet<java.lang.Object>(((this.rawSet.size() < 0x40000000) ? ((1 + this.rawSet.size()) + ((this.rawSet.size() - 3) / 3)) : java.lang.Integer.MAX_VALUE)); + rawSet.addAll(this.rawSet); + rawSet = java.util.Collections.unmodifiableSet(rawSet); + } + java.util.Set<String> stringSet; + switch (((this.stringSet == null) ? 0 : this.stringSet.size())) { + case 0 : + stringSet = java.util.Collections.emptySet(); + break; + case 1 : + stringSet = java.util.Collections.singleton(this.stringSet.get(0)); + break; + default : + stringSet = new java.util.LinkedHashSet<String>(((this.stringSet.size() < 0x40000000) ? ((1 + this.stringSet.size()) + ((this.stringSet.size() - 3) / 3)) : java.lang.Integer.MAX_VALUE)); + stringSet.addAll(this.stringSet); + stringSet = java.util.Collections.unmodifiableSet(stringSet); + } + return new BuilderSingularSets<T>(dangerMice, octopodes, rawSet, stringSet); + } + public @java.lang.Override @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") java.lang.String toString() { + return (((((((("BuilderSingularSets.BuilderSingularSetsBuilder(dangerMice=" + this.dangerMice) + ", octopodes=") + this.octopodes) + ", rawSet=") + this.rawSet) + ", stringSet=") + this.stringSet) + ")"); + } + } + private @Singular Set<T> dangerMice; + private @Singular SortedSet<? extends Number> octopodes; + private @SuppressWarnings("all") @Singular("rawSet") Set rawSet; + private @Singular("stringSet") Set<String> stringSet; + @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") BuilderSingularSets(final Set<T> dangerMice, final SortedSet<? extends Number> octopodes, final Set rawSet, final Set<String> stringSet) { + super(); + this.dangerMice = dangerMice; + this.octopodes = octopodes; + this.rawSet = rawSet; + this.stringSet = stringSet; + } + public static @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") <T>BuilderSingularSetsBuilder<T> builder() { + return new BuilderSingularSetsBuilder<T>(); + } +}
\ No newline at end of file diff --git a/test/transform/resource/after-ecj/BuilderWithAccessors.java b/test/transform/resource/after-ecj/BuilderWithAccessors.java index 79776dc4..b90ba937 100644 --- a/test/transform/resource/after-ecj/BuilderWithAccessors.java +++ b/test/transform/resource/after-ecj/BuilderWithAccessors.java @@ -1,32 +1,32 @@ @lombok.experimental.Builder @lombok.experimental.Accessors(prefix = {"p", "_"}) class BuilderWithAccessors { - public static @java.lang.SuppressWarnings("all") class BuilderWithAccessorsBuilder { + public static @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") class BuilderWithAccessorsBuilder { private int plower; private int upper; private int foo; private int _bar; - @java.lang.SuppressWarnings("all") BuilderWithAccessorsBuilder() { + @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") BuilderWithAccessorsBuilder() { super(); } - public @java.lang.SuppressWarnings("all") BuilderWithAccessorsBuilder plower(final int plower) { + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") BuilderWithAccessorsBuilder plower(final int plower) { this.plower = plower; return this; } - public @java.lang.SuppressWarnings("all") BuilderWithAccessorsBuilder upper(final int upper) { + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") BuilderWithAccessorsBuilder upper(final int upper) { this.upper = upper; return this; } - public @java.lang.SuppressWarnings("all") BuilderWithAccessorsBuilder foo(final int foo) { + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") BuilderWithAccessorsBuilder foo(final int foo) { this.foo = foo; return this; } - public @java.lang.SuppressWarnings("all") BuilderWithAccessorsBuilder _bar(final int _bar) { + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") BuilderWithAccessorsBuilder _bar(final int _bar) { this._bar = _bar; return this; } - public @java.lang.SuppressWarnings("all") BuilderWithAccessors build() { + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") BuilderWithAccessors build() { return new BuilderWithAccessors(plower, upper, foo, _bar); } - public @java.lang.Override @java.lang.SuppressWarnings("all") java.lang.String toString() { + public @java.lang.Override @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") java.lang.String toString() { return (((((((("BuilderWithAccessors.BuilderWithAccessorsBuilder(plower=" + this.plower) + ", upper=") + this.upper) + ", foo=") + this.foo) + ", _bar=") + this._bar) + ")"); } } @@ -34,14 +34,14 @@ private final int pUpper; private int _foo; private int __bar; - @java.lang.SuppressWarnings("all") BuilderWithAccessors(final int plower, final int upper, final int foo, final int _bar) { + @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") BuilderWithAccessors(final int plower, final int upper, final int foo, final int _bar) { super(); this.plower = plower; this.pUpper = upper; this._foo = foo; this.__bar = _bar; } - public static @java.lang.SuppressWarnings("all") BuilderWithAccessorsBuilder builder() { + public static @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") BuilderWithAccessorsBuilder builder() { return new BuilderWithAccessorsBuilder(); } } diff --git a/test/transform/resource/after-ecj/BuilderWithExistingBuilderClass.java b/test/transform/resource/after-ecj/BuilderWithExistingBuilderClass.java index 38cb0038..9ddbda7b 100644 --- a/test/transform/resource/after-ecj/BuilderWithExistingBuilderClass.java +++ b/test/transform/resource/after-ecj/BuilderWithExistingBuilderClass.java @@ -1,4 +1,4 @@ -import lombok.experimental.Builder; +import lombok.Builder; class BuilderWithExistingBuilderClass<T, K extends Number> { public static class BuilderWithExistingBuilderClassBuilder<Z extends Number> { private boolean arg2; @@ -6,21 +6,21 @@ class BuilderWithExistingBuilderClass<T, K extends Number> { private Z arg1; public void arg2(boolean arg) { } - @java.lang.SuppressWarnings("all") BuilderWithExistingBuilderClassBuilder() { + @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") BuilderWithExistingBuilderClassBuilder() { super(); } - public @java.lang.SuppressWarnings("all") BuilderWithExistingBuilderClassBuilder<Z> arg1(final Z arg1) { + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") BuilderWithExistingBuilderClassBuilder<Z> arg1(final Z arg1) { this.arg1 = arg1; return this; } - public @java.lang.SuppressWarnings("all") BuilderWithExistingBuilderClassBuilder<Z> arg3(final String arg3) { + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") BuilderWithExistingBuilderClassBuilder<Z> arg3(final String arg3) { this.arg3 = arg3; return this; } - public @java.lang.SuppressWarnings("all") BuilderWithExistingBuilderClass<String, Z> build() { + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") BuilderWithExistingBuilderClass<String, Z> build() { return BuilderWithExistingBuilderClass.<Z>staticMethod(arg1, arg2, arg3); } - public @java.lang.Override @java.lang.SuppressWarnings("all") java.lang.String toString() { + public @java.lang.Override @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") java.lang.String toString() { return (((((("BuilderWithExistingBuilderClass.BuilderWithExistingBuilderClassBuilder(arg1=" + this.arg1) + ", arg2=") + this.arg2) + ", arg3=") + this.arg3) + ")"); } } @@ -30,7 +30,7 @@ class BuilderWithExistingBuilderClass<T, K extends Number> { public static @Builder <Z extends Number>BuilderWithExistingBuilderClass<String, Z> staticMethod(Z arg1, boolean arg2, String arg3) { return null; } - public static @java.lang.SuppressWarnings("all") <Z extends Number>BuilderWithExistingBuilderClassBuilder<Z> builder() { + public static @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") <Z extends Number>BuilderWithExistingBuilderClassBuilder<Z> builder() { return new BuilderWithExistingBuilderClassBuilder<Z>(); } }
\ No newline at end of file diff --git a/test/transform/resource/after-ecj/ClassNamedAfterGetter.java b/test/transform/resource/after-ecj/ClassNamedAfterGetter.java index fdb6f122..79b422cc 100644 --- a/test/transform/resource/after-ecj/ClassNamedAfterGetter.java +++ b/test/transform/resource/after-ecj/ClassNamedAfterGetter.java @@ -3,7 +3,7 @@ class GetFoo { GetFoo() { super(); } - public @java.lang.SuppressWarnings("all") int getFoo() { + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") int getFoo() { return this.foo; } } diff --git a/test/transform/resource/after-ecj/CommentsInterspersed.java b/test/transform/resource/after-ecj/CommentsInterspersed.java index d708ad72..95489d54 100644 --- a/test/transform/resource/after-ecj/CommentsInterspersed.java +++ b/test/transform/resource/after-ecj/CommentsInterspersed.java @@ -6,7 +6,7 @@ public class CommentsInterspersed { super(); } public native void gwtTest(); - public @java.lang.SuppressWarnings("all") String getTest() { + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") String getTest() { return this.test; } } diff --git a/test/transform/resource/after-ecj/ConflictingStaticConstructorNames.java b/test/transform/resource/after-ecj/ConflictingStaticConstructorNames.java index f8aff69c..f9437f0e 100644 --- a/test/transform/resource/after-ecj/ConflictingStaticConstructorNames.java +++ b/test/transform/resource/after-ecj/ConflictingStaticConstructorNames.java @@ -1,25 +1,25 @@ @lombok.Data(staticConstructor = "of") @lombok.NoArgsConstructor class ConflictingStaticConstructorNames { - public @java.lang.Override @java.lang.SuppressWarnings("all") boolean equals(final java.lang.Object o) { + public @java.lang.Override @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") boolean equals(final java.lang.Object o) { if ((o == this)) return true; if ((! (o instanceof ConflictingStaticConstructorNames))) return false; - final @java.lang.SuppressWarnings("all") ConflictingStaticConstructorNames other = (ConflictingStaticConstructorNames) o; + final ConflictingStaticConstructorNames other = (ConflictingStaticConstructorNames) o; if ((! other.canEqual((java.lang.Object) this))) return false; return true; } - protected @java.lang.SuppressWarnings("all") boolean canEqual(final java.lang.Object other) { + protected @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") boolean canEqual(final java.lang.Object other) { return (other instanceof ConflictingStaticConstructorNames); } - public @java.lang.Override @java.lang.SuppressWarnings("all") int hashCode() { + public @java.lang.Override @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") int hashCode() { int result = 1; return result; } - public @java.lang.Override @java.lang.SuppressWarnings("all") java.lang.String toString() { + public @java.lang.Override @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") java.lang.String toString() { return "ConflictingStaticConstructorNames()"; } - public @java.lang.SuppressWarnings("all") ConflictingStaticConstructorNames() { + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") ConflictingStaticConstructorNames() { super(); } }
\ No newline at end of file diff --git a/test/transform/resource/after-ecj/Constructors.java b/test/transform/resource/after-ecj/Constructors.java index a4597ce6..998872a2 100644 --- a/test/transform/resource/after-ecj/Constructors.java +++ b/test/transform/resource/after-ecj/Constructors.java @@ -1,7 +1,7 @@ @lombok.RequiredArgsConstructor class RequiredArgsConstructor1 { final int x; String name; - public @java.beans.ConstructorProperties({"x"}) @java.lang.SuppressWarnings("all") RequiredArgsConstructor1(final int x) { + public @java.beans.ConstructorProperties({"x"}) @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") RequiredArgsConstructor1(final int x) { super(); this.x = x; } @@ -9,7 +9,7 @@ @lombok.RequiredArgsConstructor(access = lombok.AccessLevel.PROTECTED) class RequiredArgsConstructorAccess { final int x; String name; - protected @java.beans.ConstructorProperties({"x"}) @java.lang.SuppressWarnings("all") RequiredArgsConstructorAccess(final int x) { + protected @java.beans.ConstructorProperties({"x"}) @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") RequiredArgsConstructorAccess(final int x) { super(); this.x = x; } @@ -17,18 +17,18 @@ @lombok.RequiredArgsConstructor(staticName = "staticname") class RequiredArgsConstructorStaticName { final int x; String name; - private @java.lang.SuppressWarnings("all") RequiredArgsConstructorStaticName(final int x) { + private @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") RequiredArgsConstructorStaticName(final int x) { super(); this.x = x; } - public static @java.lang.SuppressWarnings("all") RequiredArgsConstructorStaticName staticname(final int x) { + public static @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") RequiredArgsConstructorStaticName staticname(final int x) { return new RequiredArgsConstructorStaticName(x); } } @lombok.RequiredArgsConstructor() class RequiredArgsConstructorWithAnnotations { final int x; String name; - public @Deprecated @java.beans.ConstructorProperties({"x"}) @java.lang.SuppressWarnings("all") RequiredArgsConstructorWithAnnotations(final int x) { + public @Deprecated @java.beans.ConstructorProperties({"x"}) @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") RequiredArgsConstructorWithAnnotations(final int x) { super(); this.x = x; } @@ -36,7 +36,7 @@ @lombok.AllArgsConstructor class AllArgsConstructor1 { final int x; String name; - public @java.beans.ConstructorProperties({"x", "name"}) @java.lang.SuppressWarnings("all") AllArgsConstructor1(final int x, final String name) { + public @java.beans.ConstructorProperties({"x", "name"}) @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") AllArgsConstructor1(final int x, final String name) { super(); this.x = x; this.name = name; @@ -45,35 +45,35 @@ @lombok.NoArgsConstructor class NoArgsConstructor1 { int x; String name; - public @java.lang.SuppressWarnings("all") NoArgsConstructor1() { + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") NoArgsConstructor1() { super(); } } @lombok.RequiredArgsConstructor(staticName = "of") class RequiredArgsConstructorStaticNameGenerics<T extends Number> { final T x; String name; - private @java.lang.SuppressWarnings("all") RequiredArgsConstructorStaticNameGenerics(final T x) { + private @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") RequiredArgsConstructorStaticNameGenerics(final T x) { super(); this.x = x; } - public static @java.lang.SuppressWarnings("all") <T extends Number>RequiredArgsConstructorStaticNameGenerics<T> of(final T x) { + public static @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") <T extends Number>RequiredArgsConstructorStaticNameGenerics<T> of(final T x) { return new RequiredArgsConstructorStaticNameGenerics<T>(x); } } @lombok.RequiredArgsConstructor(staticName = "of") class RequiredArgsConstructorStaticNameGenerics2<T extends Number> { final Class<T> x; String name; - private @java.lang.SuppressWarnings("all") RequiredArgsConstructorStaticNameGenerics2(final Class<T> x) { + private @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") RequiredArgsConstructorStaticNameGenerics2(final Class<T> x) { super(); this.x = x; } - public static @java.lang.SuppressWarnings("all") <T extends Number>RequiredArgsConstructorStaticNameGenerics2<T> of(final Class<T> x) { + public static @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") <T extends Number>RequiredArgsConstructorStaticNameGenerics2<T> of(final Class<T> x) { return new RequiredArgsConstructorStaticNameGenerics2<T>(x); } } @lombok.AllArgsConstructor(access = lombok.AccessLevel.PACKAGE) class AllArgsConstructorPackageAccess { final String x; - @java.lang.SuppressWarnings("all") AllArgsConstructorPackageAccess(final String x) { + @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") AllArgsConstructorPackageAccess(final String x) { super(); this.x = x; } diff --git a/test/transform/resource/after-ecj/ConstructorsConfiguration.java b/test/transform/resource/after-ecj/ConstructorsConfiguration.java index b55d3e03..33a95181 100644 --- a/test/transform/resource/after-ecj/ConstructorsConfiguration.java +++ b/test/transform/resource/after-ecj/ConstructorsConfiguration.java @@ -1,13 +1,13 @@ @lombok.AllArgsConstructor class ConstructorsConfiguration { int x; - public @java.lang.SuppressWarnings("all") ConstructorsConfiguration(final int x) { + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") ConstructorsConfiguration(final int x) { super(); this.x = x; } } @lombok.AllArgsConstructor(suppressConstructorProperties = false) class ConstructorsConfigurationExplicit { int x; - public @java.beans.ConstructorProperties({"x"}) @java.lang.SuppressWarnings("all") ConstructorsConfigurationExplicit(final int x) { + public @java.beans.ConstructorProperties({"x"}) @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") ConstructorsConfigurationExplicit(final int x) { super(); this.x = x; } diff --git a/test/transform/resource/after-ecj/ConstructorsWithAccessors.java b/test/transform/resource/after-ecj/ConstructorsWithAccessors.java index 0df8fbe1..7c691b42 100644 --- a/test/transform/resource/after-ecj/ConstructorsWithAccessors.java +++ b/test/transform/resource/after-ecj/ConstructorsWithAccessors.java @@ -3,7 +3,7 @@ int pUpper; int _huh; int __huh2; - public @java.beans.ConstructorProperties({"plower", "upper", "huh", "_huh2"}) @java.lang.SuppressWarnings("all") ConstructorsWithAccessors(final int plower, final int upper, final int huh, final int _huh2) { + public @java.beans.ConstructorProperties({"plower", "upper", "huh", "_huh2"}) @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") ConstructorsWithAccessors(final int plower, final int upper, final int huh, final int _huh2) { super(); this.plower = plower; this.pUpper = upper; diff --git a/test/transform/resource/after-ecj/DataConfiguration.java b/test/transform/resource/after-ecj/DataConfiguration.java index f2733a88..4ca1f093 100644 --- a/test/transform/resource/after-ecj/DataConfiguration.java +++ b/test/transform/resource/after-ecj/DataConfiguration.java @@ -1,33 +1,33 @@ @lombok.Data class DataConfiguration { final int x; - public @java.lang.SuppressWarnings("all") int getX() { + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") int getX() { return this.x; } - public @java.lang.Override @java.lang.SuppressWarnings("all") boolean equals(final java.lang.Object o) { + public @java.lang.Override @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") boolean equals(final java.lang.Object o) { if ((o == this)) return true; if ((! (o instanceof DataConfiguration))) return false; - final @java.lang.SuppressWarnings("all") DataConfiguration other = (DataConfiguration) o; + final DataConfiguration other = (DataConfiguration) o; if ((! other.canEqual((java.lang.Object) this))) return false; if ((this.getX() != other.getX())) return false; return true; } - protected @java.lang.SuppressWarnings("all") boolean canEqual(final java.lang.Object other) { + protected @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") boolean canEqual(final java.lang.Object other) { return (other instanceof DataConfiguration); } - public @java.lang.Override @java.lang.SuppressWarnings("all") int hashCode() { + public @java.lang.Override @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") int hashCode() { final int PRIME = 59; int result = 1; result = ((result * PRIME) + this.getX()); return result; } - public @java.lang.Override @java.lang.SuppressWarnings("all") java.lang.String toString() { + public @java.lang.Override @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") java.lang.String toString() { return (("DataConfiguration(x=" + this.getX()) + ")"); } - public @java.lang.SuppressWarnings("all") DataConfiguration(final int x) { + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") DataConfiguration(final int x) { super(); this.x = x; } diff --git a/test/transform/resource/after-ecj/DataExtended.java b/test/transform/resource/after-ecj/DataExtended.java index c2652ba4..46446a0f 100644 --- a/test/transform/resource/after-ecj/DataExtended.java +++ b/test/transform/resource/after-ecj/DataExtended.java @@ -1,36 +1,36 @@ @lombok.Data @lombok.ToString(doNotUseGetters = true) class DataExtended { int x; - public @java.lang.SuppressWarnings("all") int getX() { + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") int getX() { return this.x; } - public @java.lang.SuppressWarnings("all") void setX(final int x) { + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") void setX(final int x) { this.x = x; } - public @java.lang.Override @java.lang.SuppressWarnings("all") boolean equals(final java.lang.Object o) { + public @java.lang.Override @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") boolean equals(final java.lang.Object o) { if ((o == this)) return true; if ((! (o instanceof DataExtended))) return false; - final @java.lang.SuppressWarnings("all") DataExtended other = (DataExtended) o; + final DataExtended other = (DataExtended) o; if ((! other.canEqual((java.lang.Object) this))) return false; if ((this.getX() != other.getX())) return false; return true; } - protected @java.lang.SuppressWarnings("all") boolean canEqual(final java.lang.Object other) { + protected @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") boolean canEqual(final java.lang.Object other) { return (other instanceof DataExtended); } - public @java.lang.Override @java.lang.SuppressWarnings("all") int hashCode() { + public @java.lang.Override @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") int hashCode() { final int PRIME = 59; int result = 1; result = ((result * PRIME) + this.getX()); return result; } - public @java.lang.SuppressWarnings("all") DataExtended() { + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") DataExtended() { super(); } - public @java.lang.Override @java.lang.SuppressWarnings("all") java.lang.String toString() { + public @java.lang.Override @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") java.lang.String toString() { return (("DataExtended(x=" + this.x) + ")"); } } diff --git a/test/transform/resource/after-ecj/DataIgnore.java b/test/transform/resource/after-ecj/DataIgnore.java index d077a5db..dbf9713f 100644 --- a/test/transform/resource/after-ecj/DataIgnore.java +++ b/test/transform/resource/after-ecj/DataIgnore.java @@ -1,34 +1,34 @@ @lombok.Data class DataIgnore { final int x; String $name; - public @java.lang.SuppressWarnings("all") int getX() { + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") int getX() { return this.x; } - public @java.lang.Override @java.lang.SuppressWarnings("all") boolean equals(final java.lang.Object o) { + public @java.lang.Override @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") boolean equals(final java.lang.Object o) { if ((o == this)) return true; if ((! (o instanceof DataIgnore))) return false; - final @java.lang.SuppressWarnings("all") DataIgnore other = (DataIgnore) o; + final DataIgnore other = (DataIgnore) o; if ((! other.canEqual((java.lang.Object) this))) return false; if ((this.getX() != other.getX())) return false; return true; } - protected @java.lang.SuppressWarnings("all") boolean canEqual(final java.lang.Object other) { + protected @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") boolean canEqual(final java.lang.Object other) { return (other instanceof DataIgnore); } - public @java.lang.Override @java.lang.SuppressWarnings("all") int hashCode() { + public @java.lang.Override @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") int hashCode() { final int PRIME = 59; int result = 1; result = ((result * PRIME) + this.getX()); return result; } - public @java.lang.Override @java.lang.SuppressWarnings("all") java.lang.String toString() { + public @java.lang.Override @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") java.lang.String toString() { return (("DataIgnore(x=" + this.getX()) + ")"); } - public @java.beans.ConstructorProperties({"x"}) @java.lang.SuppressWarnings("all") DataIgnore(final int x) { + public @java.beans.ConstructorProperties({"x"}) @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") DataIgnore(final int x) { super(); this.x = x; } diff --git a/test/transform/resource/after-ecj/DataOnEnum.java b/test/transform/resource/after-ecj/DataOnEnum.java index 0f07088e..917a840b 100644 --- a/test/transform/resource/after-ecj/DataOnEnum.java +++ b/test/transform/resource/after-ecj/DataOnEnum.java @@ -3,13 +3,13 @@ public @lombok.Getter @lombok.ToString @lombok.RequiredArgsConstructor enum Data private final String someField; <clinit>() { } - public @java.lang.SuppressWarnings("all") String getSomeField() { + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") String getSomeField() { return this.someField; } - public @java.lang.Override @java.lang.SuppressWarnings("all") java.lang.String toString() { + public @java.lang.Override @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") java.lang.String toString() { return (("DataOnEnum(someField=" + this.getSomeField()) + ")"); } - private @java.lang.SuppressWarnings("all") DataOnEnum(final String someField) { + private @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") DataOnEnum(final String someField) { super(); this.someField = someField; } diff --git a/test/transform/resource/after-ecj/DataOnLocalClass.java b/test/transform/resource/after-ecj/DataOnLocalClass.java index 3f4832ff..856160de 100644 --- a/test/transform/resource/after-ecj/DataOnLocalClass.java +++ b/test/transform/resource/after-ecj/DataOnLocalClass.java @@ -7,21 +7,21 @@ class DataOnLocalClass1 { @Data class Local { final int x; String name; - public @java.lang.SuppressWarnings("all") int getX() { + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") int getX() { return this.x; } - public @java.lang.SuppressWarnings("all") String getName() { + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") String getName() { return this.name; } - public @java.lang.SuppressWarnings("all") void setName(final String name) { + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") void setName(final String name) { this.name = name; } - public @java.lang.Override @java.lang.SuppressWarnings("all") boolean equals(final java.lang.Object o) { + public @java.lang.Override @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") boolean equals(final java.lang.Object o) { if ((o == this)) return true; if ((! (o instanceof Local))) return false; - final @java.lang.SuppressWarnings("all") Local other = (Local) o; + final Local other = (Local) o; if ((! other.canEqual((java.lang.Object) this))) return false; if ((this.getX() != other.getX())) @@ -32,10 +32,10 @@ class DataOnLocalClass1 { return false; return true; } - protected @java.lang.SuppressWarnings("all") boolean canEqual(final java.lang.Object other) { + protected @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") boolean canEqual(final java.lang.Object other) { return (other instanceof Local); } - public @java.lang.Override @java.lang.SuppressWarnings("all") int hashCode() { + public @java.lang.Override @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") int hashCode() { final int PRIME = 59; int result = 1; result = ((result * PRIME) + this.getX()); @@ -43,10 +43,10 @@ class DataOnLocalClass1 { result = ((result * PRIME) + (($name == null) ? 0 : $name.hashCode())); return result; } - public @java.lang.Override @java.lang.SuppressWarnings("all") java.lang.String toString() { + public @java.lang.Override @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") java.lang.String toString() { return (((("Local(x=" + this.getX()) + ", name=") + this.getName()) + ")"); } - public @java.lang.SuppressWarnings("all") Local(final int x) { + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") Local(final int x) { super(); this.x = x; } @@ -58,22 +58,22 @@ class DataOnLocalClass2 { @Data class Local { @Data class InnerLocal { @lombok.NonNull String name; - public @lombok.NonNull @java.lang.SuppressWarnings("all") String getName() { + public @lombok.NonNull @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") String getName() { return this.name; } - public @java.lang.SuppressWarnings("all") void setName(final @lombok.NonNull String name) { + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") void setName(final @lombok.NonNull String name) { if ((name == null)) { throw new java.lang.NullPointerException("name"); } this.name = name; } - public @java.lang.Override @java.lang.SuppressWarnings("all") boolean equals(final java.lang.Object o) { + public @java.lang.Override @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") boolean equals(final java.lang.Object o) { if ((o == this)) return true; if ((! (o instanceof Local.InnerLocal))) return false; - final @java.lang.SuppressWarnings("all") InnerLocal other = (InnerLocal) o; + final InnerLocal other = (InnerLocal) o; if ((! other.canEqual((java.lang.Object) this))) return false; final java.lang.Object this$name = this.getName(); @@ -82,20 +82,20 @@ class DataOnLocalClass2 { return false; return true; } - protected @java.lang.SuppressWarnings("all") boolean canEqual(final java.lang.Object other) { + protected @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") boolean canEqual(final java.lang.Object other) { return (other instanceof Local.InnerLocal); } - public @java.lang.Override @java.lang.SuppressWarnings("all") int hashCode() { + public @java.lang.Override @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") int hashCode() { final int PRIME = 59; int result = 1; final java.lang.Object $name = this.getName(); result = ((result * PRIME) + (($name == null) ? 0 : $name.hashCode())); return result; } - public @java.lang.Override @java.lang.SuppressWarnings("all") java.lang.String toString() { + public @java.lang.Override @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") java.lang.String toString() { return (("Local.InnerLocal(name=" + this.getName()) + ")"); } - public @java.lang.SuppressWarnings("all") InnerLocal(final @lombok.NonNull String name) { + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") InnerLocal(final @lombok.NonNull String name) { super(); if ((name == null)) { @@ -105,34 +105,34 @@ class DataOnLocalClass2 { } } final int x; - public @java.lang.SuppressWarnings("all") int getX() { + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") int getX() { return this.x; } - public @java.lang.Override @java.lang.SuppressWarnings("all") boolean equals(final java.lang.Object o) { + public @java.lang.Override @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") boolean equals(final java.lang.Object o) { if ((o == this)) return true; if ((! (o instanceof Local))) return false; - final @java.lang.SuppressWarnings("all") Local other = (Local) o; + final Local other = (Local) o; if ((! other.canEqual((java.lang.Object) this))) return false; if ((this.getX() != other.getX())) return false; return true; } - protected @java.lang.SuppressWarnings("all") boolean canEqual(final java.lang.Object other) { + protected @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") boolean canEqual(final java.lang.Object other) { return (other instanceof Local); } - public @java.lang.Override @java.lang.SuppressWarnings("all") int hashCode() { + public @java.lang.Override @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") int hashCode() { final int PRIME = 59; int result = 1; result = ((result * PRIME) + this.getX()); return result; } - public @java.lang.Override @java.lang.SuppressWarnings("all") java.lang.String toString() { + public @java.lang.Override @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") java.lang.String toString() { return (("Local(x=" + this.getX()) + ")"); } - public @java.lang.SuppressWarnings("all") Local(final int x) { + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") Local(final int x) { super(); this.x = x; } diff --git a/test/transform/resource/after-ecj/DataPlain.java b/test/transform/resource/after-ecj/DataPlain.java index 858f46dd..8b243766 100644 --- a/test/transform/resource/after-ecj/DataPlain.java +++ b/test/transform/resource/after-ecj/DataPlain.java @@ -2,21 +2,21 @@ import lombok.Data; @lombok.Data class Data1 { final int x; String name; - public @java.lang.SuppressWarnings("all") int getX() { + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") int getX() { return this.x; } - public @java.lang.SuppressWarnings("all") String getName() { + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") String getName() { return this.name; } - public @java.lang.SuppressWarnings("all") void setName(final String name) { + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") void setName(final String name) { this.name = name; } - public @java.lang.Override @java.lang.SuppressWarnings("all") boolean equals(final java.lang.Object o) { + public @java.lang.Override @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") boolean equals(final java.lang.Object o) { if ((o == this)) return true; if ((! (o instanceof Data1))) return false; - final @java.lang.SuppressWarnings("all") Data1 other = (Data1) o; + final Data1 other = (Data1) o; if ((! other.canEqual((java.lang.Object) this))) return false; if ((this.getX() != other.getX())) @@ -27,10 +27,10 @@ import lombok.Data; return false; return true; } - protected @java.lang.SuppressWarnings("all") boolean canEqual(final java.lang.Object other) { + protected @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") boolean canEqual(final java.lang.Object other) { return (other instanceof Data1); } - public @java.lang.Override @java.lang.SuppressWarnings("all") int hashCode() { + public @java.lang.Override @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") int hashCode() { final int PRIME = 59; int result = 1; result = ((result * PRIME) + this.getX()); @@ -38,10 +38,10 @@ import lombok.Data; result = ((result * PRIME) + (($name == null) ? 0 : $name.hashCode())); return result; } - public @java.lang.Override @java.lang.SuppressWarnings("all") java.lang.String toString() { + public @java.lang.Override @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") java.lang.String toString() { return (((("Data1(x=" + this.getX()) + ", name=") + this.getName()) + ")"); } - public @java.beans.ConstructorProperties({"x"}) @java.lang.SuppressWarnings("all") Data1(final int x) { + public @java.beans.ConstructorProperties({"x"}) @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") Data1(final int x) { super(); this.x = x; } @@ -49,21 +49,21 @@ import lombok.Data; @Data class Data2 { final int x; String name; - public @java.lang.SuppressWarnings("all") int getX() { + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") int getX() { return this.x; } - public @java.lang.SuppressWarnings("all") String getName() { + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") String getName() { return this.name; } - public @java.lang.SuppressWarnings("all") void setName(final String name) { + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") void setName(final String name) { this.name = name; } - public @java.lang.Override @java.lang.SuppressWarnings("all") boolean equals(final java.lang.Object o) { + public @java.lang.Override @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") boolean equals(final java.lang.Object o) { if ((o == this)) return true; if ((! (o instanceof Data2))) return false; - final @java.lang.SuppressWarnings("all") Data2 other = (Data2) o; + final Data2 other = (Data2) o; if ((! other.canEqual((java.lang.Object) this))) return false; if ((this.getX() != other.getX())) @@ -74,10 +74,10 @@ import lombok.Data; return false; return true; } - protected @java.lang.SuppressWarnings("all") boolean canEqual(final java.lang.Object other) { + protected @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") boolean canEqual(final java.lang.Object other) { return (other instanceof Data2); } - public @java.lang.Override @java.lang.SuppressWarnings("all") int hashCode() { + public @java.lang.Override @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") int hashCode() { final int PRIME = 59; int result = 1; result = ((result * PRIME) + this.getX()); @@ -85,10 +85,10 @@ import lombok.Data; result = ((result * PRIME) + (($name == null) ? 0 : $name.hashCode())); return result; } - public @java.lang.Override @java.lang.SuppressWarnings("all") java.lang.String toString() { + public @java.lang.Override @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") java.lang.String toString() { return (((("Data2(x=" + this.getX()) + ", name=") + this.getName()) + ")"); } - public @java.beans.ConstructorProperties({"x"}) @java.lang.SuppressWarnings("all") Data2(final int x) { + public @java.beans.ConstructorProperties({"x"}) @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") Data2(final int x) { super(); this.x = x; } @@ -96,21 +96,21 @@ import lombok.Data; final @Data class Data3 { final int x; String name; - public @java.lang.SuppressWarnings("all") int getX() { + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") int getX() { return this.x; } - public @java.lang.SuppressWarnings("all") String getName() { + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") String getName() { return this.name; } - public @java.lang.SuppressWarnings("all") void setName(final String name) { + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") void setName(final String name) { this.name = name; } - public @java.lang.Override @java.lang.SuppressWarnings("all") boolean equals(final java.lang.Object o) { + public @java.lang.Override @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") boolean equals(final java.lang.Object o) { if ((o == this)) return true; if ((! (o instanceof Data3))) return false; - final @java.lang.SuppressWarnings("all") Data3 other = (Data3) o; + final Data3 other = (Data3) o; if ((this.getX() != other.getX())) return false; final java.lang.Object this$name = this.getName(); @@ -119,7 +119,7 @@ final @Data class Data3 { return false; return true; } - public @java.lang.Override @java.lang.SuppressWarnings("all") int hashCode() { + public @java.lang.Override @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") int hashCode() { final int PRIME = 59; int result = 1; result = ((result * PRIME) + this.getX()); @@ -127,10 +127,10 @@ final @Data class Data3 { result = ((result * PRIME) + (($name == null) ? 0 : $name.hashCode())); return result; } - public @java.lang.Override @java.lang.SuppressWarnings("all") java.lang.String toString() { + public @java.lang.Override @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") java.lang.String toString() { return (((("Data3(x=" + this.getX()) + ", name=") + this.getName()) + ")"); } - public @java.beans.ConstructorProperties({"x"}) @java.lang.SuppressWarnings("all") Data3(final int x) { + public @java.beans.ConstructorProperties({"x"}) @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") Data3(final int x) { super(); this.x = x; } @@ -140,21 +140,21 @@ final @Data @lombok.EqualsAndHashCode(callSuper = true) class Data4 extends java Data4() { super(); } - public @java.lang.SuppressWarnings("all") int getX() { + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") int getX() { return this.x; } - public @java.lang.SuppressWarnings("all") void setX(final int x) { + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") void setX(final int x) { this.x = x; } - public @java.lang.Override @java.lang.SuppressWarnings("all") java.lang.String toString() { + public @java.lang.Override @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") java.lang.String toString() { return (("Data4(x=" + this.getX()) + ")"); } - public @java.lang.Override @java.lang.SuppressWarnings("all") boolean equals(final java.lang.Object o) { + public @java.lang.Override @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") boolean equals(final java.lang.Object o) { if ((o == this)) return true; if ((! (o instanceof Data4))) return false; - final @java.lang.SuppressWarnings("all") Data4 other = (Data4) o; + final Data4 other = (Data4) o; if ((! other.canEqual((java.lang.Object) this))) return false; if ((! super.equals(o))) @@ -163,10 +163,10 @@ final @Data @lombok.EqualsAndHashCode(callSuper = true) class Data4 extends java return false; return true; } - protected @java.lang.SuppressWarnings("all") boolean canEqual(final java.lang.Object other) { + protected @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") boolean canEqual(final java.lang.Object other) { return (other instanceof Data4); } - public @java.lang.Override @java.lang.SuppressWarnings("all") int hashCode() { + public @java.lang.Override @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") int hashCode() { final int PRIME = 59; int result = 1; result = ((result * PRIME) + super.hashCode()); @@ -175,46 +175,46 @@ final @Data @lombok.EqualsAndHashCode(callSuper = true) class Data4 extends java } } @Data class Data5 { - public @java.lang.Override @java.lang.SuppressWarnings("all") boolean equals(final java.lang.Object o) { + public @java.lang.Override @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") boolean equals(final java.lang.Object o) { if ((o == this)) return true; if ((! (o instanceof Data5))) return false; - final @java.lang.SuppressWarnings("all") Data5 other = (Data5) o; + final Data5 other = (Data5) o; if ((! other.canEqual((java.lang.Object) this))) return false; return true; } - protected @java.lang.SuppressWarnings("all") boolean canEqual(final java.lang.Object other) { + protected @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") boolean canEqual(final java.lang.Object other) { return (other instanceof Data5); } - public @java.lang.Override @java.lang.SuppressWarnings("all") int hashCode() { + public @java.lang.Override @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") int hashCode() { int result = 1; return result; } - public @java.lang.Override @java.lang.SuppressWarnings("all") java.lang.String toString() { + public @java.lang.Override @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") java.lang.String toString() { return "Data5()"; } - public @java.lang.SuppressWarnings("all") Data5() { + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") Data5() { super(); } } final @Data class Data6 { - public @java.lang.Override @java.lang.SuppressWarnings("all") boolean equals(final java.lang.Object o) { + public @java.lang.Override @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") boolean equals(final java.lang.Object o) { if ((o == this)) return true; if ((! (o instanceof Data6))) return false; return true; } - public @java.lang.Override @java.lang.SuppressWarnings("all") int hashCode() { + public @java.lang.Override @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") int hashCode() { int result = 1; return result; } - public @java.lang.Override @java.lang.SuppressWarnings("all") java.lang.String toString() { + public @java.lang.Override @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") java.lang.String toString() { return "Data6()"; } - public @java.lang.SuppressWarnings("all") Data6() { + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") Data6() { super(); } } diff --git a/test/transform/resource/after-ecj/DataWithGetter.java b/test/transform/resource/after-ecj/DataWithGetter.java index ee74ed4e..b37aa137 100644 --- a/test/transform/resource/after-ecj/DataWithGetter.java +++ b/test/transform/resource/after-ecj/DataWithGetter.java @@ -2,18 +2,18 @@ private int x; private int y; private final String z; - public @java.lang.SuppressWarnings("all") void setX(final int x) { + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") void setX(final int x) { this.x = x; } - public @java.lang.SuppressWarnings("all") void setY(final int y) { + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") void setY(final int y) { this.y = y; } - public @java.lang.Override @java.lang.SuppressWarnings("all") boolean equals(final java.lang.Object o) { + public @java.lang.Override @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") boolean equals(final java.lang.Object o) { if ((o == this)) return true; if ((! (o instanceof DataWithGetter))) return false; - final @java.lang.SuppressWarnings("all") DataWithGetter other = (DataWithGetter) o; + final DataWithGetter other = (DataWithGetter) o; if ((! other.canEqual((java.lang.Object) this))) return false; if ((this.getX() != other.getX())) @@ -26,10 +26,10 @@ return false; return true; } - protected @java.lang.SuppressWarnings("all") boolean canEqual(final java.lang.Object other) { + protected @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") boolean canEqual(final java.lang.Object other) { return (other instanceof DataWithGetter); } - public @java.lang.Override @java.lang.SuppressWarnings("all") int hashCode() { + public @java.lang.Override @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") int hashCode() { final int PRIME = 59; int result = 1; result = ((result * PRIME) + this.getX()); @@ -38,20 +38,20 @@ result = ((result * PRIME) + (($z == null) ? 0 : $z.hashCode())); return result; } - public @java.lang.Override @java.lang.SuppressWarnings("all") java.lang.String toString() { + public @java.lang.Override @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") java.lang.String toString() { return (((((("DataWithGetter(x=" + this.getX()) + ", y=") + this.getY()) + ", z=") + this.getZ()) + ")"); } - public @java.beans.ConstructorProperties({"z"}) @java.lang.SuppressWarnings("all") DataWithGetter(final String z) { + public @java.beans.ConstructorProperties({"z"}) @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") DataWithGetter(final String z) { super(); this.z = z; } - public @java.lang.SuppressWarnings("all") int getX() { + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") int getX() { return this.x; } - public @java.lang.SuppressWarnings("all") int getY() { + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") int getY() { return this.y; } - public @java.lang.SuppressWarnings("all") String getZ() { + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") String getZ() { return this.z; } } diff --git a/test/transform/resource/after-ecj/DataWithGetterNone.java b/test/transform/resource/after-ecj/DataWithGetterNone.java index 056e071d..66a26277 100644 --- a/test/transform/resource/after-ecj/DataWithGetterNone.java +++ b/test/transform/resource/after-ecj/DataWithGetterNone.java @@ -2,18 +2,18 @@ private int x; private int y; private final String z; - public @java.lang.SuppressWarnings("all") void setX(final int x) { + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") void setX(final int x) { this.x = x; } - public @java.lang.SuppressWarnings("all") void setY(final int y) { + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") void setY(final int y) { this.y = y; } - public @java.lang.Override @java.lang.SuppressWarnings("all") boolean equals(final java.lang.Object o) { + public @java.lang.Override @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") boolean equals(final java.lang.Object o) { if ((o == this)) return true; if ((! (o instanceof DataWithGetterNone))) return false; - final @java.lang.SuppressWarnings("all") DataWithGetterNone other = (DataWithGetterNone) o; + final DataWithGetterNone other = (DataWithGetterNone) o; if ((! other.canEqual((java.lang.Object) this))) return false; if ((this.x != other.x)) @@ -26,10 +26,10 @@ return false; return true; } - protected @java.lang.SuppressWarnings("all") boolean canEqual(final java.lang.Object other) { + protected @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") boolean canEqual(final java.lang.Object other) { return (other instanceof DataWithGetterNone); } - public @java.lang.Override @java.lang.SuppressWarnings("all") int hashCode() { + public @java.lang.Override @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") int hashCode() { final int PRIME = 59; int result = 1; result = ((result * PRIME) + this.x); @@ -38,10 +38,10 @@ result = ((result * PRIME) + (($z == null) ? 0 : $z.hashCode())); return result; } - public @java.lang.Override @java.lang.SuppressWarnings("all") java.lang.String toString() { + public @java.lang.Override @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") java.lang.String toString() { return (((((("DataWithGetterNone(x=" + this.x) + ", y=") + this.y) + ", z=") + this.z) + ")"); } - public @java.beans.ConstructorProperties({"z"}) @java.lang.SuppressWarnings("all") DataWithGetterNone(final String z) { + public @java.beans.ConstructorProperties({"z"}) @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") DataWithGetterNone(final String z) { super(); this.z = z; } diff --git a/test/transform/resource/after-ecj/DelegateOnGetter.java b/test/transform/resource/after-ecj/DelegateOnGetter.java index 59f6a3b8..06b57ceb 100644 --- a/test/transform/resource/after-ecj/DelegateOnGetter.java +++ b/test/transform/resource/after-ecj/DelegateOnGetter.java @@ -9,7 +9,7 @@ class DelegateOnGetter { DelegateOnGetter() { super(); } - public @Delegate @java.lang.SuppressWarnings("all") Bar getBar() { + public @Delegate @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") Bar getBar() { java.lang.Object value = this.bar.get(); if ((value == null)) { @@ -35,10 +35,10 @@ class DelegateOnGetter { } return (Bar) ((value == this.bar) ? null : value); } - public @java.lang.SuppressWarnings("all") int getInt() { + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") int getInt() { return this.getBar().getInt(); } - public @java.lang.SuppressWarnings("all") void setList(final java.util.ArrayList<java.lang.String> list) { + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") void setList(final java.util.ArrayList<java.lang.String> list) { this.getBar().setList(list); } } diff --git a/test/transform/resource/after-ecj/DelegateOnGetterNone.java b/test/transform/resource/after-ecj/DelegateOnGetterNone.java index 0cfb02c0..2018e1e9 100644 --- a/test/transform/resource/after-ecj/DelegateOnGetterNone.java +++ b/test/transform/resource/after-ecj/DelegateOnGetterNone.java @@ -10,10 +10,10 @@ import lombok.Getter; DelegateOnGetterNone() { super(); } - public @java.lang.SuppressWarnings("all") int getInt() { + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") int getInt() { return this.bar.getInt(); } - public @java.lang.SuppressWarnings("all") void setList(final java.util.ArrayList<java.lang.String> list) { + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") void setList(final java.util.ArrayList<java.lang.String> list) { this.bar.setList(list); } } diff --git a/test/transform/resource/after-ecj/DelegateOnMethods.java b/test/transform/resource/after-ecj/DelegateOnMethods.java index 6560657c..3e833ebb 100644 --- a/test/transform/resource/after-ecj/DelegateOnMethods.java +++ b/test/transform/resource/after-ecj/DelegateOnMethods.java @@ -7,7 +7,7 @@ abstract class DelegateOnMethods { super(); } public abstract @Delegate Bar getBar(); - public @java.lang.SuppressWarnings("all") void bar(final java.util.ArrayList<java.lang.String> list) { + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") void bar(final java.util.ArrayList<java.lang.String> list) { this.getBar().bar(list); } } diff --git a/test/transform/resource/after-ecj/DelegateTypesAndExcludes.java b/test/transform/resource/after-ecj/DelegateTypesAndExcludes.java index 86f54139..3718c5d9 100644 --- a/test/transform/resource/after-ecj/DelegateTypesAndExcludes.java +++ b/test/transform/resource/after-ecj/DelegateTypesAndExcludes.java @@ -27,10 +27,10 @@ class DelegatePlain { DelegatePlain() { super(); } - public @java.lang.SuppressWarnings("all") void bar(final java.util.ArrayList<java.lang.String> list) { + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") void bar(final java.util.ArrayList<java.lang.String> list) { this.bar.bar(list); } - public @java.lang.SuppressWarnings("all") void foo() { + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") void foo() { this.foo.foo(); } } diff --git a/test/transform/resource/after-ecj/DelegateWithDeprecated.java b/test/transform/resource/after-ecj/DelegateWithDeprecated.java index 71eb7889..ab3aa188 100644 --- a/test/transform/resource/after-ecj/DelegateWithDeprecated.java +++ b/test/transform/resource/after-ecj/DelegateWithDeprecated.java @@ -9,13 +9,13 @@ class DelegateWithDeprecated { DelegateWithDeprecated() { super(); } - public @java.lang.Deprecated @java.lang.SuppressWarnings("all") void deprecatedAnnotation() { + public @java.lang.Deprecated @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") void deprecatedAnnotation() { this.bar.deprecatedAnnotation(); } - public @java.lang.Deprecated @java.lang.SuppressWarnings("all") void deprecatedComment() { + public @java.lang.Deprecated @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") void deprecatedComment() { this.bar.deprecatedComment(); } - public @java.lang.SuppressWarnings("all") void notDeprecated() { + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") void notDeprecated() { this.bar.notDeprecated(); } } diff --git a/test/transform/resource/after-ecj/EncodingUsAscii.java b/test/transform/resource/after-ecj/EncodingUsAscii.java new file mode 100644 index 00000000..b66feb0c --- /dev/null +++ b/test/transform/resource/after-ecj/EncodingUsAscii.java @@ -0,0 +1 @@ +//ignore: This test serves to check what happens with 'weird' characters when you use delombok. It's just not relevant for ecj. diff --git a/test/transform/resource/after-ecj/EncodingUtf8.java b/test/transform/resource/after-ecj/EncodingUtf8.java new file mode 100644 index 00000000..29dce86f --- /dev/null +++ b/test/transform/resource/after-ecj/EncodingUtf8.java @@ -0,0 +1,9 @@ +@lombok.ToString class EncodingUtf8 { + String foo๑๑ = "\t\b "; + EncodingUtf8() { + super(); + } + public @java.lang.Override @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") java.lang.String toString() { + return (("EncodingUtf8(foo๑๑=" + this.foo๑๑) + ")"); + } +}
\ No newline at end of file diff --git a/test/transform/resource/after-ecj/EqualsAndHashCode.java b/test/transform/resource/after-ecj/EqualsAndHashCode.java index 05cbf2a3..7db65c82 100644 --- a/test/transform/resource/after-ecj/EqualsAndHashCode.java +++ b/test/transform/resource/after-ecj/EqualsAndHashCode.java @@ -7,12 +7,12 @@ EqualsAndHashCode() { super(); } - public @java.lang.Override @java.lang.SuppressWarnings("all") boolean equals(final java.lang.Object o) { + public @java.lang.Override @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") boolean equals(final java.lang.Object o) { if ((o == this)) return true; if ((! (o instanceof EqualsAndHashCode))) return false; - final @java.lang.SuppressWarnings("all") EqualsAndHashCode other = (EqualsAndHashCode) o; + final EqualsAndHashCode other = (EqualsAndHashCode) o; if ((! other.canEqual((java.lang.Object) this))) return false; if ((this.x != other.x)) @@ -31,10 +31,10 @@ return false; return true; } - protected @java.lang.SuppressWarnings("all") boolean canEqual(final java.lang.Object other) { + protected @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") boolean canEqual(final java.lang.Object other) { return (other instanceof EqualsAndHashCode); } - public @java.lang.Override @java.lang.SuppressWarnings("all") int hashCode() { + public @java.lang.Override @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") int hashCode() { final int PRIME = 59; int result = 1; result = ((result * PRIME) + this.x); @@ -56,12 +56,12 @@ final @lombok.EqualsAndHashCode class EqualsAndHashCode2 { EqualsAndHashCode2() { super(); } - public @java.lang.Override @java.lang.SuppressWarnings("all") boolean equals(final java.lang.Object o) { + public @java.lang.Override @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") boolean equals(final java.lang.Object o) { if ((o == this)) return true; if ((! (o instanceof EqualsAndHashCode2))) return false; - final @java.lang.SuppressWarnings("all") EqualsAndHashCode2 other = (EqualsAndHashCode2) o; + final EqualsAndHashCode2 other = (EqualsAndHashCode2) o; if ((this.x != other.x)) return false; if ((this.y != other.y)) @@ -74,7 +74,7 @@ final @lombok.EqualsAndHashCode class EqualsAndHashCode2 { return false; return true; } - public @java.lang.Override @java.lang.SuppressWarnings("all") int hashCode() { + public @java.lang.Override @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") int hashCode() { final int PRIME = 59; int result = 1; result = ((result * PRIME) + this.x); @@ -91,20 +91,20 @@ final @lombok.EqualsAndHashCode(callSuper = false) class EqualsAndHashCode3 exte EqualsAndHashCode3() { super(); } - public @java.lang.Override @java.lang.SuppressWarnings("all") boolean equals(final java.lang.Object o) { + public @java.lang.Override @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") boolean equals(final java.lang.Object o) { if ((o == this)) return true; if ((! (o instanceof EqualsAndHashCode3))) return false; - final @java.lang.SuppressWarnings("all") EqualsAndHashCode3 other = (EqualsAndHashCode3) o; + final EqualsAndHashCode3 other = (EqualsAndHashCode3) o; if ((! other.canEqual((java.lang.Object) this))) return false; return true; } - protected @java.lang.SuppressWarnings("all") boolean canEqual(final java.lang.Object other) { + protected @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") boolean canEqual(final java.lang.Object other) { return (other instanceof EqualsAndHashCode3); } - public @java.lang.Override @java.lang.SuppressWarnings("all") int hashCode() { + public @java.lang.Override @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") int hashCode() { int result = 1; return result; } @@ -113,22 +113,22 @@ final @lombok.EqualsAndHashCode(callSuper = false) class EqualsAndHashCode3 exte EqualsAndHashCode4() { super(); } - public @java.lang.Override @java.lang.SuppressWarnings("all") boolean equals(final java.lang.Object o) { + public @java.lang.Override @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") boolean equals(final java.lang.Object o) { if ((o == this)) return true; if ((! (o instanceof EqualsAndHashCode4))) return false; - final @java.lang.SuppressWarnings("all") EqualsAndHashCode4 other = (EqualsAndHashCode4) o; + final EqualsAndHashCode4 other = (EqualsAndHashCode4) o; if ((! other.canEqual((java.lang.Object) this))) return false; if ((! super.equals(o))) return false; return true; } - protected @java.lang.SuppressWarnings("all") boolean canEqual(final java.lang.Object other) { + protected @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") boolean canEqual(final java.lang.Object other) { return (other instanceof EqualsAndHashCode4); } - public @java.lang.Override @java.lang.SuppressWarnings("all") int hashCode() { + public @java.lang.Override @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") int hashCode() { final int PRIME = 59; int result = 1; result = ((result * PRIME) + super.hashCode()); diff --git a/test/transform/resource/after-ecj/EqualsAndHashCodeWithExistingMethods.java b/test/transform/resource/after-ecj/EqualsAndHashCodeWithExistingMethods.java index feda33ce..e4efb336 100644 --- a/test/transform/resource/after-ecj/EqualsAndHashCodeWithExistingMethods.java +++ b/test/transform/resource/after-ecj/EqualsAndHashCodeWithExistingMethods.java @@ -24,12 +24,12 @@ final @lombok.EqualsAndHashCode(callSuper = true) class EqualsAndHashCodeWithExi private boolean canEqual(Object other) { return true; } - public @java.lang.Override @java.lang.SuppressWarnings("all") boolean equals(final java.lang.Object o) { + public @java.lang.Override @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") boolean equals(final java.lang.Object o) { if ((o == this)) return true; if ((! (o instanceof EqualsAndHashCodeWithExistingMethods3))) return false; - final @java.lang.SuppressWarnings("all") EqualsAndHashCodeWithExistingMethods3 other = (EqualsAndHashCodeWithExistingMethods3) o; + final EqualsAndHashCodeWithExistingMethods3 other = (EqualsAndHashCodeWithExistingMethods3) o; if ((! other.canEqual((java.lang.Object) this))) return false; if ((! super.equals(o))) @@ -38,7 +38,7 @@ final @lombok.EqualsAndHashCode(callSuper = true) class EqualsAndHashCodeWithExi return false; return true; } - public @java.lang.Override @java.lang.SuppressWarnings("all") int hashCode() { + public @java.lang.Override @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") int hashCode() { final int PRIME = 59; int result = 1; result = ((result * PRIME) + super.hashCode()); diff --git a/test/transform/resource/after-ecj/EqualsAndHashCodeWithOnParam.java b/test/transform/resource/after-ecj/EqualsAndHashCodeWithOnParam.java index fc226f06..77bba8e0 100644 --- a/test/transform/resource/after-ecj/EqualsAndHashCodeWithOnParam.java +++ b/test/transform/resource/after-ecj/EqualsAndHashCodeWithOnParam.java @@ -10,12 +10,12 @@ EqualsAndHashCodeWithOnParam() { super(); } - public @java.lang.Override @java.lang.SuppressWarnings("all") boolean equals(final @Nullable java.lang.Object o) { + public @java.lang.Override @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") boolean equals(final @Nullable java.lang.Object o) { if ((o == this)) return true; if ((! (o instanceof EqualsAndHashCodeWithOnParam))) return false; - final @java.lang.SuppressWarnings("all") EqualsAndHashCodeWithOnParam other = (EqualsAndHashCodeWithOnParam) o; + final EqualsAndHashCodeWithOnParam other = (EqualsAndHashCodeWithOnParam) o; if ((! other.canEqual((java.lang.Object) this))) return false; if ((this.x != other.x)) @@ -34,10 +34,10 @@ return false; return true; } - protected @java.lang.SuppressWarnings("all") boolean canEqual(final @Nullable java.lang.Object other) { + protected @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") boolean canEqual(final @Nullable java.lang.Object other) { return (other instanceof EqualsAndHashCodeWithOnParam); } - public @java.lang.Override @java.lang.SuppressWarnings("all") int hashCode() { + public @java.lang.Override @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") int hashCode() { final int PRIME = 59; int result = 1; result = ((result * PRIME) + this.x); diff --git a/test/transform/resource/after-ecj/EqualsAndHashCodeWithSomeExistingMethods.java b/test/transform/resource/after-ecj/EqualsAndHashCodeWithSomeExistingMethods.java index ee846c64..781faccb 100644 --- a/test/transform/resource/after-ecj/EqualsAndHashCodeWithSomeExistingMethods.java +++ b/test/transform/resource/after-ecj/EqualsAndHashCodeWithSomeExistingMethods.java @@ -22,7 +22,7 @@ import static lombok.AccessLevel.NONE; return true; if ((! (o instanceof EqualsAndHashCodeWithSomeExistingMethods2))) return false; - final @java.lang.SuppressWarnings("all") EqualsAndHashCodeWithSomeExistingMethods2 other = (EqualsAndHashCodeWithSomeExistingMethods2) o; + final EqualsAndHashCodeWithSomeExistingMethods2 other = (EqualsAndHashCodeWithSomeExistingMethods2) o; if ((! other.canEqual((java.lang.Object) this))) return false; if ((this.x != other.x)) @@ -64,7 +64,7 @@ import static lombok.AccessLevel.NONE; return true; if ((! (o instanceof EqualsAndHashCodeWithNoExistingMethods))) return false; - final @java.lang.SuppressWarnings("all") EqualsAndHashCodeWithNoExistingMethods other = (EqualsAndHashCodeWithNoExistingMethods) o; + final EqualsAndHashCodeWithNoExistingMethods other = (EqualsAndHashCodeWithNoExistingMethods) o; if ((! other.canEqual((java.lang.Object) this))) return false; if ((this.x != other.x)) diff --git a/test/transform/resource/after-ecj/GenerateSuppressFBWarnings.java b/test/transform/resource/after-ecj/GenerateSuppressFBWarnings.java new file mode 100644 index 00000000..407d41b6 --- /dev/null +++ b/test/transform/resource/after-ecj/GenerateSuppressFBWarnings.java @@ -0,0 +1,9 @@ +class GenerateSuppressFBWarnings { + @lombok.Getter int y; + GenerateSuppressFBWarnings() { + super(); + } + public @java.lang.SuppressWarnings("all") @edu.umd.cs.findbugs.annotations.SuppressFBWarnings(justification = "generated code") @javax.annotation.Generated("lombok") int getY() { + return this.y; + } +}
\ No newline at end of file diff --git a/test/transform/resource/after-ecj/GetterAccessLevel.java b/test/transform/resource/after-ecj/GetterAccessLevel.java index 14edfb56..533e05cc 100644 --- a/test/transform/resource/after-ecj/GetterAccessLevel.java +++ b/test/transform/resource/after-ecj/GetterAccessLevel.java @@ -13,31 +13,31 @@ class GetterAccessLevel { GetterAccessLevel() { super(); } - private @java.lang.SuppressWarnings("all") boolean isPrivate() { + private @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") boolean isPrivate() { return this.isPrivate; } - @java.lang.SuppressWarnings("all") boolean isPackage() { + @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") boolean isPackage() { return this.isPackage; } - protected @java.lang.SuppressWarnings("all") boolean isProtected() { + protected @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") boolean isProtected() { return this.isProtected; } - public @java.lang.SuppressWarnings("all") boolean isPublic() { + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") boolean isPublic() { return this.isPublic; } - private @java.lang.SuppressWarnings("all") String getPrivateString() { + private @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") String getPrivateString() { return this.privateString; } - @java.lang.SuppressWarnings("all") String getPackageString() { + @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") String getPackageString() { return this.packageString; } - protected @java.lang.SuppressWarnings("all") String getProtectedString() { + protected @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") String getProtectedString() { return this.protectedString; } - public @java.lang.SuppressWarnings("all") String getPublicString() { + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") String getPublicString() { return this.publicString; } - public @java.lang.SuppressWarnings("all") String getValue() { + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") String getValue() { return this.value; } } diff --git a/test/transform/resource/after-ecj/GetterAlreadyExists.java b/test/transform/resource/after-ecj/GetterAlreadyExists.java index 04f5b81e..b0856dce 100644 --- a/test/transform/resource/after-ecj/GetterAlreadyExists.java +++ b/test/transform/resource/after-ecj/GetterAlreadyExists.java @@ -6,7 +6,7 @@ class Getter1 { boolean hasFoo() { return true; } - public @java.lang.SuppressWarnings("all") boolean isFoo() { + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") boolean isFoo() { return this.foo; } } @@ -36,7 +36,7 @@ class Getter4 { String hasFoo() { return null; } - public @java.lang.SuppressWarnings("all") String getFoo() { + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") String getFoo() { return this.foo; } } @@ -48,7 +48,7 @@ class Getter5 { String isFoo() { return null; } - public @java.lang.SuppressWarnings("all") String getFoo() { + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") String getFoo() { return this.foo; } } @@ -69,7 +69,7 @@ class Getter7 { boolean hasFoo() { return false; } - public @java.lang.SuppressWarnings("all") String getFoo() { + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") String getFoo() { return this.foo; } } @@ -81,7 +81,7 @@ class Getter8 { boolean isFoo() { return false; } - public @java.lang.SuppressWarnings("all") String getFoo() { + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") String getFoo() { return this.foo; } } @@ -102,7 +102,7 @@ class Getter10 { static boolean hasFoo() { return false; } - public @java.lang.SuppressWarnings("all") boolean isFoo() { + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") boolean isFoo() { return this.foo; } } @@ -132,7 +132,7 @@ class Getter13 { static boolean hasFoo() { return false; } - public @java.lang.SuppressWarnings("all") String getFoo() { + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") String getFoo() { return this.foo; } } @@ -144,7 +144,7 @@ class Getter14 { static boolean isFoo() { return false; } - public @java.lang.SuppressWarnings("all") String getFoo() { + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") String getFoo() { return this.foo; } } @@ -165,7 +165,7 @@ class Getter16 { static String hasFoo() { return ""; } - public @java.lang.SuppressWarnings("all") String getFoo() { + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") String getFoo() { return this.foo; } } @@ -177,7 +177,7 @@ class Getter17 { static String isFoo() { return ""; } - public @java.lang.SuppressWarnings("all") String getFoo() { + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") String getFoo() { return this.foo; } } diff --git a/test/transform/resource/after-ecj/GetterBoolean.java b/test/transform/resource/after-ecj/GetterBoolean.java index a7dc2e2f..a1d1446e 100644 --- a/test/transform/resource/after-ecj/GetterBoolean.java +++ b/test/transform/resource/after-ecj/GetterBoolean.java @@ -5,13 +5,13 @@ class Getter { Getter() { super(); } - public @java.lang.SuppressWarnings("all") boolean isFoo() { + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") boolean isFoo() { return this.foo; } - public @java.lang.SuppressWarnings("all") boolean isBar() { + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") boolean isBar() { return this.isBar; } - public @java.lang.SuppressWarnings("all") boolean isHasBaz() { + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") boolean isHasBaz() { return this.hasBaz; } } @@ -23,7 +23,7 @@ class MoreGetter { boolean hasFoo() { return true; } - public @java.lang.SuppressWarnings("all") boolean isFoo() { + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") boolean isFoo() { return this.foo; } } diff --git a/test/transform/resource/after-ecj/GetterDeprecated.java b/test/transform/resource/after-ecj/GetterDeprecated.java index 546f7fb7..fc7ce561 100644 --- a/test/transform/resource/after-ecj/GetterDeprecated.java +++ b/test/transform/resource/after-ecj/GetterDeprecated.java @@ -5,10 +5,10 @@ class GetterDeprecated { GetterDeprecated() { super(); } - public @java.lang.Deprecated @java.lang.SuppressWarnings("all") int getAnnotation() { + public @java.lang.Deprecated @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") int getAnnotation() { return this.annotation; } - public @java.lang.Deprecated @java.lang.SuppressWarnings("all") int getJavadoc() { + public @java.lang.Deprecated @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") int getJavadoc() { return this.javadoc; } } diff --git a/test/transform/resource/after-ecj/GetterEnum.java b/test/transform/resource/after-ecj/GetterEnum.java index fd70ce9e..22a5b0fd 100644 --- a/test/transform/resource/after-ecj/GetterEnum.java +++ b/test/transform/resource/after-ecj/GetterEnum.java @@ -7,13 +7,13 @@ import lombok.RequiredArgsConstructor; private final @Getter String name; <clinit>() { } - public @java.lang.SuppressWarnings("all") int getId() { + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") int getId() { return this.id; } - public @java.lang.SuppressWarnings("all") String getName() { + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") String getName() { return this.name; } - private @java.lang.SuppressWarnings("all") GetterEnum(final int id, final String name) { + private @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") GetterEnum(final int id, final String name) { super(); this.id = id; this.name = name; diff --git a/test/transform/resource/after-ecj/GetterLazy.java b/test/transform/resource/after-ecj/GetterLazy.java index 8394f58d..d1ec507c 100644 --- a/test/transform/resource/after-ecj/GetterLazy.java +++ b/test/transform/resource/after-ecj/GetterLazy.java @@ -8,7 +8,7 @@ class GetterLazy { GetterLazy() { super(); } - public @java.lang.SuppressWarnings("all") ValueType getFieldName() { + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") ValueType getFieldName() { java.lang.Object value = this.fieldName.get(); if ((value == null)) { diff --git a/test/transform/resource/after-ecj/GetterLazyBoolean.java b/test/transform/resource/after-ecj/GetterLazyBoolean.java index cd5bac20..0a1d2564 100644 --- a/test/transform/resource/after-ecj/GetterLazyBoolean.java +++ b/test/transform/resource/after-ecj/GetterLazyBoolean.java @@ -7,7 +7,7 @@ private static boolean calculateBoolean() { return true; } - public @java.lang.SuppressWarnings("all") boolean isBooleanValue() { + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") boolean isBooleanValue() { java.lang.Object value = this.booleanValue.get(); if ((value == null)) { @@ -24,7 +24,7 @@ } return (java.lang.Boolean) value; } - public @java.lang.SuppressWarnings("all") boolean isOtherBooleanValue() { + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") boolean isOtherBooleanValue() { java.lang.Object value = this.otherBooleanValue.get(); if ((value == null)) { @@ -41,28 +41,28 @@ } return (java.lang.Boolean) value; } - public @java.lang.Override @java.lang.SuppressWarnings("all") boolean equals(final java.lang.Object o) { + public @java.lang.Override @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") boolean equals(final java.lang.Object o) { if ((o == this)) return true; if ((! (o instanceof GetterLazyBoolean))) return false; - final @java.lang.SuppressWarnings("all") GetterLazyBoolean other = (GetterLazyBoolean) o; + final GetterLazyBoolean other = (GetterLazyBoolean) o; if ((! other.canEqual((java.lang.Object) this))) return false; if ((this.isBooleanValue() != other.isBooleanValue())) return false; return true; } - protected @java.lang.SuppressWarnings("all") boolean canEqual(final java.lang.Object other) { + protected @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") boolean canEqual(final java.lang.Object other) { return (other instanceof GetterLazyBoolean); } - public @java.lang.Override @java.lang.SuppressWarnings("all") int hashCode() { + public @java.lang.Override @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") int hashCode() { final int PRIME = 59; int result = 1; result = ((result * PRIME) + (this.isBooleanValue() ? 79 : 97)); return result; } - public @java.lang.Override @java.lang.SuppressWarnings("all") java.lang.String toString() { + public @java.lang.Override @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") java.lang.String toString() { return (("GetterLazyBoolean(booleanValue=" + this.isBooleanValue()) + ")"); } } diff --git a/test/transform/resource/after-ecj/GetterLazyEahcToString.java b/test/transform/resource/after-ecj/GetterLazyEahcToString.java index df26f912..f0cb2ec2 100644 --- a/test/transform/resource/after-ecj/GetterLazyEahcToString.java +++ b/test/transform/resource/after-ecj/GetterLazyEahcToString.java @@ -4,7 +4,7 @@ GetterLazyEahcToString() { super(); } - public @java.lang.SuppressWarnings("all") String getValue() { + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") String getValue() { java.lang.Object value = this.value.get(); if ((value == null)) { @@ -21,15 +21,15 @@ } return (String) ((value == this.value) ? null : value); } - public @java.lang.SuppressWarnings("all") String getValue2() { + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") String getValue2() { return this.value2; } - public @java.lang.Override @java.lang.SuppressWarnings("all") boolean equals(final java.lang.Object o) { + public @java.lang.Override @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") boolean equals(final java.lang.Object o) { if ((o == this)) return true; if ((! (o instanceof GetterLazyEahcToString))) return false; - final @java.lang.SuppressWarnings("all") GetterLazyEahcToString other = (GetterLazyEahcToString) o; + final GetterLazyEahcToString other = (GetterLazyEahcToString) o; if ((! other.canEqual((java.lang.Object) this))) return false; final java.lang.Object this$value = this.getValue(); @@ -42,10 +42,10 @@ return false; return true; } - protected @java.lang.SuppressWarnings("all") boolean canEqual(final java.lang.Object other) { + protected @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") boolean canEqual(final java.lang.Object other) { return (other instanceof GetterLazyEahcToString); } - public @java.lang.Override @java.lang.SuppressWarnings("all") int hashCode() { + public @java.lang.Override @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") int hashCode() { final int PRIME = 59; int result = 1; final java.lang.Object $value = this.getValue(); @@ -54,7 +54,7 @@ result = ((result * PRIME) + (($value2 == null) ? 0 : $value2.hashCode())); return result; } - public @java.lang.Override @java.lang.SuppressWarnings("all") java.lang.String toString() { + public @java.lang.Override @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") java.lang.String toString() { return (((("GetterLazyEahcToString(value=" + this.getValue()) + ", value2=") + this.value2) + ")"); } } diff --git a/test/transform/resource/after-ecj/GetterLazyInvalid.java b/test/transform/resource/after-ecj/GetterLazyInvalid.java index da89c333..8e2bc4f3 100644 --- a/test/transform/resource/after-ecj/GetterLazyInvalid.java +++ b/test/transform/resource/after-ecj/GetterLazyInvalid.java @@ -27,7 +27,7 @@ class GetterLazyInvalidNone { GetterLazyInvalidClass() { super(); } - public @java.lang.SuppressWarnings("all") String getFieldName() { + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") String getFieldName() { return this.fieldName; } } diff --git a/test/transform/resource/after-ecj/GetterLazyNative.java b/test/transform/resource/after-ecj/GetterLazyNative.java index db70f2f4..40fe1c84 100644 --- a/test/transform/resource/after-ecj/GetterLazyNative.java +++ b/test/transform/resource/after-ecj/GetterLazyNative.java @@ -11,7 +11,7 @@ class GetterLazyNative { GetterLazyNative() { super(); } - public @java.lang.SuppressWarnings("all") boolean isBooleanField() { + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") boolean isBooleanField() { java.lang.Object value = this.booleanField.get(); if ((value == null)) { @@ -28,7 +28,7 @@ class GetterLazyNative { } return (java.lang.Boolean) value; } - public @java.lang.SuppressWarnings("all") byte getByteField() { + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") byte getByteField() { java.lang.Object value = this.byteField.get(); if ((value == null)) { @@ -45,7 +45,7 @@ class GetterLazyNative { } return (java.lang.Byte) value; } - public @java.lang.SuppressWarnings("all") short getShortField() { + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") short getShortField() { java.lang.Object value = this.shortField.get(); if ((value == null)) { @@ -62,7 +62,7 @@ class GetterLazyNative { } return (java.lang.Short) value; } - public @java.lang.SuppressWarnings("all") int getIntField() { + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") int getIntField() { java.lang.Object value = this.intField.get(); if ((value == null)) { @@ -79,7 +79,7 @@ class GetterLazyNative { } return (java.lang.Integer) value; } - public @java.lang.SuppressWarnings("all") long getLongField() { + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") long getLongField() { java.lang.Object value = this.longField.get(); if ((value == null)) { @@ -96,7 +96,7 @@ class GetterLazyNative { } return (java.lang.Long) value; } - public @java.lang.SuppressWarnings("all") float getFloatField() { + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") float getFloatField() { java.lang.Object value = this.floatField.get(); if ((value == null)) { @@ -113,7 +113,7 @@ class GetterLazyNative { } return (java.lang.Float) value; } - public @java.lang.SuppressWarnings("all") double getDoubleField() { + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") double getDoubleField() { java.lang.Object value = this.doubleField.get(); if ((value == null)) { @@ -130,7 +130,7 @@ class GetterLazyNative { } return (java.lang.Double) value; } - public @java.lang.SuppressWarnings("all") char getCharField() { + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") char getCharField() { java.lang.Object value = this.charField.get(); if ((value == null)) { @@ -147,7 +147,7 @@ class GetterLazyNative { } return (java.lang.Character) value; } - public @java.lang.SuppressWarnings("all") int[] getIntArrayField() { + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") int[] getIntArrayField() { java.lang.Object value = this.intArrayField.get(); if ((value == null)) { diff --git a/test/transform/resource/after-ecj/GetterNone.java b/test/transform/resource/after-ecj/GetterNone.java index f08726d0..e13379e0 100644 --- a/test/transform/resource/after-ecj/GetterNone.java +++ b/test/transform/resource/after-ecj/GetterNone.java @@ -6,7 +6,7 @@ import lombok.Getter; GetterNone() { super(); } - public @java.lang.SuppressWarnings("all") int getI() { + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") int getI() { return this.i; } } diff --git a/test/transform/resource/after-ecj/GetterOnClass.java b/test/transform/resource/after-ecj/GetterOnClass.java index 7668c9d3..deb56392 100644 --- a/test/transform/resource/after-ecj/GetterOnClass.java +++ b/test/transform/resource/after-ecj/GetterOnClass.java @@ -4,7 +4,7 @@ GetterOnClass1() { super(); } - public @java.lang.SuppressWarnings("all") boolean isPublic() { + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") boolean isPublic() { return this.isPublic; } } @@ -15,10 +15,10 @@ GetterOnClass2() { super(); } - @java.lang.SuppressWarnings("all") boolean isPackage() { + @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") boolean isPackage() { return this.isPackage; } - protected @java.lang.SuppressWarnings("all") boolean isProtected() { + protected @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") boolean isProtected() { return this.isProtected; } } @@ -28,7 +28,7 @@ GetterOnClass3() { super(); } - @java.lang.SuppressWarnings("all") boolean isPackage() { + @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") boolean isPackage() { return this.isPackage; } } @@ -38,7 +38,7 @@ GetterOnClass4() { super(); } - private @java.lang.SuppressWarnings("all") boolean isPrivate() { + private @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") boolean isPrivate() { return this.isPrivate; } } @@ -48,7 +48,7 @@ GetterOnClass5() { super(); } - public @java.lang.SuppressWarnings("all") boolean isPublic() { + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") boolean isPublic() { return this.isPublic; } } @@ -58,10 +58,10 @@ GetterOnClass6() { super(); } - public @java.lang.SuppressWarnings("all") String getCouldBeNull() { + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") String getCouldBeNull() { return this.couldBeNull; } - public @lombok.NonNull @java.lang.SuppressWarnings("all") String getNonNull() { + public @lombok.NonNull @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") String getNonNull() { return this.nonNull; } } diff --git a/test/transform/resource/after-ecj/GetterOnMethod.java b/test/transform/resource/after-ecj/GetterOnMethod.java index a21f628c..6b227326 100644 --- a/test/transform/resource/after-ecj/GetterOnMethod.java +++ b/test/transform/resource/after-ecj/GetterOnMethod.java @@ -7,13 +7,13 @@ class GetterOnMethod { GetterOnMethod() { super(); } - public @Deprecated @java.lang.SuppressWarnings("all") int getI() { + public @Deprecated @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") int getI() { return this.i; } - public @java.lang.Deprecated @Test @java.lang.SuppressWarnings("all") int getJ() { + public @java.lang.Deprecated @Test @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") int getJ() { return this.j; } - public @java.lang.Deprecated @Test @java.lang.SuppressWarnings("all") int getK() { + public @java.lang.Deprecated @Test @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") int getK() { return this.k; } } diff --git a/test/transform/resource/after-ecj/GetterOnMethodErrors.java b/test/transform/resource/after-ecj/GetterOnMethodErrors.java index 16c625b5..7ba02422 100644 --- a/test/transform/resource/after-ecj/GetterOnMethodErrors.java +++ b/test/transform/resource/after-ecj/GetterOnMethodErrors.java @@ -8,7 +8,7 @@ class PlaceFillerToMakeSurePositionIsRelevant { GetterOnMethodErrors() { super(); } - public @java.lang.SuppressWarnings("all") int getTest() { + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") int getTest() { return this.test; } }
\ No newline at end of file diff --git a/test/transform/resource/after-ecj/GetterOnMethodErrors2.java b/test/transform/resource/after-ecj/GetterOnMethodErrors2.java index bfaa5dd4..0dfd4c13 100644 --- a/test/transform/resource/after-ecj/GetterOnMethodErrors2.java +++ b/test/transform/resource/after-ecj/GetterOnMethodErrors2.java @@ -12,28 +12,28 @@ class GetterOnMethodErrors2 { GetterOnMethodErrors2() { super(); } - public @java.lang.SuppressWarnings("all") int getBad1() { + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") int getBad1() { return this.bad1; } - public @java.lang.SuppressWarnings("all") int getBad2() { + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") int getBad2() { return this.bad2; } - public @java.lang.SuppressWarnings("all") int getBad3() { + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") int getBad3() { return this.bad3; } - public @java.lang.SuppressWarnings("all") int getBad4() { + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") int getBad4() { return this.bad4; } - public @java.lang.SuppressWarnings("all") int getGood1() { + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") int getGood1() { return this.good1; } - public @java.lang.SuppressWarnings("all") int getGood2() { + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") int getGood2() { return this.good2; } - public @Deprecated @java.lang.SuppressWarnings("all") int getGood3() { + public @Deprecated @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") int getGood3() { return this.good3; } - public @Deprecated @Test @java.lang.SuppressWarnings("all") int getGood4() { + public @Deprecated @Test @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") int getGood4() { return this.good4; } }
\ No newline at end of file diff --git a/test/transform/resource/after-ecj/GetterOnStatic.java b/test/transform/resource/after-ecj/GetterOnStatic.java index ee90b897..89b83ed0 100644 --- a/test/transform/resource/after-ecj/GetterOnStatic.java +++ b/test/transform/resource/after-ecj/GetterOnStatic.java @@ -6,10 +6,10 @@ class Getter { Getter() { super(); } - public static @java.lang.SuppressWarnings("all") boolean isFoo() { + public static @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") boolean isFoo() { return Getter.foo; } - public static @java.lang.SuppressWarnings("all") int getBar() { + public static @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") int getBar() { return Getter.bar; } } diff --git a/test/transform/resource/after-ecj/GetterPlain.java b/test/transform/resource/after-ecj/GetterPlain.java index 10f0f9d7..d3801b62 100644 --- a/test/transform/resource/after-ecj/GetterPlain.java +++ b/test/transform/resource/after-ecj/GetterPlain.java @@ -5,10 +5,10 @@ class GetterPlain { GetterPlain() { super(); } - public @java.lang.SuppressWarnings("all") int getI() { + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") int getI() { return this.i; } - public @java.lang.SuppressWarnings("all") int getFoo() { + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") int getFoo() { return this.foo; } } diff --git a/test/transform/resource/after-ecj/GetterSetterJavadoc.java b/test/transform/resource/after-ecj/GetterSetterJavadoc.java index 9f3bb9bd..21841d47 100644 --- a/test/transform/resource/after-ecj/GetterSetterJavadoc.java +++ b/test/transform/resource/after-ecj/GetterSetterJavadoc.java @@ -1,36 +1,36 @@ @lombok.Data class GetterSetterJavadoc1 { private int fieldName; - public @java.lang.SuppressWarnings("all") int getFieldName() { + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") int getFieldName() { return this.fieldName; } - public @java.lang.SuppressWarnings("all") void setFieldName(final int fieldName) { + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") void setFieldName(final int fieldName) { this.fieldName = fieldName; } - public @java.lang.Override @java.lang.SuppressWarnings("all") boolean equals(final java.lang.Object o) { + public @java.lang.Override @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") boolean equals(final java.lang.Object o) { if ((o == this)) return true; if ((! (o instanceof GetterSetterJavadoc1))) return false; - final @java.lang.SuppressWarnings("all") GetterSetterJavadoc1 other = (GetterSetterJavadoc1) o; + final GetterSetterJavadoc1 other = (GetterSetterJavadoc1) o; if ((! other.canEqual((java.lang.Object) this))) return false; if ((this.getFieldName() != other.getFieldName())) return false; return true; } - protected @java.lang.SuppressWarnings("all") boolean canEqual(final java.lang.Object other) { + protected @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") boolean canEqual(final java.lang.Object other) { return (other instanceof GetterSetterJavadoc1); } - public @java.lang.Override @java.lang.SuppressWarnings("all") int hashCode() { + public @java.lang.Override @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") int hashCode() { final int PRIME = 59; int result = 1; result = ((result * PRIME) + this.getFieldName()); return result; } - public @java.lang.Override @java.lang.SuppressWarnings("all") java.lang.String toString() { + public @java.lang.Override @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") java.lang.String toString() { return (("GetterSetterJavadoc1(fieldName=" + this.getFieldName()) + ")"); } - public @java.lang.SuppressWarnings("all") GetterSetterJavadoc1() { + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") GetterSetterJavadoc1() { super(); } } @@ -39,10 +39,10 @@ class GetterSetterJavadoc2 { GetterSetterJavadoc2() { super(); } - public @java.lang.SuppressWarnings("all") int getFieldName() { + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") int getFieldName() { return this.fieldName; } - public @java.lang.SuppressWarnings("all") void setFieldName(final int fieldName) { + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") void setFieldName(final int fieldName) { this.fieldName = fieldName; } } @@ -51,10 +51,10 @@ class GetterSetterJavadoc3 { GetterSetterJavadoc3() { super(); } - public @java.lang.SuppressWarnings("all") int getFieldName() { + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") int getFieldName() { return this.fieldName; } - public @java.lang.SuppressWarnings("all") void setFieldName(final int fieldName) { + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") void setFieldName(final int fieldName) { this.fieldName = fieldName; } }
\ No newline at end of file diff --git a/test/transform/resource/after-ecj/GetterWithDollar.java b/test/transform/resource/after-ecj/GetterWithDollar.java index f4bc799c..424635ed 100644 --- a/test/transform/resource/after-ecj/GetterWithDollar.java +++ b/test/transform/resource/after-ecj/GetterWithDollar.java @@ -3,7 +3,7 @@ class GetterWithDollar1 { GetterWithDollar1() { super(); } - public @java.lang.SuppressWarnings("all") int get$i() { + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") int get$i() { return this.$i; } } @@ -13,10 +13,10 @@ class GetterWithDollar2 { GetterWithDollar2() { super(); } - public @java.lang.SuppressWarnings("all") int get$i() { + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") int get$i() { return this.$i; } - public @java.lang.SuppressWarnings("all") int getI() { + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") int getI() { return this.i; } } diff --git a/test/transform/resource/after-ecj/MixGetterVal.java b/test/transform/resource/after-ecj/MixGetterVal.java index d9809703..fbc89a02 100644 --- a/test/transform/resource/after-ecj/MixGetterVal.java +++ b/test/transform/resource/after-ecj/MixGetterVal.java @@ -13,7 +13,7 @@ class MixGetterVal { final @val int a = getX(); m(a); } - public @java.lang.SuppressWarnings("all") int getX() { + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") int getX() { return this.x; } }
\ No newline at end of file diff --git a/test/transform/resource/after-ecj/MultiFieldGetter.java b/test/transform/resource/after-ecj/MultiFieldGetter.java index 151c61c8..a608578e 100644 --- a/test/transform/resource/after-ecj/MultiFieldGetter.java +++ b/test/transform/resource/after-ecj/MultiFieldGetter.java @@ -6,10 +6,10 @@ class MultiFieldGetter { MultiFieldGetter() { super(); } - protected @java.lang.SuppressWarnings("all") int getX() { + protected @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") int getX() { return this.x; } - protected @java.lang.SuppressWarnings("all") int getY() { + protected @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") int getY() { return this.y; } } @@ -19,10 +19,10 @@ class MultiFieldGetter { MultiFieldGetter2() { super(); } - @java.lang.SuppressWarnings("all") int getX() { + @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") int getX() { return this.x; } - @java.lang.SuppressWarnings("all") int getY() { + @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") int getY() { return this.y; } } diff --git a/test/transform/resource/after-ecj/NonNullPlain.java b/test/transform/resource/after-ecj/NonNullPlain.java index 6e937f6a..592ff4b5 100644 --- a/test/transform/resource/after-ecj/NonNullPlain.java +++ b/test/transform/resource/after-ecj/NonNullPlain.java @@ -5,7 +5,7 @@ import java.lang.annotation.*; @lombok.NonNull int i; @lombok.NonNull String s; @NotNull Object o; - public @java.beans.ConstructorProperties({"i", "s"}) @java.lang.SuppressWarnings("all") NonNullPlain(final @lombok.NonNull int i, final @lombok.NonNull String s) { + public @java.beans.ConstructorProperties({"i", "s"}) @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") NonNullPlain(final @lombok.NonNull int i, final @lombok.NonNull String s) { super(); if ((s == null)) { @@ -14,26 +14,26 @@ import java.lang.annotation.*; this.i = i; this.s = s; } - public @lombok.NonNull @java.lang.SuppressWarnings("all") int getI() { + public @lombok.NonNull @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") int getI() { return this.i; } - public @lombok.NonNull @java.lang.SuppressWarnings("all") String getS() { + public @lombok.NonNull @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") String getS() { return this.s; } - public @java.lang.SuppressWarnings("all") Object getO() { + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") Object getO() { return this.o; } - public @java.lang.SuppressWarnings("all") void setI(final @lombok.NonNull int i) { + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") void setI(final @lombok.NonNull int i) { this.i = i; } - public @java.lang.SuppressWarnings("all") void setS(final @lombok.NonNull String s) { + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") void setS(final @lombok.NonNull String s) { if ((s == null)) { throw new java.lang.NullPointerException("s"); } this.s = s; } - public @java.lang.SuppressWarnings("all") void setO(final Object o) { + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") void setO(final Object o) { this.o = o; } }
\ No newline at end of file diff --git a/test/transform/resource/after-ecj/NonNullWithAlternateException.java b/test/transform/resource/after-ecj/NonNullWithAlternateException.java index 8a547ecf..1df18538 100644 --- a/test/transform/resource/after-ecj/NonNullWithAlternateException.java +++ b/test/transform/resource/after-ecj/NonNullWithAlternateException.java @@ -10,7 +10,7 @@ public class NonNullWithAlternateException { } System.out.println(arg); } - public @java.lang.SuppressWarnings("all") void setTest(final @lombok.NonNull String test) { + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") void setTest(final @lombok.NonNull String test) { if ((test == null)) { throw new java.lang.IllegalArgumentException("test is null"); diff --git a/test/transform/resource/after-ecj/SetterAccessLevel.java b/test/transform/resource/after-ecj/SetterAccessLevel.java index 4c1a0b97..db26226f 100644 --- a/test/transform/resource/after-ecj/SetterAccessLevel.java +++ b/test/transform/resource/after-ecj/SetterAccessLevel.java @@ -8,19 +8,19 @@ class SetterAccessLevel { SetterAccessLevel() { super(); } - private @java.lang.SuppressWarnings("all") void setPrivate(final boolean isPrivate) { + private @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") void setPrivate(final boolean isPrivate) { this.isPrivate = isPrivate; } - @java.lang.SuppressWarnings("all") void setPackage(final boolean isPackage) { + @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") void setPackage(final boolean isPackage) { this.isPackage = isPackage; } - protected @java.lang.SuppressWarnings("all") void setProtected(final boolean isProtected) { + protected @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") void setProtected(final boolean isProtected) { this.isProtected = isProtected; } - public @java.lang.SuppressWarnings("all") void setPublic(final boolean isPublic) { + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") void setPublic(final boolean isPublic) { this.isPublic = isPublic; } - public @java.lang.SuppressWarnings("all") void setValue(final boolean value) { + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") void setValue(final boolean value) { this.value = value; } } diff --git a/test/transform/resource/after-ecj/SetterAlreadyExists.java b/test/transform/resource/after-ecj/SetterAlreadyExists.java index 91b011b6..4a4d0c4c 100644 --- a/test/transform/resource/after-ecj/SetterAlreadyExists.java +++ b/test/transform/resource/after-ecj/SetterAlreadyExists.java @@ -37,7 +37,7 @@ class Setter5 { } void setFoo() { } - public @java.lang.SuppressWarnings("all") void setFoo(final String foo) { + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") void setFoo(final String foo) { this.foo = foo; } } @@ -48,7 +48,7 @@ class Setter6 { } void setFoo(String foo, int x) { } - public @java.lang.SuppressWarnings("all") void setFoo(final String foo) { + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") void setFoo(final String foo) { this.foo = foo; } } diff --git a/test/transform/resource/after-ecj/SetterDeprecated.java b/test/transform/resource/after-ecj/SetterDeprecated.java index d76612b7..91008c96 100644 --- a/test/transform/resource/after-ecj/SetterDeprecated.java +++ b/test/transform/resource/after-ecj/SetterDeprecated.java @@ -5,10 +5,10 @@ class SetterDeprecated { SetterDeprecated() { super(); } - public @java.lang.Deprecated @java.lang.SuppressWarnings("all") void setAnnotation(final int annotation) { + public @java.lang.Deprecated @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") void setAnnotation(final int annotation) { this.annotation = annotation; } - public @java.lang.Deprecated @java.lang.SuppressWarnings("all") void setJavadoc(final int javadoc) { + public @java.lang.Deprecated @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") void setJavadoc(final int javadoc) { this.javadoc = javadoc; } } diff --git a/test/transform/resource/after-ecj/SetterOnClass.java b/test/transform/resource/after-ecj/SetterOnClass.java index aa3459bb..8e6455d3 100644 --- a/test/transform/resource/after-ecj/SetterOnClass.java +++ b/test/transform/resource/after-ecj/SetterOnClass.java @@ -4,7 +4,7 @@ SetterOnClass1() { super(); } - public @java.lang.SuppressWarnings("all") void setPublic(final boolean isPublic) { + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") void setPublic(final boolean isPublic) { this.isPublic = isPublic; } } @@ -15,10 +15,10 @@ SetterOnClass2() { super(); } - @java.lang.SuppressWarnings("all") void setPackage(final boolean isPackage) { + @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") void setPackage(final boolean isPackage) { this.isPackage = isPackage; } - protected @java.lang.SuppressWarnings("all") void setProtected(final boolean isProtected) { + protected @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") void setProtected(final boolean isProtected) { this.isProtected = isProtected; } } @@ -28,7 +28,7 @@ SetterOnClass3() { super(); } - @java.lang.SuppressWarnings("all") void setPackage(final boolean isPackage) { + @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") void setPackage(final boolean isPackage) { this.isPackage = isPackage; } } @@ -38,7 +38,7 @@ SetterOnClass4() { super(); } - private @java.lang.SuppressWarnings("all") void setPrivate(final boolean isPrivate) { + private @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") void setPrivate(final boolean isPrivate) { this.isPrivate = isPrivate; } } @@ -48,7 +48,7 @@ SetterOnClass5() { super(); } - public @java.lang.SuppressWarnings("all") void setPublic(final boolean isPublic) { + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") void setPublic(final boolean isPublic) { this.isPublic = isPublic; } } @@ -58,10 +58,10 @@ SetterOnClass6() { super(); } - public @java.lang.SuppressWarnings("all") void setCouldBeNull(final String couldBeNull) { + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") void setCouldBeNull(final String couldBeNull) { this.couldBeNull = couldBeNull; } - public @java.lang.SuppressWarnings("all") void setNonNull(final @lombok.NonNull String nonNull) { + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") void setNonNull(final @lombok.NonNull String nonNull) { if ((nonNull == null)) { throw new java.lang.NullPointerException("nonNull"); diff --git a/test/transform/resource/after-ecj/SetterOnMethod.java b/test/transform/resource/after-ecj/SetterOnMethod.java index 8bdff212..4eaea8e5 100644 --- a/test/transform/resource/after-ecj/SetterOnMethod.java +++ b/test/transform/resource/after-ecj/SetterOnMethod.java @@ -2,10 +2,10 @@ import lombok.Setter; class SetterOnMethod { @lombok.Setter() int i; @lombok.Setter() int j; - public @Deprecated @java.lang.SuppressWarnings("all") void setI(final int i) { + public @Deprecated @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") void setI(final int i) { this.i = i; } - public @java.lang.Deprecated @java.lang.SuppressWarnings("all") void setJ(final int j) { + public @java.lang.Deprecated @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") void setJ(final int j) { this.j = j; } SetterOnMethod() { @@ -15,10 +15,10 @@ class SetterOnMethod { @lombok.Setter() class SetterOnClassOnMethod { int i; int j; - public @java.lang.SuppressWarnings("all") void setI(final int i) { + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") void setI(final int i) { this.i = i; } - public @java.lang.SuppressWarnings("all") void setJ(final int j) { + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") void setJ(final int j) { this.j = j; } SetterOnClassOnMethod() { @@ -28,10 +28,10 @@ class SetterOnMethod { @lombok.Setter() class SetterOnClassAndOnAField { int i; @lombok.Setter() int j; - public @java.lang.Deprecated @java.lang.SuppressWarnings("all") void setJ(final int j) { + public @java.lang.Deprecated @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") void setJ(final int j) { this.j = j; } - public @java.lang.SuppressWarnings("all") void setI(final int i) { + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") void setI(final int i) { this.i = i; } SetterOnClassAndOnAField() { diff --git a/test/transform/resource/after-ecj/SetterOnMethodOnParam.java b/test/transform/resource/after-ecj/SetterOnMethodOnParam.java index d4ea9f5d..28799f42 100644 --- a/test/transform/resource/after-ecj/SetterOnMethodOnParam.java +++ b/test/transform/resource/after-ecj/SetterOnMethodOnParam.java @@ -7,13 +7,13 @@ class SetterOnMethodOnParam { SetterOnMethodOnParam() { super(); } - public @Deprecated @java.lang.SuppressWarnings("all") void setI(final int i) { + public @Deprecated @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") void setI(final int i) { this.i = i; } - public @java.lang.Deprecated @Test @java.lang.SuppressWarnings("all") void setJ(final @Test int j) { + public @java.lang.Deprecated @Test @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") void setJ(final @Test int j) { this.j = j; } - public @java.lang.Deprecated @Test @java.lang.SuppressWarnings("all") void setK(final @Test int k) { + public @java.lang.Deprecated @Test @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") void setK(final @Test int k) { this.k = k; } }
\ No newline at end of file diff --git a/test/transform/resource/after-ecj/SetterOnParam.java b/test/transform/resource/after-ecj/SetterOnParam.java index 119c8fc3..7c2d1fc6 100644 --- a/test/transform/resource/after-ecj/SetterOnParam.java +++ b/test/transform/resource/after-ecj/SetterOnParam.java @@ -2,10 +2,10 @@ import lombok.Setter; class SetterOnParam { @lombok.Setter() int i; @lombok.Setter() int j; - public @java.lang.SuppressWarnings("all") void setI(final @SuppressWarnings("all") int i) { + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") void setI(final @SuppressWarnings("all") int i) { this.i = i; } - public @java.lang.SuppressWarnings("all") void setJ(final @java.lang.SuppressWarnings("all") int j) { + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") void setJ(final @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") int j) { this.j = j; } SetterOnParam() { @@ -15,10 +15,10 @@ class SetterOnParam { @lombok.Setter() class SetterOnClassOnParam { int i; int j; - public @java.lang.SuppressWarnings("all") void setI(final int i) { + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") void setI(final int i) { this.i = i; } - public @java.lang.SuppressWarnings("all") void setJ(final int j) { + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") void setJ(final int j) { this.j = j; } SetterOnClassOnParam() { @@ -28,10 +28,10 @@ class SetterOnParam { @lombok.Setter() class SetterOnClassAndOnAFieldParam { int i; @lombok.Setter() int j; - public @java.lang.SuppressWarnings("all") void setJ(final @java.lang.SuppressWarnings("all") int j) { + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") void setJ(final @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") int j) { this.j = j; } - public @java.lang.SuppressWarnings("all") void setI(final int i) { + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") void setI(final int i) { this.i = i; } SetterOnClassAndOnAFieldParam() { diff --git a/test/transform/resource/after-ecj/SetterOnParamAndOnMethod.java b/test/transform/resource/after-ecj/SetterOnParamAndOnMethod.java index 21d22a8f..011b2241 100644 --- a/test/transform/resource/after-ecj/SetterOnParamAndOnMethod.java +++ b/test/transform/resource/after-ecj/SetterOnParamAndOnMethod.java @@ -1,6 +1,6 @@ class SetterOnParamAndOnMethod { @lombok.Setter() int i; - public @Deprecated @java.lang.SuppressWarnings("all") void setI(final @SuppressWarnings("all") int i) { + public @Deprecated @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") void setI(final @SuppressWarnings("all") int i) { this.i = i; } SetterOnParamAndOnMethod() { diff --git a/test/transform/resource/after-ecj/SetterOnStatic.java b/test/transform/resource/after-ecj/SetterOnStatic.java index 8a5abdd8..1c5b71ae 100644 --- a/test/transform/resource/after-ecj/SetterOnStatic.java +++ b/test/transform/resource/after-ecj/SetterOnStatic.java @@ -6,10 +6,10 @@ class Setter { Setter() { super(); } - public static @java.lang.SuppressWarnings("all") void setFoo(final boolean foo) { + public static @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") void setFoo(final boolean foo) { Setter.foo = foo; } - public static @java.lang.SuppressWarnings("all") void setBar(final int bar) { + public static @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") void setBar(final int bar) { Setter.bar = bar; } } diff --git a/test/transform/resource/after-ecj/SetterPlain.java b/test/transform/resource/after-ecj/SetterPlain.java index a4b40295..4f428f0b 100644 --- a/test/transform/resource/after-ecj/SetterPlain.java +++ b/test/transform/resource/after-ecj/SetterPlain.java @@ -5,10 +5,10 @@ class SetterPlain { SetterPlain() { super(); } - public @java.lang.SuppressWarnings("all") void setI(final int i) { + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") void setI(final int i) { this.i = i; } - public @java.lang.SuppressWarnings("all") void setFoo(final int foo) { + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") void setFoo(final int foo) { this.foo = foo; } } diff --git a/test/transform/resource/after-ecj/SetterWithDollar.java b/test/transform/resource/after-ecj/SetterWithDollar.java index c5bc14f1..e8bd91df 100644 --- a/test/transform/resource/after-ecj/SetterWithDollar.java +++ b/test/transform/resource/after-ecj/SetterWithDollar.java @@ -3,7 +3,7 @@ class SetterWithDollar1 { SetterWithDollar1() { super(); } - public @java.lang.SuppressWarnings("all") void set$i(final int $i) { + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") void set$i(final int $i) { this.$i = $i; } } @@ -13,10 +13,10 @@ class SetterWithDollar2 { SetterWithDollar2() { super(); } - public @java.lang.SuppressWarnings("all") void set$i(final int $i) { + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") void set$i(final int $i) { this.$i = $i; } - public @java.lang.SuppressWarnings("all") void setI(final int i) { + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") void setI(final int i) { this.i = i; } } diff --git a/test/transform/resource/after-ecj/SimpleTypeResolution.java b/test/transform/resource/after-ecj/SimpleTypeResolution.java index c413623e..736632bc 100644 --- a/test/transform/resource/after-ecj/SimpleTypeResolution.java +++ b/test/transform/resource/after-ecj/SimpleTypeResolution.java @@ -7,7 +7,7 @@ class SimpleTypeResolutionSuccess { private @lombok.Getter int x; SimpleTypeResolutionSuccess() { } - public @java.lang.SuppressWarnings("all") int getX() { + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") int getX() { return this.x; } } diff --git a/test/transform/resource/after-ecj/ToStringConfiguration.java b/test/transform/resource/after-ecj/ToStringConfiguration.java index 8bb99146..ca36d1b4 100644 --- a/test/transform/resource/after-ecj/ToStringConfiguration.java +++ b/test/transform/resource/after-ecj/ToStringConfiguration.java @@ -5,10 +5,10 @@ import lombok.Getter; ToStringConfiguration() { super(); } - public @java.lang.Override @java.lang.SuppressWarnings("all") java.lang.String toString() { + public @java.lang.Override @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") java.lang.String toString() { return (("ToStringConfiguration(" + this.x) + ")"); } - public @java.lang.SuppressWarnings("all") int getX() { + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") int getX() { return this.x; } } @@ -17,7 +17,7 @@ import lombok.Getter; ToStringConfiguration2() { super(); } - public @java.lang.Override @java.lang.SuppressWarnings("all") java.lang.String toString() { + public @java.lang.Override @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") java.lang.String toString() { return (("ToStringConfiguration2(x=" + this.x) + ")"); } } @@ -26,10 +26,10 @@ import lombok.Getter; ToStringConfiguration3() { super(); } - public @java.lang.Override @java.lang.SuppressWarnings("all") java.lang.String toString() { + public @java.lang.Override @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") java.lang.String toString() { return (("ToStringConfiguration3(" + this.getX()) + ")"); } - public @java.lang.SuppressWarnings("all") int getX() { + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") int getX() { return this.x; } }
\ No newline at end of file diff --git a/test/transform/resource/after-ecj/ToStringInner.java b/test/transform/resource/after-ecj/ToStringInner.java index a8624823..027ccd0c 100644 --- a/test/transform/resource/after-ecj/ToStringInner.java +++ b/test/transform/resource/after-ecj/ToStringInner.java @@ -5,7 +5,7 @@ import lombok.ToString; ToStringInner() { super(); } - public @java.lang.Override @java.lang.SuppressWarnings("all") java.lang.String toString() { + public @java.lang.Override @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") java.lang.String toString() { return (("ToStringOuter.ToStringInner(y=" + this.y) + ")"); } } @@ -14,7 +14,7 @@ import lombok.ToString; ToStringStaticInner() { super(); } - public @java.lang.Override @java.lang.SuppressWarnings("all") java.lang.String toString() { + public @java.lang.Override @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") java.lang.String toString() { return (("ToStringOuter.ToStringStaticInner(y=" + this.y) + ")"); } } @@ -24,7 +24,7 @@ import lombok.ToString; ToStringMoreInner() { super(); } - public @java.lang.Override @java.lang.SuppressWarnings("all") java.lang.String toString() { + public @java.lang.Override @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") java.lang.String toString() { return (("ToStringOuter.ToStringMiddle.ToStringMoreInner(name=" + this.name) + ")"); } } @@ -37,7 +37,7 @@ import lombok.ToString; ToStringOuter() { super(); } - public @java.lang.Override @java.lang.SuppressWarnings("all") java.lang.String toString() { + public @java.lang.Override @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") java.lang.String toString() { return (((("ToStringOuter(x=" + this.x) + ", name=") + this.name) + ")"); } } diff --git a/test/transform/resource/after-ecj/ToStringPlain.java b/test/transform/resource/after-ecj/ToStringPlain.java index 7c9b47f5..939aa78e 100644 --- a/test/transform/resource/after-ecj/ToStringPlain.java +++ b/test/transform/resource/after-ecj/ToStringPlain.java @@ -5,7 +5,7 @@ import lombok.ToString; ToString1() { super(); } - public @java.lang.Override @java.lang.SuppressWarnings("all") java.lang.String toString() { + public @java.lang.Override @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") java.lang.String toString() { return (((("ToString1(x=" + this.x) + ", name=") + this.name) + ")"); } } @@ -15,7 +15,7 @@ import lombok.ToString; ToString2() { super(); } - public @java.lang.Override @java.lang.SuppressWarnings("all") java.lang.String toString() { + public @java.lang.Override @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") java.lang.String toString() { return (((("ToString2(x=" + this.x) + ", name=") + this.name) + ")"); } } diff --git a/test/transform/resource/after-ecj/Tolerate.java b/test/transform/resource/after-ecj/Tolerate.java index b5039a98..1c7b1038 100644 --- a/test/transform/resource/after-ecj/Tolerate.java +++ b/test/transform/resource/after-ecj/Tolerate.java @@ -7,10 +7,10 @@ import java.util.regex.Pattern; public @lombok.experimental.Tolerate void setPattern(String pattern) { setPattern(Pattern.compile(pattern)); } - public @java.lang.SuppressWarnings("all") void setPattern(final Pattern pattern) { + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") void setPattern(final Pattern pattern) { this.pattern = pattern; } - public @java.lang.SuppressWarnings("all") Pattern getPattern() { + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") Pattern getPattern() { return this.pattern; } } @@ -22,13 +22,13 @@ import java.util.regex.Pattern; public Tolerate2 withPattern(String nameGlob, String extensionGlob) { return withPattern(((nameGlob.replace("*", ".*") + "\\.") + extensionGlob.replace("*", ".*"))); } - public @java.lang.SuppressWarnings("all") Pattern getPattern() { + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") Pattern getPattern() { return this.pattern; } - public @java.lang.SuppressWarnings("all") Tolerate2 withPattern(final Pattern pattern) { + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") Tolerate2 withPattern(final Pattern pattern) { return ((this.pattern == pattern) ? this : new Tolerate2(pattern)); } - public @java.beans.ConstructorProperties({"pattern"}) @java.lang.SuppressWarnings("all") Tolerate2(final Pattern pattern) { + public @java.beans.ConstructorProperties({"pattern"}) @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") Tolerate2(final Pattern pattern) { super(); this.pattern = pattern; } diff --git a/test/transform/resource/after-ecj/TrickyTypeResolution.java b/test/transform/resource/after-ecj/TrickyTypeResolution.java index 4553aaba..5ea802dc 100644 --- a/test/transform/resource/after-ecj/TrickyTypeResolution.java +++ b/test/transform/resource/after-ecj/TrickyTypeResolution.java @@ -20,7 +20,7 @@ class TrickySuccess { TrickySuccess() { super(); } - public @java.lang.SuppressWarnings("all") int getX() { + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") int getX() { return this.x; } } diff --git a/test/transform/resource/after-ecj/ValAnonymousSubclassWithGenerics.java b/test/transform/resource/after-ecj/ValAnonymousSubclassWithGenerics.java new file mode 100644 index 00000000..989555fc --- /dev/null +++ b/test/transform/resource/after-ecj/ValAnonymousSubclassWithGenerics.java @@ -0,0 +1,28 @@ +import java.util.*; +import lombok.val; +public class ValAnonymousSubclassWithGenerics { + Object object = new Object() { + x() { + super(); + } + void foo() { + final @val int j = 1; + } + }; + java.util.List<String> names = new java.util.ArrayList<String>() { + x() { + super(); + } + public String get(int i) { + final @val java.lang.String result = super.get(i); + return result; + } + }; + public ValAnonymousSubclassWithGenerics() { + super(); + } + void bar() { + final @val int k = super.hashCode(); + int x = k; + } +}
\ No newline at end of file diff --git a/test/transform/resource/after-ecj/ValWithLocalClasses.java b/test/transform/resource/after-ecj/ValWithLocalClasses.java new file mode 100644 index 00000000..59880acf --- /dev/null +++ b/test/transform/resource/after-ecj/ValWithLocalClasses.java @@ -0,0 +1,20 @@ +class ValWithLocalClasses1 { + { + final @lombok.val ValWithLocalClasses2 f2 = new ValWithLocalClasses2() { + x() { + super(); + } + }; + } + ValWithLocalClasses1() { + super(); + } +} +class ValWithLocalClasses2 { + { + final @lombok.val int f3 = 0; + } + ValWithLocalClasses2() { + super(); + } +} diff --git a/test/transform/resource/after-ecj/ValueExperimental.java b/test/transform/resource/after-ecj/ValueExperimental.java index dd13574a..92deb614 100644 --- a/test/transform/resource/after-ecj/ValueExperimental.java +++ b/test/transform/resource/after-ecj/ValueExperimental.java @@ -1,39 +1,39 @@ import lombok.experimental.Value; final @Value class ValueExperimental1 { - public @java.lang.Override @java.lang.SuppressWarnings("all") boolean equals(final java.lang.Object o) { + public @java.lang.Override @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") boolean equals(final java.lang.Object o) { if ((o == this)) return true; if ((! (o instanceof ValueExperimental1))) return false; return true; } - public @java.lang.Override @java.lang.SuppressWarnings("all") int hashCode() { + public @java.lang.Override @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") int hashCode() { int result = 1; return result; } - public @java.lang.Override @java.lang.SuppressWarnings("all") java.lang.String toString() { + public @java.lang.Override @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") java.lang.String toString() { return "ValueExperimental1()"; } - public @java.lang.SuppressWarnings("all") ValueExperimental1() { + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") ValueExperimental1() { super(); } } final @lombok.experimental.Value class ValueExperimental2 { - public @java.lang.Override @java.lang.SuppressWarnings("all") boolean equals(final java.lang.Object o) { + public @java.lang.Override @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") boolean equals(final java.lang.Object o) { if ((o == this)) return true; if ((! (o instanceof ValueExperimental2))) return false; return true; } - public @java.lang.Override @java.lang.SuppressWarnings("all") int hashCode() { + public @java.lang.Override @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") int hashCode() { int result = 1; return result; } - public @java.lang.Override @java.lang.SuppressWarnings("all") java.lang.String toString() { + public @java.lang.Override @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") java.lang.String toString() { return "ValueExperimental2()"; } - public @java.lang.SuppressWarnings("all") ValueExperimental2() { + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") ValueExperimental2() { super(); } }
\ No newline at end of file diff --git a/test/transform/resource/after-ecj/ValueExperimentalStarImport.java b/test/transform/resource/after-ecj/ValueExperimentalStarImport.java index b69e85d9..5b366e04 100644 --- a/test/transform/resource/after-ecj/ValueExperimentalStarImport.java +++ b/test/transform/resource/after-ecj/ValueExperimentalStarImport.java @@ -1,20 +1,20 @@ import lombok.experimental.*; final @Value class ValueExperimentalStarImport { - public @java.lang.Override @java.lang.SuppressWarnings("all") boolean equals(final java.lang.Object o) { + public @java.lang.Override @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") boolean equals(final java.lang.Object o) { if ((o == this)) return true; if ((! (o instanceof ValueExperimentalStarImport))) return false; return true; } - public @java.lang.Override @java.lang.SuppressWarnings("all") int hashCode() { + public @java.lang.Override @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") int hashCode() { int result = 1; return result; } - public @java.lang.Override @java.lang.SuppressWarnings("all") java.lang.String toString() { + public @java.lang.Override @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") java.lang.String toString() { return "ValueExperimentalStarImport()"; } - public @java.lang.SuppressWarnings("all") ValueExperimentalStarImport() { + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") ValueExperimentalStarImport() { super(); } } diff --git a/test/transform/resource/after-ecj/ValuePlain.java b/test/transform/resource/after-ecj/ValuePlain.java index 8162ab93..1fd05da8 100644 --- a/test/transform/resource/after-ecj/ValuePlain.java +++ b/test/transform/resource/after-ecj/ValuePlain.java @@ -2,18 +2,18 @@ import lombok.Value; final @lombok.Value class Value1 { private final int x; private final String name; - public @java.lang.SuppressWarnings("all") int getX() { + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") int getX() { return this.x; } - public @java.lang.SuppressWarnings("all") String getName() { + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") String getName() { return this.name; } - public @java.lang.Override @java.lang.SuppressWarnings("all") boolean equals(final java.lang.Object o) { + public @java.lang.Override @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") boolean equals(final java.lang.Object o) { if ((o == this)) return true; if ((! (o instanceof Value1))) return false; - final @java.lang.SuppressWarnings("all") Value1 other = (Value1) o; + final Value1 other = (Value1) o; if ((this.getX() != other.getX())) return false; final java.lang.Object this$name = this.getName(); @@ -22,7 +22,7 @@ final @lombok.Value class Value1 { return false; return true; } - public @java.lang.Override @java.lang.SuppressWarnings("all") int hashCode() { + public @java.lang.Override @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") int hashCode() { final int PRIME = 59; int result = 1; result = ((result * PRIME) + this.getX()); @@ -30,10 +30,10 @@ final @lombok.Value class Value1 { result = ((result * PRIME) + (($name == null) ? 0 : $name.hashCode())); return result; } - public @java.lang.Override @java.lang.SuppressWarnings("all") java.lang.String toString() { + public @java.lang.Override @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") java.lang.String toString() { return (((("Value1(x=" + this.getX()) + ", name=") + this.getName()) + ")"); } - public @java.beans.ConstructorProperties({"x", "name"}) @java.lang.SuppressWarnings("all") Value1(final int x, final String name) { + public @java.beans.ConstructorProperties({"x", "name"}) @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") Value1(final int x, final String name) { super(); this.x = x; this.name = name; @@ -42,18 +42,18 @@ final @lombok.Value class Value1 { @Value @lombok.experimental.NonFinal class Value2 { public final int x; private final String name; - public @java.lang.SuppressWarnings("all") int getX() { + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") int getX() { return this.x; } - public @java.lang.SuppressWarnings("all") String getName() { + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") String getName() { return this.name; } - public @java.lang.Override @java.lang.SuppressWarnings("all") boolean equals(final java.lang.Object o) { + public @java.lang.Override @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") boolean equals(final java.lang.Object o) { if ((o == this)) return true; if ((! (o instanceof Value2))) return false; - final @java.lang.SuppressWarnings("all") Value2 other = (Value2) o; + final Value2 other = (Value2) o; if ((! other.canEqual((java.lang.Object) this))) return false; if ((this.getX() != other.getX())) @@ -64,10 +64,10 @@ final @lombok.Value class Value1 { return false; return true; } - protected @java.lang.SuppressWarnings("all") boolean canEqual(final java.lang.Object other) { + protected @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") boolean canEqual(final java.lang.Object other) { return (other instanceof Value2); } - public @java.lang.Override @java.lang.SuppressWarnings("all") int hashCode() { + public @java.lang.Override @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") int hashCode() { final int PRIME = 59; int result = 1; result = ((result * PRIME) + this.getX()); @@ -75,10 +75,10 @@ final @lombok.Value class Value1 { result = ((result * PRIME) + (($name == null) ? 0 : $name.hashCode())); return result; } - public @java.lang.Override @java.lang.SuppressWarnings("all") java.lang.String toString() { + public @java.lang.Override @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") java.lang.String toString() { return (((("Value2(x=" + this.getX()) + ", name=") + this.getName()) + ")"); } - public @java.beans.ConstructorProperties({"x", "name"}) @java.lang.SuppressWarnings("all") Value2(final int x, final String name) { + public @java.beans.ConstructorProperties({"x", "name"}) @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") Value2(final int x, final String name) { super(); this.x = x; this.name = name; @@ -87,35 +87,35 @@ final @lombok.Value class Value1 { final @Value class Value3 { private @lombok.experimental.NonFinal int x; private final int y; - public @java.lang.SuppressWarnings("all") int getX() { + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") int getX() { return this.x; } - public @java.lang.SuppressWarnings("all") int getY() { + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") int getY() { return this.y; } - public @java.lang.Override @java.lang.SuppressWarnings("all") boolean equals(final java.lang.Object o) { + public @java.lang.Override @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") boolean equals(final java.lang.Object o) { if ((o == this)) return true; if ((! (o instanceof Value3))) return false; - final @java.lang.SuppressWarnings("all") Value3 other = (Value3) o; + final Value3 other = (Value3) o; if ((this.getX() != other.getX())) return false; if ((this.getY() != other.getY())) return false; return true; } - public @java.lang.Override @java.lang.SuppressWarnings("all") int hashCode() { + public @java.lang.Override @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") int hashCode() { final int PRIME = 59; int result = 1; result = ((result * PRIME) + this.getX()); result = ((result * PRIME) + this.getY()); return result; } - public @java.lang.Override @java.lang.SuppressWarnings("all") java.lang.String toString() { + public @java.lang.Override @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") java.lang.String toString() { return (((("Value3(x=" + this.getX()) + ", y=") + this.getY()) + ")"); } - public @java.beans.ConstructorProperties({"x", "y"}) @java.lang.SuppressWarnings("all") Value3(final int x, final int y) { + public @java.beans.ConstructorProperties({"x", "y"}) @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") Value3(final int x, final int y) { super(); this.x = x; this.y = y; diff --git a/test/transform/resource/after-ecj/WitherAccessLevel.java b/test/transform/resource/after-ecj/WitherAccessLevel.java index 09a2e514..18b896df 100644 --- a/test/transform/resource/after-ecj/WitherAccessLevel.java +++ b/test/transform/resource/after-ecj/WitherAccessLevel.java @@ -9,19 +9,19 @@ class WitherAccessLevel { WitherAccessLevel(boolean isNone, boolean isPrivate, boolean isPackage, boolean isProtected, boolean isPublic, boolean value) { super(); } - private @java.lang.SuppressWarnings("all") WitherAccessLevel withPrivate(final boolean isPrivate) { + private @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") WitherAccessLevel withPrivate(final boolean isPrivate) { return ((this.isPrivate == isPrivate) ? this : new WitherAccessLevel(this.isNone, isPrivate, this.isPackage, this.isProtected, this.isPublic, this.value)); } - @java.lang.SuppressWarnings("all") WitherAccessLevel withPackage(final boolean isPackage) { + @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") WitherAccessLevel withPackage(final boolean isPackage) { return ((this.isPackage == isPackage) ? this : new WitherAccessLevel(this.isNone, this.isPrivate, isPackage, this.isProtected, this.isPublic, this.value)); } - protected @java.lang.SuppressWarnings("all") WitherAccessLevel withProtected(final boolean isProtected) { + protected @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") WitherAccessLevel withProtected(final boolean isProtected) { return ((this.isProtected == isProtected) ? this : new WitherAccessLevel(this.isNone, this.isPrivate, this.isPackage, isProtected, this.isPublic, this.value)); } - public @java.lang.SuppressWarnings("all") WitherAccessLevel withPublic(final boolean isPublic) { + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") WitherAccessLevel withPublic(final boolean isPublic) { return ((this.isPublic == isPublic) ? this : new WitherAccessLevel(this.isNone, this.isPrivate, this.isPackage, this.isProtected, isPublic, this.value)); } - public @java.lang.SuppressWarnings("all") WitherAccessLevel withValue(final boolean value) { + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") WitherAccessLevel withValue(final boolean value) { return ((this.value == value) ? this : new WitherAccessLevel(this.isNone, this.isPrivate, this.isPackage, this.isProtected, this.isPublic, value)); } } diff --git a/test/transform/resource/after-ecj/WitherAlreadyExists.java b/test/transform/resource/after-ecj/WitherAlreadyExists.java index ded10755..f0186ca3 100644 --- a/test/transform/resource/after-ecj/WitherAlreadyExists.java +++ b/test/transform/resource/after-ecj/WitherAlreadyExists.java @@ -37,7 +37,7 @@ class Wither5 { Wither5(String foo) { super(); } - public @java.lang.SuppressWarnings("all") Wither5 withFoo(final String foo) { + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") Wither5 withFoo(final String foo) { return ((this.foo == foo) ? this : new Wither5(foo)); } } @@ -48,7 +48,7 @@ class Wither6 { Wither6(String foo) { super(); } - public @java.lang.SuppressWarnings("all") Wither6 withFoo(final String foo) { + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") Wither6 withFoo(final String foo) { return ((this.foo == foo) ? this : new Wither6(foo)); } } diff --git a/test/transform/resource/after-ecj/WitherAndAllArgsConstructor.java b/test/transform/resource/after-ecj/WitherAndAllArgsConstructor.java index 091024e2..4443085c 100644 --- a/test/transform/resource/after-ecj/WitherAndAllArgsConstructor.java +++ b/test/transform/resource/after-ecj/WitherAndAllArgsConstructor.java @@ -4,13 +4,13 @@ final int x = 10; int y = 20; final int z; - public @java.lang.SuppressWarnings("all") WitherAndAllArgsConstructor<T, J, L> withTest(final J test) { + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") WitherAndAllArgsConstructor<T, J, L> withTest(final J test) { return ((this.test == test) ? this : new WitherAndAllArgsConstructor<T, J, L>(test, this.test2, this.y, this.z)); } - public @java.lang.SuppressWarnings("all") WitherAndAllArgsConstructor<T, J, L> withTest2(final java.util.List<L> test2) { + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") WitherAndAllArgsConstructor<T, J, L> withTest2(final java.util.List<L> test2) { return ((this.test2 == test2) ? this : new WitherAndAllArgsConstructor<T, J, L>(this.test, test2, this.y, this.z)); } - public @java.beans.ConstructorProperties({"test", "test2", "y", "z"}) @java.lang.SuppressWarnings("all") WitherAndAllArgsConstructor(final J test, final java.util.List<L> test2, final int y, final int z) { + public @java.beans.ConstructorProperties({"test", "test2", "y", "z"}) @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") WitherAndAllArgsConstructor(final J test, final java.util.List<L> test2, final int y, final int z) { super(); this.test = test; this.test2 = test2; diff --git a/test/transform/resource/after-ecj/WitherDeprecated.java b/test/transform/resource/after-ecj/WitherDeprecated.java index b57d0d79..90e5fb88 100644 --- a/test/transform/resource/after-ecj/WitherDeprecated.java +++ b/test/transform/resource/after-ecj/WitherDeprecated.java @@ -5,10 +5,10 @@ class WitherDeprecated { WitherDeprecated(int annotation, int javadoc) { super(); } - public @java.lang.Deprecated @java.lang.SuppressWarnings("all") WitherDeprecated withAnnotation(final int annotation) { + public @java.lang.Deprecated @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") WitherDeprecated withAnnotation(final int annotation) { return ((this.annotation == annotation) ? this : new WitherDeprecated(annotation, this.javadoc)); } - public @java.lang.Deprecated @java.lang.SuppressWarnings("all") WitherDeprecated withJavadoc(final int javadoc) { + public @java.lang.Deprecated @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") WitherDeprecated withJavadoc(final int javadoc) { return ((this.javadoc == javadoc) ? this : new WitherDeprecated(this.annotation, javadoc)); } } diff --git a/test/transform/resource/after-ecj/WitherOnClass.java b/test/transform/resource/after-ecj/WitherOnClass.java index 82132e87..1d5414d0 100644 --- a/test/transform/resource/after-ecj/WitherOnClass.java +++ b/test/transform/resource/after-ecj/WitherOnClass.java @@ -4,7 +4,7 @@ WitherOnClass1(boolean isNone, boolean isPublic) { super(); } - public @java.lang.SuppressWarnings("all") WitherOnClass1 withPublic(final boolean isPublic) { + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") WitherOnClass1 withPublic(final boolean isPublic) { return ((this.isPublic == isPublic) ? this : new WitherOnClass1(this.isNone, isPublic)); } } @@ -15,10 +15,10 @@ WitherOnClass2(boolean isNone, boolean isProtected, boolean isPackage) { super(); } - @java.lang.SuppressWarnings("all") WitherOnClass2 withPackage(final boolean isPackage) { + @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") WitherOnClass2 withPackage(final boolean isPackage) { return ((this.isPackage == isPackage) ? this : new WitherOnClass2(this.isNone, this.isProtected, isPackage)); } - protected @java.lang.SuppressWarnings("all") WitherOnClass2 withProtected(final boolean isProtected) { + protected @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") WitherOnClass2 withProtected(final boolean isProtected) { return ((this.isProtected == isProtected) ? this : new WitherOnClass2(this.isNone, isProtected, this.isPackage)); } } @@ -28,10 +28,10 @@ WitherOnClass3(String couldBeNull, String nonNull) { super(); } - public @java.lang.SuppressWarnings("all") WitherOnClass3 withCouldBeNull(final String couldBeNull) { + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") WitherOnClass3 withCouldBeNull(final String couldBeNull) { return ((this.couldBeNull == couldBeNull) ? this : new WitherOnClass3(couldBeNull, this.nonNull)); } - public @java.lang.SuppressWarnings("all") WitherOnClass3 withNonNull(final @lombok.NonNull String nonNull) { + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") WitherOnClass3 withNonNull(final @lombok.NonNull String nonNull) { if ((nonNull == null)) { throw new java.lang.NullPointerException("nonNull"); @@ -46,7 +46,7 @@ super(); this.fY = y; } - public @java.lang.SuppressWarnings("all") WitherOnClass4 withY(final int fY) { + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") WitherOnClass4 withY(final int fY) { return ((this.fY == fY) ? this : new WitherOnClass4(fY)); } } diff --git a/test/transform/resource/after-ecj/WitherPlain.java b/test/transform/resource/after-ecj/WitherPlain.java index ae1988bc..52177ef1 100644 --- a/test/transform/resource/after-ecj/WitherPlain.java +++ b/test/transform/resource/after-ecj/WitherPlain.java @@ -7,10 +7,10 @@ class WitherPlain { this.i = i; this.foo = foo; } - public @java.lang.SuppressWarnings("all") WitherPlain withI(final int i) { + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") WitherPlain withI(final int i) { return ((this.i == i) ? this : new WitherPlain(i, this.foo)); } - public @java.lang.SuppressWarnings("all") WitherPlain withFoo(final int foo) { + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") WitherPlain withFoo(final int foo) { return ((this.foo == foo) ? this : new WitherPlain(this.i, foo)); } } diff --git a/test/transform/resource/after-ecj/WitherWithGenerics.java b/test/transform/resource/after-ecj/WitherWithGenerics.java index ee73297c..66d8a8f8 100644 --- a/test/transform/resource/after-ecj/WitherWithGenerics.java +++ b/test/transform/resource/after-ecj/WitherWithGenerics.java @@ -6,13 +6,13 @@ class WitherWithGenerics<T, J extends T, L extends java.lang.Number> { public WitherWithGenerics(J test, java.util.List<L> test2, java.util.List<? extends L> test3) { super(); } - public @java.lang.SuppressWarnings("all") WitherWithGenerics<T, J, L> withTest(final J test) { + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") WitherWithGenerics<T, J, L> withTest(final J test) { return ((this.test == test) ? this : new WitherWithGenerics<T, J, L>(test, this.test2, this.test3)); } - public @java.lang.SuppressWarnings("all") WitherWithGenerics<T, J, L> withTest2(final java.util.List<L> test2) { + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") WitherWithGenerics<T, J, L> withTest2(final java.util.List<L> test2) { return ((this.test2 == test2) ? this : new WitherWithGenerics<T, J, L>(this.test, test2, this.test3)); } - public @java.lang.SuppressWarnings("all") WitherWithGenerics<T, J, L> withTest3(final java.util.List<? extends L> test3) { + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") WitherWithGenerics<T, J, L> withTest3(final java.util.List<? extends L> test3) { return ((this.test3 == test3) ? this : new WitherWithGenerics<T, J, L>(this.test, this.test2, test3)); } } diff --git a/test/transform/resource/before/BuilderSingularGuavaListsSets.java b/test/transform/resource/before/BuilderSingularGuavaListsSets.java new file mode 100644 index 00000000..995c00e8 --- /dev/null +++ b/test/transform/resource/before/BuilderSingularGuavaListsSets.java @@ -0,0 +1,14 @@ +import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableCollection; +import com.google.common.collect.ImmutableSet; +import com.google.common.collect.ImmutableSortedSet; + +import lombok.Singular; + +@lombok.Builder +class BuilderSingularGuavaListsSets<T> { + @Singular private ImmutableList<T> cards; + @Singular private ImmutableCollection<? extends Number> frogs; + @SuppressWarnings("all") @Singular("rawSet") private ImmutableSet rawSet; + @Singular private ImmutableSortedSet<String> passes; +} diff --git a/test/transform/resource/before/BuilderSingularGuavaMaps.java b/test/transform/resource/before/BuilderSingularGuavaMaps.java new file mode 100644 index 00000000..64a53570 --- /dev/null +++ b/test/transform/resource/before/BuilderSingularGuavaMaps.java @@ -0,0 +1,12 @@ +import com.google.common.collect.ImmutableMap; +import com.google.common.collect.ImmutableBiMap; +import com.google.common.collect.ImmutableSortedMap; + +import lombok.Singular; + +@lombok.Builder +class BuilderSingularGuavaMaps<K, V> { + @Singular private ImmutableMap<K, V> battleaxes; + @Singular private ImmutableSortedMap<Integer, ? extends V> vertices; + @SuppressWarnings("all") @Singular("rawMap") private ImmutableBiMap rawMap; +} diff --git a/test/transform/resource/before/BuilderSingularLists.java b/test/transform/resource/before/BuilderSingularLists.java new file mode 100644 index 00000000..93fced8e --- /dev/null +++ b/test/transform/resource/before/BuilderSingularLists.java @@ -0,0 +1,11 @@ +import java.util.List; +import java.util.Collection; + +import lombok.Singular; + +@lombok.Builder +class BuilderSingularLists<T> { + @Singular private List<T> children; + @Singular private Collection<? extends Number> scarves; + @SuppressWarnings("all") @Singular("rawList") private List rawList; +} diff --git a/test/transform/resource/before/BuilderSingularMaps.java b/test/transform/resource/before/BuilderSingularMaps.java new file mode 100644 index 00000000..7fe1a149 --- /dev/null +++ b/test/transform/resource/before/BuilderSingularMaps.java @@ -0,0 +1,15 @@ +//FORMAT: javaLangAsFQN = skip +//FORMAT: generated = skip +//FORMAT: finalParams = skip +import java.util.Map; +import java.util.SortedMap; + +import lombok.Singular; + +@lombok.Builder +class BuilderSingularMaps<K, V> { + @Singular private Map<K, V> women; + @Singular private SortedMap<K, ? extends Number> men; + @SuppressWarnings("all") @Singular("rawMap") private Map rawMap; + @Singular("stringMap") private Map<String, V> stringMap; +} diff --git a/test/transform/resource/before/BuilderSingularNoAutoSingularize.java b/test/transform/resource/before/BuilderSingularNoAutoSingularize.java new file mode 100644 index 00000000..31e2c3ca --- /dev/null +++ b/test/transform/resource/before/BuilderSingularNoAutoSingularize.java @@ -0,0 +1,11 @@ +//CONF: lombok.singular.auto = false +import java.util.List; + +import lombok.Singular; + +@lombok.Builder +class BuilderSingularNoAutosingularize { + @Singular private List<String> things; + @Singular("widget") private List<String> widgets; + @Singular private List<String> items; +} diff --git a/test/transform/resource/before/BuilderSingularRedirectToGuava.java b/test/transform/resource/before/BuilderSingularRedirectToGuava.java new file mode 100644 index 00000000..2dfa7684 --- /dev/null +++ b/test/transform/resource/before/BuilderSingularRedirectToGuava.java @@ -0,0 +1,13 @@ +//CONF: lombok.singular.useGuava = true +import java.util.Set; +import java.util.NavigableMap; +import java.util.Collection; + +import lombok.Singular; + +@lombok.Builder +class BuilderSingularRedirectToGuava { + @Singular private Set<String> dangerMice; + @Singular private NavigableMap<Integer, Number> things; + @Singular private Collection<Class<?>> doohickeys; +} diff --git a/test/transform/resource/before/BuilderSingularSets.java b/test/transform/resource/before/BuilderSingularSets.java new file mode 100644 index 00000000..68c4510a --- /dev/null +++ b/test/transform/resource/before/BuilderSingularSets.java @@ -0,0 +1,12 @@ +import java.util.Set; +import java.util.SortedSet; + +import lombok.Singular; + +@lombok.Builder +class BuilderSingularSets<T> { + @Singular private Set<T> dangerMice; + @Singular private SortedSet<? extends Number> octopodes; + @SuppressWarnings("all") @Singular("rawSet") private Set rawSet; + @Singular("stringSet") private Set<String> stringSet; +} diff --git a/test/transform/resource/before/BuilderWithExistingBuilderClass.java b/test/transform/resource/before/BuilderWithExistingBuilderClass.java index 262e3b85..c8e0a24b 100644 --- a/test/transform/resource/before/BuilderWithExistingBuilderClass.java +++ b/test/transform/resource/before/BuilderWithExistingBuilderClass.java @@ -1,4 +1,4 @@ -import lombok.experimental.Builder; +import lombok.Builder; class BuilderWithExistingBuilderClass<T, K extends Number> { @Builder diff --git a/test/transform/resource/before/EncodingUsAscii.java b/test/transform/resource/before/EncodingUsAscii.java new file mode 100644 index 00000000..dbcd150b --- /dev/null +++ b/test/transform/resource/before/EncodingUsAscii.java @@ -0,0 +1,5 @@ +//ENCODING: US-ASCII +@lombok.ToString +class EncodingUsAscii { + String foo\u0e51\u0e51 = "\u000e \10 "; +}
\ No newline at end of file diff --git a/test/transform/resource/before/EncodingUtf8.java b/test/transform/resource/before/EncodingUtf8.java new file mode 100644 index 00000000..75b0ee00 --- /dev/null +++ b/test/transform/resource/before/EncodingUtf8.java @@ -0,0 +1,5 @@ +//ENCODING: UTF-8 +@lombok.ToString +class EncodingUtf8 { + String foo\u0e51๑ = "\u000e \10 "; +}
\ No newline at end of file diff --git a/test/transform/resource/before/EqualsAndHashCodeWithSomeExistingMethods.java b/test/transform/resource/before/EqualsAndHashCodeWithSomeExistingMethods.java index debe75b9..ec5ef7ad 100644 --- a/test/transform/resource/before/EqualsAndHashCodeWithSomeExistingMethods.java +++ b/test/transform/resource/before/EqualsAndHashCodeWithSomeExistingMethods.java @@ -1,3 +1,4 @@ +//CONF: lombok.addGeneratedAnnotation = false import lombok.*; import static lombok.AccessLevel.NONE; diff --git a/test/transform/resource/before/GenerateSuppressFBWarnings.java b/test/transform/resource/before/GenerateSuppressFBWarnings.java new file mode 100644 index 00000000..2ab9c744 --- /dev/null +++ b/test/transform/resource/before/GenerateSuppressFBWarnings.java @@ -0,0 +1,5 @@ +//VERSION 7: +//CONF: lombok.extern.findbugs.addSuppressFBWarnings = true +class GenerateSuppressFBWarnings { + @lombok.Getter int y; +} diff --git a/test/transform/resource/before/ValAnonymousSubclassWithGenerics.java b/test/transform/resource/before/ValAnonymousSubclassWithGenerics.java index 49fc86e0..c0f8157a 100644 --- a/test/transform/resource/before/ValAnonymousSubclassWithGenerics.java +++ b/test/transform/resource/before/ValAnonymousSubclassWithGenerics.java @@ -1,4 +1,4 @@ -// ignore +// issue 205: val inside anonymous inner classes is a bit tricky in javac, this test ensures we don't break it. import java.util.*; import lombok.val; diff --git a/test/transform/resource/before/ValWithLocalClasses.java b/test/transform/resource/before/ValWithLocalClasses.java new file mode 100644 index 00000000..572a1e7d --- /dev/null +++ b/test/transform/resource/before/ValWithLocalClasses.java @@ -0,0 +1,12 @@ +//issue 694: In javac, resolving the RHS (which is what val does) can cause an entire class to be resolved, breaking all usage of val inside that class. This tests that we handle that better. +class ValWithLocalClasses1 { + { + lombok.val f2 = new ValWithLocalClasses2() {}; + } +} + +class ValWithLocalClasses2 { + { + lombok.val f3 = 0; + } +}
\ No newline at end of file diff --git a/test/transform/resource/messages-delombok/BuilderSingularNoAutosingularize.java.messages b/test/transform/resource/messages-delombok/BuilderSingularNoAutosingularize.java.messages new file mode 100644 index 00000000..8719789b --- /dev/null +++ b/test/transform/resource/messages-delombok/BuilderSingularNoAutosingularize.java.messages @@ -0,0 +1,2 @@ +8 The singular must be specified explicitly (e.g. @Singular("task")) because auto singularization is disabled. +10 The singular must be specified explicitly (e.g. @Singular("task")) because auto singularization is disabled. diff --git a/test/transform/resource/messages-delombok/EqualsAndHashCodeWithSomeExistingMethods.java.messages b/test/transform/resource/messages-delombok/EqualsAndHashCodeWithSomeExistingMethods.java.messages index d3119bd6..d8c064a0 100644 --- a/test/transform/resource/messages-delombok/EqualsAndHashCodeWithSomeExistingMethods.java.messages +++ b/test/transform/resource/messages-delombok/EqualsAndHashCodeWithSomeExistingMethods.java.messages @@ -1 +1 @@ -4 Not generating equals: One of equals or hashCode exists. You should either write both of these or none of these (in the latter case, lombok generates them). +5 Not generating equals: One of equals or hashCode exists. You should either write both of these or none of these (in the latter case, lombok generates them). diff --git a/test/transform/resource/messages-ecj/BuilderComplex.java.messages b/test/transform/resource/messages-ecj/BuilderComplex.java.messages new file mode 100644 index 00000000..4856a80d --- /dev/null +++ b/test/transform/resource/messages-ecj/BuilderComplex.java.messages @@ -0,0 +1 @@ +2 The type Builder is deprecated diff --git a/test/transform/resource/messages-ecj/BuilderSingularNoAutosingularize.java.messages b/test/transform/resource/messages-ecj/BuilderSingularNoAutosingularize.java.messages new file mode 100644 index 00000000..8719789b --- /dev/null +++ b/test/transform/resource/messages-ecj/BuilderSingularNoAutosingularize.java.messages @@ -0,0 +1,2 @@ +8 The singular must be specified explicitly (e.g. @Singular("task")) because auto singularization is disabled. +10 The singular must be specified explicitly (e.g. @Singular("task")) because auto singularization is disabled. diff --git a/test/transform/resource/messages-ecj/EqualsAndHashCodeWithSomeExistingMethods.java.messages b/test/transform/resource/messages-ecj/EqualsAndHashCodeWithSomeExistingMethods.java.messages index d3119bd6..d8c064a0 100644 --- a/test/transform/resource/messages-ecj/EqualsAndHashCodeWithSomeExistingMethods.java.messages +++ b/test/transform/resource/messages-ecj/EqualsAndHashCodeWithSomeExistingMethods.java.messages @@ -1 +1 @@ -4 Not generating equals: One of equals or hashCode exists. You should either write both of these or none of these (in the latter case, lombok generates them). +5 Not generating equals: One of equals or hashCode exists. You should either write both of these or none of these (in the latter case, lombok generates them). diff --git a/test/transform/resource/messages-ecj/ValAnonymousSubclassWithGenerics.java.messages b/test/transform/resource/messages-ecj/ValAnonymousSubclassWithGenerics.java.messages new file mode 100644 index 00000000..37f87639 --- /dev/null +++ b/test/transform/resource/messages-ecj/ValAnonymousSubclassWithGenerics.java.messages @@ -0,0 +1 @@ +17 The serializable class does not declare a static final serialVersionUID field of type long
\ No newline at end of file diff --git a/test/transform/resource/messages-idempotent/NonNullPlain.java.messages b/test/transform/resource/messages-idempotent/NonNullPlain.java.messages index 1d8c4d9c..0b520462 100644 --- a/test/transform/resource/messages-idempotent/NonNullPlain.java.messages +++ b/test/transform/resource/messages-idempotent/NonNullPlain.java.messages @@ -1,3 +1,3 @@ 3 @NonNull is meaningless on a primitive. -15 @NonNull is meaningless on a primitive. -37 @NonNull is meaningless on a primitive.
\ No newline at end of file +16 @NonNull is meaningless on a primitive. +42 @NonNull is meaningless on a primitive.
\ No newline at end of file diff --git a/usage_examples/BuilderExample_post.jpage b/usage_examples/BuilderExample_post.jpage new file mode 100644 index 00000000..863ab19b --- /dev/null +++ b/usage_examples/BuilderExample_post.jpage @@ -0,0 +1,66 @@ +import java.util.Set; + +public class BuilderExample { + private String name; + private int age; + private Set<String> occupations; + + BuilderExample(String name, int age, Set<String> occupations) { + this.name = name; + this.age = age; + this.occupations = occupations; + } + + public static BuilderExampleBuilder builder() { + return new BuilderExampleBuilder(); + } + + public static class BuilderExampleBuilder { + private String name; + private int age; + private java.util.ArrayList<String> occupations; + + BuilderExampleBuilder() { + } + + public BuilderExampleBuilder name(String name) { + this.name = name; + return this; + } + + public BuilderExampleBuilder age(int age) { + this.age = age; + return this; + } + + public BuilderExampleBuilder occupation(String occupation) { + if (this.occupations == null) { + this.occupations = new java.util.ArrayList<String>(); + } + + this.occupations.add(occupation); + return this; + } + + public BuilderExampleBuilder occupations(Collection<? extends String> occupations) { + if (this.occupations == null) { + this.occupations = new java.util.ArrayList<String>(); + } + + this.occupations.addAll(occupations); + return this; + } + + public BuilderExample build() { + // complicated switch statement to produce a compact properly sized immutable set omitted. + // go to http://projectlombok.org/features/Singular-snippet.html to see it. + Set<String> occupations = ...; + return new BuilderExample(name, age, occupations); + } + + @java.lang.Override + public String toString() { + return "BuilderExample.BuilderExampleBuilder(name = " + this.name + ", age = " + this.age + ", occupations = " + this.occupations + ")"; + } + } +}
\ No newline at end of file diff --git a/usage_examples/BuilderExample_pre.jpage b/usage_examples/BuilderExample_pre.jpage new file mode 100644 index 00000000..1557fff4 --- /dev/null +++ b/usage_examples/BuilderExample_pre.jpage @@ -0,0 +1,10 @@ +import lombok.Builder; +import lombok.Singular; +import java.util.Set; + +@Builder +public class BuilderExample { + private String name; + private int age; + @Singular private Set<String> occupations; +} diff --git a/usage_examples/Singular-snippetExample_post.jpage b/usage_examples/Singular-snippetExample_post.jpage new file mode 100644 index 00000000..4e2b0460 --- /dev/null +++ b/usage_examples/Singular-snippetExample_post.jpage @@ -0,0 +1,160 @@ +import java.util.Collection; +import java.util.Set; +import java.util.SortedMap; +import com.google.common.collect.ImmutableList; + +public class SingularExample<T extends Number> { + private Set<String> occupations; + private ImmutableList<String> axes; + private SortedMap<Integer, T> elves; + private Collection<?> minutiae; + + SingularExample(Set<String> occupations, ImmutableList<String> axes, SortedMap<Integer, T> elves, Collection<?> minutiae) { + this.occupations = occupations; + this.axes = axes; + this.elves = elves; + this.minutiae = minutiae; + } + + public static class SingularExampleBuilder<T extends Number> { + private java.util.ArrayList<String> occupations; + private com.google.common.collect.ImmutableList.Builder<String> axes; + private java.util.ArrayList<Integer> elves$key; + private java.util.ArrayList<T> elves$value; + private java.util.ArrayList<java.lang.Object> minutiae; + + SingularExampleBuilder() { + } + + public SingularExampleBuilder<T> occupation(String occupation) { + if (this.occupations == null) { + this.occupations = new java.util.ArrayList<String>(); + } + + this.occupations.add(occupation); + return this; + } + + @java.lang.SuppressWarnings("all") + public SingularExampleBuilder<T> occupations(java.util.Collection<? extends String> occupations) { + if (this.occupations == null) { + this.occupations = new java.util.ArrayList<String>(); + } + + this.occupations.addAll(occupations); + return this; + } + + public SingularExampleBuilder<T> axis(String axis) { + if (this.axes == null) { + this.axes = com.google.common.collect.ImmutableList.builder(); + } + + this.axes.add(axis); + return this; + } + + public SingularExampleBuilder<T> axes(java.lang.Iterable<? extends String> axes) { + if (this.axes == null) { + this.axes = com.google.common.collect.ImmutableList.builder(); + } + + this.axes.addAll(axes); + return this; + } + + public SingularExampleBuilder<T> elf(Integer elfKey, T elfValue) { + if (this.elves$key == null) { + this.elves$key = new java.util.ArrayList<Integer>(); + this.elves$value = new java.util.ArrayList<T>(); + } + + this.elves$key.add(elfKey); + this.elves$value.add(elfValue); + return this; + } + + public SingularExampleBuilder<T> elves(java.util.Map<? extends Integer, ? extends T> elves) { + if (this.elves$key == null) { + this.elves$key = new java.util.ArrayList<Integer>(); + this.elves$value = new java.util.ArrayList<T>(); + } + + for (java.util.Map.Entry<? extends Integer, ? extends T> $lombokEntry : elves.entrySet()) { + this.elves$key.add($lombokEntry.getKey()); + this.elves$value.add($lombokEntry.getValue()); + } + return this; + } + + public SingularExampleBuilder<T> minutia(java.lang.Object minutia) { + if (this.minutiae == null) { + this.minutiae = new java.util.ArrayList<java.lang.Object>(); + } + + this.minutiae.add(minutia); + return this; + } + + public SingularExampleBuilder<T> minutiae(java.util.Collection<?> minutiae) { + if (this.minutiae == null) { + this.minutiae = new java.util.ArrayList<java.lang.Object>(); + } + + this.minutiae.addAll(minutiae); + return this; + } + + public SingularExample<T> build() { + java.util.Set<String> occupations; + switch (this.occupations == null ? 0 : this.occupations.size()) { + case 0: + occupations = java.util.Collections.emptySet(); + break; + + case 1: + occupations = java.util.Collections.singleton(this.occupations.get(0)); + break; + + default: + occupations = new java.util.LinkedHashSet<String>(this.occupations.size() < 1073741824 ? 1 + this.occupations.size() + (this.occupations.size() - 3) / 3 : java.lang.Integer.MAX_VALUE); + occupations.addAll(this.occupations); + occupations = java.util.Collections.unmodifiableSet(occupations); + + } + + com.google.common.collect.ImmutableList<String> axes = this.axes == null ? com.google.common.collect.ImmutableList.<String>of() : this.axes.build(); + + java.util.SortedMap<Integer, T> elves = new java.util.TreeMap<Integer, T>(); + if (this.elves$key != null) for (int $i = 0; $i < (this.elves$key == null ? 0 : this.elves$key.size()); $i++) elves.put(this.elves$key.get($i), this.elves$value.get($i)); + elves = java.util.Collections.unmodifiableSortedMap(elves); + + java.util.Collection<java.lang.Object> minutiae; + switch (this.minutiae == null ? 0 : this.minutiae.size()) { + case 0: + minutiae = java.util.Collections.emptyList(); + break; + + case 1: + minutiae = java.util.Collections.singletonList(this.minutiae.get(0)); + break; + + default: + minutiae = java.util.Collections.unmodifiableList(new java.util.ArrayList<java.lang.Object>(this.minutiae)); + + } + + return new SingularExample<T>(occupations, axes, elves, minutiae); + } + + @java.lang.Override + public java.lang.String toString() { + return "SingularExample.SingularExampleBuilder(occupations=" + this.occupations + ", axes=" + this.axes + ", elves$key=" + this.elves$key + ", elves$value=" + this.elves$value + ", minutiae=" + this.minutiae + ")"; + } + } + + @java.lang.SuppressWarnings("all") + public static <T extends Number> SingularExampleBuilder<T> builder() { + return new SingularExampleBuilder<T>(); + } +} diff --git a/usage_examples/Singular-snippetExample_pre.jpage b/usage_examples/Singular-snippetExample_pre.jpage new file mode 100644 index 00000000..65f6bbc8 --- /dev/null +++ b/usage_examples/Singular-snippetExample_pre.jpage @@ -0,0 +1,14 @@ +import lombok.Builder; +import lombok.Singular; +import java.util.Collection; +import java.util.Set; +import java.util.SortedMap; +import com.google.common.collect.ImmutableList; + +@Builder +public class SingularExample<T extends Number> { + private @Singular Set<String> occupations; + private @Singular("axis") ImmutableList<String> axes; + private @Singular SortedMap<Integer, T> elves; + private @Singular Collection<?> minutiae; +} diff --git a/usage_examples/experimental/BuilderExample_post.jpage b/usage_examples/experimental/BuilderExample_post.jpage deleted file mode 100644 index 624b236b..00000000 --- a/usage_examples/experimental/BuilderExample_post.jpage +++ /dev/null @@ -1,40 +0,0 @@ -public class BuilderExample { - private String name; - private int age; - - BuilderExample(String name, int age) { - this.name = name; - this.age = age; - } - - public static BuilderExampleBuilder builder() { - return new BuilderExampleBuilder(); - } - - public static class BuilderExampleBuilder { - private String name; - private int age; - - BuilderExampleBuilder() { - } - - public BuilderExampleBuilder name(String name) { - this.name = name; - return this; - } - - public BuilderExampleBuilder age(int age) { - this.age = age; - return this; - } - - public BuilderExample build() { - return new BuilderExample(name, age); - } - - @java.lang.Override - public String toString() { - return "BuilderExample.BuilderExampleBuilder(name = " + this.name + ", age = " + this.age + ")"; - } - } -}
\ No newline at end of file diff --git a/usage_examples/experimental/BuilderExample_pre.jpage b/usage_examples/experimental/BuilderExample_pre.jpage deleted file mode 100644 index 9c754352..00000000 --- a/usage_examples/experimental/BuilderExample_pre.jpage +++ /dev/null @@ -1,7 +0,0 @@ -import lombok.experimental.Builder; - -@Builder -public class BuilderExample { - private String name; - private int age; -} diff --git a/website/download.html b/website/download.html index afacde2b..ff96db46 100644 --- a/website/download.html +++ b/website/download.html @@ -81,7 +81,7 @@ <div class="endBar"> </div> <div class="footer"> - <a href="credits.html" class="creditsLink">credits</a> | Copyright © 2009-2014 The Project Lombok Authors, licensed under the <a href="http://www.opensource.org/licenses/mit-license.php">MIT license</a>. + <a href="credits.html" class="creditsLink">credits</a> | Copyright © 2009-2015 The Project Lombok Authors, licensed under the <a href="http://www.opensource.org/licenses/mit-license.php">MIT license</a>. </div> </div> <script type="text/javascript"> diff --git a/website/features/Builder.html b/website/features/Builder.html new file mode 100644 index 00000000..b4731b07 --- /dev/null +++ b/website/features/Builder.html @@ -0,0 +1,170 @@ +<!DOCTYPE html> +<html><head> + <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> + <link rel="stylesheet" type="text/css" href="../logi/reset.css" /> + <link rel="stylesheet" type="text/css" href="features.css" /> + <link rel="shortcut icon" href="../favicon.ico" type="image/x-icon" /> + <meta name="description" content="Spice up your java" /> + <title>@Builder</title> +</head><body><div id="pepper"> + <div class="minimumHeight"></div> + <div class="meat"> + <div class="header"><a href="../index.html">Project Lombok</a></div> + <h1>@Builder</h1> + <div class="byline">... and Bob's your uncle: No-hassle fancy-pants APIs for object creation!</div> + <div class="since"> + <h3>Since</h3> + <p> + <code>@Builder</code> was introduced as experimental feature in lombok v0.12.0. + </p><p> + <code>@Builder</code> gained <code>@Singular</code> support and was promoted to the main <code>lombok</code> package since lombok v1.16.0. + </p> + </div> + <div class="overview"> + <h3>Overview</h3> + <p> + The <code>@Builder</code> annotation produces complex builder APIs for your classes. + </p><p> + <code>@Builder</code> lets you automatically produce the code required to have your class be instantiable with code such as:<br /> + <code>Person.builder().name("Adam Savage").city("San Francisco").job("Mythbusters").job("Unchained Reaction").build();</code> + </p><p> + <code>@Builder</code> can be placed on a class, or on a constructor, or on a static method. While the "on a class" and "on a constructor" + mode are the most common use-case, <code>@Builder</code> is most easily explained with the "static method" use-case. + </p><p> + A static method annotated with <code>@Builder</code> (from now on called the <em>target</em>) causes the following 7 things to be generated:<ul> + <li>An inner static class named <code><em>Foo</em>Builder</code>, with the same type arguments as the static method (called the <em>builder</em>).</li> + <li>In the <em>builder</em>: One private non-static non-final field for each parameter of the <em>target</em>.</li> + <li>In the <em>builder</em>: A package private no-args empty constructor.</li> + <li>In the <em>builder</em>: A 'setter'-like method for each parameter of the <em>target</em>: It has the same type as that parameter and the same name. + It returns the builder itself, so that the setter calls can be chained, as in the above example.</li> + <li>In the <em>builder</em>: A <code>build()</code> method which calls the static method, passing in each field. It returns the same type that the + <em>target</em> returns.</li> + <li>In the <em>builder</em>: A sensible <code>toString()</code> implementation.</li> + <li>In the class containing the <em>target</em>: A <code>builder()</code> method, which creates a new instance of the <em>builder</em>.</li> + </ul> + Each listed generated element will be silently skipped if that element already exists (disregarding parameter counts and looking only at names). This + includes the <em>builder</em> itself: If that class already exists, lombok will simply start injecting fields and methods inside this already existing + class, unless of course the fields / methods to be injected already exist. You may not put any other method (or constructor) generating lombok annotation + on a builder class though; for example, you can not put <code>@EqualsAndHashCode</code> on the builder class. + </p><p> + <code>@Builder</code> can generate so-called 'singular' methods for collection parameters/fields. These take 1 element instead of an entire list, and add the + element to the list. For example: <code>Person.builder().job("Mythbusters").job("Unchained Reaction").build();</code> would result in the <code>List<String> jobs</code> + field to have 2 strings in it. To get this behaviour, the field/parameter needs to be annotated with <code>@Singular</code>. The feature has <a href="#singular">its own documentation</a>. + </p><p> + Now that the "static method" mode is clear, putting a <code>@Builder</code> annotation on a constructor functions similarly; effectively, + constructors are just static methods that have a special syntax to invoke them: Their 'return type' is the class they construct, and their + type parameters are the same as the type parameters of the class itself. + </p><p> + Finally, applying <code>@Builder</code> to a class is as if you added <code>@AllArgsConstructor(access = AccessLevel.PACKAGE)</code> to the class and applied the + <code>@Builder</code> annotation to this all-args-constructor. This only works if you haven't written any explicit constructors yourself. If you do have an + explicit constructor, put the <code>@Builder</code> annotation on the constructor instead of on the class. + </p><p> + The name of the builder class is <code><em>Foobar</em>Builder</code>, where <em>Foobar</em> is the simplified, title-cased form of the return type of the + <em>target</em> - that is, the name of your type for <code>@Builder</code> on constructors and types, and the name of the return type for <code>@Builder</code> + on static methods. For example, if <code>@Builder</code> is applied to a class named <code>com.yoyodyne.FancyList<T></code>, then the builder name will be + <code>FancyListBuilder<T></code>. If <code>@Builder</code> is applied to a static method that returns <code>void</code>, the builder will be named + <code>VoidBuilder</code>. + </p><p> + The configurable aspects of builder are:<ul> + <li>The <em>builder's class name</em> (default: return type + 'Builder')</li> + <li>The <em>build()</em> method's name (default: <code>"build"</code>)</li> + <li>The <em>builder()</em> method's name (default: <code>"builder"</code>)</li> + </ul> + Example usage where all options are changed from their defaults:<br /> + <code>@Builder(builderClassName = "HelloWorldBuilder", buildMethodName = "execute", builderMethodName = "helloWorld")</code><br /> + </p> + </div> + <div class="overview"> + <h3><a name="singular">@Singular</a></h3> + <p> + By annotating one of the parameters (if annotating a static method or constructor with <code>@Builder</code>) or fields (if annotating a class with <code>@Builder</code>) with the + <code>@Singular</code> annotation, lombok will treat that builder node as a collection, and it generates 2 'adder' methods instead of a 'setter' method. One which adds a single element to the collection, and one + which adds all elements of another collection to the collection. No setter to just set the collection (replacing whatever was already added) will be generated. These 'singular' builders + are very complicated in order to guarantee the following properties: + <ul> + <li>When invoking <code>build()</code>, the produced collection will be immutable.</li> + <li>Calling one of the 'adder' methods after invoking <code>build()</code> does not modify any already generated objects, and, if <code>build()</code> is later called again, another collection with all the elements added since the creation of the builder is generated.</li> + <li>The produced collection will be compacted to the smallest feasible format while remaining efficient.</li> + </ul> + </p><p> + <code>@Singular</code> can only be applied to collection types known to lombok. Currently, the supported types are: + <ul> + <li><a href="http://docs.oracle.com/javase/8/docs/api/java/util/package-summary.html"><code>java.util</code></a>:<ul> + <li><code>Iterable</code>, <code>Collection</code>, and <code>List</code> (backed by a compacted unmodifiable <code>ArrayList</code> in the general case).</li> + <li><code>Set</code>, <code>SortedSet</code>, and <code>NavigableSet</code> (backed by a smartly sized unmodifiable <code>HashSet</code> or <code>TreeSet</code> in the general case).</li> + <li><code>Map</code>, <code>SortedMap</code>, and <code>NavigableMap</code> (backed by a smartly sized unmodifiable <code>HashMap</code> or <code>TreeMap</code> in the general case).</li> + </ul></li> + <li><a href="https://github.com/google/guava">Guava</a>'s <code>com.google.common.collect</code>:<ul> + <li><code>ImmutableCollection</code> and <code>ImmutableList</code> (backed by the builder feature of <code>ImmutableList</code>).</li> + <li><code>ImmutableSet</code> and <code>ImmutableSortedSet</code> (backed by the builder feature of those types).</li> + <li><code>ImmutableMap</code>, <code>ImmutableBiMap</code>, and <code>ImmutableSortedMap</code> (backed by the builder feature of those types).</li> + </ul></li> + </ul> + </p><p> + If your identifiers are written in common english, lombok assumes that the name of any collection with <code>@Singular</code> on it is an english plural and will attempt to automatically + singularize that name. If this is possible, the add-one method will use this name. For example, if your collection is called <code>statuses</code>, then the add-one method will automatically + be called <code>status</code>. You can also specify the singular form of your identifier explictly by passing the singular form as argument to the annotation like so: <code>@Singular("axis") List<Line> axes;</code>.<br /> + If lombok cannot singularize your identifier, or it is ambiguous, lombok will generate an error and force you to explicitly specify the singular name. + </p><p> + The snippet below does not show what lombok generates for a <code>@Singular</code> field/parameter because it is rather complicated. + You can view a snippet <a href="Singular-snippet.html">here</a>. + </p> + </div> + <div class="snippets"> + <div class="pre"> + <h3>With Lombok</h3> + <div class="snippet">@HTML_PRE@</div> + </div> + <div class="sep"></div> + <div class="post"> + <h3>Vanilla Java</h3> + <div class="snippet">@HTML_POST@</div> + </div> + </div> + <div style="clear: left;"></div> + <div class="overview confKeys"> + <h3>Supported configuration keys:</h3> + <dl> + <dt><code>lombok.builder.flagUsage</code> = [<code>warning</code> | <code>error</code>] (default: not set)</dt> + <dd>Lombok will flag any usage of <code>@Builder</code> as a warning or error if configured.</dd> + <dt><code>lombok.singular.useGuava</code> = [<code>true</code> | <code>false</code>] (default: false)</dt> + <dd>If <code>true</code>, lombok will use guava's <code>ImmutableXxx</code> builders and types to implement <code>java.util</code> collection interfaces, instead of creating + implementations based on <code>Collections.unmodifiableXxx</code>. You must ensure that guava is actually available on the classpath and buildpath if you use this setting. + Guava is used automatically if your field/parameter has one of the guava <code>ImmutableXxx</code> types. + <dt><code>lombok.singular.auto</code> = [<code>true</code> | <code>false</code>] (default: true)</dt> + <dd>If <code>true</code> (which is the default), lombok automatically tries to singularize your identifier name by assuming that it is a common english plural. + If <code>false</code>, you must always explicitly specify the singular name, and lombok will generate an error if you don't (useful if you write your code in a language other than english). + </dl> + </div> + <div class="overview"> + <h3>Small print</h3><div class="smallprint"> + <p> + @Singular support for <code>java.util.NavigableMap/Set</code> only works if you are compiling with JDK1.8 or higher. + </p><p> + You cannot manually provide some or all parts of a <code>@Singular</code> node; the code lombok generates is too complex for this. If you want to + manually control (part of) the builder code associated with some field or parameter, don't use <code>@Singular</code> and add everything you need manually. + </p><p> + The sorted collections (java.util: <code>SortedSet</code>, <code>NavigableSet</code>, <code>SortedMap</code>, <code>NavigableMap</code> and guava: <code>ImmutableSortedSet</code>, <code>ImmutableSortedMap</code>) require that the type argument of the collection has natural order (implements <code>java.util.Comparable</code>). There is no way to pass an explicit <code>Comparator</code> to use in the builder. + </p><p> + An <code>ArrayList</code> is used to store added elements as call methods of a <code>@Singular</code> marked field, if the target collection is from the <code>java.util</code> package, <em>even if the collection is a set or map</em>. Because lombok ensures that generated collections are compacted, a new backing instance of a set or map must be constructed anyway, and storing the data as an <code>ArrayList</code> during the build process is more efficient that storing it as a map or set. This behaviour is not externally visible, an an implementation detail of the current implementation of the <code>java.util</code> recipes for <code>@Singular @Builder</code>. + </p> + </div> + </div> + <div class="footer"> + <a href="index.html">Back to features</a> | <a href="Value.html">Previous feature (@Value)</a> | <a href="SneakyThrows.html">Next feature (@SneakyThrows)</a><br /> + <a href="../credits.html" class="creditsLink">credits</a> | <span class="copyright">Copyright © 2009-2015 The Project Lombok Authors, licensed under the <a href="http://www.opensource.org/licenses/mit-license.php">MIT license</a>.</span> + </div> + <div style="clear: both;"></div> + </div> +</div> +<script type="text/javascript"> + var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www."); + document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E")); +</script> +<script type="text/javascript"> + try { + var pageTracker = _gat._getTracker("UA-9884254-1"); + pageTracker._trackPageview(); + } catch(err) {} +</script> +</body></html> diff --git a/website/features/Cleanup.html b/website/features/Cleanup.html index f4b16946..a6f25935 100644 --- a/website/features/Cleanup.html +++ b/website/features/Cleanup.html @@ -68,7 +68,7 @@ </div> <div class="footer"> <a href="index.html">Back to features</a> | <a href="NonNull.html">Previous feature (@NonNull)</a> | <a href="GetterSetter.html">Next feature (@Getter / @Setter)</a><br /> - <a href="../credits.html" class="creditsLink">credits</a> | <span class="copyright">Copyright © 2009-2014 The Project Lombok Authors, licensed under the <a href="http://www.opensource.org/licenses/mit-license.php">MIT license</a>.</span> + <a href="../credits.html" class="creditsLink">credits</a> | <span class="copyright">Copyright © 2009-2015 The Project Lombok Authors, licensed under the <a href="http://www.opensource.org/licenses/mit-license.php">MIT license</a>.</span> </div> <div style="clear: both;"></div> </div> diff --git a/website/features/Data.html b/website/features/Data.html index c3d0a644..ed06f299 100644 --- a/website/features/Data.html +++ b/website/features/Data.html @@ -66,7 +66,7 @@ </div> <div class="footer"> <a href="index.html">Back to features</a> | <a href="Constructor.html">Previous feature (@<em>X</em>Constructor)</a> | <a href="Value.html">Next feature (@Value)</a><br /> - <a href="../credits.html" class="creditsLink">credits</a> | <span class="copyright">Copyright © 2009-2014 The Project Lombok Authors, licensed under the <a href="http://www.opensource.org/licenses/mit-license.php">MIT license</a>.</span> + <a href="../credits.html" class="creditsLink">credits</a> | <span class="copyright">Copyright © 2009-2015 The Project Lombok Authors, licensed under the <a href="http://www.opensource.org/licenses/mit-license.php">MIT license</a>.</span> </div> <div style="clear: both;"></div> </div> diff --git a/website/features/EqualsAndHashCode.html b/website/features/EqualsAndHashCode.html index 32dcb6c3..0cad6b1b 100644 --- a/website/features/EqualsAndHashCode.html +++ b/website/features/EqualsAndHashCode.html @@ -76,7 +76,7 @@ </div> <div class="footer"> <a href="index.html">Back to features</a> | <a href="ToString.html">Previous feature (@ToString)</a> | <a href="Constructor.html">Next feature (@<em>X</em>Constructor)</a><br /> - <a href="../credits.html" class="creditsLink">credits</a> | <span class="copyright">Copyright © 2009-2014 The Project Lombok Authors, licensed under the <a href="http://www.opensource.org/licenses/mit-license.php">MIT license</a>.</span> + <a href="../credits.html" class="creditsLink">credits</a> | <span class="copyright">Copyright © 2009-2015 The Project Lombok Authors, licensed under the <a href="http://www.opensource.org/licenses/mit-license.php">MIT license</a>.</span> </div> <div style="clear: both;"></div> </div> diff --git a/website/features/GetterLazy.html b/website/features/GetterLazy.html index a438f08a..ad08b480 100644 --- a/website/features/GetterLazy.html +++ b/website/features/GetterLazy.html @@ -48,7 +48,7 @@ </div> <div class="footer"> <a href="index.html">Back to features</a> | <a href="Synchronized.html">Previous feature (@Synchronized)</a> | <a href="Log.html">Next feature (@Log)</a><br /> - <a href="../credits.html" class="creditsLink">credits</a> | <span class="copyright">Copyright © 2009-2014 The Project Lombok Authors, licensed under the <a href="http://www.opensource.org/licenses/mit-license.php">MIT license</a>.</span> + <a href="../credits.html" class="creditsLink">credits</a> | <span class="copyright">Copyright © 2009-2015 The Project Lombok Authors, licensed under the <a href="http://www.opensource.org/licenses/mit-license.php">MIT license</a>.</span> </div> <div style="clear: both;"></div> </div> diff --git a/website/features/GetterSetter.html b/website/features/GetterSetter.html index ad83f86a..760e1876 100644 --- a/website/features/GetterSetter.html +++ b/website/features/GetterSetter.html @@ -87,7 +87,7 @@ </div> <div class="footer"> <a href="index.html">Back to features</a> | <a href="Cleanup.html">Previous feature (@Cleanup)</a> | <a href="ToString.html">Next feature (@ToString)</a><br /> - <a href="../credits.html" class="creditsLink">credits</a> | <span class="copyright">Copyright © 2009-2014 The Project Lombok Authors, licensed under the <a href="http://www.opensource.org/licenses/mit-license.php">MIT license</a>.</span> + <a href="../credits.html" class="creditsLink">credits</a> | <span class="copyright">Copyright © 2009-2015 The Project Lombok Authors, licensed under the <a href="http://www.opensource.org/licenses/mit-license.php">MIT license</a>.</span> </div> <div style="clear: both;"></div> </div> diff --git a/website/features/Log.html b/website/features/Log.html index 8b635280..22e5d293 100644 --- a/website/features/Log.html +++ b/website/features/Log.html @@ -83,7 +83,7 @@ </div> <div class="footer"> <a href="index.html">Back to features</a> | <a href="GetterLazy.html">Previous feature (@Getter(lazy=true))</a> | <a href="configuration.html">Next feature (configuration)</a><br /> - <a href="../credits.html" class="creditsLink">credits</a> | <span class="copyright">Copyright © 2009-2014 The Project Lombok Authors, licensed under the <a href="http://www.opensource.org/licenses/mit-license.php">MIT license</a>.</span> + <a href="../credits.html" class="creditsLink">credits</a> | <span class="copyright">Copyright © 2009-2015 The Project Lombok Authors, licensed under the <a href="http://www.opensource.org/licenses/mit-license.php">MIT license</a>.</span> </div> <div style="clear: both;"></div> </div> diff --git a/website/features/Singular-snippet.html b/website/features/Singular-snippet.html new file mode 100644 index 00000000..7afbebf8 --- /dev/null +++ b/website/features/Singular-snippet.html @@ -0,0 +1,43 @@ +<!DOCTYPE html> +<html><head> + <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> + <link rel="stylesheet" type="text/css" href="../logi/reset.css" /> + <link rel="stylesheet" type="text/css" href="features.css" /> + <link rel="shortcut icon" href="../favicon.ico" type="image/x-icon" /> + <meta name="description" content="Spice up your java" /> + <title>@Builder's @Singular (snippet)</title> +</head><body><div id="pepper"> + <div class="minimumHeight"></div> + <div class="meat"> + <div class="header"><a href="../index.html">Project Lombok</a></div> + <h1>@Singular snippet</h1> + <div class="singleColumnSnippets"> + <div class="pre"> + <h3>With Lombok</h3> + <div class="snippet">@HTML_PRE@</div> + </div> + <div class="sep"></div> + <div class="post"> + <h3>Vanilla Java</h3> + <div class="snippet">@HTML_POST@</div> + </div> + </div> + <div style="clear: left;"></div> + <div class="footer"> + <a href="Builder.html">Back to @Builder</a><br /> + <a href="../credits.html" class="creditsLink">credits</a> | <span class="copyright">Copyright © 2009-2015 The Project Lombok Authors, licensed under the <a href="http://www.opensource.org/licenses/mit-license.php">MIT license</a>.</span> + </div> + <div style="clear: both;"></div> + </div> +</div> +<script type="text/javascript"> + var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www."); + document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E")); +</script> +<script type="text/javascript"> + try { + var pageTracker = _gat._getTracker("UA-9884254-1"); + pageTracker._trackPageview(); + } catch(err) {} +</script> +</body></html> diff --git a/website/features/SneakyThrows.html b/website/features/SneakyThrows.html index e1cd6685..55f4a0b8 100644 --- a/website/features/SneakyThrows.html +++ b/website/features/SneakyThrows.html @@ -77,8 +77,8 @@ </div> </div> <div class="footer"> - <a href="index.html">Back to features</a> | <a href="Value.html">Previous feature (@Value)</a> | <a href="Synchronized.html">Next feature (@Synchronized)</a><br /> - <a href="../credits.html" class="creditsLink">credits</a> | <span class="copyright">Copyright © 2009-2014 The Project Lombok Authors, licensed under the <a href="http://www.opensource.org/licenses/mit-license.php">MIT license</a>.</span> + <a href="index.html">Back to features</a> | <a href="Builder.html">Previous feature (@Builder)</a> | <a href="Synchronized.html">Next feature (@Synchronized)</a><br /> + <a href="../credits.html" class="creditsLink">credits</a> | <span class="copyright">Copyright © 2009-2015 The Project Lombok Authors, licensed under the <a href="http://www.opensource.org/licenses/mit-license.php">MIT license</a>.</span> </div> <div style="clear: both;"></div> </div> diff --git a/website/features/Synchronized.html b/website/features/Synchronized.html index 85c161c3..df9db6b0 100644 --- a/website/features/Synchronized.html +++ b/website/features/Synchronized.html @@ -67,7 +67,7 @@ </div> <div class="footer"> <a href="index.html">Back to features</a> | <a href="SneakyThrows.html">Previous feature (@SneakyThrows)</a> | <a href="GetterLazy.html">Next feature (@Getter(lazy=true))</a><br /> - <a href="../credits.html" class="creditsLink">credits</a> | <span class="copyright">Copyright © 2009-2014 The Project Lombok Authors, licensed under the <a href="http://www.opensource.org/licenses/mit-license.php">MIT license</a>.</span> + <a href="../credits.html" class="creditsLink">credits</a> | <span class="copyright">Copyright © 2009-2015 The Project Lombok Authors, licensed under the <a href="http://www.opensource.org/licenses/mit-license.php">MIT license</a>.</span> </div> <div style="clear: both;"></div> </div> diff --git a/website/features/ToString.html b/website/features/ToString.html index 57bbd0f0..5071048c 100644 --- a/website/features/ToString.html +++ b/website/features/ToString.html @@ -74,7 +74,7 @@ </div> <div class="footer"> <a href="index.html">Back to features</a> | <a href="GetterSetter.html">Previous feature (@Getter / @Setter)</a> | <a href="EqualsAndHashCode.html">Next feature (@EqualsAndHashCode)</a><br /> - <a href="../credits.html" class="creditsLink">credits</a> | <span class="copyright">Copyright © 2009-2014 The Project Lombok Authors, licensed under the <a href="http://www.opensource.org/licenses/mit-license.php">MIT license</a>.</span> + <a href="../credits.html" class="creditsLink">credits</a> | <span class="copyright">Copyright © 2009-2015 The Project Lombok Authors, licensed under the <a href="http://www.opensource.org/licenses/mit-license.php">MIT license</a>.</span> </div> <div style="clear: both;"></div> </div> diff --git a/website/features/Value.html b/website/features/Value.html index 0e221b63..25bba650 100644 --- a/website/features/Value.html +++ b/website/features/Value.html @@ -20,6 +20,7 @@ <code>@Value</code> no longer implies <code>@Wither</code> since lombok v0.11.8. </p><p> <code>@Value</code> promoted to the main <code>lombok</code> package since lombok v0.12.0. + </p> </div> <div class="overview"> <h3>Overview</h3> @@ -67,8 +68,8 @@ </div> </div> <div class="footer"> - <a href="index.html">Back to features</a> | <a href="Data.html">Previous feature (@Data)</a> | <a href="SneakyThrows.html">Next feature (@SneakyThrows)</a><br /> - <a href="../credits.html" class="creditsLink">credits</a> | <span class="copyright">Copyright © 2009-2014 The Project Lombok Authors, licensed under the <a href="http://www.opensource.org/licenses/mit-license.php">MIT license</a>.</span> + <a href="index.html">Back to features</a> | <a href="Data.html">Previous feature (@Data)</a> | <a href="Builder.html">Next feature (@Builder)</a><br /> + <a href="../credits.html" class="creditsLink">credits</a> | <span class="copyright">Copyright © 2009-2015 The Project Lombok Authors, licensed under the <a href="http://www.opensource.org/licenses/mit-license.php">MIT license</a>.</span> </div> <div style="clear: both;"></div> </div> diff --git a/website/features/configuration.html b/website/features/configuration.html index acf874e7..7e79a9c0 100644 --- a/website/features/configuration.html +++ b/website/features/configuration.html @@ -21,7 +21,9 @@ Usually, a user of lombok puts a <code>lombok.config</code> file with their preferences in a workspace or project root directory, with the special <code>config.stopBubbling = true</code> key to tell lombok this is your root directory. You can then create <code>lombok.config</code> files in any subdirectories (generally representing projects or source packages) with different settings. </p><p> An up to date list of all configuration keys supported by your version of lombok can be generated by running: - <div class="snippet example"><code>java -jar lombok.jar config -g --verbose</code></div> + <div class="snippet example"> + <code>java -jar lombok.jar config -g --verbose</code> + </div> The output of the <em>config</em> tool is itself a valid <code>lombok.config</code> file.<br /> The <em>config</em> tool can also be used to display the complete lombok configuration used for any given directory or source file by supplying these as arguments. </p><p> @@ -42,7 +44,7 @@ Configuration files are hierarchical: Any configuration setting applies to all source files in that directory, and all source files in subdirectories, but configuration settings closer to the source file take precedence. For example, if you have in <code>/Users/me/projects/lombok.config</code> the following: <div class="snippet example"> <code>lombok.log.fieldName = foobar</code> - </div></div> + </div> and in <code>/Users/me/projects/MyProject/lombok.config</code> you have: <div class="snippet example"> <code>lombok.log.fieldName = xyzzy</code> @@ -61,19 +63,32 @@ <code>lombok.accessors.prefix += m_</code> </div> </p><p> + Comments can be included in <code>lombok.config</code> files; any line that starts with <code>#</code> is considered a comment. + </p> + </div> + <div class="overview" style="clear: left;"> + <h3>Global config keys</h3> + <p> To stop lombok from looking at parent directories for more configuration files, the special key: <div class="snippet example"> <code>config.stopBubbling = true</code> </div> - can be included. + can be included. We suggest you put this in the root of your workspace directory. </p><p> - Comments can be included in <code>lombok.config</code> files; any line that starts with <code>#</code> is considered a comment. - </p> + Lombok normally adds <code>@javax.annotation.Generated</code> annotations to all generated nodes where possible. You can stop this with: + <div class="snippet example"> + <code>lombok.addGeneratedAnnotation = false</code> + </div> + </p><p> + Lombok can add the <code>@SuppressFBWarnings</code> annotation which is useful if you want to run <a href="http://findbugs.sourceforge.net/">FindBugs</a> on your class files. To enable this feature, make sure findbugs is on the classpath when you compile, and add the following config key: + <div class="snippet example"> + <code>lombok.extern.findbugs.addSuppressFBWarnings = true</code> + </div> </div> <div style="clear: left;"></div> <div class="footer"> <a href="index.html">Back to features</a> | <a href="Log.html">Previous feature (@Log)</a> | <span class="disabled">Next feature</span><br /> - <a href="../credits.html" class="creditsLink">credits</a> | <span class="copyright">Copyright © 2009-2014 The Project Lombok Authors, licensed under the <a href="http://www.opensource.org/licenses/mit-license.php">MIT license</a>.</span> + <a href="../credits.html" class="creditsLink">credits</a> | <span class="copyright">Copyright © 2009-2015 The Project Lombok Authors, licensed under the <a href="http://www.opensource.org/licenses/mit-license.php">MIT license</a>.</span> </div> <div style="clear: both;"></div> </div> diff --git a/website/features/delombok.html b/website/features/delombok.html index 30f21c04..dbd7b51f 100644 --- a/website/features/delombok.html +++ b/website/features/delombok.html @@ -41,7 +41,7 @@ <code>lombok.jar</code> includes an ant task which can apply delombok for you. For example, to create javadoc for your project, your <code>build.xml</code> file would look something like: <div class="snippet"><pre><target name="javadoc"> - <taskdef classname="lombok.delombok.ant.DelombokTask" classpath="lib/lombok.jar" name="delombok" /> + <taskdef classname="lombok.delombok.ant.Tasks$Delombok" classpath="lib/lombok.jar" name="delombok" /> <mkdir dir="build/src-delomboked" /> <strong><delombok verbose="true" encoding="UTF-8" to="build/src-delomboked" from="src"></strong> <strong><format value="suppressWarnings:skip" /></strong> diff --git a/website/features/experimental/Accessors.html b/website/features/experimental/Accessors.html index 20590a07..3934c339 100644 --- a/website/features/experimental/Accessors.html +++ b/website/features/experimental/Accessors.html @@ -97,8 +97,8 @@ </div> </div> <div class="footer"> - <a href="index.html">Back to experimental features</a> | <a href="Builder.html">Previous feature (@Builder)</a> | <a href="ExtensionMethod.html">Next feature (@ExtensionMethod)</a><br /> - <a href="../../credits.html" class="creditsLink">credits</a> | <span class="copyright">Copyright © 2009-2014 The Project Lombok Authors, licensed under the <a href="http://www.opensource.org/licenses/mit-license.php">MIT license</a>.</span> + <a href="index.html">Back to experimental features</a> | <span class="disabled">Previous feature</span> | <a href="ExtensionMethod.html">Next feature (@ExtensionMethod)</a><br /> + <a href="../../credits.html" class="creditsLink">credits</a> | <span class="copyright">Copyright © 2009-2015 The Project Lombok Authors, licensed under the <a href="http://www.opensource.org/licenses/mit-license.php">MIT license</a>.</span> </div> <div style="clear: both;"></div> </div> diff --git a/website/features/experimental/Builder.html b/website/features/experimental/Builder.html index a8e21b9a..9f1266dc 100644 --- a/website/features/experimental/Builder.html +++ b/website/features/experimental/Builder.html @@ -12,118 +12,13 @@ <div class="header"><a href="../../index.html">Project Lombok</a></div> <h1>@Builder</h1> <div class="byline">... and Bob's your uncle: No-hassle fancy-pants APIs for object creation!</div> - <div class="since"> - <h3>Since</h3> - <p> - @Builder was introduced as experimental feature in lombok v0.12.0. - </p> - </div> - <div class="experimental"> - <h3>Experimental</h3> - <p> - Experimental because: - <ul> - <li>New feature - community feedback requested.</li> - </ul> - Current status: <em>sure thing</em> - This feature will move to the core package soon. - </div> - <div class="overview"> - <h3>Overview</h3> - <p> - The <code>@Builder</code> annotation produces complex builder APIs for your classes. - </p><p> - <code>@Builder</code> lets you automatically produce the code required to have your class be instantiable with code such as:<br /> - <code>Person.builder().name("Adam Savage").city("San Francisco").worksAt("Mythbusters").build();</code> - </p><p> - <code>@Builder</code> can be placed on a class, or on a constructor, or on a static method. While the "on a class" and "on a constructor" - mode are the most common use-case, <code>@Builder</code> is most easily explained with the "static method" use-case. - </p><p> - A static method annotated with <code>@Builder</code> (from now on called the <em>target</em>) causes the following 7 things to be generated:<ul> - <li>An inner static class named <code><em>Foo</em>Builder</code>, with the same type arguments as the static method (called the <em>builder</em>).</li> - <li>In the <em>builder</em>: One private non-static non-final field for each parameter of the <em>target</em>.</li> - <li>In the <em>builder</em>: A package private no-args empty constructor.</li> - <li>In the <em>builder</em>: A 'setter'-like method for each parameter of the <em>target</em>: It has the same type as that parameter and the same name. - It returns the builder itself, so that the setter calls can be chained, as in the above example.</li> - <li>In the <em>builder</em>: A <code>build()</code> method which calls the static method, passing in each field. It returns the same type that the - <em>target</em> returns.</li> - <li>In the <em>builder</em>: A sensible <code>toString()</code> implementation.</li> - <li>In the class containing the <em>target</em>: A <code>builder()</code> method, which creates a new instance of the <em>builder</em>.</li> - </ul> - Each listed generated element will be silently skipped if that element already exists (disregarding parameter counts and looking only at names). This - includes the <em>builder</em> itself: If that class already exists, lombok will simply start injecting fields and methods inside this already existing - class, unless of course the fields / methods to be injected already exist. You may not put any other method (or constructor) generating lombok annotation - on a builder class though; for example, you can not put <code>@EqualsAndHashCode</code> on the builder class. - </p><p> - Now that the "static method" mode is clear, putting a <code>@Builder</code> annotation on a constructor functions similarly; effectively, - constructors are just static methods that have a special syntax to invoke them: Their 'return type' is the class they construct, and their - type parameters are the same as the type parameters of the class itself. - </p><p> - Finally, applying <code>@Builder</code> to a class is as if you added <code>@AllArgsConstructor(access = AccessLevel.PACKAGE)</code> to the class and applied the - <code>@Builder</code> annotation to this all-args-constructor. This only works if you haven't written any explicit constructors yourself. If you do have an - explicit constructor, put the <code>@Builder</code> annotation on the constructor instead of on the class. - </p><p> - The name of the builder class is <code><em>Foobar</em>Builder</code>, where <em>Foobar</em> is the simplified, title-cased form of the return type of the - <em>target</em> - that is, the name of your type for <code>@Builder</code> on constructors and types, and the name of the return type for <code>@Builder</code> - on static methods. For example, if <code>@Builder</code> is applied to a class named <code>com.yoyodyne.FancyList<T></code>, then the builder name will be - <code>FancyListBuilder<T></code>. If <code>@Builder</code> is applied to a static method that returns <code>void</code>, the builder will be named - <code>VoidBuilder</code>. - </p><p> - The configurable aspects of builder are:<ul> - <li>The <em>builder's class name</em> (default: return type + 'Builder')</li> - <li>The <em>build()</em> method's name (default: <code>"build"</code>)</li> - <li>The <em>builder()</em> method's name (default: <code>"builder"</code>)</li> - <li>The 'fluent' nature of the generated 'setter'-like methods. A fluent 'setter' is named just <code>fieldName()</code>, a non-fluent one is named <code>setFieldName()</code>. (default: <code>true</code>)</li> - <li>The 'chain' nature of the generated 'setter'-like methods. A chainable 'setter' returns the builder object itself, letting you chain 'set' calls. A non-chainable setter returns <code>void</code>. (default: <code>true</code>)</li> - </ul> - Example usage where all options are changed from their defaults:<br /> - <code>@Builder(builderClassName = "HelloWorldBuilder", buildMethodName = "execute", builderMethodName = "helloWorld", fluent = false, chain = false)</code><br /> - </p> - </div> - <div class="snippets"> - <div class="pre"> - <h3>With Lombok</h3> - <div class="snippet">@HTML_PRE@</div> - </div> - <div class="sep"></div> - <div class="post"> - <h3>Vanilla Java</h3> - <div class="snippet">@HTML_POST@</div> - </div> - </div> - <div style="clear: left;"></div> - <div class="overview confKeys"> - <h3>Supported configuration keys:</h3> - <dl> - <dt><code>lombok.builder.flagUsage</code> = [<code>warning</code> | <code>error</code>] (default: not set)</dt> - <dd>Lombok will flag any usage of <code>@Builder</code> as a warning or error if configured.</dd> - </dl> - </div> - <div class="overview"> - <h3>Small print</h3><div class="smallprint"> - <p> - Another strategy for fluent APIs is that the programmer using your library statically imports your 'builder' method. In this case, you might want to name your builder - method equal to your type's name. So, the builder method for a class called <code>Person</code> would become <code>person()</code>. This is nicer if the builder method - is statically imported. - </p><p> - If the return type of your target static method is a type parameter (such as <code>T</code>), lombok will enforce an explicit builder class name. - </p><p> - You don't HAVE to use <code>@Builder</code> to build anything; you can for example put it on a static method that has lots of parameter to improve the API of it. - In this case, we suggest you use <code>buildMethodName = </code> to rename the build method to <code>execute()</code> instead. - </p><p> - The builder class will NOT get an auto-generated implementation of <code>hashCode</code> or <code>equals</code> methods! These would suggest that it is sensible to use - instances of a builder as keys in a set or map. However, that's not a sensible thing to do. Hence, no <code>hashCode</code> or <code>equals</code>. - </p><p> - Generics are sorted out for you. - </p><p> - If an explicit constructor is present, but <code>@Builder</code> is placed on the class, then the builder will be generated as if an explicit constructor is present with the - same arguments list as what <code>@AllArgsConstructor</code> would produce. If this constructor does not exist, a compile time error will result. Usually you should just either let - lombok make this constructor (delete your constructor from the source), or, move the <code>@Builder</code> annotation to the constructor. - </p> - </div> + <div class="moved"> + @Builder has been promoted to the core package in lombok release v1.16.0.<br /> + The documentation has been moved here: <a href="../Builder.html">@lombok.Builder</a>. </div> <div class="footer"> - <a href="index.html">Back to experimental features</a> | <span class="disabled">Previous feature</span> | <a href="Accessors.html">Next feature (@Accessors)</a><br /> - <a href="../../credits.html" class="creditsLink">credits</a> | <span class="copyright">Copyright © 2009-2014 The Project Lombok Authors, licensed under the <a href="http://www.opensource.org/licenses/mit-license.php">MIT license</a>.</span> + <a href="index.html">Back to experimental features</a><br /> + <a href="../../credits.html" class="creditsLink">credits</a> | <span class="copyright">Copyright © 2009-2015 The Project Lombok Authors, licensed under the <a href="http://www.opensource.org/licenses/mit-license.php">MIT license</a>.</span> </div> <div style="clear: both;"></div> </div> diff --git a/website/features/experimental/ExtensionMethod.html b/website/features/experimental/ExtensionMethod.html index 58aaf1b3..f1735376 100644 --- a/website/features/experimental/ExtensionMethod.html +++ b/website/features/experimental/ExtensionMethod.html @@ -98,7 +98,7 @@ System.out.println(x.or("Hello, World!"));</pre> </div> <div class="footer"> <a href="index.html">Back to experimental features</a> | <a href="Accessors.html">Previous feature (@Accessors)</a> | <a href="FieldDefaults.html">Next feature (@FieldDefaults)</a><br /> - <a href="../../credits.html" class="creditsLink">credits</a> | <span class="copyright">Copyright © 2009-2014 The Project Lombok Authors, licensed under the <a href="http://www.opensource.org/licenses/mit-license.php">MIT license</a>.</span> + <a href="../../credits.html" class="creditsLink">credits</a> | <span class="copyright">Copyright © 2009-2015 The Project Lombok Authors, licensed under the <a href="http://www.opensource.org/licenses/mit-license.php">MIT license</a>.</span> </div> <div style="clear: both;"></div> </div> diff --git a/website/features/experimental/FieldDefaults.html b/website/features/experimental/FieldDefaults.html index 12ea7d80..5ad30952 100644 --- a/website/features/experimental/FieldDefaults.html +++ b/website/features/experimental/FieldDefaults.html @@ -73,7 +73,7 @@ </div> <div class="footer"> <a href="index.html">Back to experimental features</a> | <a href="ExtensionMethod.html">Previous feature (@ExtensionMethod)</a> | <a href="Delegate.html">Next feature (@Delegate)</a><br /> - <a href="../../credits.html" class="creditsLink">credits</a> | <span class="copyright">Copyright © 2009-2014 The Project Lombok Authors, licensed under the <a href="http://www.opensource.org/licenses/mit-license.php">MIT license</a>.</span> + <a href="../../credits.html" class="creditsLink">credits</a> | <span class="copyright">Copyright © 2009-2015 The Project Lombok Authors, licensed under the <a href="http://www.opensource.org/licenses/mit-license.php">MIT license</a>.</span> </div> <div style="clear: both;"></div> </div> diff --git a/website/features/experimental/Value.html b/website/features/experimental/Value.html new file mode 100644 index 00000000..c2b335e6 --- /dev/null +++ b/website/features/experimental/Value.html @@ -0,0 +1,36 @@ +<!DOCTYPE html> +<html><head> + <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> + <link rel="stylesheet" type="text/css" href="../../logi/reset.css" /> + <link rel="stylesheet" type="text/css" href="../features.css" /> + <link rel="shortcut icon" href="../../favicon.ico" type="image/x-icon" /> + <meta name="description" content="Spice up your java" /> + <title>EXPERIMENTAL - @Value</title> +</head><body><div id="pepper"> + <div class="minimumHeight"></div> + <div class="meat"> + <div class="header"><a href="../../index.html">Project Lombok</a></div> + <h1>@Value</h1> + <div class="byline">Immutable classes made very easy.</div> + <div class="moved"> + @Value has been promoted to the core package in lombok release v1.12.0.<br /> + The documentation has been moved here: <a href="../Value.html">@lombok.Value</a>. + </div> + <div class="footer"> + <a href="index.html">Back to experimental features</a><br /> + <a href="../../credits.html" class="creditsLink">credits</a> | <span class="copyright">Copyright © 2009-2015 The Project Lombok Authors, licensed under the <a href="http://www.opensource.org/licenses/mit-license.php">MIT license</a>.</span> + </div> + <div style="clear: both;"></div> + </div> +</div> +<script type="text/javascript"> + var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www."); + document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E")); +</script> +<script type="text/javascript"> + try { + var pageTracker = _gat._getTracker("UA-9884254-1"); + pageTracker._trackPageview(); + } catch(err) {} +</script> +</body></html> diff --git a/website/features/experimental/Wither.html b/website/features/experimental/Wither.html index 9ca43a46..81ef475e 100644 --- a/website/features/experimental/Wither.html +++ b/website/features/experimental/Wither.html @@ -93,7 +93,7 @@ </div> <div class="footer"> <a href="index.html">Back to experimental features</a> | <a href="Delegate.html">Previous feature (@Delegate)</a> | <a href="onX.html">Next feature (onX)</a><br /> - <a href="../../credits.html" class="creditsLink">credits</a> | <span class="copyright">Copyright © 2009-2014 The Project Lombok Authors, licensed under the <a href="http://www.opensource.org/licenses/mit-license.php">MIT license</a>.</span> + <a href="../../credits.html" class="creditsLink">credits</a> | <span class="copyright">Copyright © 2009-2015 The Project Lombok Authors, licensed under the <a href="http://www.opensource.org/licenses/mit-license.php">MIT license</a>.</span> </div> <div style="clear: both;"></div> </div> diff --git a/website/features/experimental/index.html b/website/features/experimental/index.html index f37712e0..a5932b73 100644 --- a/website/features/experimental/index.html +++ b/website/features/experimental/index.html @@ -22,8 +22,6 @@ Features that receive positive community feedback and which seem to produce clean, flexible code will eventually become accepted as a core feature and move out of the experimental package. <dl> - <dt><a href="Builder.html"><code>@Builder</code></a></dt> - <dd>... and Bob's your uncle: No-hassle fancy-pants APIs for object creation!</dd> <dt><a href="Accessors.html"><code>@Accessors</code></a></dt> <dd>A more fluent API for getters and setters.</dd> <dt><a href="ExtensionMethod.html"><code>@ExtensionMethod</code></a></dt> @@ -50,10 +48,12 @@ <dl> <dt><a href="../Value.html"><code>@Value</code></a>: Promoted</dt> <dd><code>@Value</code> has proven its value and has been moved to the main package.</li> + <dt><a href="../Builder.html"><code>@Builder</code></a>: Promoted</dt> + <dd><code>@Builder</code> is a solid base to build APIs on, and has been moved to the main package.</li> </dl> </div> <div class="footer"> - <a href="../../credits.html" class="creditsLink">credits</a> | <span class="copyright">Copyright © 2009-2014 The Project Lombok Authors, licensed under the <a href="http://www.opensource.org/licenses/mit-license.php">MIT license</a>.</span> + <a href="../../credits.html" class="creditsLink">credits</a> | <span class="copyright">Copyright © 2009-2015 The Project Lombok Authors, licensed under the <a href="http://www.opensource.org/licenses/mit-license.php">MIT license</a>.</span> </div> <div style="clear: both;"></div> </div> diff --git a/website/features/experimental/onX.html b/website/features/experimental/onX.html index ba2ead86..064db557 100644 --- a/website/features/experimental/onX.html +++ b/website/features/experimental/onX.html @@ -70,7 +70,7 @@ </div> <div class="footer"> <a href="index.html">Back to experimental features</a> | <a href="Wither.html">Previous feature (@Wither)</a> | <span class="disabled">Next feature</span><br /> - <a href="../../credits.html" class="creditsLink">credits</a> | <span class="copyright">Copyright © 2009-2014 The Project Lombok Authors, licensed under the <a href="http://www.opensource.org/licenses/mit-license.php">MIT license</a>.</span> + <a href="../../credits.html" class="creditsLink">credits</a> | <span class="copyright">Copyright © 2009-2015 The Project Lombok Authors, licensed under the <a href="http://www.opensource.org/licenses/mit-license.php">MIT license</a>.</span> </div> <div style="clear: both;"></div> </div> diff --git a/website/features/features.css b/website/features/features.css index b3017fe8..58897ccd 100644 --- a/website/features/features.css +++ b/website/features/features.css @@ -92,7 +92,7 @@ dd { white-space: nowrap; } -.snippets { +.snippets, .singleColumnSnippets { margin-top: 0px; } diff --git a/website/features/index.html b/website/features/index.html index 09a148f0..84457077 100644 --- a/website/features/index.html +++ b/website/features/index.html @@ -32,6 +32,8 @@ <code>@Getter</code> on all fields, and <code>@Setter</code> on all non-final fields, and <code>@RequiredArgsConstructor</code>!</dd> <dt><a href="Value.html"><code>@Value</code></a></dt> <dd>Immutable classes made very easy.</dd> + <dt><a href="Builder.html"><code>@Builder</code></a></dt> + <dd>... and Bob's your uncle: No-hassle fancy-pants APIs for object creation!</dd> <dt><a href="SneakyThrows.html"><code>@SneakyThrows</code></a></dt> <dd>To boldly throw checked exceptions where no one has thrown them before!</dd> <dt><a href="Synchronized.html"><code>@Synchronized</code></a></dt> @@ -70,7 +72,7 @@ your source files for source-level tools such as javadoc and GWT. More information about how to run delombok, including instructions for build tools can be found at the <a href="delombok.html">delombok page</a>.</div> <div class="footer"> - <a href="../credits.html" class="creditsLink">credits</a> | <span class="copyright">Copyright © 2009-2014 The Project Lombok Authors, licensed under the <a href="http://www.opensource.org/licenses/mit-license.php">MIT license</a>.</span> + <a href="../credits.html" class="creditsLink">credits</a> | <span class="copyright">Copyright © 2009-2015 The Project Lombok Authors, licensed under the <a href="http://www.opensource.org/licenses/mit-license.php">MIT license</a>.</span> </div> <div style="clear: both;"></div> </div> diff --git a/website/index.html b/website/index.html index 9f775fd3..cfcdf9b7 100644 --- a/website/index.html +++ b/website/index.html @@ -80,7 +80,7 @@ <a href="novideo.html">I can't see the video</a> | <a href="http://jnb.ociweb.com/jnb/jnbJan2010.html">Show me a text and images based explanation and tutorial instead!</a> </div> <div class="footer"> - <a href="credits.html" class="creditsLink">credits</a> | Copyright © 2009-2014 The Project Lombok Authors, licensed under the <a href="http://www.opensource.org/licenses/mit-license.php">MIT license</a>. + <a href="credits.html" class="creditsLink">credits</a> | Copyright © 2009-2015 The Project Lombok Authors, licensed under the <a href="http://www.opensource.org/licenses/mit-license.php">MIT license</a>. </div> </div> <script type="text/javascript"> diff --git a/website/mavenrepo/index.html b/website/mavenrepo/index.html index 01227bbd..29716920 100644 --- a/website/mavenrepo/index.html +++ b/website/mavenrepo/index.html @@ -60,6 +60,11 @@ You can use lombok with ivy by adding the following to your <strong>ivy.xml</strong>: <div class="snippet"><dependency org="org.projectlombok" name="lombok" rev="@VERSION@" conf="build" /></div> </div> + <h2>SBT</h2> + <div> + You can use lombok with SBT by adding the following to your <strong>build.sbt</strong>: + <div class="snippet">libraryDependencies += "org.projectlombok" % "lombok" % "@VERSION@"</div> + </div> <h2>Gradle</h2> <div> You can use lombok with gradle by adding the following to your <strong>build.gradle</strong> in the <strong>dependencies</strong> block: diff --git a/website/setup/android.html b/website/setup/android.html index 5e0eb9e7..23decaaa 100644 --- a/website/setup/android.html +++ b/website/setup/android.html @@ -115,7 +115,7 @@ java -jar lombok.jar publicApi</pre> <div class="endBar"> </div> <div class="footer"> - <a href="../credits.html" class="creditsLink">credits</a> | Copyright © 2009-2014 The Project Lombok Authors, licensed under the <a href="http://www.opensource.org/licenses/mit-license.php">MIT license</a>. + <a href="../credits.html" class="creditsLink">credits</a> | Copyright © 2009-2015 The Project Lombok Authors, licensed under the <a href="http://www.opensource.org/licenses/mit-license.php">MIT license</a>. </div> </div> <script type="text/javascript"> diff --git a/website/setup/ecj.html b/website/setup/ecj.html index 7c3ff1bb..f9de358d 100644 --- a/website/setup/ecj.html +++ b/website/setup/ecj.html @@ -49,7 +49,7 @@ java <strong>-javaagent:lombok.jar=ECJ -Xbootclasspath/p:lombok.jar</strong> -ja <div class="endBar"> </div> <div class="footer"> - <a href="../credits.html" class="creditsLink">credits</a> | Copyright © 2009-2014 The Project Lombok Authors, licensed under the <a href="http://www.opensource.org/licenses/mit-license.php">MIT license</a>. + <a href="../credits.html" class="creditsLink">credits</a> | Copyright © 2009-2015 The Project Lombok Authors, licensed under the <a href="http://www.opensource.org/licenses/mit-license.php">MIT license</a>. </div> </div> <script type="text/javascript"> diff --git a/website/setup/gwt.html b/website/setup/gwt.html index 84e760bc..ef7ea678 100644 --- a/website/setup/gwt.html +++ b/website/setup/gwt.html @@ -52,7 +52,7 @@ java <strong>-javaagent:lombok.jar=ECJ</strong> <em>(rest of arguments)</em> <div class="endBar"> </div> <div class="footer"> - <a href="../credits.html" class="creditsLink">credits</a> | Copyright © 2009-2014 The Project Lombok Authors, licensed under the <a href="http://www.opensource.org/licenses/mit-license.php">MIT license</a>. + <a href="../credits.html" class="creditsLink">credits</a> | Copyright © 2009-2015 The Project Lombok Authors, licensed under the <a href="http://www.opensource.org/licenses/mit-license.php">MIT license</a>. </div> </div> <script type="text/javascript"> diff --git a/website/setup/netbeans.html b/website/setup/netbeans.html index 03775206..e1dafca7 100644 --- a/website/setup/netbeans.html +++ b/website/setup/netbeans.html @@ -49,7 +49,7 @@ <div class="endBar"> </div> <div class="footer"> - <a href="../credits.html" class="creditsLink">credits</a> | Copyright © 2009-2014 The Project Lombok Authors, licensed under the <a href="http://www.opensource.org/licenses/mit-license.php">MIT license</a>. + <a href="../credits.html" class="creditsLink">credits</a> | Copyright © 2009-2015 The Project Lombok Authors, licensed under the <a href="http://www.opensource.org/licenses/mit-license.php">MIT license</a>. </div> </div> <script type="text/javascript"> |