1. /*
  2. * @(#)Declaration.java 1.6 04/07/16
  3. *
  4. * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
  5. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  6. */
  7. package com.sun.mirror.declaration;
  8. import java.lang.annotation.Annotation;
  9. import java.util.Collection;
  10. import com.sun.mirror.type.*;
  11. import com.sun.mirror.util.*;
  12. /**
  13. * Represents the declaration of a program element such as a package,
  14. * class, or method. Each declaration represents a static, language-level
  15. * construct (and not, for example, a runtime construct of the virtual
  16. * machine), and typically corresponds one-to-one with a particular
  17. * fragment of source code.
  18. *
  19. * <p> Declarations should be compared using the {@link #equals(Object)}
  20. * method. There is no guarantee that any particular declaration will
  21. * always be represented by the same object.
  22. *
  23. * @author Joseph D. Darcy
  24. * @author Scott Seligman
  25. * @version 1.6 04/07/16
  26. *
  27. * @see Declarations
  28. * @see TypeMirror
  29. * @since 1.5
  30. */
  31. public interface Declaration {
  32. /**
  33. * Tests whether an object represents the same declaration as this.
  34. *
  35. * @param obj the object to be compared with this declaration
  36. * @return <tt>true</tt> if the specified object represents the same
  37. * declaration as this
  38. */
  39. boolean equals(Object obj);
  40. /**
  41. * Returns the text of the documentation ("javadoc") comment of
  42. * this declaration.
  43. *
  44. * @return the documentation comment of this declaration, or <tt>null</tt>
  45. * if there is none
  46. */
  47. String getDocComment();
  48. /**
  49. * Returns the annotations that are directly present on this declaration.
  50. *
  51. * @return the annotations directly present on this declaration;
  52. * an empty collection if there are none
  53. */
  54. Collection<AnnotationMirror> getAnnotationMirrors();
  55. /**
  56. * Returns the annotation of this declaration having the specified
  57. * type. The annotation may be either inherited or directly
  58. * present on this declaration.
  59. *
  60. * <p> The annotation returned by this method could contain an element
  61. * whose value is of type <tt>Class</tt>.
  62. * This value cannot be returned directly: information necessary to
  63. * locate and load a class (such as the class loader to use) is
  64. * not available, and the class might not be loadable at all.
  65. * Attempting to read a <tt>Class</tt> object by invoking the relevant
  66. * method on the returned annotation
  67. * will result in a {@link MirroredTypeException},
  68. * from which the corresponding {@link TypeMirror} may be extracted.
  69. * Similarly, attempting to read a <tt>Class[]</tt>-valued element
  70. * will result in a {@link MirroredTypesException}.
  71. *
  72. * <blockquote>
  73. * <i>Note:</i> This method is unlike
  74. * others in this and related interfaces. It operates on run-time
  75. * reflective information -- representations of annotation types
  76. * currently loaded into the VM -- rather than on the mirrored
  77. * representations defined by and used throughout these
  78. * interfaces. It is intended for callers that are written to
  79. * operate on a known, fixed set of annotation types.
  80. * </blockquote>
  81. *
  82. * @param <A> the annotation type
  83. * @param annotationType the <tt>Class</tt> object corresponding to
  84. * the annotation type
  85. * @return the annotation of this declaration having the specified type
  86. *
  87. * @see #getAnnotationMirrors()
  88. */
  89. <A extends Annotation> A getAnnotation(Class<A> annotationType);
  90. /**
  91. * Returns the modifiers of this declaration, excluding annotations.
  92. * Implicit modifiers, such as the <tt>public</tt> and <tt>static</tt>
  93. * modifiers of interface members, are included.
  94. *
  95. * @return the modifiers of this declaration in undefined order;
  96. * an empty collection if there are none
  97. */
  98. Collection<Modifier> getModifiers();
  99. /**
  100. * Returns the simple (unqualified) name of this declaration.
  101. * The name of a generic type does not include any reference
  102. * to its formal type parameters.
  103. * For example, the simple name of the interface declaration
  104. * {@code java.util.Set<E>} is <tt>"Set"</tt>.
  105. * If this declaration represents the empty package, an empty
  106. * string is returned.
  107. * If it represents a constructor, the simple name of its
  108. * declaring class is returned.
  109. *
  110. * @return the simple name of this declaration
  111. */
  112. String getSimpleName();
  113. /**
  114. * Returns the source position of the beginning of this declaration.
  115. * Returns <tt>null</tt> if the position is unknown or not applicable.
  116. *
  117. * <p> This source position is intended for use in providing
  118. * diagnostics, and indicates only approximately where a declaration
  119. * begins.
  120. *
  121. * @return the source position of the beginning of this declaration,
  122. * or null if the position is unknown or not applicable
  123. */
  124. SourcePosition getPosition();
  125. /**
  126. * Applies a visitor to this declaration.
  127. *
  128. * @param v the visitor operating on this declaration
  129. */
  130. void accept(DeclarationVisitor v);
  131. }