diff options
author | Roel Spilker <r.spilker@gmail.com> | 2009-11-27 03:10:03 +0100 |
---|---|---|
committer | Roel Spilker <r.spilker@gmail.com> | 2009-11-27 03:10:03 +0100 |
commit | e54c3f36e3122dfe34a119178cfcca2dcdbad998 (patch) | |
tree | 7ff5fb5ef40a34e0c36b4d6821af20e4c79d9a44 /src | |
parent | c91e3701b9f5cf85a09f998d305895d4d1617206 (diff) | |
download | lombok-e54c3f36e3122dfe34a119178cfcca2dcdbad998.tar.gz lombok-e54c3f36e3122dfe34a119178cfcca2dcdbad998.tar.bz2 lombok-e54c3f36e3122dfe34a119178cfcca2dcdbad998.zip |
Added change tracking so that 1 AST instance can tell you if any processor changed anything.
Diffstat (limited to 'src')
-rw-r--r-- | src/core/lombok/core/AST.java | 13 | ||||
-rw-r--r-- | src/core/lombok/core/LombokNode.java | 6 | ||||
-rw-r--r-- | src/core/lombok/eclipse/EclipseAST.java | 3 | ||||
-rw-r--r-- | src/core/lombok/javac/JavacAST.java | 1 |
4 files changed, 23 insertions, 0 deletions
diff --git a/src/core/lombok/core/AST.java b/src/core/lombok/core/AST.java index 6d786d1e..e769ce34 100644 --- a/src/core/lombok/core/AST.java +++ b/src/core/lombok/core/AST.java @@ -54,11 +54,24 @@ public abstract class AST<A extends AST<A, L, N>, L extends LombokNode<A, L, N>, private final String fileName; Map<N, Void> identityDetector = new IdentityHashMap<N, Void>(); private Map<N, L> nodeMap = new IdentityHashMap<N, L>(); + private boolean changed = false; protected AST(String fileName) { this.fileName = fileName == null ? "(unknown).java" : fileName; } + protected void setChanged() { + this.changed = true; + } + + protected void clearChanged() { + this.changed = false; + } + + public boolean isChanged() { + return changed; + } + /** Set the node object that wraps the internal Compilation Unit node. */ protected void setTop(L top) { this.top = top; diff --git a/src/core/lombok/core/LombokNode.java b/src/core/lombok/core/LombokNode.java index c8ee4c00..95c5a0cb 100644 --- a/src/core/lombok/core/LombokNode.java +++ b/src/core/lombok/core/LombokNode.java @@ -126,6 +126,7 @@ public abstract class LombokNode<A extends AST<A, L, N>, L extends LombokNode<A, */ @SuppressWarnings("unchecked") public L replaceWith(N newN, Kind newNodeKind) { + ast.setChanged(); L newNode = ast.buildTree(newN, newNodeKind); newNode.parent = parent; for (int i = 0; i < parent.children.size(); i++) { @@ -142,6 +143,7 @@ public abstract class LombokNode<A extends AST<A, L, N>, L extends LombokNode<A, * Also affects the underlying (Eclipse/javac) AST. */ public void replaceChildNode(N oldN, N newN) { + ast.setChanged(); ast.replaceStatementInNode(get(), oldN, newN); } @@ -228,6 +230,7 @@ public abstract class LombokNode<A extends AST<A, L, N>, L extends LombokNode<A, */ @SuppressWarnings("unchecked") public L add(N newChild, Kind newChildKind) { + ast.setChanged(); L n = ast.buildTree(newChild, newChildKind); if (n == null) return null; n.parent = (L) this; @@ -247,6 +250,8 @@ public abstract class LombokNode<A extends AST<A, L, N>, L extends LombokNode<A, L newNode = ast.buildTree(get(), kind); + ast.setChanged(); + ast.replaceNewWithExistingOld(oldNodes, newNode); } @@ -265,6 +270,7 @@ public abstract class LombokNode<A extends AST<A, L, N>, L extends LombokNode<A, * Does not change the underlying (javac/Eclipse) AST, only the wrapped view. */ public void removeChild(L child) { + ast.setChanged(); children.remove(child); } diff --git a/src/core/lombok/eclipse/EclipseAST.java b/src/core/lombok/eclipse/EclipseAST.java index e42e5de2..7f436ddf 100644 --- a/src/core/lombok/eclipse/EclipseAST.java +++ b/src/core/lombok/eclipse/EclipseAST.java @@ -60,6 +60,7 @@ public class EclipseAST extends AST<EclipseAST, EclipseNode, ASTNode> { this.compilationUnitDeclaration = ast; setTop(buildCompilationUnit(ast)); this.completeParse = isComplete(ast); + clearChanged(); } /** {@inheritDoc} */ @@ -201,12 +202,14 @@ public class EclipseAST extends AST<EclipseAST, EclipseNode, ASTNode> { public void reparse() { propagateProblems(); if (completeParse) return; + boolean changed = isChanged(); boolean newCompleteParse = isComplete(compilationUnitDeclaration); if (!newCompleteParse) return; top().rebuild(); this.completeParse = true; + if (!changed) clearChanged(); } private static boolean isComplete(CompilationUnitDeclaration unit) { diff --git a/src/core/lombok/javac/JavacAST.java b/src/core/lombok/javac/JavacAST.java index 77c63cfe..93e3f3dc 100644 --- a/src/core/lombok/javac/JavacAST.java +++ b/src/core/lombok/javac/JavacAST.java @@ -78,6 +78,7 @@ public class JavacAST extends AST<JavacAST, JavacNode, JCTree> { this.nameTable = Name.Table.instance(context); this.treeMaker = TreeMaker.instance(context); this.symtab = Symtab.instance(context); + clearChanged(); } public Context getContext() { |