src/share/classes/com/sun/source/util/JavacTask.java

Tue, 28 Feb 2012 10:33:49 -0800

author
jjg
date
Tue, 28 Feb 2012 10:33:49 -0800
changeset 1210
62e611704863
parent 582
366a7b9b5627
child 1455
75ab654b5cd5
permissions
-rw-r--r--

7093891: support multiple task listeners
Reviewed-by: darcy, mcimadamore

duke@1 1 /*
jjg@1210 2 * Copyright (c) 2005, 2012, Oracle and/or its affiliates. All rights reserved.
duke@1 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@1 4 *
duke@1 5 * This code is free software; you can redistribute it and/or modify it
duke@1 6 * under the terms of the GNU General Public License version 2 only, as
ohair@554 7 * published by the Free Software Foundation. Oracle designates this
duke@1 8 * particular file as subject to the "Classpath" exception as provided
ohair@554 9 * by Oracle in the LICENSE file that accompanied this code.
duke@1 10 *
duke@1 11 * This code is distributed in the hope that it will be useful, but WITHOUT
duke@1 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@1 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@1 14 * version 2 for more details (a copy is included in the LICENSE file that
duke@1 15 * accompanied this code).
duke@1 16 *
duke@1 17 * You should have received a copy of the GNU General Public License version
duke@1 18 * 2 along with this work; if not, write to the Free Software Foundation,
duke@1 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@1 20 *
ohair@554 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
ohair@554 22 * or visit www.oracle.com if you need additional information or have any
ohair@554 23 * questions.
duke@1 24 */
duke@1 25
duke@1 26 package com.sun.source.util;
duke@1 27
duke@1 28 import java.io.IOException;
jjg@1210 29
jjg@1210 30 import javax.annotation.processing.ProcessingEnvironment;
duke@1 31 import javax.lang.model.element.Element;
duke@1 32 import javax.lang.model.type.TypeMirror;
duke@1 33 import javax.lang.model.util.Elements;
duke@1 34 import javax.lang.model.util.Types;
duke@1 35 import javax.tools.JavaCompiler.CompilationTask;
duke@1 36 import javax.tools.JavaFileObject;
duke@1 37
jjg@1210 38 import com.sun.source.tree.CompilationUnitTree;
jjg@1210 39 import com.sun.source.tree.Tree;
jjg@1210 40 import com.sun.tools.javac.api.BasicJavacTask;
jjg@1210 41 import com.sun.tools.javac.processing.JavacProcessingEnvironment;
jjg@1210 42 import com.sun.tools.javac.util.Context;
jjg@1210 43
duke@1 44 /**
jjg@582 45 * Provides access to functionality specific to the JDK Java Compiler, javac.
duke@1 46 *
duke@1 47 * @author Peter von der Ahé
duke@1 48 * @author Jonathan Gibbons
duke@1 49 * @since 1.6
duke@1 50 */
duke@1 51 public abstract class JavacTask implements CompilationTask {
duke@1 52
duke@1 53 /**
jjg@1210 54 * Get the {@code JavacTask} for a {@code ProcessingEnvironment}.
jjg@1210 55 * If the compiler is being invoked using a
jjg@1210 56 * {@link javax.tools.JavaCompiler.CompilationTask CompilationTask},
jjg@1210 57 * then that task will be returned.
jjg@1210 58 * @param processingEnvironment
jjg@1210 59 * @return the {@code JavacTask} for a {@code ProcessingEnvironment}
jjg@1210 60 * @since 1.8
jjg@1210 61 */
jjg@1210 62 public static JavacTask instance(ProcessingEnvironment processingEnvironment) {
jjg@1210 63 if (!processingEnvironment.getClass().getName().equals(
jjg@1210 64 "com.sun.tools.javac.processing.JavacProcessingEnvironment"))
jjg@1210 65 throw new IllegalArgumentException();
jjg@1210 66 Context c = ((JavacProcessingEnvironment) processingEnvironment).getContext();
jjg@1210 67 JavacTask t = c.get(JavacTask.class);
jjg@1210 68 return (t != null) ? t : new BasicJavacTask(c, true);
jjg@1210 69 }
jjg@1210 70
jjg@1210 71 /**
duke@1 72 * Parse the specified files returning a list of abstract syntax trees.
duke@1 73 *
duke@1 74 * @return a list of abstract syntax trees
duke@1 75 * @throws IOException if an unhandled I/O error occurred in the compiler.
jjg@1210 76 * @throws IllegalStateException if the operation cannot be performed at this time.
duke@1 77 */
duke@1 78 public abstract Iterable<? extends CompilationUnitTree> parse()
duke@1 79 throws IOException;
duke@1 80
duke@1 81 /**
duke@1 82 * Complete all analysis.
duke@1 83 *
duke@1 84 * @return a list of elements that were analyzed
duke@1 85 * @throws IOException if an unhandled I/O error occurred in the compiler.
jjg@1210 86 * @throws IllegalStateException if the operation cannot be performed at this time.
duke@1 87 */
duke@1 88 public abstract Iterable<? extends Element> analyze() throws IOException;
duke@1 89
duke@1 90 /**
duke@1 91 * Generate code.
duke@1 92 *
duke@1 93 * @return a list of files that were generated
duke@1 94 * @throws IOException if an unhandled I/O error occurred in the compiler.
jjg@1210 95 * @throws IllegalStateException if the operation cannot be performed at this time.
duke@1 96 */
duke@1 97 public abstract Iterable<? extends JavaFileObject> generate() throws IOException;
duke@1 98
duke@1 99 /**
jjg@1210 100 * The specified listener will receive notification of events
jjg@1210 101 * describing the progress of this compilation task.
jjg@1210 102 *
jjg@1210 103 * If another listener is receiving notifications as a result of a prior
jjg@1210 104 * call of this method, then that listener will no longer receive notifications.
jjg@1210 105 *
jjg@1210 106 * Informally, this method is equivalent to calling {@code removeTaskListener} for
jjg@1210 107 * any listener that has been previously set, followed by {@code addTaskListener}
jjg@1210 108 * for the new listener.
jjg@1210 109 *
jjg@1210 110 * @throws IllegalStateException if the specified listener has already been added.
duke@1 111 */
duke@1 112 public abstract void setTaskListener(TaskListener taskListener);
duke@1 113
duke@1 114 /**
jjg@1210 115 * The specified listener will receive notification of events
jjg@1210 116 * describing the progress of this compilation task.
jjg@1210 117 *
jjg@1210 118 * This method may be called at any time before or during the compilation.
jjg@1210 119 *
jjg@1210 120 * @throws IllegalStateException if the specified listener has already been added.
jjg@1210 121 * @since 1.8
jjg@1210 122 */
jjg@1210 123 public abstract void addTaskListener(TaskListener taskListener);
jjg@1210 124
jjg@1210 125 /**
jjg@1210 126 * The specified listener will no longer receive notification of events
jjg@1210 127 * describing the progress of this compilation task.
jjg@1210 128 *
jjg@1210 129 * This method may be called at any time before or during the compilation.
jjg@1210 130 *
jjg@1210 131 * @since 1.8
jjg@1210 132 */
jjg@1210 133 public abstract void removeTaskListener(TaskListener taskListener);
jjg@1210 134
jjg@1210 135 /**
duke@1 136 * Get a type mirror of the tree node determined by the specified path.
jjg@1210 137 * This method has been superceded by methods on
jjg@1210 138 * {@link com.sun.source.util.Trees Trees}.
jjg@1210 139 * @see com.sun.source.util.Trees#getTypeMirror
duke@1 140 */
duke@1 141 public abstract TypeMirror getTypeMirror(Iterable<? extends Tree> path);
duke@1 142 /**
duke@1 143 * Get a utility object for dealing with program elements.
duke@1 144 */
duke@1 145 public abstract Elements getElements();
duke@1 146
duke@1 147 /**
duke@1 148 * Get a utility object for dealing with type mirrors.
duke@1 149 */
duke@1 150 public abstract Types getTypes();
duke@1 151 }

mercurial