Java Code Examples for spoon.reflect.reference.CtTypeReference

The following examples show how to use spoon.reflect.reference.CtTypeReference. 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
/**
 * Accept Numeric Variable
 */
@Override
public boolean isToBeProcessed(CtVariableRead candidate) {
	
	// SKIP not declared variable and Finale variable
	if(candidate.getVariable() == null) return false;

	if(candidate.getVariable().getSimpleName().equals("class")) return false;

	if(candidate.getVariable().getModifiers().contains(ModifierKind.FINAL)) return false;
	
	
	// SKIP IF VARIABLE IS CASTED
	if(candidate.getTypeCasts().size() > 0) return false;
	for(CtTypeReference type : candidate.getReferencedTypes()) {
		if(!this.isNumber(type)) return false;
	}
	
	if( candidate.getParent().getClass().equals(CtUnaryOperatorImpl.class)) return false;
	
	if(this.isNumber(candidate.getVariable().getType())){
		return true;
	}
	return false;
}
 
Example 2
private boolean isNumber(CtExpression<?> operand) {

	if (operand.getType().toString().equals(CtTypeReference.NULL_TYPE_NAME))
		return false;
	
	if (operand.toString().contains(".class"))
		return false;
			
	return operand.getType().getSimpleName().equals("int")
		|| operand.getType().getSimpleName().equals("long")
		|| operand.getType().getSimpleName().equals("byte")
		|| operand.getType().getSimpleName().equals("char")
	|| operand.getType().getSimpleName().equals("float")
	|| operand.getType().getSimpleName().equals("double")
	|| operand.getType().isSubtypeOf(getFactory().Type().createReference(Number.class));
}
 
Example 3
Source Project: nopol   Source File: SpoonReferenceLibrary.java    License: GNU General Public License v2.0 6 votes vote down vote up
private static boolean isVisibleFrom(CtTypeReference<?> accessingClass, CtModifiable modifiable, CtTypeReference<?> declaringClass, CtTypeReference<?> actualClass) {
    if (hasPublicModifier(modifiable)) {
        return true;
    }
    if ((isNestedIn(accessingClass, actualClass) || isNestedIn(actualClass, accessingClass)) && areSameClass(declaringClass, actualClass)) {
        return true;
    }
    if (hasNoVisibilityModifier(modifiable) && areFromSamePackage(declaringClass, actualClass) && areFromSamePackage(actualClass, accessingClass)) {
        return true;
    }
    if (hasPrivateModifier(modifiable) && areSameClass(declaringClass, accessingClass)) {
        return true;
    }
    if (hasProtectedModifier(modifiable) && areFromSamePackage(declaringClass, accessingClass)) {
        return true;
    }
    if (hasProtectedModifier(modifiable) && isSubclassOf(declaringClass, accessingClass) && areSameClass(actualClass, accessingClass)) {
        return true;
    }
    return false;
}
 
Example 4
/**
 * get all dependencies added by a CtTypedElement
 *
 * @param element
 * @return all dependencies added by element
 */
private List<CtTypeReference<?>> getDependencies(CtTypedElement<?> element) {
    List<CtTypeReference<?>> listDependencies = new ArrayList<>();
    // Literal
    if (element instanceof CtAnnotation) {
        return listDependencies;
    }
    if (element instanceof CtLiteral<?>) {
        CtLiteral<?> literal = (CtLiteral<?>) element;
        literal.getValue();
        if (literal.getValue() instanceof CtTypeReference<?>) {
            listDependencies.add((CtTypeReference<?>) literal.getValue());
        } else if (literal.getValue() instanceof CtTypedElement<?>) {
            listDependencies.add(((CtTypedElement<?>) literal.getValue())
                    .getType());
        }
    }
    // method invocation
    if (element instanceof CtInvocation<?>) {
        CtInvocation<?> invocation = (CtInvocation<?>) element;
        // the class of the method
        listDependencies.add(invocation.getExecutable().getDeclaringType());
    }
    listDependencies.add(element.getType());
    return listDependencies;
}
 
Example 5
Source Project: nopol   Source File: ClassCollector.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * get all dependencies added by a CtTypedElement
 *
 * @param element
 * @return all dependencies added by element
 */
