1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/share/classes/com/sun/source/util/JavacTask.java Wed Apr 27 01:34:52 2016 +0800 1.3 @@ -0,0 +1,153 @@ 1.4 +/* 1.5 + * Copyright (c) 2005, 2013, Oracle and/or its affiliates. All rights reserved. 1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.7 + * 1.8 + * This code is free software; you can redistribute it and/or modify it 1.9 + * under the terms of the GNU General Public License version 2 only, as 1.10 + * published by the Free Software Foundation. Oracle designates this 1.11 + * particular file as subject to the "Classpath" exception as provided 1.12 + * by Oracle in the LICENSE file that accompanied this code. 1.13 + * 1.14 + * This code is distributed in the hope that it will be useful, but WITHOUT 1.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1.17 + * version 2 for more details (a copy is included in the LICENSE file that 1.18 + * accompanied this code). 1.19 + * 1.20 + * You should have received a copy of the GNU General Public License version 1.21 + * 2 along with this work; if not, write to the Free Software Foundation, 1.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1.23 + * 1.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 1.25 + * or visit www.oracle.com if you need additional information or have any 1.26 + * questions. 1.27 + */ 1.28 + 1.29 +package com.sun.source.util; 1.30 + 1.31 +import java.io.IOException; 1.32 + 1.33 +import javax.annotation.processing.ProcessingEnvironment; 1.34 +import javax.lang.model.element.Element; 1.35 +import javax.lang.model.type.TypeMirror; 1.36 +import javax.lang.model.util.Elements; 1.37 +import javax.lang.model.util.Types; 1.38 +import javax.tools.JavaCompiler.CompilationTask; 1.39 +import javax.tools.JavaFileObject; 1.40 + 1.41 +import com.sun.source.tree.CompilationUnitTree; 1.42 +import com.sun.source.tree.Tree; 1.43 +import com.sun.tools.javac.api.BasicJavacTask; 1.44 +import com.sun.tools.javac.processing.JavacProcessingEnvironment; 1.45 +import com.sun.tools.javac.util.Context; 1.46 + 1.47 +/** 1.48 + * Provides access to functionality specific to the JDK Java Compiler, javac. 1.49 + * 1.50 + * @author Peter von der Ahé 1.51 + * @author Jonathan Gibbons 1.52 + * @since 1.6 1.53 + */ 1.54 +@jdk.Exported 1.55 +public abstract class JavacTask implements CompilationTask { 1.56 + 1.57 + /** 1.58 + * Get the {@code JavacTask} for a {@code ProcessingEnvironment}. 1.59 + * If the compiler is being invoked using a 1.60 + * {@link javax.tools.JavaCompiler.CompilationTask CompilationTask}, 1.61 + * then that task will be returned. 1.62 + * @param processingEnvironment the processing environment 1.63 + * @return the {@code JavacTask} for a {@code ProcessingEnvironment} 1.64 + * @since 1.8 1.65 + */ 1.66 + public static JavacTask instance(ProcessingEnvironment processingEnvironment) { 1.67 + if (!processingEnvironment.getClass().getName().equals( 1.68 + "com.sun.tools.javac.processing.JavacProcessingEnvironment")) 1.69 + throw new IllegalArgumentException(); 1.70 + Context c = ((JavacProcessingEnvironment) processingEnvironment).getContext(); 1.71 + JavacTask t = c.get(JavacTask.class); 1.72 + return (t != null) ? t : new BasicJavacTask(c, true); 1.73 + } 1.74 + 1.75 + /** 1.76 + * Parse the specified files returning a list of abstract syntax trees. 1.77 + * 1.78 + * @return a list of abstract syntax trees 1.79 + * @throws IOException if an unhandled I/O error occurred in the compiler. 1.80 + * @throws IllegalStateException if the operation cannot be performed at this time. 1.81 + */ 1.82 + public abstract Iterable<? extends CompilationUnitTree> parse() 1.83 + throws IOException; 1.84 + 1.85 + /** 1.86 + * Complete all analysis. 1.87 + * 1.88 + * @return a list of elements that were analyzed 1.89 + * @throws IOException if an unhandled I/O error occurred in the compiler. 1.90 + * @throws IllegalStateException if the operation cannot be performed at this time. 1.91 + */ 1.92 + public abstract Iterable<? extends Element> analyze() throws IOException; 1.93 + 1.94 + /** 1.95 + * Generate code. 1.96 + * 1.97 + * @return a list of files that were generated 1.98 + * @throws IOException if an unhandled I/O error occurred in the compiler. 1.99 + * @throws IllegalStateException if the operation cannot be performed at this time. 1.100 + */ 1.101 + public abstract Iterable<? extends JavaFileObject> generate() throws IOException; 1.102 + 1.103 + /** 1.104 + * The specified listener will receive notification of events 1.105 + * describing the progress of this compilation task. 1.106 + * 1.107 + * If another listener is receiving notifications as a result of a prior 1.108 + * call of this method, then that listener will no longer receive notifications. 1.109 + * 1.110 + * Informally, this method is equivalent to calling {@code removeTaskListener} for 1.111 + * any listener that has been previously set, followed by {@code addTaskListener} 1.112 + * for the new listener. 1.113 + * 1.114 + * @throws IllegalStateException if the specified listener has already been added. 1.115 + */ 1.116 + public abstract void setTaskListener(TaskListener taskListener); 1.117 + 1.118 + /** 1.119 + * The specified listener will receive notification of events 1.120 + * describing the progress of this compilation task. 1.121 + * 1.122 + * This method may be called at any time before or during the compilation. 1.123 + * 1.124 + * @throws IllegalStateException if the specified listener has already been added. 1.125 + * @since 1.8 1.126 + */ 1.127 + public abstract void addTaskListener(TaskListener taskListener); 1.128 + 1.129 + /** 1.130 + * The specified listener will no longer receive notification of events 1.131 + * describing the progress of this compilation task. 1.132 + * 1.133 + * This method may be called at any time before or during the compilation. 1.134 + * 1.135 + * @since 1.8 1.136 + */ 1.137 + public abstract void removeTaskListener(TaskListener taskListener); 1.138 + 1.139 + /** 1.140 + * Get a type mirror of the tree node determined by the specified path. 1.141 + * This method has been superceded by methods on 1.142 + * {@link com.sun.source.util.Trees Trees}. 1.143 + * @see com.sun.source.util.Trees#getTypeMirror 1.144 + */ 1.145 + public abstract TypeMirror getTypeMirror(Iterable<? extends Tree> path); 1.146 + 1.147 + /** 1.148 + * Get a utility object for dealing with program elements. 1.149 + */ 1.150 + public abstract Elements getElements(); 1.151 + 1.152 + /** 1.153 + * Get a utility object for dealing with type mirrors. 1.154 + */ 1.155 + public abstract Types getTypes(); 1.156 +}