当前位置: 首页>>代码示例>>Java>>正文


Java CtBinaryOperator类代码示例

本文整理汇总了Java中spoon.reflect.code.CtBinaryOperator的典型用法代码示例。如果您正苦于以下问题:Java CtBinaryOperator类的具体用法?Java CtBinaryOperator怎么用?Java CtBinaryOperator使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


CtBinaryOperator类属于spoon.reflect.code包,在下文中一共展示了CtBinaryOperator类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getInstanceOfCommands

import spoon.reflect.code.CtBinaryOperator; //导入依赖的package包/类
public List<Action> getInstanceOfCommands(List<Action> cmds) {
	List<Action> candidates = new ArrayList<>();

	for (Action action : cmds) {
		List<CtExpression<?>> conditions = action.getConditions();
		for (CtExpression<?> cond : conditions) {
			if (cond instanceof CtBinaryOperator) {
				CtBinaryOperator<?> operator = (CtBinaryOperator<?>) cond;
				if (operator.toString().contains("instanceof")) {
					candidates.add(action);
				}
			}
		}
	}
	return candidates;
}
 
开发者ID:diverse-project,项目名称:InspectorGuidget,代码行数:17,代码来源:Command.java

示例2: createEqExpressionFromSwitchCase

import spoon.reflect.code.CtBinaryOperator; //导入依赖的package包/类
public CtExpression<Boolean> createEqExpressionFromSwitchCase(final @NotNull CtSwitch<?> switchStat, final @NotNull CtCase<?> caze) {
	if(caze.getCaseExpression() == null) {// i.e. default case
		return switchStat.getCases().stream().filter(c -> c.getCaseExpression() != null).
			map(c -> negBoolExpression(createEqExpressionFromSwitchCase(switchStat, c))).reduce((a, b) -> andBoolExpression(a, b, false)).
			orElseGet(() -> switchStat.getFactory().Code().createLiteral(Boolean.TRUE));
	}

	CtBinaryOperator<Boolean> exp = switchStat.getFactory().Core().createBinaryOperator();
	// A switch is an equality test against values
	exp.setKind(BinaryOperatorKind.EQ);
	// The tested object
	exp.setLeftHandOperand(switchStat.getSelector().clone());
	// The tested constant
	exp.setRightHandOperand(caze.getCaseExpression().clone());

	return exp;
}
 
开发者ID:diverse-project,项目名称:InspectorGuidget,代码行数:18,代码来源:SpoonHelper.java

示例3: applyMono

import spoon.reflect.code.CtBinaryOperator; //导入依赖的package包/类
public void applyMono(CodeFragment tp) throws Exception {
    transplantationPoint = tp;
    Factory factory = getInputProgram().getFactory();
    CtTypeReference tInt = factory.Type().INTEGER_PRIMITIVE;
    CtLiteral one = factory.Core().createLiteral();
    one.setValue(1);
    CtReturn retStmt = (CtReturn) tp.getCtCodeFragment();

    CtBinaryOperator retExpression = factory.Core().createBinaryOperator();
    retExpression.setKind(BinaryOperatorKind.MUL);
    retExpression.setRightHandOperand(retStmt.getReturnedExpression());
    retExpression.setLeftHandOperand(one);

    multiply = retExpression;
    CtReturn retStmt2 = (CtReturn) factory.Core().clone(tp.getCtCodeFragment());
    retStmt2.setReturnedExpression(retExpression);
    tp.getCtCodeFragment().replace(retStmt2);
}
 
开发者ID:DIVERSIFY-project,项目名称:sosiefier,代码行数:19,代码来源:MultiplyByOne.java

示例4: addRemainings

import spoon.reflect.code.CtBinaryOperator; //导入依赖的package包/类
/**
 * Creates alternatives Expressions (Binary Operations) given a list of
 * Binary operators kind operators. The original kind (that one included in
 * the original expression is not analyzed)
 * 
 * @param result
 * @param op
 * @param kind
 * @param operators
 */
