Java 类com.sun.source.tree.ThrowTree 实例源码

项目:incubator-netbeans    文件:TryCatchFinally.java   
@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;
}
项目:incubator-netbeans    文件:Utilities.java   
@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;
}
项目:checker-framework    文件:MapGetHeuristics.java   
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;
}
项目:incubator-netbeans    文件:TreeDuplicator.java   
@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;
}
项目:incubator-netbeans    文件:CopyFinder.java   
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);
}
项目:incubator-netbeans    文件:MethodExitDetector.java   
@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;
}
项目:incubator-netbeans    文件:SemanticHighlighterBase.java   
@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);
}
项目:incubator-netbeans    文件:TreeNode.java   
@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;
}
项目:incubator-netbeans    文件:Flow.java   
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;
}
项目:incubator-netbeans    文件:MagicSurroundWithTryCatchFix.java   
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;
}
项目:incubator-netbeans    文件:ExpressionScanner.java   
@Override
public List<Tree> visitThrow(ThrowTree node, ExpressionScanner.ExpressionsInfo p) {
    List<Tree> result = null;
    if (acceptsTree(node)) {
        result = scan(node.getExpression(), p);
    }
    return result;
}
项目:javaide    文件:JavaInputAstVisitor.java   
@Override
public Void visitThrow(ThrowTree node, Void unused) {
    sync(node);
    token("throw");
    builder.space();
    scan(node.getExpression(), null);
    token(";");
    return null;
}
项目:error-prone    文件:Throws.java   
@Override
public boolean matches(StatementTree expressionTree, VisitorState state) {
  if (!(expressionTree instanceof ThrowTree)) {
    return false;
  }

  return thrownMatcher.matches(((ThrowTree) expressionTree).getExpression(), state);
}
项目:error-prone    文件:ErrorProneScanner.java   
@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);
}
项目:error-prone    文件:ThrowNull.java   
@Override
public Description matchThrow(ThrowTree tree, VisitorState state) {
  return (tree.getExpression().getKind() == NULL_LITERAL)
      ? describeMatch(
          tree, SuggestedFix.replace(tree.getExpression(), "new NullPointerException()"))
      : NO_MATCH;
}
项目:error-prone    文件:Finally.java   
@Override
public Description matchThrow(ThrowTree tree, VisitorState state) {
  if (new FinallyThrowMatcher().matches(tree, state)) {
    return describeMatch(tree);
  }
  return Description.NO_MATCH;
}
项目:error-prone-aspirator    文件:Finally.java   
@Override
public Description matchThrow(ThrowTree tree, VisitorState state) {
  if (new FinallyThrowMatcher().matches(tree, state)) {
    return describeMatch(tree, NO_FIX);
  }
  return Description.NO_MATCH;
}
项目:checker-framework    文件:CFGBuilder.java   
@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;
}
项目:vertx-codetrans    文件:ModelBuilder.java   
@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());
  });
}
项目:bazel    文件:CFGBuilder.java   
@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;
}
项目:compile-testing    文件:TreeDiffer.java   
@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;
}
项目:incubator-netbeans    文件:NCLOCVisitor.java   
@Override
public Object visitThrow(ThrowTree node, Object p) {
    statements++;
    return super.visitThrow(node, p);
}
项目:incubator-netbeans    文件:CyclomaticComplexityVisitor.java   
@Override
public Object visitThrow(ThrowTree node, Object p) {
    complexity++;
    return super.visitThrow(node, p);
}
项目:incubator-netbeans    文件:ExpectedTypeResolver.java   
/**
 * 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;
}
项目:incubator-netbeans    文件:EvaluatorVisitor.java   
@Override
public Mirror visitThrow(ThrowTree arg0, EvaluationContext evaluationContext) {
    Assert.error(arg0, "unsupported");
    return null;
}
项目:btrace.nb    文件:ErrorScanner.java   
@Override
public Void visitThrow(ThrowTree node, Map<ErrorDescription, Integer> p) {
    if (!isUnsafe) addError(node, ERR_NO_THROW, p);
    return super.visitThrow(node, p);
}
项目:btrace.nb    文件:ErrorScanner.java   
@Override
public Void visitThrow(ThrowTree node, Map<ErrorDescription, Integer> p) {
    if (!isUnsafe) addError(node, ERR_NO_THROW, p);
    return super.visitThrow(node, p);
}
项目:oblivion-netbeans-plugin    文件:ApexTreeVisitorAdapter.java   
@Override
public R visitThrow(ThrowTree tt, P p) {
    return null;
}
项目:oblivion-netbeans-plugin    文件:TreeFinder.java   
@Override
public List<T> visitThrow(ThrowTree node, T p) {
    return checkForCriteria(node);
}
项目:oblivion-netbeans-plugin    文件:ApexTreeFactory.java   
@Override
public ThrowTree createThrow(ExpressionTree expression) {
    return new ThrowTreeImpl(expression);
}
项目:adalid    文件:CodeAnalyzerTreeVisitor.java   
@Override
public Object visitThrow(ThrowTree t, Trees p) {
    info("ThrowTree" + CL + t.getKind() + SP + t);
    return super.visitThrow(t, p);
}
项目:refactor-faster    文件:UTemplater.java   
@Override
public UThrow visitThrow(ThrowTree tree, Void v) {
  return UThrow.create(template(tree.getExpression()));
}
项目:refactor-faster    文件:UThrow.java   
@Override
@Nullable
public Unifier visitThrow(ThrowTree throwStmt, @Nullable Unifier unifier) {
  return getExpression().unify(throwStmt.getExpression(), unifier);
}
项目:error-prone    文件:Reachability.java   
@Override
public Boolean visitThrow(ThrowTree tree, Void unused) {
  return false;
}
项目:error-prone    文件:UTemplater.java   
@Override
public UThrow visitThrow(ThrowTree tree, Void v) {
  return UThrow.create(template(tree.getExpression()));
}
项目:error-prone    文件:ControlFlowVisitor.java   
@Override
public Result visitThrow(ThrowTree node, BreakContext cxt) {
  return ALWAYS_RETURNS;
}
项目:error-prone    文件:PlaceholderUnificationVisitor.java   
@Override
public Choice<State<JCThrow>> visitThrow(ThrowTree node, State<?> state) {
  return chooseSubtrees(state, s -> unifyExpression(node.getExpression(), s), maker()::Throw);
}
项目:error-prone    文件:UThrow.java   
@Override
@Nullable
public Choice<Unifier> visitThrow(ThrowTree throwStmt, @Nullable Unifier unifier) {
  return getExpression().unify(throwStmt.getExpression(), unifier);
}
项目:checker-framework    文件:ThrowNode.java   
public ThrowNode(ThrowTree tree,
        Node expression, Types types) {
    super(types.getNoType(TypeKind.NONE));
    this.tree = tree;
    this.expression = expression;
}
项目:checker-framework    文件:PurityChecker.java   
@Override
public PurityResult visitThrow(ThrowTree node, PurityResult p) {
    return scan(node.getExpression(), p);
}