• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java CtBinaryOperator类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: 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());
}
 
开发者ID:SpoonLabs,项目名称:spoon-examples,代码行数:48,代码来源:OnTheFlyTransfoTest.java


示例17: isCondRefWidgets

import spoon.reflect.code.CtBinaryOperator; //导入依赖的package包/类
private boolean isCondRefWidgets(CtExpression<?> expr) {
	ComponentsAction access = new ComponentsAction();
	if (expr instanceof CtInvocation) {// "Copy to clipboard".equals(label);(label.contains("Copy")
		CtInvocation<?> invoke = (CtInvocation<?>) expr;
		if (invoke.getExecutable() != null && access.isGetProperty(invoke.getExecutable().getSimpleName())) {
			return true;
		} else if (invoke.getTarget() != null && isCondRefWidgets(invoke.getTarget())) {
			return true;
		} else {
			List<CtExpression<?>> arguments = invoke.getArguments();
			for (CtExpression<?> arg : arguments) {
				if (arg != null) {
					if (isCondRefWidgets(arg)) {
						return true;
					}
				}
			}
		}
	} else if (expr instanceof CtVariableAccess) {
		CtVariableAccess<?> varAccess = (CtVariableAccess<?>) expr;
		if (evType.isComponent(varAccess.getType())) {
			return true;
		}
		Set<CtExpression<?>> defs = getVarDefs(varAccess);
		if (!defs.isEmpty()) {
			for (CtExpression<?> def : defs) {
				if (isCondRefWidgets(def)) {
					return true;
				}
			}
		}
	} else if (expr instanceof CtBinaryOperator) {
		// Verify if is isDeclaredInSourceCode
		CtBinaryOperator<?> op = (CtBinaryOperator<?>) expr;
		if (op.getKind().name().equals("INSTANCEOF")) {
			if (evType.isComponentRef(op.getRightHandOperand())) {
				return true;
			}
		} else if (isCondRefWidgets(op.getLeftHandOperand()) || isCondRefWidgets(op.getRightHandOperand())) {
			return true;
		}
	} else if (expr instanceof CtUnaryOperator) {
		CtUnaryOperator<?> unary = (CtUnaryOperator<?>) expr;
		if (evType.isComponentRef(unary.getOperand())) {
			return true;
		} else if (isCondRefWidgets(unary.getOperand())) {
			return true;
		}
	}else if (expr instanceof CtNewClass){//Check if this will not have a side effect
		CtNewClass newClass = (CtNewClass) expr;
		CtTypeReference type = newClass.getType();
		 if (evType.isComponent(type.getDeclaringType())) {
				return true;
		 }
	}

	return false;

}
 
开发者ID:diverse-project,项目名称:InspectorGuidget,代码行数:60,代码来源:Command.java


示例18: testM70ExpressionOperatorSpaceExpression

import spoon.reflect.code.CtBinaryOperator; //导入依赖的package包/类
/**
 * This test uses a new ingredient space specially created to manage
 * expressions.
 * 
 * @throws Exception
 */
