Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/src/jdk.compiler/share/classes/com/sun/source/util/JavacTask.java
41175 views
1
/*
2
* Copyright (c) 2005, 2020, Oracle and/or its affiliates. All rights reserved.
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
7
* published by the Free Software Foundation. Oracle designates this
8
* particular file as subject to the "Classpath" exception as provided
9
* by Oracle in the LICENSE file that accompanied this code.
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
*
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.
24
*/
25
26
package com.sun.source.util;
27
28
import java.io.IOException;
29
30
import javax.annotation.processing.ProcessingEnvironment;
31
import javax.lang.model.element.Element;
32
import javax.lang.model.element.VariableElement;
33
import javax.lang.model.type.TypeMirror;
34
import javax.lang.model.util.Elements;
35
import javax.lang.model.util.Types;
36
import javax.tools.JavaCompiler.CompilationTask;
37
import javax.tools.JavaFileObject;
38
39
import com.sun.source.tree.CompilationUnitTree;
40
import com.sun.source.tree.Tree;
41
import com.sun.tools.javac.api.BasicJavacTask;
42
import com.sun.tools.javac.processing.JavacProcessingEnvironment;
43
import com.sun.tools.javac.util.Context;
44
45
/**
46
* Provides access to functionality specific to the JDK Java Compiler, javac.
47
*
48
* @author Peter von der Ahé
49
* @author Jonathan Gibbons
50
* @since 1.6
51
*/
52
public abstract class JavacTask implements CompilationTask {
53
/**
54
* Constructor for subclasses to call.
55
*/
56
public JavacTask() {}
57
58
/**
59
* Returns the {@code JavacTask} for a {@code ProcessingEnvironment}.
60
* If the compiler is being invoked using a
61
* {@link javax.tools.JavaCompiler.CompilationTask CompilationTask},
62
* then that task will be returned.
63
* @param processingEnvironment the processing environment
64
* @return the {@code JavacTask} for a {@code ProcessingEnvironment}
65
* @since 1.8
66
*/
67
public static JavacTask instance(ProcessingEnvironment processingEnvironment) {
68
if (!processingEnvironment.getClass().getName().equals(
69
"com.sun.tools.javac.processing.JavacProcessingEnvironment"))
70
throw new IllegalArgumentException();
71
Context c = ((JavacProcessingEnvironment) processingEnvironment).getContext();
72
JavacTask t = c.get(JavacTask.class);
73
return (t != null) ? t : new BasicJavacTask(c, true);
74
}
75
76
/**
77
* Parses the specified files returning a list of abstract syntax trees.
78
*
79
* @return a list of abstract syntax trees
80
* @throws IOException if an unhandled I/O error occurred in the compiler.
81
* @throws IllegalStateException if the operation cannot be performed at this time.
82
*/
83
public abstract Iterable<? extends CompilationUnitTree> parse()
84
throws IOException;
85
86
/**
87
* Completes all analysis.
88
*
89
* @return a list of elements that were analyzed
90
* @throws IOException if an unhandled I/O error occurred in the compiler.
91
* @throws IllegalStateException if the operation cannot be performed at this time.
92
*/
93
public abstract Iterable<? extends Element> analyze() throws IOException;
94
95
/**
96
* Generates code.
97
*
98
* @return a list of files that were generated
99
* @throws IOException if an unhandled I/O error occurred in the compiler.
100
* @throws IllegalStateException if the operation cannot be performed at this time.
101
*/
102
public abstract Iterable<? extends JavaFileObject> generate() throws IOException;
103
104
/**
105
* Sets a specified listener to receive notification of events
106
* describing the progress of this compilation task.
107
*
108
* If another listener is receiving notifications as a result of a prior
109
* call of this method, then that listener will no longer receive notifications.
110
*
111
* Informally, this method is equivalent to calling {@code removeTaskListener} for
112
* any listener that has been previously set, followed by {@code addTaskListener}
113
* for the new listener.
114
*
115
* @param taskListener the task listener
116
* @throws IllegalStateException if the specified listener has already been added.
117
*/
118
public abstract void setTaskListener(TaskListener taskListener);
119
120
/**
121
* Adds a specified listener so that it receives notification of events
122
* describing the progress of this compilation task.
123
*
124
* This method may be called at any time before or during the compilation.
125
*
126
* @param taskListener the task listener
127
* @throws IllegalStateException if the specified listener has already been added.
128
* @since 1.8
129
*/
130
public abstract void addTaskListener(TaskListener taskListener);
131
132
/**
133
* Removes the specified listener so that it no longer receives
134
* notification of events describing the progress of this
135
* compilation task.
136
*
137
* This method may be called at any time before or during the compilation.
138
*
139
* @param taskListener the task listener
140
* @since 1.8
141
*/
142
public abstract void removeTaskListener(TaskListener taskListener);
143
144
/**
145
* Sets the specified {@link ParameterNameProvider}. It may be used when
146
* {@link VariableElement#getSimpleName()} is called for a method parameter
147
* for which an authoritative name is not found. The given
148
* {@code ParameterNameProvider} may infer a user-friendly name
149
* for the method parameter.
150
*
151
* Setting a new {@code ParameterNameProvider} will clear any previously set
152
* {@code ParameterNameProvider}, which won't be queried any more.
153
*
154
* When no {@code ParameterNameProvider} is set, or when it returns null from
155
* {@link ParameterNameProvider#getParameterName(javax.lang.model.element.VariableElement)},
156
* an automatically synthesized name is returned from {@code VariableElement.getSimpleName()}.
157
*
158
* @implSpec The default implementation of this method does nothing.
159
*
160
* @param provider the provider
161
* @since 13
162
*/
163
public void setParameterNameProvider(ParameterNameProvider provider) {}
164
165
/**
166
* Returns a type mirror of the tree node determined by the specified path.
167
* This method has been superseded by methods on
168
* {@link com.sun.source.util.Trees Trees}.
169
*
170
* @param path the path
171
* @return the type mirror
172
* @see com.sun.source.util.Trees#getTypeMirror
173
*/
174
public abstract TypeMirror getTypeMirror(Iterable<? extends Tree> path);
175
176
/**
177
* Returns a utility object for dealing with program elements.
178
*
179
* @return a utility object for dealing with program elements
180
*/
181
public abstract Elements getElements();
182
183
/**
184
* Returns a utility object for dealing with type mirrors.
185
*
186
* @return the utility object for dealing with type mirrors
187
*/
188
public abstract Types getTypes();
189
}
190
191