langtools/src/jdk.javadoc/share/classes/com/sun/tools/doclets/internal/toolkit/util/MetaKeywords.java
author alanb
Thu, 17 Mar 2016 19:04:28 +0000
changeset 36526 3b41f1c69604
parent 25874 83c19f00452c
child 38617 d93a7f64e231
permissions -rw-r--r--
8142968: Module System implementation Summary: Initial integration of JEP 200, JEP 260, JEP 261, and JEP 282 Reviewed-by: jjg, jlahoda, vromero, mcimadamore, bpatel, ksrini, darcy, anazarov, dfuchs Contributed-by: alan.bateman@oracle.com, alex.buckley@oracle.com, jonathan.gibbons@oracle.com, karen.kinnear@oracle.com, mandy.chung@oracle.com, mark.reinhold@oracle.com, jan.lahoda@oracle.com, vicente.romero@oracle.com, andreas.lundblad@oracle.com, andrey.x.nazarov@oracle.com, chris.hegarty@oracle.com, erik.joelsson@oracle.com, kumar.x.srinivasan@oracle.com, sundararajan.athijegannathan@oracle.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     1
/*
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 25874
diff changeset
     2
 * Copyright (c) 2002, 2016, Oracle and/or its affiliates. All rights reserved.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
06bc494ca11e Initial load
duke
parents:
diff changeset
     4
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
06bc494ca11e Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5520
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 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
06bc494ca11e Initial load
duke
parents:
diff changeset
    26
package com.sun.tools.doclets.internal.toolkit.util;
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
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    30
import com.sun.javadoc.*;
14258
8d2148961366 8000663: clean up langtools imports
jjg
parents: 5520
diff changeset
    31
import com.sun.tools.doclets.internal.toolkit.*;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    32
06bc494ca11e Initial load
duke
parents:
diff changeset
    33
/**
06bc494ca11e Initial load
duke
parents:
diff changeset
    34
 * Provides methods for creating an array of class, method and
06bc494ca11e Initial load
duke
parents:
diff changeset
    35
 * field names to be included as meta keywords in the HTML header
06bc494ca11e Initial load
duke
parents:
diff changeset
    36
 * of class pages.  These keywords improve search results
06bc494ca11e Initial load
duke
parents:
diff changeset
    37
 * on browsers that look for keywords.
06bc494ca11e Initial load
duke
parents:
diff changeset
    38
 *
14260
727a84636f12 8000665: fix "internal API" comments on javadoc files
jjg
parents: 14258
diff changeset
    39
 *  <p><b>This is NOT part of any supported API.
727a84636f12 8000665: fix "internal API" comments on javadoc files
jjg
parents: 14258
diff changeset
    40
 *  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
    41
 *  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
    42
 *  deletion without notice.</b>
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    43
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    44
 * @author Doug Kramer
06bc494ca11e Initial load
duke
parents:
diff changeset
    45
 */
06bc494ca11e Initial load
duke
parents:
diff changeset
    46
