@Override public <T> void visitCtBinaryOperator(CtBinaryOperator<T> e) { List<CtElement> elements = new ArrayList<>(); elements.add(e.getLeftHandOperand()); elements.add(e.getRightHandOperand()); addCommentToNear(comment, elements); }
@SuppressWarnings("unchecked") @Override public <T, U> U getValue(T element) { return ((U) ((Object) (castTarget(element).getRightHandOperand()))); }
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); }
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();
public <T> void visitCtBinaryOperator(final CtBinaryOperator<T> operator) { enter(operator); scan(CtRole.ANNOTATION, operator.getAnnotations()); scan(CtRole.TYPE, operator.getType()); scan(CtRole.CAST, operator.getTypeCasts()); scan(CtRole.LEFT_OPERAND, operator.getLeftHandOperand()); scan(CtRole.RIGHT_OPERAND, operator.getRightHandOperand()); scan(CtRole.COMMENT, operator.getComments()); exit(operator); }
@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); }
@java.lang.Override public <T> void visitCtBinaryOperator(final spoon.reflect.code.CtBinaryOperator<T> operator) { replaceInListIfExist(operator.getAnnotations(), new spoon.support.visitor.replace.ReplacementVisitor.CtElementAnnotationsReplaceListener(operator)); replaceElementIfExist(operator.getType(), new spoon.support.visitor.replace.ReplacementVisitor.CtTypedElementTypeReplaceListener(operator)); replaceInListIfExist(operator.getTypeCasts(), new spoon.support.visitor.replace.ReplacementVisitor.CtExpressionTypeCastsReplaceListener(operator)); replaceElementIfExist(operator.getLeftHandOperand(), new spoon.support.visitor.replace.ReplacementVisitor.CtBinaryOperatorLeftHandOperandReplaceListener(operator)); replaceElementIfExist(operator.getRightHandOperand(), new spoon.support.visitor.replace.ReplacementVisitor.CtBinaryOperatorRightHandOperandReplaceListener(operator)); replaceInListIfExist(operator.getComments(), new spoon.support.visitor.replace.ReplacementVisitor.CtElementCommentsReplaceListener(operator)); }
operator.setLeftHandOperand((CtExpression<?>) child); return; } else if (operator.getRightHandOperand() == null) { if (child.getPosition().isValidPosition()) { int childEnd = child.getPosition().getSourceEnd(); 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;
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; }
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); } }
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; }
@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); }
names.add(factory.Code().createCodeSnippetExpression("\"" + operator.getRightHandOperand().toString() + "\"")); values.add(factory.Code().createCodeSnippetExpression(operator.getRightHandOperand().toString()));
static CtLiteral<?> concatString(CtBinaryOperator<?> binaryOperator) { return binaryOperator.getFactory().createLiteral( ((String) ((CtLiteral) binaryOperator.getLeftHandOperand()).getValue()) + ((String) ((CtLiteral) binaryOperator.getRightHandOperand()).getValue()) ); } }
@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(); } }
@Override public <T> void visitCtBinaryOperator(CtBinaryOperator<T> operator) { addFrom(operator); scan(operator.getLeftHandOperand()); if (!operator.getKind().equals(BinaryOperatorKind.INSTANCEOF)) { scan(operator.getRightHandOperand()); } }
public <T> void visitCtBinaryOperator(CtBinaryOperator<T> operator) { scan(operator.getLeftHandOperand()); write(operator.getKind().toString()); scan(operator.getRightHandOperand()); }
public <T> void visitCtBinaryOperator(CtBinaryOperator<T> operator) { enter(operator); scan(operator.getAnnotations()); scan(operator.getType()); scanReferences(operator.getTypeCasts()); scan(operator.getLeftHandOperand()); scan(operator.getRightHandOperand()); exit(operator); }
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); }
@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(); } }