private List<CtTypeReference<?>> getDependencies(CtTypedElement<?> element) {
    List<CtTypeReference<?>> listDependencies = new ArrayList<>();
    // Literal
    if (element instanceof CtAnnotation) {
        return listDependencies;
    }
    if (element instanceof CtLiteral<?>) {
        CtLiteral<?> literal = (CtLiteral<?>) element;
        literal.getValue();
        if (literal.getValue() instanceof CtTypeReference<?>) {
            listDependencies.add((CtTypeReference<?>) literal.getValue());
        } else if (literal.getValue() instanceof CtTypedElement<?>) {
            listDependencies.add(((CtTypedElement<?>) literal.getValue())
                    .getType());
        }
    }
    // method invocation
    if (element instanceof CtInvocation<?>) {
        CtInvocation<?> invocation = (CtInvocation<?>) element;
        // the class of the method
        listDependencies.add(invocation.getExecutable().getDeclaringType());
    }
    listDependencies.add(element.getType());
    return listDependencies;
}
 
Example 6
Source Project: nopol   Source File: MethodCollector.java    License: GNU General Public License v2.0 6 votes vote down vote up
@Override
public void process(CtInvocation ctElement) {
    CtExecutableReference executable = ctElement.getExecutable();
    if (executable.isConstructor()) {
        return;
    }
    String key = executable.toString();
    CtTypeReference declaringType = executable.getDeclaringType();
    if (declaringType.getPackage() != null) {
        key = declaringType.getPackage().getSimpleName() + "." + executable.getSimpleName();
    }
    if (!statMethod.containsKey(key)) {
        statMethod.put(key, 1);
    } else {
        statMethod.put(key, statMethod.get(key) + 1);
    }
}
 
Example 7
@SuppressWarnings("all")
@Test
public void main() {
    MavenLauncher launcher = new MavenLauncher(
            "./src/test/resources/project/",
            MavenLauncher.SOURCE_TYPE.APP_SOURCE);

    CtModel model = launcher.buildModel();
    List<CtMethod> methodList = model.
            filterChildren(new NamedElementFilter<CtPackage>(CtPackage.class, "ow2con")).
            filterChildren(new NamedElementFilter<CtPackage>(CtPackage.class, "publicapi")).
            filterChildren(new TypeFilter<CtMethod>(CtMethod.class)).
            filterChildren(new Filter<CtMethod>() {
                @Override
                public boolean matches(CtMethod element) {
                    boolean isPublic = element.isPublic();
                    CtTypeReference returnType = element.getType();
                    String privateApiPackage = "ow2con.privateapi";
                    boolean isTypeFromPrivateApi = returnType.getQualifiedName().contains(privateApiPackage);
                    return isPublic && isTypeFromPrivateApi;
                }
            }).list();
}
 
Example 8
public void process(CtPackage element) {
	CtPackageReference pack = element.getReference();
	Set<CtPackageReference> refs = new HashSet<>();
	for (CtType t : element.getTypes()) {
		List<CtTypeReference<?>> listReferences = Query.getReferences(t, new ReferenceTypeFilter<>(CtTypeReference.class));

		for (CtTypeReference<?> tref : listReferences) {
			if (tref.getPackage() != null && !tref.getPackage().equals(pack)) {
				if (ignoredTypes.contains(tref))
					continue;
				refs.add(tref.getPackage());
			}
		}
	}
	if (!refs.isEmpty()) {
		packRefs.put(pack, refs);
	}
}
 
Example 9
Source Project: coming   Source File: AbstractCodeAnalyzer.java    License: MIT License 6 votes vote down vote up
public CtInvocation checkInvocationWithParemetrCompatibleType(List<CtInvocation> invocationsFromClass,
		CtTypeReference type) {

	for (CtInvocation anInvocation : invocationsFromClass) {

		for (Object anObjArgument : anInvocation.getArguments()) {
			CtExpression anArgument = (CtExpression) anObjArgument;

			if (compareTypes(type, anArgument.getType())) {
				return anInvocation;
			}
		}
	}

	return null;
}
 
Example 10
Source Project: gumtree-spoon-ast-diff   Source File: NodeCreator.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public <T> void visitCtMethod(CtMethod<T> e) {
	// add the return type of the method
	CtTypeReference<T> type = e.getType();
	if (type != null) {
		ITree returnType = builder.createNode("RETURN_TYPE", type.getQualifiedName());
		returnType.setMetadata(SpoonGumTreeBuilder.SPOON_OBJECT, type);
		type.putMetadata(SpoonGumTreeBuilder.GUMTREE_NODE, returnType);
		builder.addSiblingNode(returnType);
	}

	for (CtTypeReference thrown : e.getThrownTypes()) {
		ITree thrownType = builder.createNode("THROWS", thrown.getQualifiedName());
		thrownType.setMetadata(SpoonGumTreeBuilder.SPOON_OBJECT, thrown);
		type.putMetadata(SpoonGumTreeBuilder.GUMTREE_NODE, thrownType);
		builder.addSiblingNode(thrownType);
	}

	super.visitCtMethod(e);
}
 
