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


Java CtReturn.setReturnedExpression方法代码示例

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


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

示例1: buildReplacementElement

import spoon.reflect.code.CtReturn; //导入方法依赖的package包/类
protected CtElement buildReplacementElement() {
    Factory factory = transplantationPoint.getFactory();
    CtMethod newMethod = factory.Core().clone(transplantationPoint);

    newMethod.setAnnotations(new ArrayList<CtAnnotation<? extends Annotation>>());

    CtBlock body = factory.Core().createBlock();
    body.setParent(newMethod);

    String type = newMethod.getType().getSimpleName();
    if(!(type.equals("void") || type.equals("Void"))) {
        CtReturn ret = factory.Core().createReturn();
        ret.setParent(body);
        body.addStatement(ret);

        CtCodeSnippetExpression<Object> voidValue = factory.Core().createCodeSnippetExpression();
        voidValue.setValue("null");

        ret.setReturnedExpression(voidValue);

    }
    newMethod.setBody(body);

    return newMethod;
}
 
开发者ID:DIVERSIFY-project,项目名称:sosiefier,代码行数:26,代码来源:EmptyMethodBody.java

示例2: applyMono

import spoon.reflect.code.CtReturn; //导入方法依赖的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

示例3: createReturn

import spoon.reflect.code.CtReturn; //导入方法依赖的package包/类
@SuppressWarnings({ "rawtypes", "unchecked", "static-access" })
private CtElement createReturn(CtElement rootElement) {
	CtMethod method = rootElement.getParent(CtMethod.class);

	if (method == null) {
		log.info("Element without method parent");
		return null;
	}
	// We create the "if(true)"{}
	CtIf ifReturn = MutationSupporter.getFactory().Core().createIf();
	CtExpression ifTrueExpression = MutationSupporter.getFactory().Code()
			.createCodeSnippetExpression("true");
	ifReturn.setCondition(ifTrueExpression);

	// Now we create the return statement
	CtReturn<?> returnStatement = null;
	CtTypeReference typeR = method.getType();
	if (typeR == null || "void".equals(typeR.getSimpleName())) {
		returnStatement = MutationSupporter.getFactory().Core().createReturn();
	} else {
		String codeExpression = "";
		if (prim.contains(typeR.getSimpleName())) {
			codeExpression = getZeroValue(typeR.getSimpleName().toLowerCase());
		} else if(typeR.getSimpleName().toLowerCase().equals("boolean")){
			codeExpression = "false";
		} else {
			codeExpression = "null";
		}
		CtExpression returnExpression = MutationSupporter.getFactory().Code()
				.createCodeSnippetExpression(codeExpression);
		returnStatement = MutationSupporter.getFactory().Core().createReturn();
		returnStatement.setReturnedExpression(returnExpression);
	}
	// Now, we associate if(true){return [...]}
	ifReturn.setThenStatement(returnStatement);
	return ifReturn;

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


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