@Override public <T> void visitCtUnaryOperator(CtUnaryOperator<T> operator) { CtExpression<?> operand = evaluate(operator.getOperand()); if (operand instanceof CtLiteral) { Object object = ((CtLiteral<?>) operand).getValue(); CtLiteral<Object> res = operator.getFactory().Core().createLiteral(); switch (operator.getKind()) { case NOT: res.setValue(!(Boolean) object); break; default: throw new RuntimeException("unsupported operator " + operator.getKind()); } setResult(res); return; } setResult(operator.clone()); }
public <T> void visitCtUnaryOperator(final spoon.reflect.code.CtUnaryOperator<T> operator) { spoon.reflect.code.CtUnaryOperator<T> aCtUnaryOperator = operator.getFactory().Core().createUnaryOperator(); this.builder.copy(operator, aCtUnaryOperator); aCtUnaryOperator.setAnnotations(this.cloneHelper.clone(operator.getAnnotations())); aCtUnaryOperator.setType(this.cloneHelper.clone(operator.getType())); aCtUnaryOperator.setTypeCasts(this.cloneHelper.clone(operator.getTypeCasts())); aCtUnaryOperator.setOperand(this.cloneHelper.clone(operator.getOperand())); aCtUnaryOperator.setComments(this.cloneHelper.clone(operator.getComments())); this.cloneHelper.tailor(operator, aCtUnaryOperator); this.other = aCtUnaryOperator; }
@Override public <T> void visitCtUnaryOperator(CtUnaryOperator<T> operator) { if (operator.getOperand() == null && child instanceof CtExpression) { operator.setOperand((CtExpression<T>) child); return; } super.visitCtUnaryOperator(operator); }
public <T> void visitCtUnaryOperator(final spoon.reflect.code.CtUnaryOperator<T> operator) { spoon.reflect.code.CtUnaryOperator other = ((spoon.reflect.code.CtUnaryOperator) (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.EXPRESSION, operator.getOperand(), other.getOperand()); biScan(spoon.reflect.path.CtRole.COMMENT, operator.getComments(), other.getComments()); exit(operator); }
@Override public List<MutantCtElement> execute(CtElement toMutate) { //List<CtElement> result = new ArrayList<CtElement>(); List<MutantCtElement> result = new ArrayList<MutantCtElement>(); if (toMutate instanceof CtUnaryOperator<?>) { CtUnaryOperator<?> unary = (CtUnaryOperator<?>) toMutate; if (unary.getKind() == UnaryOperatorKind.NOT) { CtExpression expIF = factory.Core().clone(unary.getOperand()); MutantCtElement mutatn = new MutantCtElement(expIF,0.3); //result.add(expIF); result.add(mutatn); } } else { if (toMutate instanceof CtTypedElement<?>) { CtExpression<?> inv = (CtExpression<?>) toMutate; if (inv.getType()!= null && inv.getType().getSimpleName().equals(boolean.class.getSimpleName())) { CtExpression<?> invClone = factory.Core().clone(inv); CtUnaryOperator unary = factory.Core().createUnaryOperator(); unary.setOperand(invClone); unary.setKind(UnaryOperatorKind.NOT); //result.add(unary); MutantCtElement mutatn = new MutantCtElement(unary,3); //result.add(expIF); result.add(mutatn); } } } return result; }
@Override public <T> void visitCtUnaryOperator(CtUnaryOperator<T> operator) { enterCtStatement(operator); enterCtExpression(operator); UnaryOperatorKind op = operator.getKind(); if (OperatorHelper.isPrefixOperator(op)) { printer.writeOperator(OperatorHelper.getOperatorText(op)); } scan(operator.getOperand()); if (OperatorHelper.isSufixOperator(op)) { printer.writeOperator(OperatorHelper.getOperatorText(op)); } exitCtExpression(operator); exitCtStatement(operator); }
public <T> void visitCtUnaryOperator(CtUnaryOperator<T> operator) { CtExpression<?> operand = evaluate(operator, operator.getOperand()); if (operand instanceof CtLiteral) { Object object = ((CtLiteral<?>) operand).getValue(); CtLiteral<Object> res = operator.getFactory().Core().createLiteral(); switch (operator.getKind()) { case NOT: res.setValue(!(Boolean) object); break; default: throw new RuntimeException("unsupported operator " + operator.getKind()); } setResult(res); return; } setResult(operator.getFactory().Core().clone(operator)); }
@SuppressWarnings("unchecked") @Override public <T, U> U getValue(T element) { return ((U) ((Object) (castTarget(element).getKind()))); }
@Override public boolean visit(PostfixExpression postfixExpression, BlockScope scope) { CtUnaryOperator<?> op = factory.Core().createUnaryOperator(); if (postfixExpression.operator == OperatorIds.PLUS) { op.setKind(UnaryOperatorKind.POSTINC); } if (postfixExpression.operator == OperatorIds.MINUS) { op.setKind(UnaryOperatorKind.POSTDEC); } context.enter(op, postfixExpression); return true; }
@SuppressWarnings("unchecked") @Override public <T, U> U getValue(T element) { return ((U) ((Object) (castTarget(element).getOperand()))); }
private CtIf createNotInitIf() { CtIf ctIf = f().Core().createIf(); CtUnaryOperator<Boolean> negInit = f().Core().createUnaryOperator(); negInit.setKind(NOT); negInit.setOperand(createStageInitInvocation()); ctIf.setCondition(negInit); return ctIf; }
@java.lang.Override public void set(spoon.reflect.code.CtExpression replace) { this.element.setOperand(replace); } }
@Override public <T> CtUnaryOperator<T> createUnaryOperator() { CtUnaryOperator<T> e = new CtUnaryOperatorImpl<>(); e.setFactory(getMainFactory()); return e; }
public <T> void visitCtUnaryOperator(final CtUnaryOperator<T> operator) { enter(operator); scan(CtRole.ANNOTATION, operator.getAnnotations()); scan(CtRole.TYPE, operator.getType()); scan(CtRole.CAST, operator.getTypeCasts()); scan(CtRole.EXPRESSION, operator.getOperand()); scan(CtRole.COMMENT, operator.getComments()); exit(operator); }
public <T> void visitCtUnaryOperator(CtUnaryOperator<T> operator) { scan(operator.getOperand()); write(operator.getKind().toString()); }
@Override public <T> void visitCtUnaryOperator(CtUnaryOperator<T> operator) { if (operator.getOperand() == null && child instanceof CtExpression) { operator.setOperand((CtExpression<T>) child); return; } super.visitCtUnaryOperator(operator); }
@Override public <T> void visitCtUnaryOperator(CtUnaryOperator<T> e) { final CtUnaryOperator peek = (CtUnaryOperator) this.other; if (e.getKind() == null) { if (peek.getKind() != null) { setNotEqual(CtRole.OPERATOR_KIND); } } else if (peek.getKind() == null) { setNotEqual(CtRole.OPERATOR_KIND); } else if (!e.getKind().equals(peek.getKind())) { setNotEqual(CtRole.OPERATOR_KIND); } super.visitCtUnaryOperator(e); }
@Override public boolean visit(PrefixExpression prefixExpression, BlockScope scope) { CtUnaryOperator<?> op = factory.Core().createUnaryOperator(); if (prefixExpression.operator == OperatorIds.PLUS) { op.setKind(UnaryOperatorKind.PREINC); } if (prefixExpression.operator == OperatorIds.MINUS) { op.setKind(UnaryOperatorKind.PREDEC); } context.enter(op, prefixExpression); return true; }
@Override public <T> void visitCtUnaryOperator(CtUnaryOperator<T> operator) { addFrom(operator); scan(operator.getOperand()); }