public class MetaKeywords {
06bc494ca11e Initial load
duke
parents:
diff changeset
    47
06bc494ca11e Initial load
duke
parents:
diff changeset
    48
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    49
     * The global configuration information for this run.
06bc494ca11e Initial load
duke
parents:
diff changeset
    50
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    51
    private final Configuration configuration;
25454
376a52c9540c 8039028: [javadoc] refactor the usage of Util.java
ksrini
parents: 22163
diff changeset
    52
    private final Utils utils;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    53
06bc494ca11e Initial load
duke
parents:
diff changeset
    54
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    55
     * Constructor
06bc494ca11e Initial load
duke
parents:
diff changeset
    56
     */
1475
19c0851667ca 6748541: javadoc should be reusable
jjg
parents: 1264
diff changeset
    57
    public MetaKeywords(Configuration configuration) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    58
        this.configuration = configuration;
25454
376a52c9540c 8039028: [javadoc] refactor the usage of Util.java
ksrini
parents: 22163
diff changeset
    59
        this.utils = configuration.utils;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    60
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
    61
06bc494ca11e Initial load
duke
parents:
diff changeset
    62
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    63
     * Returns an array of strings where each element
06bc494ca11e Initial load
duke
parents:
diff changeset
    64
     * is a class, method or field name.  This array is
06bc494ca11e Initial load
duke
parents:
diff changeset
    65
     * used to create one meta keyword tag for each element.
06bc494ca11e Initial load
duke
parents:
diff changeset
    66
     * Method parameter lists are converted to "()" and
06bc494ca11e Initial load
duke
parents:
diff changeset
    67
     * overloads are combined.
06bc494ca11e Initial load
duke
parents:
diff changeset
    68
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
    69
     * Constructors are not included because they have the same
06bc494ca11e Initial load
duke
parents:
diff changeset
    70
     * name as the class, which is already included.
06bc494ca11e Initial load
duke
parents:
diff changeset
    71
     * Nested class members are not included because their
06bc494ca11e Initial load
duke
parents:
diff changeset
    72
     * definitions are on separate pages.
06bc494ca11e Initial load
duke
parents:
diff changeset
    73
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    74
    public String[] getMetaKeywords(ClassDoc classdoc) {
22163
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 22159
diff changeset
    75
        ArrayList<String> results = new ArrayList<>();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    76
06bc494ca11e Initial load
duke
parents:
diff changeset
    77
        // Add field and method keywords only if -keywords option is used
06bc494ca11e Initial load
duke
parents:
diff changeset
    78
        if( configuration.keywords ) {
06bc494ca11e Initial load
duke
parents:
diff changeset
    79
            results.addAll(getClassKeyword(classdoc));
06bc494ca11e Initial load
duke
parents:
diff changeset
    80
            results.addAll(getMemberKeywords(classdoc.fields()));
06bc494ca11e Initial load
duke
parents:
diff changeset
    81
            results.addAll(getMemberKeywords(classdoc.methods()));
06bc494ca11e Initial load
duke
parents:
diff changeset
    82
        }
868
d0f233085cbb 6657907: javadoc has unchecked warnings
jjg
parents: 10
diff changeset
    83
        return results.toArray(new String[]{});
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    84
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
    85
06bc494ca11e Initial load
duke
parents:
diff changeset
    86
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    87
     * Get the current class for a meta tag keyword, as the first
06bc494ca11e Initial load
duke
parents:
diff changeset
    88
     * and only element of an array list.
06bc494ca11e Initial load
duke
parents:
diff changeset
    89
     */
868
d0f233085cbb 6657907: javadoc has unchecked warnings
jjg
parents: 10
diff changeset
    90
    protected ArrayList<String> getClassKeyword(ClassDoc classdoc) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    91
        String cltypelower = classdoc.isInterface() ? "interface" : "class";
22163
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 22159
diff changeset
    92
        ArrayList<String> metakeywords = new ArrayList<>(1);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    93
        metakeywords.add(classdoc.qualifiedName() + " " + cltypelower);
06bc494ca11e Initial load
duke
parents:
diff changeset
    94
        return metakeywords;
06bc494ca11e Initial load
duke
parents:
diff changeset
    95
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
    96
06bc494ca11e Initial load
duke
parents:
diff changeset
    97
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    98
     * Get the package keywords.
06bc494ca11e Initial load
duke
parents:
diff changeset
    99
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   100
    public String[] getMetaKeywords(PackageDoc packageDoc) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   101
        if( configuration.keywords ) {
25454
376a52c9540c 8039028: [javadoc] refactor the usage of Util.java
ksrini
parents: 22163
diff changeset
   102
            String pkgName = utils.getPackageName(packageDoc);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   103
            return new String[] { pkgName + " " + "package" };
06bc494ca11e Initial load
duke
parents:
diff changeset
   104
        } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
   105
            return new String[] {};
06bc494ca11e Initial load
duke
parents:
diff changeset
   106
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   107
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   108
06bc494ca11e Initial load
duke
parents:
diff changeset
   109
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   110
     * Get the overview keywords.
06bc494ca11e Initial load
duke
parents:
diff changeset
   111
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   112
    public String[] getOverviewMetaKeywords(String title, String docTitle) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   113
        if( configuration.keywords ) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   114
            String windowOverview = configuration.getText(title);
06bc494ca11e Initial load
duke
parents:
diff changeset
   115
            String[] metakeywords = { windowOverview };
06bc494ca11e Initial load
duke
parents:
diff changeset
   116
            if (docTitle.length() > 0 ) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   117
                metakeywords[0] += ", " + docTitle;
06bc494ca11e Initial load
duke
parents:
diff changeset
   118
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   119
            return metakeywords;
06bc494ca11e Initial load
duke
parents:
diff changeset
   120
        } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
   121
            return new String[] {};
06bc494ca11e Initial load
duke
parents:
diff changeset
   122
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   123
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   124
06bc494ca11e Initial load
duke
parents:
diff changeset
   125
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   126
     * Get members for meta tag keywords as an array,
06bc494ca11e Initial load
duke
parents:
diff changeset
   127
     * where each member name is a string element of the array.
06bc494ca11e Initial load
duke
parents:
diff changeset
   128
     * The parameter lists are not included in the keywords;
06bc494ca11e Initial load
duke
parents:
diff changeset
   129
     * therefore all overloaded methods are combined.<br>
06bc494ca11e Initial load
duke
parents:
diff changeset
   130
     * Example: getValue(Object) is returned in array as getValue()
06bc494ca11e Initial load
duke
parents:
diff changeset
   131
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   132
     * @param memberdocs  array of MemberDoc objects to be added to keywords
06bc494ca11e Initial load
duke
parents:
diff changeset
   133
     */
868
d0f233085cbb 6657907: javadoc has unchecked warnings
jjg
parents: 10
diff changeset
   134
    protected ArrayList<String> getMemberKeywords(MemberDoc[] memberdocs) {
22163
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 22159
diff changeset
   135
        ArrayList<String> results = new ArrayList<>();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   136
        String membername;
22159
682da512ec17 8030253: Update langtools to use strings-in-switch
briangoetz
parents: 15723
diff changeset
   137
        for (MemberDoc memberdoc : memberdocs) {
682da512ec17 8030253: Update langtools to use strings-in-switch
briangoetz
parents: 15723
diff changeset
   138
            membername = memberdoc.name() + (memberdoc.isMethod() ? "()" : "");
682da512ec17 8030253: Update langtools to use strings-in-switch
briangoetz
parents: 15723
diff changeset
   139
            if (!results.contains(membername)) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   140
                results.add(membername);
06bc494ca11e Initial load
duke
parents:
diff changeset
   141
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   142
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   143
        return results;
06bc494ca11e Initial load
duke
parents:
diff changeset
   144
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   145
}