@Override public <T, U> void setValue(T element, U value) { castTarget(element).setKind(castValue(value)); } }
public <T> void visitCtBinaryOperator(spoon.reflect.code.CtBinaryOperator<T> e) { ((spoon.reflect.code.CtBinaryOperator<T>) (other)).setKind(e.getKind()); super.visitCtBinaryOperator(e); }
@Override public boolean visit(StringLiteralConcatenation literal, BlockScope scope) { context.enter(factory.Core().createBinaryOperator().<CtBinaryOperator>setKind(BinaryOperatorKind.PLUS), literal); return true; }
@Override public boolean visit(InstanceOfExpression instanceOfExpression, BlockScope scope) { CtBinaryOperator<?> op = factory.Core().createBinaryOperator(); op.setKind(BinaryOperatorKind.INSTANCEOF); context.enter(op, instanceOfExpression); return true; }
@Override public boolean visit(OR_OR_Expression or_or_Expression, BlockScope scope) { CtBinaryOperator<?> op = factory.Core().createBinaryOperator(); op.setKind(getBinaryOperatorKind((or_or_Expression.bits & ASTNode.OperatorMASK) >> ASTNode.OperatorSHIFT)); context.enter(op, or_or_Expression); return true; }
@Override public boolean visit(BinaryExpression binaryExpression, BlockScope scope) { CtBinaryOperator<?> op = factory.Core().createBinaryOperator(); op.setKind(getBinaryOperatorKind((binaryExpression.bits & ASTNode.OperatorMASK) >> ASTNode.OperatorSHIFT)); context.enter(op, binaryExpression); return true; }
@Override public boolean visit(EqualExpression equalExpression, BlockScope scope) { CtBinaryOperator<?> op = factory.Core().createBinaryOperator(); op.setKind(getBinaryOperatorKind((equalExpression.bits & ASTNode.OperatorMASK) >> ASTNode.OperatorSHIFT)); context.enter(op, equalExpression); return true; // do nothing by default, keep traversing }
@Override public boolean visit(AND_AND_Expression and_and_Expression, BlockScope scope) { CtBinaryOperator<?> op = factory.Core().createBinaryOperator(); op.setKind(getBinaryOperatorKind((and_and_Expression.bits & ASTNode.OperatorMASK) >> ASTNode.OperatorSHIFT)); context.enter(op, and_and_Expression); return true; }
/** * 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); }
@Override public boolean visit(StringLiteralConcatenation literal, BlockScope scope) { CtBinaryOperator<String> op = factory.Core().createBinaryOperator(); op.setKind(BinaryOperatorKind.PLUS); context.enter(op, literal); List<Expression> exp = new ArrayList<Expression>(literal.counter); for (int i = 0; i < literal.counter; i++) { exp.add(literal.literals[i]); } createExpression(literal, scope, exp); return false; }
} 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);
private void createExpression(StringLiteralConcatenation literal, BlockScope scope, List<Expression> rst) { if (rst.isEmpty()) { return; } rst.get(0).traverse(this, scope); rst.remove(0); if (rst.size() > 1) { CtBinaryOperator<?> op = factory.Core().createBinaryOperator(); op.setKind(BinaryOperatorKind.PLUS); context.enter(op, literal); createExpression(literal, scope, rst); context.exit(literal); } else { createExpression(literal, scope, rst); } }
@Override public boolean visit(BinaryExpression binaryExpression, BlockScope scope) { CtBinaryOperator<?> op = factory.Core().createBinaryOperator(); op.setKind(getBinaryOperatorKind((binaryExpression.bits & ASTNode.OperatorMASK) >> ASTNode.OperatorSHIFT)); context.enter(op, binaryExpression); return true; }
@Override public boolean visit(OR_OR_Expression or_or_Expression, BlockScope scope) { CtBinaryOperator<?> op = factory.Core().createBinaryOperator(); op.setKind(getBinaryOperatorKind((or_or_Expression.bits & ASTNode.OperatorMASK) >> ASTNode.OperatorSHIFT)); context.enter(op, or_or_Expression); return true; }
@Override public boolean visit(EqualExpression equalExpression, BlockScope scope) { CtBinaryOperator<?> op = factory.Core().createBinaryOperator(); op.setKind(getBinaryOperatorKind((equalExpression.bits & ASTNode.OperatorMASK) >> ASTNode.OperatorSHIFT)); context.enter(op, equalExpression); return true; // do nothing by default, keep traversing }
@Override public boolean visit(AND_AND_Expression and_and_Expression, BlockScope scope) { CtBinaryOperator<?> op = factory.Core().createBinaryOperator(); op.setKind(getBinaryOperatorKind((and_and_Expression.bits & ASTNode.OperatorMASK) >> ASTNode.OperatorSHIFT)); context.enter(op, and_and_Expression); return true; // do nothing by default, keep traversing }
/** * 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); }
private List<Ingredient> computeIngredientsNullCheck(ModificationPoint modificationPoint, List<CtVariableAccess> varAccessInModificationPoints) { List<Ingredient> ingredients = new ArrayList(); for (CtVariableAccess iVariableAccess : varAccessInModificationPoints) { 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; }
@Override public boolean visit(InstanceOfExpression instanceOfExpression, BlockScope scope) { CtBinaryOperator<?> op = factory.Core().createBinaryOperator(); op.setKind(BinaryOperatorKind.INSTANCEOF); CtLiteral<CtTypeReference<?>> l = factory.Core().createLiteral(); l.setValue(references.getBoundedTypeReference(instanceOfExpression.type.resolvedType)); op.setRightHandOperand(l); context.enter(op, instanceOfExpression); return true; }
@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(); }