You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ProgramElementDocImpl.java 5.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. /* -*- Mode: JDE; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
  2. *
  3. * This file is part of the debugger and core tools for the AspectJ(tm)
  4. * programming language; see http://aspectj.org
  5. *
  6. * The contents of this file are subject to the Mozilla Public License
  7. * Version 1.1 (the "License"); you may not use this file except in
  8. * compliance with the License. You may obtain a copy of the License at
  9. * either http://www.mozilla.org/MPL/ or http://aspectj.org/MPL/.
  10. *
  11. * Software distributed under the License is distributed on an "AS IS" basis,
  12. * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  13. * for the specific language governing rights and limitations under the
  14. * License.
  15. *
  16. * The Original Code is AspectJ.
  17. *
  18. * The Initial Developer of the Original Code is Xerox Corporation. Portions
  19. * created by Xerox Corporation are Copyright (C) 1999-2002 Xerox Corporation.
  20. * All Rights Reserved.
  21. */
  22. package org.aspectj.tools.ajdoc;
  23. import org.aspectj.compiler.base.ast.Dec;
  24. import org.aspectj.compiler.base.ast.Modifiers;
  25. import org.aspectj.compiler.base.ast.NameType;
  26. import org.aspectj.compiler.base.ast.TypeDec;
  27. import org.aspectj.compiler.crosscuts.AspectJCompiler;
  28. import com.sun.javadoc.ClassDoc;
  29. import com.sun.javadoc.PackageDoc;
  30. import java.lang.reflect.Modifier;
  31. public abstract class ProgramElementDocImpl
  32. extends DocImpl
  33. implements org.aspectj.ajdoc.ProgramElementDoc {
  34. /** The containing ClassDoc. */
  35. private final ClassDoc containingClass;
  36. /*
  37. construction of ProgramElementDocImpl must not recursively
  38. invoke construction of instances of subclass ClassDocImpl
  39. or endless recursion will be possible
  40. */
  41. public ProgramElementDocImpl(ClassDoc containingClass) {
  42. this.containingClass = containingClass;
  43. }
  44. /**
  45. * Returns the underlying Dec used for a number of methods.
  46. *
  47. * @return the underlying Dec used for a number of methods.
  48. */
  49. protected abstract Dec dec();
  50. /**
  51. * Returns the AspectJCompiler that this tree. Delegates
  52. * to the underlying {@link #dec()}.
  53. *
  54. * @return the AspectJCompiler that compiled this tree.
  55. */
  56. protected final AspectJCompiler ajc() {
  57. return (AspectJCompiler)dec().getCompiler();
  58. }
  59. /**
  60. * Returns this's Comment.
  61. *
  62. * @return the Comment for this Doc.
  63. */
  64. public Comment getComment() {
  65. if (super.getComment() == null) {
  66. setComment(new Comment(this, dec().getFormalComment(), err()));
  67. }
  68. return super.getComment();
  69. }
  70. /**
  71. * Returns the nearest enclosing class. The returned value
  72. * is <code>null</code> if this is a top-level entity.
  73. *
  74. * @return a ClassDoc representing the nearest
  75. * enclosing class. This can be null for
  76. * top-level entities.
  77. */
  78. public ClassDoc containingClass() {
  79. return containingClass;
  80. }
  81. /**
  82. * Returns the package in which this Dec was declared.
  83. *
  84. * @return a PackageDoc representing the package
  85. * in which this Dec was declared.
  86. */
  87. public PackageDoc containingPackage() {
  88. return PackageDocImpl.getPackageDoc(nonNullTypeDec());
  89. }
  90. /**
  91. */
  92. public TypeDec nonNullTypeDec() {
  93. if (dec().getDeclaringType() == null) return null;
  94. return ((NameType)dec().getDeclaringType()).getTypeDec();
  95. }
  96. /**
  97. * An int form of this Dec's modifiers.
  98. *
  99. * @return an int form this Dec's modifiers.
  100. * @see java.lang.reflect.Modifier
  101. */
  102. public int modifierSpecifier() {
  103. return dec().getModifiers().getValue();
  104. }
  105. /**
  106. * Returns the modifiers as a String.
  107. *
  108. * @return a String representing to modifiers.
  109. */
  110. public String modifiers() {
  111. return Modifier.toString(modifierSpecifier());
  112. }
  113. /**
  114. * Returns <code>true</code> if this is <code>public</code>.
  115. *
  116. * @return <code>true</code> if this is <code>public</code>.
  117. */
  118. public boolean isPublic() {
  119. return dec().isPublic();
  120. }
  121. /**
  122. * Returns <code>true</code> if this is <code>protected</code>.
  123. *
  124. * @return <code>true</code> if this is <code>protected</code>.
  125. */
  126. public boolean isProtected() {
  127. return dec().isProtected();
  128. }
  129. /**
  130. * Returns <code>true</code> if this is <i>package private</i>.
  131. *
  132. * @return <code>true</code> if this is <i>package private</i>.
  133. */
  134. public boolean isPackagePrivate() {
  135. Modifiers mods = dec().getModifiers();
  136. // todo: consider creating Dec.isPackagePrivate()
  137. // todo: consider NPE if mods null
  138. return ((null != mods) && mods.isPackagePrivate());
  139. }
  140. /**
  141. * Returns <code>true</code> if this is <code>private</code>.
  142. *
  143. * @return <code>true</code> if this is <code>private</code>.
  144. */
  145. public boolean isPrivate() {
  146. return dec().isPrivate();
  147. }
  148. /**
  149. * Returns <code>true</code> if this is <code>static</code>.
  150. *
  151. * @return <code>true</code> if this is <code>static</code>.
  152. */
  153. public boolean isStatic() {
  154. return dec().isStatic();
  155. }
  156. /**
  157. * Returns <code>true</code> if this is <code>final</code>.
  158. *
  159. * @return <code>true</code> if this is <code>final</code>.
  160. */
  161. public boolean isFinal() {
  162. return dec().isFinal();
  163. }
  164. /**
  165. * Returns the fully-qualified type name of this Dec (not member name).
  166. *
  167. * @return the fully-qualified name.
  168. */
  169. public String qualifiedName() {
  170. return name();
  171. }
  172. /**
  173. * Returns the name -- e.g. ID.
  174. *
  175. * @return the name of the Dec.
  176. */
  177. public String name() {
  178. return dec().getId();
  179. }
  180. }