src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/taglets/ThrowsTaglet.java
Print this page
@@ -1,7 +1,7 @@
/*
- * Copyright (c) 2001, 2014, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2001, 2015, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
@@ -21,18 +21,29 @@
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
-package com.sun.tools.doclets.internal.toolkit.taglets;
+package jdk.javadoc.internal.doclets.toolkit.taglets;
import java.util.*;
+import java.util.Map.Entry;
-import com.sun.javadoc.*;
-import com.sun.tools.doclets.internal.toolkit.Content;
-import com.sun.tools.doclets.internal.toolkit.util.*;
+import javax.lang.model.element.Element;
+import javax.lang.model.element.ExecutableElement;
+import javax.lang.model.element.TypeElement;
+import javax.lang.model.type.TypeMirror;
+import com.sun.source.doctree.DocTree;
+import jdk.javadoc.internal.doclets.toolkit.Content;
+import jdk.javadoc.internal.doclets.toolkit.util.CommentHelper;
+import jdk.javadoc.internal.doclets.toolkit.util.DocFinder;
+import jdk.javadoc.internal.doclets.toolkit.util.DocFinder.Input;
+import jdk.javadoc.internal.doclets.toolkit.util.Utils;
+
+import static com.sun.source.doctree.DocTree.Kind.*;
+
/**
* A taglet that represents the @throws tag.
*
* <p><b>This is NOT part of any supported API.
* If you write code that depends on this, you do so at your own risk.
@@ -44,116 +55,122 @@
*/
public class ThrowsTaglet extends BaseExecutableMemberTaglet
implements InheritableTaglet {
public ThrowsTaglet() {
- name = "throws";
+ name = THROWS.tagName;
}
/**
* {@inheritDoc}
*/
+ @Override
public void inherit(DocFinder.Input input, DocFinder.Output output) {
- ClassDoc exception;
+ Utils utils = input.utils;
+ Element exception;
+ CommentHelper ch = utils.getCommentHelper(input.element);
if (input.tagId == null) {
- ThrowsTag throwsTag = (ThrowsTag) input.tag;
- exception = throwsTag.exception();
- input.tagId = exception == null ?
- throwsTag.exceptionName() :
- throwsTag.exception().qualifiedName();
+ exception = ch.getException(utils.configuration, input.docTreeInfo.docTree);
+ input.tagId = exception == null
+ ? ch.getExceptionName(input.docTreeInfo.docTree).getSignature()
+ : utils.getFullyQualifiedName(exception);
} else {
- exception = input.element.containingClass().findClass(input.tagId);
+ TypeElement element = input.utils.findClass(input.element, input.tagId);
+ exception = (element == null) ? null : element;
}
- for (ThrowsTag tag : ((MethodDoc)input.element).throwsTags()) {
- if (input.tagId.equals(tag.exceptionName()) ||
- (tag.exception() != null &&
- (input.tagId.equals(tag.exception().qualifiedName())))) {
+ for (DocTree dt : input.utils.getThrowsTrees(input.element)) {
+ Element texception = ch.getException(utils.configuration, dt);
+ if (texception != null && (input.tagId.equals(utils.getSimpleName(texception)) ||
+ (input.tagId.equals(utils.getFullyQualifiedName(texception))))) {
output.holder = input.element;
- output.holderTag = tag;
- output.inlineTags = input.isFirstSentence ?
- tag.firstSentenceTags() : tag.inlineTags();
- output.tagList.add(tag);
- } else if (exception != null && tag.exception() != null &&
- tag.exception().subclassOf(exception)) {
- output.tagList.add(tag);
+ output.holderTag = dt;
+ output.inlineTags = ch.getBody(input.utils.configuration, output.holderTag);
+ output.tagList.add(dt);
+ } else if (exception != null && texception != null &&
+ utils.isTypeElement(texception) && utils.isTypeElement(exception) &&
+ utils.isSubclassOf((TypeElement)texception, (TypeElement)exception)) {
+ output.tagList.add(dt);
}
}
}
/**
* Add links for exceptions that are declared but not documented.
*/
- private Content linkToUndocumentedDeclaredExceptions(
- Type[] declaredExceptionTypes, Set<String> alreadyDocumented,
- TagletWriter writer) {
+ private Content linkToUndocumentedDeclaredExceptions(List<? extends TypeMirror> declaredExceptionTypes,
+ Set<String> alreadyDocumented, TagletWriter writer) {
+ Utils utils = writer.configuration().utils;
Content result = writer.getOutputInstance();
//Add links to the exceptions declared but not documented.
- for (Type declaredExceptionType : declaredExceptionTypes) {
- if (declaredExceptionType.asClassDoc() != null &&
- !alreadyDocumented.contains(
- declaredExceptionType.asClassDoc().name()) &&
- !alreadyDocumented.contains(
- declaredExceptionType.asClassDoc().qualifiedName())) {
- if (alreadyDocumented.size() == 0) {
+ for (TypeMirror declaredExceptionType : declaredExceptionTypes) {
+ TypeElement klass = utils.asTypeElement(declaredExceptionType);
+ if (klass != null &&
+ !alreadyDocumented.contains(utils.getSimpleName(klass)) &&
+ !alreadyDocumented.contains(utils.getFullyQualifiedName(klass))) {
+ if (alreadyDocumented.isEmpty()) {
result.addContent(writer.getThrowsHeader());
}
result.addContent(writer.throwsTagOutput(declaredExceptionType));
- alreadyDocumented.add(declaredExceptionType.asClassDoc().name());
+ alreadyDocumented.add(utils.getSimpleName(klass));
}
}
return result;
}
/**
* Inherit throws documentation for exceptions that were declared but not
* documented.
*/
- private Content inheritThrowsDocumentation(Doc holder,
- Type[] declaredExceptionTypes, Set<String> alreadyDocumented,
+ private Content inheritThrowsDocumentation(Element holder,
+ List<? extends TypeMirror> declaredExceptionTypes, Set<String> alreadyDocumented,
TagletWriter writer) {
+ Utils utils = writer.configuration().utils;
Content result = writer.getOutputInstance();
- if (holder instanceof MethodDoc) {
- Set<Tag> declaredExceptionTags = new LinkedHashSet<>();
- for (Type declaredExceptionType : declaredExceptionTypes) {
- DocFinder.Output inheritedDoc =
- DocFinder.search(writer.configuration(), new DocFinder.Input((MethodDoc) holder, this,
- declaredExceptionType.typeName()));
- if (inheritedDoc.tagList.size() == 0) {
- inheritedDoc = DocFinder.search(writer.configuration(), new DocFinder.Input(
- (MethodDoc) holder, this,
- declaredExceptionType.qualifiedTypeName()));
+ if (utils.isExecutableElement(holder)) {
+ Map<List<? extends DocTree>, ExecutableElement> declaredExceptionTags = new LinkedHashMap<>();
+ for (TypeMirror declaredExceptionType : declaredExceptionTypes) {
+ Input input = new DocFinder.Input(utils, holder, this,
+ utils.getTypeName(declaredExceptionType, false));
+ DocFinder.Output inheritedDoc = DocFinder.search(writer.configuration(), input);
+ if (inheritedDoc.tagList.isEmpty()) {
+ String typeName = utils.getTypeName(declaredExceptionType, true);
+ input = new DocFinder.Input(utils, holder, this, typeName);
+ inheritedDoc = DocFinder.search(writer.configuration(), input);
}
- declaredExceptionTags.addAll(inheritedDoc.tagList);
+ if (!inheritedDoc.tagList.isEmpty()) {
+ if (inheritedDoc.holder == null) {
+ inheritedDoc.holder = holder;
}
- result.addContent(throwsTagsOutput(
- declaredExceptionTags.toArray(new ThrowsTag[] {}),
- writer, alreadyDocumented, false));
+ declaredExceptionTags.put(inheritedDoc.tagList, (ExecutableElement)inheritedDoc.holder);
}
+ }
+ result.addContent(throwsTagsOutput(declaredExceptionTags, writer, alreadyDocumented, false));
+ }
return result;
}
/**
* {@inheritDoc}
*/
- public Content getTagletOutput(Doc holder, TagletWriter writer) {
- ExecutableMemberDoc execHolder = (ExecutableMemberDoc) holder;
- ThrowsTag[] tags = execHolder.throwsTags();
+ public Content getTagletOutput(Element holder, TagletWriter writer) {
+ Utils utils = writer.configuration().utils;
+ ExecutableElement execHolder = (ExecutableElement) holder;
+ Map<List<? extends DocTree>, ExecutableElement> tagsMap = new LinkedHashMap<>();
+ tagsMap.put(utils.getThrowsTrees(execHolder), execHolder);
Content result = writer.getOutputInstance();
HashSet<String> alreadyDocumented = new HashSet<>();
- if (tags.length > 0) {
- result.addContent(throwsTagsOutput(
- execHolder.throwsTags(), writer, alreadyDocumented, true));
+ if (!tagsMap.isEmpty()) {
+ result.addContent(throwsTagsOutput(tagsMap, writer, alreadyDocumented, true));
}
result.addContent(inheritThrowsDocumentation(holder,
- execHolder.thrownExceptionTypes(), alreadyDocumented, writer));
+ execHolder.getThrownTypes(), alreadyDocumented, writer));
result.addContent(linkToUndocumentedDeclaredExceptions(
- execHolder.thrownExceptionTypes(), alreadyDocumented, writer));
+ execHolder.getThrownTypes(), alreadyDocumented, writer));
return result;
}
-
/**
* Given an array of <code>Tag</code>s representing this custom
* tag, return its string representation.
* @param throwTags the array of <code>ThrowsTag</code>s to convert.
* @param writer the TagletWriter that will write this tag.
@@ -160,26 +177,34 @@
* @param alreadyDocumented the set of exceptions that have already
* been documented.
* @param allowDups True if we allow duplicate throws tags to be documented.
* @return the Content representation of this <code>Tag</code>.
*/
- protected Content throwsTagsOutput(ThrowsTag[] throwTags,
+ protected Content throwsTagsOutput(Map<List<? extends DocTree>, ExecutableElement> throwTags,
TagletWriter writer, Set<String> alreadyDocumented, boolean allowDups) {
+ Utils utils = writer.configuration().utils;
Content result = writer.getOutputInstance();
- if (throwTags.length > 0) {
- for (ThrowsTag tt : throwTags) {
- ClassDoc cd = tt.exception();
- if ((!allowDups) && (alreadyDocumented.contains(tt.exceptionName()) ||
- (cd != null && alreadyDocumented.contains(cd.qualifiedName())))) {
+ if (!throwTags.isEmpty()) {
+ for (Entry<List<? extends DocTree>, ExecutableElement> entry : throwTags.entrySet()) {
+ CommentHelper ch = utils.getCommentHelper(entry.getValue());
+ Element e = entry.getValue();
+ for (DocTree dt : entry.getKey()) {
+ Element te = ch.getException(utils.configuration, dt);
+ String excName = ch.getExceptionName(dt).toString();
+ if ((!allowDups) &&
+ (alreadyDocumented.contains(excName) ||
+ (te != null && alreadyDocumented.contains(utils.getFullyQualifiedName(te))))) {
continue;
}
- if (alreadyDocumented.size() == 0) {
+ if (alreadyDocumented.isEmpty()) {
result.addContent(writer.getThrowsHeader());
}
- result.addContent(writer.throwsTagOutput(tt));
- alreadyDocumented.add(cd != null ?
- cd.qualifiedName() : tt.exceptionName());
+ result.addContent(writer.throwsTagOutput(e, dt));
+ alreadyDocumented.add(te != null
+ ? utils.getFullyQualifiedName(te)
+ : excName);
}
}
+ }
return result;
}
}