Java Code Examples for com.sun.source.tree.CatchTree#getParameter()

The following examples show how to use com.sun.source.tree.CatchTree#getParameter() . 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: ModelChecker.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
@Override
public Void visitCatch(CatchTree node, Void p) {
    TreePath param = new TreePath(getCurrentPath(), node.getParameter());
    Element ex = trees.getElement(param);
    validateUnionTypeInfo(ex);
    if (ex.getSimpleName().contentEquals("ex")) {
        assertTrue(ex.getKind() == ElementKind.EXCEPTION_PARAMETER, "Expected EXCEPTION_PARAMETER - found " + ex.getKind());
        for (Element e : types.asElement(trees.getLub(node)).getEnclosedElements()) {
            Member m = e.getAnnotation(Member.class);
            if (m != null) {
                assertTrue(e.getKind() == m.value(), "Expected " + m.value() + " - found " + e.getKind());
            }
        }
        assertTrue(assertionCount == 9, "Expected 9 assertions - found " + assertionCount);
    }
    return super.visitCatch(node, p);
}
 
Example 2
Source File: ModelChecker.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
@Override
public Void visitCatch(CatchTree node, Void p) {
    TreePath param = new TreePath(getCurrentPath(), node.getParameter());
    Element ex = trees.getElement(param);
    validateUnionTypeInfo(ex);
    if (ex.getSimpleName().contentEquals("ex")) {
        assertTrue(ex.getKind() == ElementKind.EXCEPTION_PARAMETER, "Expected EXCEPTION_PARAMETER - found " + ex.getKind());
        for (Element e : types.asElement(trees.getLub(node)).getEnclosedElements()) {
            Member m = e.getAnnotation(Member.class);
            if (m != null) {
                assertTrue(e.getKind() == m.value(), "Expected " + m.value() + " - found " + e.getKind());
            }
        }
        assertTrue(assertionCount == 9, "Expected 9 assertions - found " + assertionCount);
    }
    return super.visitCatch(node, p);
}
 
Example 3
Source File: JavaInputAstVisitor.java    From java-n-IDE-for-Android with Apache License 2.0 6 votes vote down vote up
/**
 * Helper method for {@link CatchTree}s.
 */
private void visitCatchClause(CatchTree node, AllowTrailingBlankLine allowTrailingBlankLine) {
    sync(node);
    builder.space();
    token("catch");
    builder.space();
    token("(");
    builder.open(plusFour);
    VariableTree ex = node.getParameter();
    if (ex.getType().getKind() == UNION_TYPE) {
        builder.open(ZERO);
        visitUnionType(ex);
        builder.close();
    } else {
        // TODO(cushon): don't break after here for consistency with for, while, etc.
        builder.breakToFill();
        builder.open(ZERO);
        scan(ex, null);
        builder.close();
    }
    builder.close();
    token(")");
    builder.space();
    visitBlock(
            node.getBlock(), CollapseEmptyOrNot.NO, AllowLeadingBlankLine.YES, allowTrailingBlankLine);
}
 
Example 4
Source File: ModelChecker.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
@Override
public Void visitCatch(CatchTree node, Void p) {
    TreePath param = new TreePath(getCurrentPath(), node.getParameter());
    Element ex = trees.getElement(param);
    validateUnionTypeInfo(ex);
    if (ex.getSimpleName().contentEquals("ex")) {
        assertTrue(ex.getKind() == ElementKind.EXCEPTION_PARAMETER, "Expected EXCEPTION_PARAMETER - found " + ex.getKind());
        for (Element e : types.asElement(trees.getLub(node)).getEnclosedElements()) {
            Member m = e.getAnnotation(Member.class);
            if (m != null) {
                assertTrue(e.getKind() == m.value(), "Expected " + m.value() + " - found " + e.getKind());
            }
        }
        assertTrue(assertionCount == 9, "Expected 9 assertions - found " + assertionCount);
    }
    return super.visitCatch(node, p);
}
 
Example 5
Source File: ModelChecker.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
@Override
public Void visitCatch(CatchTree node, Void p) {
    TreePath param = new TreePath(getCurrentPath(), node.getParameter());
    Element ex = trees.getElement(param);
    validateUnionTypeInfo(ex);
    if (ex.getSimpleName().contentEquals("ex")) {
        assertTrue(ex.getKind() == ElementKind.EXCEPTION_PARAMETER, "Expected EXCEPTION_PARAMETER - found " + ex.getKind());
        for (Element e : types.asElement(trees.getLub(node)).getEnclosedElements()) {
            Member m = e.getAnnotation(Member.class);
            if (m != null) {
                assertTrue(e.getKind() == m.value(), "Expected " + m.value() + " - found " + e.getKind());
            }
        }
        assertTrue(assertionCount == 9, "Expected 9 assertions - found " + assertionCount);
    }
    return super.visitCatch(node, p);
}
 
Example 6
Source File: JavaInputAstVisitor.java    From javaide with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Helper method for {@link CatchTree}s.
 */
private void visitCatchClause(CatchTree node, AllowTrailingBlankLine allowTrailingBlankLine) {
    sync(node);
    builder.space();
    token("catch");
    builder.space();
    token("(");
    builder.open(plusFour);
    VariableTree ex = node.getParameter();
    if (ex.getType().getKind() == UNION_TYPE) {
        builder.open(ZERO);
        visitUnionType(ex);
        builder.close();
    } else {
        // TODO(cushon): don't break after here for consistency with for, while, etc.
        builder.breakToFill();
        builder.open(ZERO);
        scan(ex, null);
        builder.close();
    }
    builder.close();
    token(")");
    builder.space();
    visitBlock(
            node.getBlock(), CollapseEmptyOrNot.NO, AllowLeadingBlankLine.YES, allowTrailingBlankLine);
}
 