Example 11
Source Project: coming   Source File: VariableResolver.java    License: MIT License 6 votes vote down vote up
/**
 * For a given VariableAccess, we search the list of Variables contains
 * compatible types (i.e. sub types)
 * 
 * @param varContext
 * @param vartofind
 * @return
 */
@SuppressWarnings({ "rawtypes", "unchecked" })
protected static List<CtVariable> compatiblesSubType(List<CtVariable> varContext, CtTypeReference typeToFind) {

	List<CtVariable> result = new ArrayList<CtVariable>();

	for (CtVariable ctVariable_i : varContext) {

		CtTypeReference typeref_i = ctVariable_i.getType();
		try {
			if (typeref_i.isSubtypeOf(typeToFind)) {
				result.add(ctVariable_i);
			}
		} catch (Exception e) {
			result.add(ctVariable_i);
		}

	}
	return result;
}
 
Example 12
Source Project: astor   Source File: VariableResolver.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * For a given VariableAccess, we search the list of Variables contains
 * compatible types (i.e. sub types)
 * 
 * @param varContext
 * @param vartofind
 * @return
 */
@SuppressWarnings({ "rawtypes", "unchecked" })
protected static List<CtVariable> compatiblesSubType(List<CtVariable> varContext, CtTypeReference typeToFind) {

	List<CtVariable> result = new ArrayList<CtVariable>();

	for (CtVariable ctVariable_i : varContext) {

		CtTypeReference typeref_i = ctVariable_i.getType();
		try {
			if (typeref_i.isSubtypeOf(typeToFind)) {
				result.add(ctVariable_i);
			}
		} catch (Exception e) {
			result.add(ctVariable_i);
		}

	}
	return result;
}
 
Example 13
Source Project: camunda-bpm-swagger   Source File: TypeHelper.java    License: Apache License 2.0 5 votes vote down vote up
public static Optional<CtMethod<?>> getInterfaceMethod(CtMethod<?> ctMethod) {
  if (ctMethod.getDeclaringType() instanceof CtClass) {
    final Optional<CtTypeReference<?>> firstSuperInterface = getFirstSuperInterface((CtClass<?>) ctMethod.getDeclaringType());
    if (firstSuperInterface.isPresent()) {
      return firstSuperInterface.get().getDeclaration().getMethods().stream().filter(m -> m.getSignature().equals(ctMethod.getSignature())).findFirst();
    }
  }
  return Optional.empty();
}
 
Example 14
public boolean isNumber(CtTypeReference type) {
	return type.getSimpleName().equals("int")
		|| type.getSimpleName().equals("long")
		|| type.getSimpleName().equals("byte")
	|| type.getSimpleName().equals("float")
	|| type.getSimpleName().equals("double");
}
 
Example 15
@Override
public boolean isToBeProcessed(CtStatement element) {
	// if (element.getParent(CtAnonymousExecutable.class)!=null) {
			// System.out.println(element.getParent(CtAnonymousExecutable.class));
			// }
	
			if(!(element instanceof CtRHSReceiver))
				return false;
			try {
				Selector.getTopLevelClass(element);
			} catch (Exception e) {
				return false;
			}

			// not in constructors because we use static fields
			if (element.getParent(CtConstructor.class) != null) {
				return false;
			}
			
			if (((CtRHSReceiver)element).getAssignment() == null)
				return false;
			
			CtTypeReference type = ((CtRHSReceiver)element).getAssignment().getType();
			
			if (type == null)
				return false;
			
			if (element.toString().contains("java.lang.String.format"))
				return false;

			return !((CtRHSReceiver)element).getAssignment().getType().isPrimitive() 
					&& (element.getParent(CtAnonymousExecutable.class) == null);
}
 
