本文整理汇总了Java中com.sun.source.tree.TryTree.getCatches方法的典型用法代码示例。如果您正苦于以下问题:Java TryTree.getCatches方法的具体用法?Java TryTree.getCatches怎么用?Java TryTree.getCatches使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.sun.source.tree.TryTree
的用法示例。
在下文中一共展示了TryTree.getCatches方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: visitTry
import com.sun.source.tree.TryTree; //导入方法依赖的package包/类
@Override
public Void visitTry(TryTree node, Collection<TreePath> trees) {
Set<TypeMirror> caught = new HashSet<TypeMirror>();
for (CatchTree ct : node.getCatches()) {
TypeMirror t = info.getTrees().getTypeMirror(new TreePath(new TreePath(getCurrentPath(), ct), ct.getParameter()));
if (t != null) {
caught.add(t);
}
}
caughtExceptions.push(caught);
try {
scan(node.getBlock(), trees);
} finally {
caughtExceptions.pop();
}
scan(node.getFinallyBlock(), trees);
return null;
}
示例2: visitTry
import com.sun.source.tree.TryTree; //导入方法依赖的package包/类
@Override
public Boolean visitTry(TryTree node, Void p) {
Set<TypeMirror> caught = new HashSet<TypeMirror>();
for (CatchTree ct : node.getCatches()) {
TypeMirror t = info.getTrees().getTypeMirror(new TreePath(new TreePath(getCurrentPath(), ct), ct.getParameter()));
if (t != null) {
caught.add(t);
}
}
caughtExceptions.push(Pair.of(caught, node));
try {
return scan(node.getBlock(), p) == Boolean.TRUE || scan(node.getFinallyBlock(), p) == Boolean.TRUE;
} finally {
caughtExceptions.pop();
}
}
示例3: visitTry
import com.sun.source.tree.TryTree; //导入方法依赖的package包/类
@Override
public Void visitTry(TryTree tryTree, List<ReformatOption> optionsToReformat) {
addLeftBraceToList(optionsToReformat, tryTree.getBlock(), PreferencesFormatOptions.BRACES_IN_OTHER_DECLARATION);
BlockTree finalBlock = tryTree.getFinallyBlock();
List<? extends CatchTree> catches = tryTree.getCatches();
if (finalBlock instanceof CompoundTree) {
addLeftBraceToList(optionsToReformat, finalBlock, PreferencesFormatOptions.BRACES_IN_OTHER_DECLARATION);
addRightBraceToList(optionsToReformat, (CompoundTree) finalBlock, PreferencesFormatOptions.AFTER_OTHER_DECLARATION);
} else if (!catches.isEmpty()) {
BlockTree catchBlock = catches.get(catches.size() - 1).getBlock();
addRightBraceToList(optionsToReformat, (CompoundTree) catchBlock, PreferencesFormatOptions.AFTER_OTHER_DECLARATION);
} else {
addRightBraceToList(optionsToReformat, (CompoundTree) tryTree.getBlock(), PreferencesFormatOptions.AFTER_OTHER_DECLARATION);
}
return null;
}
示例4: matchTry
import com.sun.source.tree.TryTree; //导入方法依赖的package包/类
@Override
public Description matchTry (TryTree tree, VisitorState state) {
List<? extends CatchTree> catchList = tree.getCatches();
if (catchList == null || catchList.size() == 0) {
// TODO: this try block does not have a catch, we should further check the
// finally block!
return Description.NO_MATCH;
}
CatchTree lastCatch = catchList.get(tree.getCatches().size() - 1);
if (overcatch(lastCatch, state)) {
if (abortInCatch(lastCatch, state)) {
LineMap lineMap = state.getPath().getCompilationUnit().getLineMap();
/* System.out.println("****** warning starts **************");
System.out.println("WARNING: abort in overcatch: "
+ state.getPath().getCompilationUnit().getSourceFile().getName()
+ ":" + lineMap.getLineNumber(TreeInfo.getStartPos((JCTree) lastCatch)));
System.out.println(state.getPath().getLeaf());
System.out.println("****** warning ends **************");
System.out.println(); */
return describeMatch(lastCatch, NO_FIX);
}
}
return Description.NO_MATCH;
}
示例5: performRewrite
import com.sun.source.tree.TryTree; //导入方法依赖的package包/类
@Override
protected void performRewrite(TransformationContext ctx) {
WorkingCopy wc = ctx.getWorkingCopy();
TreePath tp = ctx.getPath();
List<Tree> disjointTypes = new LinkedList<Tree>();
TryTree tt = (TryTree) tp.getLeaf();
int first = duplicates.get(0);
List<Integer> remainingDuplicates = duplicates.subList(1, duplicates.size());
addDisjointType(disjointTypes, tt.getCatches().get(first).getParameter().getType());
for (Integer d : remainingDuplicates) {
addDisjointType(disjointTypes, tt.getCatches().get((int) d).getParameter().getType());
}
List<CatchTree> newCatches = new LinkedList<CatchTree>();
int c = 0;
for (CatchTree ct : tt.getCatches()) {
if (c == first) {
wc.rewrite(ct.getParameter().getType(), wc.getTreeMaker().UnionType(disjointTypes));
}
if (remainingDuplicates.contains(c++)) continue;
newCatches.add(ct);
}
TryTree nue = wc.getTreeMaker().Try(tt.getResources(), tt.getBlock(), newCatches, tt.getFinallyBlock());
wc.rewrite(tt, nue);
}
示例6: visitTry
import com.sun.source.tree.TryTree; //导入方法依赖的package包/类
@Override
public Boolean visitTry(TryTree that, Void unused) {
boolean completes = scan(that.getBlock());
// assume all catch blocks are reachable; javac has already rejected unreachable
// checked exception handlers
for (CatchTree catchTree : that.getCatches()) {
completes |= scan(catchTree.getBlock());
}
if (that.getFinallyBlock() != null && !scan(that.getFinallyBlock())) {
completes = false;
}
return completes;
}
示例7: visitTry
import com.sun.source.tree.TryTree; //导入方法依赖的package包/类
@Override
public UTry visitTry(TryTree tree, Void v) {
@SuppressWarnings({"unchecked", "rawtypes"})
List<UTree<?>> resources =
cast(templateTrees(tree.getResources()), (Class<UTree<?>>) (Class) UTree.class);
UBlock block = visitBlock(tree.getBlock(), null);
ImmutableList.Builder<UCatch> catchesBuilder = ImmutableList.builder();
for (CatchTree catchTree : tree.getCatches()) {
catchesBuilder.add(visitCatch(catchTree, null));
}
UBlock finallyBlock =
(tree.getFinallyBlock() == null) ? null : visitBlock(tree.getFinallyBlock(), null);
return UTry.create(resources, block, catchesBuilder.build(), finallyBlock);
}
示例8: visitTry
import com.sun.source.tree.TryTree; //导入方法依赖的package包/类
@Override
public Result visitTry(TryTree node, BreakContext cxt) {
Result result = node.getBlock().accept(this, cxt);
for (CatchTree catchTree : node.getCatches()) {
result = result.or(catchTree.accept(this, cxt));
}
if (node.getFinallyBlock() != null) {
result = result.then(node.getFinallyBlock().accept(this, cxt));
}
return result;
}
示例9: isInapplicableExceptionType
import com.sun.source.tree.TryTree; //导入方法依赖的package包/类
private boolean isInapplicableExceptionType(TryTree tree, VisitorState state) {
for (CatchTree catchTree : tree.getCatches()) {
if (INAPPLICABLE_EXCEPTION.matches(catchTree.getParameter(), state)) {
return true;
}
}
return false;
}
示例10: hasToleratedException
import com.sun.source.tree.TryTree; //导入方法依赖的package包/类
private boolean hasToleratedException(TryTree tree) {
for (CatchTree catchTree : tree.getCatches()) {
if (catchTree.getParameter().getName().contentEquals("tolerated")) {
return true;
}
}
return false;
}
示例11: hasExpectedException
import com.sun.source.tree.TryTree; //导入方法依赖的package包/类
private boolean hasExpectedException(TryTree tree) {
for (CatchTree catchTree : tree.getCatches()) {
if (catchTree.getParameter().getName().contentEquals("expected")) {
return true;
}
}
return false;
}
示例12: anyCatchBlockMatches
import com.sun.source.tree.TryTree; //导入方法依赖的package包/类
private boolean anyCatchBlockMatches(TryTree tree, VisitorState state, Matcher<Tree> matcher) {
for (CatchTree catchTree : tree.getCatches()) {
if (matcher.matches(catchTree.getBlock(), state)) {
return true;
}
}
return false;
}
示例13: visitTry
import com.sun.source.tree.TryTree; //导入方法依赖的package包/类
@Override
public Boolean visitTry(TryTree tree, Stack<Tree> d) {
exceptions2HighlightsStack.push(null);
Boolean returnInTryBlock = scan(tree.getBlock(), d);
boolean returnInCatchBlock = true;
for (Tree t : tree.getCatches()) {
Boolean b = scan(t, d);
returnInCatchBlock &= b == Boolean.TRUE;
}
Boolean returnInFinallyBlock = scan(tree.getFinallyBlock(), d);
doPopup();
if (returnInTryBlock == Boolean.TRUE && returnInCatchBlock)
return Boolean.TRUE;
return returnInFinallyBlock;
}
示例14: findUncaughtExceptions
import com.sun.source.tree.TryTree; //导入方法依赖的package包/类
private List<? extends TypeMirror> findUncaughtExceptions(CompilationInfo info, TreePath path, List<? extends TypeMirror> exceptions) {
List<TypeMirror> result = new ArrayList<TypeMirror>();
result.addAll(exceptions);
Tree lastTree = null;
while (path != null) {
Tree currentTree = path.getLeaf();
if (currentTree.getKind() == Tree.Kind.METHOD) {
TypeMirror tm = info.getTrees().getTypeMirror(path);
if (tm != null && tm.getKind() == TypeKind.EXECUTABLE) {
for (TypeMirror mirr : ((ExecutableType) tm).getThrownTypes()) {
for (Iterator<TypeMirror> it = result.iterator(); it.hasNext();)
if (info.getTypes().isSameType(it.next(), mirr))
it.remove();
}
break;
}
}
if (currentTree.getKind() == Tree.Kind.LAMBDA_EXPRESSION) {
// no checked exceptions can be thrown out of Lambda, #243106
break;
}
if (currentTree.getKind() == Kind.TRY) {
TryTree tt = (TryTree) currentTree;
if (tt.getBlock() == lastTree) {
for (CatchTree c : tt.getCatches()) {
TreePath catchPath = new TreePath(new TreePath(path, c), c.getParameter());
VariableElement variable = (VariableElement) info.getTrees().getElement(catchPath);
if (variable == null) {
continue;
}
TypeMirror variableType = variable.asType();
if (variableType.getKind() == TypeKind.UNION) {
result.removeAll(((UnionType)variableType).getAlternatives());
} else {
result.remove(variableType);
}
}
}
}
lastTree = path.getLeaf();
path = path.getParentPath();
}
List<TypeMirror> filtered = new ArrayList<>();
OUTER: for (Iterator<TypeMirror> sourceIt = result.iterator(); sourceIt.hasNext(); ) {
TypeMirror sourceType = sourceIt.next();
for (Iterator<TypeMirror> filteredIt = filtered.iterator(); filteredIt.hasNext(); ) {
TypeMirror filteredType = filteredIt.next();
if (info.getTypes().isSubtype(sourceType, filteredType)) {
sourceIt.remove();
continue OUTER;
}
if (info.getTypes().isSubtype(filteredType, sourceType)) {
filteredIt.remove();
break;
}
}
filtered.add(sourceType);
}
return filtered;
}
示例15: visitThrow
import com.sun.source.tree.TryTree; //导入方法依赖的package包/类
/**
* Computes possible types for throw expression. Throw can safely throw an exception, which is
* either declared by method as a thrown type, or catched within method, by an upper try-catch block.
* Unchecked exceptions are permitted (derivatives of RuntimeException or Error).
*/
@Override
public List<? extends TypeMirror> visitThrow(ThrowTree node, Object p) {
List<TypeMirror> result = new ArrayList<TypeMirror>();
TreePath parents = getCurrentPath();
Tree prev = null;
while (parents != null && parents.getLeaf().getKind() != Tree.Kind.METHOD) {
Tree l = parents.getLeaf();
if (l.getKind() == Tree.Kind.TRY) {
TryTree tt = (TryTree) l;
if (prev == tt.getBlock()) {
for (CatchTree ct : tt.getCatches()) {
TypeMirror ex = info.getTrees().getTypeMirror(new TreePath(getCurrentPath(), ct.getParameter().getType()));
if (ex != null) {
switch (ex.getKind()) {
case DECLARED:
if (!result.contains(ex)) {
result.add(ex);
}
break;
case UNION:
for (TypeMirror t : ((UnionType) ex).getAlternatives()) {
if (!result.contains(t)) {
result.add(t);
}
}
break;
}
}
}
}
}
prev = l;
parents = parents.getParentPath();
}
if (parents != null) {
MethodTree mt = (MethodTree) parents.getLeaf();
for (ExpressionTree etree : mt.getThrows()) {
TypeMirror m = info.getTrees().getTypeMirror(new TreePath(parents, etree));
if (m != null && !result.contains(m)) {
result.add(m);
}
}
}
TypeMirror jlre = info.getElements().getTypeElement("java.lang.RuntimeException").asType(); // NOI18N
TypeMirror jler = info.getElements().getTypeElement("java.lang.Error").asType(); // NOI18N
for (TypeMirror em : result) {
if (jlre != null && info.getTypes().isAssignable(jlre, em)) {
jlre = null;
}
if (jler != null && info.getTypes().isAssignable(jler, em)) {
jler = null;
}
if (jlre == null && jler == null) {
break;
}
}
if (jlre != null) {
result.add(jlre);
}
if (jler != null) {
result.add(jler);
}
return result;
}