@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; }
@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; }
private boolean isTerminating(StatementTree tree) { StatementTree first = firstStatement(tree); if (first instanceof ThrowTree) return true; if (first instanceof ReturnTree) return true; if (first instanceof IfTree) { IfTree ifTree = (IfTree)first; if (ifTree.getElseStatement() != null && isTerminating(ifTree.getThenStatement()) && isTerminating(ifTree.getElseStatement())) return true; } return false; }
@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; }
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); }
@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; }
@Override public Void visitThrow(ThrowTree tree, EnumSet<UseTypes> p) { if (tree.getExpression() != null && tree.getExpression().getKind() == Kind.IDENTIFIER) { handlePossibleIdentifier(new TreePath(getCurrentPath(), tree.getExpression()), EnumSet.of(UseTypes.READ)); } return super.visitThrow(tree, p); }
@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; }
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; }
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; }
@Override public List<Tree> visitThrow(ThrowTree node, ExpressionScanner.ExpressionsInfo p) { List<Tree> result = null; if (acceptsTree(node)) { result = scan(node.getExpression(), p); } return result; }
@Override public Void visitThrow(ThrowTree node, Void unused) { sync(node); token("throw"); builder.space(); scan(node.getExpression(), null); token(";"); return null; }
@Override public boolean matches(StatementTree expressionTree, VisitorState state) { if (!(expressionTree instanceof ThrowTree)) { return false; } return thrownMatcher.matches(((ThrowTree) expressionTree).getExpression(), state); }
@Override public Void visitThrow(ThrowTree tree, VisitorState visitorState) { VisitorState state = visitorState.withPath(getCurrentPath()); for (ThrowTreeMatcher matcher : throwMatchers) { if (!isSuppressed(matcher, state)) { try { reportMatch(matcher.matchThrow(tree, state), tree, state); } catch (Throwable t) { handleError(matcher, t); } } } return super.visitThrow(tree, state); }
@Override public Description matchThrow(ThrowTree tree, VisitorState state) { return (tree.getExpression().getKind() == NULL_LITERAL) ? describeMatch( tree, SuggestedFix.replace(tree.getExpression(), "new NullPointerException()")) : NO_MATCH; }
@Override public Description matchThrow(ThrowTree tree, VisitorState state) { if (new FinallyThrowMatcher().matches(tree, state)) { return describeMatch(tree); } return Description.NO_MATCH; }
@Override public Description matchThrow(ThrowTree tree, VisitorState state) { if (new FinallyThrowMatcher().matches(tree, state)) { return describeMatch(tree, NO_FIX); } return Description.NO_MATCH; }
@Override public Node visitThrow(ThrowTree tree, Void p) { Node expression = scan(tree.getExpression(), p); TypeMirror exception = expression.getType(); ThrowNode throwsNode = new ThrowNode(tree, expression, env.getTypeUtils()); NodeWithExceptionsHolder exNode = extendWithNodeWithException( throwsNode, exception); exNode.setTerminatesExecution(true); return throwsNode; }
@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()); }); }
@Override public Node visitThrow(ThrowTree tree, Void p) { Node expression = scan(tree.getExpression(), p); TypeMirror exception = expression.getType(); ThrowNode throwsNode = new ThrowNode(tree, expression, env.getTypeUtils()); NodeWithExceptionsHolder exNode = extendWithNodeWithException(throwsNode, exception); exNode.setTerminatesExecution(true); return throwsNode; }
@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; }
@Override public Object visitThrow(ThrowTree node, Object p) { statements++; return super.visitThrow(node, p); }
@Override public Object visitThrow(ThrowTree node, Object p) { complexity++; return super.visitThrow(node, p); }
/** * 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; }
@Override public Mirror visitThrow(ThrowTree arg0, EvaluationContext evaluationContext) { Assert.error(arg0, "unsupported"); return null; }
@Override public Void visitThrow(ThrowTree node, Map<ErrorDescription, Integer> p) { if (!isUnsafe) addError(node, ERR_NO_THROW, p); return super.visitThrow(node, p); }
@Override public R visitThrow(ThrowTree tt, P p) { return null; }
@Override public List<T> visitThrow(ThrowTree node, T p) { return checkForCriteria(node); }
@Override public ThrowTree createThrow(ExpressionTree expression) { return new ThrowTreeImpl(expression); }
@Override public Object visitThrow(ThrowTree t, Trees p) { info("ThrowTree" + CL + t.getKind() + SP + t); return super.visitThrow(t, p); }
@Override public UThrow visitThrow(ThrowTree tree, Void v) { return UThrow.create(template(tree.getExpression())); }
@Override @Nullable public Unifier visitThrow(ThrowTree throwStmt, @Nullable Unifier unifier) { return getExpression().unify(throwStmt.getExpression(), unifier); }
@Override public Boolean visitThrow(ThrowTree tree, Void unused) { return false; }
@Override public Result visitThrow(ThrowTree node, BreakContext cxt) { return ALWAYS_RETURNS; }
@Override public Choice<State<JCThrow>> visitThrow(ThrowTree node, State<?> state) { return chooseSubtrees(state, s -> unifyExpression(node.getExpression(), s), maker()::Throw); }
@Override @Nullable public Choice<Unifier> visitThrow(ThrowTree throwStmt, @Nullable Unifier unifier) { return getExpression().unify(throwStmt.getExpression(), unifier); }
public ThrowNode(ThrowTree tree, Node expression, Types types) { super(types.getNoType(TypeKind.NONE)); this.tree = tree; this.expression = expression; }
@Override public PurityResult visitThrow(ThrowTree node, PurityResult p) { return scan(node.getExpression(), p); }