spoon.reflect.code.CtVariableAccess Java Examples

The following examples show how to use spoon.reflect.code.CtVariableAccess. 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: InitialConceptMetEngine.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Add all variables from the expression and candidates in a list
 * 
 * @param exptochange
 * @param candidates
 * @return
 */
private List<CtVariableAccess> collectAllVars(CtExpression exptochange, List<Ingredient> candidates) {
	List<CtVariableAccess> varAccess = VariableResolver.collectVariableAccess(exptochange);

	for (Ingredient candidateIngr : candidates) {
		CtElement candidate = candidateIngr.getCode();
		List<CtVariableAccess> varAccessCandidate = VariableResolver.collectVariableAccess(candidate);
		for (CtVariableAccess varX : varAccessCandidate) {
			if (!varAccess.contains(varX)) {
				varAccess.add(varX);
			}
		}
	}

	return varAccess;
}
 
Example #2
Source File: VariableAnalyzer.java    From coming with MIT License 6 votes vote down vote up
private void analyzV10_AffectedWithCompatibleTypes(List<CtVariableAccess> varsAffected, List<CtVariable> varsInScope,
		CtElement element, Cntx<Object> context) {
	try {
		
		for (CtVariableAccess aVariableAccessInStatement : varsAffected) {
			boolean currentHasSimType = false;
			for (CtVariable aVariableInScope : varsInScope) {
				if (!aVariableInScope.getSimpleName().equals(aVariableAccessInStatement.getVariable().getSimpleName())) {
					if (compareTypes(aVariableInScope.getType(), aVariableAccessInStatement.getType())) {
						currentHasSimType=true;
						break;
					}
				}
			}
			
			writeGroupedInfo(context, adjustIdentifyInJson(aVariableAccessInStatement),
					CodeFeatures.V10_VAR_TYPE_Similar_VAR, currentHasSimType, "FEATURES_VARS");
		}
	} catch (Throwable e) {
		e.printStackTrace();
	}
}
 
Example #3
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 #4
Source File: VariableAnalyzer.java    From coming with MIT License 6 votes vote down vote up
private void analyzeV19_VarWithSpecialName (List<CtVariableAccess> varsAffected, Cntx<Object> context) {
	
	 try {
		  for (CtVariableAccess aVarAffected : varsAffected) {
			
			boolean V19WithSpecialName = false;
			String varname= aVarAffected.getVariable().getSimpleName().toLowerCase(); 
			
			if(varname.endsWith("length") || varname.endsWith("size") || varname.endsWith("count") || varname.endsWith("value")
					|| varname.endsWith("key") || varname.equals("class"))
				V19WithSpecialName =true;
			
			if(!V19WithSpecialName && aVarAffected.getType()!=null && aVarAffected.getType().getSimpleName().toLowerCase().endsWith("exception"))
				V19WithSpecialName =true;
			
		
			writeGroupedInfo(context, adjustIdentifyInJson(aVarAffected),
					CodeFeatures.V19_With_Special_Name, 
					V19WithSpecialName, "FEATURES_VARS");
		}
	} catch (Throwable e) {
		e.printStackTrace();
	}
}
 
Example #5
Source File: AbstractCodeAnalyzer.java    From coming with MIT License 6 votes vote down vote up
public boolean isElementBeforeVariable(CtVariableAccess variableAffected, CtElement element) {

		try {
			CtStatement stst = (element instanceof CtStatement) ? (CtStatement) element
					: element.getParent(CtStatement.class);

			CtStatement target = (variableAffected instanceof CtStatement) ? (CtStatement) variableAffected
					: variableAffected.getParent(CtStatement.class);

			return target.getPosition() != null && getParentNotBlock(stst) != null
					&& target.getPosition().getSourceStart() > stst.getPosition().getSourceStart();
		} catch (Exception e) {
			// e.printStackTrace();
		}
		return false;

	}
 
Example #6
Source File: LogicalExpressionAnalyzer.java    From coming with MIT License 6 votes vote down vote up
/**
 * Check if a method declaration has a parameter compatible with that one from
 * the var affected
 * 
 * @param allMethods
 * @param varAffected
 * @return
 */
