author | jjg |
Mon, 19 Nov 2012 11:38:49 -0800 | |
changeset 14548 | aa687b312c97 |
parent 14258 | 8d2148961366 |
child 14952 | d0022ae20516 |
permissions | -rw-r--r-- |
12016 | 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 |
*/ |
|
25 |
||
26 |
package com.sun.tools.javac.api; |
|
27 |
||
28 |
import java.io.IOException; |
|
14258 | 29 |
import java.util.Collection; |
12016 | 30 |
import java.util.Locale; |
31 |
||
32 |
import javax.annotation.processing.Processor; |
|
33 |
import javax.lang.model.element.Element; |
|
34 |
import javax.lang.model.type.TypeMirror; |
|
35 |
import javax.lang.model.util.Elements; |
|
36 |
import javax.lang.model.util.Types; |
|
37 |
import javax.tools.JavaFileObject; |
|
38 |
||
39 |
import com.sun.source.tree.CompilationUnitTree; |
|
40 |
import com.sun.source.tree.Tree; |
|
41 |
import com.sun.source.util.JavacTask; |
|
42 |
import com.sun.source.util.TaskListener; |
|
43 |
import com.sun.tools.javac.model.JavacElements; |
|
44 |
import com.sun.tools.javac.model.JavacTypes; |
|
45 |
import com.sun.tools.javac.tree.JCTree; |
|
46 |
import com.sun.tools.javac.util.Context; |
|
47 |
||
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; |
|
59 |
||
60 |
public BasicJavacTask(Context c, boolean register) { |
|
61 |
context = c; |
|
62 |
if (register) |
|
63 |
context.put(JavacTask.class, this); |
|
64 |
} |
|
65 |
||
66 |
@Override |
|
67 |
public Iterable<? extends CompilationUnitTree> parse() throws IOException { |
|
68 |
throw new IllegalStateException(); |
|
69 |
} |
|
70 |
||
71 |
@Override |
|
72 |
public Iterable<? extends Element> analyze() throws IOException { |
|
73 |
throw new IllegalStateException(); |
|
74 |
} |
|
75 |
||
76 |
@Override |
|
77 |
public Iterable<? extends JavaFileObject> generate() throws IOException { |
|
78 |
throw new IllegalStateException(); |
|
79 |
} |
|
80 |
||
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 |
} |
|
90 |
||
91 |
@Override |
|
92 |
public void addTaskListener(TaskListener taskListener) { |
|
93 |
MultiTaskListener mtl = MultiTaskListener.instance(context); |
|
94 |
mtl.add(taskListener); |
|
95 |
} |
|
96 |
||
97 |
@Override |
|
98 |
public void removeTaskListener(TaskListener taskListener) { |
|
99 |
MultiTaskListener mtl = MultiTaskListener.instance(context); |
|
100 |
mtl.remove(taskListener); |
|
101 |
} |
|
102 |
||
103 |
public Collection<TaskListener> getTaskListeners() { |
|
104 |
MultiTaskListener mtl = MultiTaskListener.instance(context); |
|
105 |
return mtl.getTaskListeners(); |
|
106 |
} |
|
107 |
||
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 |
} |
|
116 |
||
117 |
@Override |
|
118 |
public Elements getElements() { |
|
119 |
return JavacElements.instance(context); |
|
120 |
} |
|
121 |
||
122 |
@Override |
|
123 |
public Types getTypes() { |
|
124 |
return JavacTypes.instance(context); |
|
125 |
} |
|
126 |
||
127 |
public void setProcessors(Iterable<? extends Processor> processors) { |
|
128 |
throw new IllegalStateException(); |
|
129 |
} |
|
130 |
||
131 |
public void setLocale(Locale locale) { |
|
132 |
throw new IllegalStateException(); |
|
133 |
} |
|
134 |
||
135 |
public Boolean call() { |
|
136 |
throw new IllegalStateException(); |
|
137 |
} |
|
138 |
||
14044
0070e9c44020
7196462: JavacProcessingEnvironment should tolerate BasicJavacTask
jjg
parents:
12016
diff
changeset
|
139 |
/** |
0070e9c44020
7196462: JavacProcessingEnvironment should tolerate BasicJavacTask
jjg
parents:
12016
diff
changeset
|
140 |
* For internal use only. This method will be |
0070e9c44020
7196462: JavacProcessingEnvironment should tolerate BasicJavacTask
jjg
parents:
12016
diff
changeset
|
141 |
* removed without warning. |
0070e9c44020
7196462: JavacProcessingEnvironment should tolerate BasicJavacTask
jjg
parents:
12016
diff
changeset
|
142 |
*/ |
14548
aa687b312c97
8001098: Provide a simple light-weight "plug-in" mechanism for javac
jjg
parents:
14258
diff
changeset
|
143 |
public Context getContext() { |
aa687b312c97
8001098: Provide a simple light-weight "plug-in" mechanism for javac
jjg
parents:
14258
diff
changeset
|
144 |
return context; |
aa687b312c97
8001098: Provide a simple light-weight "plug-in" mechanism for javac
jjg
parents:
14258
diff
changeset
|
145 |
} |
aa687b312c97
8001098: Provide a simple light-weight "plug-in" mechanism for javac
jjg
parents:
14258
diff
changeset
|
146 |
|
aa687b312c97
8001098: Provide a simple light-weight "plug-in" mechanism for javac
jjg
parents:
14258
diff
changeset
|
147 |
/** |
aa687b312c97
8001098: Provide a simple light-weight "plug-in" mechanism for javac
jjg
parents:
14258
diff
changeset
|
148 |
* For internal use only. This method will be |
aa687b312c97
8001098: Provide a simple light-weight "plug-in" mechanism for javac
jjg
parents:
14258
diff
changeset
|
149 |
* removed without warning. |
aa687b312c97
8001098: Provide a simple light-weight "plug-in" mechanism for javac
jjg
parents:
14258
diff
changeset
|
150 |
*/ |
14044
0070e9c44020
7196462: JavacProcessingEnvironment should tolerate BasicJavacTask
jjg
parents:
12016
diff
changeset
|
151 |
public void updateContext(Context newContext) { |
0070e9c44020
7196462: JavacProcessingEnvironment should tolerate BasicJavacTask
jjg
parents:
12016
diff
changeset
|
152 |
context = newContext; |
0070e9c44020
7196462: JavacProcessingEnvironment should tolerate BasicJavacTask
jjg
parents:
12016
diff
changeset
|
153 |
} |
12016 | 154 |
} |