com.sun.source.tree.ThrowTree Java Examples
The following examples show how to use
com.sun.source.tree.ThrowTree.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Utilities.java From netbeans with Apache License 2.0 | 6 votes |
@Override public Boolean visitThrow(ThrowTree node, Void p) { TypeMirror type = info.getTrees().getTypeMirror(new TreePath(getCurrentPath(), node.getExpression())); boolean isCaught = false; OUTER: for (Pair<Set<TypeMirror>, Tree> pair : caughtExceptions) { Set<TypeMirror> caught = pair.first(); for (TypeMirror c : caught) { if (info.getTypes().isSubtype(type, c)) { isCaught = true; targetTrees.add(pair.second()); break OUTER; } } } return super.visitThrow(node, p) == Boolean.TRUE || !isCaught; }
Example #2
Source File: TryCatchFinally.java From netbeans with Apache License 2.0 | 6 votes |
@Override public Void visitThrow(ThrowTree node, Collection<TreePath> trees) { if (!analyzeThrows) { return null; } TypeMirror type = info.getTrees().getTypeMirror(new TreePath(getCurrentPath(), node.getExpression())); boolean isCaught = false; OUTER: for (Set<TypeMirror> caught : caughtExceptions) { for (TypeMirror c : caught) { if (info.getTypes().isSubtype(type, c)) { isCaught = true; break OUTER; } } } super.visitThrow(node, trees); if (!isCaught) { trees.add(getCurrentPath()); } return null; }
Example #3
Source File: TreeDiffer.java From compile-testing with Apache License 2.0 | 5 votes |
@Override public Void visitThrow(ThrowTree expected, Tree actual) { Optional<ThrowTree> other = checkTypeAndCast(expected, actual); if (!other.isPresent()) { addTypeMismatch(expected, actual); return null; } scan(expected.getExpression(), other.get().getExpression()); return null; }
Example #4
Source File: JavaInputAstVisitor.java From java-n-IDE-for-Android with Apache License 2.0 | 5 votes |
@Override public Void visitThrow(ThrowTree node, Void unused) { sync(node); token("throw"); builder.space(); scan(node.getExpression(), null); token(";"); return null; }
Example #5
Source File: ModelBuilder.java From vertx-codetrans with Apache License 2.0 | 5 votes |
@Override public CodeModel visitThrow(ThrowTree node, VisitContext context) { ThrowableModel throwableExpression = (ThrowableModel) scan(node.getExpression(), context); return StatementModel.render(writer -> { writer.renderThrow(throwableExpression.getType(), throwableExpression.getReason()); }); }
Example #6
Source File: JavaInputAstVisitor.java From google-java-format with Apache License 2.0 | 5 votes |
@Override public Void visitThrow(ThrowTree node, Void unused) { sync(node); token("throw"); builder.space(); scan(node.getExpression(), null); token(";"); return null; }
Example #7
Source File: JavaInputAstVisitor.java From javaide with GNU General Public License v3.0 | 5 votes |
@Override public Void visitThrow(ThrowTree node, Void unused) { sync(node); token("throw"); builder.space(); scan(node.getExpression(), null); token(";"); return null; }
Example #8
Source File: ExpressionScanner.java From netbeans with Apache License 2.0 | 5 votes |
@Override public List<Tree> visitThrow(ThrowTree node, ExpressionScanner.ExpressionsInfo p) { List<Tree> result = null; if (acceptsTree(node)) { result = scan(node.getExpression(), p); } return result; }
Example #9
Source File: MagicSurroundWithTryCatchFix.java From netbeans with Apache License 2.0 | 5 votes |
private static StatementTree createRethrow(WorkingCopy info, TreeMaker make, String name) { if (!ErrorFixesFakeHint.isRethrow(ErrorFixesFakeHint.getPreferences(info.getFileObject(), FixKind.SURROUND_WITH_TRY_CATCH))) { return null; } ThrowTree result = make.Throw(make.Identifier(name)); info.tag(result.getExpression(), Utilities.TAG_SELECT); return result; }
Example #10
Source File: Flow.java From netbeans with Apache License 2.0 | 5 votes |
public Boolean visitThrow(ThrowTree node, ConstructorData p) { super.visitThrow(node, p); if (node.getExpression() != null) { TypeMirror thrown = info.getTrees().getTypeMirror(new TreePath(getCurrentPath(), node.getExpression())); recordResumeOnExceptionHandler(thrown); } return null; }
Example #11
Source File: TreeNode.java From netbeans with Apache License 2.0 | 5 votes |
@Override public Void visitThrow(ThrowTree tree, List<Node> d) { List<Node> below = new ArrayList<Node>(); addCorrespondingType(below); addCorrespondingComments(below); super.visitThrow(tree, below); d.add(new TreeNode(info, getCurrentPath(), below)); return null; }
Example #12
Source File: MethodExitDetector.java From netbeans with Apache License 2.0 | 5 votes |
@Override public Boolean visitThrow(ThrowTree tree, Stack<Tree> d) { addToExceptionsMap(info.getTrees().getTypeMirror(new TreePath(getCurrentPath(), tree.getExpression())), tree); super.visitThrow(tree, d); return Boolean.TRUE; }
Example #13
Source File: CopyFinder.java From netbeans with Apache License 2.0 | 5 votes |
public Boolean visitThrow(ThrowTree node, TreePath p) { if (p == null) { super.visitThrow(node, p); return false; } ThrowTree at = (ThrowTree) p.getLeaf(); return scan(node.getExpression(), at.getExpression(), p); }
Example #14
Source File: TreeDuplicator.java From netbeans with Apache License 2.0 | 5 votes |
@Override public Tree visitThrow(ThrowTree tree, Void p) { ThrowTree n = make.Throw(tree.getExpression()); model.setType(n, model.getType(tree)); comments.copyComments(tree, n); model.setPos(n, model.getPos(tree)); return n; }
Example #15
Source File: ExpectedTypeResolver.java From netbeans with Apache License 2.0 | 4 votes |
/** * 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; }
Example #16
Source File: CyclomaticComplexityVisitor.java From netbeans with Apache License 2.0 | 4 votes |
@Override public Object visitThrow(ThrowTree node, Object p) { complexity++; return super.visitThrow(node, p); }
Example #17
Source File: NCLOCVisitor.java From netbeans with Apache License 2.0 | 4 votes |
@Override public Object visitThrow(ThrowTree node, Object p) { statements++; return super.visitThrow(node, p); }
Example #18
Source File: TreeConverter.java From j2objc with Apache License 2.0 | 4 votes |
private TreeNode convertThrow(ThrowTree node, TreePath parent) { TreePath path = getTreePath(parent, node); return new ThrowStatement().setExpression((Expression) convert(node.getExpression(), path)); }
Example #19
Source File: UTemplater.java From Refaster with Apache License 2.0 | 4 votes |
@Override public UThrow visitThrow(ThrowTree tree, Void v) { return UThrow.create(template(tree.getExpression())); }
Example #20
Source File: UThrow.java From Refaster with Apache License 2.0 | 4 votes |
@Override @Nullable public Unifier visitThrow(ThrowTree throwStmt, @Nullable Unifier unifier) { return getExpression().unify(throwStmt.getExpression(), unifier); }