Example 16
Source Project: astor   Source File: WrapwithIfOp.java    License: GNU General Public License v2.0 5 votes vote down vote up
@Override
public List<MetaOperatorInstance> createMetaOperatorInstances(ModificationPoint modificationPoint,
		List<IngredientFromDyna> ingredients) {

	// The parameters to be included in the new method
	List<CtVariableAccess> varsToBeParameters = SupportOperators.collectAllVarsFromDynaIngredients(ingredients,
			modificationPoint);

	// List of parameters
	List<CtParameter<?>> parameters = new ArrayList<>();
	List<CtExpression<?>> realParameters = new ArrayList<>();
	for (CtVariableAccess ctVariableAccess : varsToBeParameters) {
		// the parent is null, it is setter latter
		CtParameter pari = MutationSupporter.getFactory().createParameter(null, ctVariableAccess.getType(),
				ctVariableAccess.getVariable().getSimpleName());
		parameters.add(pari);
		realParameters.add(ctVariableAccess.clone().setPositions(new NoSourcePosition()));
	}

	// let's start with one, and let's keep the Zero for the default (all ifs are
	// false)
	int candidateNumber = 0;
	CtTypeReference returnType = MutationSupporter.getFactory().createCtTypeReference(Boolean.class);

	CtElement codeElement = (targetElement == null) ? modificationPoint.getCodeElement() : targetElement;

	// let's create the meta

	MetaOperatorInstance megaOp = MetaGenerator.createMetaStatementReplacement(modificationPoint, codeElement,
			MutationSupporter.getFactory().createCodeSnippetExpression("true"), candidateNumber,
			ingredients.stream().map(Ingredient.class::cast).collect(Collectors.toList())//
			, parameters, realParameters, this, returnType);
	List<MetaOperatorInstance> opsMega = new ArrayList();
	opsMega.add(megaOp);

	return opsMega;
}
 
Example 17
Source Project: nopol   Source File: CollectableValueFinder.java    License: GNU General Public License v2.0 5 votes vote down vote up
protected void addGettersOfFields(Collection<CtVariable<?>> reachedVariables, CtTypeReference<?> type) {
    for (CtVariable<?> variable : reachedVariables) {
        if (isField(variable)) {
            addGetters(type, variable, nameFor(variable));
        }
    }
}
 
Example 18
Source Project: nopol   Source File: CollectableValueFinder.java    License: GNU General Public License v2.0 5 votes vote down vote up
protected void addGetters(CtTypeReference<?> type, CtVariable<?> variable, String variableName) {
    Collection<CtMethod<?>> methods = accessibleMethodsFrom(type, variable.getType());
    for (CtMethod<?> method : methods) {
        if (isGetter(method)) {
            accessibleGetters().add(variableName, method.getSimpleName());
        }
    }
}
 
Example 19
Source Project: nopol   Source File: SpoonReferenceLibrary.java    License: GNU General Public License v2.0 5 votes vote down vote up
public static Collection<CtMethod<?>> accessibleMethodsFrom(CtTypeReference<?> accessingType, CtTypeReference<?> accessedType) {
    Collection<CtMethod<?>> accessibleMethods = MetaList.newLinkedList();
    try {
        Collection<CtMethod<?>> allMethods = methodsOf(accessedType);
        for (CtMethod<?> method : allMethods) {
            if (isVisibleFrom(accessingType, method, method.getDeclaringType().getReference(), accessedType)) {
                accessibleMethods.add(method);
            }
        }
    } catch (Throwable e) {
        logWarning(logger(), e.toString());
    }
    return accessibleMethods;
}
 
Example 20
Source Project: astor   Source File: VariableResolver.java    License: GNU General Public License v2.0 5 votes vote down vote up
public static boolean areTypesCompatible(CtTypeReference type1, CtTypeReference type2) {
	try {// Check if an existing variable (name taken from
			// cluster)
			// is compatible with with that one out of scope

		boolean bothArray = false;
		boolean notCompatible = false;
		do {
			// We check if types are arrays.
			boolean clusterIsArray = type1 instanceof CtArrayTypeReference;
			boolean ourIsArray = type2 instanceof CtArrayTypeReference;

			if (clusterIsArray ^ ourIsArray) {
				notCompatible = true;

			}
			// if both are arrays, we extract the component
			// type, and we compare it again
			bothArray = clusterIsArray && ourIsArray;
			if (bothArray) {
				type1 = ((CtArrayTypeReference) type1).getComponentType();
				type2 = ((CtArrayTypeReference) type2).getComponentType();
			}

		} while (bothArray);

		if (notCompatible)
			return false;

		if (type1.isSubtypeOf(type2)) {
			return true;
		}
	} catch (Exception e) {
		logger.error(e);
	}
	return false;
}
 
