1 /* |
1 /* |
2 * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
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 |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. Oracle designates this |
7 * published by the Free Software Foundation. Oracle designates this |
62 import com.sun.tools.javac.util.ListBuffer; |
62 import com.sun.tools.javac.util.ListBuffer; |
63 import com.sun.tools.javac.util.Name; |
63 import com.sun.tools.javac.util.Name; |
64 import com.sun.tools.javac.util.Names; |
64 import com.sun.tools.javac.util.Names; |
65 import com.sun.tools.javac.util.Position; |
65 import com.sun.tools.javac.util.Position; |
66 |
66 |
67 import static com.sun.tools.javac.code.Flags.*; |
|
68 import static com.sun.tools.javac.code.Kinds.*; |
67 import static com.sun.tools.javac.code.Kinds.*; |
69 |
68 |
70 /** |
69 /** |
71 * Represents a java class and provides access to information |
70 * Represents a java class and provides access to information |
72 * about the class, the class' comment and tags, and the |
71 * about the class, the class' comment and tags, and the |
145 } |
144 } |
146 |
145 |
147 /** |
146 /** |
148 * Return true if this is a class, not an interface. |
147 * Return true if this is a class, not an interface. |
149 */ |
148 */ |
|
149 @Override |
150 public boolean isClass() { |
150 public boolean isClass() { |
151 return !Modifier.isInterface(getModifiers()); |
151 return !Modifier.isInterface(getModifiers()); |
152 } |
152 } |
153 |
153 |
154 /** |
154 /** |
155 * Return true if this is a ordinary class, |
155 * Return true if this is a ordinary class, |
156 * not an enumeration, exception, an error, or an interface. |
156 * not an enumeration, exception, an error, or an interface. |
157 */ |
157 */ |
|
158 @Override |
158 public boolean isOrdinaryClass() { |
159 public boolean isOrdinaryClass() { |
159 if (isEnum() || isInterface() || isAnnotationType()) { |
160 if (isEnum() || isInterface() || isAnnotationType()) { |
160 return false; |
161 return false; |
161 } |
162 } |
162 for (Type t = type; t.tag == TypeTags.CLASS; t = env.types.supertype(t)) { |
163 for (Type t = type; t.tag == TypeTags.CLASS; t = env.types.supertype(t)) { |
170 |
171 |
171 /** |
172 /** |
172 * Return true if this is an enumeration. |
173 * Return true if this is an enumeration. |
173 * (For legacy doclets, return false.) |
174 * (For legacy doclets, return false.) |
174 */ |
175 */ |
|
176 @Override |
175 public boolean isEnum() { |
177 public boolean isEnum() { |
176 return (getFlags() & Flags.ENUM) != 0 |
178 return (getFlags() & Flags.ENUM) != 0 |
177 && |
179 && |
178 !env.legacyDoclet; |
180 !env.legacyDoclet; |
179 } |
181 } |
180 |
182 |
181 /** |
183 /** |
182 * Return true if this is an interface, but not an annotation type. |
184 * Return true if this is an interface, but not an annotation type. |
183 * Overridden by AnnotationTypeDocImpl. |
185 * Overridden by AnnotationTypeDocImpl. |
184 */ |
186 */ |
|
187 @Override |
185 public boolean isInterface() { |
188 public boolean isInterface() { |
186 return Modifier.isInterface(getModifiers()); |
189 return Modifier.isInterface(getModifiers()); |
187 } |
190 } |
188 |
191 |
189 /** |
192 /** |
190 * Return true if this is an exception class |
193 * Return true if this is an exception class |
191 */ |
194 */ |
|
195 @Override |
192 public boolean isException() { |
196 public boolean isException() { |
193 if (isEnum() || isInterface() || isAnnotationType()) { |
197 if (isEnum() || isInterface() || isAnnotationType()) { |
194 return false; |
198 return false; |
195 } |
199 } |
196 for (Type t = type; t.tag == TypeTags.CLASS; t = env.types.supertype(t)) { |
200 for (Type t = type; t.tag == TypeTags.CLASS; t = env.types.supertype(t)) { |
372 |
378 |
373 /** |
379 /** |
374 * Return the qualified name and any type parameters. |
380 * Return the qualified name and any type parameters. |
375 * Each parameter is a type variable with optional bounds. |
381 * Each parameter is a type variable with optional bounds. |
376 */ |
382 */ |
|
383 @Override |
377 public String toString() { |
384 public String toString() { |
378 return classToString(env, tsym, true); |
385 return classToString(env, tsym, true); |
379 } |
386 } |
380 |
387 |
381 /** |
388 /** |
399 * Each parameter is a type variable with optional bounds. |
406 * Each parameter is a type variable with optional bounds. |
400 * If "full" is true all names are qualified, otherwise they are |
407 * If "full" is true all names are qualified, otherwise they are |
401 * qualified by their enclosing class(es) only. |
408 * qualified by their enclosing class(es) only. |
402 */ |
409 */ |
403 static String classToString(DocEnv env, ClassSymbol c, boolean full) { |
410 static String classToString(DocEnv env, ClassSymbol c, boolean full) { |
404 StringBuffer s = new StringBuffer(); |
411 StringBuilder s = new StringBuilder(); |
405 if (!c.isInner()) { // if c is not an inner class |
412 if (!c.isInner()) { // if c is not an inner class |
406 s.append(getClassName(c, full)); |
413 s.append(getClassName(c, full)); |
407 } else { |
414 } else { |
408 // c is an inner class, so include type params of outer. |
415 // c is an inner class, so include type params of outer. |
409 ClassSymbol encl = c.owner.enclClass(); |
416 ClassSymbol encl = c.owner.enclClass(); |
447 |
454 |
448 /** |
455 /** |
449 * Return the modifier string for this class. If it's an interface |
456 * Return the modifier string for this class. If it's an interface |
450 * exclude 'abstract' keyword from the modifier string |
457 * exclude 'abstract' keyword from the modifier string |
451 */ |
458 */ |
|
459 @Override |
452 public String modifiers() { |
460 public String modifiers() { |
453 return Modifier.toString(modifierSpecifier()); |
461 return Modifier.toString(modifierSpecifier()); |
454 } |
462 } |
455 |
463 |
|
464 @Override |
456 public int modifierSpecifier() { |
465 public int modifierSpecifier() { |
457 int modifiers = getModifiers(); |
466 int modifiers = getModifiers(); |
458 return (isInterface() || isAnnotationType()) |
467 return (isInterface() || isAnnotationType()) |
459 ? modifiers & ~Modifier.ABSTRACT |
468 ? modifiers & ~Modifier.ABSTRACT |
460 : modifiers; |
469 : modifiers; |
1283 |
1292 |
1284 /** |
1293 /** |
1285 * Return the source position of the entity, or null if |
1294 * Return the source position of the entity, or null if |
1286 * no position is available. |
1295 * no position is available. |
1287 */ |
1296 */ |
|
1297 @Override |
1288 public SourcePosition position() { |
1298 public SourcePosition position() { |
1289 if (tsym.sourcefile == null) return null; |
1299 if (tsym.sourcefile == null) return null; |
1290 return SourcePositionImpl.make(tsym.sourcefile, |
1300 return SourcePositionImpl.make(tsym.sourcefile, |
1291 (tree==null) ? Position.NOPOS : tree.pos, |
1301 (tree==null) ? Position.NOPOS : tree.pos, |
1292 lineMap); |
1302 lineMap); |