langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/CommentUtils.java
author ksrini
Mon, 10 Oct 2016 11:21:00 -0700
changeset 41452 ddaef4bba083
parent 39364 bd6d4a7936b4
child 43261 d377e97291d8
permissions -rw-r--r--
8165991: Fix DocTreeFactory newDocCommentTree 8154349: New doclet incorrectly shows entire text body for JavaFX properties in summary section Reviewed-by: jjg
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
diff changeset
     1
/*
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
diff changeset
     2
 * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
diff changeset
     4
 *
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
diff changeset
    10
 *
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
diff changeset
    15
 * accompanied this code).
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
diff changeset
    16
 *
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
diff changeset
    20
 *
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
diff changeset
    23
 * questions.
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
diff changeset
    24
 */
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
diff changeset
    25
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
diff changeset
    26
/**
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
diff changeset
    27
 *  A utility class.
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
diff changeset
    28
 *
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
diff changeset
    29
 *  <p><b>This is NOT part of any supported API.
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
diff changeset
    30
 *  If you write code that depends on this, you do so at your own risk.
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
diff changeset
    31
 *  This code and its internal interfaces are subject to change or
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
diff changeset
    32
 *  deletion without notice.</b>
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
diff changeset
    33
 */
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
diff changeset
    34
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
diff changeset
    35
package jdk.javadoc.internal.doclets.toolkit;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
diff changeset
    36
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
diff changeset
    37
import com.sun.source.doctree.DocCommentTree;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
diff changeset
    38
import com.sun.source.doctree.DocTree;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
diff changeset
    39
import com.sun.source.doctree.IdentifierTree;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
diff changeset
    40
import com.sun.source.doctree.ReferenceTree;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
diff changeset
    41
import com.sun.source.doctree.TextTree;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
diff changeset
    42
import com.sun.source.util.DocTreeFactory;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
diff changeset
    43
import com.sun.source.util.DocTreePath;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
diff changeset
    44
import com.sun.source.util.DocTrees;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
diff changeset
    45
import com.sun.source.util.TreePath;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
diff changeset
    46
import java.util.ArrayList;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
diff changeset
    47
import java.util.HashMap;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
diff changeset
    48
import java.util.List;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
diff changeset
    49
import javax.lang.model.element.Element;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
diff changeset
    50
import javax.lang.model.element.ElementKind;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
diff changeset
    51
import javax.lang.model.element.ExecutableElement;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
diff changeset
    52
import javax.lang.model.element.Name;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
diff changeset
    53
import javax.lang.model.element.PackageElement;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
diff changeset
    54
import javax.lang.model.element.VariableElement;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
diff changeset
    55
import javax.lang.model.util.Elements;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
diff changeset
    56
import javax.tools.FileObject;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
diff changeset
    57
import jdk.javadoc.internal.doclets.toolkit.util.Utils;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
diff changeset
    58
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
diff changeset
    59
public class CommentUtils {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
diff changeset
    60
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
diff changeset
    61
    final Configuration configuration;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
diff changeset
    62
    final DocTreeFactory treeFactory;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
diff changeset
    63
    final HashMap<Element, DocCommentDuo> dcTreesMap = new HashMap<>();
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
diff changeset
    64
    final DocTrees trees;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
diff changeset
    65
    final Elements elementUtils;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
diff changeset
    66
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
diff changeset
    67
    protected CommentUtils(Configuration configuration) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
diff changeset
    68
        this.configuration = configuration;
39364
bd6d4a7936b4 8160301: javadoc RootDoclmpl and DocEnv needs to be renamed
ksrini
parents: 35426
diff changeset
    69
        trees = configuration.docEnv.getDocTrees();
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
diff changeset
    70
        treeFactory = trees.getDocTreeFactory();
39364
bd6d4a7936b4 8160301: javadoc RootDoclmpl and DocEnv needs to be renamed
ksrini
parents: 35426
diff changeset
    71
        elementUtils = configuration.docEnv.getElementUtils();
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
diff changeset
    72
    }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
diff changeset
    73
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
diff changeset
    74
    public List<? extends DocTree> makePropertyDescriptionTree(List<? extends DocTree> content) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
diff changeset
    75
        List<DocTree> out = new ArrayList<>();
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
diff changeset
    76
        Name name = elementUtils.getName("propertyDescription");
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
diff changeset
    77
        out.add(treeFactory.newUnknownBlockTagTree(name, content));
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
diff changeset
    78
        return out;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
diff changeset
    79
    }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
diff changeset
    80
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
diff changeset
    81
    public List<? extends DocTree> makePropertyDescriptionTree(String content) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
diff changeset
    82
        List<DocTree> inlist = new ArrayList<>();
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
diff changeset
    83
        inlist.add(treeFactory.newCommentTree(content));
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
diff changeset
    84
        List<DocTree> out = new ArrayList<>();
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
diff changeset
    85
        Name name = elementUtils.getName("propertyDescription");
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
diff changeset
    86
        out.add(treeFactory.newUnknownBlockTagTree(name, inlist));
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
diff changeset
    87
        return out;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
