43 import com.sun.tools.javac.file.JavacFileManager; |
43 import com.sun.tools.javac.file.JavacFileManager; |
44 import com.sun.tools.javac.main.Arguments; |
44 import com.sun.tools.javac.main.Arguments; |
45 import com.sun.tools.javac.main.Option; |
45 import com.sun.tools.javac.main.Option; |
46 import com.sun.tools.javac.util.ClientCodeException; |
46 import com.sun.tools.javac.util.ClientCodeException; |
47 import com.sun.tools.javac.util.Context; |
47 import com.sun.tools.javac.util.Context; |
|
48 import com.sun.tools.javac.util.DefinedBy; |
|
49 import com.sun.tools.javac.util.DefinedBy.Api; |
48 import com.sun.tools.javac.util.Log; |
50 import com.sun.tools.javac.util.Log; |
49 import com.sun.tools.javac.util.PropagatedException; |
51 import com.sun.tools.javac.util.PropagatedException; |
50 |
52 |
51 /** |
53 /** |
52 * TODO: describe com.sun.tools.javac.api.Tool |
54 * TODO: describe com.sun.tools.javac.api.Tool |
76 */ |
78 */ |
77 public static JavacTool create() { |
79 public static JavacTool create() { |
78 return new JavacTool(); |
80 return new JavacTool(); |
79 } |
81 } |
80 |
82 |
81 @Override // @DefinedBy(COMPILER_API) |
83 @Override @DefinedBy(Api.COMPILER) |
82 public JavacFileManager getStandardFileManager( |
84 public JavacFileManager getStandardFileManager( |
83 DiagnosticListener<? super JavaFileObject> diagnosticListener, |
85 DiagnosticListener<? super JavaFileObject> diagnosticListener, |
84 Locale locale, |
86 Locale locale, |
85 Charset charset) { |
87 Charset charset) { |
86 Context context = new Context(); |
88 Context context = new Context(); |
92 : new PrintWriter(new OutputStreamWriter(System.err, charset), true); |
94 : new PrintWriter(new OutputStreamWriter(System.err, charset), true); |
93 context.put(Log.outKey, pw); |
95 context.put(Log.outKey, pw); |
94 return new JavacFileManager(context, true, charset); |
96 return new JavacFileManager(context, true, charset); |
95 } |
97 } |
96 |
98 |
97 @Override // @DefinedBy(COMPILER_API) |
99 @Override @DefinedBy(Api.COMPILER) |
98 public JavacTask getTask(Writer out, |
100 public JavacTask getTask(Writer out, |
99 JavaFileManager fileManager, |
101 JavaFileManager fileManager, |
100 DiagnosticListener<? super JavaFileObject> diagnosticListener, |
102 DiagnosticListener<? super JavaFileObject> diagnosticListener, |
101 Iterable<String> options, |
103 Iterable<String> options, |
102 Iterable<String> classes, |
104 Iterable<String> classes, |
163 } catch (ClientCodeException ex) { |
165 } catch (ClientCodeException ex) { |
164 throw new RuntimeException(ex.getCause()); |
166 throw new RuntimeException(ex.getCause()); |
165 } |
167 } |
166 } |
168 } |
167 |
169 |
168 @Override // @DefinedBy(COMPILER_API) |
170 @Override @DefinedBy(Api.COMPILER) |
169 public int run(InputStream in, OutputStream out, OutputStream err, String... arguments) { |
171 public int run(InputStream in, OutputStream out, OutputStream err, String... arguments) { |
170 if (err == null) |
172 if (err == null) |
171 err = System.err; |
173 err = System.err; |
172 for (String argument : arguments) |
174 for (String argument : arguments) |
173 argument.getClass(); // null check |
175 argument.getClass(); // null check |
174 return com.sun.tools.javac.Main.compile(arguments, new PrintWriter(err, true)); |
176 return com.sun.tools.javac.Main.compile(arguments, new PrintWriter(err, true)); |
175 } |
177 } |
176 |
178 |
177 @Override // @DefinedBy(COMPILER_API) |
179 @Override @DefinedBy(Api.COMPILER) |
178 public Set<SourceVersion> getSourceVersions() { |
180 public Set<SourceVersion> getSourceVersions() { |
179 return Collections.unmodifiableSet(EnumSet.range(SourceVersion.RELEASE_3, |
181 return Collections.unmodifiableSet(EnumSet.range(SourceVersion.RELEASE_3, |
180 SourceVersion.latest())); |
182 SourceVersion.latest())); |
181 } |
183 } |
182 |
184 |
183 @Override // @DefinedBy(COMPILER_API) |
185 @Override @DefinedBy(Api.COMPILER) |
184 public int isSupportedOption(String option) { |
186 public int isSupportedOption(String option) { |
185 Set<Option> recognizedOptions = Option.getJavacToolOptions(); |
187 Set<Option> recognizedOptions = Option.getJavacToolOptions(); |
186 for (Option o : recognizedOptions) { |
188 for (Option o : recognizedOptions) { |
187 if (o.matches(option)) |
189 if (o.matches(option)) |
188 return o.hasArg() ? 1 : 0; |
190 return o.hasArg() ? 1 : 0; |