Example 21
Source Project: gumtree-spoon-ast-diff   Source File: NodeCreator.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void scanCtReference(CtReference reference) {


    if (reference instanceof CtTypeReference && reference.getRoleInParent() == CtRole.SUPER_TYPE) {
        ITree superType = builder.createNode("SUPER_TYPE", reference.toString());
        CtWrapper<CtReference> k = new CtWrapper<CtReference>(reference, reference.getParent());
        superType.setMetadata(SpoonGumTreeBuilder.SPOON_OBJECT, k);
        reference.putMetadata(SpoonGumTreeBuilder.GUMTREE_NODE, superType);
        builder.addSiblingNode(superType);
    } else {
        super.scanCtReference(reference);
    }
}
 
Example 22
Source Project: nopol   Source File: SpoonMethodLibrary.java    License: GNU General Public License v2.0 5 votes vote down vote up
public static Collection<CtMethod<?>> methodsOf(CtTypeReference<?> type) {
    CtType<?> declaration = type.getDeclaration();
    if (isType(declaration)) {
        return ((CtType<?>) declaration).getAllMethods();
    }
    return asList();
}
 
Example 23
Source Project: nopol   Source File: SpoonElementLibrary.java    License: GNU General Public License v2.0 5 votes vote down vote up
public static CtTypeReference<?> typeOf(CtElement element) {
    if (isSimpleType(element)) {
        return ((CtType<?>) element).getReference();
    }
    if (isTypedElement(element)) {
        return ((CtTypedElement<?>) element).getType();
    }
    return typeOf(parentOfType(CtType.class, element));
}
 
Example 24
Source Project: nopol   Source File: ClassCollector.java    License: GNU General Public License v2.0 5 votes vote down vote up
@Override
public void process(CtTypedElement element) {
    List<CtTypeReference<?>> listDependencies = getDependencies(element);

    CtTypeReference<Exception> exception = getFactory().Class().createReference(Exception.class);
    for (CtTypeReference<?> ctTypeReference : listDependencies) {
        if (ctTypeReference == null) {
            continue;
        }
        if (ctTypeReference.isPrimitive()) {
            continue;
        }
        if (ctTypeReference.toString().equals("<nulltype>")) {
            continue;
        }
        if (exception.isSubtypeOf(ctTypeReference)) {
            continue;
        }
        if (classes.contains(ctTypeReference.getQualifiedName())) {
            return;
        }
        if (classes.add(ctTypeReference.getQualifiedName())) {
            logger.debug("[class] " + ctTypeReference.getQualifiedName());
        }
    }

}
 
Example 25
Source Project: astor   Source File: VariableResolver.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Return a list of variables that match with the variable access passed as
 * parameter. The last argument indicate if we map also the vars name
 * 
 * @param varContext
 * @param vartofind
 * @param mapName
 * @return
 */
protected static List<CtVariable> matchVariable(List<CtVariable> varContext, CtVariableAccess vartofind,
		boolean mapName) {
	List<CtVariable> varMatched = new ArrayList<>();
	try {
		CtTypeReference typeToFind = vartofind.getType();

		// First we search for compatible variables according to the type
		List<CtVariable> types = compatiblesSubType(varContext, typeToFind);
		if (types.isEmpty()) {
			return varMatched;
		}
		// Then, we search
		for (CtVariable ctVariableWithTypes : types) {
			// comparing name is optional, according to argument.
			boolean matchName = !mapName
					|| ctVariableWithTypes.getSimpleName().equals(vartofind.getVariable().getSimpleName());
			if (matchName) {
				varMatched.add(ctVariableWithTypes);
			}
		}

	} catch (Exception ex) {
		logger.error("Variable verification error", ex);
	}

	return varMatched;
}
 
Example 26
Source Project: spoon-examples   Source File: Spoonerism.java    License: GNU General Public License v2.0 5 votes vote down vote up
Spoonerism extendTestingClasses() {
    // Now we need to extend the classes.
    // WARNING: There is a small problem with this, can you spot it?
    // Answer at bottom
    CtTypeReference<?> baseTestingClassRef =
            baseTestingClass.getReference();
    for (CtClass<?> ctClass: testingClasses) {
        if (ctClass.getSuperclass() == null) {
            ctClass.setSuperclass(baseTestingClassRef);
        }
    }
    return this;
}
 