protected void addRemainings(List<CtExpression> result,
		CtBinaryOperator<?> op, BinaryOperatorKind kind,
		List<BinaryOperatorKind> operators) {
	// TODO: recursive?
	if (operators.contains(kind)) {
		for (BinaryOperatorKind binaryOperatorKind : operators) {
			if (binaryOperatorKind != kind) {
				// Cloning
				CtExpression right = factory.Core().clone(
						op.getRightHandOperand());
				CtExpression left = factory.Core().clone(
						op.getLeftHandOperand());

				CtBinaryOperator binaryOp = factory.Code()
						.createBinaryOperator(left, right,
								binaryOperatorKind);
				// Set parent
				right.setParent(binaryOp);
				left.setParent(binaryOp);

				result.add(binaryOp);
			}
		}
	}
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:36,代码来源:BinaryOperatorMutator.java

示例5: getExpressions

import spoon.reflect.code.CtBinaryOperator; //导入依赖的package包/类
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;
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:24,代码来源:ExpressionRevolver.java

示例6: test_t_214116

import spoon.reflect.code.CtBinaryOperator; //导入依赖的package包/类
@Test
public void test_t_214116() throws Exception{
	AstComparator diff = new AstComparator();
	// meld  src/test/resources/examples/t_214116/left_Modeller_1.134.java src/test/resources/examples/t_214116/right_Modeller_1.135.java
	File fl = new File("src/test/resources/examples/t_214116/left_Modeller_1.134.java");
	File fr = new File("src/test/resources/examples/t_214116/right_Modeller_1.135.java");
	Diff result = diff.compare(fl,fr);

	CtElement ancestor = result.commonAncestor();
	assertTrue(ancestor instanceof CtBinaryOperator);


	List<Operation> actions = result.getRootOperations();
	//result.debugInformation();
	assertEquals(actions.size(), 2);
	assertTrue(result.containsOperation(OperationKind.Update, "Literal", "\" \""));

	// the change is in a throw
	CtElement elem = actions.get(0).getNode();
	assertNotNull(elem);
	assertNotNull(elem.getParent(CtThrow.class));

}
 
开发者ID:SpoonLabs,项目名称:gumtree-spoon-ast-diff,代码行数:24,代码来源:AstComparatorTest.java

示例7: test_t_224512

import spoon.reflect.code.CtBinaryOperator; //导入依赖的package包/类
@Test
public void test_t_224512() throws Exception{
	AstComparator diff = new AstComparator();
	// meld  src/test/resources/examples/t_224512/left_Server_1.925.java src/test/resources/examples/t_224512/right_Server_1.926.java
	File fl = new File("src/test/resources/examples/t_224512/left_Server_1.925.java");
	File fr = new File("src/test/resources/examples/t_224512/right_Server_1.926.java");
	Diff result = diff.compare(fl,fr);

	CtElement ancestor = result.commonAncestor();
	assertTrue(ancestor instanceof CtBinaryOperator);

	List<Operation> actions = result.getRootOperations();
	result.debugInformation();
	assertEquals(actions.size(), 2);
	assertTrue(result.containsOperation(OperationKind.Insert, "BinaryOperator", "AND"));
	assertTrue(result.containsOperation(OperationKind.Move, "BinaryOperator", "AND"));
}
 
开发者ID:SpoonLabs,项目名称:gumtree-spoon-ast-diff,代码行数:18,代码来源:AstComparatorTest.java

示例8: process

import spoon.reflect.code.CtBinaryOperator; //导入依赖的package包/类
@Override
public void process(CtElement candidate) {
	if (!(candidate instanceof CtBinaryOperator)) {
		return;
	}
	CtBinaryOperator op = (CtBinaryOperator)candidate;
	op.setKind(BinaryOperatorKind.MINUS);
}
 
开发者ID:SpoonLabs,项目名称:spoon-examples,代码行数:9,代码来源:BinaryOperatorMutator.java

示例9: findUsedVar

import spoon.reflect.code.CtBinaryOperator; //导入依赖的package包/类
/**
 * Get used variables in this expression. If the expression is a method
 * call, the caller is included in used variables
 */
public List<CtVariableAccess<?>> findUsedVar(CtExpression<?> expr) {
	List<CtVariableAccess<?>> res = new ArrayList<>();

	if (expr instanceof CtFieldAccess) {
		CtFieldAccess<?> access = (CtFieldAccess<?>) expr;
		if (access.getTarget() != null) {
			res.addAll(findUsedVar(access.getTarget()));
		} else {
			res.add(access);
		}
	} else if (expr instanceof CtBinaryOperator) {
		CtBinaryOperator<?> op = (CtBinaryOperator<?>) expr;
		res.addAll(findUsedVar(op.getLeftHandOperand()));
		res.addAll(findUsedVar(op.getRightHandOperand()));
	} else if (expr instanceof CtUnaryOperator) {// Added to get all
													// conditions of a
													// command in Command
													// class
		CtUnaryOperator<?> unary = (CtUnaryOperator<?>) expr;
		res.addAll(findUsedVar(unary.getOperand()));
	} else if (expr instanceof CtInvocation) {
		CtInvocation<?> invoke = (CtInvocation<?>) expr;
		res.addAll(findUsedVar(invoke.getTarget()));
		for (Object param : invoke.getArguments()) {
			res.addAll(findUsedVar((CtExpression<?>) param));
		}
	} else if (expr instanceof CtVariableAccess) {
		res.add((CtVariableAccess<?>) expr);
	}

	return res;
}
 
开发者ID:diverse-project,项目名称:InspectorGuidget,代码行数:37,代码来源:DefUse.java

示例10: andBoolExpression

import spoon.reflect.code.CtBinaryOperator; //导入依赖的package包/类
public CtExpression<Boolean> andBoolExpression(final @NotNull CtExpression<Boolean> exp1, final @NotNull CtExpression<Boolean> exp2, final boolean clone) {
	final CtBinaryOperator<Boolean> and = exp1.getFactory().Core().createBinaryOperator();
	and.setKind(BinaryOperatorKind.AND);

	if(clone) {
		and.setLeftHandOperand(exp1.clone());
		and.setRightHandOperand(exp2.clone());
	}else {
		and.setLeftHandOperand(exp1);
		and.setRightHandOperand(exp2);
	}
	return and;
}
 
开发者ID:diverse-project,项目名称:InspectorGuidget,代码行数:14,代码来源:SpoonHelper.java

示例11: testClassListenerSwitchDefault

import spoon.reflect.code.CtBinaryOperator; //导入依赖的package包/类
@Test
public void testClassListenerSwitchDefault() {
	analyser.addInputResource("src/test/resources/java/analysers/ActionListenerCondSwitchDefault.java");
	analyser.run();
	assertEquals(1, analyser.getCommands().values().size());
	assertEquals(1L, analyser.getCommands().values().stream().mapToLong(c -> c.getNbTotalCmds()).sum());
	assertTrue(analyser.getCommands().values().iterator().next().getCommands().iterator().next().getConditions().get(0).effectiveStatmt instanceof CtBinaryOperator);
}
 
开发者ID:diverse-project,项目名称:InspectorGuidget,代码行数:9,代码来源:TestCommandAnalyser.java

示例12: createBinaryOp

import spoon.reflect.code.CtBinaryOperator; //导入依赖的package包/类
private CtBinaryOperator createBinaryOp(
		CtBinaryOperator<?> op, BinaryOperatorKind binaryOperatorKind,
		CtExpression left_i, CtExpression right_i) {
	CtExpression right_c = factory.Core().clone(right_i);
	CtExpression left_c = factory.Core().clone(left_i);

	CtBinaryOperator binaryOp = factory.Code()
			.createBinaryOperator(left_c, right_c,
					binaryOperatorKind);
	// Set parent
	right_c.setParent(binaryOp);
	left_c.setParent(binaryOp);
	return binaryOp;

}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:16,代码来源:BinaryOperatorMutator.java

示例13: execute

import spoon.reflect.code.CtBinaryOperator; //导入依赖的package包/类
public List<MutantCtElement> execute(CtElement toMutate) {

		// List<CtExpression> result = new ArrayList<CtExpression>();
		List<MutantCtElement> result = new ArrayList<MutantCtElement>();

		if (toMutate instanceof CtBinaryOperator<?>) {
			CtBinaryOperator<?> op = (CtBinaryOperator<?>) toMutate;
			BinaryOperatorKind kind = op.getKind();

			addRemainingsAndFoward(result, op, operators1);

		}
		return result;
	}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:15,代码来源:LogicalBinaryOperatorMutator.java

示例14: newComposedExpression

import spoon.reflect.code.CtBinaryOperator; //导入依赖的package包/类
public static <T> CtExpression<T> newComposedExpression(Factory factory, CtExpression<T> leftExpression, CtExpression<T> rightExpression, BinaryOperatorKind operator) {
    CtBinaryOperator<T> composedExpression = factory.Code().createBinaryOperator(leftExpression, rightExpression, operator);
    setParent(composedExpression, leftExpression, rightExpression);
    return composedExpression;
}
 
开发者ID:SpoonLabs,项目名称:nopol,代码行数:6,代码来源:SpoonModelLibrary.java

示例15: isToBeProcessed

import spoon.reflect.code.CtBinaryOperator; //导入依赖的package包/类
@Override
public boolean isToBeProcessed(CtElement candidate) {
	return candidate instanceof CtBinaryOperator;
}
 
开发者ID:SpoonLabs,项目名称:spoon-examples,代码行数:5,代码来源:BinaryOperatorMutator.java


注:本文中的spoon.reflect.code.CtBinaryOperator类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。