author | ksrini |
Fri, 09 Feb 2018 13:58:17 -0800 | |
changeset 48840 | 5e2d2067da48 |
parent 47216 | 71c04702a3d5 |
permissions | -rw-r--r-- |
10 | 1 |
/* |
48840
5e2d2067da48
8194651: javadoc: mark the com.sun.javadoc API for removal
ksrini
parents:
47216
diff
changeset
|
2 |
* Copyright (c) 1997, 2018, 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 |
||
37938
42baa89d2156
8075703: jdk.javadoc module exports com.sun.tools.javadoc package which contains a lot of internal API.
jjg
parents:
25874
diff
changeset
|
26 |
package com.sun.tools.javadoc.main; |
10 | 27 |
|
14258 | 28 |
import java.lang.reflect.Modifier; |
29 |
import java.text.CollationKey; |
|
10 | 30 |
|
14258 | 31 |
import com.sun.javadoc.*; |
14802 | 32 |
import com.sun.source.util.TreePath; |
10 | 33 |
import com.sun.tools.javac.code.Attribute; |
34 |
import com.sun.tools.javac.code.Symbol; |
|
35 |
import com.sun.tools.javac.code.Symbol.ClassSymbol; |
|
36 |
import com.sun.tools.javac.tree.JCTree; |
|
14802 | 37 |
import com.sun.tools.javac.tree.JCTree.JCCompilationUnit; |
10 | 38 |
import com.sun.tools.javac.util.Position; |
39 |
||
40 |
/** |
|
41 |
* Represents a java program element: class, interface, field, |
|
42 |
* constructor, or method. |
|
43 |
* This is an abstract class dealing with information common to |
|
44 |
* these elements. |
|
45 |
* |
|
14260
727a84636f12
8000665: fix "internal API" comments on javadoc files
jjg
parents:
14258
diff
changeset
|
46 |
* <p><b>This is NOT part of any supported API. |
727a84636f12
8000665: fix "internal API" comments on javadoc files
jjg
parents:
14258
diff
changeset
|
47 |
* 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
|
48 |
* 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
|
49 |
* deletion without notice.</b> |
727a84636f12
8000665: fix "internal API" comments on javadoc files
jjg
parents:
14258
diff
changeset
|
50 |
* |
10 | 51 |
* @see MemberDocImpl |
52 |
* @see ClassDocImpl |
|
53 |
* |
|
54 |
* @author Robert Field |
|
55 |
* @author Neal Gafter (rewrite) |
|
56 |
* @author Scott Seligman (generics, enums, annotations) |
|
57 |
*/ |
|
48840
5e2d2067da48
8194651: javadoc: mark the com.sun.javadoc API for removal
ksrini
parents:
47216
diff
changeset
|
58 |
@Deprecated(since="9", forRemoval=true) |
5e2d2067da48
8194651: javadoc: mark the com.sun.javadoc API for removal
ksrini
parents:
47216
diff
changeset
|
59 |
@SuppressWarnings("removal") |
10 | 60 |
public abstract class ProgramElementDocImpl |
61 |
extends DocImpl implements ProgramElementDoc { |
|
62 |
||
63 |
private final Symbol sym; |
|
64 |
||
65 |
// For source position information. |
|
66 |
JCTree tree = null; |
|
67 |
Position.LineMap lineMap = null; |
|
68 |
||
69 |
||
70 |
// Cache for getModifiers(). |
|
71 |
private int modifiers = -1; |
|
72 |
||
14802 | 73 |
protected ProgramElementDocImpl(DocEnv env, Symbol sym, TreePath treePath) { |
74 |
super(env, treePath); |
|
10 | 75 |
this.sym = sym; |
14802 | 76 |
if (treePath != null) { |
77 |
tree = (JCTree) treePath.getLeaf(); |
|
78 |
lineMap = ((JCCompilationUnit) treePath.getCompilationUnit()).lineMap; |
|
79 |
} |
|
10 | 80 |
} |
81 |
||
14802 | 82 |
@Override |
83 |
void setTreePath(TreePath treePath) { |
|
84 |
super.setTreePath(treePath); |
|
85 |
this.tree = (JCTree) treePath.getLeaf(); |
|
86 |
this.lineMap = ((JCCompilationUnit) treePath.getCompilationUnit()).lineMap; |
|
10 | 87 |
} |
88 |
||
89 |
/** |
|
90 |
* Subclasses override to identify the containing class |
|
91 |
*/ |
|
92 |
protected abstract ClassSymbol getContainingClass(); |
|
93 |
||
94 |
/** |
|
95 |
* Returns the flags in terms of javac's flags |
|
96 |
*/ |
|
97 |
abstract protected long getFlags(); |
|
98 |
||
99 |
/** |
|
100 |
* Returns the modifier flags in terms of java.lang.reflect.Modifier. |
|
101 |
*/ |
|
102 |
protected int getModifiers() { |
|
103 |
if (modifiers == -1) { |
|
104 |
modifiers = DocEnv.translateModifiers(getFlags()); |
|
105 |
} |
|
106 |
return modifiers; |
|
107 |
} |
|
108 |
||
109 |
/** |
|
110 |
* Get the containing class of this program element. |
|
111 |
* |
|
112 |
* @return a ClassDocImpl for this element's containing class. |
|
113 |
* If this is a class with no outer class, return null. |
|
114 |
*/ |
|
115 |
public ClassDoc containingClass() { |
|
116 |
if (getContainingClass() == null) { |
|
117 |
return null; |
|
118 |
} |
|
119 |
return env.getClassDoc(getContainingClass()); |
|
120 |
} |
|
121 |
||
122 |
/** |
|
123 |
* Return the package that this member is contained in. |
|
124 |
* Return "" if in unnamed package. |
|
125 |
*/ |
|
126 |
public PackageDoc containingPackage() { |
|
127 |
return env.getPackageDoc(getContainingClass().packge()); |
|
128 |
} |
|
129 |
||
130 |
/** |
|
131 |
* Get the modifier specifier integer. |
|
132 |
* |
|
133 |
* @see java.lang.reflect.Modifier |
|
134 |
*/ |
|
135 |
public int modifierSpecifier() { |
|
136 |
int modifiers = getModifiers(); |
|
137 |
if (isMethod() && containingClass().isInterface()) |
|
138 |
// Remove the implicit abstract modifier. |
|
139 |
return modifiers & ~Modifier.ABSTRACT; |
|
140 |
return modifiers; |
|
141 |
} |
|
142 |
||
143 |
/** |
|
144 |
* Get modifiers string. |
|
145 |
* <pre> |
|
146 |
* Example, for: |
|
147 |
* public abstract int foo() { ... } |
|
148 |
* modifiers() would return: |
|
149 |
* 'public abstract' |
|
150 |
* </pre> |
|
151 |
* Annotations are not included. |
|
152 |
*/ |
|
153 |
public String modifiers() { |
|
154 |
int modifiers = getModifiers(); |
|
155 |
if (isAnnotationTypeElement() || |
|
156 |
(isMethod() && containingClass().isInterface())) { |
|
157 |
// Remove the implicit abstract modifier. |
|
158 |
return Modifier.toString(modifiers & ~Modifier.ABSTRACT); |
|
159 |
} else { |
|
160 |
return Modifier.toString(modifiers); |
|
161 |
} |
|
162 |
} |
|
163 |
||
164 |
/** |
|
165 |
* Get the annotations of this program element. |
|
166 |
* Return an empty array if there are none. |
|
167 |
*/ |
|
168 |
public AnnotationDesc[] annotations() { |
|
14961
e731935052af
8005098: Provide isSynthesized() information on Attribute.Compound
jfranck
parents:
14802
diff
changeset
|
169 |
AnnotationDesc res[] = new AnnotationDesc[sym.getRawAttributes().length()]; |
10 | 170 |
int i = 0; |
14961
e731935052af
8005098: Provide isSynthesized() information on Attribute.Compound
jfranck
parents:
14802
diff
changeset
|
171 |
for (Attribute.Compound a : sym.getRawAttributes()) { |
10 | 172 |
res[i++] = new AnnotationDescImpl(env, a); |
173 |
} |
|
174 |
return res; |
|
175 |
} |
|
176 |
||
177 |
/** |
|
178 |
* Return true if this program element is public |
|
179 |
*/ |
|
180 |
public boolean isPublic() { |
|
181 |
int modifiers = getModifiers(); |
|
182 |
return Modifier.isPublic(modifiers); |
|
183 |
} |
|
184 |
||
185 |
/** |
|
186 |
* Return true if this program element is protected |
|
187 |
*/ |
|
188 |
public boolean isProtected() { |
|
189 |
int modifiers = getModifiers(); |
|
190 |
return Modifier.isProtected(modifiers); |
|
191 |
} |
|
192 |
||
193 |
/** |
|
194 |
* Return true if this program element is private |
|
195 |
*/ |
|
196 |
public boolean isPrivate() { |
|
197 |
int modifiers = getModifiers(); |
|
198 |
return Modifier.isPrivate(modifiers); |
|
199 |
} |
|
200 |
||
201 |
/** |
|
202 |
* Return true if this program element is package private |
|
203 |
*/ |
|
204 |
public boolean isPackagePrivate() { |
|
205 |
return !(isPublic() || isPrivate() || isProtected()); |
|
206 |
} |
|
207 |
||
208 |
/** |
|
209 |
* Return true if this program element is static |
|
210 |
*/ |
|
211 |
public boolean isStatic() { |
|
212 |
int modifiers = getModifiers(); |
|
213 |
return Modifier.isStatic(modifiers); |
|
214 |
} |
|
215 |
||
216 |
/** |
|
217 |
* Return true if this program element is final |
|
218 |
*/ |
|
219 |
public boolean isFinal() { |
|
220 |
int modifiers = getModifiers(); |
|
221 |
return Modifier.isFinal(modifiers); |
|
222 |
} |
|
223 |
||
224 |
/** |
|
225 |
* Generate a key for sorting. |
|
226 |
*/ |
|
227 |
CollationKey generateKey() { |
|
228 |
String k = name(); |
|
229 |
// System.out.println("COLLATION KEY FOR " + this + " is \"" + k + "\""); |
|
230 |
return env.doclocale.collator.getCollationKey(k); |
|
231 |
} |
|
232 |
||
233 |
} |