public CtMethod checkBooleanMethodDeclarationWithTypeInParameter(List allMethods, CtVariableAccess varAffected) {
	
	for (Object omethod : allMethods) {

		if (!(omethod instanceof CtMethod))
			continue;

		CtMethod anotherMethodInBuggyClass = (CtMethod) omethod;

		for (Object oparameter : anotherMethodInBuggyClass.getParameters()) {
			CtParameter parameter = (CtParameter) oparameter;

			if (compareTypes(varAffected.getType(), parameter.getType())) {
				if (anotherMethodInBuggyClass.getType().unbox().toString().equals("boolean")) {

					return anotherMethodInBuggyClass;
				}
			}
		}
	}
	return null;
}
 
Example #7
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 #8
Source File: VariableResolver.java    From coming with MIT License 6 votes vote down vote up
public static List<CtVariableAccess> collectVariableReadIgnoringBlocks(CtElement element) {

		if (element instanceof CtIf) {
			return collectVariableRead(((CtIf) element).getCondition());
		}
		if (element instanceof CtWhile) {
			return collectVariableRead(((CtWhile) element).getLoopingExpression());
		}

		if (element instanceof CtFor) {
			return collectVariableRead(((CtFor) element).getExpression());
		}

		return collectVariableRead(element);

	}
 
Example #9
Source File: VariableResolver.java    From coming with MIT License 6 votes vote down vote up
public static List<CtVariableAccess> collectVariableAccessIgnoringBlocks(CtElement element) {

		if (element instanceof CtIf) {
			return collectVariableAccess(((CtIf) element).getCondition());
		}
		if (element instanceof CtWhile) {
			return collectVariableAccess(((CtWhile) element).getLoopingExpression());
		}

		if (element instanceof CtFor) {
			return collectVariableAccess(((CtFor) element).getExpression());
		}

		return collectVariableAccess(element);

	}
 
Example #10
Source File: VariableResolver.java    From coming with MIT License 6 votes vote down vote up
public static List<CtVariableAccess> checkMapping(Map<CtVariableAccess, List<CtVariable>> matched) {
	List<CtVariableAccess> notMapped = new ArrayList<>();

	if (matched == null)
		return notMapped;

	// Now, we analyze if all access were matched
	for (CtVariableAccess ctVariableAccess : matched.keySet()) {
		List<CtVariable> mapped = matched.get(ctVariableAccess);
		if (mapped.isEmpty()) {
			// One var access was not mapped
			// return false;
			notMapped.add(ctVariableAccess);
		}
	}
	// All VarAccess were mapped
	// return true;
	return notMapped;
}
 
Example #11
Source File: VariableResolver.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
public static List<CtVariableAccess> collectVariableReadIgnoringBlocks(CtElement element) {

		if (element instanceof CtIf) {
			return collectVariableRead(((CtIf) element).getCondition());
		}
		if (element instanceof CtWhile) {
			return collectVariableRead(((CtWhile) element).getLoopingExpression());
		}

		if (element instanceof CtFor) {
			return collectVariableRead(((CtFor) element).getExpression());
		}

		return collectVariableRead(element);

	}
 
Example #12
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 #13
Source File: VariablePlaceholder.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public void apply() {
	olderNameOfVariable.clear();
	for (String placeholder : palceholdersToVariables.keySet()) {

		List<CtVariableAccess> variables = palceholdersToVariables.get(placeholder);
		for (CtVariableAccess variableUnderAnalysis : variables) {
			this.olderNameOfVariable.put(variableUnderAnalysis,
					variableUnderAnalysis.getVariable().getSimpleName());
			variableUnderAnalysis.getVariable().setSimpleName(placeholder);
			// workaround: Problems with var Shadowing
			variableUnderAnalysis.getFactory().getEnvironment().setNoClasspath(true);
			if (variableUnderAnalysis instanceof CtFieldAccess) {
				CtFieldAccess fieldAccess = (CtFieldAccess) variableUnderAnalysis;
				fieldAccess.getVariable().setDeclaringType(null);

			}
		}
	}
}
 
Example #14
Source File: MethodXVariableReplacementOp.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
protected List<Ingredient> computeIngredientsFromMInvokToReplace(ModificationPoint modificationPoint,
		CtInvocation invocationToReplace) {

	List<Ingredient> ingredients = new ArrayList<>();
	List<CtVariable> varsInContext = modificationPoint.getContextOfModificationPoint();

	for (CtVariable iVarInContext : varsInContext) {

		if (!SupportOperators.checkIsSubtype(iVarInContext.getType(), invocationToReplace.getType())) {
			continue;
		}

		CtVariableAccess iVarAccessFromContext = MutationSupporter.getFactory()
				.createVariableRead(iVarInContext.getReference(), false);
		Ingredient ingredient = new Ingredient(iVarAccessFromContext);
		// we use this property to indicate the old variable to replace
		ingredient.setDerivedFrom(invocationToReplace);
		ingredients.add(ingredient);

	}

	return ingredients;
}
 
Example #15
Source File: VariableResolver.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns a map between the variables with name conflicts.
 * 
 * @param varsFromContext
 * @param varInductionCollected
 * @return
 */
public static Map<CtVariableAccess, List<CtVariable>> searchVarNameConflicts(List<CtVariable> varsFromContext,
		List<CtVariableAccess> varInductionCollected) {

	Map<CtVariableAccess, List<CtVariable>> mappingConflicts = new HashMap<>();

	for (CtVariableAccess inductionVar : varInductionCollected) {

		List<CtVariable> varsConf = new ArrayList<>();
		String nameInduction = inductionVar.getVariable().getSimpleName();

		for (CtVariable ctVariableContext : varsFromContext) {
			String nameVarContexr = ctVariableContext.getSimpleName();
			if (nameInduction.equals(nameVarContexr)) {
				varsConf.add(ctVariableContext);
			}
		}
		if (varsConf.size() > 0) {
			mappingConflicts.put(inductionVar, varsConf);
		}

	}
	return mappingConflicts;
}
 
Example #16
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 #17
Source File: VariableResolver.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
public static List<CtVariableAccess> collectVariableAccessIgnoringBlocks(CtElement element) {

		if (element instanceof CtIf) {
			return collectVariableAccess(((CtIf) element).getCondition());
		}
		if (element instanceof CtWhile) {
			return collectVariableAccess(((CtWhile) element).getLoopingExpression());
		}

		if (element instanceof CtFor) {
			return collectVariableAccess(((CtFor) element).getExpression());
		}

		return collectVariableAccess(element);

	}
 
Example #18
Source File: WrapwithIfNullCheck.java    From astor with 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 #19
Source File: WrapwithIfOp.java    From astor with 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 #20
Source File: GramProcessor.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Order the var access list by name.
 * 
 * @param vars
 */
public void sortVarsByNames(List<CtVariableAccess> vars) {

	Collections.sort(vars, new Comparator<CtVariableAccess>() {

		@Override
		public int compare(CtVariableAccess o1, CtVariableAccess o2) {
			return o1.getVariable().getSimpleName().compareTo(o2.getVariable().getSimpleName());
		}
	});

}
 
Example #21
Source File: ExpressionIngredientSpaceProcessor.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void process(CtExpression element) {

	if (element instanceof CtAssignment || element instanceof CtNewArray || element instanceof CtTypeAccess
			|| element instanceof CtVariableAccess || element instanceof CtLiteral)
		return;
	if (element.getType() != null)
		this.add(element);

}
 
Example #22
Source File: GramProcessor.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Remove parenthesis from a var access. e.g. (a)
 * 
 * @param vars
 */
private void cleanParenthesis(List<CtVariableAccess> vars) {
	for (CtVariableAccess ctVariableAccess : vars) {
		String name = ctVariableAccess.getVariable().getSimpleName();
		if (name.startsWith("(")) {
			int l = name.length();
			String nm = name.substring(1, l - 2);
		}

	}
}
 
