1. /*
  2. * @(#)AnnotationProcessorEnvironment.java 1.7 04/07/19
  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.apt;
  8. import java.util.Collection;
  9. import java.util.Map;
  10. import com.sun.mirror.declaration.*;
  11. import com.sun.mirror.util.*;
  12. /**
  13. * The environment encapsulating the state needed by an annotation processor.
  14. * An annotation processing tool makes this environment available
  15. * to all annotation processors.
  16. *
  17. * <p> When an annotation processing tool is invoked, it is given a
  18. * set of type declarations on which to operate. These
  19. * are refered to as the <i>specified</i> types.
  20. * The type declarations said to be <i>included</i> in this invocation
  21. * consist of the specified types and any types nested within them.
  22. *
  23. * <p> {@link DeclarationFilter}
  24. * provides a simple way to select just the items of interest
  25. * when a method returns a collection of declarations.
  26. *
  27. * @author Joseph D. Darcy
  28. * @author Scott Seligman
  29. * @version 1.7 04/07/19
  30. * @since 1.5
  31. */
  32. public interface AnnotationProcessorEnvironment {
  33. /**
  34. * Returns the options passed to the annotation processing tool.
  35. * Options are returned in the form of a map from option name
  36. * (such as <tt>"-encoding"</tt>) to option value.
  37. * For an option with no value (such as <tt>"-help"</tt>), the
  38. * corresponding value in the map is <tt>null</tt>.
  39. *
  40. * <p> Options beginning with <tt>"-A"</tt> are <i>processor-specific.</i>
  41. * Such options are unrecognized by the tool, but intended to be used by
  42. * some annotation processor.
  43. *
  44. * @return the options passed to the tool
  45. */
  46. Map<String,String> getOptions();
  47. /**
  48. * Returns the messager used to report errors, warnings, and other
  49. * notices.
  50. *
  51. * @return the messager
  52. */
  53. Messager getMessager();
  54. /**
  55. * Returns the filer used to create new source, class, or auxiliary
  56. * files.
  57. *
  58. * @return the filer
  59. */
  60. Filer getFiler();
  61. /**
  62. * Returns the declarations of the types specified when the
  63. * annotation processing tool was invoked.
  64. *
  65. * @return the types specified when the tool was invoked, or an
  66. * empty collection if there were none
  67. */
  68. Collection<TypeDeclaration> getSpecifiedTypeDeclarations();
  69. /**
  70. * Returns the declaration of a package given its fully qualified name.
  71. *
  72. * @param name fully qualified package name, or "" for the unnamed package
  73. * @return the declaration of the named package, or null if it cannot
  74. * be found
  75. */
  76. PackageDeclaration getPackage(String name);
  77. /**
  78. * Returns the declaration of a type given its fully qualified name.
  79. *
  80. * @param name fully qualified type name
  81. * @return the declaration of the named type, or null if it cannot be
  82. * found
  83. */
  84. TypeDeclaration getTypeDeclaration(String name);
  85. /**
  86. * A convenience method that returns the declarations of the types
  87. * {@linkplain AnnotationProcessorEnvironment <i>included</i>}
  88. * in this invocation of the annotation processing tool.
  89. *
  90. * @return the declarations of the types included in this invocation
  91. * of the tool, or an empty collection if there are none
  92. */
  93. Collection<TypeDeclaration> getTypeDeclarations();
  94. /**
  95. * Returns the declarations annotated with the given annotation type.
  96. * Only declarations of the types
  97. * {@linkplain AnnotationProcessorEnvironment <i>included</i>}
  98. * in this invocation of the annotation processing tool, or
  99. * declarations of members, parameters, or type parameters
  100. * declared within those, are returned.
  101. *
  102. * @param a annotation type being requested
  103. * @return the declarations annotated with the given annotation type,
  104. * or an empty collection if there are none
  105. */
  106. Collection<Declaration> getDeclarationsAnnotatedWith(
  107. AnnotationTypeDeclaration a);
  108. /**
  109. * Returns an implementation of some utility methods for
  110. * operating on declarations.
  111. *
  112. * @return declaration utilities
  113. */
  114. Declarations getDeclarationUtils();
  115. /**
  116. * Returns an implementation of some utility methods for
  117. * operating on types.
  118. *
  119. * @return type utilities
  120. */
  121. Types getTypeUtils();
  122. /**
  123. * Add a listener. If the listener is currently registered to listen,
  124. * adding it again will have no effect.
  125. *
  126. * @param listener The listener to add.
  127. * @throws NullPointerException if the listener is null
  128. */
  129. void addListener(AnnotationProcessorListener listener);
  130. /**
  131. * Remove a listener. If the listener is not currently listening,
  132. * the method call does nothing.
  133. *
  134. * @param listener The listener to remove.
  135. * @throws NullPointerException if the listener is null
  136. */
  137. void removeListener(AnnotationProcessorListener listener);
  138. }