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.tools.javac.api;
27
28 import java.util.Collection;
29 import java.util.LinkedHashSet;
30 import java.util.Locale;
31 import java.util.ServiceLoader;
32 import java.util.Set;
33 import java.util.stream.Collectors;
34
35 import javax.annotation.processing.Processor;
36 import javax.lang.model.element.Element;
37 import javax.lang.model.type.TypeMirror;
38 import javax.lang.model.util.Elements;
39 import javax.lang.model.util.Types;
40 import javax.tools.JavaFileObject;
41
42 import com.sun.source.tree.CompilationUnitTree;
43 import com.sun.source.tree.Tree;
44 import com.sun.source.util.JavacTask;
45 import com.sun.source.util.Plugin;
46 import com.sun.source.util.TaskListener;
47 import com.sun.tools.doclint.DocLint;
48 import com.sun.tools.javac.main.JavaCompiler;
49 import com.sun.tools.javac.model.JavacElements;
50 import com.sun.tools.javac.model.JavacTypes;
113 public void addTaskListener(TaskListener taskListener) {
114 MultiTaskListener mtl = MultiTaskListener.instance(context);
115 mtl.add(taskListener);
116 }
117
118 @Override @DefinedBy(Api.COMPILER_TREE)
119 public void removeTaskListener(TaskListener taskListener) {
120 MultiTaskListener mtl = MultiTaskListener.instance(context);
121 mtl.remove(taskListener);
122 }
123
124 public Collection<TaskListener> getTaskListeners() {
125 MultiTaskListener mtl = MultiTaskListener.instance(context);
126 return mtl.getTaskListeners();
127 }
128
129 @Override @DefinedBy(Api.COMPILER_TREE)
130 public TypeMirror getTypeMirror(Iterable<? extends Tree> path) {
131 // TODO: Should complete attribution if necessary
132 Tree last = null;
133 for (Tree node : path)
134 last = node;
135 return ((JCTree)last).type;
136 }
137
138 @Override @DefinedBy(Api.COMPILER_TREE)
139 public Elements getElements() {
140 if (context == null)
141 throw new IllegalStateException();
142 return JavacElements.instance(context);
143 }
144
145 @Override @DefinedBy(Api.COMPILER_TREE)
146 public Types getTypes() {
147 if (context == null)
148 throw new IllegalStateException();
149 return JavacTypes.instance(context);
150 }
151
152 @Override @DefinedBy(Api.COMPILER)
153 public void setProcessors(Iterable<? extends Processor> processors) {
154 throw new IllegalStateException();
155 }
|
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.tools.javac.api;
27
28 import java.util.Collection;
29 import java.util.LinkedHashSet;
30 import java.util.Locale;
31 import java.util.Objects;
32 import java.util.ServiceLoader;
33 import java.util.Set;
34 import java.util.stream.Collectors;
35
36 import javax.annotation.processing.Processor;
37 import javax.lang.model.element.Element;
38 import javax.lang.model.type.TypeMirror;
39 import javax.lang.model.util.Elements;
40 import javax.lang.model.util.Types;
41 import javax.tools.JavaFileObject;
42
43 import com.sun.source.tree.CompilationUnitTree;
44 import com.sun.source.tree.Tree;
45 import com.sun.source.util.JavacTask;
46 import com.sun.source.util.Plugin;
47 import com.sun.source.util.TaskListener;
48 import com.sun.tools.doclint.DocLint;
49 import com.sun.tools.javac.main.JavaCompiler;
50 import com.sun.tools.javac.model.JavacElements;
51 import com.sun.tools.javac.model.JavacTypes;
114 public void addTaskListener(TaskListener taskListener) {
115 MultiTaskListener mtl = MultiTaskListener.instance(context);
116 mtl.add(taskListener);
117 }
118
119 @Override @DefinedBy(Api.COMPILER_TREE)
120 public void removeTaskListener(TaskListener taskListener) {
121 MultiTaskListener mtl = MultiTaskListener.instance(context);
122 mtl.remove(taskListener);
123 }
124
125 public Collection<TaskListener> getTaskListeners() {
126 MultiTaskListener mtl = MultiTaskListener.instance(context);
127 return mtl.getTaskListeners();
128 }
129
130 @Override @DefinedBy(Api.COMPILER_TREE)
131 public TypeMirror getTypeMirror(Iterable<? extends Tree> path) {
132 // TODO: Should complete attribution if necessary
133 Tree last = null;
134 for (Tree node : path) {
135 last = Objects.requireNonNull(node);
136 }
137 if (last == null) {
138 throw new IllegalArgumentException("empty path");
139 }
140 return ((JCTree) last).type;
141 }
142
143 @Override @DefinedBy(Api.COMPILER_TREE)
144 public Elements getElements() {
145 if (context == null)
146 throw new IllegalStateException();
147 return JavacElements.instance(context);
148 }
149
150 @Override @DefinedBy(Api.COMPILER_TREE)
151 public Types getTypes() {
152 if (context == null)
153 throw new IllegalStateException();
154 return JavacTypes.instance(context);
155 }
156
157 @Override @DefinedBy(Api.COMPILER)
158 public void setProcessors(Iterable<? extends Processor> processors) {
159 throw new IllegalStateException();
160 }
|