本文整理汇总了Java中spoon.reflect.code.CtCatch类的典型用法代码示例。如果您正苦于以下问题:Java CtCatch类的具体用法?Java CtCatch怎么用?Java CtCatch使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
CtCatch类属于spoon.reflect.code包,在下文中一共展示了CtCatch类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: usingLauncher
import spoon.reflect.code.CtCatch; //导入依赖的package包/类
public static void usingLauncher(){
/**STEP 1: initialize a spoon launcher*/
Launcher launcher = new Launcher();
launcher.addInputResource("E:/workspaceee/PATool/src/sklse/yongfeng/spoon/Person.java");
/**STEP 2: create AST model*/
launcher.buildModel();
CtModel ASTModel = launcher.getModel();
/**STEP 3: access the program elements*/
List<CtCatch> lsCatchs = ASTModel.getElements(new TypeFilter(CtCatch.class));
for(CtCatch catchs: lsCatchs){
if(catchs.getBody().getStatements().size() == 0){
System.out.println("EMPTY CATCH!");
System.out.println("meta model : " + catchs.getClass().toString());
System.out.println("parent model: " + catchs.getParent().getClass().toString());
}
}
}
开发者ID:Gu-Youngfeng,项目名称:PATool,代码行数:21,代码来源:Usage.java
示例2: getStatementParentNotCtrlFlow
import spoon.reflect.code.CtCatch; //导入依赖的package包/类
/**
* Returns the first parent statement or the element before this statement if the statement is a control flow statement.
* @param elt The element to analyse.
* @return The found element.
*/
public Optional<CtElement> getStatementParentNotCtrlFlow(@Nullable CtElement elt) {
CtElement res = elt;
boolean found = false;
while(!found && res != null) {
if(res instanceof CtStatement) {
found = true;
}else {
if(res.isParentInitialized()) {
CtElement parent = res.getParent();
// FIXME use CtBodyHolder Spoon 5.5
if(parent instanceof CtIf || parent instanceof CtSwitch || parent instanceof CtLoop || parent instanceof CtTry ||
parent instanceof CtCatch || parent instanceof CtCase) {
found = true;
}else {
res = parent;
}
}else {
res = null;
}
}
}
return Optional.ofNullable(res);
}
开发者ID:diverse-project,项目名称:InspectorGuidget,代码行数:31,代码来源:SpoonHelper.java
示例3: process
import spoon.reflect.code.CtCatch; //导入依赖的package包/类
@Override
/***
* <p>Processing the program element (in this example we use CtCatch).</p>
*/
public void process(CtCatch elem) {
System.out.println("processing...");
if(elem.getBody().getStatements().size() == 0){
count++;
System.out.println("meta model : " + elem.getClass().toString());
System.out.println("parent model: " + elem.getParent().getClass().toString());
// System.out.println("No Empty!");
System.out.println("empty catch count: " + count);
}
}
开发者ID:Gu-Youngfeng,项目名称:PATool,代码行数:15,代码来源:CatchProcessor.java
示例4: newTryCatch
import spoon.reflect.code.CtCatch; //导入依赖的package包/类
public static CtTry newTryCatch(Factory factory, CtStatement tryBlock, List<CtCatch> catchers, CtElement parent) {
CtTry tryCatch = factory.Core().createTry();
tryCatch.setBody(asBlock(tryBlock, tryCatch));
tryCatch.setCatchers(catchers);
setParent(tryCatch, catchers);
setParent(parent, tryCatch);
return tryCatch;
}
开发者ID:SpoonLabs,项目名称:nopol,代码行数:9,代码来源:SpoonModelLibrary.java
示例5: process
import spoon.reflect.code.CtCatch; //导入依赖的package包/类
@Override
public void process(CtCatch element) {
int methodId = ProcessorUtil.methodId(getMethod(element));
int localId = getLocalId(element);
String snippet = getLogger() + ".writeCatch(Thread.currentThread(),\"" + methodId + "\",\""
+ localId + "\"," + element.getParameter().getSimpleName() + ")";
CtCodeSnippetStatement snippetStmt = getFactory().Code().createCodeSnippetStatement(snippet);
element.getBody().insertBegin(snippetStmt);
}
开发者ID:DIVERSIFY-project,项目名称:sosiefier,代码行数:12,代码来源:CatchProcessor.java
示例6: process
import spoon.reflect.code.CtCatch; //导入依赖的package包/类
@Override
public void process(CtCatch element) {
int methodId = methodId(getMethod(element));
int localId = getLocalId(element);
String snippet = getLogger() + ".writeCatch(Thread.currentThread(),\"" + methodId + "\",\""
+ localId + "\"," + element.getParameter().getSimpleName() + ")";
CtCodeSnippetStatement snippetStmt = getFactory().Code().createCodeSnippetStatement(snippet);
element.getBody().insertBegin(snippetStmt);
}
开发者ID:DIVERSIFY-project,项目名称:sosiefier,代码行数:12,代码来源:CatchProcessor.java
示例7: process
import spoon.reflect.code.CtCatch; //导入依赖的package包/类
@Override
public void process(CtStatement element) {
if (!(element instanceof CtBlock || element instanceof CtClass || element instanceof CtMethod
|| element instanceof CtTry || element instanceof CtCatch) &&
(element.getParent() instanceof CtBlock) &&
(!(element.toString().startsWith("super"))
|| ConfigurationProperties.getPropertyBool("manipulatesuper"))) {
add(element);
}
}
开发者ID:SpoonLabs,项目名称:astor,代码行数:11,代码来源:SingleStatementFixSpaceProcessor.java
示例8: newCatch
import spoon.reflect.code.CtCatch; //导入依赖的package包/类
public static <E extends Throwable> CtCatch newCatch(Factory factory, Class<E> throwableClass, String catchName, CtStatement catchBlock) {
CtCatch aCatch = factory.Core().createCatch();
aCatch.setParameter(factory.Code().createCatchVariable(newTypeReference(factory, throwableClass), catchName));
aCatch.setBody(asBlock(catchBlock, aCatch));
return aCatch;
}
开发者ID:SpoonLabs,项目名称:nopol,代码行数:7,代码来源:SpoonModelLibrary.java
示例9: isToBeProcessed
import spoon.reflect.code.CtCatch; //导入依赖的package包/类
@Override
public boolean isToBeProcessed(CtCatch candidate) {
return candidate.getBody().getStatements().size() == 0;
}
开发者ID:SpoonLabs,项目名称:spoon-examples,代码行数:5,代码来源:CatchProcessor.java
示例10: process
import spoon.reflect.code.CtCatch; //导入依赖的package包/类
@Override
public void process(CtCatch element) {
getEnvironment().report(this, Level.WARN, element, "empty catch clause");
emptyCatchs.add(element);
}
开发者ID:SpoonLabs,项目名称:spoon-examples,代码行数:6,代码来源:CatchProcessor.java
示例11: analyseSingleListenerMethod
import spoon.reflect.code.CtCatch; //导入依赖的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
示例12: isToBeProcessed
import spoon.reflect.code.CtCatch; //导入依赖的package包/类
@Override
public boolean isToBeProcessed(CtCatch candidate) {
return candidate.getParent(CtExecutable.class) != null;
}
开发者ID:DIVERSIFY-project,项目名称:sosiefier,代码行数:5,代码来源:CatchProcessor.java
注:本文中的spoon.reflect.code.CtCatch类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论