Example #23
Source File: GramProcessor.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Get all permutation of a list of var access
 * 
 * @param sequence
 * @param n
 * @return
 */
private static List getPermutationsOfVarNames(List sequence, int n) {
	List allPermutationObtained = new ArrayList<>();

	int N = sequence.size();

	int[] binary = new int[(int) Math.pow(2, N)];
	for (int i = 0; i < Math.pow(2, N); i++) {
		int b = 1;
		binary[i] = 0;
		int num = i, count = 0;
		while (num > 0) {
			if (num % 2 == 1)
				count++;
			binary[i] += (num % 2) * b;
			num /= 2;
			b = b * 10;
		}
		if (count == n) {
			List subs = new ArrayList<>();
			for (int j = 0; j < N; j++) {
				if (binary[i] % 10 == 1)
					subs.add(((CtVariableAccess) sequence.get(j)).getVariable().getSimpleName());
				binary[i] /= 10;
			}
			String listflat = (String) subs.stream().map(Object::toString).collect(Collectors.joining(" "));
			allPermutationObtained.add(listflat);
		}
	}
	return allPermutationObtained;
}
 
Example #24
Source File: VariableAnalyzer.java    From coming with MIT License 5 votes vote down vote up
/**
 * For each involved variable, whether has any other variables in scope that are
 * similar in identifier name and type compatible
 * 
 * @param varsAffected
 * @param varsInScope
 * @param element
 * @param context
 */
private void analyzeV2_AffectedDistanceVarName(List<CtVariableAccess> varsAffected, List<CtVariable> varsInScope,
		CtElement element, Cntx<Object> context) {
	try {

		for (CtVariableAccess aVarAffected : varsAffected) {

			boolean v2VarSimilarNameCompatibleType = false;
			boolean v2VarSimilarName = false;

			for (CtVariable aVarInScope : varsInScope) {
				if (!aVarInScope.getSimpleName().equals(aVarAffected.getVariable().getSimpleName())) {
					int dist = StringDistance.calculate(aVarInScope.getSimpleName(),
							aVarAffected.getVariable().getSimpleName());
					if ((dist > 0 && dist < 3) || nameStartEndWithOther (aVarInScope.getSimpleName(), 
							aVarAffected.getVariable().getSimpleName())) {
						v2VarSimilarName=true;
						if (compareTypes(aVarAffected.getType(), aVarInScope.getType())) {
							v2VarSimilarNameCompatibleType = true;
							break;
						}
					}
				}
			}
			
			writeGroupedInfo(context, adjustIdentifyInJson(aVarAffected), 
					CodeFeatures.V2_HAS_VAR_SIM_NAME,
					v2VarSimilarName, "FEATURES_VARS");
			
			writeGroupedInfo(context, adjustIdentifyInJson(aVarAffected), 
					CodeFeatures.V2_HAS_VAR_SIM_NAME_COMP_TYPE,
					v2VarSimilarNameCompatibleType, "FEATURES_VARS");
			
		}
		
	} catch (Throwable e) {
		e.printStackTrace();
	}
}
 
Example #25
Source File: VariableResolver.java    From coming with MIT License 5 votes vote down vote up
/**
 * Retrieves the variables out of scope from the element given a context.
 */
public static List<CtVariableAccess> retriveVariablesOutOfContext(List<CtVariable> varContext,
		List<CtVariableAccess> variablesToChech) {
	List<CtVariableAccess> variablesOutOfScope = new ArrayList<>();

	for (CtVariableAccess variableAccessFromElement : variablesToChech) {
		if (!fitInPlace(varContext, variableAccessFromElement)) {
			variablesOutOfScope.add(variableAccessFromElement);
		}
	}
	return variablesOutOfScope;
}
 
Example #26
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 #27
Source File: VariableResolver.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Retrieves the variables out of scope from the element given a context.
 */
