langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/util/DocFinder.java
author ksrini
Mon, 10 Oct 2016 11:21:00 -0700
changeset 41452 ddaef4bba083
parent 35426 374342e56a56
child 45417 f7479ee8de69
permissions -rw-r--r--
8165991: Fix DocTreeFactory newDocCommentTree 8154349: New doclet incorrectly shows entire text body for JavaFX properties in summary section Reviewed-by: jjg
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     1
/*
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
     2
 * Copyright (c) 2003, 2016, Oracle and/or its affiliates. All rights reserved.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
06bc494ca11e Initial load
duke
parents:
diff changeset
     4
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
06bc494ca11e Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5520
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 1264
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5520
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 1264
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    10
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
06bc494ca11e Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
06bc494ca11e Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
06bc494ca11e Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
06bc494ca11e Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
06bc494ca11e Initial load
duke
parents:
diff changeset
    16
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
06bc494ca11e Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
06bc494ca11e Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
06bc494ca11e Initial load
duke
parents:
diff changeset
    20
 *
5520
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 1264
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 1264
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 1264
diff changeset
    23
 * questions.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    24
 */
06bc494ca11e Initial load
duke
parents:
diff changeset
    25
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
    26
package jdk.javadoc.internal.doclets.toolkit.util;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    27
14258
8d2148961366 8000663: clean up langtools imports
jjg
parents: 5520
diff changeset
    28
import java.util.*;
8d2148961366 8000663: clean up langtools imports
jjg
parents: 5520
diff changeset
    29
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
    30
import javax.lang.model.element.Element;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
    31
import javax.lang.model.element.ExecutableElement;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
    32
import javax.lang.model.element.TypeElement;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
    33
import javax.lang.model.type.TypeMirror;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
    34
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
    35
import com.sun.source.doctree.DocTree;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
    36
import jdk.javadoc.internal.doclets.toolkit.Configuration;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
    37
import jdk.javadoc.internal.doclets.toolkit.taglets.InheritableTaglet;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    38
06bc494ca11e Initial load
duke
parents:
diff changeset
    39
/**
06bc494ca11e Initial load
duke
parents:
diff changeset
    40
 * Search for the requested documentation.  Inherit documentation if necessary.
06bc494ca11e Initial load
duke
parents:
diff changeset
    41
 *
14260
727a84636f12 8000665: fix "internal API" comments on javadoc files
jjg
parents: 14258
diff changeset
    42
 *  <p><b>This is NOT part of any supported API.
727a84636f12 8000665: fix "internal API" comments on javadoc files
jjg
parents: 14258
diff changeset
    43
 *  If you write code that depends on this, you do so at your own risk.
727a84636f12 8000665: fix "internal API" comments on javadoc files
jjg
parents: 14258
diff changeset
    44
 *  This code and its internal interfaces are subject to change or
727a84636f12 8000665: fix "internal API" comments on javadoc files
jjg
parents: 14258
diff changeset
    45
 *  deletion without notice.</b>
727a84636f12 8000665: fix "internal API" comments on javadoc files
jjg
parents: 14258
diff changeset
    46
 *
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    47
 * @author Jamie Ho
06bc494ca11e Initial load
duke
parents:
diff changeset
    48
 */
06bc494ca11e Initial load
duke
parents:
diff changeset
    49
public class DocFinder {
06bc494ca11e Initial load
duke
parents:
diff changeset
    50
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
    51
    public static final class DocTreeInfo {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
    52
        public final DocTree docTree;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
    53
        public final Element element;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
    54
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
    55
        public DocTreeInfo() {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
    56
            this.docTree = null;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
    57
            this.element = null;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
    58
        }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
    59
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
    60
        public DocTreeInfo(DocTree docTree, Element baseElement) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
    61
            this.docTree = docTree;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
    62
            this.element = baseElement;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
    63
        }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
    64
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
    65
        @Override
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
    66
        public String toString() {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
    67
            return "DocTreeInfo{" + "docTree=" + docTree + ", element=" + element + '}';
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
    68
        }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
    69
    }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
    70
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    71
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    72
     * The class that encapsulates the input.
