aboutsummaryrefslogtreecommitdiff
path: root/src/core/lombok/eclipse/handlers
diff options
context:
space:
mode:
authorReinier Zwitserloot <reinier@zwitserloot.com>2011-10-25 19:39:08 +0200
committerReinier Zwitserloot <reinier@zwitserloot.com>2011-10-25 19:39:08 +0200
commit16661be2d99359c94569620e1daf2362d5356341 (patch)
treecca9a8062623818a3a995a7c86f228e023448f02 /src/core/lombok/eclipse/handlers
parent7f7d1eed36f605cc7ca0e7af81ea9caf895e7b73 (diff)
downloadlombok-16661be2d99359c94569620e1daf2362d5356341.tar.gz
lombok-16661be2d99359c94569620e1daf2362d5356341.tar.bz2
lombok-16661be2d99359c94569620e1daf2362d5356341.zip
Fixed issue 289: non-static inner classes whose outer class has generics can't be @EqualsAndHashCode marked.
Diffstat (limited to 'src/core/lombok/eclipse/handlers')
-rw-r--r--src/core/lombok/eclipse/handlers/EclipseHandlerUtil.java3
-rw-r--r--src/core/lombok/eclipse/handlers/HandleEqualsAndHashCode.java32
2 files changed, 30 insertions, 5 deletions
diff --git a/src/core/lombok/eclipse/handlers/EclipseHandlerUtil.java b/src/core/lombok/eclipse/handlers/EclipseHandlerUtil.java
index fef55904..328a8e6d 100644
--- a/src/core/lombok/eclipse/handlers/EclipseHandlerUtil.java
+++ b/src/core/lombok/eclipse/handlers/EclipseHandlerUtil.java
@@ -1211,6 +1211,9 @@ public class EclipseHandlerUtil {
throw Lombok.sneakyThrow(e);
}
+ result.sourceStart = source.sourceStart;
+ result.sourceEnd = source.sourceEnd;
+
setGeneratedBy(result, source);
return result;
}
diff --git a/src/core/lombok/eclipse/handlers/HandleEqualsAndHashCode.java b/src/core/lombok/eclipse/handlers/HandleEqualsAndHashCode.java
index a4989b4c..d51aab4c 100644
--- a/src/core/lombok/eclipse/handlers/HandleEqualsAndHashCode.java
+++ b/src/core/lombok/eclipse/handlers/HandleEqualsAndHashCode.java
@@ -408,6 +408,27 @@ public class HandleEqualsAndHashCode extends EclipseAnnotationHandler<EqualsAndH
return method;
}
+ private TypeReference createTypeReference(EclipseNode type, long p) {
+ List<String> list = new ArrayList<String>();
+ list.add(type.getName());
+ EclipseNode tNode = type.up();
+ while (tNode != null && tNode.getKind() == Kind.TYPE) {
+ list.add(tNode.getName());
+ tNode = tNode.up();
+ }
+ Collections.reverse(list);
+
+ if (list.size() == 1) return new SingleTypeReference(list.get(0).toCharArray(), p);
+ long[] ps = new long[list.size()];
+ char[][] tokens = new char[list.size()][];
+ for (int i = 0; i < list.size(); i++) {
+ ps[i] = p;
+ tokens[i] = list.get(i).toCharArray();
+ }
+
+ return new QualifiedTypeReference(tokens, ps);
+ }
+
private MethodDeclaration createEquals(EclipseNode type, Collection<EclipseNode> fields, boolean callSuper, ASTNode source, FieldAccess fieldAccess, boolean needsCanEqual) {
int pS = source.sourceStart; int pE = source.sourceEnd;
long p = (long)pS << 32 | pE;
@@ -452,12 +473,11 @@ public class HandleEqualsAndHashCode extends EclipseAnnotationHandler<EqualsAndH
statements.add(ifOtherEqualsThis);
}
- /* if (!(o instanceof MyType) return false; */ {
+ /* if (!(o instanceof Outer.Inner.MyType) return false; */ {
SingleNameReference oRef = new SingleNameReference(new char[] { 'o' }, p);
setGeneratedBy(oRef, source);
- SingleTypeReference typeReference = new SingleTypeReference(typeDecl.name, p);
- setGeneratedBy(typeReference, source);
+ TypeReference typeReference = createTypeReference(type, p);
InstanceOfExpression instanceOf = new InstanceOfExpression(oRef, typeReference);
instanceOf.sourceStart = pS; instanceOf.sourceEnd = pE;
@@ -505,6 +525,7 @@ 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);
}
@@ -653,7 +674,7 @@ public class HandleEqualsAndHashCode extends EclipseAnnotationHandler<EqualsAndH
private MethodDeclaration createCanEqual(EclipseNode type, ASTNode source) {
/* public boolean canEqual(final java.lang.Object other) {
- * return other instanceof MyType;
+ * return other instanceof Outer.Inner.MyType;
* }
*/
int pS = source.sourceStart; int pE = source.sourceEnd;
@@ -683,7 +704,8 @@ public class HandleEqualsAndHashCode extends EclipseAnnotationHandler<EqualsAndH
SingleNameReference otherRef = new SingleNameReference(otherName, p);
setGeneratedBy(otherRef, source);
- SingleTypeReference typeReference = new SingleTypeReference(((TypeDeclaration)type.get()).name, p);
+ TypeReference typeReference = createTypeReference(type, p);
+
setGeneratedBy(typeReference, source);
InstanceOfExpression instanceOf = new InstanceOfExpression(otherRef, typeReference);