aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRoland Praml <praml@foconis.de>2018-07-09 20:29:21 +0200
committerRoel Spilker <r.spilker@gmail.com>2018-08-20 20:46:31 +0200
commit100cff228d0f4d68219460aefe89b70877b726dc (patch)
treed0df4b9d8c7525e19be7d4aba056a37c247fa9a5 /src
parent2b0cd53d55d882fbc49d5f736c845353098eb34e (diff)
downloadlombok-100cff228d0f4d68219460aefe89b70877b726dc.tar.gz
lombok-100cff228d0f4d68219460aefe89b70877b726dc.tar.bz2
lombok-100cff228d0f4d68219460aefe89b70877b726dc.zip
reduced calls of traverse invocations
Diffstat (limited to 'src')
-rw-r--r--src/core/lombok/eclipse/HandlerLibrary.java18
-rw-r--r--src/core/lombok/eclipse/TransformEclipseAST.java28
2 files changed, 34 insertions, 12 deletions
diff --git a/src/core/lombok/eclipse/HandlerLibrary.java b/src/core/lombok/eclipse/HandlerLibrary.java
index 07c6f97b..75a22f03 100644
--- a/src/core/lombok/eclipse/HandlerLibrary.java
+++ b/src/core/lombok/eclipse/HandlerLibrary.java
@@ -32,6 +32,7 @@ import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
+import java.util.Set;
import java.util.SortedSet;
import java.util.TreeSet;
@@ -212,21 +213,25 @@ public class HandlerLibrary {
* @param ast The Compilation Unit that contains the Annotation AST Node.
* @param annotationNode The Lombok AST Node representing the Annotation AST Node.
* @param annotation 'node.get()' - convenience parameter.
+ * @param priority current prioritiy
+ * @return the priority we want to run - MAX_VALUE means never
*/
- public void handleAnnotation(CompilationUnitDeclaration ast, EclipseNode annotationNode, org.eclipse.jdt.internal.compiler.ast.Annotation annotation, long priority) {
+ public long handleAnnotation(CompilationUnitDeclaration ast, EclipseNode annotationNode, org.eclipse.jdt.internal.compiler.ast.Annotation annotation, long priority) {
TypeResolver resolver = new TypeResolver(annotationNode.getImportList());
TypeReference rawType = annotation.type;
- if (rawType == null) return;
+ if (rawType == null) return Long.MAX_VALUE;
String fqn = resolver.typeRefToFullyQualifiedName(annotationNode, typeLibrary, toQualifiedName(annotation.type.getTypeName()));
- if (fqn == null) return;
+ if (fqn == null) return Long.MAX_VALUE;
AnnotationHandlerContainer<?> container = annotationHandlers.get(fqn);
- if (container == null) return;
- if (priority != container.getPriority()) return;
+ if (container == null) return Long.MAX_VALUE;
+
+ if (priority < container.getPriority()) return container.getPriority(); // we want to run at this priority
+ if (priority > container.getPriority()) return Long.MAX_VALUE; // it's over- we do not want to run again
if (!annotationNode.isCompleteParse() && container.deferUntilPostDiet()) {
if (needsHandling(annotation)) container.preHandle(annotation, annotationNode);
- return;
+ return Long.MAX_VALUE;
}
try {
@@ -236,6 +241,7 @@ public class HandlerLibrary {
} catch (Throwable t) {
error(ast, String.format("Lombok annotation handler %s failed", container.handler.getClass()), t);
}
+ return Long.MAX_VALUE;
}
/**
diff --git a/src/core/lombok/eclipse/TransformEclipseAST.java b/src/core/lombok/eclipse/TransformEclipseAST.java
index 541924ad..24e24495 100644
--- a/src/core/lombok/eclipse/TransformEclipseAST.java
+++ b/src/core/lombok/eclipse/TransformEclipseAST.java
@@ -24,6 +24,8 @@ package lombok.eclipse;
import static lombok.eclipse.handlers.EclipseHandlerUtil.*;
import java.lang.reflect.Field;
+import java.util.HashSet;
+import java.util.Set;
import lombok.ConfigurationKeys;
import lombok.core.LombokConfiguration;
@@ -186,42 +188,56 @@ public class TransformEclipseAST {
* then handles any PrintASTs.
*/
public void go() {
+ long nextPriority = Long.MIN_VALUE;
for (Long d : handlers.getPriorities()) {
- ast.traverse(new AnnotationVisitor(d));
+ if (nextPriority > d) {
+ continue;
+ }
+ AnnotationVisitor visitor = new AnnotationVisitor(d);
+ ast.traverse(visitor);
+ // if no visitor interested for this AST, nextPriority would be MAX_VALUE and we bail out immediatetly
+ nextPriority = visitor.getNextPriority();
handlers.callASTVisitors(ast, d, ast.isCompleteParse());
}
}
private static class AnnotationVisitor extends EclipseASTAdapter {
private final long priority;
+ // this is the next priority we continue to visit.
+ // Long.MAX_VALUE means never. Each visit method will potentially reduce the next priority
+ private long nextPriority = Long.MAX_VALUE;
public AnnotationVisitor(long priority) {
this.priority = priority;
}
+ public long getNextPriority() {
+ return nextPriority;
+ }
+
@Override public void visitAnnotationOnField(FieldDeclaration field, EclipseNode annotationNode, Annotation annotation) {
CompilationUnitDeclaration top = (CompilationUnitDeclaration) annotationNode.top().get();
- handlers.handleAnnotation(top, annotationNode, annotation, priority);
+ nextPriority = Math.min(nextPriority, handlers.handleAnnotation(top, annotationNode, annotation, priority));
}
@Override public void visitAnnotationOnMethodArgument(Argument arg, AbstractMethodDeclaration method, EclipseNode annotationNode, Annotation annotation) {
CompilationUnitDeclaration top = (CompilationUnitDeclaration) annotationNode.top().get();
- handlers.handleAnnotation(top, annotationNode, annotation, priority);
+ nextPriority = Math.min(nextPriority, handlers.handleAnnotation(top, annotationNode, annotation, priority));
}
@Override public void visitAnnotationOnLocal(LocalDeclaration local, EclipseNode annotationNode, Annotation annotation) {
CompilationUnitDeclaration top = (CompilationUnitDeclaration) annotationNode.top().get();
- handlers.handleAnnotation(top, annotationNode, annotation, priority);
+ nextPriority = Math.min(nextPriority, handlers.handleAnnotation(top, annotationNode, annotation, priority));
}
@Override public void visitAnnotationOnMethod(AbstractMethodDeclaration method, EclipseNode annotationNode, Annotation annotation) {
CompilationUnitDeclaration top = (CompilationUnitDeclaration) annotationNode.top().get();
- handlers.handleAnnotation(top, annotationNode, annotation, priority);
+ nextPriority = Math.min(nextPriority, handlers.handleAnnotation(top, annotationNode, annotation, priority));
}
@Override public void visitAnnotationOnType(TypeDeclaration type, EclipseNode annotationNode, Annotation annotation) {
CompilationUnitDeclaration top = (CompilationUnitDeclaration) annotationNode.top().get();
- handlers.handleAnnotation(top, annotationNode, annotation, priority);
+ nextPriority = Math.min(nextPriority, handlers.handleAnnotation(top, annotationNode, annotation, priority));
}
}
}