gumtree.spoon.builder.LabelFinder 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.CtAssert;
import spoon.reflect.code.CtAssignment;
import spoon.reflect.code.CtBinaryOperator;
import spoon.reflect.code.CtBlock;
import spoon.reflect.code.CtBreak;
import spoon.reflect.code.CtConstructorCall;
import spoon.reflect.code.CtContinue;
import spoon.reflect.code.CtIf;
import spoon.reflect.code.CtInvocation;
import spoon.reflect.code.CtLiteral;
import spoon.reflect.code.CtOperatorAssignment;
import spoon.reflect.code.CtReturn;
import spoon.reflect.code.CtSuperAccess;
import spoon.reflect.code.CtThisAccess;
import spoon.reflect.code.CtTypeAccess;
import spoon.reflect.code.CtUnaryOperator;
import spoon.reflect.code.CtVariableAccess;
import spoon.reflect.code.CtWhile;
import spoon.reflect.declaration.CtNamedElement;
import spoon.reflect.path.CtRole;
import spoon.reflect.reference.CtTypeReference;
import spoon.reflect.visitor.CtInheritanceScanner;
class LabelFinder extends CtInheritanceScanner {
public String label = "";
@Override
public void scanCtNamedElement(CtNamedElement e) {
label = e.getSimpleName();
}
@Override
public void scanCtVariableAccess(CtVariableAccess variableAccess) {
label = variableAccess.getVariable().getSimpleName();
}
@Override
public void visitCtInvocation(CtInvocation invocation) {
if (invocation.getExecutable() != null) {
CtTypeReference decl = invocation.getExecutable().getDeclaringType();
label = (decl!=null?decl.getQualifiedName():"")+"#"+invocation.getExecutable().getSignature();
}
}
@Override
public void visitCtConstructorCall(CtConstructorCall ctConstructorCall) {
if (ctConstructorCall.getExecutable() != null) {
label = ctConstructorCall.getExecutable().getSignature();
}
}
@Override
public void visitCtLiteral(CtLiteral literal) {
label = literal.toString();
}
@Override
public void visitCtIf(CtIf e) {
label = "if";
}
@Override
public void visitCtWhile(CtWhile e) {
label = "while";
}
@Override
public void visitCtBreak(CtBreak e) {
label = "break";
}
@Override
public void visitCtContinue(CtContinue e) {
label = "break";
}
@Override
public void visitCtReturn(CtReturn e) {
label = "return";
}
@Override
public void visitCtAssert(CtAssert e) {
label = "assert";
}
@Override
public void visitCtAssignment(CtAssignment e) {
label = "=";
}
@Override
public void visitCtOperatorAssignment(CtOperatorAssignment e) {
label = e.getLabel();
}
@Override
public void visitCtBlock(CtBlock e) {
if (e.getRoleInParent() == CtRole.ELSE) {
label = "ELSE";
} else if (e.getRoleInParent() == CtRole.THEN) {
label = "THEN";
} else {
label = "{";
}
}
@Override
public void visitCtBinaryOperator(CtBinaryOperator operator) {
label = operator.getKind().toString();
}
@Override
public void visitCtUnaryOperator(CtUnaryOperator operator) {
label = operator.getKind().toString();
}
@Override
public void visitCtThisAccess(CtThisAccess thisAccess) {
label = thisAccess.toString();
}
@Override
public void visitCtSuperAccess(CtSuperAccess f) {
label = f.toString();
}
@Override
public void visitCtTypeAccess(CtTypeAccess typeAccess) {
if (typeAccess.getAccessedType() != null) {
label = typeAccess.getAccessedType().getQualifiedName();
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy