From 003832670e5115fc0cd93f46f4f48482048ee078 Mon Sep 17 00:00:00 2001 From: Roel Spilker Date: Mon, 4 Dec 2017 21:41:03 +0100 Subject: delombok no longer prints generated outer-instance constructor parameters, fixes #1521 --- src/delombok/lombok/delombok/PrettyPrinter.java | 15 +++--- .../resource/after-delombok/InnerClass.java | 51 ++++++++++++++++++++ test/transform/resource/after-ecj/InnerClass.java | 56 ++++++++++++++++++++++ test/transform/resource/before/InnerClass.java | 17 +++++++ 4 files changed, 133 insertions(+), 6 deletions(-) create mode 100644 test/transform/resource/after-delombok/InnerClass.java create mode 100644 test/transform/resource/after-ecj/InnerClass.java create mode 100644 test/transform/resource/before/InnerClass.java diff --git a/src/delombok/lombok/delombok/PrettyPrinter.java b/src/delombok/lombok/delombok/PrettyPrinter.java index 611055e0..4261a558 100644 --- a/src/delombok/lombok/delombok/PrettyPrinter.java +++ b/src/delombok/lombok/delombok/PrettyPrinter.java @@ -813,6 +813,11 @@ public class PrettyPrinter extends JCTree.Visitor { print(tree.encl); print("."); } + boolean moveFirstParameter = tree.args.nonEmpty() && tree.args.head instanceof JCUnary && tree.args.head.toString().startsWith("<*nullchk*>"); + if (moveFirstParameter) { + print(((JCUnary) tree.args.head).arg); + print("."); + } print("new "); if (!tree.typeargs.isEmpty()) { @@ -822,12 +827,10 @@ public class PrettyPrinter extends JCTree.Visitor { } print(tree.clazz); print("("); - if (tree.args.nonEmpty()) { - if (tree.args.head instanceof JCIdent) { - print(tree.args, ", "); - } else { - print(tree.args.tail, ", "); - } + if (moveFirstParameter) { + print(tree.args.tail, ", "); + } else { + print(tree.args, ", "); } print(")"); if (tree.def != null) { diff --git a/test/transform/resource/after-delombok/InnerClass.java b/test/transform/resource/after-delombok/InnerClass.java new file mode 100644 index 00000000..6d42bb79 --- /dev/null +++ b/test/transform/resource/after-delombok/InnerClass.java @@ -0,0 +1,51 @@ +class A { + class B { + String s; + @java.lang.SuppressWarnings("all") + public B(final String s) { + this.s = s; + } + } +} +class C { + final class D { + private final A a; + A.B test(String s) { + return a.new B(s) { + }; + } + @java.lang.SuppressWarnings("all") + public D(final A a) { + this.a = a; + } + @java.lang.SuppressWarnings("all") + public A getA() { + return this.a; + } + @java.lang.Override + @java.lang.SuppressWarnings("all") + public boolean equals(final java.lang.Object o) { + if (o == this) return true; + if (!(o instanceof C.D)) return false; + final C.D other = (C.D) o; + final java.lang.Object this$a = this.getA(); + final java.lang.Object other$a = other.getA(); + if (this$a == null ? other$a != null : !this$a.equals(other$a)) return false; + return true; + } + @java.lang.Override + @java.lang.SuppressWarnings("all") + public int hashCode() { + final int PRIME = 59; + int result = 1; + final java.lang.Object $a = this.getA(); + result = result * PRIME + ($a == null ? 43 : $a.hashCode()); + return result; + } + @java.lang.Override + @java.lang.SuppressWarnings("all") + public java.lang.String toString() { + return "C.D(a=" + this.getA() + ")"; + } + } +} \ No newline at end of file diff --git a/test/transform/resource/after-ecj/InnerClass.java b/test/transform/resource/after-ecj/InnerClass.java new file mode 100644 index 00000000..32004225 --- /dev/null +++ b/test/transform/resource/after-ecj/InnerClass.java @@ -0,0 +1,56 @@ +class A { + @lombok.AllArgsConstructor class B { + String s; + public @java.lang.SuppressWarnings("all") B(final String s) { + super(); + this.s = s; + } + } + A() { + super(); + } +} +class C { + final @lombok.Value class D { + private final A a; + A.B test(String s) { + return a.new B(s) { + x( $anonymous0) { + super($anonymous0); + } +}; + } + public @java.lang.SuppressWarnings("all") A getA() { + return this.a; + } + public @java.lang.Override @java.lang.SuppressWarnings("all") boolean equals(final java.lang.Object o) { + if ((o == this)) + return true; + if ((! (o instanceof C.D))) + return false; + final C.D other = (C.D) o; + final java.lang.Object this$a = this.getA(); + final java.lang.Object other$a = other.getA(); + if (((this$a == null) ? (other$a != null) : (! this$a.equals(other$a)))) + return false; + return true; + } + public @java.lang.Override @java.lang.SuppressWarnings("all") int hashCode() { + final int PRIME = 59; + int result = 1; + final java.lang.Object $a = this.getA(); + result = ((result * PRIME) + (($a == null) ? 43 : $a.hashCode())); + return result; + } + public @java.lang.Override @java.lang.SuppressWarnings("all") java.lang.String toString() { + return (("C.D(a=" + this.getA()) + ")"); + } + public @java.lang.SuppressWarnings("all") D(final A a) { + super(); + this.a = a; + } + } + C() { + super(); + } +} diff --git a/test/transform/resource/before/InnerClass.java b/test/transform/resource/before/InnerClass.java new file mode 100644 index 00000000..ba020686 --- /dev/null +++ b/test/transform/resource/before/InnerClass.java @@ -0,0 +1,17 @@ +class A { + @lombok.AllArgsConstructor + class B { + String s; + } +} + +class C { + @lombok.Value + class D { + A a; + + A.B test(String s) { + return a.new B(s) {}; + } + } +} \ No newline at end of file -- cgit