author | ksrini |
Mon, 05 Jun 2017 13:45:34 -0700 | |
changeset 45417 | f7479ee8de69 |
parent 39594 | 63bb794f0e20 |
permissions | -rw-r--r-- |
10 | 1 |
/* |
45417 | 2 |
* Copyright (c) 2002, 2017, 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 |
||
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
25874
diff
changeset
|
26 |
package jdk.javadoc.internal.doclets.toolkit.util; |
10 | 27 |
|
14258 | 28 |
import java.util.*; |
29 |
||
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
25874
diff
changeset
|
30 |
import javax.lang.model.element.Element; |
36526 | 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 | 35 |
import jdk.javadoc.internal.doclets.toolkit.BaseConfiguration; |
10 | 36 |
|
37 |
/** |
|
38 |
* Provides methods for creating an array of class, method and |
|
39 |
* field names to be included as meta keywords in the HTML header |
|
40 |
* of class pages. These keywords improve search results |
|
41 |
* on browsers that look for keywords. |
|
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 | 47 |
* |
48 |
* @author Doug Kramer |
|
49 |
*/ |
|
50 |
public class MetaKeywords { |
|
51 |
||
52 |
/** |
|
53 |
* The global configuration information for this run. |
|
54 |
*/ |
|
45417 | 55 |
private final BaseConfiguration config; |
10 | 56 |
|
57 |
/** |
|
58 |
* Constructor |
|
59 |
*/ |
|
45417 | 60 |
public MetaKeywords(BaseConfiguration configuration) { |
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
25874
diff
changeset
|
61 |
config = configuration; |
10 | 62 |
} |
63 |
||
64 |
/** |
|
65 |
* Returns an array of strings where each element |
|
66 |
* is a class, method or field name. This array is |
|
67 |
* used to create one meta keyword tag for each element. |
|
68 |
* Method parameter lists are converted to "()" and |
|
69 |
* overloads are combined. |
|
70 |
* |
|
71 |
* Constructors are not included because they have the same |
|
72 |
* name as the class, which is already included. |
|
73 |
* Nested class members are not included because their |
|
74 |
* definitions are on separate pages. |
|
75 |
*/ |
|
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
25874
diff
changeset
|
76 |
public List<String> getMetaKeywords(TypeElement typeElement) { |
22163 | 77 |
ArrayList<String> results = new ArrayList<>(); |
10 | 78 |
|
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 | 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 | 87 |
} |
88 |
||
89 |
/** |
|
90 |
* Get the current class for a meta tag keyword, as the first |
|
91 |
* and only element of an array list. |
|
92 |
*/ |
|
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
25874
diff
changeset
|
93 |
protected List<String> getClassKeyword(TypeElement typeElement) { |
22163 | 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 | 97 |
return metakeywords; |
98 |
} |
|
99 |
||
100 |
/** |
|
101 |
* Get the package keywords. |
|
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 | 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 | 113 |
* Get the module keywords. |
114 |
* |
|
115 |
* @param mdle the module being documented |
|
116 |
*/ |
|
117 |
public List<String> getMetaKeywordsForModule(ModuleElement mdle) { |
|
118 |
if (config.keywords) { |
|
119 |
return Arrays.asList(mdle.getQualifiedName() + " " + "module"); |
|
120 |
} else { |
|
121 |
return Collections.emptyList(); |
|
122 |
} |
|
123 |
} |
|
124 |
||
125 |
/** |
|
10 | 126 |
* Get the overview keywords. |
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 | 136 |
} |
137 |
} |
|
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
25874
diff
changeset
|
138 |
return result; |
10 | 139 |
} |
140 |
||
141 |
/** |
|
142 |
* Get members for meta tag keywords as an array, |
|
143 |
* where each member name is a string element of the array. |
|
144 |
* The parameter lists are not included in the keywords; |
|
145 |
* therefore all overloaded methods are combined.<br> |
|
146 |
* Example: getValue(Object) is returned in array as getValue() |
|
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 | 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 | 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 | 157 |
results.add(membername); |
158 |
} |
|
159 |
} |
|
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
25874
diff
changeset
|
160 |
((ArrayList)results).trimToSize(); |
10 | 161 |
return results; |
162 |
} |
|
163 |
} |