gumtree.spoon.builder.NodeCreator Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of gumtree-spoon-ast-diff Show documentation
Show all versions of gumtree-spoon-ast-diff Show documentation
Computes the AST difference between two Spoon abstract syntax trees using the Gumtree algorithm.
package gumtree.spoon.builder;
import spoon.reflect.code.CtArrayAccess;
import spoon.reflect.code.CtBinaryOperator;
import spoon.reflect.code.CtConstructorCall;
import spoon.reflect.code.CtExpression;
import spoon.reflect.code.CtInvocation;
import spoon.reflect.code.CtLiteral;
import spoon.reflect.code.CtThisAccess;
import spoon.reflect.code.CtTypeAccess;
import spoon.reflect.code.CtUnaryOperator;
import spoon.reflect.code.CtVariableAccess;
import spoon.reflect.declaration.CtNamedElement;
import spoon.reflect.visitor.CtInheritanceScanner;
class NodeCreator extends CtInheritanceScanner {
private final TreeScanner builder;
NodeCreator(TreeScanner builder) {
this.builder = builder;
}
@Override
public void scanCtNamedElement(CtNamedElement e) {
builder.addNodeToTree(builder.createNode(e, e.getSimpleName()));
}
@Override
public > void scanCtArrayAccess(CtArrayAccess arrayAccess) {
builder.addNodeToTree(builder.createNode(arrayAccess, arrayAccess.toString()));
}
@Override
public void scanCtVariableAccess(CtVariableAccess variableAccess) {
if (variableAccess.getVariable() != null) {
builder.addNodeToTree(builder.createNode(variableAccess, variableAccess.getVariable().getSimpleName()));
}
}
@Override
public void visitCtInvocation(CtInvocation invocation) {
if (invocation.getExecutable() != null) {
builder.addNodeToTree(builder.createNode(invocation, invocation.getExecutable().getSignature()));
}
}
@Override
public void visitCtConstructorCall(CtConstructorCall ctConstructorCall) {
if (ctConstructorCall.getType() != null) {
builder.addNodeToTree(builder.createNode(ctConstructorCall, ctConstructorCall.getExecutable().getSignature()));
}
}
@Override
public void visitCtLiteral(CtLiteral literal) {
builder.addNodeToTree(builder.createNode(literal, literal.toString()));
}
@Override
public void visitCtBinaryOperator(CtBinaryOperator operator) {
builder.addNodeToTree(builder.createNode(operator, operator.getKind().toString()));
}
@Override
public void visitCtUnaryOperator(CtUnaryOperator operator) {
builder.addNodeToTree(builder.createNode(operator, operator.getKind().toString()));
}
@Override
public void visitCtThisAccess(CtThisAccess thisAccess) {
builder.addNodeToTree(builder.createNode(thisAccess, thisAccess.toString()));
}
@Override
public void visitCtTypeAccess(CtTypeAccess typeAccess) {
builder.addNodeToTree(builder.createNode(typeAccess, typeAccess.getSignature()));
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy