Java Code Examples for spoon.reflect.reference.CtVariableReference

The following examples show how to use spoon.reflect.reference.CtVariableReference. 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: coming   Source File: VariableResolver.java    License: MIT License 6 votes vote down vote up
/**
 * It retrieves all variables access which declarations are inside the
 * ingredient.
 * 
 * @param ingredientRootElement
 * @param varAccessCollected
 * @return
 */
public static List<CtVariableAccess> collectInductionVariableAccess(CtElement ingredientRootElement,
		List<CtVariableAccess> varAccessCollected) {

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

	for (CtVariableAccess ctVariableAccess : varAccessCollected) {

		CtVariableReference varref = ctVariableAccess.getVariable();

		// We are interesting in induction vars, they are modeled as
		// LocalVariables
		if (!(varref instanceof CtLocalVariableReference))
			continue;

		CtVariable var = varref.getDeclaration();

		boolean insideIngredient = checkParent(var, ingredientRootElement);
		if (insideIngredient)
			induction.add(ctVariableAccess);

	}
	return induction;
}
 
Example 2
Source Project: astor   Source File: VariableResolver.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * It retrieves all variables access which declarations are inside the
 * ingredient.
 * 
 * @param ingredientRootElement
 * @param varAccessCollected
 * @return
 */
public static List<CtVariableAccess> collectInductionVariableAccess(CtElement ingredientRootElement,
		List<CtVariableAccess> varAccessCollected) {

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

	for (CtVariableAccess ctVariableAccess : varAccessCollected) {

		CtVariableReference varref = ctVariableAccess.getVariable();

		// We are interesting in induction vars, they are modeled as
		// LocalVariables
		if (!(varref instanceof CtLocalVariableReference))
			continue;

		CtVariable var = varref.getDeclaration();

		boolean insideIngredient = checkParent(var, ingredientRootElement);
		if (insideIngredient)
			induction.add(ctVariableAccess);

	}
	return induction;
}
 
Example 3
Source Project: coming   Source File: VariableResolver.java    License: MIT License 5 votes vote down vote up
public static List<CtVariableAccess> collectStaticVariableAccess(CtElement rootElement,
		List<CtVariableAccess> varAccessCollected) {
	List<CtVariableAccess> statics = new ArrayList<>();

	for (CtVariableAccess ctVariableAccess : varAccessCollected) {
		CtVariableReference varref = ctVariableAccess.getVariable();

		if (isStatic(varref)) {
			statics.add(ctVariableAccess);
		}
	}
	return statics;
}
 
Example 4
Source Project: astor   Source File: VariableResolver.java    License: GNU General Public License v2.0 5 votes vote down vote up
public static List<CtVariableAccess> collectStaticVariableAccess(CtElement rootElement,
		List<CtVariableAccess> varAccessCollected) {
	List<CtVariableAccess> statics = new ArrayList<>();

	for (CtVariableAccess ctVariableAccess : varAccessCollected) {
		CtVariableReference varref = ctVariableAccess.getVariable();

		if (isStatic(varref)) {
			statics.add(ctVariableAccess);
		}
	}
	return statics;
}
 
Example 5
Source Project: nopol   Source File: StatCollector.java    License: GNU General Public License v2.0 4 votes vote down vote up
public Map<CtVariableReference, Integer> getStatVariable() {
    return statVariable;
}
 
Example 6
Source Project: astor   Source File: VariableResolver.java    License: GNU General Public License v2.0 4 votes vote down vote up
/**
 * Adapt the ingredient to the destination according to the mapping. We directly
 * manipulate the variables from the ingredient, which are stored in VarMapping
 * 
 * @param varMapping
 * @param destination
 * @return it returns the original variable reference of each converted variable
 */
@SuppressWarnings("unchecked")
public static Map<VarAccessWrapper, CtVariableAccess> convertIngredient(VarMapping varMapping,
		Map<String, CtVariable> mapToFollow) {

	Map<VarAccessWrapper, CtVariableAccess> originalMap = new HashMap<>();

	Map<VarAccessWrapper, List<CtVariable>> mappedVars = varMapping.getMappedVariables();
	for (VarAccessWrapper var : mappedVars.keySet()) {
		CtVariable varNew = mapToFollow.get(var.getVar().getVariable().getSimpleName());
		//
		CtVariableReference newVarReference = varNew.getReference();

		CtVariableAccess originalVarAccessDestination = var.getVar();
		CtVariableAccess newVarAccessDestination = null;

		// if the var to reference is a local or parameter
		if (newVarReference instanceof CtLocalVariableReference
				|| newVarReference instanceof CtParameterReference) {
			// let's check the destination Writes or Reads
			if (originalVarAccessDestination instanceof CtFieldWrite
					|| originalVarAccessDestination instanceof CtVariableWrite) {
				// We replace the Write by a Var writter
				newVarAccessDestination = MutationSupporter.getFactory().Core().createVariableWrite();
				newVarAccessDestination.setVariable(newVarReference);

			} else { // read
				newVarAccessDestination = MutationSupporter.getFactory().Code().createVariableRead(newVarReference,
						varNew.hasModifier(ModifierKind.STATIC));
			}

		} else
		// else, if we want to reference a field
		if (newVarReference instanceof CtFieldReference) {
			// let's check the destination, write or read
			if (originalVarAccessDestination instanceof CtFieldWrite<?>
					|| originalVarAccessDestination instanceof CtFieldRead<?>) {
				newVarAccessDestination = MutationSupporter.getFactory().Core().createFieldWrite();

			} else {
				newVarAccessDestination = MutationSupporter.getFactory().Core().createFieldRead();

			}
			newVarAccessDestination.setVariable(newVarReference);
		}
		// At the end, for all cases:
		if (newVarAccessDestination != null) {
			originalMap.put(new VarAccessWrapper(newVarAccessDestination), originalVarAccessDestination);
			originalVarAccessDestination.replace(newVarAccessDestination);
		} else {
			logger.error("No destination resolved");
		}

	} // end for
	return originalMap;
}
 
Example 7
Source Project: coming   Source File: VariableResolver.java    License: MIT License 3 votes vote down vote up
public static boolean isStatic(CtVariableReference varref) {

		if (!(varref instanceof CtFieldReference)) {
			return false;
		}

		CtFieldReference fieldRef = (CtFieldReference) varref;

		return fieldRef.isStatic();

	}
 
Example 8
Source Project: astor   Source File: VariableResolver.java    License: GNU General Public License v2.0 3 votes vote down vote up
public static boolean isStatic(CtVariableReference varref) {

		if (!(varref instanceof CtFieldReference)) {
			return false;
		}

		CtFieldReference fieldRef = (CtFieldReference) varref;

		return fieldRef.isStatic();

	}