diff changeset
    88
    }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
diff changeset
    89
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
diff changeset
    90
    public List<? extends DocTree> makeFirstSentenceTree(String content) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
diff changeset
    91
        List<DocTree> out = new ArrayList<>();
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
diff changeset
    92
        out.add(treeFactory.newTextTree(content));
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
diff changeset
    93
        return out;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
diff changeset
    94
    }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
diff changeset
    95
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
diff changeset
    96
    public DocTree makeSeeTree(String sig, Element e) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
diff changeset
    97
        List<DocTree> list = new ArrayList<>();
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
diff changeset
    98
        list.add(treeFactory.newReferenceTree(sig));
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
diff changeset
    99
        return treeFactory.newSeeTree(list);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
diff changeset
   100
    }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
diff changeset
   101
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
diff changeset
   102
    public DocTree makeTextTree(String content) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
diff changeset
   103
        TextTree text = treeFactory.newTextTree(content);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
diff changeset
   104
        return (DocTree) text;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
diff changeset
   105
    }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
diff changeset
   106
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
diff changeset
   107
    public void setEnumValuesTree(Configuration config, Element e) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
diff changeset
   108
        Utils utils = config.utils;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
diff changeset
   109
        String klassName = utils.getSimpleName(utils.getEnclosingTypeElement(e));
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
diff changeset
   110
41452
ddaef4bba083 8165991: Fix DocTreeFactory newDocCommentTree
ksrini
parents: 39364
diff changeset
   111
        List<DocTree> fullBody = new ArrayList<>();
ddaef4bba083 8165991: Fix DocTreeFactory newDocCommentTree
ksrini
parents: 39364
diff changeset
   112
        fullBody.add(treeFactory.newTextTree(config.getText("doclet.enum_values_doc.fullbody", klassName)));
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
diff changeset
   113
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
diff changeset
   114
        List<DocTree> descriptions = new ArrayList<>();
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
diff changeset
   115
        descriptions.add(treeFactory.newTextTree(config.getText("doclet.enum_values_doc.return")));
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
diff changeset
   116
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
diff changeset
   117
        List<DocTree> tags = new ArrayList<>();
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
diff changeset
   118
        tags.add(treeFactory.newReturnTree(descriptions));
41452
ddaef4bba083 8165991: Fix DocTreeFactory newDocCommentTree
ksrini
parents: 39364
diff changeset
   119
        DocCommentTree docTree = treeFactory.newDocCommentTree(fullBody, tags);
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
diff changeset
   120
        dcTreesMap.put(e, new DocCommentDuo(null, docTree));
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
diff changeset
   121
    }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
diff changeset
   122
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
diff changeset
   123
    public void setEnumValueOfTree(Configuration config, Element e) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
diff changeset
   124
41452
ddaef4bba083 8165991: Fix DocTreeFactory newDocCommentTree
ksrini
parents: 39364
diff changeset
   125
        List<DocTree> fullBody = new ArrayList<>();
ddaef4bba083 8165991: Fix DocTreeFactory newDocCommentTree
ksrini
parents: 39364
diff changeset
   126
        fullBody.add(treeFactory.newTextTree(config.getText("doclet.enum_valueof_doc.fullbody")));
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
diff changeset
   127
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
diff changeset
   128
        List<DocTree> tags = new ArrayList<>();
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
diff changeset
   129
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
diff changeset
   130
        List<DocTree> paramDescs = new ArrayList<>();
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
diff changeset
   131
        paramDescs.add(treeFactory.newTextTree(config.getText("doclet.enum_valueof_doc.param_name")));
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
diff changeset
   132
        ExecutableElement ee = (ExecutableElement) e;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
diff changeset
   133
        java.util.List<? extends VariableElement> parameters = ee.getParameters();
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
diff changeset
   134
        VariableElement param = parameters.get(0);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
diff changeset
   135
        IdentifierTree id = treeFactory.newIdentifierTree(elementUtils.getName(param.getSimpleName().toString()));
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
diff changeset
   136
        tags.add(treeFactory.newParamTree(false, id, paramDescs));
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
diff changeset
   137
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
diff changeset
   138
        List<DocTree> returnDescs = new ArrayList<>();
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
diff changeset
   139
        returnDescs.add(treeFactory.newTextTree(config.getText("doclet.enum_valueof_doc.return")));
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
diff changeset
   140
        tags.add(treeFactory.newReturnTree(returnDescs));
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
diff changeset
   141
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
diff changeset
   142
        List<DocTree> throwsDescs = new ArrayList<>();
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
diff changeset
   143
        throwsDescs.add(treeFactory.newTextTree(config.getText("doclet.enum_valueof_doc.throws_ila")));
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
diff changeset
   144
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
diff changeset
   145
        ReferenceTree ref = treeFactory.newReferenceTree("java.lang.IllegalArgumentException");
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
diff changeset
   146
        tags.add(treeFactory.newThrowsTree(ref, throwsDescs));
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
diff changeset
   147
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
diff changeset
   148
        throwsDescs = new ArrayList<>();
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
diff changeset
   149
        throwsDescs.add(treeFactory.newTextTree(config.getText("doclet.enum_valueof_doc.throws_npe")));
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
diff changeset
   150
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
diff changeset
   151
        ref = treeFactory.newReferenceTree("java.lang.NullPointerException");
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
diff changeset
   152
        tags.add(treeFactory.newThrowsTree(ref, throwsDescs));
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
diff changeset
   153
