author | jlahoda |
Mon, 01 Apr 2019 14:46:17 +0200 | |
branch | jlahoda-tree-builder |
changeset 57298 | 72d5f7163f12 |
parent 47216 | 71c04702a3d5 |
child 54514 | b0651dcc8d98 |
permissions | -rw-r--r-- |
10 | 1 |
/* |
25287 | 2 |
* Copyright (c) 2005, 2014, Oracle and/or its affiliates. All rights reserved. |
10 | 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 |
|
5520 | 7 |
* published by the Free Software Foundation. Oracle designates this |
10 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5520 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
10 | 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 |
* |
|
5520 | 21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
10 | 24 |
*/ |
25 |
||
26 |
package com.sun.source.util; |
|
27 |
||
28 |
import java.io.IOException; |
|
12016 | 29 |
|
30 |
import javax.annotation.processing.ProcessingEnvironment; |
|
10 | 31 |
import javax.lang.model.element.Element; |
32 |
import javax.lang.model.type.TypeMirror; |
|
33 |
import javax.lang.model.util.Elements; |
|
34 |
import javax.lang.model.util.Types; |
|
35 |
import javax.tools.JavaCompiler.CompilationTask; |
|
36 |
import javax.tools.JavaFileObject; |
|
37 |
||
12016 | 38 |
import com.sun.source.tree.CompilationUnitTree; |
39 |
import com.sun.source.tree.Tree; |
|
40 |
import com.sun.tools.javac.api.BasicJavacTask; |
|
41 |
import com.sun.tools.javac.processing.JavacProcessingEnvironment; |
|
42 |
import com.sun.tools.javac.util.Context; |
|
43 |
||
10 | 44 |
/** |
5848
c5a4ce47e780
6960407: Potential rebranding issues in openjdk/langtools repository sources
jjg
parents:
5520
diff
changeset
|
45 |
* Provides access to functionality specific to the JDK Java Compiler, javac. |
10 | 46 |
* |
47 |
* @author Peter von der Ahé |
|
48 |
* @author Jonathan Gibbons |
|
49 |
* @since 1.6 |
|
50 |
*/ |
|
51 |
public abstract class JavacTask implements CompilationTask { |
|
52 |
||
53 |
/** |
|
25287 | 54 |
* Returns the {@code JavacTask} for a {@code ProcessingEnvironment}. |
12016 | 55 |
* If the compiler is being invoked using a |
56 |
* {@link javax.tools.JavaCompiler.CompilationTask CompilationTask}, |
|
57 |
* then that task will be returned. |
|
16559 | 58 |
* @param processingEnvironment the processing environment |
12016 | 59 |
* @return the {@code JavacTask} for a {@code ProcessingEnvironment} |
60 |
* @since 1.8 |
|
61 |
*/ |
|
62 |
public static JavacTask instance(ProcessingEnvironment processingEnvironment) { |
|
63 |
if (!processingEnvironment.getClass().getName().equals( |
|
64 |
"com.sun.tools.javac.processing.JavacProcessingEnvironment")) |
|
65 |
throw new IllegalArgumentException(); |
|
66 |
Context c = ((JavacProcessingEnvironment) processingEnvironment).getContext(); |
|
67 |
JavacTask t = c.get(JavacTask.class); |
|
68 |
return (t != null) ? t : new BasicJavacTask(c, true); |
|
69 |
} |
|
70 |
||
71 |
/** |
|
25287 | 72 |
* Parses the specified files returning a list of abstract syntax trees. |
10 | 73 |
* |
74 |
* @return a list of abstract syntax trees |
|
75 |
* @throws IOException if an unhandled I/O error occurred in the compiler. |
|
12016 | 76 |
* @throws IllegalStateException if the operation cannot be performed at this time. |
10 | 77 |
*/ |
78 |
public abstract Iterable<? extends CompilationUnitTree> parse() |
|
79 |
throws IOException; |
|
80 |
||
81 |
/** |
|
25287 | 82 |
* Completes all analysis. |
10 | 83 |
* |
84 |
* @return a list of elements that were analyzed |
|
85 |
* @throws IOException if an unhandled I/O error occurred in the compiler. |
|
12016 | 86 |
* @throws IllegalStateException if the operation cannot be performed at this time. |
10 | 87 |
*/ |
88 |
public abstract Iterable<? extends Element> analyze() throws IOException; |
|
89 |
||
90 |
/** |
|
25287 | 91 |
* Generates code. |
10 | 92 |
* |
93 |
* @return a list of files that were generated |
|
94 |
* @throws IOException if an unhandled I/O error occurred in the compiler. |
|
12016 | 95 |
* @throws IllegalStateException if the operation cannot be performed at this time. |
10 | 96 |
*/ |
97 |
public abstract Iterable<? extends JavaFileObject> generate() throws IOException; |
|
98 |
||
99 |
/** |
|
25287 | 100 |
* Sets a specified listener to receive notification of events |
12016 | 101 |
* describing the progress of this compilation task. |
102 |
* |
|
103 |
* If another listener is receiving notifications as a result of a prior |
|
104 |
* call of this method, then that listener will no longer receive notifications. |
|
105 |
* |
|
106 |
* Informally, this method is equivalent to calling {@code removeTaskListener} for |
|
107 |
* any listener that has been previously set, followed by {@code addTaskListener} |
|
108 |
* for the new listener. |
|
109 |
* |
|
25287 | 110 |
* @param taskListener the task listener |
12016 | 111 |
* @throws IllegalStateException if the specified listener has already been added. |
10 | 112 |
*/ |
113 |
public abstract void setTaskListener(TaskListener taskListener); |
|
114 |
||
115 |
/** |
|
25287 | 116 |
* Adds a specified listener so that it receives notification of events |
12016 | 117 |
* describing the progress of this compilation task. |
118 |
* |
|
119 |
* This method may be called at any time before or during the compilation. |
|
120 |
* |
|
25287 | 121 |
* @param taskListener the task listener |
12016 | 122 |
* @throws IllegalStateException if the specified listener has already been added. |
123 |
* @since 1.8 |
|
124 |
*/ |
|
125 |
public abstract void addTaskListener(TaskListener taskListener); |
|
126 |
||
127 |
/** |
|
25287 | 128 |
* Removes the specified listener so that it no longer receives |
129 |
* notification of events describing the progress of this |
|
130 |
* compilation task. |
|
12016 | 131 |
* |
132 |
* This method may be called at any time before or during the compilation. |
|
133 |
* |
|
25287 | 134 |
* @param taskListener the task listener |
12016 | 135 |
* @since 1.8 |
136 |
*/ |
|
137 |
public abstract void removeTaskListener(TaskListener taskListener); |
|
138 |
||
139 |
/** |
|
25287 | 140 |
* Returns a type mirror of the tree node determined by the specified path. |
12016 | 141 |
* This method has been superceded by methods on |
142 |
* {@link com.sun.source.util.Trees Trees}. |
|
26264
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
25874
diff
changeset
|
143 |
* |
25287 | 144 |
* @param path the path |
145 |
* @return the type mirror |
|
12016 | 146 |
* @see com.sun.source.util.Trees#getTypeMirror |
10 | 147 |
*/ |
148 |
public abstract TypeMirror getTypeMirror(Iterable<? extends Tree> path); |
|
14952 | 149 |
|
10 | 150 |
/** |
25287 | 151 |
* Returns a utility object for dealing with program elements. |
26264
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
25874
diff
changeset
|
152 |
* |
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
25874
diff
changeset
|
153 |
* @return a utility object for dealing with program elements |
10 | 154 |
*/ |
155 |
public abstract Elements getElements(); |
|
156 |
||
157 |
/** |
|
25287 | 158 |
* Returns a utility object for dealing with type mirrors. |
26264
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
25874
diff
changeset
|
159 |
* |
25287 | 160 |
* @return the utility object for dealing with type mirrors |
10 | 161 |
*/ |
162 |
public abstract Types getTypes(); |
|
163 |
} |