author | alanb |
Thu, 17 Mar 2016 19:04:28 +0000 | |
changeset 36526 | 3b41f1c69604 |
parent 25874 | 83c19f00452c |
child 38617 | d93a7f64e231 |
permissions | -rw-r--r-- |
10 | 1 |
/* |
36526 | 2 |
* Copyright (c) 2002, 2016, Oracle and/or its affiliates. All rights reserved. |
10 | 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 |
|
5520 | 7 |
* published by the Free Software Foundation. Oracle designates this |
10 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5520 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
10 | 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 |
* |
|
5520 | 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. |
|
10 | 24 |
*/ |
25 |
||
26 |
package com.sun.tools.doclets.internal.toolkit.util; |
|
27 |
||
14258 | 28 |
import java.util.*; |
29 |
||
10 | 30 |
import com.sun.javadoc.*; |
14258 | 31 |
import com.sun.tools.doclets.internal.toolkit.*; |
10 | 32 |
|
33 |
/** |
|
34 |
* Provides methods for creating an array of class, method and |
|
35 |
* field names to be included as meta keywords in the HTML header |
|
36 |
* of class pages. These keywords improve search results |
|
37 |
* on browsers that look for keywords. |
|
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 | 43 |
* |
44 |
* @author Doug Kramer |
|
45 |
*/ |
|
46 |
public class MetaKeywords { |
|
47 |
||
48 |
/** |
|
49 |
* The global configuration information for this run. |
|
50 |
*/ |
|
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 | 53 |
|
54 |
/** |
|
55 |
* Constructor |
|
56 |
*/ |
|
1475 | 57 |
public MetaKeywords(Configuration configuration) { |
10 | 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 | 60 |
} |
61 |
||
62 |
/** |
|
63 |
* Returns an array of strings where each element |
|
64 |
* is a class, method or field name. This array is |
|
65 |
* used to create one meta keyword tag for each element. |
|
66 |
* Method parameter lists are converted to "()" and |
|
67 |
* overloads are combined. |
|
68 |
* |
|
69 |
* Constructors are not included because they have the same |
|
70 |
* name as the class, which is already included. |
|
71 |
* Nested class members are not included because their |
|
72 |
* definitions are on separate pages. |
|
73 |
*/ |
|
74 |
public String[] getMetaKeywords(ClassDoc classdoc) { |
|
22163 | 75 |
ArrayList<String> results = new ArrayList<>(); |
10 | 76 |
|
77 |
// Add field and method keywords only if -keywords option is used |
|
78 |
if( configuration.keywords ) { |
|
79 |
results.addAll(getClassKeyword(classdoc)); |
|
80 |
results.addAll(getMemberKeywords(classdoc.fields())); |
|
81 |
results.addAll(getMemberKeywords(classdoc.methods())); |
|
82 |
} |
|
868 | 83 |
return results.toArray(new String[]{}); |
10 | 84 |
} |
85 |
||
86 |
/** |
|
87 |
* Get the current class for a meta tag keyword, as the first |
|
88 |
* and only element of an array list. |
|
89 |
*/ |
|
868 | 90 |
protected ArrayList<String> getClassKeyword(ClassDoc classdoc) { |
10 | 91 |
String cltypelower = classdoc.isInterface() ? "interface" : "class"; |
22163 | 92 |
ArrayList<String> metakeywords = new ArrayList<>(1); |
10 | 93 |
metakeywords.add(classdoc.qualifiedName() + " " + cltypelower); |
94 |
return metakeywords; |
|
95 |
} |
|
96 |
||
97 |
/** |
|
98 |
* Get the package keywords. |
|
99 |
*/ |
|
100 |
public String[] getMetaKeywords(PackageDoc packageDoc) { |
|
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 | 103 |
return new String[] { pkgName + " " + "package" }; |
104 |
} else { |
|
105 |
return new String[] {}; |
|
106 |
} |
|
107 |
} |
|
108 |
||
109 |
/** |
|
110 |
* Get the overview keywords. |
|
111 |
*/ |
|
112 |
public String[] getOverviewMetaKeywords(String title, String docTitle) { |
|
113 |
if( configuration.keywords ) { |
|
114 |
String windowOverview = configuration.getText(title); |
|
115 |
String[] metakeywords = { windowOverview }; |
|
116 |
if (docTitle.length() > 0 ) { |
|
117 |
metakeywords[0] += ", " + docTitle; |
|
118 |
} |
|
119 |
return metakeywords; |
|
120 |
} else { |
|
121 |
return new String[] {}; |
|
122 |
} |
|
123 |
} |
|
124 |
||
125 |
/** |
|
126 |
* Get members for meta tag keywords as an array, |
|
127 |
* where each member name is a string element of the array. |
|
128 |
* The parameter lists are not included in the keywords; |
|
129 |
* therefore all overloaded methods are combined.<br> |
|
130 |
* Example: getValue(Object) is returned in array as getValue() |
|
131 |
* |
|
132 |
* @param memberdocs array of MemberDoc objects to be added to keywords |
|
133 |
*/ |
|
868 | 134 |
protected ArrayList<String> getMemberKeywords(MemberDoc[] memberdocs) { |
22163 | 135 |
ArrayList<String> results = new ArrayList<>(); |
10 | 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 | 140 |
results.add(membername); |
141 |
} |
|
142 |
} |
|
143 |
return results; |
|
144 |
} |
|
145 |
} |