@Test
public void testM70ExpressionOperatorSpaceExpression() throws Exception {

	CommandSummary command = MathCommandsTests.getMath70Command();
	command.command.put("-parameters",
			ExtensionPoints.INGREDIENT_PROCESSOR.identifier + File.pathSeparator
					+ ExpressionIngredientSpaceProcessor.class.getCanonicalName() + File.pathSeparator
					+ "applytemplates:false");
	command.command.put("-maxgen", "0");// Avoid evolution
	command.command.put("-customop", ExpressionReplaceOperator.class.getName());
	command.command.put("-scope", ExpressionTypeIngredientSpace.class.getName());

	AstorMain main1 = new AstorMain();
	main1.execute(command.flat());

	List<ProgramVariant> variantss = main1.getEngine().getVariants();
	assertTrue(variantss.size() > 0);

	JGenProg engine = (JGenProg) main1.getEngine();
	ModificationPoint modificationPoint = variantss.get(0).getModificationPoints().get(14);

	assertEquals("i < (maximalIterationCount)", modificationPoint.getCodeElement().toString());

	// Let's inspect the ingredient space:
	ExpressionTypeIngredientSpace ingredientSpace = (ExpressionTypeIngredientSpace) engine.getIngredientStrategy()
			.getIngredientSpace();
	assertNotNull(ingredientSpace);
	assertTrue(ExpressionTypeIngredientSpace.class.isInstance(ingredientSpace));

	log.debug("keys: \n" + ingredientSpace.getLocations());

	log.debug("Ingredient \n:" + ingredientSpace.getAllIngredients());

	// Let's test the creation of a operator instance.
	OperatorInstance opInstance = engine.createOperatorInstanceForPoint(modificationPoint);

	assertNotNull(opInstance);
	assertEquals(ExpressionReplaceOperator.class.getName(), opInstance.getOperationApplied().getClass().getName());

	assertNotNull("Operator replacement needs an ingredient", opInstance.getModified());

	log.debug("Op instance created " + opInstance);
	log.debug("Op instance Ingredient:  " + opInstance.getModified());

	assertTrue(CtBinaryOperator.class.isInstance(opInstance.getOriginal()));
	log.debug("\n Type ingredient: " + ((CtBinaryOperator) opInstance.getOriginal()).getType());
	assertTrue(CtBinaryOperator.class.isInstance(opInstance.getModified()));

	CtBinaryOperator binOpIngredient = (CtBinaryOperator) opInstance.getModified();
	log.debug("\n Type ingredient: " + binOpIngredient.getType());

	assertEquals(((CtBinaryOperator) opInstance.getOriginal()).getType(), binOpIngredient.getType());

	List<CtCodeElement> ingredients = ingredientSpace.getIngredients(opInstance.getOriginal(),
			ExpressionReplaceOperator.class.getName());

	// let's check all ingredients
	for (CtCodeElement ingredient : ingredients) {
		assertTrue(CtBinaryOperator.class.isInstance(ingredient));
		assertEquals(((CtBinaryOperator) opInstance.getOriginal()).getType(),
				((CtBinaryOperator) ingredient).getType());
	}

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


示例19: testM70ExpressionOperator

import spoon.reflect.code.CtBinaryOperator; //导入依赖的package包/类
/**
 * This test checks if it works fine a new operator that works at the
 * expression level.
 * 
 * @throws Exception
 */
@Test
public void testM70ExpressionOperator() throws Exception {

	CommandSummary command = MathCommandsTests.getMath70Command();
	command.command.put("-parameters",
			ExtensionPoints.INGREDIENT_PROCESSOR.identifier + File.pathSeparator
					+ ExpressionIngredientSpaceProcessor.class.getCanonicalName() + File.pathSeparator
					+ "applytemplates:false");
	command.command.put("-maxgen", "0");// Avoid evolution
	command.command.put("-customop", ExpressionReplaceOperator.class.getName());

	AstorMain main1 = new AstorMain();
	main1.execute(command.flat());

	List<ProgramVariant> variantss = main1.getEngine().getVariants();
	assertTrue(variantss.size() > 0);

	JGenProg engine = (JGenProg) main1.getEngine();
	ModificationPoint modificationPoint = variantss.get(0).getModificationPoints().get(14);

	assertEquals("i < (maximalIterationCount)", modificationPoint.getCodeElement().toString());

	// Let's test the creation of a operator instance.
	OperatorInstance opInstance = engine.createOperatorInstanceForPoint(modificationPoint);

	assertNotNull(opInstance);
	assertEquals(ExpressionReplaceOperator.class.getName(), opInstance.getOperationApplied().getClass().getName());

	assertNotNull("Operator replacement needs an ingredient", opInstance.getModified());

	log.debug("Op instance created " + opInstance);
	log.debug("Op instance Ingredient:  " + opInstance.getModified());

	// Let's inspect the ingredient space:
	AstorCtIngredientSpace ingredientSpace = (AstorCtIngredientSpace) engine.getIngredientStrategy()
			.getIngredientSpace();
	assertNotNull(ingredientSpace);

	assertTrue(CtBinaryOperator.class.isInstance(opInstance.getOriginal()));
	log.debug("\n Type ingredient: " + ((CtBinaryOperator) opInstance.getOriginal()).getType());
	assertTrue(CtBinaryOperator.class.isInstance(opInstance.getModified()));

	CtBinaryOperator binOpIngredient = (CtBinaryOperator) opInstance.getModified();
	log.debug("\n Type ingredient: " + binOpIngredient.getType());

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


示例20: testM70ExpressionAsModificationPoint

import spoon.reflect.code.CtBinaryOperator; //导入依赖的package包/类
/**
 * This test checks if astor is able to manipulate expression as element in
 * a modification point
 * 
 * @throws Exception
 */
@Test
public void testM70ExpressionAsModificationPoint() throws Exception {

	CommandSummary command = MathCommandsTests.getMath70Command();
	command.command.put("-parameters",
			ExtensionPoints.INGREDIENT_PROCESSOR.identifier + File.pathSeparator
					+ ExpressionIngredientSpaceProcessor.class.getCanonicalName() + File.pathSeparator
					+ "applytemplates:false");
	command.command.put("-maxgen", "0");// Avoid evolution

	AstorMain main1 = new AstorMain();
	main1.execute(command.flat());

	List<ProgramVariant> variantss = main1.getEngine().getVariants();
	assertTrue(variantss.size() > 0);

	JGenProg jgp = (JGenProg) main1.getEngine();
	AstorIngredientSpace ingSpace = (AstorIngredientSpace) jgp.getIngredientStrategy().getIngredientSpace();

	int i = 0;
	for (ModificationPoint modpoint : variantss.get(0).getModificationPoints()) {
		System.out.println("--> " + (i++) + " " + modpoint.getCodeElement());

	}
	ModificationPoint modificationPoint = variantss.get(0).getModificationPoints().get(14);
	CtExpression originalExp = (CtExpression) modificationPoint.getCodeElement();
	assertEquals("i < (maximalIterationCount)", originalExp.toString());
	CtClass parentClass = originalExp.getParent(CtClass.class);
	String parentClassString = parentClass.toString();

	assertNotNull(parentClass);
	// Let's mutate the expression
	CtExpression clonedExp = (CtExpression) MutationSupporter.clone(originalExp);
	CtBinaryOperator binOpExpr = (CtBinaryOperator) clonedExp;
	// Let's check that the operator that will be inserted is not equal to
	// the current.
	assertNotEquals(BinaryOperatorKind.GT, binOpExpr.getKind());
	// Update operator
	binOpExpr.setKind(BinaryOperatorKind.GT);

	ExpressionReplaceOperator expOperator = new ExpressionReplaceOperator();
	OperatorInstance expOperatorInstance = new OperatorInstance(modificationPoint, expOperator, originalExp,
			clonedExp);

	boolean applied = expOperatorInstance.applyModification();
	assertTrue(applied);

	assertNotEquals(clonedExp, originalExp);
	assertEquals("i > (maximalIterationCount)", clonedExp.toString());
	assertEquals("i > (maximalIterationCount)", modificationPoint.getCodeElement().toString());

	// Let's check that the mutated class is different to the original
	String mutatedClassString = parentClass.toString();
	assertNotEquals(parentClassString, mutatedClassString);

	// Undo operator, we should have the original class
	boolean undo = expOperatorInstance.undoModification();
	String revertedChangeClassString = parentClass.toString();
	assertTrue(undo);
	assertEquals("i < (maximalIterationCount)", modificationPoint.getCodeElement().toString());

	assertEquals(parentClassString, revertedChangeClassString);

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



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java AppLocal类代码示例发布时间:2022-05-23
下一篇:
Java SchedulerAppUtils类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap