com.sun.source.doctree.ThrowsTree Java Examples
The following examples show how to use
com.sun.source.doctree.ThrowsTree.
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: Checker.java From jdk8u60 with GNU General Public License v2.0 | 6 votes |
@Override public Void visitThrows(ThrowsTree tree, Void ignore) { ReferenceTree exName = tree.getExceptionName(); Element ex = env.trees.getElement(new DocTreePath(getCurrentPath(), exName)); if (ex == null) { env.messages.error(REFERENCE, tree, "dc.ref.not.found"); } else if (isThrowable(ex.asType())) { switch (env.currElement.getKind()) { case CONSTRUCTOR: case METHOD: if (isCheckedException(ex.asType())) { ExecutableElement ee = (ExecutableElement) env.currElement; checkThrowsDeclared(exName, ex.asType(), ee.getThrownTypes()); } break; default: env.messages.error(REFERENCE, tree, "dc.invalid.throws"); } } else { env.messages.error(REFERENCE, tree, "dc.invalid.throws"); } warnIfEmpty(tree, tree.getDescription()); return scan(tree.getDescription(), ignore); }
Example #2
Source File: Checker.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
@Override public Void visitThrows(ThrowsTree tree, Void ignore) { ReferenceTree exName = tree.getExceptionName(); Element ex = env.trees.getElement(new DocTreePath(getCurrentPath(), exName)); if (ex == null) { env.messages.error(REFERENCE, tree, "dc.ref.not.found"); } else if (isThrowable(ex.asType())) { switch (env.currElement.getKind()) { case CONSTRUCTOR: case METHOD: if (isCheckedException(ex.asType())) { ExecutableElement ee = (ExecutableElement) env.currElement; checkThrowsDeclared(exName, ex.asType(), ee.getThrownTypes()); } break; default: env.messages.error(REFERENCE, tree, "dc.invalid.throws"); } } else { env.messages.error(REFERENCE, tree, "dc.invalid.throws"); } warnIfEmpty(tree, tree.getDescription()); return scan(tree.getDescription(), ignore); }
Example #3
Source File: Checker.java From openjdk-8 with GNU General Public License v2.0 | 6 votes |
@Override public Void visitThrows(ThrowsTree tree, Void ignore) { ReferenceTree exName = tree.getExceptionName(); Element ex = env.trees.getElement(new DocTreePath(getCurrentPath(), exName)); if (ex == null) { env.messages.error(REFERENCE, tree, "dc.ref.not.found"); } else if (isThrowable(ex.asType())) { switch (env.currElement.getKind()) { case CONSTRUCTOR: case METHOD: if (isCheckedException(ex.asType())) { ExecutableElement ee = (ExecutableElement) env.currElement; checkThrowsDeclared(exName, ex.asType(), ee.getThrownTypes()); } break; default: env.messages.error(REFERENCE, tree, "dc.invalid.throws"); } } else { env.messages.error(REFERENCE, tree, "dc.invalid.throws"); } warnIfEmpty(tree, tree.getDescription()); return scan(tree.getDescription(), ignore); }
Example #4
Source File: Checker.java From openjdk-8-source with GNU General Public License v2.0 | 6 votes |
@Override public Void visitThrows(ThrowsTree tree, Void ignore) { ReferenceTree exName = tree.getExceptionName(); Element ex = env.trees.getElement(new DocTreePath(getCurrentPath(), exName)); if (ex == null) { env.messages.error(REFERENCE, tree, "dc.ref.not.found"); } else if (isThrowable(ex.asType())) { switch (env.currElement.getKind()) { case CONSTRUCTOR: case METHOD: if (isCheckedException(ex.asType())) { ExecutableElement ee = (ExecutableElement) env.currElement; checkThrowsDeclared(exName, ex.asType(), ee.getThrownTypes()); } break; default: env.messages.error(REFERENCE, tree, "dc.invalid.throws"); } } else { env.messages.error(REFERENCE, tree, "dc.invalid.throws"); } warnIfEmpty(tree, tree.getDescription()); return scan(tree.getDescription(), ignore); }
Example #5
Source File: Checker.java From hottub with GNU General Public License v2.0 | 6 votes |
@Override public Void visitThrows(ThrowsTree tree, Void ignore) { ReferenceTree exName = tree.getExceptionName(); Element ex = env.trees.getElement(new DocTreePath(getCurrentPath(), exName)); if (ex == null) { env.messages.error(REFERENCE, tree, "dc.ref.not.found"); } else if (isThrowable(ex.asType())) { switch (env.currElement.getKind()) { case CONSTRUCTOR: case METHOD: if (isCheckedException(ex.asType())) { ExecutableElement ee = (ExecutableElement) env.currElement; checkThrowsDeclared(exName, ex.asType(), ee.getThrownTypes()); } break; default: env.messages.error(REFERENCE, tree, "dc.invalid.throws"); } } else { env.messages.error(REFERENCE, tree, "dc.invalid.throws"); } warnIfEmpty(tree, tree.getDescription()); return scan(tree.getDescription(), ignore); }
Example #6
Source File: Checker.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
@Override @DefinedBy(Api.COMPILER_TREE) public Void visitThrows(ThrowsTree tree, Void ignore) { ReferenceTree exName = tree.getExceptionName(); Element ex = env.trees.getElement(new DocTreePath(getCurrentPath(), exName)); if (ex == null) { env.messages.error(REFERENCE, tree, "dc.ref.not.found"); } else if (isThrowable(ex.asType())) { switch (env.currElement.getKind()) { case CONSTRUCTOR: case METHOD: if (isCheckedException(ex.asType())) { ExecutableElement ee = (ExecutableElement) env.currElement; checkThrowsDeclared(exName, ex.asType(), ee.getThrownTypes()); } break; default: env.messages.error(REFERENCE, tree, "dc.invalid.throws"); } } else { env.messages.error(REFERENCE, tree, "dc.invalid.throws"); } warnIfEmpty(tree, tree.getDescription()); return scan(tree.getDescription(), ignore); }
Example #7
Source File: Checker.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 6 votes |
@Override public Void visitThrows(ThrowsTree tree, Void ignore) { ReferenceTree exName = tree.getExceptionName(); Element ex = env.trees.getElement(new DocTreePath(getCurrentPath(), exName)); if (ex == null) { env.messages.error(REFERENCE, tree, "dc.ref.not.found"); } else if (isThrowable(ex.asType())) { switch (env.currElement.getKind()) { case CONSTRUCTOR: case METHOD: if (isCheckedException(ex.asType())) { ExecutableElement ee = (ExecutableElement) env.currElement; checkThrowsDeclared(exName, ex.asType(), ee.getThrownTypes()); } break; default: env.messages.error(REFERENCE, tree, "dc.invalid.throws"); } } else { env.messages.error(REFERENCE, tree, "dc.invalid.throws"); } warnIfEmpty(tree, tree.getDescription()); return scan(tree.getDescription(), ignore); }
Example #8
Source File: Checker.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
@Override public Void visitThrows(ThrowsTree tree, Void ignore) { ReferenceTree exName = tree.getExceptionName(); Element ex = env.trees.getElement(new DocTreePath(getCurrentPath(), exName)); if (ex == null) { env.messages.error(REFERENCE, tree, "dc.ref.not.found"); } else if (isThrowable(ex.asType())) { switch (env.currElement.getKind()) { case CONSTRUCTOR: case METHOD: if (isCheckedException(ex.asType())) { ExecutableElement ee = (ExecutableElement) env.currElement; checkThrowsDeclared(exName, ex.asType(), ee.getThrownTypes()); } break; default: env.messages.error(REFERENCE, tree, "dc.invalid.throws"); } } else { env.messages.error(REFERENCE, tree, "dc.invalid.throws"); } warnIfEmpty(tree, tree.getDescription()); return scan(tree.getDescription(), ignore); }
Example #9
Source File: Analyzer.java From netbeans with Apache License 2.0 | 5 votes |
@NbBundle.Messages({"# {0} - [@throws|@exception]", "# {1} - @throws name", "DUPLICATE_THROWS_DESC=Duplicate @{0} tag: {1}", "# {0} - [@throws|@exception]", "# {1} - @throws name", "UNKNOWN_THROWABLE_DESC=Unknown throwable: @{0} {1}"}) private void checkThrowsDeclared(ThrowsTree tree, Element ex, String fqn, List<? extends TypeMirror> list, DocTreePathHandle dtph, int start, int end, List<ErrorDescription> errors) { boolean found = false; final TypeMirror type; if(ex != null) { type = ex.asType(); } else { TypeElement typeElement = javac.getElements().getTypeElement(fqn); if(typeElement != null) { type = typeElement.asType(); } else { type = null; } } for (TypeMirror t: list) { if(ctx.isCanceled()) { return; } if(type != null && javac.getTypes().isAssignable(type, t)) { if(!foundThrows.add(type)) { errors.add(ErrorDescriptionFactory.forSpan(ctx, start, end, DUPLICATE_THROWS_DESC(tree.getTagName(), fqn), new RemoveTagFix(dtph, "@" + tree.getTagName()).toEditorFix())); } found = true; break; } if (type == null && fqn.equals(t.toString())) { if(!foundThrows.add(t)) { errors.add(ErrorDescriptionFactory.forSpan(ctx, start, end, DUPLICATE_THROWS_DESC(tree.getTagName(), fqn), new RemoveTagFix(dtph, "@" + tree.getTagName()).toEditorFix())); } found = true; break; } } if (!found) { errors.add(ErrorDescriptionFactory.forSpan(ctx, start, end, UNKNOWN_THROWABLE_DESC(tree.getTagName(), fqn), new RemoveTagFix(dtph, "@" + tree.getTagName()).toEditorFix())); } }
Example #10
Source File: CommentHelper.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
public Element getException(Configuration c, DocTree dtree) { if (dtree.getKind() == THROWS || dtree.getKind() == EXCEPTION) { ThrowsTree tt = (ThrowsTree)dtree; ReferenceTree exceptionName = tt.getExceptionName(); return getElement(c, exceptionName); } return null; }
Example #11
Source File: ImmutableDocTreeTranslator.java From netbeans with Apache License 2.0 | 5 votes |
protected final ThrowsTree rewriteChildren(ThrowsTree tree) { ThrowsTree value = tree; ReferenceTree exception = (ReferenceTree) translate(tree.getExceptionName()); List<? extends DocTree> description = translateDoc(tree.getDescription()); if (exception != tree.getExceptionName() || description != tree.getDescription()) { value = make.Throws(exception, description); } return value; }
Example #12
Source File: VeryPretty.java From netbeans with Apache License 2.0 | 5 votes |
@Override public Void visitThrows(ThrowsTree node, Void p) { printTagName(node); needSpace(); doAccept((DCTree)node.getExceptionName()); if(!node.getDescription().isEmpty()) { needSpace(); for (DocTree docTree : node.getDescription()) { doAccept((DCTree)docTree); } } return null; }
Example #13
Source File: JavadocFormatter.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
@Override @DefinedBy(Api.COMPILER_TREE) public Object visitThrows(ThrowsTree node, Object p) { return formatDef(node.getExceptionName().getSignature(), node.getDescription()); }
Example #14
Source File: JavadocConverter.java From j2objc with Apache License 2.0 | 4 votes |
@Override public Void visitThrows(ThrowsTree node, TagElement tag) { setTagValues(tag, TagElement.TagKind.THROWS, node, node.getExceptionName()); scan(node.getDescription(), tag); return null; }
Example #15
Source File: CommentHelper.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
public ReferenceTree getExceptionName(DocTree dtree) { return (dtree.getKind() == THROWS || dtree.getKind() == EXCEPTION) ? ((ThrowsTree)dtree).getExceptionName() : null; }
Example #16
Source File: ImmutableDocTreeTranslator.java From netbeans with Apache License 2.0 | 4 votes |
@Override public DocTree visitThrows(ThrowsTree tree, Object p) { return rewriteChildren(tree); }
Example #17
Source File: JavadocHelper.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
private String getThrownException(JavacTask task, TreePath rootOn, DocCommentTree comment, ThrowsTree tt) { DocTrees trees = DocTrees.instance(task); Element exc = trees.getElement(new DocTreePath(new DocTreePath(rootOn, comment), tt.getExceptionName())); return exc != null ? exc.toString() : null; }
Example #18
Source File: TreeFactory.java From netbeans with Apache License 2.0 | 4 votes |
public ThrowsTree Throws(ReferenceTree name, List<? extends DocTree> description) { return docMake.at(NOPOS).newThrowsTree(name, description); }
Example #19
Source File: Analyzer.java From netbeans with Apache License 2.0 | 4 votes |
private void findInheritedParams(ExecutableElement method, TypeElement typeElement, Set<String> inheritedParams, Set<String> inheritedTypeParams, Set<String> inheritedThrows) { if(typeElement == null) return; List<TypeMirror> superTypes = new ArrayList<>(); superTypes.add(typeElement.getSuperclass()); superTypes.addAll(typeElement.getInterfaces()); for (TypeMirror typeMirror : superTypes) { for (Element el : javac.getElementUtilities().getMembers(typeMirror, (e, type) -> e.getKind() == ElementKind.METHOD)) { if(ctx.isCanceled()) { return; } if(javac.getElements().overrides(method, (ExecutableElement) el, typeElement)) { ElementHandle<ExecutableElement> overriddenMethod = ElementHandle.create((ExecutableElement) el); FileObject source = SourceUtils.getFile(overriddenMethod, ctx.getInfo().getClasspathInfo()); if (source == null) { continue; } try { JavaSource.forFileObject(source).runUserActionTask(cc -> { cc.toPhase(Phase.ELEMENTS_RESOLVED); if (ctx.isCanceled()) { return ; //cancel } ExecutableElement m = overriddenMethod.resolve(cc); TreePath tp = m != null ? cc.getTrees().getPath(m) : null; if (tp == null) { return ; //TODO: log??? } DocCommentTree methodDoc = cc.getDocTrees().getDocCommentTree(tp); if(methodDoc != null) { for (DocTree tag : methodDoc.getBlockTags()) { switch (tag.getKind()) { case PARAM: String name = ((ParamTree) tag).getName().getName().toString(); if (((ParamTree) tag).isTypeParameter()) { inheritedTypeParams.add(name); } else { inheritedParams.add(name); } break; case THROWS: Element thrownType = cc.getDocTrees().getElement(new DocTreePath(new DocTreePath(new DocTreePath(tp, methodDoc), tag), ((ThrowsTree) tag).getExceptionName())); if (thrownType != null && thrownType.getKind().isClass()) { inheritedThrows.add(((TypeElement) thrownType).getQualifiedName().toString()); } break; case RETURN: returnTypeFound |= true; } } } }, true); } catch (IOException ex) { LOG.log(Level.FINE, null, ex); } } } } }
Example #20
Source File: Analyzer.java From netbeans with Apache License 2.0 | 4 votes |
@Override public Void visitThrows(ThrowsTree tree, List<ErrorDescription> errors) { boolean oldInheritDoc = foundInheritDoc; ReferenceTree exName = tree.getExceptionName(); DocTreePath refPath = new DocTreePath(getCurrentPath(), tree.getExceptionName()); Element ex = javac.getDocTrees().getElement(refPath); Types types = javac.getTypes(); Elements elements = javac.getElements(); final TypeElement throwableEl = elements.getTypeElement("java.lang.Throwable"); final TypeElement errorEl = elements.getTypeElement("java.lang.Error"); final TypeElement runtimeEl = elements.getTypeElement("java.lang.RuntimeException"); if(throwableEl == null || errorEl == null || runtimeEl == null) { LOG.warning("Broken java-platform, cannot resolve " + throwableEl == null? "java.lang.Throwable" : errorEl == null? "java.lang.Error" : "java.lang.RuntimeException"); //NOI18N return null; } TypeMirror throwable = throwableEl.asType(); TypeMirror error = errorEl.asType(); TypeMirror runtime = runtimeEl.asType(); DocTreePath currentDocPath = getCurrentPath(); DocTreePathHandle dtph = DocTreePathHandle.create(currentDocPath, javac); if(dtph == null) { return null; } DocSourcePositions sp = (DocSourcePositions) javac.getTrees().getSourcePositions(); int start = (int) sp.getStartPosition(javac.getCompilationUnit(), currentDocPath.getDocComment(), tree); int end = (int) sp.getEndPosition(javac.getCompilationUnit(), currentDocPath.getDocComment(), tree); if (ex == null || (ex.asType().getKind() == TypeKind.DECLARED && types.isAssignable(ex.asType(), throwable))) { switch (currentElement.getKind()) { case CONSTRUCTOR: case METHOD: if (ex == null || !(types.isAssignable(ex.asType(), error) || types.isAssignable(ex.asType(), runtime))) { ExecutableElement ee = (ExecutableElement) currentElement; String fqn; if (ex != null) { fqn = ((TypeElement) ex).getQualifiedName().toString(); } else { ExpressionTree referenceClass = javac.getTreeUtilities().getReferenceClass(new DocTreePath(currentDocPath, exName)); if(referenceClass == null) break; fqn = referenceClass.toString(); } checkThrowsDeclared(tree, ex, fqn, ee.getThrownTypes(), dtph, start, end, errors); } break; default: // env.messages.error(REFERENCE, tree, "dc.invalid.throws"); } } else { // env.messages.error(REFERENCE, tree, "dc.invalid.throws"); } warnIfEmpty(tree, tree.getDescription()); super.visitThrows(tree, errors); foundInheritDoc = oldInheritDoc; return null; }
Example #21
Source File: TreeFactory.java From netbeans with Apache License 2.0 | 4 votes |
public ThrowsTree Exception(ReferenceTree name, List<? extends DocTree> description) { return docMake.at(NOPOS).newExceptionTree(name, description); }
Example #22
Source File: RefactoringVisitor.java From netbeans with Apache License 2.0 | 4 votes |
public DocTree visitThrows(ThrowsTree node, Element p, Void ignore) { return super.visitThrows(node, p); }
Example #23
Source File: RefactoringVisitor.java From netbeans with Apache License 2.0 | 4 votes |
@Override public DocTree visitThrows(ThrowsTree node, Element p) { return instance.visitThrows(node, p); }
Example #24
Source File: RefactoringVisitor.java From netbeans with Apache License 2.0 | 4 votes |
/** * @since 1.47 */ @Override public DocTree visitThrows(ThrowsTree node, Element p) { return docScanner.visitThrows(node, p, null); }
Example #25
Source File: TreeMaker.java From netbeans with Apache License 2.0 | 2 votes |
/**Creates the DocTree's ThrowsTree that will produce @throws. * * @param name reference to the documented exception * @param description the description of the thrown exception * @return newly created ThrowsTree * @since 0.124 */ public ThrowsTree Throws(ReferenceTree name, List<? extends DocTree> description) { return delegate.Throws(name, description); }
Example #26
Source File: DocTreeFactory.java From openjdk-jdk9 with GNU General Public License v2.0 | 2 votes |
/** * Create a new {@code ExceptionTree} object, to represent an {@code @exception } tag. * @param name the name of the exception * @param description a description of why the exception might be thrown * @return an {@code ExceptionTree} object */ ThrowsTree newExceptionTree(ReferenceTree name, List<? extends DocTree> description);
Example #27
Source File: DocTreeFactory.java From openjdk-jdk9 with GNU General Public License v2.0 | 2 votes |
/** * Create a new {@code ThrowsTree} object, to represent a {@code @throws } tag. * @param name the name of the exception * @param description a description of why the exception might be thrown * @return a {@code ThrowsTree} object */ ThrowsTree newThrowsTree(ReferenceTree name, List<? extends DocTree> description);
Example #28
Source File: DocTreeFactory.java From lua-for-android with BSD 3-Clause "New" or "Revised" License | 2 votes |
/** * Create a new {@code ThrowsTree} object, to represent a {@code @throws } tag. * @param name the name of the exception * @param description a description of why the exception might be thrown * @return a {@code ThrowsTree} object */ ThrowsTree newThrowsTree(ReferenceTree name, List<? extends DocTree> description);
Example #29
Source File: DocTreeFactory.java From lua-for-android with BSD 3-Clause "New" or "Revised" License | 2 votes |
/** * Create a new {@code ExceptionTree} object, to represent an {@code @exception } tag. * @param name the name of the exception * @param description a description of why the exception might be thrown * @return an {@code ExceptionTree} object */ ThrowsTree newExceptionTree(ReferenceTree name, List<? extends DocTree> description);
Example #30
Source File: TreeMaker.java From netbeans with Apache License 2.0 | 2 votes |
/**Creates the DocTree's ThrowsTree that will produce @exception. * * @param name reference to the documented exception * @param description the description of the thrown exception * @return newly created Exception * @since 0.124 */ public ThrowsTree Exception(ReferenceTree name, List<? extends DocTree> description) { return delegate.Exception(name, description); }