Java Code Examples for spoon.reflect.code.CtBinaryOperator#getRightHandOperand()

The following examples show how to use spoon.reflect.code.CtBinaryOperator#getRightHandOperand() . 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 File: BinaryOperatorAnalyzer.java    From coming with MIT License 6 votes vote down vote up
private void analyzeBinaryOperatorInvolve01 (CtBinaryOperator operatorunderstudy, int operatorindex, Cntx<Object> context) {
	
	boolean whethercontain01 = false; 
			
	CtExpression leftexpression = operatorunderstudy.getLeftHandOperand();
	CtExpression rightexpression = operatorunderstudy.getRightHandOperand();
	
	if(leftexpression.toString().trim().equals("0") || leftexpression.toString().trim().equals("0.0") ||
			leftexpression.toString().trim().equals("1.0") || leftexpression.toString().trim().equals("1")
			|| rightexpression.toString().trim().equals("0") || rightexpression.toString().trim().equals("0.0") ||
			rightexpression.toString().trim().equals("1.0") || rightexpression.toString().trim().equals("1")
			|| leftexpression.toString().trim().endsWith("1") || rightexpression.toString().trim().endsWith("1"))
		whethercontain01 = true;
	
	writeGroupedInfo(context, Integer.toString(operatorindex)+"_"+operatorunderstudy, CodeFeatures.O3_CONTAIN_01, 
			whethercontain01, "FEATURES_BINARYOPERATOR");
}
 
Example 2
Source File: ConditionRemoveTransform.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
@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();
	}
}
 
Example 3
Source File: ExpressionTransform.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
@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();
	}
}
 
Example 4
Source File: BinaryOperatorAnalyzer.java    From coming with MIT License 5 votes vote down vote up
private void analyzeBinaryLogicalOperator(CtBinaryOperator operatorunderstudy, int operatorindex, Cntx<Object> context) {
	
	boolean whethercontainnotoperator = false;
	
	BinaryOperatorKind operatorkind = operatorunderstudy.getKind();

	if(logicalOperator.contains(operatorkind)) {
		
		CtExpression leftexpression = operatorunderstudy.getLeftHandOperand();
		CtExpression rightexpression = operatorunderstudy.getRightHandOperand();
				
		List<CtBinaryOperator> logicalOperatorLeft = leftexpression.getElements(
		  e -> e instanceof CtBinaryOperator && logicalOperator.contains(((CtBinaryOperator) e).getKind()));
		
		List<CtBinaryOperator> logicalOperatorRight = rightexpression.getElements(
				  e -> e instanceof CtBinaryOperator && logicalOperator.contains(((CtBinaryOperator) e).getKind()));
		
		if(logicalOperatorLeft.size() == 0) {	
			if(scannotoperator(leftexpression))
				whethercontainnotoperator=true;
		}
			
		if(!whethercontainnotoperator && logicalOperatorRight.size() == 0)	{
			if(scannotoperator(rightexpression))
				whethercontainnotoperator=true;
		}
	}
	
	writeGroupedInfo(context, Integer.toString(operatorindex)+"_"+operatorunderstudy, CodeFeatures.O2_LOGICAL_CONTAIN_NOT, 
			whethercontainnotoperator, "FEATURES_BINARYOPERATOR");
	
}
 
Example 5
Source File: LogicRedOperator.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
private List<Ingredient> computeIngredientsFromOperatorToReduce(ModificationPoint modificationPoint,
		CtBinaryOperator binaryToReduce) {

	List<Ingredient> ingredientsReducedExpressions = new ArrayList();

	CtExpression left = binaryToReduce.getLeftHandOperand();
	addOperator(ingredientsReducedExpressions, binaryToReduce, left);
	CtExpression right = binaryToReduce.getRightHandOperand();
	addOperator(ingredientsReducedExpressions, binaryToReduce, right);

	return ingredientsReducedExpressions;
}
 
Example 6
Source File: OperatorTransform.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
@Override
public <T> void visitCtBinaryOperator(CtBinaryOperator<T> operator) {
	super.visitCtBinaryOperator(operator);
	@SuppressWarnings("rawtypes")
	CtExpression left = operator.getLeftHandOperand();
	
	String typelefthand=left.getType().getQualifiedName();
	String typeoperator=operator.getType().getQualifiedName();
	typelefthand = typelefthand.replaceAll("\\d","");
	typeoperator = typeoperator.replaceAll("\\d","");
	@SuppressWarnings("rawtypes")
	CtExpression exp = null;
	
	BinaryOperatorKind kind=operator.getKind();
	if(rop.contains(kind))
		exp = OperatorGenerator.fetchROP(operator, this.mutSupporter, this.modificationPoint, typelefthand, "ROP");
	else if(aop.contains(kind))
		exp = OperatorGenerator.fetchROP(operator, this.mutSupporter, this.modificationPoint, typeoperator, "AOP");
			
	if (exp != null)
		candidates.put(operator, exp);
	
	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();
	}
}
 
Example 7
Source File: BinaryOperatorAnalyzer.java    From coming with MIT License 3 votes vote down vote up
private void analyzeBinaryOperatorInvolveNull(CtBinaryOperator operatorunderstudy, int operatorindex, Cntx<Object> context) {
	
	boolean whethercontainnull = false; 
			
	CtExpression leftexpression = operatorunderstudy.getLeftHandOperand();
	CtExpression rightexpression = operatorunderstudy.getRightHandOperand();
	
	if(leftexpression.toString().trim().equals("null") || rightexpression.toString().trim().equals("null"))
		whethercontainnull = true;
	
	writeGroupedInfo(context, Integer.toString(operatorindex)+"_"+operatorunderstudy, CodeFeatures.O3_CONTAIN_NULL, 
			whethercontainnull, "FEATURES_BINARYOPERATOR");
	
}