langtools/src/share/classes/com/sun/tools/doclets/internal/toolkit/util/MetaKeywords.java
author briangoetz
Wed, 18 Dec 2013 16:05:18 -0500
changeset 22163 3651128c74eb
parent 22159 682da512ec17
child 25454 376a52c9540c
permissions -rw-r--r--
8030244: Update langtools to use Diamond Reviewed-by: darcy
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     1
/*
15723
58a73dac9ee4 8006124: javadoc/doclet should be updated to support profiles
bpatel
parents: 14260
diff changeset
     2
 * Copyright (c) 2002, 2013, 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.*;
15723
58a73dac9ee4 8006124: javadoc/doclet should be updated to support profiles
bpatel
parents: 14260
diff changeset
    31
import com.sun.tools.javac.jvm.Profile;
14258
8d2148961366 8000663: clean up langtools imports
jjg
parents: 5520
diff changeset
    32
import com.sun.tools.doclets.internal.toolkit.*;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    33
06bc494ca11e Initial load
duke
parents:
diff changeset
    34
/**
06bc494ca11e Initial load
duke
parents:
diff changeset
    35
 * Provides methods for creating an array of class, method and
06bc494ca11e Initial load
duke
parents:
diff changeset
    36
 * field names to be included as meta keywords in the HTML header
06bc494ca11e Initial load
duke
parents:
diff changeset
    37
 * of class pages.  These keywords improve search results
06bc494ca11e Initial load
duke
parents:
diff changeset
    38
 * on browsers that look for keywords.
06bc494ca11e Initial load
duke
parents:
diff changeset
    39
 *
14260
727a84636f12 8000665: fix "internal API" comments on javadoc files
jjg
parents: 14258
diff changeset
    40
 *  <p><b>This is NOT part of any supported API.
727a84636f12 8000665: fix "internal API" comments on javadoc files
jjg
parents: 14258
diff changeset
    41
 *  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
    42
 *  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
    43
 *  deletion without notice.</b>
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    44
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    45
 * @author Doug Kramer
06bc494ca11e Initial load
duke
parents:
diff changeset
    46
 */
06bc494ca11e Initial load
duke
parents:
diff changeset
    47
