1 /* |
1 /* |
2 * Copyright (c) 2005, 2006, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 2005, 2013, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
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 |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. |
7 * published by the Free Software Foundation. |
38 import javax.tools.JavaFileObject; |
38 import javax.tools.JavaFileObject; |
39 import javax.tools.StandardJavaFileManager; |
39 import javax.tools.StandardJavaFileManager; |
40 import javax.tools.ToolProvider; |
40 import javax.tools.ToolProvider; |
41 |
41 |
42 public class TestJavacTask { |
42 public class TestJavacTask { |
43 |
43 static final JavaCompiler compiler = ToolProvider.getSystemJavaCompiler(); |
44 static JavacTaskImpl getTask(JavaCompiler compiler, File... file) { |
44 static JavacTaskImpl getTask(File... file) { |
45 StandardJavaFileManager fm = compiler.getStandardFileManager(null, null, null); |
45 StandardJavaFileManager fm = compiler.getStandardFileManager(null, null, null); |
46 Iterable<? extends JavaFileObject> files = |
46 Iterable<? extends JavaFileObject> files = |
47 fm.getJavaFileObjectsFromFiles(Arrays.asList(file)); |
47 fm.getJavaFileObjectsFromFiles(Arrays.asList(file)); |
48 return (JavacTaskImpl)compiler.getTask(null, fm, null, null, null, files); |
48 return (JavacTaskImpl)compiler.getTask(null, fm, null, null, null, files); |
49 } |
49 } |
50 |
50 |
51 public static void main(String... args) throws IOException { |
51 static void basicTest(String... args) throws IOException { |
52 JavaCompiler tool = ToolProvider.getSystemJavaCompiler(); |
|
53 String srcdir = System.getProperty("test.src"); |
52 String srcdir = System.getProperty("test.src"); |
54 File file = new File(srcdir, args[0]); |
53 File file = new File(srcdir, args[0]); |
55 JavacTaskImpl task = getTask(tool, file); |
54 JavacTaskImpl task = getTask(file); |
56 for (TypeElement clazz : task.enter(task.parse())) |
55 for (TypeElement clazz : task.enter(task.parse())) |
57 System.out.println(clazz.getSimpleName()); |
56 System.out.println(clazz.getSimpleName()); |
58 } |
57 } |
59 |
58 |
|
59 static void checkKindError() { |
|
60 final File testFile = new File("Test.java "); // <-note trailing space! |
|
61 try { |
|
62 getTask(testFile); |
|
63 } catch (IllegalArgumentException iae) { |
|
64 if (!iae.getMessage().contains("\"" + testFile.getName() + "\"")) { |
|
65 System.err.println("Got message: " + iae.getMessage()); |
|
66 throw new RuntimeException("Error: expected string not found"); |
|
67 } |
|
68 } |
|
69 } |
|
70 |
|
71 public static void main(String... args) throws IOException { |
|
72 basicTest(args); |
|
73 checkKindError(); |
|
74 } |
60 } |
75 } |