author | amurillo |
Thu, 13 Aug 2015 15:50:52 -0700 | |
changeset 32224 | dae855d05f6c |
parent 25874 | 83c19f00452c |
child 32800 | 8457813125e3 |
permissions | -rw-r--r-- |
10 | 1 |
/* |
25443
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
17275
diff
changeset
|
2 |
* Copyright (c) 1997, 2014, 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.javadoc; |
|
27 |
||
14258 | 28 |
import java.lang.reflect.Modifier; |
29 |
||
10 | 30 |
import com.sun.javadoc.*; |
14802 | 31 |
import com.sun.source.util.TreePath; |
10 | 32 |
import com.sun.tools.javac.code.*; |
33 |
import com.sun.tools.javac.code.Symbol.*; |
|
34 |
import com.sun.tools.javac.code.Type; |
|
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14260
diff
changeset
|
35 |
import static com.sun.tools.javac.code.TypeTag.CLASS; |
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14260
diff
changeset
|
36 |
|
10 | 37 |
/** |
38 |
* Represents a method of a java class. |
|
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> |
727a84636f12
8000665: fix "internal API" comments on javadoc files
jjg
parents:
14258
diff
changeset
|
44 |
* |
10 | 45 |
* @since 1.2 |
46 |
* @author Robert Field |
|
47 |
* @author Neal Gafter (rewrite) |
|
48 |
*/ |
|
49 |
||
50 |
public class MethodDocImpl |
|
51 |
extends ExecutableMemberDocImpl implements MethodDoc { |
|
52 |
||
53 |
/** |
|
54 |
* constructor. |
|
55 |
*/ |
|
56 |
public MethodDocImpl(DocEnv env, MethodSymbol sym) { |
|
57 |
super(env, sym); |
|
58 |
} |
|
59 |
||
60 |
/** |
|
61 |
* constructor. |
|
62 |
*/ |
|
14802 | 63 |
public MethodDocImpl(DocEnv env, MethodSymbol sym, TreePath treePath) { |
64 |
super(env, sym, treePath); |
|
10 | 65 |
} |
66 |
||
67 |
/** |
|
68 |
* Return true if it is a method, which it is. |
|
69 |
* Note: constructors are not methods. |
|
70 |
* This method is overridden by AnnotationTypeElementDocImpl. |
|
71 |
* |
|
72 |
* @return true |
|
73 |
*/ |
|
74 |
public boolean isMethod() { |
|
75 |
return true; |
|
76 |
} |
|
77 |
||
78 |
/** |
|
14951
8d9ea42e4aba
8004814: javadoc should be able to detect default methods
vromero
parents:
14802
diff
changeset
|
79 |
* Return true if this method is default |
8d9ea42e4aba
8004814: javadoc should be able to detect default methods
vromero
parents:
14802
diff
changeset
|
80 |
*/ |
8d9ea42e4aba
8004814: javadoc should be able to detect default methods
vromero
parents:
14802
diff
changeset
|
81 |
public boolean isDefault() { |
8d9ea42e4aba
8004814: javadoc should be able to detect default methods
vromero
parents:
14802
diff
changeset
|
82 |
return (sym.flags() & Flags.DEFAULT) != 0; |
8d9ea42e4aba
8004814: javadoc should be able to detect default methods
vromero
parents:
14802
diff
changeset
|
83 |
} |
8d9ea42e4aba
8004814: javadoc should be able to detect default methods
vromero
parents:
14802
diff
changeset
|
84 |
|
8d9ea42e4aba
8004814: javadoc should be able to detect default methods
vromero
parents:
14802
diff
changeset
|
85 |
/** |
10 | 86 |
* Return true if this method is abstract |
87 |
*/ |
|
88 |
public boolean isAbstract() { |
|
15034
b7c791bc4526
8004891: Check for abstract method in javadoc does not conform to the language model
bpatel
parents:
14951
diff
changeset
|
89 |
return (Modifier.isAbstract(getModifiers()) && !isDefault()); |
10 | 90 |
} |
91 |
||
92 |
/** |
|
93 |
* Get return type. |
|
94 |
* |
|
95 |
* @return the return type of this method, null if it |
|
96 |
* is a constructor. |
|
97 |
*/ |
|
98 |
public com.sun.javadoc.Type returnType() { |
|
99 |
return TypeMaker.getType(env, sym.type.getReturnType(), false); |
|
100 |
} |
|
101 |
||
102 |
/** |
|
103 |
* Return the class that originally defined the method that |
|
104 |
* is overridden by the current definition, or null if no |
|
105 |
* such class exists. |
|
106 |
* |
|
107 |
* @return a ClassDocImpl representing the superclass that |
|
108 |
* originally defined this method, null if this method does |
|
109 |
* not override a definition in a superclass. |
|
110 |
*/ |
|
111 |
public ClassDoc overriddenClass() { |
|
112 |
com.sun.javadoc.Type t = overriddenType(); |
|
113 |
return (t != null) ? t.asClassDoc() : null; |
|
114 |
} |
|
115 |
||
116 |
/** |
|
117 |
* Return the type containing the method that this method overrides. |
|
118 |
* It may be a <code>ClassDoc</code> or a <code>ParameterizedType</code>. |
|
119 |
*/ |
|
120 |
public com.sun.javadoc.Type overriddenType() { |
|
121 |
||
122 |
if ((sym.flags() & Flags.STATIC) != 0) { |
|
123 |
return null; |
|
124 |
} |
|
125 |
||
126 |
ClassSymbol origin = (ClassSymbol)sym.owner; |
|
127 |
for (Type t = env.types.supertype(origin.type); |
|
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14260
diff
changeset
|
128 |
t.hasTag(CLASS); |
10 | 129 |
t = env.types.supertype(t)) { |
130 |
ClassSymbol c = (ClassSymbol)t.tsym; |
|
25443
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
17275
diff
changeset
|
131 |
for (Symbol sym2 : c.members().getSymbolsByName(sym.name)) { |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
17275
diff
changeset
|
132 |
if (sym.overrides(sym2, origin, env.types, true)) { |
10 | 133 |
return TypeMaker.getType(env, t); |
134 |
} |
|
135 |
} |
|
136 |
} |
|
137 |
return null; |
|
138 |
} |
|
139 |
||
140 |
/** |
|
141 |
* Return the method that this method overrides. |
|
142 |
* |
|
143 |
* @return a MethodDoc representing a method definition |
|
144 |
* in a superclass this method overrides, null if |
|
145 |
* this method does not override. |
|
146 |
*/ |
|
147 |
public MethodDoc overriddenMethod() { |
|
148 |
||
149 |
// Real overriding only. Static members are simply hidden. |
|
150 |
// Likewise for constructors, but the MethodSymbol.overrides |
|
151 |
// method takes this into account. |
|
152 |
if ((sym.flags() & Flags.STATIC) != 0) { |
|
153 |
return null; |
|
154 |
} |
|
155 |
||
156 |
// Derived from com.sun.tools.javac.comp.Check.checkOverride . |
|
157 |
||
158 |
ClassSymbol origin = (ClassSymbol)sym.owner; |
|
159 |
for (Type t = env.types.supertype(origin.type); |
|
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14260
diff
changeset
|
160 |
t.hasTag(CLASS); |
10 | 161 |
t = env.types.supertype(t)) { |
162 |
ClassSymbol c = (ClassSymbol)t.tsym; |
|
25443
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
17275
diff
changeset
|
163 |
for (Symbol sym2 : c.members().getSymbolsByName(sym.name)) { |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
17275
diff
changeset
|
164 |
if (sym.overrides(sym2, origin, env.types, true)) { |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
17275
diff
changeset
|
165 |
return env.getMethodDoc((MethodSymbol)sym2); |
10 | 166 |
} |
167 |
} |
|
168 |
} |
|
169 |
return null; |
|
170 |
} |
|
171 |
||
172 |
/** |
|
173 |
* Tests whether this method overrides another. |
|
174 |
* The overridden method may be one declared in a superclass or |
|
175 |
* a superinterface (unlike {@link #overriddenMethod()}). |
|
176 |
* |
|
177 |
* <p> When a non-abstract method overrides an abstract one, it is |
|
178 |
* also said to <i>implement</i> the other. |
|
179 |
* |
|
180 |
* @param meth the other method to examine |
|
181 |
* @return <tt>true</tt> if this method overrides the other |
|
182 |
*/ |
|
183 |
public boolean overrides(MethodDoc meth) { |
|
184 |
MethodSymbol overridee = ((MethodDocImpl) meth).sym; |
|
185 |
ClassSymbol origin = (ClassSymbol) sym.owner; |
|
186 |
||
187 |
return sym.name == overridee.name && |
|
188 |
||
189 |
// not reflexive as per JLS |
|
190 |
sym != overridee && |
|
191 |
||
192 |
// we don't care if overridee is static, though that wouldn't |
|
193 |
// compile |
|
194 |
!sym.isStatic() && |
|
195 |
||
196 |
// sym, whose declaring type is the origin, must be |
|
197 |
// in a subtype of overridee's type |
|
198 |
env.types.asSuper(origin.type, overridee.owner) != null && |
|
199 |
||
200 |
// check access and signatures; don't check return types |
|
201 |
sym.overrides(overridee, origin, env.types, false); |
|
202 |
} |
|
203 |
||
204 |
||
205 |
public String name() { |
|
17275
bcaa1940863a
8012656: cache frequently used name strings for DocImpl classes
jjg
parents:
15034
diff
changeset
|
206 |
if (name == null) { |
bcaa1940863a
8012656: cache frequently used name strings for DocImpl classes
jjg
parents:
15034
diff
changeset
|
207 |
name = sym.name.toString(); |
bcaa1940863a
8012656: cache frequently used name strings for DocImpl classes
jjg
parents:
15034
diff
changeset
|
208 |
} |
bcaa1940863a
8012656: cache frequently used name strings for DocImpl classes
jjg
parents:
15034
diff
changeset
|
209 |
return name; |
10 | 210 |
} |
211 |
||
17275
bcaa1940863a
8012656: cache frequently used name strings for DocImpl classes
jjg
parents:
15034
diff
changeset
|
212 |
private String name; |
bcaa1940863a
8012656: cache frequently used name strings for DocImpl classes
jjg
parents:
15034
diff
changeset
|
213 |
|
10 | 214 |
public String qualifiedName() { |
17275
bcaa1940863a
8012656: cache frequently used name strings for DocImpl classes
jjg
parents:
15034
diff
changeset
|
215 |
if (qualifiedName == null) { |
bcaa1940863a
8012656: cache frequently used name strings for DocImpl classes
jjg
parents:
15034
diff
changeset
|
216 |
qualifiedName = sym.enclClass().getQualifiedName() + "." + sym.name; |
bcaa1940863a
8012656: cache frequently used name strings for DocImpl classes
jjg
parents:
15034
diff
changeset
|
217 |
} |
bcaa1940863a
8012656: cache frequently used name strings for DocImpl classes
jjg
parents:
15034
diff
changeset
|
218 |
return qualifiedName; |
10 | 219 |
} |
220 |
||
17275
bcaa1940863a
8012656: cache frequently used name strings for DocImpl classes
jjg
parents:
15034
diff
changeset
|
221 |
private String qualifiedName; |
bcaa1940863a
8012656: cache frequently used name strings for DocImpl classes
jjg
parents:
15034
diff
changeset
|
222 |
|
10 | 223 |
/** |
224 |
* Returns a string representation of this method. Includes the |
|
225 |
* qualified signature, the qualified method name, and any type |
|
226 |
* parameters. Type parameters follow the class name, as they do |
|
227 |
* in the syntax for invoking methods with explicit type parameters. |
|
228 |
*/ |
|
229 |
public String toString() { |
|
230 |
return sym.enclClass().getQualifiedName() + |
|
231 |
"." + typeParametersString() + name() + signature(); |
|
232 |
} |
|
233 |
} |