本文整理汇总了Java中spoon.reflect.code.CtThrow类的典型用法代码示例。如果您正苦于以下问题:Java CtThrow类的具体用法?Java CtThrow怎么用?Java CtThrow使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
CtThrow类属于spoon.reflect.code包,在下文中一共展示了CtThrow类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: process
import spoon.reflect.code.CtThrow; //导入依赖的package包/类
public void process(Bound annotation, CtParameter<?> element) {
final CtMethod parent = element.getParent(CtMethod.class);
// Build if check for min.
CtIf anIf = getFactory().Core().createIf();
anIf.setCondition(getFactory().Code().<Boolean>createCodeSnippetExpression(element.getSimpleName() + " < " + annotation.min()));
CtThrow throwStmt = getFactory().Core().createThrow();
throwStmt.setThrownExpression((CtExpression<? extends Throwable>) getFactory().Core().createCodeSnippetExpression().setValue("new RuntimeException(\"out of min bound (\" + " + element.getSimpleName() + " + \" < " + annotation.min() + "\")"));
anIf.setThenStatement(throwStmt);
parent.getBody().insertBegin(anIf);
anIf.setParent(parent);
// Build if check for max.
anIf = getFactory().Core().createIf();
anIf.setCondition(getFactory().Code().<Boolean>createCodeSnippetExpression(element.getSimpleName() + " > " + annotation.max()));
anIf.setThenStatement(getFactory().Code().createCtThrow("new RuntimeException(\"out of max bound (\" + " + element.getSimpleName() + " + \" > " + annotation.max() + "\")"));
parent.getBody().insertBegin(anIf);
anIf.setParent(parent);
}
开发者ID:SpoonLabs,项目名称:spoon-examples,代码行数:20,代码来源:BoundProcessor.java
示例2: process
import spoon.reflect.code.CtThrow; //导入依赖的package包/类
@Override
public void process(CtThrow throwStmt) {
int methodId = ProcessorUtil.methodId(getMethod(throwStmt));
int localId = getLocalId(throwStmt);
String localVar = "throwable_" + localId;
String snippet = throwStmt.getThrownExpression().getType() + " " + localVar + " = " + throwStmt.getThrownExpression();
CtCodeSnippetStatement var = getFactory().Code().createCodeSnippetStatement(snippet);
snippet = getLogger()+".writeThrow(Thread.currentThread(),\"" + methodId + "\",\""
+ localId + "\"," + localVar + ")";
CtCodeSnippetStatement log = getFactory().Code().createCodeSnippetStatement(snippet);
CtCodeSnippetStatement thro = getFactory().Code().createCodeSnippetStatement("throw " + localVar);
CtBlock block = getFactory().Core().createBlock();
block.addStatement(var);
block.addStatement(log);
block.addStatement(thro);
throwStmt.replace(block);
throwStmt.getParent(CtBlock.class).removeStatement(throwStmt);
}
开发者ID:DIVERSIFY-project,项目名称:sosiefier,代码行数:25,代码来源:ThrowProcessor.java
示例3: process
import spoon.reflect.code.CtThrow; //导入依赖的package包/类
@Override
public void process(CtThrow throwStmt) {
int methodId = methodId(getMethod(throwStmt));
int localId = getLocalId(throwStmt);
String localVar = "throwable_" + localId;
String snippet = throwStmt.getThrownExpression().getType() + " " + localVar + " = " + throwStmt.getThrownExpression();
CtCodeSnippetStatement var = getFactory().Code().createCodeSnippetStatement(snippet);
snippet = getLogger()+".writeThrow(Thread.currentThread(),\"" + methodId + "\",\""
+ localId + "\"," + localVar + ")";
CtCodeSnippetStatement log = getFactory().Code().createCodeSnippetStatement(snippet);
CtCodeSnippetStatement thro = getFactory().Code().createCodeSnippetStatement("throw " + localVar);
CtBlock block = getFactory().Core().createBlock();
block.addStatement(var);
block.addStatement(log);
block.addStatement(thro);
throwStmt.replace(block);
throwStmt.getParent(CtBlock.class).removeStatement(throwStmt);
}
开发者ID:DIVERSIFY-project,项目名称:sosiefier,代码行数:25,代码来源:ThrowProcessor.java
示例4: process
import spoon.reflect.code.CtThrow; //导入依赖的package包/类
@Override
public void process(CtStatement element) {
if (element instanceof CtIf) {
add(((CtIf) element).getCondition());
} else if (element instanceof CtFor) {
add(((CtFor) element).getExpression());
} else if (element instanceof CtWhile) {
add(((CtWhile) element).getLoopingExpression());
} else if (element instanceof CtDo) {
add(((CtDo) element).getLoopingExpression());
} else if (element instanceof CtThrow) {
add(((CtThrow) element).getThrownExpression());
} else if (element instanceof CtInvocation && (element.getParent() instanceof CtBlock)) {
add(element);
} else if (element instanceof CtAssignment || element instanceof CtConstructorCall
|| element instanceof CtCFlowBreak || element instanceof CtLocalVariable) {
add(element);
}
}
开发者ID:SpoonLabs,项目名称:astor,代码行数:22,代码来源:SpecialStatementFixSpaceProcessor.java
示例5: test_t_214116
import spoon.reflect.code.CtThrow; //导入依赖的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
示例6: newThrow
import spoon.reflect.code.CtThrow; //导入依赖的package包/类
public static <E extends Throwable> CtThrow newThrow(Factory factory, Class<E> throwableClass, String thrownExpression) {
return newThrow(factory, newExpressionFromSnippet(factory, thrownExpression, throwableClass));
}
开发者ID:SpoonLabs,项目名称:nopol,代码行数:4,代码来源:SpoonModelLibrary.java
示例7: isRelevantCommandStatement
import spoon.reflect.code.CtThrow; //导入依赖的package包/类
public <T extends CtElement> boolean isRelevantCommandStatement(@NotNull T stat, @NotNull CtExecutable<?> exec) {
return !(stat instanceof CtThrow) &&
!SpoonHelper.INSTANCE.isReturnBreakStatement(stat) && !SpoonHelper.INSTANCE.isSuperCall(exec, stat) &&
!SpoonHelper.INSTANCE.isLogStatement(stat) && !(stat instanceof CtAssert<?>);
}
开发者ID:diverse-project,项目名称:InspectorGuidget,代码行数:6,代码来源:SpoonHelper.java
示例8: isToBeProcessed
import spoon.reflect.code.CtThrow; //导入依赖的package包/类
@Override
public boolean isToBeProcessed(CtThrow candidate) {
return candidate.getParent(CtExecutable.class) != null
&& !getMethod(candidate).getThrownTypes().isEmpty();
}
开发者ID:DIVERSIFY-project,项目名称:sosiefier,代码行数:6,代码来源:ThrowProcessor.java
注:本文中的spoon.reflect.code.CtThrow类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论