Java Code Examples for spoon.reflect.code.CtVariableAccess#getVariable()

The following examples show how to use spoon.reflect.code.CtVariableAccess#getVariable() . 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: VariableAnalyzer.java    From coming with MIT License 6 votes vote down vote up
/**
 * For each involved variable, is it constant?–can assume variables whose
 * identifier names are majorly capital letters are constant variables
 * 
 * @param varsAffected
 * @param element
 * @param context
 */
private void analyzeV3_AffectedHasConstant(List<CtVariableAccess> varsAffected, CtElement element,
		Cntx<Object> context) {
	try {
		
		for (CtVariableAccess aVarAffected : varsAffected) {
			boolean currentIsConstant = false;
			if (aVarAffected.getVariable() instanceof CtFieldReference &&
			// Check if it's uppercase
					aVarAffected.getVariable().getSimpleName().toUpperCase()
							.equals(aVarAffected.getVariable().getSimpleName())) {
				currentIsConstant = true;
			}
			
			writeGroupedInfo(context, adjustIdentifyInJson(aVarAffected), 
					CodeFeatures.V3_HAS_CONSTANT,
					currentIsConstant, "FEATURES_VARS");
		}
	} catch (Throwable e) {
		e.printStackTrace();
	}
}
 
Example 2
Source File: VariableResolver.java    From coming with 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 3
Source File: WrapwithIfNullCheck.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
private List<Ingredient> computeIngredientsNullCheck(ModificationPoint modificationPoint,
		List<CtVariableAccess> varAccessInModificationPoints) {

	List<Ingredient> ingredients = new ArrayList();

	for (CtVariableAccess iVariableAccess : varAccessInModificationPoints) {

		// Let's check the type, if primitive discard it
		if (iVariableAccess.getVariable() != null && iVariableAccess.getVariable().getType() != null
				&& iVariableAccess.getVariable().getType().isPrimitive())
			continue;

		CtVariableAccess iVariableAccessC = iVariableAccess.clone();
		MutationSupporter.clearPosition(iVariableAccessC);

		CtBinaryOperator<Boolean> binaryOp = new CtBinaryOperatorImpl<>();
		binaryOp.setLeftHandOperand(iVariableAccessC);
		binaryOp.setRightHandOperand(MutationSupporter.getFactory().createCodeSnippetExpression("null"));
		binaryOp.setKind(BinaryOperatorKind.NE);

		ingredients.add(new Ingredient(binaryOp));

	}

	return ingredients;
}
 
Example 4
Source File: VariableResolver.java    From astor with 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 5
Source File: VariableResolver.java    From coming with 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 6
Source File: VariableResolver.java    From astor with 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;
}