1 /*
   2  * Copyright 2004 Sun Microsystems, Inc.  All Rights Reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   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
   7  * published by the Free Software Foundation.  Sun designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Sun in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
  22  * CA 95054 USA or visit www.sun.com if you need additional information or
  23  * have any questions.
  24  */
  25 
  26 package com.sun.mirror.apt;
  27 
  28 
  29 import java.util.Collection;
  30 import java.util.Set;
  31 
  32 import com.sun.mirror.declaration.AnnotationTypeDeclaration;
  33 
  34 
  35 /**
  36  * A factory for creating annotation processors.
  37  * Each factory is responsible for creating processors for one or more
  38  * annotation types.
  39  * The factory is said to <i>support</i> these types.
  40  *
  41  * <p> Each implementation of an <tt>AnnotationProcessorFactory</tt>
  42  * must provide a public no-argument constructor to be used by tools to
  43  * instantiate the factory.
  44  *
  45  * @author Joseph D. Darcy
  46  * @author Scott Seligman
  47  * @since 1.5
  48  */
  49 
  50 public interface AnnotationProcessorFactory {
  51 
  52     /**
  53      * Returns the options recognized by this factory or by any of the
  54      * processors it may create.
  55      * Only {@linkplain AnnotationProcessorEnvironment#getOptions()
  56      * processor-specific} options are included, each of which begins
  57      * with <tt>"-A"</tt>.  For example, if this factory recognizes
  58      * options such as <tt>-Adebug -Aloglevel=3</tt>, it will
  59      * return the strings <tt>"-Adebug"</tt> and <tt>"-Aloglevel"</tt>.
  60      *
  61      * <p> A tool might use this information to determine if any
  62      * options provided by a user are unrecognized by any processor,
  63      * in which case it may wish to report an error.
  64      *
  65      * @return the options recognized by this factory or by any of the
  66      * processors it may create, or an empty collection if none
  67      */
  68     Collection<String> supportedOptions();
  69 
  70     /**
  71      * Returns the names of the annotation types supported by this factory.
  72      * An element of the result may be the canonical (fully qualified) name
  73      * of a supported annotation type.  Alternately it may be of the form
  74      * <tt>"<i>name</i>.*"</tt>
  75      * representing the set of all annotation types
  76      * with canonical names beginning with <tt>"<i>name</i>."</tt>
  77      * Finally, <tt>"*"</tt> by itself represents the set of all
  78      * annotation types.
  79      *
  80      * @return the names of the annotation types supported by this factory
  81      */
  82     Collection<String> supportedAnnotationTypes();
  83 
  84     /**
  85      * Returns an annotation processor for a set of annotation
  86      * types. The set will be empty if the factory supports
  87      * &quot;<tt>*</tt>&quot; and the specified type declarations have
  88      * no annotations.  Note that the set of annotation types may be
  89      * empty for other reasons, such as giving the factory an
  90      * opportunity to register a listener.  An
  91      * <tt>AnnotationProcessorFactory</tt> must gracefully handle an
  92      * empty set of annotations; an appropriate response to an empty
  93      * set will often be returning {@link AnnotationProcessors#NO_OP}.
  94      *
  95      * @param atds type declarations of the annotation types to be processed
  96      * @param env  environment to use during processing
  97      * @return an annotation processor for the given annotation types,
  98      *          or <tt>null</tt> if the types are not supported or the
  99      *          processor cannot be created
 100      */
 101     AnnotationProcessor getProcessorFor(Set<AnnotationTypeDeclaration> atds,
 102                                         AnnotationProcessorEnvironment env);
 103 }