mirror of
https://github.com/tiennm99/lombok.git
synced 2026-10-14 02:16:18 +00:00
Added change tracking so that 1 AST instance can tell you if any processor changed anything.
This commit is contained in:
1 parent
c91e3701b9
commit
e54c3f36e3
4 files changed
+23
No files matched your search
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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() {
|
||||
|
||||
Reference in new issue
Block a user