Example 27
/**
 * 
 * Creates ingredients according to the TypeReference of an element. The
 * ingredients are valid in the modification point location. TODO: Move to the
 * operator?
 * 
 * @param parentVariant
 * @param iModifPoint
 * @param targetType
 * @return
 */
public List<IngredientFromDyna> synthesizeCandidatesIngredientsFromType(ProgramVariant parentVariant,
		ModificationPoint iModifPoint, DynaIngredientPool clusterEvaluatedExpressions, CtTypeReference targetType) {

	List<IngredientFromDyna> newIngredientsResult = new ArrayList<>();

	// for (String i_testName : clusterEvaluatedExpressions.keySet()) {
	// TODO: see how to modify this

	if (clusterEvaluatedExpressions == null
			|| clusterEvaluatedExpressions.getClusterEvaluatedExpressions() == null) {
		return newIngredientsResult;
	}

	for (ClusterExpressions i_cluster : clusterEvaluatedExpressions.getClusterEvaluatedExpressions()) {

		if (i_cluster.size() > 0) {
			EvaluatedExpression firstExpressionOfCluster = i_cluster.get(0);

			operationsExecuted++;

			// let's check the types
			String classofExpression = i_cluster.getClusterType();

			String classofiHole = targetType.box().getQualifiedName();

			if (!ConfigurationProperties.getPropertyBool("avoidtypecomparison")// In case that we dont want
																				// to compare hole types
					&& !classofiHole.equals(classofExpression)) {
				continue;
			}

			IngredientFromDyna ingredientSynthesized = createIngredient(firstExpressionOfCluster);
			newIngredientsResult.add(ingredientSynthesized);

		}
		// }
	}
	return newIngredientsResult;
}
 
Example 28
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 29
Source Project: astor   Source File: WrapwithIfNullCheck.java    License: GNU General Public License v2.0 5 votes vote down vote up
@Override
	public List<MetaOperatorInstance> createMetaOperatorInstances(ModificationPoint modificationPoint) {

		//
		CtElement codeElement = (targetElement == null) ? modificationPoint.getCodeElement() : targetElement;

		List<CtVariableAccess> varAccessInModificationPoints = VariableResolver.collectVariableAccess(codeElement);

		List<Ingredient> ingredients = this.computeIngredientsNullCheck(modificationPoint,
				varAccessInModificationPoints);

		// The parameters to be included in the new method
		List<CtVariableAccess> varsToBeParameters = varAccessInModificationPoints;

		// List of parameters
		List<CtParameter<?>> parameters = new ArrayList<>();
		List<CtExpression<?>> realParameters = new ArrayList<>();
		for (CtVariableAccess ctVariableAccess : varsToBeParameters) {
			// the parent is null, it is setter latter
			CtParameter pari = MutationSupporter.getFactory().createParameter(null, ctVariableAccess.getType(),
					ctVariableAccess.getVariable().getSimpleName());
			parameters.add(pari);
			realParameters.add(ctVariableAccess.clone().setPositions(new NoSourcePosition()));
		}
///
		// let's start with one, and let's keep the Zero for the default (all ifs are
		// false)
		int candidateNumber = 0;
		CtTypeReference returnType = MutationSupporter.getFactory().createCtTypeReference(Boolean.class);

		MetaOperatorInstance megaOp = MetaGenerator.createMetaStatementReplacement(modificationPoint, codeElement,
				MutationSupporter.getFactory().createCodeSnippetExpression("true"), candidateNumber, ingredients,
				parameters, realParameters, this, returnType);
		List<MetaOperatorInstance> opsMega = new ArrayList();
		opsMega.add(megaOp);

		return opsMega;
	}
 
Example 30
Source Project: gumtree-spoon-ast-diff   Source File: LabelFinder.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public <T> void visitCtInvocation(CtInvocation<T> invocation) {
	if (invocation.getExecutable() != null) {
		CtTypeReference decl = invocation.getExecutable().getDeclaringType();
		// label =
		// (decl!=null?decl.getQualifiedName():"")+"#"+invocation.getExecutable().getSignature();
		// label = (decl != null ? decl.getQualifiedName() : "") + "#" +
		// invocation.getExecutable().getSimpleName();
		label = invocation.getExecutable().getSimpleName();

	}
}