public class MetaKeywords {
06bc494ca11e Initial load
duke
parents:
diff changeset
    48
06bc494ca11e Initial load
duke
parents:
diff changeset
    49
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    50
     * The global configuration information for this run.
06bc494ca11e Initial load
duke
parents:
diff changeset
    51
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    52
    private final Configuration configuration;
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;
06bc494ca11e Initial load
duke
parents:
diff changeset
    59
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
    60
06bc494ca11e Initial load
duke
parents:
diff changeset
    61
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    62
     * Returns an array of strings where each element
06bc494ca11e Initial load
duke
parents:
diff changeset
    63
     * is a class, method or field name.  This array is
06bc494ca11e Initial load
duke
parents:
diff changeset
    64
     * used to create one meta keyword tag for each element.
06bc494ca11e Initial load
duke
parents:
diff changeset
    65
     * Method parameter lists are converted to "()" and
06bc494ca11e Initial load
duke
parents:
diff changeset
    66
     * overloads are combined.
06bc494ca11e Initial load
duke
parents:
diff changeset
    67
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
    68
     * Constructors are not included because they have the same
06bc494ca11e Initial load
duke
parents:
diff changeset
    69
     * name as the class, which is already included.
06bc494ca11e Initial load
duke
parents:
diff changeset
    70
     * Nested class members are not included because their
06bc494ca11e Initial load
duke
parents:
diff changeset
    71
     * definitions are on separate pages.
06bc494ca11e Initial load
duke
parents:
diff changeset
    72
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    73
    public String[] getMetaKeywords(ClassDoc classdoc) {
22163
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 22159
diff changeset
    74
        ArrayList<String> results = new ArrayList<>();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    75
06bc494ca11e Initial load
duke
parents:
diff changeset
    76
        // Add field and method keywords only if -keywords option is used
06bc494ca11e Initial load
duke
parents:
diff changeset
    77
        if( configuration.keywords ) {
06bc494ca11e Initial load
duke
parents:
diff changeset
    78
            results.addAll(getClassKeyword(classdoc));
06bc494ca11e Initial load
duke
parents:
diff changeset
    79
            results.addAll(getMemberKeywords(classdoc.fields()));
06bc494ca11e Initial load
duke
parents:
diff changeset
    80
            results.addAll(getMemberKeywords(classdoc.methods()));
06bc494ca11e Initial load
duke
parents:
diff changeset
    81
        }
868
d0f233085cbb 6657907: javadoc has unchecked warnings
jjg
parents: 10
diff changeset
    82
        return results.toArray(new String[]{});
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    83
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
    84
06bc494ca11e Initial load
duke
parents:
diff changeset
    85
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    86
     * Get the current class for a meta tag keyword, as the first
06bc494ca11e Initial load
duke
parents:
diff changeset
    87
     * and only element of an array list.
06bc494ca11e Initial load
duke
parents:
diff changeset
    88
     */
868
d0f233085cbb 6657907: javadoc has unchecked warnings
jjg
parents: 10
diff changeset
    89
    protected ArrayList<String> getClassKeyword(ClassDoc classdoc) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    90
        String cltypelower = classdoc.isInterface() ? "interface" : "class";
22163
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 22159
diff changeset
    91
        ArrayList<String> metakeywords = new ArrayList<>(1);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    92
        metakeywords.add(classdoc.qualifiedName() + " " + cltypelower);
06bc494ca11e Initial load
duke
parents:
diff changeset
    93
        return metakeywords;
06bc494ca11e Initial load
duke
parents:
diff changeset
    94
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
    95
06bc494ca11e Initial load
duke
parents:
diff changeset
    96
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    97
     * Get the package keywords.
06bc494ca11e Initial load
duke
parents:
diff changeset
    98
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    99
    public String[] getMetaKeywords(PackageDoc packageDoc) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   100
        if( configuration.keywords ) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   101
            String pkgName = Util.getPackageName(packageDoc);
06bc494ca11e Initial load
duke
parents:
diff changeset
   102
            return new String[] { pkgName + " " + "package" };
06bc494ca11e Initial load
duke
parents:
diff changeset
   103
        } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
   104
            return new String[] {};
06bc494ca11e Initial load
duke
parents:
diff changeset
   105
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   106
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   107
06bc494ca11e Initial load
duke
parents:
diff changeset
   108
    /**
15723
58a73dac9ee4 8006124: javadoc/doclet should be updated to support profiles
bpatel
parents: 14260
diff changeset
   109
     * Get the profile keywords.
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
     * @param profile the profile being documented
58a73dac9ee4 8006124: javadoc/doclet should be updated to support profiles
bpatel
parents: 14260
diff changeset
   112
     */
58a73dac9ee4 8006124: javadoc/doclet should be updated to support profiles
bpatel
parents: 14260
diff changeset
   113
    public String[] getMetaKeywords(Profile profile) {
58a73dac9ee4 8006124: javadoc/doclet should be updated to support profiles
bpatel
parents: 14260
diff changeset
   114
        if( configuration.keywords ) {
58a73dac9ee4 8006124: javadoc/doclet should be updated to support profiles
bpatel
parents: 14260
diff changeset
   115
            String profileName = profile.name;
58a73dac9ee4 8006124: javadoc/doclet should be updated to support profiles
bpatel
parents: 14260
diff changeset
   116
            return new String[] { profileName + " " + "profile" };
58a73dac9ee4 8006124: javadoc/doclet should be updated to support profiles
bpatel
parents: 14260
diff changeset
   117
        } else {
58a73dac9ee4 8006124: javadoc/doclet should be updated to support profiles
bpatel
parents: 14260
diff changeset
   118
            return new String[] {};
58a73dac9ee4 8006124: javadoc/doclet should be updated to support profiles
bpatel
parents: 14260
diff changeset
   119
        }
58a73dac9ee4 8006124: javadoc/doclet should be updated to support profiles
bpatel
parents: 14260
diff changeset
   120
    }
58a73dac9ee4 8006124: javadoc/doclet should be updated to support profiles
bpatel
parents: 14260
diff changeset
   121
58a73dac9ee4 8006124: javadoc/doclet should be updated to support profiles
bpatel
parents: 14260
diff changeset
   122
    /**
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   123
     * Get the overview keywords.
06bc494ca11e Initial load
duke
parents:
diff changeset
   124
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   125
    public String[] getOverviewMetaKeywords(String title, String docTitle) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   126
        if( configuration.keywords ) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   127
            String windowOverview = configuration.getText(title);
06bc494ca11e Initial load
duke
parents:
diff changeset
   128
            String[] metakeywords = { windowOverview };
06bc494ca11e Initial load
duke
parents:
diff changeset
   129
            if (docTitle.length() > 0 ) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   130
                metakeywords[0] += ", " + docTitle;
06bc494ca11e Initial load
duke
parents:
diff changeset
   131
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   132
            return metakeywords;
06bc494ca11e Initial load
duke
parents:
diff changeset
   133
        } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
   134
            return new String[] {};
06bc494ca11e Initial load
duke
parents:
diff changeset
   135
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   136
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   137
06bc494ca11e Initial load
duke
parents:
diff changeset
   138
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   139
     * Get members for meta tag keywords as an array,
06bc494ca11e Initial load
duke
parents:
diff changeset
   140
     * where each member name is a string element of the array.
06bc494ca11e Initial load
duke
parents:
diff changeset
   141
     * The parameter lists are not included in the keywords;
06bc494ca11e Initial load
duke
parents:
diff changeset
   142
     * therefore all overloaded methods are combined.<br>
06bc494ca11e Initial load
duke
parents:
diff changeset
   143
     * Example: getValue(Object) is returned in array as getValue()
06bc494ca11e Initial load
duke
parents:
diff changeset
   144
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   145
     * @param memberdocs  array of MemberDoc objects to be added to keywords
06bc494ca11e Initial load
duke
parents:
diff changeset
   146
     */
868
d0f233085cbb 6657907: javadoc has unchecked warnings
jjg
parents: 10
diff changeset
   147
    protected ArrayList<String> getMemberKeywords(MemberDoc[] memberdocs) {
22163
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 22159
diff changeset
   148
        ArrayList<String> results = new ArrayList<>();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   149
        String membername;
22159
682da512ec17 8030253: Update langtools to use strings-in-switch
briangoetz
parents: 15723
diff changeset
   150
        for (MemberDoc memberdoc : memberdocs) {
682da512ec17 8030253: Update langtools to use strings-in-switch
briangoetz
parents: 15723
diff changeset
   151
            membername = memberdoc.name() + (memberdoc.isMethod() ? "()" : "");
682da512ec17 8030253: Update langtools to use strings-in-switch
briangoetz
parents: 15723
diff changeset
   152
            if (!results.contains(membername)) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   153
                results.add(membername);
06bc494ca11e Initial load
duke
parents:
diff changeset
   154
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   155
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   156
        return results;
06bc494ca11e Initial load
duke
parents:
diff changeset
   157
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   158
}