From 16661be2d99359c94569620e1daf2362d5356341 Mon Sep 17 00:00:00 2001 From: Reinier Zwitserloot Date: Tue, 25 Oct 2011 19:39:08 +0200 Subject: Fixed issue 289: non-static inner classes whose outer class has generics can't be @EqualsAndHashCode marked. --- .../eclipse/handlers/EclipseHandlerUtil.java | 3 ++ .../eclipse/handlers/HandleEqualsAndHashCode.java | 32 ++++++++++++++++++---- .../javac/handlers/HandleEqualsAndHashCode.java | 29 ++++++++++++++++---- 3 files changed, 54 insertions(+), 10 deletions(-) (limited to 'src') 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 list = new ArrayList(); + 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 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 list = new ArrayList(); + list.add(type.getName()); + JavacNode tNode = type.up(); + while (tNode != null && tNode.getKind() == Kind.TYPE) { + list.add(tNode.getName()); + tNode = tNode.up(); + } + Collections.reverse(list); + + TreeMaker maker = type.getTreeMaker(); + JCExpression chain = maker.Ident(type.toName(list.get(0))); + + for (int i = 1; i < list.size(); i++) { + chain = maker.Select(chain, type.toName(list.get(i))); + } + + return chain; + } + private JCMethodDecl createEquals(JavacNode typeNode, List fields, boolean callSuper, FieldAccess fieldAccess, boolean needsCanEqual, JCTree source) { TreeMaker maker = typeNode.getTreeMaker(); JCClassDecl type = (JCClassDecl) typeNode.get(); @@ -341,8 +361,8 @@ public class HandleEqualsAndHashCode extends JavacAnnotationHandlernil()); JCExpression returnType = maker.TypeIdent(getCtcInt(TypeTags.class, "BOOLEAN")); @@ -458,7 +477,7 @@ public class HandleEqualsAndHashCode extends JavacAnnotationHandler params = List.of(maker.VarDef(maker.Modifiers(Flags.FINAL), otherName, objectType, null)); JCBlock body = maker.Block(0, List.of( - maker.Return(maker.TypeTest(maker.Ident(otherName), maker.Ident(type.name))))); + maker.Return(maker.TypeTest(maker.Ident(otherName), createTypeReference(typeNode))))); return recursiveSetGeneratedBy(maker.MethodDef(mods, canEqualName, returnType, List.nil(), params, List.nil(), body, null), source); } -- cgit