langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/util/MetaKeywords.java
author ksrini
Mon, 05 Jun 2017 13:45:34 -0700
changeset 45417 f7479ee8de69
parent 39594 63bb794f0e20
permissions -rw-r--r--
8177848: Rename Configuration(Impl) classes Reviewed-by: jjg
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     1
/*
45417
f7479ee8de69 8177848: Rename Configuration(Impl) classes
ksrini
parents: 39594
diff changeset
     2
 * Copyright (c) 2002, 2017, Oracle and/or its affiliates. All rights reserved.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
06bc494ca11e Initial load
duke
parents:
diff changeset
     4
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
06bc494ca11e Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5520
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 1475
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5520
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 1475
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    10
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
06bc494ca11e Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
06bc494ca11e Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
06bc494ca11e Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
06bc494ca11e Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
06bc494ca11e Initial load
duke
parents:
diff changeset
    16
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
06bc494ca11e Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
06bc494ca11e Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
06bc494ca11e Initial load
duke
parents:
diff changeset
    20
 *
5520
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 1475
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 1475
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 1475
diff changeset
    23
 * questions.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    24
 */
06bc494ca11e Initial load
duke
parents:
diff changeset
    25
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
    26
package jdk.javadoc.internal.doclets.toolkit.util;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    27
14258
8d2148961366 8000663: clean up langtools imports
jjg
parents: 5520
diff changeset
    28
import java.util.*;
8d2148961366 8000663: clean up langtools imports
jjg
parents: 5520
diff changeset
    29
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
    30
import javax.lang.model.element.Element;
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35426
diff changeset
    31
import javax.lang.model.element.ModuleElement;
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
    32
import javax.lang.model.element.PackageElement;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
    33
import javax.lang.model.element.TypeElement;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
    34
45417
f7479ee8de69 8177848: Rename Configuration(Impl) classes
ksrini
parents: 39594
diff changeset
    35
import jdk.javadoc.internal.doclets.toolkit.BaseConfiguration;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    36
06bc494ca11e Initial load
duke
parents:
diff changeset
    37
/**
06bc494ca11e Initial load
duke
parents:
diff changeset
    38
 * Provides methods for creating an array of class, method and
06bc494ca11e Initial load
duke
parents:
diff changeset
    39
 * field names to be included as meta keywords in the HTML header
06bc494ca11e Initial load
duke
parents:
diff changeset
    40
 * of class pages.  These keywords improve search results
06bc494ca11e Initial load
duke
parents:
diff changeset
    41
 * on browsers that look for keywords.
06bc494ca11e Initial load
duke
parents:
diff changeset
    42
 *
14260
727a84636f12 8000665: fix "internal API" comments on javadoc files
jjg
parents: 14258
diff changeset
    43
 *  <p><b>This is NOT part of any supported API.
727a84636f12 8000665: fix "internal API" comments on javadoc files
jjg
parents: 14258
diff changeset
    44
 *  If you write code that depends on this, you do so at your own risk.
727a84636f12 8000665: fix "internal API" comments on javadoc files
jjg
parents: 14258
diff changeset
    45
 *  This code and its internal interfaces are subject to change or
727a84636f12 8000665: fix "internal API" comments on javadoc files
jjg
parents: 14258
diff changeset
    46
 *  deletion without notice.</b>
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    47
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    48
 * @author Doug Kramer
06bc494ca11e Initial load
duke
parents:
diff changeset
    49
 */
06bc494ca11e Initial load
duke
parents:
diff changeset
    50
