本文整理汇总了Java中spoon.reflect.code.CtBinaryOperator.getKind方法的典型用法代码示例。如果您正苦于以下问题:Java CtBinaryOperator.getKind方法的具体用法?Java CtBinaryOperator.getKind怎么用?Java CtBinaryOperator.getKind使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类spoon.reflect.code.CtBinaryOperator
的用法示例。
在下文中一共展示了CtBinaryOperator.getKind方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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;
}
示例2: example
import spoon.reflect.code.CtBinaryOperator; //导入方法依赖的package包/类
@Test
public void example() throws Exception {
Launcher l = new Launcher();
// required for having IFoo.class in the classpath in Maven
l.setArgs(new String[] {"--source-classpath","target/test-classes"});
l.addInputResource("src/test/resources/transformation/");
l.buildModel();
CtClass foo = l.getFactory().Package().getRootPackage().getElements(new NamedElementFilter<>(CtClass.class, "Foo1")).get(0);
// compiling and testing the initial class
Class<?> fooClass = InMemoryJavaCompiler.newInstance().compile(foo.getQualifiedName(), "package "+foo.getPackage().getQualifiedName()+";"+foo.toString());
IFoo x = (IFoo) fooClass.newInstance();
// testing its behavior
assertEquals(5, x.m());
// now we apply a transformation
// we replace "+" by "-"
for(Object e : foo.getElements(new TypeFilter(CtBinaryOperator.class))) {
CtBinaryOperator op = (CtBinaryOperator)e;
if (op.getKind()==BinaryOperatorKind.PLUS) {
op.setKind(BinaryOperatorKind.MINUS);
}
}
// first assertion on the results of the transfo
// there are no more additions in the code
assertEquals(0, foo.getElements(new Filter<CtBinaryOperator<?>>() {
@Override
public boolean matches(CtBinaryOperator<?> arg0) {
return arg0.getKind()==BinaryOperatorKind.PLUS;
}
}).size());
// second assertions on the behavior of the transformed code
// compiling and testing the transformed class
fooClass = InMemoryJavaCompiler.newInstance().compile(foo.getQualifiedName(), "package "+foo.getPackage().getQualifiedName()+";"+foo.toString());
IFoo y = (IFoo) fooClass.newInstance();
// testing its behavior with subtraction
assertEquals(1, y.m());
System.out.println("yes y.m()="+y.m());
}