diff options
Diffstat (limited to 'src/core/lombok/eclipse')
17 files changed, 100 insertions, 4 deletions
diff --git a/src/core/lombok/eclipse/EclipseASTVisitor.java b/src/core/lombok/eclipse/EclipseASTVisitor.java index 0c0e2d96..7f9faf43 100644 --- a/src/core/lombok/eclipse/EclipseASTVisitor.java +++ b/src/core/lombok/eclipse/EclipseASTVisitor.java @@ -1,5 +1,5 @@ /* - * Copyright © 2009 Reinier Zwitserloot and Roel Spilker. + * Copyright © 2009-2011 Reinier Zwitserloot and Roel Spilker. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -43,6 +43,13 @@ import org.eclipse.jdt.internal.compiler.ast.TypeReference; */ public interface EclipseASTVisitor { /** + * Return true if this handler should not be run in the diet parse phase. + * 'diet parse' is where method bodies aren't filled in yet. If you have a method-level annotation that modifies the contents of that method, + * return {@code true} here. Otherwise, return {@code false} here. + */ + boolean deferUntilPostDiet(); + + /** * Called at the very beginning and end. */ void visitCompilationUnit(EclipseNode top, CompilationUnitDeclaration unit); @@ -112,6 +119,10 @@ public interface EclipseASTVisitor { private int indent = 0; private boolean printClassNames = false; + public boolean deferUntilPostDiet() { + return false; + } + /** * @param printContent if true, bodies are printed directly, as java code, * instead of a tree listing of every AST node inside it. diff --git a/src/core/lombok/eclipse/EclipseAnnotationHandler.java b/src/core/lombok/eclipse/EclipseAnnotationHandler.java index c105f252..2841eb9f 100644 --- a/src/core/lombok/eclipse/EclipseAnnotationHandler.java +++ b/src/core/lombok/eclipse/EclipseAnnotationHandler.java @@ -49,4 +49,11 @@ public interface EclipseAnnotationHandler<T extends java.lang.annotation.Annotat * as access useful methods such as generating warnings or errors focused on the annotation. */ void handle(AnnotationValues<T> annotation, org.eclipse.jdt.internal.compiler.ast.Annotation ast, EclipseNode annotationNode); + + /** + * Return true if this handler should not be run in the diet parse phase. + * 'diet parse' is where method bodies aren't filled in yet. If you have a method-level annotation that modifies the contents of that method, + * return {@code true} here. Otherwise, return {@code false} here. + */ + boolean deferUntilPostDiet(); } diff --git a/src/core/lombok/eclipse/EclipseNode.java b/src/core/lombok/eclipse/EclipseNode.java index e6fd1b03..62238a1c 100644 --- a/src/core/lombok/eclipse/EclipseNode.java +++ b/src/core/lombok/eclipse/EclipseNode.java @@ -1,5 +1,5 @@ /* - * Copyright © 2009-2010 Reinier Zwitserloot and Roel Spilker. + * Copyright © 2009-2011 Reinier Zwitserloot and Roel Spilker. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -50,6 +50,8 @@ public class EclipseNode extends lombok.core.LombokNode<EclipseAST, EclipseNode, * Visits this node and all child nodes depth-first, calling the provided visitor's visit methods. */ public void traverse(EclipseASTVisitor visitor) { + if (!this.isCompleteParse() && visitor.deferUntilPostDiet()) return; + switch (getKind()) { case COMPILATION_UNIT: visitor.visitCompilationUnit(this, (CompilationUnitDeclaration)get()); diff --git a/src/core/lombok/eclipse/HandlerLibrary.java b/src/core/lombok/eclipse/HandlerLibrary.java index 231a00d6..efc00873 100644 --- a/src/core/lombok/eclipse/HandlerLibrary.java +++ b/src/core/lombok/eclipse/HandlerLibrary.java @@ -72,6 +72,10 @@ public class HandlerLibrary { AnnotationValues<T> annValues = Eclipse.createAnnotation(annotationClass, annotationNode); handler.handle(annValues, annotation, annotationNode); } + + public boolean deferUntilPostDiet() { + return handler.deferUntilPostDiet(); + } } private Map<String, AnnotationHandlerContainer<?>> annotationHandlers = @@ -167,6 +171,7 @@ public class HandlerLibrary { AnnotationHandlerContainer<?> container = annotationHandlers.get(fqn); if (container == null) continue; + if (!annotationNode.isCompleteParse() && container.deferUntilPostDiet()) continue; try { if (checkAndSetHandled(annotation)) container.handle(annotation, annotationNode); diff --git a/src/core/lombok/eclipse/TransformEclipseAST.java b/src/core/lombok/eclipse/TransformEclipseAST.java index 314c8a7d..e260604b 100644 --- a/src/core/lombok/eclipse/TransformEclipseAST.java +++ b/src/core/lombok/eclipse/TransformEclipseAST.java @@ -167,6 +167,10 @@ public class TransformEclipseAST { } private static class AnnotationVisitor extends EclipseASTAdapter { + public boolean deferUntilPostDiet() { + return false; + } + @Override public void visitAnnotationOnField(FieldDeclaration field, EclipseNode annotationNode, Annotation annotation) { CompilationUnitDeclaration top = (CompilationUnitDeclaration) annotationNode.top().get(); handlers.handleAnnotation(top, annotationNode, annotation); diff --git a/src/core/lombok/eclipse/handlers/HandleCleanup.java b/src/core/lombok/eclipse/handlers/HandleCleanup.java index 4f9615b6..6620e9d7 100644 --- a/src/core/lombok/eclipse/handlers/HandleCleanup.java +++ b/src/core/lombok/eclipse/handlers/HandleCleanup.java @@ -59,6 +59,10 @@ import org.mangosdk.spi.ProviderFor; */ @ProviderFor(EclipseAnnotationHandler.class) public class HandleCleanup implements EclipseAnnotationHandler<Cleanup> { + @Override public boolean deferUntilPostDiet() { + return false; + } + public void handle(AnnotationValues<Cleanup> annotation, Annotation ast, EclipseNode annotationNode) { String cleanupName = annotation.getInstance().value(); if (cleanupName.length() == 0) { diff --git a/src/core/lombok/eclipse/handlers/HandleConstructor.java b/src/core/lombok/eclipse/handlers/HandleConstructor.java index e0715961..a0589ad7 100644 --- a/src/core/lombok/eclipse/handlers/HandleConstructor.java +++ b/src/core/lombok/eclipse/handlers/HandleConstructor.java @@ -73,6 +73,10 @@ import org.mangosdk.spi.ProviderFor; public class HandleConstructor { @ProviderFor(EclipseAnnotationHandler.class) public static class HandleNoArgsConstructor implements EclipseAnnotationHandler<NoArgsConstructor> { + @Override public boolean deferUntilPostDiet() { + return false; + } + @Override public void handle(AnnotationValues<NoArgsConstructor> annotation, Annotation ast, EclipseNode annotationNode) { EclipseNode typeNode = annotationNode.up(); if (!checkLegality(typeNode, annotationNode, NoArgsConstructor.class.getSimpleName())) return; @@ -88,6 +92,10 @@ public class HandleConstructor { @ProviderFor(EclipseAnnotationHandler.class) public static class HandleRequiredArgsConstructor implements EclipseAnnotationHandler<RequiredArgsConstructor> { + @Override public boolean deferUntilPostDiet() { + return false; + } + @Override public void handle(AnnotationValues<RequiredArgsConstructor> annotation, Annotation ast, EclipseNode annotationNode) { EclipseNode typeNode = annotationNode.up(); if (!checkLegality(typeNode, annotationNode, RequiredArgsConstructor.class.getSimpleName())) return; @@ -117,6 +125,10 @@ public class HandleConstructor { @ProviderFor(EclipseAnnotationHandler.class) public static class HandleAllArgsConstructor implements EclipseAnnotationHandler<AllArgsConstructor> { + @Override public boolean deferUntilPostDiet() { + return false; + } + @Override public void handle(AnnotationValues<AllArgsConstructor> annotation, Annotation ast, EclipseNode annotationNode) { EclipseNode typeNode = annotationNode.up(); if (!checkLegality(typeNode, annotationNode, AllArgsConstructor.class.getSimpleName())) return; diff --git a/src/core/lombok/eclipse/handlers/HandleData.java b/src/core/lombok/eclipse/handlers/HandleData.java index 9b3d7e51..5d05af6b 100644 --- a/src/core/lombok/eclipse/handlers/HandleData.java +++ b/src/core/lombok/eclipse/handlers/HandleData.java @@ -37,6 +37,10 @@ import org.mangosdk.spi.ProviderFor; */ @ProviderFor(EclipseAnnotationHandler.class) public class HandleData implements EclipseAnnotationHandler<Data> { + @Override public boolean deferUntilPostDiet() { + return false; + } + public void handle(AnnotationValues<Data> annotation, Annotation ast, EclipseNode annotationNode) { Data ann = annotation.getInstance(); EclipseNode typeNode = annotationNode.up(); diff --git a/src/core/lombok/eclipse/handlers/HandleEqualsAndHashCode.java b/src/core/lombok/eclipse/handlers/HandleEqualsAndHashCode.java index 3be8fdfa..9fdbea1e 100644 --- a/src/core/lombok/eclipse/handlers/HandleEqualsAndHashCode.java +++ b/src/core/lombok/eclipse/handlers/HandleEqualsAndHashCode.java @@ -116,6 +116,10 @@ public class HandleEqualsAndHashCode implements EclipseAnnotationHandler<EqualsA generateMethods(typeNode, errorNode, null, null, null, false, FieldAccess.GETTER); } + @Override public boolean deferUntilPostDiet() { + return false; + } + @Override public void handle(AnnotationValues<EqualsAndHashCode> annotation, Annotation ast, EclipseNode annotationNode) { EqualsAndHashCode ann = annotation.getInstance(); diff --git a/src/core/lombok/eclipse/handlers/HandleGetter.java b/src/core/lombok/eclipse/handlers/HandleGetter.java index 3af09afb..17f2880c 100644 --- a/src/core/lombok/eclipse/handlers/HandleGetter.java +++ b/src/core/lombok/eclipse/handlers/HandleGetter.java @@ -131,6 +131,10 @@ public class HandleGetter implements EclipseAnnotationHandler<Getter> { createGetterForField(level, fieldNode, fieldNode, pos, false, onMethod, lazy); } + @Override public boolean deferUntilPostDiet() { + return false; + } + public void handle(AnnotationValues<Getter> annotation, Annotation ast, EclipseNode annotationNode) { EclipseNode node = annotationNode.up(); Getter annotationInstance = annotation.getInstance(); diff --git a/src/core/lombok/eclipse/handlers/HandleLog.java b/src/core/lombok/eclipse/handlers/HandleLog.java index a51d8e7e..9a10e5bc 100644 --- a/src/core/lombok/eclipse/handlers/HandleLog.java +++ b/src/core/lombok/eclipse/handlers/HandleLog.java @@ -46,7 +46,6 @@ import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants; import org.mangosdk.spi.ProviderFor; public class HandleLog { - private HandleLog() { throw new UnsupportedOperationException(); } @@ -154,6 +153,10 @@ public class HandleLog { */ @ProviderFor(EclipseAnnotationHandler.class) public static class HandleCommonsLog implements EclipseAnnotationHandler<lombok.extern.apachecommons.CommonsLog> { + @Override public boolean deferUntilPostDiet() { + return false; + } + @Override public void handle(AnnotationValues<lombok.extern.apachecommons.CommonsLog> annotation, Annotation source, EclipseNode annotationNode) { processAnnotation(LoggingFramework.COMMONS, annotation, source, annotationNode); } @@ -164,6 +167,10 @@ public class HandleLog { */ @ProviderFor(EclipseAnnotationHandler.class) public static class HandleJulLog implements EclipseAnnotationHandler<lombok.extern.java.Log> { + @Override public boolean deferUntilPostDiet() { + return false; + } + @Override public void handle(AnnotationValues<lombok.extern.java.Log> annotation, Annotation source, EclipseNode annotationNode) { processAnnotation(LoggingFramework.JUL, annotation, source, annotationNode); } @@ -174,6 +181,10 @@ public class HandleLog { */ @ProviderFor(EclipseAnnotationHandler.class) public static class HandleLog4jLog implements EclipseAnnotationHandler<lombok.extern.log4j.Log4j> { + @Override public boolean deferUntilPostDiet() { + return false; + } + @Override public void handle(AnnotationValues<lombok.extern.log4j.Log4j> annotation, Annotation source, EclipseNode annotationNode) { processAnnotation(LoggingFramework.LOG4J, annotation, source, annotationNode); } @@ -184,6 +195,10 @@ public class HandleLog { */ @ProviderFor(EclipseAnnotationHandler.class) public static class HandleSlf4jLog implements EclipseAnnotationHandler<lombok.extern.slf4j.Slf4j> { + @Override public boolean deferUntilPostDiet() { + return false; + } + @Override public void handle(AnnotationValues<lombok.extern.slf4j.Slf4j> annotation, Annotation source, EclipseNode annotationNode) { processAnnotation(LoggingFramework.SLF4J, annotation, source, annotationNode); } diff --git a/src/core/lombok/eclipse/handlers/HandlePrintAST.java b/src/core/lombok/eclipse/handlers/HandlePrintAST.java index be86a566..24a3f687 100644 --- a/src/core/lombok/eclipse/handlers/HandlePrintAST.java +++ b/src/core/lombok/eclipse/handlers/HandlePrintAST.java @@ -40,6 +40,10 @@ import lombok.eclipse.EclipseNode; */ @ProviderFor(EclipseAnnotationHandler.class) public class HandlePrintAST implements EclipseAnnotationHandler<PrintAST> { + @Override public boolean deferUntilPostDiet() { + return false; + } + public void handle(AnnotationValues<PrintAST> annotation, Annotation ast, EclipseNode annotationNode) { if (!annotationNode.isCompleteParse()) return; diff --git a/src/core/lombok/eclipse/handlers/HandleSetter.java b/src/core/lombok/eclipse/handlers/HandleSetter.java index ac3ff2a2..c9f98d15 100644 --- a/src/core/lombok/eclipse/handlers/HandleSetter.java +++ b/src/core/lombok/eclipse/handlers/HandleSetter.java @@ -120,6 +120,10 @@ public class HandleSetter implements EclipseAnnotationHandler<Setter> { createSetterForField(level, fieldNode, fieldNode, pos, false, onMethod, onParam); } + @Override public boolean deferUntilPostDiet() { + return false; + } + public void handle(AnnotationValues<Setter> annotation, Annotation ast, EclipseNode annotationNode) { EclipseNode node = annotationNode.up(); AccessLevel level = annotation.getInstance().value(); diff --git a/src/core/lombok/eclipse/handlers/HandleSneakyThrows.java b/src/core/lombok/eclipse/handlers/HandleSneakyThrows.java index 4b36d688..f426b9ce 100644 --- a/src/core/lombok/eclipse/handlers/HandleSneakyThrows.java +++ b/src/core/lombok/eclipse/handlers/HandleSneakyThrows.java @@ -69,6 +69,10 @@ public class HandleSneakyThrows implements EclipseAnnotationHandler<SneakyThrows } } + @Override public boolean deferUntilPostDiet() { + return true; + } + @Override public void handle(AnnotationValues<SneakyThrows> annotation, Annotation source, EclipseNode annotationNode) { List<String> exceptionNames = annotation.getRawExpressions("value"); List<DeclaredException> exceptions = new ArrayList<DeclaredException>(); diff --git a/src/core/lombok/eclipse/handlers/HandleSynchronized.java b/src/core/lombok/eclipse/handlers/HandleSynchronized.java index ac751aa5..905316bc 100644 --- a/src/core/lombok/eclipse/handlers/HandleSynchronized.java +++ b/src/core/lombok/eclipse/handlers/HandleSynchronized.java @@ -57,6 +57,10 @@ public class HandleSynchronized implements EclipseAnnotationHandler<Synchronized private static final char[] INSTANCE_LOCK_NAME = "$lock".toCharArray(); private static final char[] STATIC_LOCK_NAME = "$LOCK".toCharArray(); + @Override public boolean deferUntilPostDiet() { + return true; + } + @Override public void handle(AnnotationValues<Synchronized> annotation, Annotation source, EclipseNode annotationNode) { int p1 = source.sourceStart -1; int p2 = source.sourceStart -2; diff --git a/src/core/lombok/eclipse/handlers/HandleToString.java b/src/core/lombok/eclipse/handlers/HandleToString.java index 553f097b..fff8750f 100644 --- a/src/core/lombok/eclipse/handlers/HandleToString.java +++ b/src/core/lombok/eclipse/handlers/HandleToString.java @@ -98,6 +98,10 @@ public class HandleToString implements EclipseAnnotationHandler<ToString> { generateToString(typeNode, errorNode, null, null, includeFieldNames, null, false, FieldAccess.GETTER); } + @Override public boolean deferUntilPostDiet() { + return false; + } + public void handle(AnnotationValues<ToString> annotation, Annotation ast, EclipseNode annotationNode) { ToString ann = annotation.getInstance(); List<String> excludes = Arrays.asList(ann.exclude()); diff --git a/src/core/lombok/eclipse/handlers/HandleVal.java b/src/core/lombok/eclipse/handlers/HandleVal.java index 8ab43131..cca5d690 100644 --- a/src/core/lombok/eclipse/handlers/HandleVal.java +++ b/src/core/lombok/eclipse/handlers/HandleVal.java @@ -1,5 +1,5 @@ /* - * Copyright © 2010 Reinier Zwitserloot, Roel Spilker and Robbert Jan Grootjans. + * Copyright © 2010-2011 Reinier Zwitserloot, Roel Spilker and Robbert Jan Grootjans. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -37,6 +37,10 @@ import org.mangosdk.spi.ProviderFor; */ @ProviderFor(EclipseASTVisitor.class) public class HandleVal extends EclipseASTAdapter { + @Override public boolean deferUntilPostDiet() { + return false; + } + @Override public void visitLocal(EclipseNode localNode, LocalDeclaration local) { if (!Eclipse.typeMatches(val.class, localNode, local.type)) return; boolean variableOfForEach = false; |