06bc494ca11e Initial load
duke
parents:
diff changeset
    73
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    74
    public static class Input {
06bc494ca11e Initial load
duke
parents:
diff changeset
    75
        /**
17547
40f2f9a5a445 8008768: Using {@inheritDoc} in simple tag defined via -tag fails
jjg
parents: 14260
diff changeset
    76
         * The element to search documentation from.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    77
         */
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
    78
        public Element element;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    79
        /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    80
         * The taglet to search for documentation on behalf of. Null if we want
06bc494ca11e Initial load
duke
parents:
diff changeset
    81
         * to search for overall documentation.
06bc494ca11e Initial load
duke
parents:
diff changeset
    82
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
    83
        public InheritableTaglet taglet = null;
06bc494ca11e Initial load
duke
parents:
diff changeset
    84
06bc494ca11e Initial load
duke
parents:
diff changeset
    85
        /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    86
         * The id of the tag to retrieve documentation for.
06bc494ca11e Initial load
duke
parents:
diff changeset
    87
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
    88
        public String tagId = null;
06bc494ca11e Initial load
duke
parents:
diff changeset
    89
06bc494ca11e Initial load
duke
parents:
diff changeset
    90
        /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    91
         * The tag to retrieve documentation for.  This is only used for the
06bc494ca11e Initial load
duke
parents:
diff changeset
    92
         * inheritDoc tag.
06bc494ca11e Initial load
duke
parents:
diff changeset
    93
         */
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
    94
        public final DocTreeInfo docTreeInfo;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    95
06bc494ca11e Initial load
duke
parents:
diff changeset
    96
        /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    97
         * True if we only want to search for the first sentence.
06bc494ca11e Initial load
duke
parents:
diff changeset
    98
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
    99
        public boolean isFirstSentence = false;
06bc494ca11e Initial load
duke
parents:
diff changeset
   100
06bc494ca11e Initial load
duke
parents:
diff changeset
   101
        /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   102
         * True if we are looking for documentation to replace the inheritDocTag.
06bc494ca11e Initial load
duke
parents:
diff changeset
   103
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
   104
        public boolean isInheritDocTag = false;
06bc494ca11e Initial load
duke
parents:
diff changeset
   105
06bc494ca11e Initial load
duke
parents:
diff changeset
   106
        /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   107
         * Used to distinguish between type variable param tags and regular
06bc494ca11e Initial load
duke
parents:
diff changeset
   108
         * param tags.
06bc494ca11e Initial load
duke
parents:
diff changeset
   109
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
   110
        public boolean isTypeVariableParamTag = false;
06bc494ca11e Initial load
duke
parents:
diff changeset
   111
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
   112
        public final Utils utils;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
   113
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
   114
        public Input(Utils utils, Element element, InheritableTaglet taglet, DocTreeInfo dtInfo,
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   115
                boolean isFirstSentence, boolean isInheritDocTag) {
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
   116
            this.utils = utils;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
   117
            this.element = element;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   118
            this.taglet = taglet;
06bc494ca11e Initial load
duke
parents:
diff changeset
   119
            this.isFirstSentence = isFirstSentence;
06bc494ca11e Initial load
duke
parents:
diff changeset
   120
            this.isInheritDocTag = isInheritDocTag;
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
   121
            this.docTreeInfo = dtInfo;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   122
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   123
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
   124
        public Input(Utils utils, Element element, InheritableTaglet taglet, String tagId) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
   125
            this(utils, element);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   126
            this.taglet = taglet;
06bc494ca11e Initial load
duke
parents:
diff changeset
   127
            this.tagId = tagId;
06bc494ca11e Initial load
duke
parents:
diff changeset
   128
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   129
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
   130
        public Input(Utils utils, Element element, InheritableTaglet taglet, String tagId,
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   131
            boolean isTypeVariableParamTag) {
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
   132
            this(utils, element);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   133
            this.taglet = taglet;
06bc494ca11e Initial load
duke
parents:
diff changeset
   134
            this.tagId = tagId;
06bc494ca11e Initial load
duke
parents:
diff changeset
   135
            this.isTypeVariableParamTag = isTypeVariableParamTag;
06bc494ca11e Initial load
duke
parents:
diff changeset
   136
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   137
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
   138
        public Input(Utils utils, Element element, InheritableTaglet taglet) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
   139
            this(utils, element);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   140
            this.taglet = taglet;
06bc494ca11e Initial load
duke
parents:
diff changeset
   141
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   142
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
   143
        public Input(Utils utils, Element element) {
17547
40f2f9a5a445 8008768: Using {@inheritDoc} in simple tag defined via -tag fails
jjg
parents: 14260
diff changeset
   144
            if (element == null)
40f2f9a5a445 8008768: Using {@inheritDoc} in simple tag defined via -tag fails
jjg
parents: 14260
diff changeset
   145
                throw new NullPointerException();
40f2f9a5a445 8008768: Using {@inheritDoc} in simple tag defined via -tag fails
jjg
parents: 14260
diff changeset
   146
            this.element = element;
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
   147
            this.utils = utils;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
   148
            this.docTreeInfo = new DocTreeInfo();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   149
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   150
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
   151
        public Input(Utils utils, Element element, boolean isFirstSentence) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
   152
            this(utils, element);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   153
            this.isFirstSentence = isFirstSentence;
06bc494ca11e Initial load
duke
parents:
diff changeset
   154
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   155
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
   156
        public Input copy(Utils utils) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
   157
            if (this.element == null) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
   158
                throw new NullPointerException();
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
   159
            }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
   160
            Input clone = new Input(utils, this.element, this.taglet, this.docTreeInfo,
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
   161
                    this.isFirstSentence, this.isInheritDocTag);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   162
            clone.tagId = this.tagId;
06bc494ca11e Initial load
duke
parents:
diff changeset
   163
            clone.isTypeVariableParamTag = this.isTypeVariableParamTag;
06bc494ca11e Initial load
duke
parents:
diff changeset
   164
            return clone;
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
   165
        }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   166
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
   167
        /**
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
   168
         * For debugging purposes
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
   169
         * @return string representation
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
   170
         */
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
   171
        @Override
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
   172
        public String toString() {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
   173
            String encl = element == null ? "" : element.getEnclosingElement().toString() + "::";
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
   174
            return "Input{" + "element=" + encl + element
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
   175
                    + ", taglet=" + taglet
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
   176
                    + ", tagId=" + tagId + ", tag=" + docTreeInfo
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
   177
                    + ", isFirstSentence=" + isFirstSentence
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
   178
                    + ", isInheritDocTag=" + isInheritDocTag
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
   179
                    + ", isTypeVariableParamTag=" + isTypeVariableParamTag
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
   180
                    + ", utils=" + utils + '}';
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   181
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   182
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   183
06bc494ca11e Initial load
duke
parents:
diff changeset
   184
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   185
     * The class that encapsulates the output.
06bc494ca11e Initial load
duke
parents:
diff changeset
   186
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   187
    public static class Output {
06bc494ca11e Initial load
duke
parents:
diff changeset
   188
        /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   189
         * The tag that holds the documentation.  Null if documentation
06bc494ca11e Initial load
duke
parents:
diff changeset
   190
         * is not held by a tag.
06bc494ca11e Initial load
duke
parents:
diff changeset
   191
         */
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
   192
        public DocTree holderTag;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   193
06bc494ca11e Initial load
duke
parents:
diff changeset
   194
        /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   195
         * The Doc object that holds the documentation.
06bc494ca11e Initial load
duke
parents:
diff changeset
   196
         */
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
   197
        public Element holder;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   198
06bc494ca11e Initial load
duke
parents:
diff changeset
   199
        /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   200
         * The inherited documentation.
06bc494ca11e Initial load
duke
parents:
diff changeset
   201
         */
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
   202
        public List<? extends DocTree> inlineTags = Collections.emptyList();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   203
06bc494ca11e Initial load
duke
parents:
diff changeset
   204
        /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   205
         * False if documentation could not be inherited.
06bc494ca11e Initial load
duke
parents:
diff changeset
   206
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
   207
        public boolean isValidInheritDocTag = true;
06bc494ca11e Initial load
duke
parents:
diff changeset
   208
06bc494ca11e Initial load
duke
parents:
diff changeset
   209
        /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   210
         * When automatically inheriting throws tags, you sometime must inherit
17547
40f2f9a5a445 8008768: Using {@inheritDoc} in simple tag defined via -tag fails
jjg
parents: 14260
diff changeset
   211
         * more than one tag.  For example if the element declares that it throws
40f2f9a5a445 8008768: Using {@inheritDoc} in simple tag defined via -tag fails
jjg
parents: 14260
diff changeset
   212
         * IOException and the overridden element has throws tags for IOException and
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   213
         * ZipException, both tags would be inherited because ZipException is a
06bc494ca11e Initial load
duke
parents:
diff changeset
   214
         * subclass of IOException.  This subclass of DocFinder.Output allows
06bc494ca11e Initial load
duke
parents:
diff changeset
   215
         * multiple tag inheritence.
06bc494ca11e Initial load
duke
parents:
diff changeset
   216
         */
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
   217
        public List<DocTree> tagList  = new ArrayList<>();
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
   218
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
   219
        /**
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
   220
         * Returns a string representation for debugging purposes
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
   221
         * @return string
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
   222
         */
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
   223
        @Override
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
   224
        public String toString() {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
   225
            String encl = holder == null ? "" : holder.getEnclosingElement().toString() + "::";
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
   226
            return "Output{" + "holderTag=" + holderTag
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
   227
                    + ", holder=" + encl + holder
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
   228
                    + ", inlineTags=" + inlineTags
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
   229
                    + ", isValidInheritDocTag=" + isValidInheritDocTag
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
   230
                    + ", tagList=" + tagList + '}';
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
   231
        }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   232
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   233
06bc494ca11e Initial load
duke
parents:
diff changeset
   234
    /**
17547
40f2f9a5a445 8008768: Using {@inheritDoc} in simple tag defined via -tag fails
jjg
parents: 14260
diff changeset
   235
     * Search for the requested comments in the given element.  If it does not
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
   236
     * have comments, return documentation from the overridden element if possible.
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
   237
     * If the overridden element does not exist or does not have documentation to
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   238
     * inherit, search for documentation to inherit from implemented methods.
06bc494ca11e Initial load
duke
parents:
diff changeset
   239
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   240
     * @param input the input object used to perform the search.
06bc494ca11e Initial load
duke
parents:
diff changeset
   241
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   242
     * @return an Output object representing the documentation that was found.
06bc494ca11e Initial load
duke
parents:
diff changeset
   243
     */
25454
376a52c9540c 8039028: [javadoc] refactor the usage of Util.java
ksrini
parents: 22163
diff changeset
   244
    public static Output search(Configuration configuration, Input input) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   245
        Output output = new Output();
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
   246
        Utils utils = configuration.utils;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   247
        if (input.isInheritDocTag) {
17547
40f2f9a5a445 8008768: Using {@inheritDoc} in simple tag defined via -tag fails
jjg
parents: 14260
diff changeset
   248
            //Do nothing because "element" does not have any documentation.
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
   249
            //All it has is {@inheritDoc}.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   250
        } else if (input.taglet == null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   251
            //We want overall documentation.
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
   252
            output.inlineTags = input.isFirstSentence
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
   253
                    ? utils.getFirstSentenceTrees(input.element)
41452
ddaef4bba083 8165991: Fix DocTreeFactory newDocCommentTree
ksrini
parents: 35426
diff changeset
   254
                    : utils.getFullBody(input.element);
17547
40f2f9a5a445 8008768: Using {@inheritDoc} in simple tag defined via -tag fails
jjg
parents: 14260
diff changeset
   255
            output.holder = input.element;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   256
        } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
   257
            input.taglet.inherit(input, output);
06bc494ca11e Initial load
duke
parents:
diff changeset
   258
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   259
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
   260
        if (output.inlineTags != null && !output.inlineTags.isEmpty()) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   261
            return output;
06bc494ca11e Initial load
duke
parents:
diff changeset
   262
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   263
        output.isValidInheritDocTag = false;
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
   264
        Input inheritedSearchInput = input.copy(configuration.utils);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   265
        inheritedSearchInput.isInheritDocTag = false;
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
   266
        if (utils.isMethod(input.element)) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
   267
            ExecutableElement overriddenMethod = utils.overriddenMethod((ExecutableElement) input.element);
17547
40f2f9a5a445 8008768: Using {@inheritDoc} in simple tag defined via -tag fails
jjg
parents: 14260
diff changeset
   268
            if (overriddenMethod != null) {
40f2f9a5a445 8008768: Using {@inheritDoc} in simple tag defined via -tag fails
jjg
parents: 14260
diff changeset
   269
                inheritedSearchInput.element = overriddenMethod;
25454
376a52c9540c 8039028: [javadoc] refactor the usage of Util.java
ksrini
parents: 22163
diff changeset
   270
                output = search(configuration, inheritedSearchInput);
17547
40f2f9a5a445 8008768: Using {@inheritDoc} in simple tag defined via -tag fails
jjg
parents: 14260
diff changeset
   271
                output.isValidInheritDocTag = true;
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
   272
                if (!output.inlineTags.isEmpty()) {
17547
40f2f9a5a445 8008768: Using {@inheritDoc} in simple tag defined via -tag fails
jjg
parents: 14260
diff changeset
   273
                    return output;
40f2f9a5a445 8008768: Using {@inheritDoc} in simple tag defined via -tag fails
jjg
parents: 14260
diff changeset
   274
                }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   275
            }
17547
40f2f9a5a445 8008768: Using {@inheritDoc} in simple tag defined via -tag fails
jjg
parents: 14260
diff changeset
   276
            //NOTE:  When we fix the bug where ClassDoc.interfaceTypes() does
40f2f9a5a445 8008768: Using {@inheritDoc} in simple tag defined via -tag fails
jjg
parents: 14260
diff changeset
   277
            //       not pass all implemented interfaces, we will use the
40f2f9a5a445 8008768: Using {@inheritDoc} in simple tag defined via -tag fails
jjg
parents: 14260
diff changeset
   278
            //       appropriate element here.
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
   279
            ImplementedMethods implMethods
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
   280
                    = new ImplementedMethods((ExecutableElement) input.element, configuration);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
   281
            List<ExecutableElement> implementedMethods = implMethods.build();
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
   282
            for (ExecutableElement implementedMethod : implementedMethods) {
22159
682da512ec17 8030253: Update langtools to use strings-in-switch
briangoetz
parents: 17547
diff changeset
   283
                inheritedSearchInput.element = implementedMethod;
25454
376a52c9540c 8039028: [javadoc] refactor the usage of Util.java
ksrini
parents: 22163
diff changeset
   284
                output = search(configuration, inheritedSearchInput);
17547
40f2f9a5a445 8008768: Using {@inheritDoc} in simple tag defined via -tag fails
jjg
parents: 14260
diff changeset
   285
                output.isValidInheritDocTag = true;
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
   286
                if (!output.inlineTags.isEmpty()) {
17547
40f2f9a5a445 8008768: Using {@inheritDoc} in simple tag defined via -tag fails
jjg
parents: 14260
diff changeset
   287
                    return output;
40f2f9a5a445 8008768: Using {@inheritDoc} in simple tag defined via -tag fails
jjg
parents: 14260
diff changeset
   288
                }
40f2f9a5a445 8008768: Using {@inheritDoc} in simple tag defined via -tag fails
jjg
parents: 14260
diff changeset
   289
            }
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
   290
        } else if (utils.isTypeElement(input.element)) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
   291
            TypeMirror t = ((TypeElement) input.element).getSuperclass();
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
   292
            Element superclass = utils.asTypeElement(t);
17547
40f2f9a5a445 8008768: Using {@inheritDoc} in simple tag defined via -tag fails
jjg
parents: 14260
diff changeset
   293
            if (superclass != null) {
40f2f9a5a445 8008768: Using {@inheritDoc} in simple tag defined via -tag fails
jjg
parents: 14260
diff changeset
   294
                inheritedSearchInput.element = superclass;
25454
376a52c9540c 8039028: [javadoc] refactor the usage of Util.java
ksrini
parents: 22163
diff changeset
   295
                output = search(configuration, inheritedSearchInput);
17547
40f2f9a5a445 8008768: Using {@inheritDoc} in simple tag defined via -tag fails
jjg
parents: 14260
diff changeset
   296
                output.isValidInheritDocTag = true;
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
   297
                if (!output.inlineTags.isEmpty()) {
17547
40f2f9a5a445 8008768: Using {@inheritDoc} in simple tag defined via -tag fails
jjg
parents: 14260
diff changeset
   298
                    return output;
40f2f9a5a445 8008768: Using {@inheritDoc} in simple tag defined via -tag fails
jjg
parents: 14260
diff changeset
   299
                }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   300
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   301
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   302
        return output;
06bc494ca11e Initial load
duke
parents:
diff changeset
   303
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   304
}