Example 7
Source File: ModelChecker.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
@Override
public Void visitCatch(CatchTree node, Void p) {
    TreePath param = new TreePath(getCurrentPath(), node.getParameter());
    Element ex = trees.getElement(param);
    validateUnionTypeInfo(ex);
    if (ex.getSimpleName().contentEquals("ex")) {
        assertTrue(ex.getKind() == ElementKind.EXCEPTION_PARAMETER, "Expected EXCEPTION_PARAMETER - found " + ex.getKind());
        for (Element e : types.asElement(trees.getLub(node)).getEnclosedElements()) {
            Member m = e.getAnnotation(Member.class);
            if (m != null) {
                assertTrue(e.getKind() == m.value(), "Expected " + m.value() + " - found " + e.getKind());
            }
        }
        assertTrue(assertionCount == 9, "Expected 9 assertions - found " + assertionCount);
    }
    return super.visitCatch(node, p);
}
 
Example 8
Source File: ModelChecker.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
@Override
public Void visitCatch(CatchTree node, Void p) {
    TreePath param = new TreePath(getCurrentPath(), node.getParameter());
    Element ex = trees.getElement(param);
    validateUnionTypeInfo(ex);
    if (ex.getSimpleName().contentEquals("ex")) {
        assertTrue(ex.getKind() == ElementKind.EXCEPTION_PARAMETER, "Expected EXCEPTION_PARAMETER - found " + ex.getKind());
        for (Element e : types.asElement(trees.getLub(node)).getEnclosedElements()) {
            Member m = e.getAnnotation(Member.class);
            if (m != null) {
                assertTrue(e.getKind() == m.value(), "Expected " + m.value() + " - found " + e.getKind());
            }
        }
        assertTrue(assertionCount == 9, "Expected 9 assertions - found " + assertionCount);
    }
    return super.visitCatch(node, p);
}
 
Example 9
Source File: ModelChecker.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
@Override
public Void visitCatch(CatchTree node, Void p) {
    TreePath param = new TreePath(getCurrentPath(), node.getParameter());
    Element ex = trees.getElement(param);
    validateUnionTypeInfo(ex);
    if (ex.getSimpleName().contentEquals("ex")) {
        assertTrue(ex.getKind() == ElementKind.EXCEPTION_PARAMETER, "Expected EXCEPTION_PARAMETER - found " + ex.getKind());
        for (Element e : types.asElement(trees.getLub(node)).getEnclosedElements()) {
            Member m = e.getAnnotation(Member.class);
            if (m != null) {
                assertTrue(e.getKind() == m.value(), "Expected " + m.value() + " - found " + e.getKind());
            }
        }
        assertTrue(assertionCount == 9, "Expected 9 assertions - found " + assertionCount);
    }
    return super.visitCatch(node, p);
}
 
Example 10
Source File: ModelChecker.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
@Override
public Void visitCatch(CatchTree node, Void p) {
    TreePath param = new TreePath(getCurrentPath(), node.getParameter());
    Element ex = trees.getElement(param);
    validateUnionTypeInfo(ex);
    if (ex.getSimpleName().contentEquals("ex")) {
        assertTrue(ex.getKind() == ElementKind.EXCEPTION_PARAMETER, "Expected EXCEPTION_PARAMETER - found " + ex.getKind());
        for (Element e : types.asElement(trees.getLub(node)).getEnclosedElements()) {
            Member m = e.getAnnotation(Member.class);
            if (m != null) {
                assertTrue(e.getKind() == m.value(), "Expected " + m.value() + " - found " + e.getKind());
            }
        }
        assertTrue(assertionCount == 9, "Expected 9 assertions - found " + assertionCount);
    }
    return super.visitCatch(node, p);
}
 
Example 11
Source File: JavaInputAstVisitor.java    From google-java-format with Apache License 2.0 6 votes vote down vote up
/** Helper method for {@link CatchTree}s. */
private void visitCatchClause(CatchTree node, AllowTrailingBlankLine allowTrailingBlankLine) {
  sync(node);
  builder.space();
  token("catch");
  builder.space();
  token("(");
  builder.open(plusFour);
  VariableTree ex = node.getParameter();
  if (ex.getType().getKind() == UNION_TYPE) {
    builder.open(ZERO);
    visitUnionType(ex);
    builder.close();
  } else {
    // TODO(cushon): don't break after here for consistency with for, while, etc.
    builder.breakToFill();
    builder.open(ZERO);
    scan(ex, null);
    builder.close();
  }
  builder.close();
  token(")");
  builder.space();
  visitBlock(
      node.getBlock(), CollapseEmptyOrNot.NO, AllowLeadingBlankLine.YES, allowTrailingBlankLine);
}
 
Example 12
Source File: UncaughtException.java    From netbeans with Apache License 2.0 4 votes vote down vote up
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;
}
 
Example 13
Source File: Utilities.java    From netbeans with Apache License 2.0 3 votes vote down vote up
/**
 * Helper that retrieves all caught exception from a conventional catch
 * clause or from catch clause that contain alternatives. Empty collection
 * is returned in the case of an error.
 * 
 * @param ct catch clause
 * @return exception list, never null.
 */
public static List<? extends TypeMirror> getUnionExceptions(CompilationInfo info, TreePath cP, CatchTree ct) {
    if (ct.getParameter() == null) {
        return Collections.emptyList();
    }
    TypeMirror exT = info.getTrees().getTypeMirror(new TreePath(cP, ct.getParameter()));
    return getCaughtExceptions(exT);
}