Java Code Examples for spoon.reflect.code.CtUnaryOperator

The following examples show how to use spoon.reflect.code.CtUnaryOperator. These examples are extracted from open source projects. 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 Project: astor   Source File: ExpressionRevolver.java    License: GNU General Public License v2.0 6 votes vote down vote up
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 2
Source Project: astor   Source File: ReturnExpresionMutOp.java    License: GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean canBeAppliedToPoint(ModificationPoint point) {

	return (point.getCodeElement() instanceof CtReturn)
			&& (point.getCodeElement().getElements(new TypeFilter(CtBinaryOperator.class)).size() > 0
					|| point.getCodeElement().getElements(new TypeFilter(CtUnaryOperator.class)).size() > 0);

}
 
Example 3
Source Project: astor   Source File: TransformStrategy.java    License: GNU General Public License v2.0 5 votes vote down vote up
@SuppressWarnings({ "unchecked", "rawtypes" })
public List<String> transform () {
	CtStatement targetStmt = (CtStatement) this.modificationPoint.getCodeElement();
	if (targetStmt instanceof CtInvocation)
		this.visitCtInvocation((CtInvocation) targetStmt);
	else if (targetStmt instanceof CtConstructorCall)
		this.visitCtConstructorCall((CtConstructorCall) targetStmt);
	else if (targetStmt instanceof CtIf)
		this.visitCtIf ((CtIf)targetStmt);
	else if (targetStmt instanceof CtReturn)
		this.visitCtReturn((CtReturn) targetStmt);
	else if (targetStmt instanceof CtSwitch)
		this.visitCtSwitch((CtSwitch) targetStmt);
	else if (targetStmt instanceof CtCase)
		this.visitCtCase((CtCase) targetStmt);
	else if (targetStmt instanceof CtAssignment)
		this.visitCtAssignment((CtAssignment) targetStmt);
	else if (targetStmt instanceof CtAssert)
		this.visitCtAssert((CtAssert) targetStmt);
	else if (targetStmt instanceof CtFor)
		this.visitCtFor((CtFor) targetStmt);
	else if (targetStmt instanceof CtForEach)
		this.visitCtForEach((CtForEach) targetStmt);
	else if (targetStmt instanceof CtWhile)
		this.visitCtWhile((CtWhile) targetStmt);
	else if (targetStmt instanceof CtUnaryOperator)
		this.visitCtUnaryOperator((CtUnaryOperator) targetStmt);
	else if (targetStmt instanceof CtSynchronized)
		this.visitCtSynchronized((CtSynchronized) targetStmt);

	return list;
}
 
Example 4
Source Project: astor   Source File: TransformStrategy.java    License: GNU General Public License v2.0 5 votes vote down vote up
@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
public <T> void visitCtUnaryOperator(CtUnaryOperator<T> operator) {
	super.visitCtUnaryOperator(operator);
	
	CtExpression exper=operator.getOperand();
	if (candidates.containsKey(exper)) {
		operator.setOperand(candidates.get(exper));
		saveSketchAndSynthesize();
		operator.setOperand(exper);
		resoreDiskFile();
	}
}
 
Example 5
Source Project: coming   Source File: BinaryOperatorAnalyzer.java    License: MIT License 4 votes vote down vote up
private boolean scannotoperator (CtExpression expressiontostudy) {
	
	List<String> unaryOps = new ArrayList();
	
	CtScanner scanner = new CtScanner() {

		@Override
		public <T> void visitCtUnaryOperator(CtUnaryOperator<T> operator) {

			super.visitCtUnaryOperator(operator);
			unaryOps.add(operator.getKind().toString());
		}
	};
	
	scanner.scan(expressiontostudy);
	
	return unaryOps.contains(UnaryOperatorKind.NOT.toString());
}
 
Example 6
Source Project: gumtree-spoon-ast-diff   Source File: LabelFinder.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public <T> void visitCtUnaryOperator(CtUnaryOperator<T> operator) {
	label = operator.getKind().toString();
}