spoon.reflect.code.CtBinaryOperator Java Examples
The following examples show how to use
spoon.reflect.code.CtBinaryOperator.
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: LogicalExpressionMetaMutator.java From metamutator with GNU General Public License v3.0 | 6 votes |
public void process(CtBinaryOperator<Boolean> binaryOperator) { BinaryOperatorKind kind = binaryOperator.getKind(); if (LOGICAL_OPERATORS.contains(kind)) { mutateOperator(binaryOperator, LOGICAL_OPERATORS); } else if (COMPARISON_OPERATORS.contains(kind)) { if (isNumber(binaryOperator.getLeftHandOperand()) && isNumber(binaryOperator.getRightHandOperand())) { mutateOperator(binaryOperator, COMPARISON_OPERATORS); } else { EnumSet<BinaryOperatorKind> clone = REDUCED_COMPARISON_OPERATORS.clone(); clone.add(kind); mutateOperator(binaryOperator, clone); } } }
Example #2
Source File: AstComparatorTest.java From gumtree-spoon-ast-diff with Apache License 2.0 | 6 votes |
@Test public void test_t_224512() throws Exception { AstComparator diff = new AstComparator(); // meld src/test/resources/examples/t_224512/left_Server_1.925.java // src/test/resources/examples/t_224512/right_Server_1.926.java File fl = new File("src/test/resources/examples/t_224512/left_Server_1.925.java"); File fr = new File("src/test/resources/examples/t_224512/right_Server_1.926.java"); Diff result = diff.compare(fl, fr); CtElement ancestor = result.commonAncestor(); assertTrue(ancestor instanceof CtBinaryOperator); List<Operation> actions = result.getRootOperations(); result.debugInformation(); assertEquals(actions.size(), 2); assertTrue(result.containsOperation(OperationKind.Insert, "BinaryOperator", "AND")); assertTrue(result.containsOperation(OperationKind.Move, "BinaryOperator", "AND")); }
Example #3
Source File: AstComparatorTest.java From gumtree-spoon-ast-diff with Apache License 2.0 | 6 votes |
@Test public void test_t_214116() throws Exception { AstComparator diff = new AstComparator(); // meld src/test/resources/examples/t_214116/left_Modeller_1.134.java // src/test/resources/examples/t_214116/right_Modeller_1.135.java File fl = new File("src/test/resources/examples/t_214116/left_Modeller_1.134.java"); File fr = new File("src/test/resources/examples/t_214116/right_Modeller_1.135.java"); Diff result = diff.compare(fl, fr); CtElement ancestor = result.commonAncestor(); assertTrue(ancestor instanceof CtBinaryOperator); List<Operation> actions = result.getRootOperations(); // result.debugInformation(); assertEquals(actions.size(), 2); assertTrue(result.containsOperation(OperationKind.Update, "Literal", "\" \"")); // the change is in a throw CtElement elem = actions.get(0).getNode(); assertNotNull(elem); assertNotNull(elem.getParent(CtThrow.class)); }
Example #4
Source File: ExpressionRevolver.java From astor with GNU General Public License v2.0 | 6 votes |
public static List<CtExpression<Boolean>> getExpressions(CtExpression<Boolean> element) { List<CtExpression<Boolean>> expsRetrieved = new ArrayList<CtExpression<Boolean>>(); if (element instanceof CtUnaryOperator) { expsRetrieved.add(element); element = ((CtUnaryOperator) element).getOperand(); } if (element instanceof CtBinaryOperator) { expsRetrieved.add(element); CtBinaryOperator bin = (CtBinaryOperator) element; if (bin.getKind().equals(BinaryOperatorKind.AND) || bin.getKind().equals(BinaryOperatorKind.OR)) { expsRetrieved.addAll(getExpressions(bin.getLeftHandOperand())); expsRetrieved.addAll(getExpressions(bin.getRightHandOperand())); } } else { if (element instanceof CtInvocation && element.getType().getSimpleName().equals(boolean.class.getSimpleName())) { expsRetrieved.add(element); } } return expsRetrieved; }
Example #5
Source File: DataCombinerSpoon.java From astor with GNU General Public License v2.0 | 6 votes |
private void add(final List<CtExpression> result, CtExpression binaryExpression) { boolean makesence = true; try { if (binaryExpression instanceof CtBinaryOperator) { makesence = isExpressionMakeSense((CtBinaryOperator) binaryExpression); } if (makesence) { this.callListener(binaryExpression); result.add(binaryExpression); } } catch (Exception e) { // the hash is different, so it throws an exception // System.err.println("error checking"); // System.err.println(binaryExpression); // e.printStackTrace(); } }
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: 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 #8
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 #9
Source File: OperatorReplacementOp.java From astor with GNU General Public License v2.0 | 6 votes |
public List<Ingredient> getNewBinary(CtBinaryOperator oldBinary, List<BinaryOperatorKind> ops) { List<Ingredient> mutationAll = new ArrayList<>(); if (ops.contains(oldBinary.getKind())) { for (BinaryOperatorKind binaryOperatorKind2 : ops) { if (binaryOperatorKind2.equals(oldBinary.getKind())) continue; CtBinaryOperator binaryOp = MutationSupporter.getFactory().Code().createBinaryOperator( oldBinary.getLeftHandOperand().clone(), oldBinary.getRightHandOperand(), binaryOperatorKind2); MutationSupporter.clearPosition(binaryOp); Ingredient newIngredientExtended = new Ingredient(binaryOp); newIngredientExtended.setDerivedFrom(oldBinary); mutationAll.add(newIngredientExtended); newIngredientExtended.getMetadata().put("left_original", oldBinary.getLeftHandOperand()); newIngredientExtended.getMetadata().put("right_original", oldBinary.getRightHandOperand()); newIngredientExtended.getMetadata().put("operator", binaryOperatorKind2); } } return mutationAll; }
Example #10
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 #11
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 #12
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 #13
Source File: BinaryOperatorMutator.java From astor with GNU General Public License v2.0 | 6 votes |
/** * Creates alternatives Expressions (Binary Operations) given a list of Binary * operators kind operators. The original kind (that one included in the * original expression is not analyzed) * * @param result * @param op * @param kind * @param operators */ protected void addRemainings(List<CtExpression> result, CtBinaryOperator<?> op, BinaryOperatorKind kind, List<BinaryOperatorKind> operators) { // TODO: recursive? if (operators.contains(kind)) { for (BinaryOperatorKind binaryOperatorKind : operators) { if (binaryOperatorKind != kind) { // Cloning CtExpression right = factory.Core().clone(op.getRightHandOperand()); CtExpression left = factory.Core().clone(op.getLeftHandOperand()); CtBinaryOperator binaryOp = factory.Code().createBinaryOperator(left, right, binaryOperatorKind); // Set parent right.setParent(binaryOp); left.setParent(binaryOp); result.add(binaryOp); } } } }
Example #14
Source File: JMutRepair.java From coming with MIT License | 6 votes |
/** * Certain patterns/characteristics of search-space of a repair tool can't be represented by ChangePatternSpecification * This filter is supposed to delete/remove such instances from the results given by PatternInstanceAnalyser. * * @param patternInstance * @param revision * @param diff * @return */ @Override public boolean filter(ChangePatternInstance patternInstance, IRevision revision, Diff diff) { String patternType = patternInstance.getPattern().getName().split(File.pathSeparator)[1]; if (patternType.startsWith("binary")) { Operation upd = patternInstance.getActions().get(0); CtBinaryOperator src = (CtBinaryOperator) upd.getSrcNode(); CtBinaryOperator dst = (CtBinaryOperator) upd.getDstNode(); return src.getLeftHandOperand().equals(dst.getLeftHandOperand()) && src.getRightHandOperand().equals(dst.getRightHandOperand()); } return true; }
Example #15
Source File: CodeElementInfo.java From coming with MIT License | 6 votes |
public CodeElementInfo(CtElement elementoriginal, List<CtExpression> allExpressions, List<CtExpression> allrootlogicalexpers, List<CtBinaryOperator> allBinOperators) { this.element = elementoriginal; this.desirableExpressions = allExpressions; this.logicalExpressions = allrootlogicalexpers; this.binoperators = allBinOperators; setContext(); setVarsInScope(); setParentClass(); setStatementList(); setMethodList(); setInvocationsFromClass(); setConstructorcallsFromClass(); setElementToStudy(); setVarsAffected(); setInvocations(); setConstructorcalls(); setLiteralsFromFaultyLine(); setTypeaccess(); }
Example #16
Source File: BinaryOperatorAnalyzer.java From coming with MIT License | 6 votes |
private void analyzeBinaryOperatorInvolve01 (CtBinaryOperator operatorunderstudy, int operatorindex, Cntx<Object> context) { boolean whethercontain01 = false; CtExpression leftexpression = operatorunderstudy.getLeftHandOperand(); CtExpression rightexpression = operatorunderstudy.getRightHandOperand(); if(leftexpression.toString().trim().equals("0") || leftexpression.toString().trim().equals("0.0") || leftexpression.toString().trim().equals("1.0") || leftexpression.toString().trim().equals("1") || rightexpression.toString().trim().equals("0") || rightexpression.toString().trim().equals("0.0") || rightexpression.toString().trim().equals("1.0") || rightexpression.toString().trim().equals("1") || leftexpression.toString().trim().endsWith("1") || rightexpression.toString().trim().endsWith("1")) whethercontain01 = true; writeGroupedInfo(context, Integer.toString(operatorindex)+"_"+operatorunderstudy, CodeFeatures.O3_CONTAIN_01, whethercontain01, "FEATURES_BINARYOPERATOR"); }
Example #17
Source File: ArithmeticOperatorMetaMutator.java From metamutator with GNU General Public License v3.0 | 6 votes |
@Override public boolean isToBeProcessed(CtBinaryOperator<Boolean> element) { try { Selector.getTopLevelClass(element); } catch (NullPointerException e) { return false; } // not in constructors because we use static fields if (element.getParent(CtConstructor.class) != null) { return false; } // not in fields declaration because we use static fields if (element.getParent(CtField.class) != null) { return false; } return (ARITHMETIC_OPERATORS.contains(element.getKind())) && (element.getParent(CtAnonymousExecutable.class) == null); }
Example #18
Source File: AbstractCodeAnalyzer.java From coming with MIT License | 6 votes |
/** * Return if the Condition is a guard * * @param condition * @return */ // we want the condition not to be null related check public boolean checkNormalGuardCondition(CtExpression condition) { if (condition != null) { List<CtBinaryOperator> binOp = condition.getElements(new TypeFilter<>(CtBinaryOperator.class)); if (binOp != null && binOp.size() > 0) { for (CtBinaryOperator ctBinaryOperator : binOp) { if (ctBinaryOperator.getRightHandOperand().toString().equals("null") || ctBinaryOperator.getLeftHandOperand().toString().equals("null")) { return false; } } } return true; } return false; }
Example #19
Source File: AbstractCodeAnalyzer.java From coming with MIT License | 6 votes |
public boolean checkNullCheckGuardCondition(CtExpression condition) { if (condition != null) { List<CtBinaryOperator> binOp = condition.getElements(new TypeFilter<>(CtBinaryOperator.class)); if (binOp != null && binOp.size() > 0) { for (CtBinaryOperator ctBinaryOperator : binOp) { if (!ctBinaryOperator.getRightHandOperand().toString().equals("null") && !ctBinaryOperator.getLeftHandOperand().toString().equals("null")) { return false; } } return true; } return false; } return false; }
Example #20
Source File: LogicalExpressionAnalyzer.java From coming with MIT License | 6 votes |
public boolean isLogicalExpression(CtElement currentElement) { if (currentElement == null) return false; if ((currentElement instanceof CtBinaryOperator)) { CtBinaryOperator binOp = (CtBinaryOperator) currentElement; if(binOp.getKind().equals(BinaryOperatorKind.AND) || binOp.getKind().equals(BinaryOperatorKind.OR) || binOp.getKind().equals(BinaryOperatorKind.EQ) || binOp.getKind().equals(BinaryOperatorKind.GE) || binOp.getKind().equals(BinaryOperatorKind.GT) || binOp.getKind().equals(BinaryOperatorKind.INSTANCEOF) || binOp.getKind().equals(BinaryOperatorKind.LE) || binOp.getKind().equals(BinaryOperatorKind.LT) || binOp.getKind().equals(BinaryOperatorKind.NE)) return true; } return false; }
Example #21
Source File: LogicalExpressionMetaMutator.java From metamutator with GNU General Public License v3.0 | 5 votes |
@Override public boolean isToBeProcessed(CtBinaryOperator<Boolean> element) { // if (element.getParent(CtAnonymousExecutable.class)!=null) { // System.out.println(element.getParent(CtAnonymousExecutable.class)); // } try { Selector.getTopLevelClass(element); } catch (NullPointerException e) { return false; } // not in constructors because we use static fields if (element.getParent(CtConstructor.class) != null) { return false; } // not in fields declaration because we use static fields if (element.getParent(CtField.class) != null) { return false; } return (LOGICAL_OPERATORS.contains(element.getKind()) || COMPARISON_OPERATORS .contains(element.getKind())) && (element.getParent(CtAnonymousExecutable.class) == null) // not // in // static // block ; }
Example #22
Source File: LogicRedOperator.java From astor with GNU General Public License v2.0 | 5 votes |
@Override public boolean canBeAppliedToPoint(ModificationPoint point) { // See that the modification points are statements return (point.getCodeElement() instanceof CtStatement // Let's check we have a binary expression && (point.getCodeElement() instanceof CtBinaryOperator // the element has a binary expression || point.getCodeElement().getElements(new TypeFilter<>(CtBinaryOperator.class)).size() > 0)); }
Example #23
Source File: LogicRedOperator.java From astor with GNU General Public License v2.0 | 5 votes |
public void addOperator(List<Ingredient> ingredientsReducedExpressions, CtBinaryOperator binaryOperatorToReduce, CtExpression subterm) { MutationSupporter.clearPosition(subterm); Ingredient newIngredientExtended = new Ingredient(subterm.clone()); newIngredientExtended.setDerivedFrom(binaryOperatorToReduce); ingredientsReducedExpressions.add(newIngredientExtended); newIngredientExtended.getMetadata().put("original", binaryOperatorToReduce); newIngredientExtended.getMetadata().put("reduced", subterm); }
Example #24
Source File: LogicRedOperator.java From astor with GNU General Public License v2.0 | 5 votes |
private List<Ingredient> computeIngredientsFromOperatorToReduce(ModificationPoint modificationPoint, CtBinaryOperator binaryToReduce) { List<Ingredient> ingredientsReducedExpressions = new ArrayList(); CtExpression left = binaryToReduce.getLeftHandOperand(); addOperator(ingredientsReducedExpressions, binaryToReduce, left); CtExpression right = binaryToReduce.getRightHandOperand(); addOperator(ingredientsReducedExpressions, binaryToReduce, right); return ingredientsReducedExpressions; }
Example #25
Source File: OperatorGenerator.java From astor with GNU General Public License v2.0 | 5 votes |
@SuppressWarnings({ "rawtypes", "static-access" }) public static CtExpression fetchROP(CtBinaryOperator operator, MutationSupporter mutSupporter, ModificationPoint modificationPoint, String type, String querytype) { if (type == null || type.equals("")) return null; CtCodeSnippetExpression typeexper = mutSupporter.getFactory().Code().createCodeSnippetExpression(type+".class"); ArrayList<CtExpression> param = getParameter(mutSupporter.getFactory(), operator); param.add(1, mutSupporter.getFactory().Code().createCodeSnippetExpression(Integer.toString(0))); param.add(3, typeexper); CtExpression[] arr = param.toArray(new CtExpression[param.size()]); CtExecutableReference<Object> ref = mutSupporter.getFactory().Core().createExecutableReference(); ref.setSimpleName(querytype); CtInvocation methodcall=mutSupporter.getFactory().Code().createInvocation(mutSupporter.getFactory().Code(). createCodeSnippetExpression("fr.inria.astor.approaches.scaffold.scaffoldsynthesis.ScaffoldSynthesisEntry"), ref, arr); CtCodeSnippetExpression invokemethod = mutSupporter.getFactory().Code().createCodeSnippetExpression(methodcall.toString() +".invoke()".toString()); return invokemethod; }
Example #26
Source File: ConditionMutationTransform.java From astor with GNU General Public License v2.0 | 5 votes |
public ConditionMutationTransform (ModificationPoint modPoint, int modificationPointIndex, MutationSupporter supporter, ProjectRepairFacade facade ,ScaffoldRepairEngine engine) { super(modPoint, modificationPointIndex, supporter,facade,engine); pre = "CMT"; querytype="COND"; usedBinExper=new ArrayList<CtBinaryOperator<?>>(); }
Example #27
Source File: ConditionMutationTransform.java From astor with GNU General Public License v2.0 | 5 votes |
@Override public <T> void visitCtBinaryOperator(CtBinaryOperator<T> operator) { super.visitCtBinaryOperator(operator); if(operator.getKind()==BinaryOperatorKind.AND||operator.getKind()==BinaryOperatorKind.OR) { fetchCOND(operator); } }
Example #28
Source File: BinaryOperatorMutator.java From spoon-examples with GNU General Public License v2.0 | 5 votes |
@Override public void process(CtElement candidate) { if (!(candidate instanceof CtBinaryOperator)) { return; } CtBinaryOperator op = (CtBinaryOperator)candidate; op.setKind(BinaryOperatorKind.MINUS); }
Example #29
Source File: SingleOperatorChangeOperator.java From astor with GNU General Public License v2.0 | 5 votes |
public SingleOperatorChangeOperator(ModificationPoint modificationPoint, CtBinaryOperator original, CtExpression leftOriginal, CtExpression rightNew, BinaryOperatorKind operator, AstorOperator astoroperator) { super(); this.leftOriginal = leftOriginal; this.rightOriginal = rightNew; this.operator = operator; this.original = original; super.setOperationApplied(astoroperator); super.setModificationPoint(modificationPoint); }
Example #30
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; }