spoon.reflect.reference.CtVariableReference Java Examples
The following examples show how to use
spoon.reflect.reference.CtVariableReference.
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: VariableResolver.java From coming with MIT License | 6 votes |
/** * 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 File: VariableResolver.java From astor with GNU General Public License v2.0 | 6 votes |
/** * 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 File: VariableResolver.java From coming with MIT License | 5 votes |
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 File: VariableResolver.java From astor with GNU General Public License v2.0 | 5 votes |
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 File: StatCollector.java From nopol with GNU General Public License v2.0 | 4 votes |
public Map<CtVariableReference, Integer> getStatVariable() { return statVariable; }
Example #6
Source File: VariableResolver.java From astor with GNU General Public License v2.0 | 4 votes |
/** * 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 File: VariableResolver.java From coming with MIT License | 3 votes |
public static boolean isStatic(CtVariableReference varref) { if (!(varref instanceof CtFieldReference)) { return false; } CtFieldReference fieldRef = (CtFieldReference) varref; return fieldRef.isStatic(); }
Example #8
Source File: VariableResolver.java From astor with GNU General Public License v2.0 | 3 votes |
public static boolean isStatic(CtVariableReference varref) { if (!(varref instanceof CtFieldReference)) { return false; } CtFieldReference fieldRef = (CtFieldReference) varref; return fieldRef.isStatic(); }