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

Java CtReturn类代码示例

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

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



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

示例1: isStopStatement

import spoon.reflect.code.CtReturn; //导入依赖的package包/类
private boolean isStopStatement(List<CtCodeElement> elements) {

		// if (elements.size() == 1 && elements.toString().contains("return")){
		// if (elements.get(0) instanceof CtReturn){
		// CtReturn ret = (CtReturn) elements.get(0);
		// if (ret.getReturnedExpression() == null){
		// return true;
		// }
		// }
		// }
		if (elements.size() == 1) {
			if (elements.toString().contains("return")) {
				if (elements.get(0) instanceof CtReturn) {
					CtReturn<?> ret = (CtReturn<?>) elements.get(0);
					if (ret.getReturnedExpression() == null) {
						return true;
					}
				}
			} else if (elements.toString().contains("break")) { // ||
																// elements.toString().contains("continue")){
				return true;
			}

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


示例2: 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


示例3: 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


示例4: test_t_204225

import spoon.reflect.code.CtReturn; //导入依赖的package包/类
@Test
public void test_t_204225() throws Exception{
	AstComparator diff = new AstComparator();
	// meld  src/test/resources/examples/t_204225/left_UMLModelElementStereotypeComboBoxModel_1.3.java src/test/resources/examples/t_204225/right_UMLModelElementStereotypeComboBoxModel_1.4.java
	File fl = new File("src/test/resources/examples/t_204225/left_UMLModelElementStereotypeComboBoxModel_1.3.java");
	File fr = new File("src/test/resources/examples/t_204225/right_UMLModelElementStereotypeComboBoxModel_1.4.java");
	Diff result = diff.compare(fl,fr);

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

	List<Operation> actions = result.getRootOperations();
	//result.debugInformation();
	assertEquals(actions.size(), 2);
	assertTrue(result.containsOperation(OperationKind.Insert, "BinaryOperator", "OR"));
	assertTrue(result.containsOperation(OperationKind.Move, "BinaryOperator", "AND"));


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


示例5: test_t_221295

import spoon.reflect.code.CtReturn; //导入依赖的package包/类
@Test
public void test_t_221295() throws Exception{
	AstComparator diff = new AstComparator();
	// meld  src/test/resources/examples/t_221295/left_Board_1.5.java src/test/resources/examples/t_221295/right_Board_1.6.java
	File fl = new File("src/test/resources/examples/t_221295/left_Board_1.5.java");
	File fr = new File("src/test/resources/examples/t_221295/right_Board_1.6.java");
	Diff result = diff.compare(fl,fr);

	List<Operation> actions = result.getRootOperations();
	result.debugInformation();
	assertEquals(actions.size(), 1);
	assertTrue(result.containsOperation(OperationKind.Update, "BinaryOperator", "GT"));

	CtElement elem = actions.get(0).getNode();
	assertNotNull(elem);
	assertNotNull(elem.getParent(CtReturn.class));

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


示例6: test_t_221958

import spoon.reflect.code.CtReturn; //导入依赖的package包/类
@Test
public void test_t_221958() throws Exception{
	AstComparator diff = new AstComparator();
	// meld  src/test/resources/examples/t_221958/left_TilesetManager_1.22.java src/test/resources/examples/t_221958/right_TilesetManager_1.23.java
	File fl = new File("src/test/resources/examples/t_221958/left_TilesetManager_1.22.java");
	File fr = new File("src/test/resources/examples/t_221958/right_TilesetManager_1.23.java");
	Diff result = diff.compare(fl,fr);

	List<Operation> actions = result.getRootOperations();
	result.debugInformation();
	assertEquals(actions.size(), 1);
	assertTrue(result.containsOperation(OperationKind.Insert, "Literal", "null"));

	CtElement elem = actions.get(0).getNode();
	assertNotNull(elem);
	assertNotNull(elem.getParent(CtReturn.class));

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


示例7: isGetter

import spoon.reflect.code.CtReturn; //导入依赖的package包/类
public static boolean isGetter(CtMethod<?> method) {
    if (hasNoArguments(method) && numberOfStatements(method) == 1) {
        CtStatement statement = lastStatementOf(method);
        return isReturnStatement(statement) && isFieldAccess(((CtReturn<?>) statement).getReturnedExpression());
    }
    return false;
}
 
开发者ID:SpoonLabs,项目名称:nopol,代码行数:8,代码来源:SpoonMethodLibrary.java


示例8: returnStatementsIn

import spoon.reflect.code.CtReturn; //导入依赖的package包/类
public static Collection<CtReturn<?>> returnStatementsIn(CtLoop loop) {
    List<CtReturn<?>> returnsOfLoop = MetaList.newArrayList();
    List<CtReturn<?>> allReturns = (List) allChildrenOf(loop, CtReturn.class);
    for (CtReturn<?> candidateReturn : allReturns) {
        if (isReturningFrom(loop, candidateReturn)) {
            returnsOfLoop.add(candidateReturn);
        }
    }
    return returnsOfLoop;
}
 
开发者ID:SpoonLabs,项目名称:nopol,代码行数:11,代码来源:SpoonLoopLibrary.java


示例9: containsOnlyReturn

import spoon.reflect.code.CtReturn; //导入依赖的package包/类
protected boolean containsOnlyReturn(CtStatement stmt) {
    if(stmt instanceof CtStatementList) {
        CtStatementList list = (CtStatementList) stmt;
        return list.getStatements().size() == 1 && list.getStatements().get(0) instanceof CtReturn;
    } else {
        return stmt instanceof CtReturn;
    }
}
 
开发者ID:DIVERSIFY-project,项目名称:sosiefier,代码行数:9,代码来源:JsonRemoveParameterConditionInput.java


示例10: getAllDelete

import spoon.reflect.code.CtReturn; //导入依赖的package包/类
public Set<ASTTransformation> getAllDelete(CodeFragment codeFragment) {
    Set<ASTTransformation> allDelete = new HashSet<>();

    if (!(codeFragment.getCtCodeFragment() instanceof CtReturn)
            && !(codeFragment.getCtCodeFragment() instanceof CtLocalVariable)) {
        ASTDelete delete = new ASTDelete();
        delete.setTransplantationPoint(codeFragment);
        allDelete.add(delete);
    }

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


示例11: nbAllDelete

import spoon.reflect.code.CtReturn; //导入依赖的package包/类
public int nbAllDelete(CodeFragment codeFragment) {

        if (!(codeFragment.getCtCodeFragment() instanceof CtReturn)
                && !(codeFragment.getCtCodeFragment() instanceof CtLocalVariable)) {
           return 1;
        } else {
            return 0;
        }
    }
 
开发者ID:DIVERSIFY-project,项目名称:sosiefier,代码行数:10,代码来源:ASTTransformationSearchSpace.java


示例12: delete

import spoon.reflect.code.CtReturn; //导入依赖的package包/类
protected ASTDelete delete() throws Exception {
    ASTDelete tf = new ASTDelete();
    CodeFragment transplantationPoint = null;

    while (transplantationPoint == null) {
        transplantationPoint = findRandomFragment(true);
        if (transplantationPoint.getCtCodeFragment() instanceof CtReturn
                || transplantationPoint.getCtCodeFragment() instanceof CtLocalVariable)
            transplantationPoint = null;
    }
    tf.setTransplantationPoint(transplantationPoint);

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


示例13: isReturnInt

import spoon.reflect.code.CtReturn; //导入依赖的package包/类
protected boolean isReturnInt(CtElement stmt) {
    if (stmt instanceof CtReturn) {
        CtReturn ret = (CtReturn) stmt;
        if(ret.getReturnedExpression() != null) {
            try {
                if (ret.getReturnedExpression().getType().getActualClass() == int.class) return true;
            } catch (Exception e) {

            }
        }

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


示例14: allHashCodeTransformation

import spoon.reflect.code.CtReturn; //导入依赖的package包/类
protected List<Transformation> allHashCodeTransformation(boolean withCoverage) {
    List<Transformation> hashCodeTransformation = new ArrayList<>();

    for(CodeFragment stmt : allCodeFragmentInHasCode(withCoverage)) {
        for(CodeFragment stmt2: findCandidate(stmt)) {
            for(Map<String, String> varMapping : getAllVarMapping(stmt, stmt2)) {
                ASTAdd add = new ASTAdd();
                add.setTransplantationPoint(stmt);
                add.setTransplant(stmt2);
                add.setVarMapping(varMapping);
                hashCodeTransformation.add(add);

                ASTReplace replace = new ASTReplace();
                replace.setTransplantationPoint(stmt);
                replace.setTransplant(stmt2);
                replace.setVarMapping(varMapping);
                hashCodeTransformation.add(replace);
            }
        }
        if(!(stmt.getCtCodeFragment() instanceof CtReturn)
                && !(stmt.getCtCodeFragment() instanceof CtLocalVariable)) {
            ASTDelete delete = new ASTDelete();
            delete.setTransplantationPoint(stmt);
            hashCodeTransformation.add(delete);
        }
    }
    return hashCodeTransformation;
}
 
开发者ID:DIVERSIFY-project,项目名称:sosiefier,代码行数:29,代码来源:HashCodeQuery.java


示例15: isToBeProcessed

import spoon.reflect.code.CtReturn; //导入依赖的package包/类
public boolean isToBeProcessed(CtReturn candidate) {
    try {
        CtLiteral literal = (CtLiteral)candidate.getReturnedExpression();
        String type = literal.getType().getSimpleName();
        return type.equals("boolean") || type.equals("short") ||
                type.equals("int") || type.equals("long") ||
                type.equals("byte") || type.equals("float") ||
                type.equals("double");

    } catch (Exception e) {
        return false;
    }
}
 
开发者ID:DIVERSIFY-project,项目名称:sosiefier,代码行数:14,代码来源:ReturnProcessor.java


示例16: canBeAppliedToPoint

import spoon.reflect.code.CtReturn; //导入依赖的package包/类
@Override
public boolean canBeAppliedToPoint(ModificationPoint point) {

	boolean apply = super.canBeAppliedToPoint(point);
	if (!apply)
		return apply;

	// do not insert after a return
	if (point.getCodeElement() instanceof CtReturn) {
		return false;
	}

	// Otherwise, accept the element
	return true;
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:16,代码来源:InsertAfterOp.java


示例17: canBeAppliedToPoint

import spoon.reflect.code.CtReturn; //导入依赖的package包/类
@Override
public boolean canBeAppliedToPoint(ModificationPoint point) {
	if (!(point.getCodeElement() instanceof CtStatement))
		return false;
	//Do not remove local declaration 
	if (point.getCodeElement() instanceof CtLocalVariable) {
		CtLocalVariable lv = (CtLocalVariable) point.getCodeElement();
		boolean shadow = false;
		CtClass parentC = point.getCodeElement().getParent(CtClass.class);
		List<CtField> ff = parentC.getFields();
		for (CtField<?> f : ff) {
			if (f.getSimpleName().equals(lv.getSimpleName()))
				shadow = true;
		}
		if (!shadow)
			return false;
	}
	//do not remove the last statement
	CtMethod parentMethd = point.getCodeElement().getParent(CtMethod.class);
	if(point.getCodeElement() instanceof CtReturn  
			&& parentMethd.getBody().getLastStatement().equals(point.getCodeElement())){
		return false;
	}
	
	
	//Otherwise, accept the element
	return true;
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:29,代码来源:RemoveOp.java


示例18: 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


示例19: isReturningFrom

import spoon.reflect.code.CtReturn; //导入依赖的package包/类
public static boolean isReturningFrom(CtLoop loop, CtReturn<?> returnStatement) {
    if (returnStatement.getParent(CtLoop.class) == loop) {
        return returnStatement.getParent(CtMethod.class) == loop.getParent(CtMethod.class);
    }
    return false;
}
 
开发者ID:SpoonLabs,项目名称:nopol,代码行数:7,代码来源:SpoonLoopLibrary.java


示例20: analyseSingleListenerMethod

import spoon.reflect.code.CtReturn; //导入依赖的package包/类
private void analyseSingleListenerMethod(final @NotNull  Optional<CtClass<?>> listenerClass,
										 final @NotNull CtExecutable<?> listenerMethod) {
	if((listenerMethod.getBody() == null || listenerMethod.getBody().getStatements().isEmpty()) &&
		(!(listenerMethod instanceof CtLambda) || ((CtLambda<?>)listenerMethod).getExpression() == null)) {// A lambda may not have a body but an expression
		// Empty so no command
		synchronized(commands) { commands.put(listenerMethod, new UIListener(listenerMethod)); }
	}else {
		final List<CtStatement> conds = getConditionalStatements(listenerMethod, listenerClass, new HashSet<>());

		if(conds.isEmpty()) {
			// when no conditional, the content of the method forms a command.
			UIListener list = new UIListener(listenerMethod);

			if(listenerMethod.getBody()==null && listenerMethod instanceof CtLambda<?>) {
				// It means it is a lambda
				list.addCommand(new Command(new CommandStatmtEntry(true, Collections.singletonList(((CtLambda<?>)listenerMethod).getExpression())),
					Collections.emptyList(), listenerMethod));
				synchronized(commands) { commands.put(listenerMethod, list); }
			} else {
				// It means it is a method
				list.addCommand(new Command(new CommandStatmtEntry(true, listenerMethod.getBody().getStatements()), Collections.emptyList(), listenerMethod));
				synchronized(commands) { commands.put(listenerMethod, list); }
			}
		}else {
			// For each conditional statements found in the listener method or in its dispatched methods,
			// a command is extracted.
			conds.forEach(cond -> extractCommandsFromConditionalStatements(cond, listenerMethod, conds));

			// Treating the potential code block located after the last conditional statement
			UIListener uiListener;

			synchronized(commands) {
				uiListener = commands.get(listenerMethod);
			}

			final List<Command> cmds = uiListener.getCommands();
			// Getting the line number of the last statement used in a command or in a conditional block.
			final int start = cmds.parallelStream().mapToInt(c -> c.getLineEnd()).max().orElseGet(() ->
						conds.parallelStream().mapToInt(c -> c.getPosition().getEndLine()).max().orElse(Integer.MAX_VALUE));
			// Getting the line code of the end of the listener method
			final int end = listenerMethod.getBody().getPosition().getEndLine();
			// Getting all the statements located in between the start and end code lines.
			// returns, throws and catch blocks are ignored.
			final List<CtStatement> finalBlock = listenerMethod.getBody().getElements(new LinePositionFilter(start, end)).
				parallelStream().filter(s -> SpoonHelper.INSTANCE.isRelevantCommandStatement(s, listenerMethod) && s.getParent(CtCatch.class)==null).
				collect(Collectors.toList());

			// If there is such statements.
			if(!finalBlock.isEmpty()) {
				// If all the commands have a return statement at their end, it means that this block will form another command.
				if(cmds.parallelStream().filter(c -> c.getMainStatmtEntry().isPresent()).map(c -> c.getMainStatmtEntry().get()).
					allMatch(c -> !c.statmts.isEmpty() && c.statmts.get(c.statmts.size() - 1) instanceof CtReturn)) {
					uiListener.addCommand(new Command(new CommandStatmtEntry(true, finalBlock), Collections.emptyList(), listenerMethod));
				}else {
					// If no command has a return statement at their end, it means that this block will be part of each of these
					// commands.
					if(cmds.parallelStream().filter(c -> c.getMainStatmtEntry().isPresent()).map(c -> c.getMainStatmtEntry().get()).
						noneMatch(c -> !c.statmts.isEmpty() && c.statmts.get(c.statmts.size() - 1) instanceof CtReturn)) {
						cmds.forEach(c -> c.addAllStatements(Collections.singletonList(new CommandStatmtEntry(false, finalBlock))));
					}
					// For the other case (some of the commands have a return but some others not), we cannot manage that.
				}
			}

			// Looking for a super call in the given listener
			identifyingSuperListenerCall(uiListener);
		}
	}
}
 
开发者ID:diverse-project,项目名称:InspectorGuidget,代码行数:70,代码来源:CommandAnalyser.java



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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