@Override public <T> void visitCtBinaryOperator(CtBinaryOperator<T> operator) { enterCtExpression(operator); scan(operator.getLeftHandOperand()); printer.writeSpace(); printer.writeOperator(OperatorHelper.getOperatorText(operator.getKind())); printer.writeSpace(); try (Writable _context = context.modify()) { if (operator.getKind() == BinaryOperatorKind.INSTANCEOF) { _context.forceWildcardGenerics(true); } scan(operator.getRightHandOperand()); } exitCtExpression(operator); }
public <T> void visitCtBinaryOperator(final spoon.reflect.code.CtBinaryOperator<T> operator) { spoon.reflect.code.CtBinaryOperator<T> aCtBinaryOperator = operator.getFactory().Core().createBinaryOperator(); this.builder.copy(operator, aCtBinaryOperator); aCtBinaryOperator.setAnnotations(this.cloneHelper.clone(operator.getAnnotations())); aCtBinaryOperator.setType(this.cloneHelper.clone(operator.getType())); aCtBinaryOperator.setTypeCasts(this.cloneHelper.clone(operator.getTypeCasts())); aCtBinaryOperator.setLeftHandOperand(this.cloneHelper.clone(operator.getLeftHandOperand())); aCtBinaryOperator.setRightHandOperand(this.cloneHelper.clone(operator.getRightHandOperand())); aCtBinaryOperator.setComments(this.cloneHelper.clone(operator.getComments())); this.cloneHelper.tailor(operator, aCtBinaryOperator); this.other = aCtBinaryOperator; }
@Override public <T> CtBinaryOperator<T> createBinaryOperator() { CtBinaryOperator<T> e = new CtBinaryOperatorImpl<>(); e.setFactory(getMainFactory()); return e; }
@Override public <T> void visitCtBinaryOperator(CtBinaryOperator<T> e) { List<CtElement> elements = new ArrayList<>(); elements.add(e.getLeftHandOperand()); elements.add(e.getRightHandOperand()); addCommentToNear(comment, elements); }
public <T> void visitCtBinaryOperator(final spoon.reflect.code.CtBinaryOperator<T> operator) { spoon.reflect.code.CtBinaryOperator other = ((spoon.reflect.code.CtBinaryOperator) (this.stack.peek())); enter(operator); biScan(spoon.reflect.path.CtRole.ANNOTATION, operator.getAnnotations(), other.getAnnotations()); biScan(spoon.reflect.path.CtRole.TYPE, operator.getType(), other.getType()); biScan(spoon.reflect.path.CtRole.CAST, operator.getTypeCasts(), other.getTypeCasts()); biScan(spoon.reflect.path.CtRole.LEFT_OPERAND, operator.getLeftHandOperand(), other.getLeftHandOperand()); biScan(spoon.reflect.path.CtRole.RIGHT_OPERAND, operator.getRightHandOperand(), other.getRightHandOperand()); biScan(spoon.reflect.path.CtRole.COMMENT, operator.getComments(), other.getComments()); exit(operator); }
@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(); } }
@SuppressWarnings("unchecked") public <T> void visitCtBinaryOperator(CtBinaryOperator<T> operator) { CtExpression<?> left = evaluate(operator, operator.getLeftHandOperand()); CtExpression<?> right = evaluate(operator, operator.getRightHandOperand()); if ((left instanceof CtLiteral) && (right instanceof CtLiteral)) { Object leftObject = ((CtLiteral<?>) left).getValue(); Object rightObject = ((CtLiteral<?>) right).getValue(); CtLiteral<Object> res = operator.getFactory().Core().createLiteral(); switch (operator.getKind()) { case AND: res.setValue((Boolean) leftObject && (Boolean) rightObject); break; case MINUS: res.setValue(convert(operator.getType(), ((Number) leftObject).doubleValue() - ((Number) rightObject).doubleValue())); break; case MUL: res.setValue(convert(operator.getType(), ((Number) leftObject).doubleValue() * ((Number) rightObject).doubleValue())); break; case DIV: res.setValue(convert(operator.getType(), ((Number) leftObject).doubleValue() / ((Number) rightObject).doubleValue())); break; res.setValue("" + leftObject + rightObject); } else { res.setValue(convert(operator.getType(), ((Number) leftObject).doubleValue() + ((Number) rightObject).doubleValue()));
@Override public <T> void visitCtBinaryOperator(CtBinaryOperator<T> operator) { if (child instanceof CtExpression) { if (operator.getLeftHandOperand() == null) { operator.setLeftHandOperand((CtExpression<?>) child); return; } else if (operator.getRightHandOperand() == null) { if (child.getPosition().isValidPosition()) { int childEnd = child.getPosition().getSourceEnd(); SourcePosition oldPos = operator.getPosition(); if (oldPos.isValidPosition() && oldPos.getSourceEnd() < childEnd) { operator.setPosition(operator.getFactory().Core().createSourcePosition( oldPos.getCompilationUnit(), oldPos.getSourceStart(), childEnd, operator.setRightHandOperand((CtExpression<?>) child); return; } else if (jdtTreeBuilder.getContextBuilder().stack.peek().node instanceof StringLiteralConcatenation) { CtBinaryOperator<?> op = operator.getFactory().Core().createBinaryOperator(); op.setKind(BinaryOperatorKind.PLUS); op.setLeftHandOperand(operator.getRightHandOperand()); op.setRightHandOperand((CtExpression<?>) child); operator.setRightHandOperand(op); int[] lineSeparatorPositions = jdtTreeBuilder.getContextBuilder().getCompilationUnitLineSeparatorPositions(); SourcePosition leftPosition = op.getLeftHandOperand().getPosition(); SourcePosition rightPosition = op.getRightHandOperand().getPosition(); op.setPosition(op.getFactory().createSourcePosition(leftPosition.getCompilationUnit(), leftPosition.getSourceStart(), rightPosition.getSourceEnd(), lineSeparatorPositions)); return;
super.visitCtBinaryOperator(operator); @SuppressWarnings("rawtypes") CtExpression left = operator.getLeftHandOperand(); String typeoperator=operator.getType().getQualifiedName(); typelefthand = typelefthand.replaceAll("\\d",""); typeoperator = typeoperator.replaceAll("\\d",""); CtExpression exp = null; BinaryOperatorKind kind=operator.getKind(); if(rop.contains(kind)) exp = OperatorGenerator.fetchROP(operator, this.mutSupporter, this.modificationPoint, typelefthand, "ROP"); operator.setLeftHandOperand(candidates.get(left)); saveSketchAndSynthesize(); operator.setLeftHandOperand(left); resoreDiskFile(); CtExpression right = operator.getRightHandOperand(); if (candidates.containsKey(right)) { operator.setRightHandOperand(candidates.get(right)); saveSketchAndSynthesize(); operator.setRightHandOperand(right); resoreDiskFile();
@Override @SuppressWarnings("unchecked") public <T> void visitCtBinaryOperator(CtBinaryOperator<T> operator) { CtExpression<?> left = evaluate(operator.getLeftHandOperand()); CtExpression<?> right = evaluate(operator.getRightHandOperand()); if ((left instanceof CtLiteral) && (right instanceof CtLiteral)) { Object leftObject = ((CtLiteral<?>) left).getValue(); Object rightObject = ((CtLiteral<?>) right).getValue(); CtLiteral<Object> res = operator.getFactory().Core().createLiteral(); switch (operator.getKind()) { case AND: res.setValue((Boolean) leftObject && (Boolean) rightObject); break; case MINUS: res.setValue(convert(operator.getType(), ((Number) leftObject).doubleValue() - ((Number) rightObject).doubleValue())); break; case MUL: res.setValue(convert(operator.getType(), ((Number) leftObject).doubleValue() * ((Number) rightObject).doubleValue())); break; case DIV: res.setValue(convert(operator.getType(), ((Number) leftObject).doubleValue() / ((Number) rightObject).doubleValue())); break; res.setValue("" + leftObject + rightObject); } else { res.setValue(convert(operator.getType(),
@Override public <T> void visitCtBinaryOperator(CtBinaryOperator<T> operator) { if (child instanceof CtExpression) { if (operator.getLeftHandOperand() == null) { operator.setLeftHandOperand((CtExpression<?>) child); return; } else if (operator.getRightHandOperand() == null) { operator.setRightHandOperand((CtExpression<?>) child); return; } } super.visitCtBinaryOperator(operator); }
/** * Creates a binary operator. * * @param <T> * the type of the expression * @param left * the left operand * @param right * the right operand * @param kind * the operator kind * @return a binary operator expression */ public <T> CtBinaryOperator<T> createBinaryOperator(CtExpression<?> left, CtExpression<?> right, BinaryOperatorKind kind) { return factory.Core().<T>createBinaryOperator().setLeftHandOperand(left).setKind(kind).setRightHandOperand(right); }
public <T> void visitCtBinaryOperator(CtBinaryOperator<T> operator) { enterCtExpression(operator); boolean paren = false; try { paren = (operator.getParent() instanceof CtBinaryOperator) || (operator.getParent() instanceof CtUnaryOperator); } catch (ParentNotInitializedException ex) { // nothing if we have no parent } if (paren) { write("("); } scan(operator.getLeftHandOperand()); write(" ").writeOperator(operator.getKind()).write(" "); scan(operator.getRightHandOperand()); if (paren) { write(")"); } exitCtExpression(operator); }
static CtLiteral<?> concatString(CtBinaryOperator<?> binaryOperator) { return binaryOperator.getFactory().createLiteral( ((String) ((CtLiteral) binaryOperator.getLeftHandOperand()).getValue()) + ((String) ((CtLiteral) binaryOperator.getRightHandOperand()).getValue()) ); } }
@SuppressWarnings("unchecked") @Override public <T, U> U getValue(T element) { return ((U) ((Object) (castTarget(element).getKind()))); }
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); newIngredientExtended.setDerivedFrom(previousExpression); ingredientsNewBinaryExpressions.add(newIngredientExtended); } return ingredientsNewBinaryExpressions; }
static void flatStringLiterals(CtMethod<?> testMethod) { final List<CtBinaryOperator> deepestBinOp = testMethod.getElements( op -> (op.getLeftHandOperand() instanceof CtLiteral && ((CtLiteral) op.getLeftHandOperand()).getValue() instanceof String) && op.getRightHandOperand() instanceof CtLiteral && ((CtLiteral) op.getRightHandOperand()).getValue() instanceof String ); deepestBinOp.forEach(StringLiteralAmplifier::concatAndReplace); if (deepestBinOp.stream() .allMatch(ctBinaryOperator -> ctBinaryOperator.getParent(CtBinaryOperator.class) == null)) { return; } else { flatStringLiterals(testMethod); } }
@Override public <T, U> void setValue(T element, U value) { castTarget(element).setKind(castValue(value)); } }
@SuppressWarnings("unchecked") @Override public <T, U> U getValue(T element) { return ((U) ((Object) (castTarget(element).getLeftHandOperand()))); }