Java Code Examples for spoon.reflect.code.CtBinaryOperator#setRightHandOperand()
The following examples show how to use
spoon.reflect.code.CtBinaryOperator#setRightHandOperand() .
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: WrapwithIfNullCheck.java From astor with GNU General Public License v2.0 | 6 votes |
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 2
Source File: SingleOperatorChangeOperator.java From astor with GNU General Public License v2.0 | 6 votes |
@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 3
Source File: SingleLogicExpOperator.java From astor with GNU General Public License v2.0 | 6 votes |
@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 4
Source File: ConditionRemoveTransform.java From astor with GNU General Public License v2.0 | 6 votes |
@SuppressWarnings({ "rawtypes", "static-access" }) @Override public <T> void visitCtBinaryOperator(CtBinaryOperator<T> operator) { super.visitCtBinaryOperator(operator); if(operator.getKind()==BinaryOperatorKind.AND||operator.getKind()==BinaryOperatorKind.OR) { CtExpression right = operator.getRightHandOperand(); operator.setKind(BinaryOperatorKind.AND); CtLiteral<Boolean> literalvalue = this.mutSupporter.getFactory().Core().createLiteral(); Boolean bval=true; literalvalue.setValue(bval); operator.setRightHandOperand(literalvalue); saveSketchAndSynthesize(); operator.setRightHandOperand(right); resoreDiskFile(); CtExpression left = operator.getLeftHandOperand(); operator.setKind(BinaryOperatorKind.AND); operator.setLeftHandOperand(literalvalue); saveSketchAndSynthesize(); operator.setLeftHandOperand(left); resoreDiskFile(); } }
Example 5
Source File: ConditionRemoveTransform.java From astor with GNU General Public License v2.0 | 6 votes |
@SuppressWarnings({ "static-access", "rawtypes", "unchecked" }) public void visitCtIf(CtIf ifElement) { super.visitCtIf(ifElement); CtExpression cond = ifElement.getCondition(); CtLiteral<Boolean> literalvalue = this.mutSupporter.getFactory().Core().createLiteral(); Boolean bval=false; literalvalue.setValue(bval); CtBinaryOperator<?> newcond = this.mutSupporter.getFactory().Core().createBinaryOperator(); newcond.setKind(BinaryOperatorKind.AND); newcond.setRightHandOperand(literalvalue); newcond.setLeftHandOperand(cond); ifElement.setCondition((CtExpression<Boolean>) newcond); saveSketchAndSynthesize(); ifElement.setCondition(cond); resoreDiskFile(); }
Example 6
Source File: ExpressionTransform.java From astor with GNU General Public License v2.0 | 6 votes |
@Override public <T> void visitCtBinaryOperator(CtBinaryOperator<T> operator) { super.visitCtBinaryOperator(operator); @SuppressWarnings("rawtypes") CtExpression left = operator.getLeftHandOperand(); if (candidates.containsKey(left)) { operator.setLeftHandOperand(candidates.get(left)); saveSketchAndSynthesize(); operator.setLeftHandOperand(left); resoreDiskFile(); } @SuppressWarnings("rawtypes") CtExpression right = operator.getRightHandOperand(); if (candidates.containsKey(right)) { operator.setRightHandOperand(candidates.get(right)); saveSketchAndSynthesize(); operator.setRightHandOperand(right); resoreDiskFile(); } }
Example 7
Source File: LogicExpOperator.java From astor with GNU General Public License v2.0 | 5 votes |
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; }
Example 8
Source File: OperatorTransform.java From astor with GNU General Public License v2.0 | 5 votes |
@Override public <T> void visitCtBinaryOperator(CtBinaryOperator<T> operator) { super.visitCtBinaryOperator(operator); @SuppressWarnings("rawtypes") CtExpression left = operator.getLeftHandOperand(); String typelefthand=left.getType().getQualifiedName(); String typeoperator=operator.getType().getQualifiedName(); typelefthand = typelefthand.replaceAll("\\d",""); typeoperator = typeoperator.replaceAll("\\d",""); @SuppressWarnings("rawtypes") CtExpression exp = null; BinaryOperatorKind kind=operator.getKind(); if(rop.contains(kind)) exp = OperatorGenerator.fetchROP(operator, this.mutSupporter, this.modificationPoint, typelefthand, "ROP"); else if(aop.contains(kind)) exp = OperatorGenerator.fetchROP(operator, this.mutSupporter, this.modificationPoint, typeoperator, "AOP"); if (exp != null) candidates.put(operator, exp); if (candidates.containsKey(left)) { operator.setLeftHandOperand(candidates.get(left)); saveSketchAndSynthesize(); operator.setLeftHandOperand(left); resoreDiskFile(); } @SuppressWarnings("rawtypes") CtExpression right = operator.getRightHandOperand(); if (candidates.containsKey(right)) { operator.setRightHandOperand(candidates.get(right)); saveSketchAndSynthesize(); operator.setRightHandOperand(right); resoreDiskFile(); } }