src/jdk.compiler/share/classes/jdk/internal/shellsupport/doc/JavadocHelper.java
author iignatyev
Tue, 25 Sep 2018 18:26:46 -0700
changeset 51876 d2b381ea8477
parent 48237 ee130cca69e6
permissions -rw-r--r--
8211134: problem list compiler/whitebox/ForceNMethodSweepTest.java Reviewed-by: kvn
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
41865
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
     1
/*
44063
5f0cf4126949 8175560: Drop String pkgName from javax.tools.JavaFileManager.getLocationForModule(Location location, JavaFileObject fo, String pkgName)
jlahoda
parents: 43773
diff changeset
     2
 * Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
41865
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
     4
 *
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    10
 *
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    15
 * accompanied this code).
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    16
 *
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    20
 *
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    23
 * questions.
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    24
 */
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    25
package jdk.internal.shellsupport.doc;
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    26
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    27
import java.io.IOException;
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    28
import java.net.URI;
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    29
import java.net.URISyntaxException;
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    30
import java.nio.file.Path;
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    31
import java.util.ArrayList;
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    32
import java.util.Arrays;
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    33
import java.util.Collection;
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    34
import java.util.Comparator;
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    35
import java.util.HashMap;
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    36
import java.util.HashSet;
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    37
import java.util.IdentityHashMap;
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    38
import java.util.Iterator;
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    39
import java.util.List;
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    40
import java.util.Map;
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    41
import java.util.Map.Entry;
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    42
import java.util.Objects;
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    43
import java.util.Set;
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    44
import java.util.Stack;
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    45
import java.util.TreeMap;
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    46
import java.util.stream.Collectors;
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    47
import java.util.stream.Stream;
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    48
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    49
import javax.lang.model.element.Element;
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    50
import javax.lang.model.element.ElementKind;
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    51
import javax.lang.model.element.ExecutableElement;
43773
8d8593871575 8174245: Javadoc is not working for some methods
jlahoda
parents: 42827
diff changeset
    52
import javax.lang.model.element.ModuleElement;
41865
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    53
import javax.lang.model.element.TypeElement;
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    54
import javax.lang.model.element.VariableElement;
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    55
import javax.lang.model.type.DeclaredType;
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    56
import javax.lang.model.type.TypeKind;
42827
36468b5fa7f4 8181370: Convert anonymous inner classes into lambdas/method references
mcimadamore
parents: 41865
diff changeset
    57
import javax.lang.model.type.TypeMirror;
41865
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    58
import javax.lang.model.util.ElementFilter;
43773
8d8593871575 8174245: Javadoc is not working for some methods
jlahoda
parents: 42827
diff changeset
    59
import javax.lang.model.util.Elements;
8d8593871575 8174245: Javadoc is not working for some methods
jlahoda
parents: 42827
diff changeset
    60
import javax.tools.ForwardingJavaFileManager;
41865
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    61
import javax.tools.JavaCompiler;
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    62
import javax.tools.JavaFileManager;
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    63
import javax.tools.JavaFileObject;
48028
9e022f580a9d 8190552: Augment the Compiler API tree with APIs to represent HTML content
ksrini
parents: 47216
diff changeset
    64
import javax.tools.JavaFileObject.Kind;
41865
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    65
import javax.tools.SimpleJavaFileObject;
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    66
import javax.tools.StandardJavaFileManager;
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    67
import javax.tools.StandardLocation;
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    68
import javax.tools.ToolProvider;
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    69
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    70
import com.sun.source.doctree.DocCommentTree;
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    71
import com.sun.source.doctree.DocTree;
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    72
import com.sun.source.doctree.InheritDocTree;
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    73
import com.sun.source.doctree.ParamTree;
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    74
import com.sun.source.doctree.ReturnTree;
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    75
import com.sun.source.doctree.ThrowsTree;
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    76
import com.sun.source.tree.ClassTree;
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    77
import com.sun.source.tree.CompilationUnitTree;
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    78
import com.sun.source.tree.MethodTree;
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    79
import com.sun.source.tree.VariableTree;
48237
ee130cca69e6 8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents: 48028
diff changeset
    80
