diff options
Diffstat (limited to 'src/core/lombok/eclipse')
3 files changed, 33 insertions, 4 deletions
diff --git a/src/core/lombok/eclipse/handlers/HandleEqualsAndHashCode.java b/src/core/lombok/eclipse/handlers/HandleEqualsAndHashCode.java index d4c63da3..ef01835c 100644 --- a/src/core/lombok/eclipse/handlers/HandleEqualsAndHashCode.java +++ b/src/core/lombok/eclipse/handlers/HandleEqualsAndHashCode.java @@ -222,14 +222,17 @@ public class HandleEqualsAndHashCode extends EclipseAnnotationHandler<EqualsAndH } MethodDeclaration equalsMethod = createEquals(typeNode, nodesForEquality, callSuper, errorNode.get(), fieldAccess, needsCanEqual); + equalsMethod.traverse(new SetGeneratedByVisitor(errorNode.get()), ((TypeDeclaration)typeNode.get()).scope); injectMethod(typeNode, equalsMethod); if (needsCanEqual) { MethodDeclaration canEqualMethod = createCanEqual(typeNode, errorNode.get()); + canEqualMethod.traverse(new SetGeneratedByVisitor(errorNode.get()), ((TypeDeclaration)typeNode.get()).scope); injectMethod(typeNode, canEqualMethod); } MethodDeclaration hashCodeMethod = createHashCode(typeNode, nodesForEquality, callSuper, errorNode.get(), fieldAccess); + hashCodeMethod.traverse(new SetGeneratedByVisitor(errorNode.get()), ((TypeDeclaration)typeNode.get()).scope); injectMethod(typeNode, hashCodeMethod); } diff --git a/src/core/lombok/eclipse/handlers/HandleGetter.java b/src/core/lombok/eclipse/handlers/HandleGetter.java index 1d59afb4..b7d9c5ed 100644 --- a/src/core/lombok/eclipse/handlers/HandleGetter.java +++ b/src/core/lombok/eclipse/handlers/HandleGetter.java @@ -24,18 +24,23 @@ package lombok.eclipse.handlers; import static lombok.eclipse.Eclipse.*; import static lombok.eclipse.handlers.EclipseHandlerUtil.*; +import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.HashMap; +import java.util.List; import java.util.Map; import lombok.AccessLevel; +import lombok.Delegate; import lombok.Getter; +import lombok.core.AST.Kind; import lombok.core.AnnotationValues; import lombok.core.TransformationsUtil; -import lombok.core.AST.Kind; import lombok.eclipse.EclipseAnnotationHandler; import lombok.eclipse.EclipseNode; +import lombok.eclipse.agent.PatchDelegate; +import lombok.eclipse.handlers.EclipseHandlerUtil.FieldAccess; import org.eclipse.jdt.internal.compiler.ast.ASTNode; import org.eclipse.jdt.internal.compiler.ast.AllocationExpression; @@ -69,6 +74,8 @@ import org.mangosdk.spi.ProviderFor; */ @ProviderFor(EclipseAnnotationHandler.class) public class HandleGetter extends EclipseAnnotationHandler<Getter> { + private static final Annotation[] EMPTY_ANNOTATIONS_ARRAY = new Annotation[0]; + public boolean generateGetterForType(EclipseNode typeNode, EclipseNode pos, AccessLevel level, boolean checkForTypeLevelGetter) { if (checkForTypeLevelGetter) { if (typeNode != null) for (EclipseNode child : typeNode.down()) { @@ -205,13 +212,25 @@ public class HandleGetter extends EclipseAnnotationHandler<Getter> { } MethodDeclaration method = generateGetter((TypeDeclaration) fieldNode.up().get(), fieldNode, getterName, modifier, source, lazy); - Annotation[] copiedAnnotations = copyAnnotations(source, findAnnotations(field, TransformationsUtil.NON_NULL_PATTERN), findAnnotations(field, TransformationsUtil.NULLABLE_PATTERN)); + Annotation[] copiedAnnotations = copyAnnotations(source, findAnnotations(field, TransformationsUtil.NON_NULL_PATTERN), findAnnotations(field, TransformationsUtil.NULLABLE_PATTERN), findDelegatesAndMarkAsHandled(fieldNode)); if (copiedAnnotations.length != 0) { method.annotations = copiedAnnotations; } injectMethod(fieldNode.up(), method); } + + private static Annotation[] findDelegatesAndMarkAsHandled(EclipseNode fieldNode) { + List<Annotation> delegates = new ArrayList<Annotation>(); + for (EclipseNode child : fieldNode.down()) { + if (annotationTypeMatches(Delegate.class, child)) { + Annotation delegate = (Annotation)child.get(); + PatchDelegate.markHandled(delegate); + delegates.add(delegate); + } + } + return delegates.toArray(EMPTY_ANNOTATIONS_ARRAY); + } private MethodDeclaration generateGetter(TypeDeclaration parent, EclipseNode fieldNode, String name, int modifier, ASTNode source, boolean lazy) { diff --git a/src/core/lombok/eclipse/handlers/SetGeneratedByVisitor.java b/src/core/lombok/eclipse/handlers/SetGeneratedByVisitor.java index 13292cdd..7d2b7a74 100644 --- a/src/core/lombok/eclipse/handlers/SetGeneratedByVisitor.java +++ b/src/core/lombok/eclipse/handlers/SetGeneratedByVisitor.java @@ -247,6 +247,13 @@ public final class SetGeneratedByVisitor extends ASTVisitor { node.nameSourcePosition = recalcSourcePosition(node.nameSourcePosition); } + private void applyOffsetQualifiedNameReference(QualifiedNameReference node) { + applyOffsetExpression(node); + for (int i = 0; i < node.sourcePositions.length; i++) { + node.sourcePositions[i] = recalcSourcePosition(node.sourcePositions[i]); + } + } + private void applyOffsetQualifiedTypeReference(QualifiedTypeReference node) { applyOffsetExpression(node); for (int i = 0; i < node.sourcePositions.length; i++) { @@ -787,8 +794,8 @@ public final class SetGeneratedByVisitor extends ASTVisitor { } @Override public boolean visit(QualifiedNameReference node, BlockScope scope) { - setGeneratedBy(node, source); - applyOffsetExpression(node); + setGeneratedBy(node, source); + applyOffsetQualifiedNameReference(node); return super.visit(node, scope); } |