langtools/src/share/classes/com/sun/mirror/apt/AnnotationProcessorEnvironment.java
author duke
Sat, 01 Dec 2007 00:00:00 +0000
changeset 10 06bc494ca11e
child 3378 22011d9a9398
permissions -rw-r--r--
Initial load
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     1
/*
06bc494ca11e Initial load
duke
parents:
diff changeset
     2
 * Copyright 2004 Sun Microsystems, Inc.  All Rights Reserved.
06bc494ca11e Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
06bc494ca11e Initial load
duke
parents:
diff changeset
     4
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
06bc494ca11e Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
06bc494ca11e Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Sun designates this
06bc494ca11e Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
06bc494ca11e Initial load
duke
parents:
diff changeset
     9
 * by Sun in the LICENSE file that accompanied this code.
06bc494ca11e Initial load
duke
parents:
diff changeset
    10
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
06bc494ca11e Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
06bc494ca11e Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
06bc494ca11e Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
06bc494ca11e Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
06bc494ca11e Initial load
duke
parents:
diff changeset
    16
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
06bc494ca11e Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
06bc494ca11e Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
06bc494ca11e Initial load
duke
parents:
diff changeset
    20
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    21
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
06bc494ca11e Initial load
duke
parents:
diff changeset
    22
 * CA 95054 USA or visit www.sun.com if you need additional information or
06bc494ca11e Initial load
duke
parents:
diff changeset
    23
 * have any questions.
06bc494ca11e Initial load
duke
parents:
diff changeset
    24
 */
06bc494ca11e Initial load
duke
parents:
diff changeset
    25
06bc494ca11e Initial load
duke
parents:
diff changeset
    26
package com.sun.mirror.apt;
06bc494ca11e Initial load
duke
parents:
diff changeset
    27
06bc494ca11e Initial load
duke
parents:
diff changeset
    28
06bc494ca11e Initial load
duke
parents:
diff changeset
    29
import java.util.Collection;
06bc494ca11e Initial load
duke
parents:
diff changeset
    30
import java.util.Map;
06bc494ca11e Initial load
duke
parents:
diff changeset
    31
06bc494ca11e Initial load
duke
parents:
diff changeset
    32
import com.sun.mirror.declaration.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    33
import com.sun.mirror.util.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    34
06bc494ca11e Initial load
duke
parents:
diff changeset
    35
06bc494ca11e Initial load
duke
parents:
diff changeset
    36
/**
06bc494ca11e Initial load
duke
parents:
diff changeset
    37
 * The environment encapsulating the state needed by an annotation processor.
06bc494ca11e Initial load
duke
parents:
diff changeset
    38
 * An annotation processing tool makes this environment available
06bc494ca11e Initial load
duke
parents:
diff changeset
    39
 * to all annotation processors.
06bc494ca11e Initial load
duke
parents:
diff changeset
    40
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    41
 * <p> When an annotation processing tool is invoked, it is given a
06bc494ca11e Initial load
duke
parents:
diff changeset
    42
 * set of type declarations on which to operate.  These
06bc494ca11e Initial load
duke
parents:
diff changeset
    43
 * are refered to as the <i>specified</i> types.
06bc494ca11e Initial load
duke
parents:
diff changeset
    44
 * The type declarations said to be <i>included</i> in this invocation
06bc494ca11e Initial load
duke
parents:
diff changeset
    45
 * consist of the specified types and any types nested within them.
06bc494ca11e Initial load
duke
parents:
diff changeset
    46
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    47
 * <p> {@link DeclarationFilter}
06bc494ca11e Initial load
duke
parents:
diff changeset
    48
 * provides a simple way to select just the items of interest
06bc494ca11e Initial load
duke
parents:
diff changeset
    49
 * when a method returns a collection of declarations.
06bc494ca11e Initial load
duke
parents:
diff changeset
    50
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    51
 * @author Joseph D. Darcy
06bc494ca11e Initial load
duke
parents:
diff changeset
    52
 * @author Scott Seligman
06bc494ca11e Initial load
duke
parents:
diff changeset
    53
 * @since 1.5
06bc494ca11e Initial load
duke
parents:
diff changeset
    54
 */
06bc494ca11e Initial load
duke
parents:
diff changeset
    55
06bc494ca11e Initial load
duke
parents:
diff changeset
    56
