Java Code Examples for spoon.reflect.code.CtThisAccess

The following examples show how to use spoon.reflect.code.CtThisAccess. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: astor   Source File: InvocationResolver.java    License: GNU General Public License v2.0 5 votes vote down vote up
@SuppressWarnings("rawtypes")
public static InvocationMatching mapImplicitInvocation(CtClass ctClassMP, CtAbstractInvocation inv0) {
	if (inv0 instanceof CtInvocation) {
		CtInvocation invocation0 = (CtInvocation) inv0;

		CtExpression tpr = invocation0.getTarget();
		if (tpr instanceof CtThisAccess) {
			CtThisAccess<?> targetthis = (CtThisAccess) tpr;
			CtTypeReference tpref = targetthis.getType();
			if (ctClassMP.isSubtypeOf(tpref))
				return InvocationMatching.TARGET_SAME_TYPE;
			else if (chechSignatures(ctClassMP.getAllExecutables(), invocation0.getExecutable(), false)) {
				return InvocationMatching.SAME_SIGNATURE_FROM_DIFF_TYPE;
			} else {
				log.debug("Signature " + invocation0.getExecutable().getSignature());
				log.debug(
						"Not compatible: " + ctClassMP.getQualifiedName() + " with " + (tpref.getQualifiedName()));
				return InvocationMatching.TARGET_INCOMPATIBLE;
			}
		} else {
			log.debug("Explicit target " + tpr);
			return InvocationMatching.TARGET_IS_VARIABLE;
		}
	} else {

		if (inv0 instanceof CtConstructorCall) {
			return InvocationMatching.CONTRUCTOR;

		}

		return InvocationMatching.OTHER;
	}

}
 
Example 2
@Override
public <T> void visitCtThisAccess(CtThisAccess<T> thisAccess) {
    /* this method has to be implemented by the non abstract class */
}
 
Example 3
Source Project: astor   Source File: SupportOperators.java    License: GNU General Public License v2.0 4 votes vote down vote up
public static List<CtInvocation> retrieveInvocationsFromMethod(CtTypeReference variableToReplaceType,
		CtClass classUnderAnalysis, ModificationPoint point) {
	List<CtInvocation> newInvocations = new ArrayList<>();

	boolean isParentMethodStatic = isParentMethodStatic(point.getCodeElement());

	List allMethods = SupportOperators.getAllMethodsFromClass(classUnderAnalysis);

	CtThisAccess<Object> createThisAccess = MutationSupporter.getFactory()
			.createThisAccess(MutationSupporter.getFactory().Type().objectType(), true);

	for (Object omethod : allMethods) {

		if (!(omethod instanceof CtMethod))
			continue;

		CtMethod anotherMethod = (CtMethod) omethod;

		if (isParentMethodStatic && //
				!anotherMethod.getModifiers().contains(ModifierKind.STATIC)) {
			// if the modification point is in a static method, the method to call must be
			// static
			continue;
		}

		if (anotherMethod.getSimpleName().startsWith(VarReplacementByMethodCallOp.META_METHOD_LABEL))
			// It's a meta-method, discard
			continue;

		boolean compatibleReturnTypes = SupportOperators.checkIsSubtype(anotherMethod.getType(),
				variableToReplaceType);

		if (compatibleReturnTypes) {

			List<CtInvocation> newInvToMethods = createRealInvocationsAllPosibilities(point, anotherMethod,
					createThisAccess);
			newInvocations.addAll(newInvToMethods);
		}
	}

	return newInvocations;
}
 
Example 4
Source Project: gumtree-spoon-ast-diff   Source File: LabelFinder.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public <T> void visitCtThisAccess(CtThisAccess<T> thisAccess) {
	label = thisAccess.toString();
}