public static List<CtVariableAccess> retriveVariablesOutOfContext(List<CtVariable> varContext,
		List<CtVariableAccess> variablesToChech) {
	List<CtVariableAccess> variablesOutOfScope = new ArrayList<>();

	for (CtVariableAccess variableAccessFromElement : variablesToChech) {
		if (!fitInPlace(varContext, variableAccessFromElement)) {
			variablesOutOfScope.add(variableAccessFromElement);
		}
	}
	return variablesOutOfScope;
}
 
Example #28
Source File: TOSIngredientRandomSearchStrategy.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
@SuppressWarnings({ "unchecked", "rawtypes" })
public List<TOSInstance> getInstances(ModificationPoint modificationPoint, Ingredient ingredientBaseSelected) {
	// Now, let's get the ingredients.
	List<TOSInstance> ingredientTransformed = null;
	if (this.cacheInstances.containsKey(modificationPoint, ingredientBaseSelected.getChacheCodeString())) {
		ingredientTransformed = (List<TOSInstance>) this.cacheInstances.get(modificationPoint,
				ingredientBaseSelected.getChacheCodeString());
		log.debug("Ingredients " + StringUtil.trunc(ingredientBaseSelected.getChacheCodeString())
				+ " cache of size " + ingredientTransformed.size());

	} else {

		log.debug("Not in cache, generating for " + modificationPoint + " and "
				+ ingredientBaseSelected.getChacheCodeString());

		TOSEntity tos = (TOSEntity) ingredientBaseSelected;
		List<CtVariableAccess> outofscope = tos.getVarsOutOfContext(modificationPoint);
		if (!outofscope.isEmpty()) {
			log.debug("\nWe cannot generate a patch from tos" + StringUtil.trunc(tos.getCode()) + " in location"
					+ modificationPoint + "\nvars out of context: " + outofscope);
			return Lists.newArrayList();
		}
		log.debug("Tos fits " + StringUtil.trunc(tos.getCode()) + " in location" + modificationPoint);
		ingredientTransformed = new ArrayList<>();
		List<Ingredient> ing = transformationStrategy.transform(modificationPoint, tos);
		for (Ingredient ingredient : ing) {
			ingredientTransformed.add((TOSInstance) ingredient);
		}

		this.cacheInstances.put(modificationPoint, ingredientBaseSelected.getChacheCodeString(),
				ingredientTransformed);

	}
	return ingredientTransformed;
}
 
Example #29
Source File: VariableTransformation.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
public String toStringMap() {
	String r = "";
	for (String ph_name : this.varplaceholder.getPalceholders().keySet()) {

		List<CtVariableAccess> va = this.varplaceholder.getPalceholders().get(ph_name);
		CtVariableAccess va1 = va.get(0);

		CtVariable vcomb = this.combination.getCombination().get(va1.getVariable().getSimpleName());
		r += vcomb.getSimpleName() + " -->  " + ph_name;
		r += ", ";

	}

	return r;
}
 
Example #30
Source File: VariableAnalyzer.java    From coming with MIT License 5 votes vote down vote up
private int[] argumentDiff(List<CtElement> argumentsoriginal, List<CtElement> argumentsother, CtVariableAccess varaccess) {
	
	int numberdiffargument =0;
	int numberdiffvarreplacebyvar =0;
	int numberdiffvarreplacebymethod =0;
	
	for(int index=0; index<argumentsoriginal.size(); index++) {
		
		CtElement original = argumentsoriginal.get(index);
		CtElement other = argumentsother.get(index);
		
		if(original.equals(other) || original.toString().equals(other.toString())) {
			// same
		} else {
			numberdiffargument+=1;
			if(original instanceof CtVariableAccess && original.equals(varaccess)) {
				if(other instanceof CtVariableAccess)
					numberdiffvarreplacebyvar+=1;
				else if(other instanceof CtInvocation || other instanceof CtConstructorCall)
					numberdiffvarreplacebymethod+=1;
				else {
					// do nothing
				}
			}
		}
	}

	int diffarray[]=new int[3];
	diffarray[0]=numberdiffargument;
	diffarray[1]=numberdiffvarreplacebyvar;
	diffarray[2]=numberdiffvarreplacebymethod;

       return diffarray;
}