Path: blob/aarch64-shenandoah-jdk8u272-b10/langtools/src/share/classes/com/sun/source/util/JavacTask.java
38899 views
/*1* Copyright (c) 2005, 2013, 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 com.sun.source.util;2627import java.io.IOException;2829import javax.annotation.processing.ProcessingEnvironment;30import javax.lang.model.element.Element;31import javax.lang.model.type.TypeMirror;32import javax.lang.model.util.Elements;33import javax.lang.model.util.Types;34import javax.tools.JavaCompiler.CompilationTask;35import javax.tools.JavaFileObject;3637import com.sun.source.tree.CompilationUnitTree;38import com.sun.source.tree.Tree;39import com.sun.tools.javac.api.BasicJavacTask;40import com.sun.tools.javac.processing.JavacProcessingEnvironment;41import com.sun.tools.javac.util.Context;4243/**44* Provides access to functionality specific to the JDK Java Compiler, javac.45*46* @author Peter von der Ahé47* @author Jonathan Gibbons48* @since 1.649*/50@jdk.Exported51public abstract class JavacTask implements CompilationTask {5253/**54* Get the {@code JavacTask} for a {@code ProcessingEnvironment}.55* If the compiler is being invoked using a56* {@link javax.tools.JavaCompiler.CompilationTask CompilationTask},57* then that task will be returned.58* @param processingEnvironment the processing environment59* @return the {@code JavacTask} for a {@code ProcessingEnvironment}60* @since 1.861*/62public static JavacTask instance(ProcessingEnvironment processingEnvironment) {63if (!processingEnvironment.getClass().getName().equals(64"com.sun.tools.javac.processing.JavacProcessingEnvironment"))65throw new IllegalArgumentException();66Context c = ((JavacProcessingEnvironment) processingEnvironment).getContext();67JavacTask t = c.get(JavacTask.class);68return (t != null) ? t : new BasicJavacTask(c, true);69}7071/**72* Parse the specified files returning a list of abstract syntax trees.73*74* @return a list of abstract syntax trees75* @throws IOException if an unhandled I/O error occurred in the compiler.76* @throws IllegalStateException if the operation cannot be performed at this time.77*/78public abstract Iterable<? extends CompilationUnitTree> parse()79throws IOException;8081/**82* Complete all analysis.83*84* @return a list of elements that were analyzed85* @throws IOException if an unhandled I/O error occurred in the compiler.86* @throws IllegalStateException if the operation cannot be performed at this time.87*/88public abstract Iterable<? extends Element> analyze() throws IOException;8990/**91* Generate code.92*93* @return a list of files that were generated94* @throws IOException if an unhandled I/O error occurred in the compiler.95* @throws IllegalStateException if the operation cannot be performed at this time.96*/97public abstract Iterable<? extends JavaFileObject> generate() throws IOException;9899/**100* The specified listener will receive notification of events101* describing the progress of this compilation task.102*103* If another listener is receiving notifications as a result of a prior104* call of this method, then that listener will no longer receive notifications.105*106* Informally, this method is equivalent to calling {@code removeTaskListener} for107* any listener that has been previously set, followed by {@code addTaskListener}108* for the new listener.109*110* @throws IllegalStateException if the specified listener has already been added.111*/112public abstract void setTaskListener(TaskListener taskListener);113114/**115* The specified listener will receive notification of events116* describing the progress of this compilation task.117*118* This method may be called at any time before or during the compilation.119*120* @throws IllegalStateException if the specified listener has already been added.121* @since 1.8122*/123public abstract void addTaskListener(TaskListener taskListener);124125/**126* The specified listener will no longer receive notification of events127* describing the progress of this compilation task.128*129* This method may be called at any time before or during the compilation.130*131* @since 1.8132*/133public abstract void removeTaskListener(TaskListener taskListener);134135/**136* Get a type mirror of the tree node determined by the specified path.137* This method has been superceded by methods on138* {@link com.sun.source.util.Trees Trees}.139* @see com.sun.source.util.Trees#getTypeMirror140*/141public abstract TypeMirror getTypeMirror(Iterable<? extends Tree> path);142143/**144* Get a utility object for dealing with program elements.145*/146public abstract Elements getElements();147148/**149* Get a utility object for dealing with type mirrors.150*/151public abstract Types getTypes();152}153154155