Java Code Examples for spoon.reflect.code.CtInvocation#getType()

The following examples show how to use spoon.reflect.code.CtInvocation#getType() . 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 File: MethodAnalyzer.java    From coming with MIT License 6 votes vote down vote up
private void analyzeM5(CtElement element, Cntx<Object> context, List<CtInvocation> invocations,
		List<CtVariable> varsInScope) {
	
	try {
		for (CtInvocation invocation : invocations) {
			boolean currentInvocationWithCompVar = false;
			CtTypeReference type = invocation.getType();

			if (type != null) {
				// for the variables in scope
				for (CtVariable varInScope : varsInScope) {
					if (compareTypes(type, varInScope.getType())) {
						currentInvocationWithCompVar = true;
						break;
					}
				}
			}

			writeGroupedInfo(context, adjustIdentifyInJson(invocation),
					CodeFeatures.M5_MI_WITH_COMPATIBLE_VAR_TYPE, 
					currentInvocationWithCompVar, "FEATURES_METHODS");			
		}
	  } catch (Exception e) {
	}
}
 
Example 2
Source File: WholeStatementAnalyzer.java    From coming with MIT License 5 votes vote down vote up
private void analyzeS15_HasObjectiveInvocations(CtElement element, Cntx<Object> context, CtClass parentClass,
		List<CtInvocation> invocationstostudy) {

	try {
		boolean S15anyReturnObjective = false;

		for (CtInvocation invocation : invocationstostudy) {

			CtStatement parent = invocation.getParent(new LineFilter());

			if (isNormalGuard(invocation, (parent)) || isNullCheckGuard(invocation, (parent)))
				continue;

			if ((invocation.getType() != null && !invocation.getType().isPrimitive())
					|| whetherhasobjective(inferPotentionalTypes(invocation, parentClass))) {
				S15anyReturnObjective = true;
			}

			if (S15anyReturnObjective)
				break;
		}

		context.put(CodeFeatures.S15_HAS_OBJECTIVE_METHOD_CALL, S15anyReturnObjective);
	} catch (Throwable e) {
		e.printStackTrace();
	}
}
 
Example 3
Source File: TOSInvocationGenerator.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
@SuppressWarnings("rawtypes")
private List<InvocationPlaceholder> generate(CtAbstractInvocation ctAbstractInvocation,
		T originalStatement) {
	List<InvocationPlaceholder> tosGenerated = new ArrayList<>();

	// We collect all variables
	List<CtAbstractInvocation> invocations = InvocationResolver.collectInvocation(originalStatement, true);

	int nrmethod = 0;
	for (int i = 0; i < invocations.size(); i++) {

		CtAbstractInvocation invocation_i = invocations.get(i);
		if (invocation_i instanceof CtInvocation) {
			if (ctAbstractInvocation.equals(invocation_i)) {

				CtInvocation cinvocationToModify = (CtInvocation) invocation_i;
				if (cinvocationToModify.getTarget() == null) {
					//log.debug("\nTarget null " + ctAbstractInvocation);
					continue;
				}
				String newName = String.format(PATTERN,
						cinvocationToModify.getTarget().getType().getQualifiedName(),
						cinvocationToModify.getType().getQualifiedName(), nrmethod++);

				InvocationPlaceholder tf = new InvocationPlaceholder(newName, cinvocationToModify,
						cinvocationToModify.getTarget().getType(), cinvocationToModify.getType());

				tosGenerated.add(tf);

				break;
			}
		}

	}

	return tosGenerated;
}
 
Example 4
Source File: MethodXVariableReplacementOp.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
@Override
public List<MetaOperatorInstance> createMetaOperatorInstances(ModificationPoint modificationPoint) {

	MetaOperatorInstance opMega = new MetaOperatorInstance(this, MetaGenerator.getNewIdentifier());

	List<OperatorInstance> opsOfVariant = new ArrayList();

	Map<Integer, Ingredient> ingredientOfMapped = new HashMap<>();

	//
	List<CtInvocation> invocationsFromModifPoints = getInvocations(modificationPoint.getCodeElement());

	log.debug("\nModifcationPoint: \n" + modificationPoint);

	// let's start with one, and let's keep the Zero for the default (all ifs are
	// false)
	// TODO: we only can activate one mutant

	int variableCounter = 0;
	for (CtInvocation invocationToReplace : invocationsFromModifPoints) {

		// The return type of the new method correspond to the type of variable to
		// change
		CtTypeReference returnType = invocationToReplace.getType();

		List<Ingredient> ingredients = this.computeIngredientsFromMInvokToReplace(modificationPoint,
				invocationToReplace);

		if (ingredients.isEmpty()) {
			// Nothing to replace
			continue;
		}

		// The parameters to be included in the new method
		List<CtVariableAccess> varsToBeParameters = ingredients.stream().map(e -> e.getCode())
				.map(CtVariableAccess.class::cast).collect(Collectors.toList());
		// The variable from the existing invocation must also be a parameter
		SupportOperators.putVarsNotDuplicated(modificationPoint.getCodeElement(), varsToBeParameters);

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

		variableCounter++;

		MetaGenerator.createMetaForSingleElement(opMega, modificationPoint, invocationToReplace, variableCounter,
				ingredients, parameters, realParameters, returnType, opsOfVariant, ingredientOfMapped);

	} // End variable

	opMega.setOperatorInstances(opsOfVariant);
	opMega.setAllIngredients(ingredientOfMapped);
	opMega.setOperationApplied(this);
	opMega.setOriginal(modificationPoint.getCodeElement());
	opMega.setModificationPoint(modificationPoint);

	List<MetaOperatorInstance> opsMega = new ArrayList();
	opsMega.add(opMega);

	return opsMega;
}
 
Example 5
Source File: MethodXMethodReplacementOp.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
@Override
public List<MetaOperatorInstance> createMetaOperatorInstances(ModificationPoint modificationPoint) {

	List<MetaOperatorInstance> opsMega = new ArrayList();

	MapList<CtInvocation, Ingredient> ingredientsPerInvocation = this
			.retrieveInvocationIngredient(modificationPoint);
	if (ingredientsPerInvocation.isEmpty()) {
		log.debug("Any ingredient (other invocations) for modif point " + modificationPoint.identified);
		// Nothing to replace
		return opsMega;
	}

	log.debug("\nMethodInvoReplacement: \n" + modificationPoint);

	// let's start with one, and let's keep the Zero for the default (all ifs are
	// false)

	// As difference with var replacement, a metamutant for each invocation
	for (CtInvocation invocationToReplace : ingredientsPerInvocation.keySet()) {

		int invocationCounter = 0;

		List<Ingredient> ingredients = ingredientsPerInvocation.get(invocationToReplace);

		List<CtVariableAccess> varsToBeParameters = new ArrayList<>();

		// The parameters to be included in the new method
		for (Ingredient ingredient : ingredients) {
			SupportOperators.putVarsNotDuplicated(ingredient.getCode(), varsToBeParameters);

		}

		// The variable from the existing invocation must also be a parameter
		SupportOperators.putVarsNotDuplicated(modificationPoint.getCodeElement(), varsToBeParameters);

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

		invocationCounter++;

		/// Let's start creating the body of the new method.
		// first the main try
		CtTypeReference returnTypeOfInvocation = invocationToReplace.getType();

		MetaOperatorInstance megaOp = MetaGenerator.createMetaFineGrainedReplacement(modificationPoint,
				invocationToReplace, invocationCounter, ingredients, parameters, realParameters, this,
				returnTypeOfInvocation);
		opsMega.add(megaOp);

	} // End invocation

	return opsMega;
}