public interface AnnotationProcessorEnvironment {
06bc494ca11e Initial load
duke
parents:
diff changeset
    57
06bc494ca11e Initial load
duke
parents:
diff changeset
    58
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    59
     * Returns the options passed to the annotation processing tool.
06bc494ca11e Initial load
duke
parents:
diff changeset
    60
     * Options are returned in the form of a map from option name
06bc494ca11e Initial load
duke
parents:
diff changeset
    61
     * (such as <tt>"-encoding"</tt>) to option value.
06bc494ca11e Initial load
duke
parents:
diff changeset
    62
     * For an option with no value (such as <tt>"-help"</tt>), the
06bc494ca11e Initial load
duke
parents:
diff changeset
    63
     * corresponding value in the map is <tt>null</tt>.
06bc494ca11e Initial load
duke
parents:
diff changeset
    64
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
    65
     * <p> Options beginning with <tt>"-A"</tt> are <i>processor-specific.</i>
06bc494ca11e Initial load
duke
parents:
diff changeset
    66
     * Such options are unrecognized by the tool, but intended to be used by
06bc494ca11e Initial load
duke
parents:
diff changeset
    67
     * some annotation processor.
06bc494ca11e Initial load
duke
parents:
diff changeset
    68
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
    69
     * @return the options passed to the tool
06bc494ca11e Initial load
duke
parents:
diff changeset
    70
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    71
    Map<String,String> getOptions();
06bc494ca11e Initial load
duke
parents:
diff changeset
    72
06bc494ca11e Initial load
duke
parents:
diff changeset
    73
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    74
     * Returns the messager used to report errors, warnings, and other
06bc494ca11e Initial load
duke
parents:
diff changeset
    75
     * notices.
06bc494ca11e Initial load
duke
parents:
diff changeset
    76
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
    77
     * @return the messager
06bc494ca11e Initial load
duke
parents:
diff changeset
    78
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    79
    Messager getMessager();
06bc494ca11e Initial load
duke
parents:
diff changeset
    80
06bc494ca11e Initial load
duke
parents:
diff changeset
    81
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    82
     * Returns the filer used to create new source, class, or auxiliary
06bc494ca11e Initial load
duke
parents:
diff changeset
    83
     * files.
06bc494ca11e Initial load
duke
parents:
diff changeset
    84
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
    85
     * @return the filer
06bc494ca11e Initial load
duke
parents:
diff changeset
    86
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    87
    Filer getFiler();
06bc494ca11e Initial load
duke
parents:
diff changeset
    88
06bc494ca11e Initial load
duke
parents:
diff changeset
    89
06bc494ca11e Initial load
duke
parents:
diff changeset
    90
06bc494ca11e Initial load
duke
parents:
diff changeset
    91
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    92
     * Returns the declarations of the types specified when the
06bc494ca11e Initial load
duke
parents:
diff changeset
    93
     * annotation processing tool was invoked.
06bc494ca11e Initial load
duke
parents:
diff changeset
    94
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
    95
     * @return the types specified when the tool was invoked, or an
06bc494ca11e Initial load
duke
parents:
diff changeset
    96
     * empty collection if there were none
06bc494ca11e Initial load
duke
parents:
diff changeset
    97
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    98
    Collection<TypeDeclaration> getSpecifiedTypeDeclarations();
06bc494ca11e Initial load
duke
parents:
diff changeset
    99
06bc494ca11e Initial load
duke
parents:
diff changeset
   100
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   101
     * Returns the declaration of a package given its fully qualified name.
06bc494ca11e Initial load
duke
parents:
diff changeset
   102
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   103
     * @param name  fully qualified package name, or "" for the unnamed package
06bc494ca11e Initial load
duke
parents:
diff changeset
   104
     * @return the declaration of the named package, or null if it cannot
06bc494ca11e Initial load
duke
parents:
diff changeset
   105
     * be found
06bc494ca11e Initial load
duke
parents:
diff changeset
   106
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   107
    PackageDeclaration getPackage(String name);
06bc494ca11e Initial load
duke
parents:
diff changeset
   108
06bc494ca11e Initial load
duke
parents:
diff changeset
   109
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   110
     * Returns the declaration of a type given its fully qualified name.
06bc494ca11e Initial load
duke
parents:
diff changeset
   111
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   112
     * @param name  fully qualified type name
06bc494ca11e Initial load
duke
parents:
diff changeset
   113
     * @return the declaration of the named type, or null if it cannot be
06bc494ca11e Initial load
duke
parents:
diff changeset
   114
     * found
06bc494ca11e Initial load
duke
parents:
diff changeset
   115
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   116
    TypeDeclaration getTypeDeclaration(String name);
06bc494ca11e Initial load
duke
parents:
diff changeset
   117
06bc494ca11e Initial load
duke
parents:
diff changeset
   118
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   119
     * A convenience method that returns the declarations of the types
06bc494ca11e Initial load
duke
parents:
diff changeset
   120
     * {@linkplain AnnotationProcessorEnvironment <i>included</i>}
06bc494ca11e Initial load
duke
parents:
diff changeset
   121
     * in this invocation of the annotation processing tool.
06bc494ca11e Initial load
duke
parents:
diff changeset
   122
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   123
     * @return the declarations of the types included in this invocation
06bc494ca11e Initial load
duke
parents:
diff changeset
   124
     * of the tool, or an empty collection if there are none
06bc494ca11e Initial load
duke
parents:
diff changeset
   125
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   126
    Collection<TypeDeclaration> getTypeDeclarations();
06bc494ca11e Initial load
duke
parents:
diff changeset
   127
06bc494ca11e Initial load
duke
parents:
diff changeset
   128
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   129
     * Returns the declarations annotated with the given annotation type.
06bc494ca11e Initial load
duke
parents:
diff changeset
   130
     * Only declarations of the types
06bc494ca11e Initial load
duke
parents:
diff changeset
   131
     * {@linkplain AnnotationProcessorEnvironment <i>included</i>}
06bc494ca11e Initial load
duke
parents:
diff changeset
   132
     * in this invocation of the annotation processing tool, or
06bc494ca11e Initial load
duke
parents:
diff changeset
   133
     * declarations of members, parameters, or type parameters
06bc494ca11e Initial load
duke
parents:
diff changeset
   134
     * declared within those, are returned.
06bc494ca11e Initial load
duke
parents:
diff changeset
   135
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   136
     * @param a  annotation type being requested
06bc494ca11e Initial load
duke
parents:
diff changeset
   137
     * @return the declarations annotated with the given annotation type,
06bc494ca11e Initial load
duke
parents:
diff changeset
   138
     * or an empty collection if there are none
06bc494ca11e Initial load
duke
parents:
diff changeset
   139
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   140
    Collection<Declaration> getDeclarationsAnnotatedWith(
06bc494ca11e Initial load
duke
parents:
diff changeset
   141
                                                AnnotationTypeDeclaration a);
06bc494ca11e Initial load
duke
parents:
diff changeset
   142
06bc494ca11e Initial load
duke
parents:
diff changeset
   143
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   144
     * Returns an implementation of some utility methods for
06bc494ca11e Initial load
duke
parents:
diff changeset
   145
     * operating on declarations.
06bc494ca11e Initial load
duke
parents:
diff changeset
   146
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   147
     * @return declaration utilities
06bc494ca11e Initial load
duke
parents:
diff changeset
   148
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   149
    Declarations getDeclarationUtils();
06bc494ca11e Initial load
duke
parents:
diff changeset
   150
06bc494ca11e Initial load
duke
parents:
diff changeset
   151
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   152
     * Returns an implementation of some utility methods for
06bc494ca11e Initial load
duke
parents:
diff changeset
   153
     * operating on types.
06bc494ca11e Initial load
duke
parents:
diff changeset
   154
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   155
     * @return type utilities
06bc494ca11e Initial load
duke
parents:
diff changeset
   156
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   157
    Types getTypeUtils();
06bc494ca11e Initial load
duke
parents:
diff changeset
   158
06bc494ca11e Initial load
duke
parents:
diff changeset
   159
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   160
     * Add a listener.  If the listener is currently registered to listen,
06bc494ca11e Initial load
duke
parents:
diff changeset
   161
     * adding it again will have no effect.
06bc494ca11e Initial load
duke
parents:
diff changeset
   162
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   163
     * @param listener The listener to add.
06bc494ca11e Initial load
duke
parents:
diff changeset
   164
     * @throws NullPointerException if the listener is null
06bc494ca11e Initial load
duke
parents:
diff changeset
   165
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   166
    void addListener(AnnotationProcessorListener listener);
06bc494ca11e Initial load
duke
parents:
diff changeset
   167
06bc494ca11e Initial load
duke
parents:
diff changeset
   168
06bc494ca11e Initial load
duke
parents:
diff changeset
   169
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   170
     * Remove a listener.  If the listener is not currently listening,
06bc494ca11e Initial load
duke
parents:
diff changeset
   171
     * the method call does nothing.
06bc494ca11e Initial load
duke
parents:
diff changeset
   172
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   173
     * @param listener The listener to remove.
06bc494ca11e Initial load
duke
parents:
diff changeset
   174
     * @throws NullPointerException if the listener is null
06bc494ca11e Initial load
duke
parents:
diff changeset
   175
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   176
    void removeListener(AnnotationProcessorListener listener);
06bc494ca11e Initial load
duke
parents:
diff changeset
   177
}