41452
ddaef4bba083 8165991: Fix DocTreeFactory newDocCommentTree
ksrini
parents: 39364
diff changeset
   154
        DocCommentTree docTree = treeFactory.newDocCommentTree(fullBody, tags);
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
diff changeset
   155
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
diff changeset
   156
        dcTreesMap.put(e, new DocCommentDuo(null, docTree));
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
diff changeset
   157
    }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
diff changeset
   158
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
diff changeset
   159
    /*
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
diff changeset
   160
     * Returns the TreePath/DocCommentTree duo for synthesized element.
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
diff changeset
   161
     */
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
diff changeset
   162
    public DocCommentDuo getSyntheticCommentDuo(Element e) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
diff changeset
   163
        return dcTreesMap.get(e);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
diff changeset
   164
    }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
diff changeset
   165
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
diff changeset
   166
    /*
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
diff changeset
   167
     * Returns the TreePath/DocCommentTree duo for html sources.
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
diff changeset
   168
     */
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
diff changeset
   169
    public DocCommentDuo getHtmlCommentDuo(Element e) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
diff changeset
   170
        FileObject fo = null;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
diff changeset
   171
        if (e.getKind().equals(ElementKind.OTHER)) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
diff changeset
   172
            fo = configuration.getOverviewPath();
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
diff changeset
   173
        } else if (e.getKind().equals(ElementKind.PACKAGE)) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
diff changeset
   174
            fo = configuration.workArounds.getJavaFileObject((PackageElement)e);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
diff changeset
   175
        }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
diff changeset
   176
        if (fo == null) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
diff changeset
   177
            return null;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
diff changeset
   178
        }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
diff changeset
   179
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
diff changeset
   180
        DocCommentTree dcTree = trees.getDocCommentTree(fo);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
diff changeset
   181
        if (dcTree == null) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
diff changeset
   182
            return null;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
diff changeset
   183
        }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
diff changeset
   184
        DocTreePath treePath = trees.getDocTreePath(fo);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
diff changeset
   185
        return new DocCommentDuo(treePath.getTreePath(), dcTree);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
diff changeset
   186
    }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
diff changeset
   187
41452
ddaef4bba083 8165991: Fix DocTreeFactory newDocCommentTree
ksrini
parents: 39364
diff changeset
   188
    public void setDocCommentTree(Element element, List<DocTree> fullBody,
ddaef4bba083 8165991: Fix DocTreeFactory newDocCommentTree
ksrini
parents: 39364
diff changeset
   189
            List<DocTree> blockTags, Utils utils) {
ddaef4bba083 8165991: Fix DocTreeFactory newDocCommentTree
ksrini
parents: 39364
diff changeset
   190
        DocCommentTree docTree = treeFactory.newDocCommentTree(fullBody, blockTags);
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
diff changeset
   191
        dcTreesMap.put(element, new DocCommentDuo(null, docTree));
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
diff changeset
   192
        // There maybe an entry with the original comments usually null,
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
diff changeset
   193
        // therefore remove that entry if it exists, and allow a new one
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
diff changeset
   194
        // to be reestablished.
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
diff changeset
   195
        utils.removeCommentHelper(element);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
diff changeset
   196
    }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
diff changeset
   197
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
diff changeset
   198
    /**
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
diff changeset
   199
     * A simplistic container to transport a TreePath, DocCommentTree pair.
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
diff changeset
   200
     * Here is why we need this:
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
diff changeset
   201
     * a. not desirable to add javac's pair.
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
diff changeset
   202
     * b. DocTreePath is not a viable  option either, as a null TreePath is required
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
diff changeset
   203
     * to represent synthetic comments for Enum.values, valuesOf, javafx properties.
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
diff changeset
   204
     */
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
diff changeset
   205
    public static class DocCommentDuo {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
diff changeset
   206
        public final TreePath treePath;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
diff changeset
   207
        public final DocCommentTree dcTree;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
diff changeset
   208
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
diff changeset
   209
        public DocCommentDuo(TreePath treePath, DocCommentTree dcTree) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
diff changeset
   210
            this.treePath = treePath;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
diff changeset
   211
            this.dcTree = dcTree;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
diff changeset
   212
        }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
diff changeset
   213
    }
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
diff changeset
   214
}