aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorReinier Zwitserloot <reinier@zwitserloot.com>2018-04-23 22:36:07 +0200
committerReinier Zwitserloot <reinier@zwitserloot.com>2018-04-23 22:36:07 +0200
commita27826b268c28a7aa1596bb07461ab1cfb113d82 (patch)
treeed589f67954005c4169855e75ac8fcbde9decd6c
parent472d602693bdccde135ff084c44bfebd285a2101 (diff)
downloadlombok-a27826b268c28a7aa1596bb07461ab1cfb113d82.tar.gz
lombok-a27826b268c28a7aa1596bb07461ab1cfb113d82.tar.bz2
lombok-a27826b268c28a7aa1596bb07461ab1cfb113d82.zip
[bugfix] generics on inner classes whose outer type has generics, when the outer type is an interface, caused bugs in ecj.
-rw-r--r--src/core/lombok/eclipse/handlers/HandleEqualsAndHashCode.java4
-rw-r--r--test/transform/resource/after-delombok/EqualsAndHashCodeWithGenericsOnInnersInInterfaces.java27
-rw-r--r--test/transform/resource/after-ecj/EqualsAndHashCodeWithGenericsOnInnersInInterfaces.java30
-rw-r--r--test/transform/resource/before/BuilderWithRecursiveGenerics.java2
-rw-r--r--test/transform/resource/before/EqualsAndHashCodeWithGenericsOnInnersInInterfaces.java6
5 files changed, 67 insertions, 2 deletions
diff --git a/src/core/lombok/eclipse/handlers/HandleEqualsAndHashCode.java b/src/core/lombok/eclipse/handlers/HandleEqualsAndHashCode.java
index 75339f7c..3e226269 100644
--- a/src/core/lombok/eclipse/handlers/HandleEqualsAndHashCode.java
+++ b/src/core/lombok/eclipse/handlers/HandleEqualsAndHashCode.java
@@ -479,14 +479,16 @@ public class HandleEqualsAndHashCode extends EclipseAnnotationHandler<EqualsAndH
list.add(type.getName());
if (addWildcards) genericsCount.add(arraySizeOf(((TypeDeclaration) type.get()).typeParameters));
- boolean staticContext = (((TypeDeclaration) type.get()).modifiers & Modifier.STATIC) != 0;
+ boolean staticContext = (((TypeDeclaration) type.get()).modifiers & ClassFileConstants.AccStatic) != 0;
EclipseNode tNode = type.up();
+ if (!staticContext && tNode.getKind() == Kind.TYPE && (((TypeDeclaration) tNode.get()).modifiers & ClassFileConstants.AccInterface) != 0) staticContext = true;
while (tNode != null && tNode.getKind() == Kind.TYPE) {
list.add(tNode.getName());
if (addWildcards) genericsCount.add(staticContext ? 0 : arraySizeOf(((TypeDeclaration) tNode.get()).typeParameters));
if (!staticContext) staticContext = (((TypeDeclaration) tNode.get()).modifiers & Modifier.STATIC) != 0;
tNode = tNode.up();
+ if (!staticContext && tNode.getKind() == Kind.TYPE && (((TypeDeclaration) tNode.get()).modifiers & ClassFileConstants.AccInterface) != 0) staticContext = true;
}
Collections.reverse(list);
if (addWildcards) Collections.reverse(genericsCount);
diff --git a/test/transform/resource/after-delombok/EqualsAndHashCodeWithGenericsOnInnersInInterfaces.java b/test/transform/resource/after-delombok/EqualsAndHashCodeWithGenericsOnInnersInInterfaces.java
new file mode 100644
index 00000000..ed25b317
--- /dev/null
+++ b/test/transform/resource/after-delombok/EqualsAndHashCodeWithGenericsOnInnersInInterfaces.java
@@ -0,0 +1,27 @@
+public interface EqualsAndHashCodeWithGenericsOnInnersInInterfaces<A> {
+ class Inner<B> {
+ int x;
+ @java.lang.Override
+ @java.lang.SuppressWarnings("all")
+ public boolean equals(final java.lang.Object o) {
+ if (o == this) return true;
+ if (!(o instanceof EqualsAndHashCodeWithGenericsOnInnersInInterfaces.Inner)) return false;
+ final EqualsAndHashCodeWithGenericsOnInnersInInterfaces.Inner<?> other = (EqualsAndHashCodeWithGenericsOnInnersInInterfaces.Inner<?>) o;
+ if (!other.canEqual((java.lang.Object) this)) return false;
+ if (this.x != other.x) return false;
+ return true;
+ }
+ @java.lang.SuppressWarnings("all")
+ protected boolean canEqual(final java.lang.Object other) {
+ return other instanceof EqualsAndHashCodeWithGenericsOnInnersInInterfaces.Inner;
+ }
+ @java.lang.Override
+ @java.lang.SuppressWarnings("all")
+ public int hashCode() {
+ final int PRIME = 59;
+ int result = 1;
+ result = result * PRIME + this.x;
+ return result;
+ }
+ }
+}
diff --git a/test/transform/resource/after-ecj/EqualsAndHashCodeWithGenericsOnInnersInInterfaces.java b/test/transform/resource/after-ecj/EqualsAndHashCodeWithGenericsOnInnersInInterfaces.java
new file mode 100644
index 00000000..8c849502
--- /dev/null
+++ b/test/transform/resource/after-ecj/EqualsAndHashCodeWithGenericsOnInnersInInterfaces.java
@@ -0,0 +1,30 @@
+public interface EqualsAndHashCodeWithGenericsOnInnersInInterfaces<A> {
+ @lombok.EqualsAndHashCode class Inner<B> {
+ int x;
+ Inner() {
+ super();
+ }
+ public @java.lang.Override @java.lang.SuppressWarnings("all") boolean equals(final java.lang.Object o) {
+ if ((o == this))
+ return true;
+ if ((! (o instanceof EqualsAndHashCodeWithGenericsOnInnersInInterfaces.Inner)))
+ return false;
+ final EqualsAndHashCodeWithGenericsOnInnersInInterfaces.Inner<?> other = (EqualsAndHashCodeWithGenericsOnInnersInInterfaces.Inner<?>) o;
+ if ((! other.canEqual((java.lang.Object) this)))
+ return false;
+ if ((this.x != other.x))
+ return false;
+ return true;
+ }
+ protected @java.lang.SuppressWarnings("all") boolean canEqual(final java.lang.Object other) {
+ return (other instanceof EqualsAndHashCodeWithGenericsOnInnersInInterfaces.Inner);
+ }
+ public @java.lang.Override @java.lang.SuppressWarnings("all") int hashCode() {
+ final int PRIME = 59;
+ int result = 1;
+ result = ((result * PRIME) + this.x);
+ return result;
+ }
+ }
+}
+
diff --git a/test/transform/resource/before/BuilderWithRecursiveGenerics.java b/test/transform/resource/before/BuilderWithRecursiveGenerics.java
index 041da414..0ab86220 100644
--- a/test/transform/resource/before/BuilderWithRecursiveGenerics.java
+++ b/test/transform/resource/before/BuilderWithRecursiveGenerics.java
@@ -5,7 +5,7 @@ import lombok.Value;
public class BuilderWithRecursiveGenerics {
interface Inter<T, U extends Inter<T, U>> {}
-
+
@Builder @Value public static class Test<Foo, Bar extends Set<Foo>, Quz extends Inter<Bar, Quz>> {
Foo foo;
Bar bar;
diff --git a/test/transform/resource/before/EqualsAndHashCodeWithGenericsOnInnersInInterfaces.java b/test/transform/resource/before/EqualsAndHashCodeWithGenericsOnInnersInInterfaces.java
new file mode 100644
index 00000000..585ebbde
--- /dev/null
+++ b/test/transform/resource/before/EqualsAndHashCodeWithGenericsOnInnersInInterfaces.java
@@ -0,0 +1,6 @@
+public interface EqualsAndHashCodeWithGenericsOnInnersInInterfaces<A> {
+ @lombok.EqualsAndHashCode class Inner<B> {
+ int x;
+ }
+}
+