diff options
author | Roel Spilker <r.spilker@gmail.com> | 2015-12-18 20:17:47 +0100 |
---|---|---|
committer | Roel Spilker <r.spilker@gmail.com> | 2015-12-18 20:17:47 +0100 |
commit | 34a6fd644f6036bef5c2d94d925b6cf8e20ab17d (patch) | |
tree | ea2fb595c6fa804ed1b5c87541536687c29a2a63 | |
parent | d3c79494a32d439b6a936d24c8440e893fc2cb50 (diff) | |
download | lombok-34a6fd644f6036bef5c2d94d925b6cf8e20ab17d.tar.gz lombok-34a6fd644f6036bef5c2d94d925b6cf8e20ab17d.tar.bz2 lombok-34a6fd644f6036bef5c2d94d925b6cf8e20ab17d.zip |
fix issue #932: `@Delegate` would not generate varargs on javac
-rw-r--r-- | doc/changelog.markdown | 3 | ||||
-rw-r--r-- | src/core/lombok/javac/handlers/HandleDelegate.java | 8 | ||||
-rw-r--r-- | test/transform/resource/after-delombok/DelegateWithVarargs.java | 29 | ||||
-rw-r--r-- | test/transform/resource/after-ecj/DelegateWithVarargs.java | 25 | ||||
-rw-r--r-- | test/transform/resource/before/DelegateWithVarargs.java | 12 |
5 files changed, 74 insertions, 3 deletions
diff --git a/doc/changelog.markdown b/doc/changelog.markdown index 3c7e31c5..74d2fdc8 100644 --- a/doc/changelog.markdown +++ b/doc/changelog.markdown @@ -15,8 +15,9 @@ Lombok Changelog * FEATURE: A `lombok.config` key can now be used to set the default behaviour of `@EqualsAndHashCode` when generating methods for a class that extends something in regards to calling the superclass implementations of `equals` and `hashCode` or not. [Issue #965](https://github.com/rzwitserloot/lombok/issues/965). * FEATURE: Putting `@Wither` on abstract classes now generates something slightly more useful: An abstract wither method. [Issue #945](https://github.com/rzwitserloot/lombok/issues/945). * BUGFIX: lambdas with 1 argument that has an explicit type did not pretty print correctly. [Issue #972](https://github.com/rzwitserloot/lombok/issues/972). -* BUGFIX: `@Value` and `@FieldDefaults` no longer make uninitialized static fields final. [Issue #928](https://github.com/rzwitserloot/lombok/issues/928). * BUGFIX: When using delombok, a source file with only `@NonNull` annotations on parameters as lombok feature would not get properly delomboked. [Issue #950](https://github.com/rzwitserloot/lombok/issues/950). +* BUGFIX: `@Delegate` in javac would generate arrays instead of varargs parameters. [Issue #932](https://github.com/rzwitserloot/lombok/issues/932). +* BUGFIX: `@Value` and `@FieldDefaults` no longer make uninitialized static fields final. [Issue #928](https://github.com/rzwitserloot/lombok/issues/928). * ENHANCEMENT: Putting `@NonNull` on a parameter of an abstract method no longer generates a warning, to allow you to use this annotation to document intended behaviour [Issue #807](https://github.com/rzwitserloot/lombok/issues/807). ### v1.16.6 (August 18th, 2015) diff --git a/src/core/lombok/javac/handlers/HandleDelegate.java b/src/core/lombok/javac/handlers/HandleDelegate.java index fc3c81f3..680e7745 100644 --- a/src/core/lombok/javac/handlers/HandleDelegate.java +++ b/src/core/lombok/javac/handlers/HandleDelegate.java @@ -299,7 +299,7 @@ public class HandleDelegate extends JavacAnnotationHandler<Delegate> { annotations = com.sun.tools.javac.util.List.nil(); } - JCModifiers mods = maker.Modifiers(Flags.PUBLIC, annotations); + JCModifiers mods = maker.Modifiers(PUBLIC, annotations); JCExpression returnType = JavacResolution.typeToJCTree((Type) sig.type.getReturnType(), annotation.getAst(), true); boolean useReturn = sig.type.getReturnType().getKind() != TypeKind.VOID; ListBuffer<JCVariableDecl> params = sig.type.getParameterTypes().isEmpty() ? null : new ListBuffer<JCVariableDecl>(); @@ -326,11 +326,15 @@ public class HandleDelegate extends JavacAnnotationHandler<Delegate> { } int idx = 0; + String[] paramNames = sig.getParameterNames(); + boolean varargs = sig.elem.isVarArgs(); for (TypeMirror param : sig.type.getParameterTypes()) { long flags = JavacHandlerUtil.addFinalIfNeeded(Flags.PARAMETER, annotation.getContext()); JCModifiers paramMods = maker.Modifiers(flags); - String[] paramNames = sig.getParameterNames(); Name name = annotation.toName(paramNames[idx++]); + if (varargs && idx == paramNames.length) { + paramMods.flags |= VARARGS; + } params.append(maker.VarDef(paramMods, name, JavacResolution.typeToJCTree((Type) param, annotation.getAst(), true), null)); args.append(maker.Ident(name)); } diff --git a/test/transform/resource/after-delombok/DelegateWithVarargs.java b/test/transform/resource/after-delombok/DelegateWithVarargs.java new file mode 100644 index 00000000..1d240524 --- /dev/null +++ b/test/transform/resource/after-delombok/DelegateWithVarargs.java @@ -0,0 +1,29 @@ +class DelegateWithVarargs { + private Bar bar; + private interface Bar { + void justOneParameter(int... varargs); + void multipleParameters(String first, int... varargs); + void array(int[] array); + void arrayVarargs(int[]... arrayVarargs); + } + @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") + public void justOneParameter(final int... varargs) { + this.bar.justOneParameter(varargs); + } + @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") + public void multipleParameters(final java.lang.String first, final int... varargs) { + this.bar.multipleParameters(first, varargs); + } + @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") + public void array(final int[] array) { + this.bar.array(array); + } + @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") + public void arrayVarargs(final int[]... arrayVarargs) { + this.bar.arrayVarargs(arrayVarargs); + } +} diff --git a/test/transform/resource/after-ecj/DelegateWithVarargs.java b/test/transform/resource/after-ecj/DelegateWithVarargs.java new file mode 100644 index 00000000..a0b5b7b5 --- /dev/null +++ b/test/transform/resource/after-ecj/DelegateWithVarargs.java @@ -0,0 +1,25 @@ +import lombok.experimental.Delegate; +class DelegateWithVarargs { + private interface Bar { + void justOneParameter(int... varargs); + void multipleParameters(String first, int... varargs); + void array(int[] array); + void arrayVarargs(int[]... arrayVarargs); + } + private @Delegate Bar bar; + DelegateWithVarargs() { + super(); + } + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") void array(final int[] array) { + this.bar.array(array); + } + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") void arrayVarargs(final int[]... arrayVarargs) { + this.bar.arrayVarargs(arrayVarargs); + } + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") void justOneParameter(final int... varargs) { + this.bar.justOneParameter(varargs); + } + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") void multipleParameters(final java.lang.String first, final int... varargs) { + this.bar.multipleParameters(first, varargs); + } +} diff --git a/test/transform/resource/before/DelegateWithVarargs.java b/test/transform/resource/before/DelegateWithVarargs.java new file mode 100644 index 00000000..0c266620 --- /dev/null +++ b/test/transform/resource/before/DelegateWithVarargs.java @@ -0,0 +1,12 @@ +import lombok.experimental.Delegate; + +class DelegateWithVarargs { + @Delegate private Bar bar; + + private interface Bar { + void justOneParameter(int... varargs); + void multipleParameters(String first, int... varargs); + void array(int[] array); + void arrayVarargs(int[]... arrayVarargs); + } +}
\ No newline at end of file |