Java Code Examples for spoon.reflect.code.CtBinaryOperator#setParent()

The following examples show how to use spoon.reflect.code.CtBinaryOperator#setParent() . 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: SingleOperatorChangeOperator.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
@Override
public boolean applyModification() {
	CtBinaryOperator newBinaryOperator = new CtBinaryOperatorImpl<>();
	newBinaryOperator.setKind(operator);

	CtExpression leftOriginal2 = (CtExpression) MetaGenerator.geOriginalElement(leftOriginal);
	newBinaryOperator.setLeftHandOperand(leftOriginal2.clone());

	CtExpression rightOriginal2 = (CtExpression) MetaGenerator.geOriginalElement(rightOriginal);
	newBinaryOperator.setRightHandOperand(rightOriginal2.clone());

	//
	newBinaryOperator.setFactory(MutationSupporter.getFactory());
	newBinaryOperator.setParent(original.getParent());
	//

	super.setOriginal(original);
	super.setModified(newBinaryOperator);

	return super.applyModification();
}
 
Example 2
Source File: SingleLogicExpOperator.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
@Override
public boolean applyModification() {
	CtBinaryOperator binaryOperator = new CtBinaryOperatorImpl<>();
	binaryOperator.setKind(operator);

	CtExpression leftOriginal2 = (CtExpression) MetaGenerator.geOriginalElement(leftOriginal);
	binaryOperator.setLeftHandOperand(leftOriginal2.clone());

	CtExpression newRightExpression = rightNew;
	binaryOperator.setRightHandOperand(newRightExpression);

	//
	binaryOperator.setFactory(MutationSupporter.getFactory());
	binaryOperator.setParent(leftOriginal2.getParent());
	//

	super.setOriginal(leftOriginal2);
	super.setModified(binaryOperator);

	return super.applyModification();
}
 
Example 3
Source File: LogicExpOperator.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
private List<Ingredient> computeIngredientsFromExpressionExplansion(ModificationPoint modificationPoint,
		CtExpression previousExpression, List<IngredientFromDyna> ingredientsDynamoth,
		BinaryOperatorKind operatorKind2) {

	List<Ingredient> ingredientsNewBinaryExpressions = new ArrayList();

	for (IngredientFromDyna ingredientFromDyna : ingredientsDynamoth) {

		CtBinaryOperator binaryOperator = new CtBinaryOperatorImpl<>();
		binaryOperator.setKind(operatorKind2);

		CtExpression previousExpressionCloned = previousExpression.clone();
		MutationSupporter.clearPosition(previousExpressionCloned);
		binaryOperator.setLeftHandOperand(previousExpressionCloned);

		CtExpression newRightExpression = MutationSupporter.getFactory()
				.createCodeSnippetExpression(ingredientFromDyna.getDynmothExpression().toString());
		binaryOperator.setRightHandOperand(newRightExpression);

		//
		binaryOperator.setFactory(MutationSupporter.getFactory());
		binaryOperator.setParent(previousExpression.getParent());

		Ingredient newIngredientExtended = new Ingredient(binaryOperator);
		// Updated: new code
		newIngredientExtended.getMetadata().put("operator", operatorKind2);
		newIngredientExtended.getMetadata().put("right", newRightExpression);
		newIngredientExtended.getMetadata().put("leftoriginal", previousExpression);
		//

		ingredientsNewBinaryExpressions.add(newIngredientExtended);
	}

	return ingredientsNewBinaryExpressions;
}