All Downloads are FREE. Search and download functionalities are using the official Maven repository.

gumtree.spoon.builder.LabelFinder Maven / Gradle / Ivy

Go to download

Computes the AST difference between two Spoon abstract syntax trees using the Gumtree algorithm.

There is a newer version: 1.81
Show newest version
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.CtComment;
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.CtAnnotation;
import spoon.reflect.declaration.CtNamedElement;
import spoon.reflect.declaration.CtType;
import spoon.reflect.path.CtRole;
import spoon.reflect.reference.CtTypeReference;
import spoon.reflect.visitor.CtInheritanceScanner;

import java.lang.annotation.Annotation;

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().isConstructor()) {
			CtType parentType = invocation.getParent(CtType.class);
			if (parentType.getQualifiedName().equals(invocation.getExecutable().getDeclaringType().getQualifiedName())) {
				label = "this";
			} else {
				label = "super";
			}
		} else {
			label = invocation.getExecutable().getSimpleName();
		}
	}

	@Override
	public  void visitCtConstructorCall(CtConstructorCall ctConstructorCall) {
		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 = "continue";
	}

	@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();
		}
	}

	@Override
	public void visitCtComment(CtComment comment) {
		label = comment.getContent();
	}

	@Override
	public  void visitCtAnnotation(CtAnnotation annotation) {
		if (annotation.getType() != null) {
			label = annotation.getType().getQualifiedName();
		}
	}

	@Override
	public  void visitCtTypeReference(CtTypeReference e) {
			label = e.getQualifiedName();
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy