Tue, 25 Sep 2012 13:11:05 -0700
7196464: upgrade JavaCompiler.shouldStopPolicy to accomodate policies in face of error and no error
Reviewed-by: mcimadamore
1 /*
2 * Copyright (c) 2005, 2012, 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 */
26 package com.sun.tools.javac.api;
28 import java.io.IOException;
29 import java.util.Locale;
31 import javax.annotation.processing.Processor;
32 import javax.lang.model.element.Element;
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.JavaFileObject;
38 import com.sun.source.tree.CompilationUnitTree;
39 import com.sun.source.tree.Tree;
40 import com.sun.source.util.JavacTask;
41 import com.sun.source.util.TaskListener;
42 import com.sun.tools.javac.model.JavacElements;
43 import com.sun.tools.javac.model.JavacTypes;
44 import com.sun.tools.javac.tree.JCTree;
45 import com.sun.tools.javac.util.Context;
46 import java.util.Collection;
48 /**
49 * Provides basic functionality for implementations of JavacTask.
50 *
51 * <p><b>This is NOT part of any supported API.
52 * If you write code that depends on this, you do so at your own
53 * risk. This code and its internal interfaces are subject to change
54 * or deletion without notice.</b></p>
55 */
56 public class BasicJavacTask extends JavacTask {
57 protected Context context;
58 private TaskListener taskListener;
60 public BasicJavacTask(Context c, boolean register) {
61 context = c;
62 if (register)
63 context.put(JavacTask.class, this);
64 }
66 @Override
67 public Iterable<? extends CompilationUnitTree> parse() throws IOException {
68 throw new IllegalStateException();
69 }
71 @Override
72 public Iterable<? extends Element> analyze() throws IOException {
73 throw new IllegalStateException();
74 }
76 @Override
77 public Iterable<? extends JavaFileObject> generate() throws IOException {
78 throw new IllegalStateException();
79 }
81 @Override
82 public void setTaskListener(TaskListener tl) {
83 MultiTaskListener mtl = MultiTaskListener.instance(context);
84 if (taskListener != null)
85 mtl.remove(taskListener);
86 if (tl != null)
87 mtl.add(tl);
88 taskListener = tl;
89 }
91 @Override
92 public void addTaskListener(TaskListener taskListener) {
93 MultiTaskListener mtl = MultiTaskListener.instance(context);
94 mtl.add(taskListener);
95 }
97 @Override
98 public void removeTaskListener(TaskListener taskListener) {
99 MultiTaskListener mtl = MultiTaskListener.instance(context);
100 mtl.remove(taskListener);
101 }
103 public Collection<TaskListener> getTaskListeners() {
104 MultiTaskListener mtl = MultiTaskListener.instance(context);
105 return mtl.getTaskListeners();
106 }
108 @Override
109 public TypeMirror getTypeMirror(Iterable<? extends Tree> path) {
110 // TODO: Should complete attribution if necessary
111 Tree last = null;
112 for (Tree node : path)
113 last = node;
114 return ((JCTree)last).type;
115 }
117 @Override
118 public Elements getElements() {
119 return JavacElements.instance(context);
120 }
122 @Override
123 public Types getTypes() {
124 return JavacTypes.instance(context);
125 }
127 public void setProcessors(Iterable<? extends Processor> processors) {
128 throw new IllegalStateException();
129 }
131 public void setLocale(Locale locale) {
132 throw new IllegalStateException();
133 }
135 public Boolean call() {
136 throw new IllegalStateException();
137 }
139 /**
140 * For internal use only. This method will be
141 * removed without warning.
142 */
143 public void updateContext(Context newContext) {
144 context = newContext;
145 }
146 }