本文整理汇总了Java中spoon.reflect.code.CtReturn类的典型用法代码示例。如果您正苦于以下问题:Java CtReturn类的具体用法?Java CtReturn怎么用?Java CtReturn使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
CtReturn类属于spoon.reflect.code包,在下文中一共展示了CtReturn类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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;
}
示例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;
}
示例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);
}
示例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"));
}
示例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));
}
示例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));
}
示例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;
}
示例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;
}
示例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;
}
}
示例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;
}
示例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;
}
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
}