src/share/classes/com/sun/tools/doclets/internal/toolkit/util/MetaKeywords.java

Sat, 07 Nov 2020 10:30:02 +0800

author
aoqi
date
Sat, 07 Nov 2020 10:30:02 +0800
changeset 3938
93012e2a5d1d
parent 2525
2eb010b6cb22
permissions
-rw-r--r--

Added tag mips-jdk8u275-b01 for changeset eb6ee6a5f2fe

     1 /*
     2  * Copyright (c) 2002, 2013, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.  Oracle designates this
     8  * particular file as subject to the "Classpath" exception as provided
     9  * by Oracle in the LICENSE file that accompanied this code.
    10  *
    11  * This code is distributed in the hope that it will be useful, but WITHOUT
    12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    14  * version 2 for more details (a copy is included in the LICENSE file that
    15  * accompanied this code).
    16  *
    17  * You should have received a copy of the GNU General Public License version
    18  * 2 along with this work; if not, write to the Free Software Foundation,
    19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    20  *
    21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    22  * or visit www.oracle.com if you need additional information or have any
    23  * questions.
    24  */
    26 package com.sun.tools.doclets.internal.toolkit.util;
    28 import java.util.*;
    30 import com.sun.javadoc.*;
    31 import com.sun.tools.javac.jvm.Profile;
    32 import com.sun.tools.doclets.internal.toolkit.*;
    34 /**
    35  * Provides methods for creating an array of class, method and
    36  * field names to be included as meta keywords in the HTML header
    37  * of class pages.  These keywords improve search results
    38  * on browsers that look for keywords.
    39  *
    40  *  <p><b>This is NOT part of any supported API.
    41  *  If you write code that depends on this, you do so at your own risk.
    42  *  This code and its internal interfaces are subject to change or
    43  *  deletion without notice.</b>
    44  *
    45  * @author Doug Kramer
    46  */
    47 public class MetaKeywords {
    49     /**
    50      * The global configuration information for this run.
    51      */
    52     private final Configuration configuration;
    54     /**
    55      * Constructor
    56      */
    57     public MetaKeywords(Configuration configuration) {
    58         this.configuration = configuration;
    59     }
    61     /**
    62      * Returns an array of strings where each element
    63      * is a class, method or field name.  This array is
    64      * used to create one meta keyword tag for each element.
    65      * Method parameter lists are converted to "()" and
    66      * overloads are combined.
    67      *
    68      * Constructors are not included because they have the same
    69      * name as the class, which is already included.
    70      * Nested class members are not included because their
    71      * definitions are on separate pages.
    72      */
    73     public String[] getMetaKeywords(ClassDoc classdoc) {
    74         ArrayList<String> results = new ArrayList<String>();
    76         // Add field and method keywords only if -keywords option is used
    77         if( configuration.keywords ) {
    78             results.addAll(getClassKeyword(classdoc));
    79             results.addAll(getMemberKeywords(classdoc.fields()));
    80             results.addAll(getMemberKeywords(classdoc.methods()));
    81         }
    82         return results.toArray(new String[]{});
    83     }
    85     /**
    86      * Get the current class for a meta tag keyword, as the first
    87      * and only element of an array list.
    88      */
    89     protected ArrayList<String> getClassKeyword(ClassDoc classdoc) {
    90         String cltypelower = classdoc.isInterface() ? "interface" : "class";
    91         ArrayList<String> metakeywords = new ArrayList<String>(1);
    92         metakeywords.add(classdoc.qualifiedName() + " " + cltypelower);
    93         return metakeywords;
    94     }
    96     /**
    97      * Get the package keywords.
    98      */
    99     public String[] getMetaKeywords(PackageDoc packageDoc) {
   100         if( configuration.keywords ) {
   101             String pkgName = Util.getPackageName(packageDoc);
   102             return new String[] { pkgName + " " + "package" };
   103         } else {
   104             return new String[] {};
   105         }
   106     }
   108     /**
   109      * Get the profile keywords.
   110      *
   111      * @param profile the profile being documented
   112      */
   113     public String[] getMetaKeywords(Profile profile) {
   114         if( configuration.keywords ) {
   115             String profileName = profile.name;
   116             return new String[] { profileName + " " + "profile" };
   117         } else {
   118             return new String[] {};
   119         }
   120     }
   122     /**
   123      * Get the overview keywords.
   124      */
   125     public String[] getOverviewMetaKeywords(String title, String docTitle) {
   126         if( configuration.keywords ) {
   127             String windowOverview = configuration.getText(title);
   128             String[] metakeywords = { windowOverview };
   129             if (docTitle.length() > 0 ) {
   130                 metakeywords[0] += ", " + docTitle;
   131             }
   132             return metakeywords;
   133         } else {
   134             return new String[] {};
   135         }
   136     }
   138     /**
   139      * Get members for meta tag keywords as an array,
   140      * where each member name is a string element of the array.
   141      * The parameter lists are not included in the keywords;
   142      * therefore all overloaded methods are combined.<br>
   143      * Example: getValue(Object) is returned in array as getValue()
   144      *
   145      * @param memberdocs  array of MemberDoc objects to be added to keywords
   146      */
   147     protected ArrayList<String> getMemberKeywords(MemberDoc[] memberdocs) {
   148         ArrayList<String> results = new ArrayList<String>();
   149         String membername;
   150         for (int i=0; i < memberdocs.length; i++) {
   151             membername = memberdocs[i].name()
   152                              + (memberdocs[i].isMethod() ? "()" : "");
   153             if ( ! results.contains(membername) ) {
   154                 results.add(membername);
   155             }
   156         }
   157         return results;
   158     }
   159 }

mercurial