diff options
32 files changed, 382 insertions, 279 deletions
diff --git a/src/core/lombok/ConfigurationKeys.java b/src/core/lombok/ConfigurationKeys.java index 12307471..05550a06 100644 --- a/src/core/lombok/ConfigurationKeys.java +++ b/src/core/lombok/ConfigurationKeys.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2013-2020 The Project Lombok Authors. + * Copyright (C) 2013-2021 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; import java.util.List; import lombok.core.configuration.CallSuperType; +import lombok.core.configuration.CapitalizationStrategy; import lombok.core.configuration.CheckerFrameworkVersion; import lombok.core.configuration.ConfigurationKey; import lombok.core.configuration.FlagUsageType; @@ -559,11 +560,12 @@ public class ConfigurationKeys { 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).") {}; /** - * lombok configuration: {@code lombok.accessors.javaBeansSpecCapitalization} = {@code true} | {@code false}. + * lombok configuration: {@code lombok.accessors.capitalization} = {@code basic} | {@code beanspec}. * - * For any class without an {@code @Accessors} that explicitly defines the {@code javaBeansSpecCapitalization} option, this value is used (default = false). + * Which capitalization rule is used to turn field names into getter/setter/with names and vice versa for field names that start with 1 lowercase letter, then 1 uppercase letter. + * basic = {@code uShape} becomes {@code getUShape}, beanspec = {@code uShape} becomes {@code getuShape} (default = basic). */ - public static final ConfigurationKey<Boolean> ACCESSORS_JAVA_BEANS_SPEC_CAPITALIZATION = new ConfigurationKey<Boolean>("lombok.accessors.javaBeansSpecCapitalization", "Generating accessors name according to the JavaBeans Spec (default: false).") {}; + public static final ConfigurationKey<CapitalizationStrategy> ACCESSORS_JAVA_BEANS_SPEC_CAPITALIZATION = new ConfigurationKey<CapitalizationStrategy>("lombok.accessors.capitalization", "Which capitalization strategy to use when converting field names to accessor names and vice versa (default: basic).") {}; // ----- ExtensionMethod ----- diff --git a/src/core/lombok/core/AST.java b/src/core/lombok/core/AST.java index 9f3a471f..07d035c5 100755 --- a/src/core/lombok/core/AST.java +++ b/src/core/lombok/core/AST.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2009-2019 The Project Lombok Authors. + * Copyright (C) 2009-2021 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 @@ -430,6 +430,9 @@ public abstract class AST<A extends AST<A, L, N>, L extends LombokNode<A, L, N>, } } + /** + * @return The {@code lombok.config} configuration value for the provided {@code key}, or {@code null} if that key is not in the config / there is no config. + */ public final <T> T readConfiguration(ConfigurationKey<T> key) { long start = configTracker == null ? 0L : configTracker.start(); try { @@ -438,4 +441,17 @@ public abstract class AST<A extends AST<A, L, N>, L extends LombokNode<A, L, N>, if (configTracker != null) configTracker.end(start); } } + + /** + * @return The {@code lombok.config} configuration value for the provided {@code key}, or {@code defaultValue} if that key is not in the config / there is no config. + */ + public final <T> T readConfigurationOr(ConfigurationKey<T> key, T defaultValue) { + long start = configTracker == null ? 0L : configTracker.start(); + try { + T value = LombokConfiguration.read(key, this); + return value != null ? value : defaultValue; + } finally { + if (configTracker != null) configTracker.end(start); + } + } } diff --git a/src/core/lombok/core/configuration/CapitalizationStrategy.java b/src/core/lombok/core/configuration/CapitalizationStrategy.java new file mode 100644 index 00000000..affd3576 --- /dev/null +++ b/src/core/lombok/core/configuration/CapitalizationStrategy.java @@ -0,0 +1,52 @@ +/* + * Copyright (C) 2021 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.configuration; + +/** Used for lombok configuration to determine how to transform field names when turning them into accessor method names and vice versa. */ +public enum CapitalizationStrategy { + BASIC { + @Override public String capitalize(String in) { + if (in.length() == 0) return in; + char first = in.charAt(0); + if (!Character.isLowerCase(first)) return in; + boolean useUpperCase = in.length() > 2 && + (Character.isTitleCase(in.charAt(1)) || Character.isUpperCase(in.charAt(1))); + return (useUpperCase ? Character.toUpperCase(first) : Character.toTitleCase(first)) + in.substring(1); + } + }, + BEANSPEC { + @Override public String capitalize(String in) { + if (in.length() == 0) return in; + char first = in.charAt(0); + if (!Character.isLowerCase(first) || (in.length() > 1 && Character.isUpperCase(in.charAt(1)))) return in; + boolean useUpperCase = in.length() > 2 && Character.isTitleCase(in.charAt(1)); + return (useUpperCase ? Character.toUpperCase(first) : Character.toTitleCase(first)) + in.substring(1); + } + }, + ; + + public static CapitalizationStrategy defaultValue() { + return BASIC; + } + + public abstract String capitalize(String in); +} diff --git a/src/core/lombok/core/configuration/FlagUsageType.java b/src/core/lombok/core/configuration/FlagUsageType.java index 8717c22b..293a2f1d 100644 --- a/src/core/lombok/core/configuration/FlagUsageType.java +++ b/src/core/lombok/core/configuration/FlagUsageType.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2014 The Project Lombok Authors. + * Copyright (C) 2014-2021 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,7 +21,7 @@ */ package lombok.core.configuration; -/** Used for lombok configuration to flag usages of certain lombok feature. */ +/** Used for lombok configuration to flag usages of certain lombok features. */ public enum FlagUsageType { WARNING, ERROR, ALLOW; } diff --git a/src/core/lombok/core/handlers/HandlerUtil.java b/src/core/lombok/core/handlers/HandlerUtil.java index f45481d4..c00b5dca 100644 --- a/src/core/lombok/core/handlers/HandlerUtil.java +++ b/src/core/lombok/core/handlers/HandlerUtil.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2013-2020 The Project Lombok Authors. + * Copyright (C) 2013-2021 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 @@ -46,6 +46,7 @@ import lombok.core.AnnotationValues; import lombok.core.JavaIdentifiers; import lombok.core.LombokNode; import lombok.core.configuration.AllowHelper; +import lombok.core.configuration.CapitalizationStrategy; import lombok.core.configuration.ConfigurationKey; import lombok.core.configuration.FlagUsageType; import lombok.experimental.Accessors; @@ -591,7 +592,7 @@ public class HandlerUtil { List<String> prefix = explicitPrefix ? Arrays.asList(ac.prefix()) : ast.readConfiguration(ConfigurationKeys.ACCESSORS_PREFIX); boolean fluent = explicitFluent ? ac.fluent() : Boolean.TRUE.equals(ast.readConfiguration(ConfigurationKeys.ACCESSORS_FLUENT)); - boolean javaBeansSpecCapitalization = explicitJavaBeansSpecCapitalization ? ac.javaBeansSpecCapitalization() : Boolean.TRUE.equals(ast.readConfiguration(ConfigurationKeys.ACCESSORS_JAVA_BEANS_SPEC_CAPITALIZATION)); + CapitalizationStrategy capitalizationStrategy = ast.readConfigurationOr(ConfigurationKeys.ACCESSORS_JAVA_BEANS_SPEC_CAPITALIZATION, CapitalizationStrategy.defaultValue()); fieldName = removePrefix(fieldName, prefix); if (fieldName == null) return null; @@ -604,7 +605,7 @@ public class HandlerUtil { return booleanPrefix + fName.substring(2); } - return buildAccessorName(isBoolean ? booleanPrefix : normalPrefix, fName, javaBeansSpecCapitalization); + return buildAccessorName(isBoolean ? booleanPrefix : normalPrefix, fName, capitalizationStrategy); } /** @@ -677,14 +678,13 @@ public class HandlerUtil { boolean explicitPrefix = accessors != null && accessors.isExplicit("prefix"); boolean explicitFluent = accessors != null && accessors.isExplicit("fluent"); - boolean explicitJavaBeansSpecCapitalization = accessors != null && accessors.isExplicit("javaBeansSpecCapitalization"); - Accessors ac = (explicitPrefix || explicitFluent || explicitJavaBeansSpecCapitalization) ? accessors.getInstance() : null; + Accessors ac = (explicitPrefix || explicitFluent) ? accessors.getInstance() : null; List<String> prefix = explicitPrefix ? Arrays.asList(ac.prefix()) : ast.readConfiguration(ConfigurationKeys.ACCESSORS_PREFIX); boolean fluent = explicitFluent ? ac.fluent() : Boolean.TRUE.equals(ast.readConfiguration(ConfigurationKeys.ACCESSORS_FLUENT)); - boolean javaBeansSpecCapitalization = explicitJavaBeansSpecCapitalization ? ac.javaBeansSpecCapitalization() : Boolean.TRUE.equals(ast.readConfiguration(ConfigurationKeys.ACCESSORS_JAVA_BEANS_SPEC_CAPITALIZATION)); - + CapitalizationStrategy capitalizationStrategy = ast.readConfigurationOr(ConfigurationKeys.ACCESSORS_JAVA_BEANS_SPEC_CAPITALIZATION, CapitalizationStrategy.defaultValue()); + fieldName = removePrefix(fieldName, prefix); if (fieldName == null) return Collections.emptyList(); @@ -695,8 +695,8 @@ public class HandlerUtil { if (adhereToFluent && fluent) { names.add(baseName); } else { - names.add(buildAccessorName(normalPrefix, baseName, javaBeansSpecCapitalization)); - if (!normalPrefix.equals(booleanPrefix)) names.add(buildAccessorName(booleanPrefix, baseName, javaBeansSpecCapitalization)); + names.add(buildAccessorName(normalPrefix, baseName, capitalizationStrategy)); + if (!normalPrefix.equals(booleanPrefix)) names.add(buildAccessorName(booleanPrefix, baseName, capitalizationStrategy)); } } @@ -722,40 +722,36 @@ public class HandlerUtil { } /** + * @param node Any node (used to fetch config of capitalization strategy). + * @param prefix Something like {@code get} or {@code set} or {@code is}. + * @param suffix Something like {@code running}. + * @return prefix + smartly title-cased suffix. For example, {@code setRunning}. + */ + public static String buildAccessorName(AST<?, ?, ?> ast, String prefix, String suffix) { + CapitalizationStrategy capitalizationStrategy = ast.readConfigurationOr(ConfigurationKeys.ACCESSORS_JAVA_BEANS_SPEC_CAPITALIZATION, CapitalizationStrategy.defaultValue()); + return buildAccessorName(prefix, suffix, capitalizationStrategy); + } + + /** + * @param node Any node (used to fetch config of capitalization strategy). * @param prefix Something like {@code get} or {@code set} or {@code is}. * @param suffix Something like {@code running}. * @return prefix + smartly title-cased suffix. For example, {@code setRunning}. */ - public static String buildAccessorName(String prefix, String suffix) { - return buildAccessorName(prefix, suffix, false); + public static String buildAccessorName(LombokNode<?, ?, ?> node, String prefix, String suffix) { + CapitalizationStrategy capitalizationStrategy = node.getAst().readConfigurationOr(ConfigurationKeys.ACCESSORS_JAVA_BEANS_SPEC_CAPITALIZATION, CapitalizationStrategy.defaultValue()); + return buildAccessorName(prefix, suffix, capitalizationStrategy); } /** * @param prefix Something like {@code get} or {@code set} or {@code is}. * @param suffix Something like {@code running}. - * @param shouldFollowJavaBeansSpecCapitalization {@code boolean} that indicates whether the capitalization rules should follow JavaBeanSpec - * @return if shouldFollowJavaBeansSpecCapitalization is {@code true} and name start with only single lowercase letter, returns simple suffix+prefix. For example, {@code setaFieldName} - * otherwise, returns prefix + smartly title-cased suffix. For example, {@code setRunning}. + * @param capitalizationStrategy Which strategy to use to capitalize the name part. */ - private static String buildAccessorName(String prefix, String suffix, boolean shouldFollowJavaBeansSpecCapitalization) { + private static String buildAccessorName(String prefix, String suffix, CapitalizationStrategy capitalizationStrategy) { if (suffix.length() == 0) return prefix; if (prefix.length() == 0) return suffix; - - char first = suffix.charAt(0); - if (!Character.isLowerCase(first)) { - return String.format("%s%s", prefix, suffix); - } - - boolean useUpperCase = suffix.length() > 2 && - (Character.isTitleCase(suffix.charAt(1)) || Character.isUpperCase(suffix.charAt(1))); - if (shouldFollowJavaBeansSpecCapitalization && useUpperCase) { - return String.format("%s%s", prefix, suffix); - } - - suffix = String.format("%s%s", - useUpperCase ? Character.toUpperCase(first) : Character.toTitleCase(first), - suffix.subSequence(1, suffix.length())); - return String.format("%s%s", prefix, suffix); + return prefix + capitalizationStrategy.capitalize(suffix); } public static String camelCaseToConstant(String fieldName) { diff --git a/src/core/lombok/eclipse/handlers/HandleBuilder.java b/src/core/lombok/eclipse/handlers/HandleBuilder.java index 82d3bfcf..2bfe1e8b 100755 --- a/src/core/lombok/eclipse/handlers/HandleBuilder.java +++ b/src/core/lombok/eclipse/handlers/HandleBuilder.java @@ -665,7 +665,7 @@ public class HandleBuilder extends EclipseAnnotationHandler<Builder> { for (BuilderFieldData bfd : job.builderFields) { String setterName = new String(bfd.name); String setterPrefix = !prefix.isEmpty() ? prefix : job.oldFluent ? "" : "set"; - if (!setterPrefix.isEmpty()) setterName = HandlerUtil.buildAccessorName(setterPrefix, setterName); + if (!setterPrefix.isEmpty()) setterName = HandlerUtil.buildAccessorName(job.sourceNode, setterPrefix, setterName); MessageSend ms = new MessageSend(); Expression[] tgt = new Expression[bfd.singularData == null ? 1 : 2]; @@ -1033,9 +1033,9 @@ public class HandleBuilder extends EclipseAnnotationHandler<Builder> { String setterPrefix = prefix.isEmpty() ? "set" : prefix; String setterName; if (job.oldFluent) { - setterName = prefix.isEmpty() ? new String(bfd.name) : HandlerUtil.buildAccessorName(setterPrefix, new String(bfd.name)); + setterName = prefix.isEmpty() ? new String(bfd.name) : HandlerUtil.buildAccessorName(job.sourceNode, setterPrefix, new String(bfd.name)); } else { - setterName = HandlerUtil.buildAccessorName(setterPrefix, new String(bfd.name)); + setterName = HandlerUtil.buildAccessorName(job.sourceNode, setterPrefix, new String(bfd.name)); } for (int i = 0; i < len; i++) { diff --git a/src/core/lombok/eclipse/handlers/HandleSuperBuilder.java b/src/core/lombok/eclipse/handlers/HandleSuperBuilder.java index 5bc6c125..26b62cbf 100644 --- a/src/core/lombok/eclipse/handlers/HandleSuperBuilder.java +++ b/src/core/lombok/eclipse/handlers/HandleSuperBuilder.java @@ -798,7 +798,7 @@ public class HandleSuperBuilder extends EclipseAnnotationHandler<SuperBuilder> { } private MessageSend createSetterCallWithInstanceValue(BuilderFieldData bfd, EclipseNode type, ASTNode source, String setterPrefix) { - char[] setterName = HandlerUtil.buildAccessorName(setterPrefix, String.valueOf(bfd.name)).toCharArray(); + char[] setterName = HandlerUtil.buildAccessorName(type, setterPrefix, String.valueOf(bfd.name)).toCharArray(); MessageSend ms = new MessageSend(); Expression[] tgt = new Expression[bfd.singularData == null ? 1 : 2]; @@ -1004,7 +1004,7 @@ public class HandleSuperBuilder extends EclipseAnnotationHandler<SuperBuilder> { if (existing == null) existing = EMPTY_METHODS; int len = existing.length; - String setterName = HandlerUtil.buildAccessorName(setterPrefix, new String(paramName)); + String setterName = HandlerUtil.buildAccessorName(job.sourceNode, setterPrefix, new String(paramName)); for (int i = 0; i < len; i++) { if (!(existing[i] instanceof MethodDeclaration)) continue; diff --git a/src/core/lombok/eclipse/handlers/singulars/EclipseGuavaSingularizer.java b/src/core/lombok/eclipse/handlers/singulars/EclipseGuavaSingularizer.java index 7dcf18c9..9b464a25 100755 --- a/src/core/lombok/eclipse/handlers/singulars/EclipseGuavaSingularizer.java +++ b/src/core/lombok/eclipse/handlers/singulars/EclipseGuavaSingularizer.java @@ -126,7 +126,7 @@ abstract class EclipseGuavaSingularizer extends EclipseSingularizer { FieldReference thisDotField = new FieldReference(data.getPluralName(), 0L); thisDotField.receiver = new ThisReference(0, 0); Assignment a = new Assignment(thisDotField, new NullLiteral(0, 0), 0); - md.selector = HandlerUtil.buildAccessorName("clear", new String(data.getPluralName())).toCharArray(); + md.selector = HandlerUtil.buildAccessorName(builderType, "clear", new String(data.getPluralName())).toCharArray(); md.statements = returnStatement != null ? new Statement[] {a, returnStatement} : new Statement[] {a}; md.returnType = returnType; md.annotations = generateSelfReturnAnnotations(deprecate, cfv, data.getSource()); @@ -173,8 +173,8 @@ abstract class EclipseGuavaSingularizer extends EclipseSingularizer { md.arguments[i].annotations = typeUseAnns; } md.returnType = returnType; - char[] prefixedSingularName = data.getSetterPrefix().length == 0 ? data.getSingularName() : HandlerUtil.buildAccessorName(new String(data.getSetterPrefix()), new String(data.getSingularName())).toCharArray(); - md.selector = fluent ? prefixedSingularName : HandlerUtil.buildAccessorName("add", new String(data.getSingularName())).toCharArray(); + char[] prefixedSingularName = data.getSetterPrefix().length == 0 ? data.getSingularName() : HandlerUtil.buildAccessorName(builderType, new String(data.getSetterPrefix()), new String(data.getSingularName())).toCharArray(); + md.selector = fluent ? prefixedSingularName : HandlerUtil.buildAccessorName(builderType, "add", new String(data.getSingularName())).toCharArray(); Annotation[] selfReturnAnnotations = generateSelfReturnAnnotations(deprecate, cfv, data.getSource()); Annotation[] copyToSetterAnnotations = copyAnnotations(md, findCopyableToBuilderSingularSetterAnnotations(data.getAnnotation().up())); md.annotations = concat(selfReturnAnnotations, copyToSetterAnnotations, Annotation.class); @@ -213,8 +213,8 @@ abstract class EclipseGuavaSingularizer extends EclipseSingularizer { md.arguments = new Argument[] {param}; md.returnType = returnType; - char[] prefixedSelector = data.getSetterPrefix().length == 0 ? data.getPluralName() : HandlerUtil.buildAccessorName(new String(data.getSetterPrefix()), new String(data.getPluralName())).toCharArray(); - md.selector = fluent ? prefixedSelector : HandlerUtil.buildAccessorName("addAll", new String(data.getPluralName())).toCharArray(); + char[] prefixedSelector = data.getSetterPrefix().length == 0 ? data.getPluralName() : HandlerUtil.buildAccessorName(builderType, new String(data.getSetterPrefix()), new String(data.getPluralName())).toCharArray(); + md.selector = fluent ? prefixedSelector : HandlerUtil.buildAccessorName(builderType, "addAll", new String(data.getPluralName())).toCharArray(); Annotation[] selfReturnAnnotations = generateSelfReturnAnnotations(deprecate, cfv, data.getSource()); Annotation[] copyToSetterAnnotations = copyAnnotations(md, findCopyableToSetterAnnotations(data.getAnnotation().up())); md.annotations = concat(selfReturnAnnotations, copyToSetterAnnotations, Annotation.class); diff --git a/src/core/lombok/eclipse/handlers/singulars/EclipseJavaUtilListSetSingularizer.java b/src/core/lombok/eclipse/handlers/singulars/EclipseJavaUtilListSetSingularizer.java index 882b7adc..6f5e9add 100755 --- a/src/core/lombok/eclipse/handlers/singulars/EclipseJavaUtilListSetSingularizer.java +++ b/src/core/lombok/eclipse/handlers/singulars/EclipseJavaUtilListSetSingularizer.java @@ -112,7 +112,7 @@ abstract class EclipseJavaUtilListSetSingularizer extends EclipseJavaUtilSingula thisDotField.receiver = new ThisReference(0, 0); FieldReference thisDotField2 = new FieldReference(data.getPluralName(), 0L); thisDotField2.receiver = new ThisReference(0, 0); - md.selector = HandlerUtil.buildAccessorName("clear", new String(data.getPluralName())).toCharArray(); + md.selector = HandlerUtil.buildAccessorName(builderType, "clear", new String(data.getPluralName())).toCharArray(); MessageSend clearMsg = new MessageSend(); clearMsg.receiver = thisDotField2; clearMsg.selector = "clear".toCharArray(); @@ -151,8 +151,8 @@ abstract class EclipseJavaUtilListSetSingularizer extends EclipseJavaUtilSingula param.annotations = typeUseAnns; md.arguments = new Argument[] {param}; md.returnType = returnType; - char[] prefixedSingularName = data.getSetterPrefix().length == 0 ? data.getSingularName() : HandlerUtil.buildAccessorName(new String(data.getSetterPrefix()), new String(data.getSingularName())).toCharArray(); - md.selector = fluent ? prefixedSingularName : HandlerUtil.buildAccessorName("add", new String(data.getSingularName())).toCharArray(); + char[] prefixedSingularName = data.getSetterPrefix().length == 0 ? data.getSingularName() : HandlerUtil.buildAccessorName(builderType, new String(data.getSetterPrefix()), new String(data.getSingularName())).toCharArray(); + md.selector = fluent ? prefixedSingularName : HandlerUtil.buildAccessorName(builderType, "add", new String(data.getSingularName())).toCharArray(); Annotation[] selfReturnAnnotations = generateSelfReturnAnnotations(deprecate, cfv, data.getSource()); Annotation[] copyToSetterAnnotations = copyAnnotations(md, findCopyableToBuilderSingularSetterAnnotations(data.getAnnotation().up())); md.annotations = concat(selfReturnAnnotations, copyToSetterAnnotations, Annotation.class); @@ -189,8 +189,8 @@ abstract class EclipseJavaUtilListSetSingularizer extends EclipseJavaUtilSingula md.arguments = new Argument[] {param}; md.returnType = returnType; - char[] prefixedSelector = data.getSetterPrefix().length == 0 ? data.getPluralName() : HandlerUtil.buildAccessorName(new String(data.getSetterPrefix()), new String(data.getPluralName())).toCharArray(); - md.selector = fluent ? prefixedSelector : HandlerUtil.buildAccessorName("addAll", new String(data.getPluralName())).toCharArray(); + char[] prefixedSelector = data.getSetterPrefix().length == 0 ? data.getPluralName() : HandlerUtil.buildAccessorName(builderType, new String(data.getSetterPrefix()), new String(data.getPluralName())).toCharArray(); + md.selector = fluent ? prefixedSelector : HandlerUtil.buildAccessorName(builderType, "addAll", new String(data.getPluralName())).toCharArray(); Annotation[] selfReturnAnnotations = generateSelfReturnAnnotations(deprecate, cfv, data.getSource()); Annotation[] copyToSetterAnnotations = copyAnnotations(md, findCopyableToSetterAnnotations(data.getAnnotation().up())); md.annotations = concat(selfReturnAnnotations, copyToSetterAnnotations, Annotation.class); diff --git a/src/core/lombok/eclipse/handlers/singulars/EclipseJavaUtilMapSingularizer.java b/src/core/lombok/eclipse/handlers/singulars/EclipseJavaUtilMapSingularizer.java index a766612f..c28ba59d 100755 --- a/src/core/lombok/eclipse/handlers/singulars/EclipseJavaUtilMapSingularizer.java +++ b/src/core/lombok/eclipse/handlers/singulars/EclipseJavaUtilMapSingularizer.java @@ -177,7 +177,7 @@ public class EclipseJavaUtilMapSingularizer extends EclipseJavaUtilSingularizer thisDotField2.receiver = new ThisReference(0, 0); FieldReference thisDotField3 = new FieldReference(valueFieldName, 0L); thisDotField3.receiver = new ThisReference(0, 0); - md.selector = HandlerUtil.buildAccessorName("clear", new String(data.getPluralName())).toCharArray(); + md.selector = HandlerUtil.buildAccessorName(builderType, "clear", new String(data.getPluralName())).toCharArray(); MessageSend clearMsg1 = new MessageSend(); clearMsg1.receiver = thisDotField2; clearMsg1.selector = "clear".toCharArray(); @@ -249,7 +249,7 @@ public class EclipseJavaUtilMapSingularizer extends EclipseJavaUtilSingularizer String name = new String(data.getSingularName()); String setterPrefix = data.getSetterPrefix().length > 0 ? new String(data.getSetterPrefix()) : fluent ? "" : "put"; - String setterName = HandlerUtil.buildAccessorName(setterPrefix, name); + String setterName = HandlerUtil.buildAccessorName(builderType, setterPrefix, name); md.selector = setterName.toCharArray(); Annotation[] selfReturnAnnotations = generateSelfReturnAnnotations(deprecate, cfv, data.getSource()); @@ -325,7 +325,7 @@ public class EclipseJavaUtilMapSingularizer extends EclipseJavaUtilSingularizer String name = new String(data.getPluralName()); String setterPrefix = data.getSetterPrefix().length > 0 ? new String(data.getSetterPrefix()) : fluent ? "" : "put"; - String setterName = HandlerUtil.buildAccessorName(setterPrefix, name); + String setterName = HandlerUtil.buildAccessorName(builderType, setterPrefix, name); md.selector = setterName.toCharArray(); Annotation[] selfReturnAnnotations = generateSelfReturnAnnotations(deprecate, cfv, data.getSource()); diff --git a/src/core/lombok/experimental/Accessors.java b/src/core/lombok/experimental/Accessors.java index b3da9a5b..dc9ae4b0 100644 --- a/src/core/lombok/experimental/Accessors.java +++ b/src/core/lombok/experimental/Accessors.java @@ -55,15 +55,6 @@ public @interface Accessors { boolean chain() default false; /** - * If true, accessors names will be capitalized according to JavaBeans capitalization rules. - * If {@code true}, an accessor for a field that starts with a single lowercase letter followed by a capital letter, - * wont capitalize the first letter (named {@code getaFieldName()}, not for example {@code getAFieldName}). - * <strong>default: false</strong> - * @return - */ - boolean javaBeansSpecCapitalization() default false; - - /** * If present, only fields with any of the stated prefixes are given the getter/setter treatment. * Note that a prefix only counts if the next character is NOT a lowercase character or the last * letter of the prefix is not a letter (for instance an underscore). If multiple fields diff --git a/src/core/lombok/javac/handlers/HandleBuilder.java b/src/core/lombok/javac/handlers/HandleBuilder.java index bb852b55..d8fdfb1b 100644 --- a/src/core/lombok/javac/handlers/HandleBuilder.java +++ b/src/core/lombok/javac/handlers/HandleBuilder.java @@ -636,7 +636,7 @@ public class HandleBuilder extends JavacAnnotationHandler<Builder> { for (BuilderFieldData bfd : job.builderFields) { String setterPrefix = !prefix.isEmpty() ? prefix : job.oldFluent ? "" : "set"; String prefixedSetterName = bfd.name.toString(); - if (!setterPrefix.isEmpty()) prefixedSetterName = HandlerUtil.buildAccessorName(setterPrefix, prefixedSetterName); + if (!setterPrefix.isEmpty()) prefixedSetterName = HandlerUtil.buildAccessorName(job.sourceNode, setterPrefix, prefixedSetterName); Name setterName = job.toName(prefixedSetterName); JCExpression[] tgt = new JCExpression[bfd.singularData == null ? 1 : 2]; @@ -901,7 +901,7 @@ public class HandleBuilder extends JavacAnnotationHandler<Builder> { private void makePrefixedSetterMethodForBuilder(BuilderJob job, BuilderFieldData bfd, boolean deprecate, String prefix) { JavacNode fieldNode = bfd.createdFields.get(0); String setterPrefix = !prefix.isEmpty() ? prefix : job.oldFluent ? "" : "set"; - String setterName = HandlerUtil.buildAccessorName(setterPrefix, bfd.name.toString()); + String setterName = HandlerUtil.buildAccessorName(job.sourceNode, setterPrefix, bfd.name.toString()); Name setterName_ = job.builderType.toName(setterName); for (JavacNode child : job.builderType.down()) { diff --git a/src/core/lombok/javac/handlers/HandleSuperBuilder.java b/src/core/lombok/javac/handlers/HandleSuperBuilder.java index 50193f99..b5bc73fb 100644 --- a/src/core/lombok/javac/handlers/HandleSuperBuilder.java +++ b/src/core/lombok/javac/handlers/HandleSuperBuilder.java @@ -777,7 +777,7 @@ public class HandleSuperBuilder extends JavacAnnotationHandler<SuperBuilder> { arg = maker.Conditional(eqNull, emptyCollection, tgt[1]); } - String setterName = HandlerUtil.buildAccessorName(setterPrefix, bfd.name.toString()); + String setterName = HandlerUtil.buildAccessorName(job.sourceNode, setterPrefix, bfd.name.toString()); JCMethodInvocation apply = maker.Apply(List.<JCExpression>nil(), maker.Select(maker.Ident(job.toName(BUILDER_VARIABLE_NAME)), job.toName(setterName)), List.of(arg)); JCExpressionStatement exec = maker.Exec(apply); return exec; @@ -949,7 +949,7 @@ public class HandleSuperBuilder extends JavacAnnotationHandler<SuperBuilder> { } private void generateSimpleSetterMethodForBuilder(SuperBuilderJob job, boolean deprecate, JavacNode fieldNode, Name paramName, Name nameOfSetFlag, JCExpression returnType, JCStatement returnStatement, List<JCAnnotation> annosOnParam, JavacNode originalFieldNode, String setterPrefix) { - String setterName = HandlerUtil.buildAccessorName(setterPrefix, paramName.toString()); + String setterName = HandlerUtil.buildAccessorName(job.sourceNode, setterPrefix, paramName.toString()); Name setterName_ = job.builderType.toName(setterName); for (JavacNode child : job.builderType.down()) { diff --git a/src/core/lombok/javac/handlers/JavacSingularsRecipes.java b/src/core/lombok/javac/handlers/JavacSingularsRecipes.java index 4ca09b82..77fcd4ea 100644 --- a/src/core/lombok/javac/handlers/JavacSingularsRecipes.java +++ b/src/core/lombok/javac/handlers/JavacSingularsRecipes.java @@ -300,7 +300,7 @@ public class JavacSingularsRecipes { ListBuffer<JCStatement> statements = new ListBuffer<JCStatement>(); statements.append(clearStatement); - Name methodName = builderType.toName(HandlerUtil.buildAccessorName("clear", data.getPluralName().toString())); + Name methodName = builderType.toName(HandlerUtil.buildAccessorName(source, "clear", data.getPluralName().toString())); finishAndInjectMethod(cfv, maker, returnType, returnStatement, data, builderType, source, deprecate, statements, methodName, List.<JCVariableDecl>nil(), List.<JCAnnotation>nil(), access, null); } @@ -312,7 +312,7 @@ public class JavacSingularsRecipes { Name name = data.getSingularName(); String setterPrefix = data.getSetterPrefix(); if (setterPrefix.isEmpty() && !fluent) setterPrefix = getAddMethodName(); - if (!setterPrefix.isEmpty()) name = builderType.toName(HandlerUtil.buildAccessorName(setterPrefix, name.toString())); + if (!setterPrefix.isEmpty()) name = builderType.toName(HandlerUtil.buildAccessorName(source, setterPrefix, name.toString())); statements.prepend(createConstructBuilderVarIfNeeded(maker, data, builderType, source)); List<JCAnnotation> methodAnnotations = copyAnnotations(findCopyableToBuilderSingularSetterAnnotations(data.annotation.up())); @@ -344,7 +344,7 @@ public class JavacSingularsRecipes { Name name = data.getPluralName(); String setterPrefix = data.getSetterPrefix(); if (setterPrefix.isEmpty() && !fluent) setterPrefix = getAddMethodName() + "All"; - if (!setterPrefix.isEmpty()) name = builderType.toName(HandlerUtil.buildAccessorName(setterPrefix, name.toString())); + if (!setterPrefix.isEmpty()) name = builderType.toName(HandlerUtil.buildAccessorName(source, setterPrefix, name.toString())); JCExpression paramType = getPluralMethodParamType(builderType); paramType = addTypeArgs(getTypeArgumentsCount(), true, builderType, paramType, data.getTypeArgs(), source); long paramFlags = JavacHandlerUtil.addFinalIfNeeded(Flags.PARAMETER, builderType.getContext()); diff --git a/test/transform/resource/after-delombok/BuilderWithJavaBeansSpecCapitalization.java b/test/transform/resource/after-delombok/BuilderWithJavaBeansSpecCapitalization.java new file mode 100644 index 00000000..4a21f2c3 --- /dev/null +++ b/test/transform/resource/after-delombok/BuilderWithJavaBeansSpecCapitalization.java @@ -0,0 +1,106 @@ +class BuilderWithJavaBeansSpecCapitalization { + java.util.List<String> a; + java.util.List<String> aField; + String bField; + @java.lang.SuppressWarnings("all") + BuilderWithJavaBeansSpecCapitalization(final java.util.List<String> a, final java.util.List<String> aField, final String bField) { + this.a = a; + this.aField = aField; + this.bField = bField; + } + @java.lang.SuppressWarnings("all") + public static class BuilderWithJavaBeansSpecCapitalizationBuilder { + @java.lang.SuppressWarnings("all") + private java.util.ArrayList<String> a; + @java.lang.SuppressWarnings("all") + private java.util.ArrayList<String> aField; + @java.lang.SuppressWarnings("all") + private String bField; + @java.lang.SuppressWarnings("all") + BuilderWithJavaBeansSpecCapitalizationBuilder() { + } + @java.lang.SuppressWarnings("all") + public BuilderWithJavaBeansSpecCapitalization.BuilderWithJavaBeansSpecCapitalizationBuilder setZ(final String z) { + if (this.a == null) this.a = new java.util.ArrayList<String>(); + this.a.add(z); + return this; + } + @java.lang.SuppressWarnings("all") + public BuilderWithJavaBeansSpecCapitalization.BuilderWithJavaBeansSpecCapitalizationBuilder setA(final java.util.Collection<? extends String> a) { + if (a == null) { + throw new java.lang.NullPointerException("a cannot be null"); + } + if (this.a == null) this.a = new java.util.ArrayList<String>(); + this.a.addAll(a); + return this; + } + @java.lang.SuppressWarnings("all") + public BuilderWithJavaBeansSpecCapitalization.BuilderWithJavaBeansSpecCapitalizationBuilder clearA() { + if (this.a != null) this.a.clear(); + return this; + } + @java.lang.SuppressWarnings("all") + public BuilderWithJavaBeansSpecCapitalization.BuilderWithJavaBeansSpecCapitalizationBuilder setyField(final String yField) { + if (this.aField == null) this.aField = new java.util.ArrayList<String>(); + this.aField.add(yField); + return this; + } + @java.lang.SuppressWarnings("all") + public BuilderWithJavaBeansSpecCapitalization.BuilderWithJavaBeansSpecCapitalizationBuilder setaField(final java.util.Collection<? extends String> aField) { + if (aField == null) { + throw new java.lang.NullPointerException("aField cannot be null"); + } + if (this.aField == null) this.aField = new java.util.ArrayList<String>(); + this.aField.addAll(aField); + return this; + } + @java.lang.SuppressWarnings("all") + public BuilderWithJavaBeansSpecCapitalization.BuilderWithJavaBeansSpecCapitalizationBuilder clearaField() { + if (this.aField != null) this.aField.clear(); + return this; + } + /** + * @return {@code this}. + */ + @java.lang.SuppressWarnings("all") + public BuilderWithJavaBeansSpecCapitalization.BuilderWithJavaBeansSpecCapitalizationBuilder setbField(final String bField) { + this.bField = bField; + return this; + } + @java.lang.SuppressWarnings("all") + public BuilderWithJavaBeansSpecCapitalization build() { + java.util.List<String> a; + switch (this.a == null ? 0 : this.a.size()) { + case 0: + a = java.util.Collections.emptyList(); + break; + case 1: + a = java.util.Collections.singletonList(this.a.get(0)); + break; + default: + a = java.util.Collections.unmodifiableList(new java.util.ArrayList<String>(this.a)); + } + java.util.List<String> aField; + switch (this.aField == null ? 0 : this.aField.size()) { + case 0: + aField = java.util.Collections.emptyList(); + break; + case 1: + aField = java.util.Collections.singletonList(this.aField.get(0)); + break; + default: + aField = java.util.Collections.unmodifiableList(new java.util.ArrayList<String>(this.aField)); + } + return new BuilderWithJavaBeansSpecCapitalization(a, aField, this.bField); + } + @java.lang.Override + @java.lang.SuppressWarnings("all") + public java.lang.String toString() { + return "BuilderWithJavaBeansSpecCapitalization.BuilderWithJavaBeansSpecCapitalizationBuilder(a=" + this.a + ", aField=" + this.aField + ", bField=" + this.bField + ")"; + } + } + @java.lang.SuppressWarnings("all") + public static BuilderWithJavaBeansSpecCapitalization.BuilderWithJavaBeansSpecCapitalizationBuilder builder() { + return new BuilderWithJavaBeansSpecCapitalization.BuilderWithJavaBeansSpecCapitalizationBuilder(); + } +}
\ No newline at end of file diff --git a/test/transform/resource/after-delombok/GetterWithJavaBeansSpecCapitalization.java b/test/transform/resource/after-delombok/GetterWithJavaBeansSpecCapitalization.java index 06026c1b..51ccfe63 100644 --- a/test/transform/resource/after-delombok/GetterWithJavaBeansSpecCapitalization.java +++ b/test/transform/resource/after-delombok/GetterWithJavaBeansSpecCapitalization.java @@ -1,17 +1,3 @@ -class GetterWithoutJavaBeansSpecCapitalization { - int a; - int aField; - @java.lang.SuppressWarnings("all") - public int getA() { - return this.a; - } - @java.lang.SuppressWarnings("all") - public int getAField() { - return this.aField; - } -} - - class GetterWithJavaBeansSpecCapitalization { int a; int aField; @@ -23,6 +9,4 @@ class GetterWithJavaBeansSpecCapitalization { public int getaField() { return this.aField; } -} - - +}
\ No newline at end of file diff --git a/test/transform/resource/after-delombok/SetterWithJavaBeansSpecCapitalization.java b/test/transform/resource/after-delombok/SetterWithJavaBeansSpecCapitalization.java index 24c8e883..de68ee60 100644 --- a/test/transform/resource/after-delombok/SetterWithJavaBeansSpecCapitalization.java +++ b/test/transform/resource/after-delombok/SetterWithJavaBeansSpecCapitalization.java @@ -1,16 +1,3 @@ -class SetterWithoutJavaBeansSpecCapitalization { - int a; - int aField; - @java.lang.SuppressWarnings("all") - public void setA(final int a) { - this.a = a; - } - @java.lang.SuppressWarnings("all") - public void setAField(final int aField) { - this.aField = aField; - } -} - class SetterWithJavaBeansSpecCapitalization { int a; int aField; @@ -23,5 +10,3 @@ class SetterWithJavaBeansSpecCapitalization { this.aField = aField; } } - - diff --git a/test/transform/resource/after-delombok/ValueWithJavaBeansSpecCapitalization.java b/test/transform/resource/after-delombok/ValueWithJavaBeansSpecCapitalization.java index 20139baf..b92dd5b6 100644 --- a/test/transform/resource/after-delombok/ValueWithJavaBeansSpecCapitalization.java +++ b/test/transform/resource/after-delombok/ValueWithJavaBeansSpecCapitalization.java @@ -1,16 +1,13 @@ final class ValueWithJavaBeansSpecCapitalization { private final int aField; - @java.lang.SuppressWarnings("all") public ValueWithJavaBeansSpecCapitalization(final int aField) { this.aField = aField; } - @java.lang.SuppressWarnings("all") public int getaField() { return this.aField; } - @java.lang.Override @java.lang.SuppressWarnings("all") public boolean equals(final java.lang.Object o) { @@ -20,7 +17,6 @@ final class ValueWithJavaBeansSpecCapitalization { if (this.getaField() != other.getaField()) return false; return true; } - @java.lang.Override @java.lang.SuppressWarnings("all") public int hashCode() { @@ -29,27 +25,22 @@ final class ValueWithJavaBeansSpecCapitalization { result = result * PRIME + this.getaField(); return result; } - @java.lang.Override @java.lang.SuppressWarnings("all") public java.lang.String toString() { return "ValueWithJavaBeansSpecCapitalization(aField=" + this.getaField() + ")"; } } - final class ValueWithoutJavaBeansSpecCapitalization { private final int aField; - @java.lang.SuppressWarnings("all") public ValueWithoutJavaBeansSpecCapitalization(final int aField) { this.aField = aField; } - @java.lang.SuppressWarnings("all") public int getAField() { return this.aField; } - @java.lang.Override @java.lang.SuppressWarnings("all") public boolean equals(final java.lang.Object o) { @@ -59,7 +50,6 @@ final class ValueWithoutJavaBeansSpecCapitalization { if (this.getAField() != other.getAField()) return false; return true; } - @java.lang.Override @java.lang.SuppressWarnings("all") public int hashCode() { @@ -68,7 +58,6 @@ final class ValueWithoutJavaBeansSpecCapitalization { result = result * PRIME + this.getAField(); return result; } - @java.lang.Override @java.lang.SuppressWarnings("all") public java.lang.String toString() { diff --git a/test/transform/resource/after-delombok/WithOnJavaBeansSpecCapitalization.java b/test/transform/resource/after-delombok/WithOnJavaBeansSpecCapitalization.java deleted file mode 100644 index afed2f0e..00000000 --- a/test/transform/resource/after-delombok/WithOnJavaBeansSpecCapitalization.java +++ /dev/null @@ -1,29 +0,0 @@ -class WithOnJavaBeansSpecCapitalization { - int aField; - - WithOnJavaBeansSpecCapitalization(int aField) { - } - - /** - * @return a clone of this object, except with this updated property (returns {@code this} if an identical value is passed). - */ - @java.lang.SuppressWarnings("all") - public WithOnJavaBeansSpecCapitalization withaField(final int aField) { - return this.aField == aField ? this : new WithOnJavaBeansSpecCapitalization(aField); - } -} - -class WithOffJavaBeansSpecCapitalization { - int aField; - - WithOffJavaBeansSpecCapitalization(int aField) { - } - - /** - * @return a clone of this object, except with this updated property (returns {@code this} if an identical value is passed). - */ - @java.lang.SuppressWarnings("all") - public WithOffJavaBeansSpecCapitalization withAField(final int aField) { - return this.aField == aField ? this : new WithOffJavaBeansSpecCapitalization(aField); - } -} diff --git a/test/transform/resource/after-delombok/WithWithJavaBeansSpecCapitalization.java b/test/transform/resource/after-delombok/WithWithJavaBeansSpecCapitalization.java new file mode 100644 index 00000000..e3737848 --- /dev/null +++ b/test/transform/resource/after-delombok/WithWithJavaBeansSpecCapitalization.java @@ -0,0 +1,12 @@ +class WithWithJavaBeansSpecCapitalization { + int aField; + WithWithJavaBeansSpecCapitalization(int aField) { + } + /** + * @return a clone of this object, except with this updated property (returns {@code this} if an identical value is passed). + */ + @java.lang.SuppressWarnings("all") + public WithWithJavaBeansSpecCapitalization withaField(final int aField) { + return this.aField == aField ? this : new WithWithJavaBeansSpecCapitalization(aField); + } +} diff --git a/test/transform/resource/after-ecj/BuilderWithJavaBeansSpecCapitalization.java b/test/transform/resource/after-ecj/BuilderWithJavaBeansSpecCapitalization.java new file mode 100644 index 00000000..1107254f --- /dev/null +++ b/test/transform/resource/after-ecj/BuilderWithJavaBeansSpecCapitalization.java @@ -0,0 +1,99 @@ +@lombok.Builder(setterPrefix = "set") class BuilderWithJavaBeansSpecCapitalization { + public static @java.lang.SuppressWarnings("all") class BuilderWithJavaBeansSpecCapitalizationBuilder { + private @java.lang.SuppressWarnings("all") java.util.ArrayList<String> a; + private @java.lang.SuppressWarnings("all") java.util.ArrayList<String> aField; + private @java.lang.SuppressWarnings("all") String bField; + @java.lang.SuppressWarnings("all") BuilderWithJavaBeansSpecCapitalizationBuilder() { + super(); + } + public @java.lang.SuppressWarnings("all") BuilderWithJavaBeansSpecCapitalization.BuilderWithJavaBeansSpecCapitalizationBuilder setZ(final String z) { + if ((this.a == null)) + this.a = new java.util.ArrayList<String>(); + this.a.add(z); + return this; + } + public @java.lang.SuppressWarnings("all") BuilderWithJavaBeansSpecCapitalization.BuilderWithJavaBeansSpecCapitalizationBuilder setA(final java.util.Collection<? extends String> a) { + if ((a == null)) + { + throw new java.lang.NullPointerException("a cannot be null"); + } + if ((this.a == null)) + this.a = new java.util.ArrayList<String>(); + this.a.addAll(a); + return this; + } + public @java.lang.SuppressWarnings("all") BuilderWithJavaBeansSpecCapitalization.BuilderWithJavaBeansSpecCapitalizationBuilder clearA() { + if ((this.a != null)) + this.a.clear(); + return this; + } + public @java.lang.SuppressWarnings("all") BuilderWithJavaBeansSpecCapitalization.BuilderWithJavaBeansSpecCapitalizationBuilder setyField(final String yField) { + if ((this.aField == null)) + this.aField = new java.util.ArrayList<String>(); + this.aField.add(yField); + return this; + } + public @java.lang.SuppressWarnings("all") BuilderWithJavaBeansSpecCapitalization.BuilderWithJavaBeansSpecCapitalizationBuilder setaField(final java.util.Collection<? extends String> aField) { + if ((aField == null)) + { + throw new java.lang.NullPointerException("aField cannot be null"); + } + if ((this.aField == null)) + this.aField = new java.util.ArrayList<String>(); + this.aField.addAll(aField); + return this; + } + public @java.lang.SuppressWarnings("all") BuilderWithJavaBeansSpecCapitalization.BuilderWithJavaBeansSpecCapitalizationBuilder clearaField() { + if ((this.aField != null)) + this.aField.clear(); + return this; + } + /** + * @return {@code this}. + */ + public @java.lang.SuppressWarnings("all") BuilderWithJavaBeansSpecCapitalization.BuilderWithJavaBeansSpecCapitalizationBuilder setbField(final String bField) { + this.bField = bField; + return this; + } + public @java.lang.SuppressWarnings("all") BuilderWithJavaBeansSpecCapitalization build() { + java.util.List<String> a; + switch (((this.a == null) ? 0 : this.a.size())) { + case 0 : + a = java.util.Collections.emptyList(); + break; + case 1 : + a = java.util.Collections.singletonList(this.a.get(0)); + break; + default : + a = java.util.Collections.unmodifiableList(new java.util.ArrayList<String>(this.a)); + } + java.util.List<String> aField; + switch (((this.aField == null) ? 0 : this.aField.size())) { + case 0 : + aField = java.util.Collections.emptyList(); + break; + case 1 : + aField = java.util.Collections.singletonList(this.aField.get(0)); + break; + default : + aField = java.util.Collections.unmodifiableList(new java.util.ArrayList<String>(this.aField)); + } + return new BuilderWithJavaBeansSpecCapitalization(a, aField, this.bField); + } + public @java.lang.Override @java.lang.SuppressWarnings("all") java.lang.String toString() { + return (((((("BuilderWithJavaBeansSpecCapitalization.BuilderWithJavaBeansSpecCapitalizationBuilder(a=" + this.a) + ", aField=") + this.aField) + ", bField=") + this.bField) + ")"); + } + } + @lombok.Singular("z") java.util.List<String> a; + @lombok.Singular("yField") java.util.List<String> aField; + String bField; + @java.lang.SuppressWarnings("all") BuilderWithJavaBeansSpecCapitalization(final java.util.List<String> a, final java.util.List<String> aField, final String bField) { + super(); + this.a = a; + this.aField = aField; + this.bField = bField; + } + public static @java.lang.SuppressWarnings("all") BuilderWithJavaBeansSpecCapitalization.BuilderWithJavaBeansSpecCapitalizationBuilder builder() { + return new BuilderWithJavaBeansSpecCapitalization.BuilderWithJavaBeansSpecCapitalizationBuilder(); + } +} diff --git a/test/transform/resource/after-ecj/GetterWithJavaBeansSpecCapitalization.java b/test/transform/resource/after-ecj/GetterWithJavaBeansSpecCapitalization.java index d605b4ac..745529a0 100644 --- a/test/transform/resource/after-ecj/GetterWithJavaBeansSpecCapitalization.java +++ b/test/transform/resource/after-ecj/GetterWithJavaBeansSpecCapitalization.java @@ -1,33 +1,13 @@ -class GetterWithoutJavaBeansSpecCapitalization { +class GetterWithJavaBeansSpecCapitalization { @lombok.Getter int a; @lombok.Getter int aField; - - GetterWithoutJavaBeansSpecCapitalization() { - super(); - } - - public @java.lang.SuppressWarnings("all") int getA() { - return this.a; - } - - public @java.lang.SuppressWarnings("all") int getAField() { - return this.aField; - } -} - -@lombok.experimental.Accessors(javaBeansSpecCapitalization = true) class GetterWithJavaBeansSpecCapitalization { - @lombok.Getter int a; - @lombok.Getter int aField; - GetterWithJavaBeansSpecCapitalization() { super(); } - public @java.lang.SuppressWarnings("all") int getA() { return this.a; } - public @java.lang.SuppressWarnings("all") int getaField() { return this.aField; } -} +}
\ No newline at end of file diff --git a/test/transform/resource/after-ecj/SetterWithJavaBeansSpecCapitalization.java b/test/transform/resource/after-ecj/SetterWithJavaBeansSpecCapitalization.java index 9907621f..4e99890a 100644 --- a/test/transform/resource/after-ecj/SetterWithJavaBeansSpecCapitalization.java +++ b/test/transform/resource/after-ecj/SetterWithJavaBeansSpecCapitalization.java @@ -1,33 +1,13 @@ -class SetterWithoutJavaBeansSpecCapitalization { +class SetterWithJavaBeansSpecCapitalization { @lombok.Setter int a; @lombok.Setter int aField; - - SetterWithoutJavaBeansSpecCapitalization() { - super(); - } - - public @java.lang.SuppressWarnings("all") void setA(final int a) { - this.a = a; - } - - public @java.lang.SuppressWarnings("all") void setAField(final int aField) { - this.aField = aField; - } -} - -@lombok.experimental.Accessors(javaBeansSpecCapitalization = true) class SetterWithJavaBeansSpecCapitalization { - @lombok.Setter int a; - @lombok.Setter int aField; - SetterWithJavaBeansSpecCapitalization() { super(); } - public @java.lang.SuppressWarnings("all") void setA(final int a) { this.a = a; } - public @java.lang.SuppressWarnings("all") void setaField(final int aField) { this.aField = aField; } -} +}
\ No newline at end of file diff --git a/test/transform/resource/after-ecj/ValueWithJavaBeansSpecCapitalization.java b/test/transform/resource/after-ecj/ValueWithJavaBeansSpecCapitalization.java index f41fcf58..8117dbb0 100644 --- a/test/transform/resource/after-ecj/ValueWithJavaBeansSpecCapitalization.java +++ b/test/transform/resource/after-ecj/ValueWithJavaBeansSpecCapitalization.java @@ -1,4 +1,4 @@ -final @lombok.Value @lombok.experimental.Accessors(javaBeansSpecCapitalization = true) class ValueWithJavaBeansSpecCapitalization { +final @lombok.Value class ValueWithJavaBeansSpecCapitalization { private final int aField; public @java.lang.SuppressWarnings("all") int getaField() { return this.aField; @@ -27,32 +27,3 @@ final @lombok.Value @lombok.experimental.Accessors(javaBeansSpecCapitalization = this.aField = aField; } } -final @lombok.Value class ValueWithoutJavaBeansSpecCapitalization { - private final int aField; - public @java.lang.SuppressWarnings("all") int getAField() { - return this.aField; - } - public @java.lang.Override @java.lang.SuppressWarnings("all") boolean equals(final java.lang.Object o) { - if ((o == this)) - return true; - if ((! (o instanceof ValueWithoutJavaBeansSpecCapitalization))) - return false; - final ValueWithoutJavaBeansSpecCapitalization other = (ValueWithoutJavaBeansSpecCapitalization) o; - if ((this.getAField() != other.getAField())) - return false; - return true; - } - public @java.lang.Override @java.lang.SuppressWarnings("all") int hashCode() { - final int PRIME = 59; - int result = 1; - result = ((result * PRIME) + this.getAField()); - return result; - } - public @java.lang.Override @java.lang.SuppressWarnings("all") java.lang.String toString() { - return (("ValueWithoutJavaBeansSpecCapitalization(aField=" + this.getAField()) + ")"); - } - public @java.lang.SuppressWarnings("all") ValueWithoutJavaBeansSpecCapitalization(final int aField) { - super(); - this.aField = aField; - } -} diff --git a/test/transform/resource/after-ecj/WithOnJavaBeansSpecCapitalization.java b/test/transform/resource/after-ecj/WithOnJavaBeansSpecCapitalization.java deleted file mode 100644 index 06164fe9..00000000 --- a/test/transform/resource/after-ecj/WithOnJavaBeansSpecCapitalization.java +++ /dev/null @@ -1,25 +0,0 @@ -@lombok.With @lombok.experimental.Accessors(javaBeansSpecCapitalization = true) class WithOnJavaBeansSpecCapitalization { - int aField; - WithOnJavaBeansSpecCapitalization(int aField) { - super(); - } - /** - * @return a clone of this object, except with this updated property (returns {@code this} if an identical value is passed). - */ - public @java.lang.SuppressWarnings("all") WithOnJavaBeansSpecCapitalization withaField(final int aField) { - return ((this.aField == aField) ? this : new WithOnJavaBeansSpecCapitalization(aField)); - } -} - -@lombok.With class WithOffJavaBeansSpecCapitalization { - int aField; - WithOffJavaBeansSpecCapitalization(int aField) { - super(); - } - /** - * @return a clone of this object, except with this updated property (returns {@code this} if an identical value is passed). - */ - public @java.lang.SuppressWarnings("all") WithOffJavaBeansSpecCapitalization withAField(final int aField) { - return ((this.aField == aField) ? this : new WithOffJavaBeansSpecCapitalization(aField)); - } -} diff --git a/test/transform/resource/after-ecj/WithWithJavaBeansSpecCapitalization.java b/test/transform/resource/after-ecj/WithWithJavaBeansSpecCapitalization.java new file mode 100644 index 00000000..d530ad8a --- /dev/null +++ b/test/transform/resource/after-ecj/WithWithJavaBeansSpecCapitalization.java @@ -0,0 +1,12 @@ +@lombok.With class WithOnJavaBeansSpecCapitalization { + int aField; + WithWithJavaBeansSpecCapitalization(int aField) { + super(); + } + /** + * @return a clone of this object, except with this updated property (returns {@code this} if an identical value is passed). + */ + public @java.lang.SuppressWarnings("all") WithWithJavaBeansSpecCapitalization withaField(final int aField) { + return ((this.aField == aField) ? this : new WithWithJavaBeansSpecCapitalization(aField)); + } +} diff --git a/test/transform/resource/before/BuilderWithJavaBeansSpecCapitalization.java b/test/transform/resource/before/BuilderWithJavaBeansSpecCapitalization.java new file mode 100644 index 00000000..db1fe15f --- /dev/null +++ b/test/transform/resource/before/BuilderWithJavaBeansSpecCapitalization.java @@ -0,0 +1,7 @@ +//CONF: lombok.accessors.capitalization = beanspec +@lombok.Builder(setterPrefix = "set") +class BuilderWithJavaBeansSpecCapitalization { + @lombok.Singular("z") java.util.List<String> a; + @lombok.Singular("yField") java.util.List<String> aField; + String bField; +} diff --git a/test/transform/resource/before/GetterWithJavaBeansSpecCapitalization.java b/test/transform/resource/before/GetterWithJavaBeansSpecCapitalization.java index 3c27317c..68f41e3d 100644 --- a/test/transform/resource/before/GetterWithJavaBeansSpecCapitalization.java +++ b/test/transform/resource/before/GetterWithJavaBeansSpecCapitalization.java @@ -1,11 +1,5 @@ -class GetterWithoutJavaBeansSpecCapitalization { - @lombok.Getter int a; - @lombok.Getter int aField; -} - -@lombok.experimental.Accessors(javaBeansSpecCapitalization=true) +//CONF: lombok.accessors.capitalization = beanspec class GetterWithJavaBeansSpecCapitalization { @lombok.Getter int a; @lombok.Getter int aField; } - diff --git a/test/transform/resource/before/SetterWithJavaBeansSpecCapitalization.java b/test/transform/resource/before/SetterWithJavaBeansSpecCapitalization.java index 80a1b4ee..b5e34ba7 100644 --- a/test/transform/resource/before/SetterWithJavaBeansSpecCapitalization.java +++ b/test/transform/resource/before/SetterWithJavaBeansSpecCapitalization.java @@ -1,11 +1,5 @@ -class SetterWithoutJavaBeansSpecCapitalization { - @lombok.Setter int a; - @lombok.Setter int aField; -} - -@lombok.experimental.Accessors(javaBeansSpecCapitalization=true) +//CONF: lombok.accessors.capitalization = beanspec class SetterWithJavaBeansSpecCapitalization { @lombok.Setter int a; @lombok.Setter int aField; } - diff --git a/test/transform/resource/before/ValueWithJavaBeansSpecCapitalization.java b/test/transform/resource/before/ValueWithJavaBeansSpecCapitalization.java index f0044ed9..7c001f6e 100644 --- a/test/transform/resource/before/ValueWithJavaBeansSpecCapitalization.java +++ b/test/transform/resource/before/ValueWithJavaBeansSpecCapitalization.java @@ -1,10 +1,5 @@ +//CONF: lombok.accessors.capitalization = beanspec @lombok.Value -@lombok.experimental.Accessors(javaBeansSpecCapitalization = true) class ValueWithJavaBeansSpecCapitalization { final int aField; } - -@lombok.Value -class ValueWithoutJavaBeansSpecCapitalization { - final int aField; -} diff --git a/test/transform/resource/before/WithOnJavaBeansSpecCapitalization.java b/test/transform/resource/before/WithOnJavaBeansSpecCapitalization.java deleted file mode 100644 index 476fb5a4..00000000 --- a/test/transform/resource/before/WithOnJavaBeansSpecCapitalization.java +++ /dev/null @@ -1,16 +0,0 @@ -@lombok.With -@lombok.experimental.Accessors(javaBeansSpecCapitalization = true) -class WithOnJavaBeansSpecCapitalization { - int aField; - - WithOnJavaBeansSpecCapitalization(int aField) { - } -} - -@lombok.With -class WithOffJavaBeansSpecCapitalization { - int aField; - - WithOffJavaBeansSpecCapitalization(int aField) { - } -} diff --git a/test/transform/resource/before/WithWithJavaBeansSpecCapitalization.java b/test/transform/resource/before/WithWithJavaBeansSpecCapitalization.java new file mode 100644 index 00000000..ef4a78ad --- /dev/null +++ b/test/transform/resource/before/WithWithJavaBeansSpecCapitalization.java @@ -0,0 +1,8 @@ +//CONF: lombok.accessors.capitalization = beanspec +@lombok.With +class WithWithJavaBeansSpecCapitalization { + int aField; + + WithWithJavaBeansSpecCapitalization(int aField) { + } +} |