import com.sun.source.util.DocSourcePositions;
41865
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    81
import com.sun.source.util.DocTreePath;
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    82
import com.sun.source.util.DocTreeScanner;
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    83
import com.sun.source.util.DocTrees;
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    84
import com.sun.source.util.JavacTask;
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    85
import com.sun.source.util.TreePath;
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    86
import com.sun.source.util.TreePathScanner;
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    87
import com.sun.source.util.Trees;
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    88
import com.sun.tools.javac.api.JavacTaskImpl;
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    89
import com.sun.tools.javac.util.DefinedBy;
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    90
import com.sun.tools.javac.util.DefinedBy.Api;
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    91
import com.sun.tools.javac.util.Pair;
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    92
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    93
/**Helper to find javadoc and resolve @inheritDoc.
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    94
 */
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    95
public abstract class JavadocHelper implements AutoCloseable {
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    96
    private static final JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    97
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    98
    /**Create the helper.
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
    99
     *
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   100
     * @param mainTask JavacTask from which the further Elements originate
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   101
     * @param sourceLocations paths where source files should be searched
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   102
     * @return a JavadocHelper
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   103
     */
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   104
    public static JavadocHelper create(JavacTask mainTask, Collection<? extends Path> sourceLocations) {
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   105
        StandardJavaFileManager fm = compiler.getStandardFileManager(null, null, null);
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   106
        try {
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   107
            fm.setLocationFromPaths(StandardLocation.SOURCE_PATH, sourceLocations);
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   108
            return new OnDemandJavadocHelper(mainTask, fm);
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   109
        } catch (IOException ex) {
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   110
            try {
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   111
                fm.close();
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   112
            } catch (IOException closeEx) {
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   113
            }
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   114
            return new JavadocHelper() {
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   115
                @Override
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   116
                public String getResolvedDocComment(Element forElement) throws IOException {
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   117
                    return null;
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   118
                }
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   119
                @Override
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   120
                public Element getSourceElement(Element forElement) throws IOException {
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   121
                    return forElement;
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   122
                }
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   123
                @Override
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   124
                public void close() throws IOException {}
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   125
            };
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   126
        }
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   127
    }
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   128
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   129
    /**Returns javadoc for the given element, if it can be found, or null otherwise. The javadoc
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   130
     * will have @inheritDoc resolved.
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   131
     *
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   132
     * @param forElement element for which the javadoc should be searched
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   133
     * @return javadoc if found, null otherwise
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   134
     * @throws IOException if something goes wrong in the search
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   135
     */
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   136
    public abstract String getResolvedDocComment(Element forElement) throws IOException;
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   137
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   138
    /**Returns an element representing the same given program element, but the returned element will
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   139
     * be resolved from source, if it can be found. Returns the original element if the source for
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   140
     * the given element cannot be found.
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   141
     *
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   142
     * @param forElement element for which the source element should be searched
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   143
     * @return source element if found, the original element otherwise
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   144
     * @throws IOException if something goes wrong in the search
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   145
     */
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   146
    public abstract Element getSourceElement(Element forElement) throws IOException;
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   147
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   148
    /**Closes the helper.
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   149
     *
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   150
     * @throws IOException if something foes wrong during the close
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   151
     */
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   152
    @Override
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   153
    public abstract void close() throws IOException;
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   154
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   155
    private static final class OnDemandJavadocHelper extends JavadocHelper {
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   156
        private final JavacTask mainTask;
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   157
        private final JavaFileManager baseFileManager;
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   158
        private final StandardJavaFileManager fm;
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   159
        private final Map<String, Pair<JavacTask, TreePath>> signature2Source = new HashMap<>();
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   160
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   161
        private OnDemandJavadocHelper(JavacTask mainTask, StandardJavaFileManager fm) {
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   162
            this.mainTask = mainTask;
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   163
            this.baseFileManager = ((JavacTaskImpl) mainTask).getContext().get(JavaFileManager.class);
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   164
            this.fm = fm;
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   165
        }
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   166
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   167
        @Override
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   168
        public String getResolvedDocComment(Element forElement) throws IOException {
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   169
            Pair<JavacTask, TreePath> sourceElement = getSourceElement(mainTask, forElement);
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   170
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   171
            if (sourceElement == null)
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   172
                return null;
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   173
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   174
            return getResolvedDocComment(sourceElement.fst, sourceElement.snd);
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   175
        }
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   176
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   177
        @Override
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   178
        public Element getSourceElement(Element forElement) throws IOException {
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   179
            Pair<JavacTask, TreePath> sourceElement = getSourceElement(mainTask, forElement);
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   180
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   181
            if (sourceElement == null)
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   182
                return forElement;
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   183
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   184
            Element result = Trees.instance(sourceElement.fst).getElement(sourceElement.snd);
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   185
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   186
            if (result == null)
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   187
                return forElement;
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   188
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   189
            return result;
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   190
        }
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   191
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   192
        private String getResolvedDocComment(JavacTask task, TreePath el) throws IOException {
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   193
            DocTrees trees = DocTrees.instance(task);
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   194
            Element element = trees.getElement(el);
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   195
            String docComment = trees.getDocComment(el);
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   196
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   197
            if (docComment == null && element.getKind() == ElementKind.METHOD) {
48237
ee130cca69e6 8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents: 48028
diff changeset
   198
                //if a method does not have a javadoc,
ee130cca69e6 8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents: 48028
diff changeset
   199
                //try to use javadoc from the methods overridden by this method:
41865
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   200
                ExecutableElement executableElement = (ExecutableElement) element;
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   201
                Iterable<Element> superTypes =
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   202
                        () -> superTypeForInheritDoc(task, element.getEnclosingElement()).iterator();
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   203
                for (Element sup : superTypes) {
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   204
                   for (ExecutableElement supMethod : ElementFilter.methodsIn(sup.getEnclosedElements())) {
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   205
                       TypeElement clazz = (TypeElement) executableElement.getEnclosingElement();
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   206
                       if (task.getElements().overrides(executableElement, supMethod, clazz)) {
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   207
                           Pair<JavacTask, TreePath> source = getSourceElement(task, supMethod);
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   208
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   209
                           if (source != null) {
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   210
                               String overriddenComment = getResolvedDocComment(source.fst, source.snd);
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   211
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   212
                               if (overriddenComment != null) {
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   213
                                   return overriddenComment;
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   214
                               }
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   215
                           }
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   216
                       }
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   217
                   }
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   218
                }
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   219
            }
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   220
48237
ee130cca69e6 8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents: 48028
diff changeset
   221
            if (docComment == null)
ee130cca69e6 8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents: 48028
diff changeset
   222
                return null;
ee130cca69e6 8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents: 48028
diff changeset
   223
48028
9e022f580a9d 8190552: Augment the Compiler API tree with APIs to represent HTML content
ksrini
parents: 47216
diff changeset
   224
            Pair<DocCommentTree, Integer> parsed = parseDocComment(task, docComment);
9e022f580a9d 8190552: Augment the Compiler API tree with APIs to represent HTML content
ksrini
parents: 47216
diff changeset
   225
            DocCommentTree docCommentTree = parsed.fst;
9e022f580a9d 8190552: Augment the Compiler API tree with APIs to represent HTML content
ksrini
parents: 47216
diff changeset
   226
            int offset = parsed.snd;
41865
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   227
            IOException[] exception = new IOException[1];
48237
ee130cca69e6 8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents: 48028
diff changeset
   228
            Comparator<int[]> spanComp =
ee130cca69e6 8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents: 48028
diff changeset
   229
                    (span1, span2) -> span1[0] != span2[0] ? span2[0] - span1[0]
ee130cca69e6 8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents: 48028
diff changeset
   230
                                                           : span2[1] - span1[0];
ee130cca69e6 8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents: 48028
diff changeset
   231
            //spans in the docComment that should be replaced with the given Strings:
ee130cca69e6 8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents: 48028
diff changeset
   232
            Map<int[], List<String>> replace = new TreeMap<>(spanComp);
ee130cca69e6 8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents: 48028
diff changeset
   233
            DocSourcePositions sp = trees.getSourcePositions();
41865
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   234
48237
ee130cca69e6 8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents: 48028
diff changeset
   235
            //fill in missing elements and resolve {@inheritDoc}
ee130cca69e6 8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents: 48028
diff changeset
   236
            //if an element is (silently) missing in the javadoc, a synthetic {@inheritDoc}
ee130cca69e6 8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents: 48028
diff changeset
   237
            //is created for it.
41865
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   238
            new DocTreeScanner<Void, Void>() {
48237
ee130cca69e6 8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents: 48028
diff changeset
   239
                /* enclosing doctree that may contain {@inheritDoc} (explicit or synthetic)*/
41865
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   240
                private Stack<DocTree> interestingParent = new Stack<>();
48237
ee130cca69e6 8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents: 48028
diff changeset
   241
                /* current top-level DocCommentTree*/
41865
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   242
                private DocCommentTree dcTree;
48237
ee130cca69e6 8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents: 48028
diff changeset
   243
                /* javadoc from a super method from which we may copy elements.*/
41865
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   244
                private String inherited;
48237
ee130cca69e6 8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents: 48028
diff changeset
   245
                /* JavacTask from which inherited originates.*/
ee130cca69e6 8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents: 48028
diff changeset
   246
                private JavacTask inheritedJavacTask;
ee130cca69e6 8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents: 48028
diff changeset
   247
                /* TreePath to the super method from which inherited originates.*/
ee130cca69e6 8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents: 48028
diff changeset
   248
                private TreePath inheritedTreePath;
ee130cca69e6 8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents: 48028
diff changeset
   249
                /* Synthetic trees that contain {@inheritDoc} and
ee130cca69e6 8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents: 48028
diff changeset
   250
                 * texts which which they should be replaced.*/
41865
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   251
                private Map<DocTree, String> syntheticTrees = new IdentityHashMap<>();
48237
ee130cca69e6 8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents: 48028
diff changeset
   252
                /* Position on which the synthetic trees should be inserted.*/
ee130cca69e6 8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents: 48028
diff changeset
   253
                private long insertPos = offset;
41865
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   254
                @Override @DefinedBy(Api.COMPILER_TREE)
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   255
                public Void visitDocComment(DocCommentTree node, Void p) {
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   256
                    dcTree = node;
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   257
                    interestingParent.push(node);
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   258
                    try {
48237
ee130cca69e6 8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents: 48028
diff changeset
   259
                        if (node.getFullBody().isEmpty()) {
ee130cca69e6 8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents: 48028
diff changeset
   260
                            //there is no body in the javadoc, add synthetic {@inheritDoc}, which
ee130cca69e6 8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents: 48028
diff changeset
   261
                            //will be automatically filled in visitInheritDoc:
ee130cca69e6 8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents: 48028
diff changeset
   262
                            DocCommentTree dc = parseDocComment(task, "{@inheritDoc}").fst;
ee130cca69e6 8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents: 48028
diff changeset
   263
                            syntheticTrees.put(dc, "*\n");
ee130cca69e6 8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents: 48028
diff changeset
   264
                            interestingParent.push(dc);
ee130cca69e6 8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents: 48028
diff changeset
   265
                            boolean prevInSynthetic = inSynthetic;
ee130cca69e6 8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents: 48028
diff changeset
   266
                            try {
ee130cca69e6 8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents: 48028
diff changeset
   267
                                inSynthetic = true;
ee130cca69e6 8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents: 48028
diff changeset
   268
                                scan(dc.getFirstSentence(), p);
ee130cca69e6 8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents: 48028
diff changeset
   269
                                scan(dc.getBody(), p);
ee130cca69e6 8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents: 48028
diff changeset
   270
                            } finally {
ee130cca69e6 8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents: 48028
diff changeset
   271
                                inSynthetic = prevInSynthetic;
ee130cca69e6 8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents: 48028
diff changeset
   272
                                interestingParent.pop();
ee130cca69e6 8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents: 48028
diff changeset
   273
                            }
ee130cca69e6 8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents: 48028
diff changeset
   274
                        } else {
ee130cca69e6 8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents: 48028
diff changeset
   275
                            scan(node.getFirstSentence(), p);
ee130cca69e6 8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents: 48028
diff changeset
   276
                            scan(node.getBody(), p);
ee130cca69e6 8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents: 48028
diff changeset
   277
                        }
ee130cca69e6 8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents: 48028
diff changeset
   278
                        //add missing @param, @throws and @return, augmented with {@inheritDoc}
ee130cca69e6 8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents: 48028
diff changeset
   279
                        //which will be resolved in visitInheritDoc:
41865
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   280
                        List<DocTree> augmentedBlockTags = new ArrayList<>(node.getBlockTags());
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   281
                        if (element.getKind() == ElementKind.METHOD) {
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   282
                            ExecutableElement executableElement = (ExecutableElement) element;
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   283
                            List<String> parameters =
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   284
                                    executableElement.getParameters()
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   285
                                                     .stream()
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   286
                                                     .map(param -> param.getSimpleName().toString())
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   287
                                                     .collect(Collectors.toList());
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   288
                            List<String> throwsList =
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   289
                                    executableElement.getThrownTypes()
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   290
                                                     .stream()
42827
36468b5fa7f4 8181370: Convert anonymous inner classes into lambdas/method references
mcimadamore
parents: 41865
diff changeset
   291
                                                     .map(TypeMirror::toString)
41865
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   292
                                                     .collect(Collectors.toList());
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   293
                            Set<String> missingParams = new HashSet<>(parameters);
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   294
                            Set<String> missingThrows = new HashSet<>(throwsList);
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   295
                            boolean hasReturn = false;
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   296
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   297
                            for (DocTree dt : augmentedBlockTags) {
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   298
                                switch (dt.getKind()) {
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   299
                                    case PARAM:
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   300
                                        missingParams.remove(((ParamTree) dt).getName().getName().toString());
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   301
                                        break;
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   302
                                    case THROWS:
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   303
                                        missingThrows.remove(getThrownException(task, el, docCommentTree, (ThrowsTree) dt));
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   304
                                        break;
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   305
                                    case RETURN:
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   306
                                        hasReturn = true;
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   307
                                        break;
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   308
                                }
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   309
                            }
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   310
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   311
                            for (String missingParam : missingParams) {
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   312
                                DocTree syntheticTag = parseBlockTag(task, "@param " + missingParam + " {@inheritDoc}");
48237
ee130cca69e6 8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents: 48028
diff changeset
   313
                                syntheticTrees.put(syntheticTag, "@param " + missingParam + " *\n");
41865
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   314
                                insertTag(augmentedBlockTags, syntheticTag, parameters, throwsList);
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   315
                            }
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   316
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   317
                            for (String missingThrow : missingThrows) {
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   318
                                DocTree syntheticTag = parseBlockTag(task, "@throws " + missingThrow + " {@inheritDoc}");
48237
ee130cca69e6 8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents: 48028
diff changeset
   319
                                syntheticTrees.put(syntheticTag, "@throws " + missingThrow + " *\n");
41865
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   320
                                insertTag(augmentedBlockTags, syntheticTag, parameters, throwsList);
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   321
                            }
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   322
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   323
                            if (!hasReturn) {
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   324
                                DocTree syntheticTag = parseBlockTag(task, "@return {@inheritDoc}");
48237
ee130cca69e6 8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents: 48028
diff changeset
   325
                                syntheticTrees.put(syntheticTag, "@return *\n");
41865
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   326
                                insertTag(augmentedBlockTags, syntheticTag, parameters, throwsList);
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   327
                            }
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   328
                        }
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   329
                        scan(augmentedBlockTags, p);
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   330
                        return null;
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   331
                    } finally {
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   332
                        interestingParent.pop();
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   333
                    }
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   334
                }
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   335
                @Override @DefinedBy(Api.COMPILER_TREE)
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   336
                public Void visitParam(ParamTree node, Void p) {
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   337
                    interestingParent.push(node);
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   338
                    try {
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   339
                        return super.visitParam(node, p);
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   340
                    } finally {
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   341
                        interestingParent.pop();
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   342
                    }
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   343
                }
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   344
                @Override @DefinedBy(Api.COMPILER_TREE)
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   345
                public Void visitThrows(ThrowsTree node, Void p) {
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   346
                    interestingParent.push(node);
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   347
                    try {
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   348
                        return super.visitThrows(node, p);
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   349
                    } finally {
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   350
                        interestingParent.pop();
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   351
                    }
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   352
                }
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   353
                @Override @DefinedBy(Api.COMPILER_TREE)
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   354
                public Void visitReturn(ReturnTree node, Void p) {
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   355
                    interestingParent.push(node);
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   356
                    try {
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   357
                        return super.visitReturn(node, p);
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   358
                    } finally {
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   359
                        interestingParent.pop();
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   360
                    }
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   361
                }
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   362
                @Override @DefinedBy(Api.COMPILER_TREE)
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   363
                public Void visitInheritDoc(InheritDocTree node, Void p) {
48237
ee130cca69e6 8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents: 48028
diff changeset
   364
                    //replace (schedule replacement into the replace map)
ee130cca69e6 8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents: 48028
diff changeset
   365
                    //{@inheritDoc} with the corresponding text from an overridden method
ee130cca69e6 8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents: 48028
diff changeset
   366
ee130cca69e6 8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents: 48028
diff changeset
   367
                    //first, fill in inherited, inheritedJavacTask and inheritedTreePath if not
ee130cca69e6 8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents: 48028
diff changeset
   368
                    //done yet:
41865
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   369
                    if (inherited == null) {
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   370
                        try {
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   371
                            if (element.getKind() == ElementKind.METHOD) {
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   372
                                ExecutableElement executableElement = (ExecutableElement) element;
48237
ee130cca69e6 8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents: 48028
diff changeset
   373
                                Iterable<ExecutableElement> superMethods =
ee130cca69e6 8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents: 48028
diff changeset
   374
                                        () -> superMethodsForInheritDoc(task, executableElement).
ee130cca69e6 8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents: 48028
diff changeset
   375
                                              iterator();
ee130cca69e6 8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents: 48028
diff changeset
   376
                                for (Element supMethod : superMethods) {
ee130cca69e6 8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents: 48028
diff changeset
   377
                                   Pair<JavacTask, TreePath> source =
ee130cca69e6 8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents: 48028
diff changeset
   378
                                           getSourceElement(task, supMethod);
41865
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   379
48237
ee130cca69e6 8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents: 48028
diff changeset
   380
                                   if (source != null) {
ee130cca69e6 8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents: 48028
diff changeset
   381
                                       String overriddenComment =
ee130cca69e6 8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents: 48028
diff changeset
   382
                                               getResolvedDocComment(source.fst,
ee130cca69e6 8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents: 48028
diff changeset
   383
                                                                     source.snd);
41865
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   384
48237
ee130cca69e6 8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents: 48028
diff changeset
   385
                                       if (overriddenComment != null) {
ee130cca69e6 8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents: 48028
diff changeset
   386
                                           inheritedJavacTask = source.fst;
ee130cca69e6 8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents: 48028
diff changeset
   387
                                           inheritedTreePath = source.snd;
ee130cca69e6 8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents: 48028
diff changeset
   388
                                           inherited = overriddenComment;
ee130cca69e6 8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents: 48028
diff changeset
   389
                                           break;
41865
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   390
                                       }
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   391
                                   }
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   392
                                }
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   393
                            }
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   394
                        } catch (IOException ex) {
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   395
                            exception[0] = ex;
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   396
                            return null;
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   397
                        }
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   398
                    }
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   399
                    if (inherited == null) {
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   400
                        return null;
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   401
                    }
48028
9e022f580a9d 8190552: Augment the Compiler API tree with APIs to represent HTML content
ksrini
parents: 47216
diff changeset
   402
                    Pair<DocCommentTree, Integer> parsed =
9e022f580a9d 8190552: Augment the Compiler API tree with APIs to represent HTML content
ksrini
parents: 47216
diff changeset
   403
                            parseDocComment(inheritedJavacTask, inherited);
9e022f580a9d 8190552: Augment the Compiler API tree with APIs to represent HTML content
ksrini
parents: 47216
diff changeset
   404
                    DocCommentTree inheritedDocTree = parsed.fst;
9e022f580a9d 8190552: Augment the Compiler API tree with APIs to represent HTML content
ksrini
parents: 47216
diff changeset
   405
                    int offset = parsed.snd;
41865
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   406
                    List<List<? extends DocTree>> inheritedText = new ArrayList<>();
48237
ee130cca69e6 8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents: 48028
diff changeset
   407
                    //find the corresponding piece in the inherited javadoc
ee130cca69e6 8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents: 48028
diff changeset
   408
                    //(interesting parent keeps the enclosing tree):
41865
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   409
                    DocTree parent = interestingParent.peek();
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   410
                    switch (parent.getKind()) {
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   411
                        case DOC_COMMENT:
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   412
                            inheritedText.add(inheritedDocTree.getFullBody());
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   413
                            break;
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   414
                        case PARAM:
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   415
                            String paramName = ((ParamTree) parent).getName().getName().toString();
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   416
                            new DocTreeScanner<Void, Void>() {
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   417
                                @Override @DefinedBy(Api.COMPILER_TREE)
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   418
                                public Void visitParam(ParamTree node, Void p) {
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   419
                                    if (node.getName().getName().contentEquals(paramName)) {
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   420
                                        inheritedText.add(node.getDescription());
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   421
                                    }
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   422
                                    return super.visitParam(node, p);
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   423
                                }
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   424
                            }.scan(inheritedDocTree, null);
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   425
                            break;
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   426
                        case THROWS:
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   427
                            String thrownName = getThrownException(task, el, docCommentTree, (ThrowsTree) parent);
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   428
                            new DocTreeScanner<Void, Void>() {
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   429
                                @Override @DefinedBy(Api.COMPILER_TREE)
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   430
                                public Void visitThrows(ThrowsTree node, Void p) {
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   431
                                    if (Objects.equals(getThrownException(inheritedJavacTask, inheritedTreePath, inheritedDocTree, node), thrownName)) {
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   432
                                        inheritedText.add(node.getDescription());
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   433
                                    }
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   434
                                    return super.visitThrows(node, p);
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   435
                                }
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   436
                            }.scan(inheritedDocTree, null);
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   437
                            break;
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   438
                        case RETURN:
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   439
                            new DocTreeScanner<Void, Void>() {
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   440
                                @Override @DefinedBy(Api.COMPILER_TREE)
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   441
                                public Void visitReturn(ReturnTree node, Void p) {
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   442
                                    inheritedText.add(node.getDescription());
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   443
                                    return super.visitReturn(node, p);
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   444
                                }
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   445
                            }.scan(inheritedDocTree, null);
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   446
                            break;
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   447
                    }
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   448
                    if (!inheritedText.isEmpty()) {
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   449
                        long start = Long.MAX_VALUE;
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   450
                        long end = Long.MIN_VALUE;
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   451
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   452
                        for (DocTree t : inheritedText.get(0)) {
48237
ee130cca69e6 8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents: 48028
diff changeset
   453
                            start = Math.min(start,
ee130cca69e6 8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents: 48028
diff changeset
   454
                                             sp.getStartPosition(null, inheritedDocTree, t) - offset);
ee130cca69e6 8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents: 48028
diff changeset
   455
                            end   = Math.max(end,
ee130cca69e6 8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents: 48028
diff changeset
   456
                                             sp.getEndPosition(null, inheritedDocTree, t) - offset);
41865
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   457
                        }
48237
ee130cca69e6 8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents: 48028
diff changeset
   458
                        String text = end >= 0 ? inherited.substring((int) start, (int) end) : "";
41865
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   459
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   460
                        if (syntheticTrees.containsKey(parent)) {
48237
ee130cca69e6 8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents: 48028
diff changeset
   461
                            //if the {@inheritDoc} is inside a synthetic tree, don't delete anything,
ee130cca69e6 8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents: 48028
diff changeset
   462
                            //but insert the required text
ee130cca69e6 8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents: 48028
diff changeset
   463
                            //(insertPos is the position at which new stuff should be added):
ee130cca69e6 8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents: 48028
diff changeset
   464
                            int[] span = new int[] {(int) insertPos, (int) insertPos};
ee130cca69e6 8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents: 48028
diff changeset
   465
                            replace.computeIfAbsent(span, s -> new ArrayList<>())
ee130cca69e6 8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents: 48028
diff changeset
   466
                                    .add(syntheticTrees.get(parent).replace("*", text));
41865
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   467
                        } else {
48237
ee130cca69e6 8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents: 48028
diff changeset
   468
                            //replace the {@inheritDoc} with the full text from
ee130cca69e6 8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents: 48028
diff changeset
   469
                            //the overridden method:
ee130cca69e6 8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents: 48028
diff changeset
   470
                            long inheritedStart = sp.getStartPosition(null, dcTree, node);
ee130cca69e6 8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents: 48028
diff changeset
   471
                            long inheritedEnd   = sp.getEndPosition(null, dcTree, node);
ee130cca69e6 8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents: 48028
diff changeset
   472
                            int[] span = new int[] {(int) inheritedStart, (int) inheritedEnd};
41865
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   473
48237
ee130cca69e6 8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents: 48028
diff changeset
   474
                            replace.computeIfAbsent(span, s -> new ArrayList<>())
ee130cca69e6 8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents: 48028
diff changeset
   475
                                    .add(text);
41865
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   476
                        }
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   477
                    }
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   478
                    return super.visitInheritDoc(node, p);
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   479
                }
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   480
                private boolean inSynthetic;
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   481
                @Override @DefinedBy(Api.COMPILER_TREE)
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   482
                public Void scan(DocTree tree, Void p) {
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   483
                    if (exception[0] != null) {
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   484
                        return null;
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   485
                    }
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   486
                    boolean prevInSynthetic = inSynthetic;
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   487
                    try {
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   488
                        inSynthetic |= syntheticTrees.containsKey(tree);
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   489
                        return super.scan(tree, p);
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   490
                    } finally {
48237
ee130cca69e6 8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents: 48028
diff changeset
   491
                        if (!inSynthetic && tree != null) {
ee130cca69e6 8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents: 48028
diff changeset
   492
                            //for nonsynthetic trees, preserve the ending position as the future
ee130cca69e6 8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents: 48028
diff changeset
   493
                            //insertPos (as future missing elements should be inserted behind
ee130cca69e6 8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents: 48028
diff changeset
   494
                            //this tree)
ee130cca69e6 8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents: 48028
diff changeset
   495
                            //if there is a newline immediately behind this tree, insert behind
ee130cca69e6 8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents: 48028
diff changeset
   496
                            //the newline:
ee130cca69e6 8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents: 48028
diff changeset
   497
                            long endPos = sp.getEndPosition(null, dcTree, tree);
ee130cca69e6 8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents: 48028
diff changeset
   498
                            if (endPos >= 0) {
ee130cca69e6 8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents: 48028
diff changeset
   499
                                if (endPos - offset + 1 < docComment.length() &&
ee130cca69e6 8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents: 48028
diff changeset
   500
                                    docComment.charAt((int) (endPos - offset + 1)) == '\n') {
ee130cca69e6 8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents: 48028
diff changeset
   501
                                    endPos++;
ee130cca69e6 8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents: 48028
diff changeset
   502
                                }
ee130cca69e6 8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents: 48028
diff changeset
   503
                                if (endPos - offset < docComment.length()) {
ee130cca69e6 8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents: 48028
diff changeset
   504
                                    insertPos = endPos + 1;
ee130cca69e6 8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents: 48028
diff changeset
   505
                                } else {
ee130cca69e6 8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents: 48028
diff changeset
   506
                                    insertPos = endPos;
ee130cca69e6 8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents: 48028
diff changeset
   507
                                }
ee130cca69e6 8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents: 48028
diff changeset
   508
                            }
41865
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   509
                        }
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   510
                        inSynthetic = prevInSynthetic;
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   511
                    }
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   512
                }
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   513
48237
ee130cca69e6 8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents: 48028
diff changeset
   514
                /* Insert a synthetic tag (toInsert) into the list of tags at
ee130cca69e6 8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents: 48028
diff changeset
   515
                 * an appropriate position.*/
41865
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   516
                private void insertTag(List<DocTree> tags, DocTree toInsert, List<String> parameters, List<String> throwsTypes) {
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   517
                    Comparator<DocTree> comp = (tag1, tag2) -> {
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   518
                        if (tag1.getKind() == tag2.getKind()) {
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   519
                            switch (toInsert.getKind()) {
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   520
                                case PARAM: {
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   521
                                    ParamTree p1 = (ParamTree) tag1;
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   522
                                    ParamTree p2 = (ParamTree) tag2;
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   523
                                    int i1 = parameters.indexOf(p1.getName().getName().toString());
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   524
                                    int i2 = parameters.indexOf(p2.getName().getName().toString());
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   525
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   526
                                    return i1 - i2;
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   527
                                }
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   528
                                case THROWS: {
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   529
                                    ThrowsTree t1 = (ThrowsTree) tag1;
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   530
                                    ThrowsTree t2 = (ThrowsTree) tag2;
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   531
                                    int i1 = throwsTypes.indexOf(getThrownException(task, el, docCommentTree, t1));
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   532
                                    int i2 = throwsTypes.indexOf(getThrownException(task, el, docCommentTree, t2));
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   533
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   534
                                    return i1 - i2;
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   535
                                }
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   536
                            }
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   537
                        }
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   538
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   539
                        int i1 = tagOrder.indexOf(tag1.getKind());
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   540
                        int i2 = tagOrder.indexOf(tag2.getKind());
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   541
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   542
                        return i1 - i2;
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   543
                    };
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   544
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   545
                    for (int i = 0; i < tags.size(); i++) {
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   546
                        if (comp.compare(tags.get(i), toInsert) >= 0) {
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   547
                            tags.add(i, toInsert);
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   548
                            return ;
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   549
                        }
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   550
                    }
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   551
                    tags.add(toInsert);
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   552
                }
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   553
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   554
                private final List<DocTree.Kind> tagOrder = Arrays.asList(DocTree.Kind.PARAM, DocTree.Kind.THROWS, DocTree.Kind.RETURN);
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   555
            }.scan(docCommentTree, null);
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   556
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   557
            if (replace.isEmpty())
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   558
                return docComment;
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   559
48237
ee130cca69e6 8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents: 48028
diff changeset
   560
            //do actually replace {@inheritDoc} with the new text (as scheduled by the visitor
ee130cca69e6 8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents: 48028
diff changeset
   561
            //above):
41865
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   562
            StringBuilder replacedInheritDoc = new StringBuilder(docComment);
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   563
48237
ee130cca69e6 8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents: 48028
diff changeset
   564
            for (Entry<int[], List<String>> e : replace.entrySet()) {
ee130cca69e6 8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents: 48028
diff changeset
   565
                replacedInheritDoc.delete(e.getKey()[0] - offset, e.getKey()[1] - offset);
ee130cca69e6 8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents: 48028
diff changeset
   566
                replacedInheritDoc.insert(e.getKey()[0] - offset,
ee130cca69e6 8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents: 48028
diff changeset
   567
                                          e.getValue().stream().collect(Collectors.joining("")));
41865
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   568
            }
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   569
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   570
            return replacedInheritDoc.toString();
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   571
        }
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   572
48237
ee130cca69e6 8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents: 48028
diff changeset
   573
        /* Find methods from which the given method may inherit javadoc, in the proper order.*/
ee130cca69e6 8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents: 48028
diff changeset
   574
        private Stream<ExecutableElement> superMethodsForInheritDoc(JavacTask task,
ee130cca69e6 8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents: 48028
diff changeset
   575
                                                                     ExecutableElement method) {
ee130cca69e6 8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents: 48028
diff changeset
   576
            TypeElement type = (TypeElement) method.getEnclosingElement();
ee130cca69e6 8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents: 48028
diff changeset
   577
ee130cca69e6 8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents: 48028
diff changeset
   578
            return this.superTypeForInheritDoc(task, type)
ee130cca69e6 8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents: 48028
diff changeset
   579
                       .flatMap(sup -> ElementFilter.methodsIn(sup.getEnclosedElements()).stream())
ee130cca69e6 8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents: 48028
diff changeset
   580
                       .filter(supMethod -> task.getElements().overrides(method, supMethod, type));
ee130cca69e6 8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents: 48028
diff changeset
   581
        }
ee130cca69e6 8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents: 48028
diff changeset
   582
ee130cca69e6 8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents: 48028
diff changeset
   583
        /* Find types from which methods in type may inherit javadoc, in the proper order.*/
41865
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   584
        private Stream<Element> superTypeForInheritDoc(JavacTask task, Element type) {
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   585
            TypeElement clazz = (TypeElement) type;
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   586
            Stream<Element> result = interfaces(clazz);
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   587
            result = Stream.concat(result, interfaces(clazz).flatMap(el -> superTypeForInheritDoc(task, el)));
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   588
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   589
            if (clazz.getSuperclass().getKind() == TypeKind.DECLARED) {
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   590
                Element superClass = ((DeclaredType) clazz.getSuperclass()).asElement();
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   591
                result = Stream.concat(result, Stream.of(superClass));
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   592
                result = Stream.concat(result, superTypeForInheritDoc(task, superClass));
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   593
            }
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   594
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   595
            return result;
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   596
        }
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   597
        //where:
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   598
            private Stream<Element> interfaces(TypeElement clazz) {
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   599
                return clazz.getInterfaces()
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   600
                            .stream()
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   601
                            .filter(tm -> tm.getKind() == TypeKind.DECLARED)
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   602
                            .map(tm -> ((DeclaredType) tm).asElement());
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   603
            }
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   604
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   605
         private DocTree parseBlockTag(JavacTask task, String blockTag) {
48028
9e022f580a9d 8190552: Augment the Compiler API tree with APIs to represent HTML content
ksrini
parents: 47216
diff changeset
   606
            DocCommentTree dc = parseDocComment(task, blockTag).fst;
41865
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   607
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   608
            return dc.getBlockTags().get(0);
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   609
        }
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   610
48028
9e022f580a9d 8190552: Augment the Compiler API tree with APIs to represent HTML content
ksrini
parents: 47216
diff changeset
   611
        private Pair<DocCommentTree, Integer> parseDocComment(JavacTask task, String javadoc) {
41865
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   612
            DocTrees trees = DocTrees.instance(task);
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   613
            try {
48028
9e022f580a9d 8190552: Augment the Compiler API tree with APIs to represent HTML content
ksrini
parents: 47216
diff changeset
   614
                SimpleJavaFileObject fo =
9e022f580a9d 8190552: Augment the Compiler API tree with APIs to represent HTML content
ksrini
parents: 47216
diff changeset
   615
                        new SimpleJavaFileObject(new URI("mem://doc.html"), Kind.HTML) {
41865
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   616
                    @Override @DefinedBy(Api.COMPILER)
48028
9e022f580a9d 8190552: Augment the Compiler API tree with APIs to represent HTML content
ksrini
parents: 47216
diff changeset
   617
                    public CharSequence getCharContent(boolean ignoreEncodingErrors)
9e022f580a9d 8190552: Augment the Compiler API tree with APIs to represent HTML content
ksrini
parents: 47216
diff changeset
   618
                            throws IOException {
41865
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   619
                        return "<body>" + javadoc + "</body>";
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   620
                    }
48028
9e022f580a9d 8190552: Augment the Compiler API tree with APIs to represent HTML content
ksrini
parents: 47216
diff changeset
   621
                };
9e022f580a9d 8190552: Augment the Compiler API tree with APIs to represent HTML content
ksrini
parents: 47216
diff changeset
   622
                DocCommentTree tree = trees.getDocCommentTree(fo);
9e022f580a9d 8190552: Augment the Compiler API tree with APIs to represent HTML content
ksrini
parents: 47216
diff changeset
   623
                int offset = (int) trees.getSourcePositions().getStartPosition(null, tree, tree);
48237
ee130cca69e6 8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents: 48028
diff changeset
   624
                offset += "<body>".length();
48028
9e022f580a9d 8190552: Augment the Compiler API tree with APIs to represent HTML content
ksrini
parents: 47216
diff changeset
   625
                return Pair.of(tree, offset);
41865
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   626
            } catch (URISyntaxException ex) {
48028
9e022f580a9d 8190552: Augment the Compiler API tree with APIs to represent HTML content
ksrini
parents: 47216
diff changeset
   627
                throw new IllegalStateException(ex);
41865
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   628
            }
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   629
        }
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   630
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   631
        private String getThrownException(JavacTask task, TreePath rootOn, DocCommentTree comment, ThrowsTree tt) {
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   632
            DocTrees trees = DocTrees.instance(task);
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   633
            Element exc = trees.getElement(new DocTreePath(new DocTreePath(rootOn, comment), tt.getExceptionName()));
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   634
            return exc != null ? exc.toString() : null;
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   635
        }
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   636
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   637
        private Pair<JavacTask, TreePath> getSourceElement(JavacTask origin, Element el) throws IOException {
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   638
            String handle = elementSignature(el);
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   639
            Pair<JavacTask, TreePath> cached = signature2Source.get(handle);
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   640
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   641
            if (cached != null) {
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   642
                return cached.fst != null ? cached : null;
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   643
            }
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   644
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   645
            TypeElement type = topLevelType(el);
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   646
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   647
            if (type == null)
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   648
                return null;
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   649
43773
8d8593871575 8174245: Javadoc is not working for some methods
jlahoda
parents: 42827
diff changeset
   650
            Elements elements = origin.getElements();
8d8593871575 8174245: Javadoc is not working for some methods
jlahoda
parents: 42827
diff changeset
   651
            String binaryName = elements.getBinaryName(type).toString();
8d8593871575 8174245: Javadoc is not working for some methods
jlahoda
parents: 42827
diff changeset
   652
            ModuleElement module = elements.getModuleOf(type);
8d8593871575 8174245: Javadoc is not working for some methods
jlahoda
parents: 42827
diff changeset
   653
            String moduleName = module == null || module.isUnnamed()
8d8593871575 8174245: Javadoc is not working for some methods
jlahoda
parents: 42827
diff changeset
   654
                    ? null
8d8593871575 8174245: Javadoc is not working for some methods
jlahoda
parents: 42827
diff changeset
   655
                    : module.getQualifiedName().toString();
8d8593871575 8174245: Javadoc is not working for some methods
jlahoda
parents: 42827
diff changeset
   656
            Pair<JavacTask, CompilationUnitTree> source = findSource(moduleName, binaryName);
41865
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   657
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   658
            if (source == null)
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   659
                return null;
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   660
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   661
            fillElementCache(source.fst, source.snd);
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   662
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   663
            cached = signature2Source.get(handle);
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   664
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   665
            if (cached != null) {
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   666
                return cached;
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   667
            } else {
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   668
                signature2Source.put(handle, Pair.of(null, null));
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   669
                return null;
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   670
            }
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   671
        }
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   672
        //where:
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   673
            private String elementSignature(Element el) {
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   674
                switch (el.getKind()) {
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   675
                    case ANNOTATION_TYPE: case CLASS: case ENUM: case INTERFACE:
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   676
                        return ((TypeElement) el).getQualifiedName().toString();
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   677
                    case FIELD:
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   678
                        return elementSignature(el.getEnclosingElement()) + "." + el.getSimpleName() + ":" + el.asType();
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   679
                    case ENUM_CONSTANT:
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   680
                        return elementSignature(el.getEnclosingElement()) + "." + el.getSimpleName();
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   681
                    case EXCEPTION_PARAMETER: case LOCAL_VARIABLE: case PARAMETER: case RESOURCE_VARIABLE:
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   682
                        return el.getSimpleName() + ":" + el.asType();
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   683
                    case CONSTRUCTOR: case METHOD:
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   684
                        StringBuilder header = new StringBuilder();
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   685
                        header.append(elementSignature(el.getEnclosingElement()));
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   686
                        if (el.getKind() == ElementKind.METHOD) {
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   687
                            header.append(".");
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   688
                            header.append(el.getSimpleName());
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   689
                        }
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   690
                        header.append("(");
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   691
                        String sep = "";
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   692
                        ExecutableElement method = (ExecutableElement) el;
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   693
                        for (Iterator<? extends VariableElement> i = method.getParameters().iterator(); i.hasNext();) {
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   694
                            VariableElement p = i.next();
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   695
                            header.append(sep);
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   696
                            header.append(p.asType());
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   697
                            sep = ", ";
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   698
                        }
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   699
                        header.append(")");
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   700
                        return header.toString();
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   701
                   default:
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   702
                        return el.toString();
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   703
                }
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   704
            }
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   705
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   706
            private TypeElement topLevelType(Element el) {
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   707
                if (el.getKind() == ElementKind.PACKAGE)
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   708
                    return null;
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   709
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   710
                while (el != null && el.getEnclosingElement().getKind() != ElementKind.PACKAGE) {
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   711
                    el = el.getEnclosingElement();
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   712
                }
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   713
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   714
                return el != null && (el.getKind().isClass() || el.getKind().isInterface()) ? (TypeElement) el : null;
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   715
            }
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   716
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   717
            private void fillElementCache(JavacTask task, CompilationUnitTree cut) throws IOException {
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   718
                Trees trees = Trees.instance(task);
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   719
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   720
                new TreePathScanner<Void, Void>() {
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   721
                    @Override @DefinedBy(Api.COMPILER_TREE)
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   722
                    public Void visitMethod(MethodTree node, Void p) {
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   723
                        handleDeclaration();
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   724
                        return null;
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   725
                    }
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   726
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   727
                    @Override @DefinedBy(Api.COMPILER_TREE)
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   728
                    public Void visitClass(ClassTree node, Void p) {
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   729
                        handleDeclaration();
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   730
                        return super.visitClass(node, p);
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   731
                    }
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   732
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   733
                    @Override @DefinedBy(Api.COMPILER_TREE)
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   734
                    public Void visitVariable(VariableTree node, Void p) {
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   735
                        handleDeclaration();
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   736
                        return super.visitVariable(node, p);
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   737
                    }
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   738
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   739
                    private void handleDeclaration() {
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   740
                        Element currentElement = trees.getElement(getCurrentPath());
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   741
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   742
                        if (currentElement != null) {
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   743
                            signature2Source.put(elementSignature(currentElement), Pair.of(task, getCurrentPath()));
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   744
                        }
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   745
                    }
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   746
                }.scan(cut, null);
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   747
            }
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   748
43773
8d8593871575 8174245: Javadoc is not working for some methods
jlahoda
parents: 42827
diff changeset
   749
        private Pair<JavacTask, CompilationUnitTree> findSource(String moduleName,
8d8593871575 8174245: Javadoc is not working for some methods
jlahoda
parents: 42827
diff changeset
   750
                                                                String binaryName) throws IOException {
41865
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   751
            JavaFileObject jfo = fm.getJavaFileForInput(StandardLocation.SOURCE_PATH,
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   752
                                                        binaryName,
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   753
                                                        JavaFileObject.Kind.SOURCE);
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   754
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   755
            if (jfo == null)
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   756
                return null;
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   757
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   758
            List<JavaFileObject> jfos = Arrays.asList(jfo);
43773
8d8593871575 8174245: Javadoc is not working for some methods
jlahoda
parents: 42827
diff changeset
   759
            JavaFileManager patchFM = moduleName != null
8d8593871575 8174245: Javadoc is not working for some methods
jlahoda
parents: 42827
diff changeset
   760
                    ? new PatchModuleFileManager(baseFileManager, jfo, moduleName)
8d8593871575 8174245: Javadoc is not working for some methods
jlahoda
parents: 42827
diff changeset
   761
                    : baseFileManager;
8d8593871575 8174245: Javadoc is not working for some methods
jlahoda
parents: 42827
diff changeset
   762
            JavacTaskImpl task = (JavacTaskImpl) compiler.getTask(null, patchFM, d -> {}, null, null, jfos);
41865
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   763
            Iterable<? extends CompilationUnitTree> cuts = task.parse();
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   764
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   765
            task.enter();
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   766
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   767
            return Pair.of(task, cuts.iterator().next());
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   768
        }
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   769
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   770
        @Override
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   771
        public void close() throws IOException {
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   772
            fm.close();
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   773
        }
43773
8d8593871575 8174245: Javadoc is not working for some methods
jlahoda
parents: 42827
diff changeset
   774
8d8593871575 8174245: Javadoc is not working for some methods
jlahoda
parents: 42827
diff changeset
   775
        private static final class PatchModuleFileManager
8d8593871575 8174245: Javadoc is not working for some methods
jlahoda
parents: 42827
diff changeset
   776
                extends ForwardingJavaFileManager<JavaFileManager> {
8d8593871575 8174245: Javadoc is not working for some methods
jlahoda
parents: 42827
diff changeset
   777
8d8593871575 8174245: Javadoc is not working for some methods
jlahoda
parents: 42827
diff changeset
   778
            private final JavaFileObject file;
8d8593871575 8174245: Javadoc is not working for some methods
jlahoda
parents: 42827
diff changeset
   779
            private final String moduleName;
8d8593871575 8174245: Javadoc is not working for some methods
jlahoda
parents: 42827
diff changeset
   780
8d8593871575 8174245: Javadoc is not working for some methods
jlahoda
parents: 42827
diff changeset
   781
            public PatchModuleFileManager(JavaFileManager fileManager,
8d8593871575 8174245: Javadoc is not working for some methods
jlahoda
parents: 42827
diff changeset
   782
                                          JavaFileObject file,
8d8593871575 8174245: Javadoc is not working for some methods
jlahoda
parents: 42827
diff changeset
   783
                                          String moduleName) {
8d8593871575 8174245: Javadoc is not working for some methods
jlahoda
parents: 42827
diff changeset
   784
                super(fileManager);
8d8593871575 8174245: Javadoc is not working for some methods
jlahoda
parents: 42827
diff changeset
   785
                this.file = file;
8d8593871575 8174245: Javadoc is not working for some methods
jlahoda
parents: 42827
diff changeset
   786
                this.moduleName = moduleName;
8d8593871575 8174245: Javadoc is not working for some methods
jlahoda
parents: 42827
diff changeset
   787
            }
8d8593871575 8174245: Javadoc is not working for some methods
jlahoda
parents: 42827
diff changeset
   788
8d8593871575 8174245: Javadoc is not working for some methods
jlahoda
parents: 42827
diff changeset
   789
            @Override @DefinedBy(Api.COMPILER)
8d8593871575 8174245: Javadoc is not working for some methods
jlahoda
parents: 42827
diff changeset
   790
            public Location getLocationForModule(Location location,
44063
5f0cf4126949 8175560: Drop String pkgName from javax.tools.JavaFileManager.getLocationForModule(Location location, JavaFileObject fo, String pkgName)
jlahoda
parents: 43773
diff changeset
   791
                                                 JavaFileObject fo) throws IOException {
43773
8d8593871575 8174245: Javadoc is not working for some methods
jlahoda
parents: 42827
diff changeset
   792
                return fo == file
8d8593871575 8174245: Javadoc is not working for some methods
jlahoda
parents: 42827
diff changeset
   793
                        ? PATCH_LOCATION
44063
5f0cf4126949 8175560: Drop String pkgName from javax.tools.JavaFileManager.getLocationForModule(Location location, JavaFileObject fo, String pkgName)
jlahoda
parents: 43773
diff changeset
   794
                        : super.getLocationForModule(location, fo);
43773
8d8593871575 8174245: Javadoc is not working for some methods
jlahoda
parents: 42827
diff changeset
   795
            }
8d8593871575 8174245: Javadoc is not working for some methods
jlahoda
parents: 42827
diff changeset
   796
8d8593871575 8174245: Javadoc is not working for some methods
jlahoda
parents: 42827
diff changeset
   797
            @Override @DefinedBy(Api.COMPILER)
8d8593871575 8174245: Javadoc is not working for some methods
jlahoda
parents: 42827
diff changeset
   798
            public String inferModuleName(Location location) throws IOException {
8d8593871575 8174245: Javadoc is not working for some methods
jlahoda
parents: 42827
diff changeset
   799
                return location == PATCH_LOCATION
8d8593871575 8174245: Javadoc is not working for some methods
jlahoda
parents: 42827
diff changeset
   800
                        ? moduleName
8d8593871575 8174245: Javadoc is not working for some methods
jlahoda
parents: 42827
diff changeset
   801
                        : super.inferModuleName(location);
8d8593871575 8174245: Javadoc is not working for some methods
jlahoda
parents: 42827
diff changeset
   802
            }
8d8593871575 8174245: Javadoc is not working for some methods
jlahoda
parents: 42827
diff changeset
   803
8d8593871575 8174245: Javadoc is not working for some methods
jlahoda
parents: 42827
diff changeset
   804
            @Override @DefinedBy(Api.COMPILER)
8d8593871575 8174245: Javadoc is not working for some methods
jlahoda
parents: 42827
diff changeset
   805
            public boolean hasLocation(Location location) {
8d8593871575 8174245: Javadoc is not working for some methods
jlahoda
parents: 42827
diff changeset
   806
                return location == StandardLocation.PATCH_MODULE_PATH ||
8d8593871575 8174245: Javadoc is not working for some methods
jlahoda
parents: 42827
diff changeset
   807
                       super.hasLocation(location);
8d8593871575 8174245: Javadoc is not working for some methods
jlahoda
parents: 42827
diff changeset
   808
            }
8d8593871575 8174245: Javadoc is not working for some methods
jlahoda
parents: 42827
diff changeset
   809
8d8593871575 8174245: Javadoc is not working for some methods
jlahoda
parents: 42827
diff changeset
   810
            private static final Location PATCH_LOCATION = new Location() {
8d8593871575 8174245: Javadoc is not working for some methods
jlahoda
parents: 42827
diff changeset
   811
                @Override @DefinedBy(Api.COMPILER)
8d8593871575 8174245: Javadoc is not working for some methods
jlahoda
parents: 42827
diff changeset
   812
                public String getName() {
8d8593871575 8174245: Javadoc is not working for some methods
jlahoda
parents: 42827
diff changeset
   813
                    return "PATCH_LOCATION";
8d8593871575 8174245: Javadoc is not working for some methods
jlahoda
parents: 42827
diff changeset
   814
                }
8d8593871575 8174245: Javadoc is not working for some methods
jlahoda
parents: 42827
diff changeset
   815
8d8593871575 8174245: Javadoc is not working for some methods
jlahoda
parents: 42827
diff changeset
   816
                @Override @DefinedBy(Api.COMPILER)
8d8593871575 8174245: Javadoc is not working for some methods
jlahoda
parents: 42827
diff changeset
   817
                public boolean isOutputLocation() {
8d8593871575 8174245: Javadoc is not working for some methods
jlahoda
parents: 42827
diff changeset
   818
                    return false;
8d8593871575 8174245: Javadoc is not working for some methods
jlahoda
parents: 42827
diff changeset
   819
                }
8d8593871575 8174245: Javadoc is not working for some methods
jlahoda
parents: 42827
diff changeset
   820
8d8593871575 8174245: Javadoc is not working for some methods
jlahoda
parents: 42827
diff changeset
   821
                @Override @DefinedBy(Api.COMPILER)
8d8593871575 8174245: Javadoc is not working for some methods
jlahoda
parents: 42827
diff changeset
   822
                public boolean isModuleOrientedLocation() {
8d8593871575 8174245: Javadoc is not working for some methods
jlahoda
parents: 42827
diff changeset
   823
                    return false;
8d8593871575 8174245: Javadoc is not working for some methods
jlahoda
parents: 42827
diff changeset
   824
                }
8d8593871575 8174245: Javadoc is not working for some methods
jlahoda
parents: 42827
diff changeset
   825
8d8593871575 8174245: Javadoc is not working for some methods
jlahoda
parents: 42827
diff changeset
   826
            };
8d8593871575 8174245: Javadoc is not working for some methods
jlahoda
parents: 42827
diff changeset
   827
        }
41865
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   828
    }
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   829
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents:
diff changeset
   830
}