public class MetaKeywords {
06bc494ca11e Initial load
duke
parents:
diff changeset
    51
06bc494ca11e Initial load
duke
parents:
diff changeset
    52
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    53
     * The global configuration information for this run.
06bc494ca11e Initial load
duke
parents:
diff changeset
    54
     */
45417
f7479ee8de69 8177848: Rename Configuration(Impl) classes
ksrini
parents: 39594
diff changeset
    55
    private final BaseConfiguration config;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    56
06bc494ca11e Initial load
duke
parents:
diff changeset
    57
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    58
     * Constructor
06bc494ca11e Initial load
duke
parents:
diff changeset
    59
     */
45417
f7479ee8de69 8177848: Rename Configuration(Impl) classes
ksrini
parents: 39594
diff changeset
    60
    public MetaKeywords(BaseConfiguration configuration) {
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
    61
        config = configuration;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    62
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
    63
06bc494ca11e Initial load
duke
parents:
diff changeset
    64
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    65
     * Returns an array of strings where each element
06bc494ca11e Initial load
duke
parents:
diff changeset
    66
     * is a class, method or field name.  This array is
06bc494ca11e Initial load
duke
parents:
diff changeset
    67
     * used to create one meta keyword tag for each element.
06bc494ca11e Initial load
duke
parents:
diff changeset
    68
     * Method parameter lists are converted to "()" and
06bc494ca11e Initial load
duke
parents:
diff changeset
    69
     * overloads are combined.
06bc494ca11e Initial load
duke
parents:
diff changeset
    70
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
    71
     * Constructors are not included because they have the same
06bc494ca11e Initial load
duke
parents:
diff changeset
    72
     * name as the class, which is already included.
06bc494ca11e Initial load
duke
parents:
diff changeset
    73
     * Nested class members are not included because their
06bc494ca11e Initial load
duke
parents:
diff changeset
    74
     * definitions are on separate pages.
06bc494ca11e Initial load
duke
parents:
diff changeset
    75
     */
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
    76
    public List<String> getMetaKeywords(TypeElement typeElement) {
22163
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 22159
diff changeset
    77
        ArrayList<String> results = new ArrayList<>();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    78
06bc494ca11e Initial load
duke
parents:
diff changeset
    79
        // Add field and method keywords only if -keywords option is used
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
    80
        if (config.keywords) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
    81
            results.addAll(getClassKeyword(typeElement));
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
    82
            results.addAll(getMemberKeywords(config.utils.getFields(typeElement)));
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
    83
            results.addAll(getMemberKeywords(config.utils.getMethods(typeElement)));
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    84
        }
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
    85
        ((ArrayList)results).trimToSize();
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
    86
        return results;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    87
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
    88
06bc494ca11e Initial load
duke
parents:
diff changeset
    89
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    90
     * Get the current class for a meta tag keyword, as the first
06bc494ca11e Initial load
duke
parents:
diff changeset
    91
     * and only element of an array list.
06bc494ca11e Initial load
duke
parents:
diff changeset
    92
     */
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
    93
    protected List<String> getClassKeyword(TypeElement typeElement) {
22163
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 22159
diff changeset
    94
        ArrayList<String> metakeywords = new ArrayList<>(1);
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
    95
        String cltypelower = config.utils.isInterface(typeElement) ? "interface" : "class";
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
    96
        metakeywords.add(config.utils.getFullyQualifiedName(typeElement) + " " + cltypelower);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    97
        return metakeywords;
06bc494ca11e Initial load
duke
parents:
diff changeset
    98
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
    99
06bc494ca11e Initial load
duke
parents:
diff changeset
   100
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   101
     * Get the package keywords.
06bc494ca11e Initial load
duke
parents:
diff changeset
   102
     */
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
   103
    public List<String> getMetaKeywords(PackageElement packageElement) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
   104
        List<String> result = new ArrayList<>(1);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
   105
        if (config.keywords) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
   106
            String pkgName = config.utils.getPackageName(packageElement);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
   107
            result.add(pkgName + " " + "package");
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   108
        }
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
   109
        return result;
15723
58a73dac9ee4 8006124: javadoc/doclet should be updated to support profiles
bpatel
parents: 14260
diff changeset
   110
    }
58a73dac9ee4 8006124: javadoc/doclet should be updated to support profiles
bpatel
parents: 14260
diff changeset
   111
58a73dac9ee4 8006124: javadoc/doclet should be updated to support profiles
bpatel
parents: 14260
diff changeset
   112
    /**
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35426
diff changeset
   113
     * Get the module keywords.
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35426
diff changeset
   114
     *
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35426
diff changeset
   115
     * @param mdle the module being documented
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35426
diff changeset
   116
     */
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35426
diff changeset
   117
    public List<String> getMetaKeywordsForModule(ModuleElement mdle) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35426
diff changeset
   118
        if (config.keywords) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35426
diff changeset
   119
            return Arrays.asList(mdle.getQualifiedName() + " " + "module");
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35426
diff changeset
   120
        } else {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35426
diff changeset
   121
            return Collections.emptyList();
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35426
diff changeset
   122
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35426
diff changeset
   123
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35426
diff changeset
   124
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35426
diff changeset
   125
    /**
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   126
     * Get the overview keywords.
06bc494ca11e Initial load
duke
parents:
diff changeset
   127
     */
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
   128
    public List<String> getOverviewMetaKeywords(String title, String docTitle) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
   129
         List<String> result = new ArrayList<>(1);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
   130
        if (config.keywords) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
   131
            String windowOverview = config.getText(title);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
   132
            if (docTitle.length() > 0) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
   133
                result.add(windowOverview + ", " + docTitle);
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
   134
            } else {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
   135
                result.add(windowOverview);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   136
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   137
        }
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
   138
        return result;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   139
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   140
06bc494ca11e Initial load
duke
parents:
diff changeset
   141
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   142
     * Get members for meta tag keywords as an array,
06bc494ca11e Initial load
duke
parents:
diff changeset
   143
     * where each member name is a string element of the array.
06bc494ca11e Initial load
duke
parents:
diff changeset
   144
     * The parameter lists are not included in the keywords;
06bc494ca11e Initial load
duke
parents:
diff changeset
   145
     * therefore all overloaded methods are combined.<br>
06bc494ca11e Initial load
duke
parents:
diff changeset
   146
     * Example: getValue(Object) is returned in array as getValue()
06bc494ca11e Initial load
duke
parents:
diff changeset
   147
     *
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
   148
     * @param members  array of members to be added to keywords
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   149
     */
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
   150
    protected List<String> getMemberKeywords(List<? extends Element> members) {
22163
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 22159
diff changeset
   151
        ArrayList<String> results = new ArrayList<>();
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
   152
        for (Element member : members) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
   153
            String membername = config.utils.isMethod(member)
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
   154
                    ? config.utils.getSimpleName(member) + "()"
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
   155
                    : config.utils.getSimpleName(member);
22159
682da512ec17 8030253: Update langtools to use strings-in-switch
briangoetz
parents: 15723
diff changeset
   156
            if (!results.contains(membername)) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   157
                results.add(membername);
06bc494ca11e Initial load
duke
parents:
diff changeset
   158
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   159
        }
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
   160
        ((ArrayList)results).trimToSize();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   161
        return results;
06bc494ca11e Initial load
duke
parents:
diff changeset
   162
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   163
}