src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/util/DocFinder.java
Print this page
*** 1,7 ****
/*
! * Copyright (c) 2003, 2014, 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
--- 1,7 ----
/*
! * Copyright (c) 2003, 2016, 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,38 ****
* 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.util;
import java.util.*;
! import com.sun.javadoc.*;
! import com.sun.tools.doclets.internal.toolkit.Configuration;
! import com.sun.tools.doclets.internal.toolkit.taglets.*;
/**
* Search for the requested documentation. Inherit documentation if necessary.
*
* <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.
--- 21,43 ----
* 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 jdk.javadoc.internal.doclets.toolkit.util;
import java.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.Configuration;
+ import jdk.javadoc.internal.doclets.toolkit.taglets.InheritableTaglet;
+
/**
* Search for the requested documentation. Inherit documentation if necessary.
*
* <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.
*** 42,59 ****
* @author Jamie Ho
* @since 1.5
*/
public class DocFinder {
/**
* The class that encapsulates the input.
*/
public static class Input {
/**
* The element to search documentation from.
*/
! public ProgramElementDoc element;
/**
* The taglet to search for documentation on behalf of. Null if we want
* to search for overall documentation.
*/
public InheritableTaglet taglet = null;
--- 47,84 ----
* @author Jamie Ho
* @since 1.5
*/
public class DocFinder {
+ public static final class DocTreeInfo {
+ public final DocTree docTree;
+ public final Element element;
+
+ public DocTreeInfo() {
+ this.docTree = null;
+ this.element = null;
+ }
+
+ public DocTreeInfo(DocTree docTree, Element baseElement) {
+ this.docTree = docTree;
+ this.element = baseElement;
+ }
+
+ @Override
+ public String toString() {
+ return "DocTreeInfo{" + "docTree=" + docTree + ", element=" + element + '}';
+ }
+ }
+
/**
* The class that encapsulates the input.
*/
public static class Input {
/**
* The element to search documentation from.
*/
! public Element element;
/**
* The taglet to search for documentation on behalf of. Null if we want
* to search for overall documentation.
*/
public InheritableTaglet taglet = null;
*** 65,75 ****
/**
* The tag to retrieve documentation for. This is only used for the
* inheritDoc tag.
*/
! public Tag tag = null;
/**
* True if we only want to search for the first sentence.
*/
public boolean isFirstSentence = false;
--- 90,100 ----
/**
* The tag to retrieve documentation for. This is only used for the
* inheritDoc tag.
*/
! public final DocTreeInfo docTreeInfo;
/**
* True if we only want to search for the first sentence.
*/
public boolean isFirstSentence = false;
*** 83,143 ****
* Used to distinguish between type variable param tags and regular
* param tags.
*/
public boolean isTypeVariableParamTag = false;
! public Input(ProgramElementDoc element, InheritableTaglet taglet, Tag tag,
boolean isFirstSentence, boolean isInheritDocTag) {
! this(element);
this.taglet = taglet;
- this.tag = tag;
this.isFirstSentence = isFirstSentence;
this.isInheritDocTag = isInheritDocTag;
}
! public Input(ProgramElementDoc element, InheritableTaglet taglet, String tagId) {
! this(element);
this.taglet = taglet;
this.tagId = tagId;
}
! public Input(ProgramElementDoc element, InheritableTaglet taglet, String tagId,
boolean isTypeVariableParamTag) {
! this(element);
this.taglet = taglet;
this.tagId = tagId;
this.isTypeVariableParamTag = isTypeVariableParamTag;
}
! public Input(ProgramElementDoc element, InheritableTaglet taglet) {
! this(element);
this.taglet = taglet;
}
! public Input(ProgramElementDoc element) {
if (element == null)
throw new NullPointerException();
this.element = element;
}
! public Input(ProgramElementDoc element, boolean isFirstSentence) {
! this(element);
this.isFirstSentence = isFirstSentence;
}
! public Input copy() {
! Input clone = new Input(this.element);
! clone.taglet = this.taglet;
clone.tagId = this.tagId;
- clone.tag = this.tag;
- clone.isFirstSentence = this.isFirstSentence;
- clone.isInheritDocTag = this.isInheritDocTag;
clone.isTypeVariableParamTag = this.isTypeVariableParamTag;
- if (clone.element == null)
- throw new NullPointerException();
return clone;
}
}
/**
* The class that encapsulates the output.
--- 108,186 ----
* Used to distinguish between type variable param tags and regular
* param tags.
*/
public boolean isTypeVariableParamTag = false;
! public final Utils utils;
!
! public Input(Utils utils, Element element, InheritableTaglet taglet, DocTreeInfo dtInfo,
boolean isFirstSentence, boolean isInheritDocTag) {
! this.utils = utils;
! this.element = element;
this.taglet = taglet;
this.isFirstSentence = isFirstSentence;
this.isInheritDocTag = isInheritDocTag;
+ this.docTreeInfo = dtInfo;
}
! public Input(Utils utils, Element element, InheritableTaglet taglet, String tagId) {
! this(utils, element);
this.taglet = taglet;
this.tagId = tagId;
}
! public Input(Utils utils, Element element, InheritableTaglet taglet, String tagId,
boolean isTypeVariableParamTag) {
! this(utils, element);
this.taglet = taglet;
this.tagId = tagId;
this.isTypeVariableParamTag = isTypeVariableParamTag;
}
! public Input(Utils utils, Element element, InheritableTaglet taglet) {
! this(utils, element);
this.taglet = taglet;
}
! public Input(Utils utils, Element element) {
if (element == null)
throw new NullPointerException();
this.element = element;
+ this.utils = utils;
+ this.docTreeInfo = new DocTreeInfo();
}
! public Input(Utils utils, Element element, boolean isFirstSentence) {
! this(utils, element);
this.isFirstSentence = isFirstSentence;
}
! public Input copy(Utils utils) {
! if (this.element == null) {
! throw new NullPointerException();
! }
! Input clone = new Input(utils, this.element, this.taglet, this.docTreeInfo,
! this.isFirstSentence, this.isInheritDocTag);
clone.tagId = this.tagId;
clone.isTypeVariableParamTag = this.isTypeVariableParamTag;
return clone;
+ }
+ /**
+ * For debugging purposes
+ * @return string representation
+ */
+ @Override
+ public String toString() {
+ String encl = element == null ? "" : element.getEnclosingElement().toString() + "::";
+ return "Input{" + "element=" + encl + element
+ + ", taglet=" + taglet
+ + ", tagId=" + tagId + ", tag=" + docTreeInfo
+ + ", isFirstSentence=" + isFirstSentence
+ + ", isInheritDocTag=" + isInheritDocTag
+ + ", isTypeVariableParamTag=" + isTypeVariableParamTag
+ + ", utils=" + utils + '}';
}
}
/**
* The class that encapsulates the output.
*** 145,165 ****
public static class Output {
/**
* The tag that holds the documentation. Null if documentation
* is not held by a tag.
*/
! public Tag holderTag;
/**
* The Doc object that holds the documentation.
*/
! public Doc holder;
/**
* The inherited documentation.
*/
! public Tag[] inlineTags = new Tag[] {};
/**
* False if documentation could not be inherited.
*/
public boolean isValidInheritDocTag = true;
--- 188,208 ----
public static class Output {
/**
* The tag that holds the documentation. Null if documentation
* is not held by a tag.
*/
! public DocTree holderTag;
/**
* The Doc object that holds the documentation.
*/
! public Element holder;
/**
* The inherited documentation.
*/
! public List<? extends DocTree> inlineTags = Collections.emptyList();
/**
* False if documentation could not be inherited.
*/
public boolean isValidInheritDocTag = true;
*** 170,243 ****
* IOException and the overridden element has throws tags for IOException and
* ZipException, both tags would be inherited because ZipException is a
* subclass of IOException. This subclass of DocFinder.Output allows
* multiple tag inheritence.
*/
! public List<Tag> tagList = new ArrayList<>();
}
/**
* Search for the requested comments in the given element. If it does not
! * have comments, return documentation from the overriden element if possible.
! * If the overriden element does not exist or does not have documentation to
* inherit, search for documentation to inherit from implemented methods.
*
* @param input the input object used to perform the search.
*
* @return an Output object representing the documentation that was found.
*/
public static Output search(Configuration configuration, Input input) {
Output output = new Output();
if (input.isInheritDocTag) {
//Do nothing because "element" does not have any documentation.
! //All it has it {@inheritDoc}.
} else if (input.taglet == null) {
//We want overall documentation.
! output.inlineTags = input.isFirstSentence ?
! input.element.firstSentenceTags() :
! input.element.inlineTags();
output.holder = input.element;
} else {
input.taglet.inherit(input, output);
}
! if (output.inlineTags != null && output.inlineTags.length > 0) {
return output;
}
output.isValidInheritDocTag = false;
! Input inheritedSearchInput = input.copy();
inheritedSearchInput.isInheritDocTag = false;
! if (input.element instanceof MethodDoc) {
! MethodDoc overriddenMethod = ((MethodDoc) input.element).overriddenMethod();
if (overriddenMethod != null) {
inheritedSearchInput.element = overriddenMethod;
output = search(configuration, inheritedSearchInput);
output.isValidInheritDocTag = true;
! if (output.inlineTags.length > 0) {
return output;
}
}
//NOTE: When we fix the bug where ClassDoc.interfaceTypes() does
// not pass all implemented interfaces, we will use the
// appropriate element here.
! MethodDoc[] implementedMethods =
! (new ImplementedMethods((MethodDoc) input.element, configuration)).build(false);
! for (MethodDoc implementedMethod : implementedMethods) {
inheritedSearchInput.element = implementedMethod;
output = search(configuration, inheritedSearchInput);
output.isValidInheritDocTag = true;
! if (output.inlineTags.length > 0) {
return output;
}
}
! } else if (input.element instanceof ClassDoc) {
! ProgramElementDoc superclass = ((ClassDoc) input.element).superclass();
if (superclass != null) {
inheritedSearchInput.element = superclass;
output = search(configuration, inheritedSearchInput);
output.isValidInheritDocTag = true;
! if (output.inlineTags.length > 0) {
return output;
}
}
}
return output;
--- 213,303 ----
* IOException and the overridden element has throws tags for IOException and
* ZipException, both tags would be inherited because ZipException is a
* subclass of IOException. This subclass of DocFinder.Output allows
* multiple tag inheritence.
*/
! public List<DocTree> tagList = new ArrayList<>();
!
! /**
! * Returns a string representation for debugging purposes
! * @return string
! */
! @Override
! public String toString() {
! String encl = holder == null ? "" : holder.getEnclosingElement().toString() + "::";
! return "Output{" + "holderTag=" + holderTag
! + ", holder=" + encl + holder
! + ", inlineTags=" + inlineTags
! + ", isValidInheritDocTag=" + isValidInheritDocTag
! + ", tagList=" + tagList + '}';
}
+ }
/**
* Search for the requested comments in the given element. If it does not
! * have comments, return documentation from the overridden element if possible.
! * If the overridden element does not exist or does not have documentation to
* inherit, search for documentation to inherit from implemented methods.
*
* @param input the input object used to perform the search.
*
* @return an Output object representing the documentation that was found.
*/
public static Output search(Configuration configuration, Input input) {
Output output = new Output();
+ Utils utils = configuration.utils;
if (input.isInheritDocTag) {
//Do nothing because "element" does not have any documentation.
! //All it has is {@inheritDoc}.
} else if (input.taglet == null) {
//We want overall documentation.
! output.inlineTags = input.isFirstSentence
! ? utils.getFirstSentenceTrees(input.element)
! : utils.getBody(input.element);
output.holder = input.element;
} else {
input.taglet.inherit(input, output);
}
! if (output.inlineTags != null && !output.inlineTags.isEmpty()) {
return output;
}
output.isValidInheritDocTag = false;
! Input inheritedSearchInput = input.copy(configuration.utils);
inheritedSearchInput.isInheritDocTag = false;
! if (utils.isMethod(input.element)) {
! ExecutableElement overriddenMethod = utils.overriddenMethod((ExecutableElement) input.element);
if (overriddenMethod != null) {
inheritedSearchInput.element = overriddenMethod;
output = search(configuration, inheritedSearchInput);
output.isValidInheritDocTag = true;
! if (!output.inlineTags.isEmpty()) {
return output;
}
}
//NOTE: When we fix the bug where ClassDoc.interfaceTypes() does
// not pass all implemented interfaces, we will use the
// appropriate element here.
! ImplementedMethods implMethods
! = new ImplementedMethods((ExecutableElement) input.element, configuration);
! List<ExecutableElement> implementedMethods = implMethods.build();
! for (ExecutableElement implementedMethod : implementedMethods) {
inheritedSearchInput.element = implementedMethod;
output = search(configuration, inheritedSearchInput);
output.isValidInheritDocTag = true;
! if (!output.inlineTags.isEmpty()) {
return output;
}
}
! } else if (utils.isTypeElement(input.element)) {
! TypeMirror t = ((TypeElement) input.element).getSuperclass();
! Element superclass = utils.asTypeElement(t);
if (superclass != null) {
inheritedSearchInput.element = superclass;
output = search(configuration, inheritedSearchInput);
output.isValidInheritDocTag = true;
! if (!output.inlineTags.isEmpty()) {
return output;
}
}
}
return output;