Path: blob/master/src/java.compiler/share/classes/javax/annotation/processing/ProcessingEnvironment.java
41159 views
/*1* Copyright (c) 2005, 2020, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package javax.annotation.processing;2627import java.util.Map;28import java.util.Locale;29import javax.lang.model.SourceVersion;30import javax.lang.model.util.Elements;31import javax.lang.model.util.Types;3233/**34* An annotation processing tool framework will {@linkplain35* Processor#init provide an annotation processor with an object36* implementing this interface} so the processor can use facilities37* provided by the framework to write new files, report error38* messages, and find other utilities.39*40* <p>Third parties may wish to provide value-add wrappers around the41* facility objects from this interface, for example a {@code Filer}42* extension that allows multiple processors to coordinate writing out43* a single source file. To enable this, for processors running in a44* context where their side effects via the API could be visible to45* each other, the tool infrastructure must provide corresponding46* facility objects that are {@code .equals}, {@code Filer}s that are47* {@code .equals}, and so on. In addition, the tool invocation must48* be able to be configured such that from the perspective of the49* running annotation processors, at least the chosen subset of helper50* classes are viewed as being loaded by the same class loader.51* (Since the facility objects manage shared state, the implementation52* of a wrapper class must know whether or not the same base facility53* object has been wrapped before.)54*55* @author Joseph D. Darcy56* @author Scott Seligman57* @author Peter von der Ahé58* @since 1.659*/60public interface ProcessingEnvironment {61/**62* {@return the processor-specific options passed to the annotation63* processing tool} Options are returned in the form of a map from64* option name to option value. For an option with no value, the65* corresponding value in the map is {@code null}.66*67* <p>See documentation of the particular tool infrastructure68* being used for details on how to pass in processor-specific69* options. For example, a command-line implementation may70* distinguish processor-specific options by prefixing them with a71* known string like {@code "-A"}; other tool implementations may72* follow different conventions or provide alternative mechanisms.73* A given implementation may also provide implementation-specific74* ways of finding options passed to the tool in addition to the75* processor-specific options.76*/77Map<String,String> getOptions();7879/**80* {@return the messager used to report errors, warnings, and other81* notices}82*/83Messager getMessager();8485/**86* {@return the filer used to create new source, class, or auxiliary87* files}88*/89Filer getFiler();9091/**92* {@return an implementation of some utility methods for93* operating on elements}94*/95Elements getElementUtils();9697/**98* {@return an implementation of some utility methods for99* operating on types}100*/101Types getTypeUtils();102103/**104* {@return the source version that any generated {@linkplain105* Filer#createSourceFile source} and {@linkplain106* Filer#createClassFile class} files should conform to}107*108* @see Processor#getSupportedSourceVersion109*/110SourceVersion getSourceVersion();111112/**113* {@return the current locale or {@code null} if no locale is in114* effect} The locale can be be used to provide localized115* {@linkplain Messager messages}.116*/117Locale getLocale();118119/**120* Returns {@code true} if <em>preview features</em> are enabled121* and {@code false} otherwise.122* @return whether or not preview features are enabled123*124* @implSpec The default implementation of this method returns125* {@code false}.126*127* @since 13128*/129default boolean isPreviewEnabled() {130return false;131}132}133134135