aboutsummaryrefslogtreecommitdiff
path: root/src/core/lombok/javac/apt
diff options
context:
space:
mode:
authorReinier Zwitserloot <reinier@zwitserloot.com>2012-08-10 18:30:35 +0200
committerReinier Zwitserloot <reinier@zwitserloot.com>2012-08-10 18:30:35 +0200
commit0dbc68a5cc2df113c22a72c78c39dedd1e1cb714 (patch)
treefdc7a3c836ac5a702ee5ff15062d1ac451a1c699 /src/core/lombok/javac/apt
parentb31ca9606b25839701194c5fca71c12c1a165565 (diff)
downloadlombok-0dbc68a5cc2df113c22a72c78c39dedd1e1cb714.tar.gz
lombok-0dbc68a5cc2df113c22a72c78c39dedd1e1cb714.tar.bz2
lombok-0dbc68a5cc2df113c22a72c78c39dedd1e1cb714.zip
Added an optimization to javac: Don't force new resolution rounds if none of the handlers in the next priority level need it.
Diffstat (limited to 'src/core/lombok/javac/apt')
-rw-r--r--src/core/lombok/javac/apt/Processor.java68
1 files changed, 41 insertions, 27 deletions
diff --git a/src/core/lombok/javac/apt/Processor.java b/src/core/lombok/javac/apt/Processor.java
index 190a369b..94e0e644 100644
--- a/src/core/lombok/javac/apt/Processor.java
+++ b/src/core/lombok/javac/apt/Processor.java
@@ -29,6 +29,7 @@ import java.lang.reflect.Method;
import java.net.URL;
import java.util.ArrayList;
import java.util.Enumeration;
+import java.util.HashSet;
import java.util.IdentityHashMap;
import java.util.List;
import java.util.Map;
@@ -85,10 +86,12 @@ public class Processor extends AbstractProcessor {
SortedSet<Long> p = transformer.getPriorities();
if (p.isEmpty()) {
this.priorityLevels = new long[] {0L};
+ this.priorityLevelsRequiringResolutionReset = new HashSet<Long>();
} else {
this.priorityLevels = new long[p.size()];
int i = 0;
for (Long prio : p) this.priorityLevels[i++] = prio;
+ this.priorityLevelsRequiringResolutionReset = transformer.getPrioritiesRequiringResolutionReset();
}
}
@@ -216,6 +219,7 @@ public class Processor extends AbstractProcessor {
private final IdentityHashMap<JCCompilationUnit, Long> roots = new IdentityHashMap<JCCompilationUnit, Long>();
private long[] priorityLevels;
+ private Set<Long> priorityLevelsRequiringResolutionReset;
/** {@inheritDoc} */
@Override public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
@@ -232,37 +236,47 @@ public class Processor extends AbstractProcessor {
roots.put(unit, priorityLevels[0]);
}
- // Step 2: For all CUs (in the map, not the roundEnv!), run them across all handlers at their current prio level.
-
- for (long prio : priorityLevels) {
- List<JCCompilationUnit> cusForThisRound = new ArrayList<JCCompilationUnit>();
- for (Map.Entry<JCCompilationUnit, Long> entry : roots.entrySet()) {
- Long prioOfCu = entry.getValue();
- if (prioOfCu == null || prioOfCu != prio) continue;
- cusForThisRound.add(entry.getKey());
+ while (true) {
+ // Step 2: For all CUs (in the map, not the roundEnv!), run them across all handlers at their current prio level.
+
+ for (long prio : priorityLevels) {
+ List<JCCompilationUnit> cusForThisRound = new ArrayList<JCCompilationUnit>();
+ for (Map.Entry<JCCompilationUnit, Long> entry : roots.entrySet()) {
+ Long prioOfCu = entry.getValue();
+ if (prioOfCu == null || prioOfCu != prio) continue;
+ cusForThisRound.add(entry.getKey());
+ }
+ transformer.transform(prio, processingEnv.getContext(), cusForThisRound);
}
- transformer.transform(prio, processingEnv.getContext(), cusForThisRound);
- }
-
- // Step 3: Push up all CUs to the next level. Set level to null if there is no next level.
-
- boolean nextRoundNeeded = false;
- for (int i = priorityLevels.length - 1; i >= 0; i--) {
- Long curLevel = priorityLevels[i];
- Long nextLevel = (i == priorityLevels.length - 1) ? null : priorityLevels[i + 1];
- for (Map.Entry<JCCompilationUnit, Long> entry : roots.entrySet()) {
- if (curLevel.equals(entry.getValue())) {
- entry.setValue(nextLevel);
- if (nextLevel != null) nextRoundNeeded = true;
+
+ // Step 3: Push up all CUs to the next level. Set level to null if there is no next level.
+
+ Set<Long> newLevels = new HashSet<Long>();
+ for (int i = priorityLevels.length - 1; i >= 0; i--) {
+ Long curLevel = priorityLevels[i];
+ Long nextLevel = (i == priorityLevels.length - 1) ? null : priorityLevels[i + 1];
+ for (Map.Entry<JCCompilationUnit, Long> entry : roots.entrySet()) {
+ if (curLevel.equals(entry.getValue())) {
+ entry.setValue(nextLevel);
+ newLevels.add(nextLevel);
+ }
}
}
+ newLevels.remove(null);
+
+ // Step 4: If ALL values are null, quit. Else, either do another loop right now or force a resolution reset by forcing a new round in the annotation processor.
+
+ if (newLevels.isEmpty()) return false;
+ newLevels.retainAll(priorityLevelsRequiringResolutionReset);
+ if (newLevels.isEmpty()) {
+ // None of the new levels need resolution, so just keep going.
+ continue;
+ } else {
+ // Force a new round to reset resolution. The next round will cause this method (process) to be called again.
+ forceNewRound((JavacFiler) processingEnv.getFiler());
+ return false;
+ }
}
-
- // Step 4: If ALL values are null, quit. Else, force new round.
-
- if (nextRoundNeeded) forceNewRound((JavacFiler) processingEnv.getFiler());
-
- return false;
}
private int dummyCount = 0;