Fri, 09 May 2014 20:33:21 -0700
8041424: 8u20 l10n resource file translation update 1
Reviewed-by: naoto, yhuang
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.Collection;
30 import java.util.Locale;
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;
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;
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 static JavacTask instance(Context context) {
61 JavacTask instance = context.get(JavacTask.class);
62 if (instance == null)
63 instance = new BasicJavacTask(context, true);
64 return instance;
65 }
67 public BasicJavacTask(Context c, boolean register) {
68 context = c;
69 if (register)
70 context.put(JavacTask.class, this);
71 }
73 @Override
74 public Iterable<? extends CompilationUnitTree> parse() throws IOException {
75 throw new IllegalStateException();
76 }
78 @Override
79 public Iterable<? extends Element> analyze() throws IOException {
80 throw new IllegalStateException();
81 }
83 @Override
84 public Iterable<? extends JavaFileObject> generate() throws IOException {
85 throw new IllegalStateException();
86 }
88 @Override
89 public void setTaskListener(TaskListener tl) {
90 MultiTaskListener mtl = MultiTaskListener.instance(context);
91 if (taskListener != null)
92 mtl.remove(taskListener);
93 if (tl != null)
94 mtl.add(tl);
95 taskListener = tl;
96 }
98 @Override
99 public void addTaskListener(TaskListener taskListener) {
100 MultiTaskListener mtl = MultiTaskListener.instance(context);
101 mtl.add(taskListener);
102 }
104 @Override
105 public void removeTaskListener(TaskListener taskListener) {
106 MultiTaskListener mtl = MultiTaskListener.instance(context);
107 mtl.remove(taskListener);
108 }
110 public Collection<TaskListener> getTaskListeners() {
111 MultiTaskListener mtl = MultiTaskListener.instance(context);
112 return mtl.getTaskListeners();
113 }
115 @Override
116 public TypeMirror getTypeMirror(Iterable<? extends Tree> path) {
117 // TODO: Should complete attribution if necessary
118 Tree last = null;
119 for (Tree node : path)
120 last = node;
121 return ((JCTree)last).type;
122 }
124 @Override
125 public Elements getElements() {
126 return JavacElements.instance(context);
127 }
129 @Override
130 public Types getTypes() {
131 return JavacTypes.instance(context);
132 }
134 public void setProcessors(Iterable<? extends Processor> processors) {
135 throw new IllegalStateException();
136 }
138 public void setLocale(Locale locale) {
139 throw new IllegalStateException();
140 }
142 public Boolean call() {
143 throw new IllegalStateException();
144 }
146 /**
147 * For internal use only. This method will be
148 * removed without warning.
149 */
150 public Context getContext() {
151 return context;
152 }
154 /**
155 * For internal use only. This method will be
156 * removed without warning.
157 */
158 public void updateContext(Context newContext) {
159 context = newContext;
160 }
161 }