com.sun.tools.javac.api.JavacTool Java Examples

The following examples show how to use com.sun.tools.javac.api.JavacTool. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source Project: openjdk-jdk8u-backup   Author: AdoptOpenJDK   File: T6430241.java    License: GNU General Public License v2.0 6 votes vote down vote up
void testTaskAPI(boolean expectWarnings, Iterable<? extends File> pcp) throws Exception {
    System.err.println("test task API: " + pcp);

    JavacTool tool = JavacTool.create();
    StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null);

    if (pcp != null)
        fm.setLocation(StandardLocation.PLATFORM_CLASS_PATH, pcp);

    Iterable<? extends JavaFileObject> files = fm.getJavaFileObjects(testFile);

    StringWriter sw = new StringWriter();
    PrintWriter pw = new PrintWriter(sw);
    JavacTask task = tool.getTask(pw, fm, null, null, null, files);
    boolean ok = task.call();
    String out = showOutput(sw.toString());

    checkCompilationOK(ok);
    checkOutput(out, expectWarnings);
}
 
Example #2
Source Project: openjdk-jdk8u-backup   Author: AdoptOpenJDK   File: AbstractTreeScannerTest.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Read a file.
 * @param file the file to be read
 * @return the tree for the content of the file
 * @throws IOException if any IO errors occur
 * @throws TreePosTest.ParseException if any errors occur while parsing the file
 */
JCCompilationUnit read(File file) throws IOException, ParseException {
    JavacTool tool = JavacTool.create();
    r.errors = 0;
    Iterable<? extends JavaFileObject> files = fm.getJavaFileObjects(file);
    JavacTask task = tool.getTask(pw, fm, r, Collections.<String>emptyList(), null, files);
    Iterable<? extends CompilationUnitTree> trees = task.parse();
    pw.flush();
    if (r.errors > 0)
        throw new ParseException(sw.toString());
    Iterator<? extends CompilationUnitTree> iter = trees.iterator();
    if (!iter.hasNext())
        throw new Error("no trees found");
    JCCompilationUnit t = (JCCompilationUnit) iter.next();
    if (iter.hasNext())
        throw new Error("too many trees found");
    return t;
}
 
Example #3
Source Project: manifold   Author: manifold-systems   File: PathUtil.java    License: Apache License 2.0 6 votes vote down vote up
public static String findToolsJar()
{
  String javaHome = System.getProperty( "java.home" );
  String toolsJar = javaHome + File.separator + "lib" + File.separator + "tools.jar";
  if( !PathUtil.isFile( PathUtil.create( toolsJar ) ) )
  {
    try
    {
      URI toolsJarUri = JavacTool.class.getProtectionDomain().getCodeSource().getLocation().toURI();
      toolsJar = new File( toolsJarUri ).getAbsolutePath();
    }
    catch( URISyntaxException e )
    {
      System.out.println( "Could not find tools.jar" );
    }
  }
  return toolsJar;
}
 
Example #4
Source Project: openjdk-jdk9   Author: AdoptOpenJDK   File: T6345974.java    License: GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
    PrintWriter out = new PrintWriter(System.out, true);
    JavacTool tool = JavacTool.create();
    try (StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null)) {
        File testSrc = new File(System.getProperty("test.src"));
        Iterable<? extends JavaFileObject> f =
            fm.getJavaFileObjectsFromFiles(Arrays.asList(new File(testSrc, "T6345974.java")));
        JavacTask task = tool.getTask(out, fm, null, null, null, f);
        Iterable<? extends CompilationUnitTree> trees = task.parse();
        out.flush();

        Scanner s = new Scanner();
        for (CompilationUnitTree t: trees)
            s.scan(t, null);
    }
}
 
Example #5
Source Project: TencentKona-8   Author: Tencent   File: T6993305.java    License: GNU General Public License v2.0 6 votes vote down vote up
void run() throws Exception {
    File testSrc = new File(System.getProperty("test.src"));

    JavacTool tool = JavacTool.create();
    StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null);

    File f = new File(testSrc, T6993305.class.getSimpleName() + ".java");
    Iterable<? extends JavaFileObject> fos = fm.getJavaFileObjects(f);
    JavacTask task = tool.getTask(null, fm, null, null, null, fos);
    Iterable<? extends CompilationUnitTree> cus = task.parse();

    TestScanner s = new TestScanner();
    s.scan(cus, task);

    if (errors > 0)
        throw new Exception(errors + " errors occurred");
}
 
Example #6
Source Project: TencentKona-8   Author: Tencent   File: TreePosTest.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Read a file.
 * @param file the file to be read
 * @return the tree for the content of the file
 * @throws IOException if any IO errors occur
 * @throws TreePosTest.ParseException if any errors occur while parsing the file
 */
JCCompilationUnit read(File file) throws IOException, ParseException {
    JavacTool tool = JavacTool.create();
    r.errors = 0;
    Iterable<? extends JavaFileObject> files = fm.getJavaFileObjects(file);
    JavacTask task = tool.getTask(pw, fm, r, Collections.<String>emptyList(), null, files);
    Iterable<? extends CompilationUnitTree> trees = task.parse();
    pw.flush();
    if (r.errors > 0)
        throw new ParseException(sw.toString());
    Iterator<? extends CompilationUnitTree> iter = trees.iterator();
    if (!iter.hasNext())
        throw new Error("no trees found");
    JCCompilationUnit t = (JCCompilationUnit) iter.next();
    if (iter.hasNext())
        throw new Error("too many trees found");
    return t;
}
 
Example #7
Source Project: openjdk-8   Author: bpupadhyaya   File: DocTreePathScannerTest.java    License: GNU General Public License v2.0 6 votes vote down vote up
void run() throws Exception {
    List<File> files = new ArrayList<File>();
    File testSrc = new File(System.getProperty("test.src"));
    for (File f: testSrc.listFiles()) {
        if (f.isFile() && f.getName().endsWith(".java"))
            files.add(f);
    }

    JavacTool javac = JavacTool.create();
    StandardJavaFileManager fm = javac.getStandardFileManager(null, null, null);

    Iterable<? extends JavaFileObject> fos = fm.getJavaFileObjectsFromFiles(files);

    JavacTask t = javac.getTask(null, fm, null, null, null, fos);
    DocTrees trees = DocTrees.instance(t);

    Iterable<? extends CompilationUnitTree> units = t.parse();

    DeclScanner ds = new DeclScanner(trees);
    for (CompilationUnitTree unit: units) {
        ds.scan(unit, null);
    }

    if (errors > 0)
        throw new Exception(errors + " errors occurred");
}
 
Example #8
Source Project: openjdk-8   Author: bpupadhyaya   File: T6410706.java    License: GNU General Public License v2.0 6 votes vote down vote up
public static void main(String... args) throws IOException {
    String testSrc = System.getProperty("test.src", ".");
    String testClasses = System.getProperty("test.classes", ".");
    JavacTool tool = JavacTool.create();
    MyDiagListener dl = new MyDiagListener();
    StandardJavaFileManager fm = tool.getStandardFileManager(dl, null, null);
    fm.setLocation(StandardLocation.CLASS_OUTPUT, Arrays.asList(new File(testClasses)));
    Iterable<? extends JavaFileObject> files =
        fm.getJavaFileObjectsFromFiles(Arrays.asList(new File(testSrc, T6410706.class.getName()+".java")));
    JavacTask task = tool.getTask(null, fm, dl, null, null, files);
    task.parse();
    task.analyze();
    task.generate();

    // expect 2 notes:
    // Note: T6410706.java uses or overrides a deprecated API.
    // Note: Recompile with -Xlint:deprecation for details.

    if (dl.notes != 2)
        throw new AssertionError(dl.notes + " notes given");
}
 
Example #9
Source Project: TencentKona-8   Author: Tencent   File: T6430241.java    License: GNU General Public License v2.0 6 votes vote down vote up
void testTaskAPI(boolean expectWarnings, Iterable<? extends File> pcp) throws Exception {
    System.err.println("test task API: " + pcp);

    JavacTool tool = JavacTool.create();
    StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null);

    if (pcp != null)
        fm.setLocation(StandardLocation.PLATFORM_CLASS_PATH, pcp);

    Iterable<? extends JavaFileObject> files = fm.getJavaFileObjects(testFile);

    StringWriter sw = new StringWriter();
    PrintWriter pw = new PrintWriter(sw);
    JavacTask task = tool.getTask(pw, fm, null, null, null, files);
    boolean ok = task.call();
    String out = showOutput(sw.toString());

    checkCompilationOK(ok);
    checkOutput(out, expectWarnings);
}
 
Example #10
Source Project: TencentKona-8   Author: Tencent   File: TestDocComments.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * method-run.
 */
void run() throws Exception {
    File testSrc = new File(System.getProperty("test.src"));
    File file = new File(testSrc, "TestDocComments.java");

    JavacTool tool = JavacTool.create();
    StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null);

    StringWriter sw = new StringWriter();
    PrintWriter pw = new PrintWriter(sw);
    Iterable<? extends JavaFileObject> fileObjects = fm.getJavaFileObjects(file);
    JavacTask task = tool.getTask(pw, fm, null, null, null, fileObjects);
    Iterable<? extends CompilationUnitTree> units = task.parse();
    Trees trees = Trees.instance(task);

    CommentScanner s = new CommentScanner();
    int n = s.scan(units, trees);

    if (n != 12)
        error("Unexpected number of doc comments found: " + n);

    if (errors > 0)
        throw new Exception(errors + " errors occurred");
}
 
Example #11
Source Project: TencentKona-8   Author: Tencent   File: DocTreePathScannerTest.java    License: GNU General Public License v2.0 6 votes vote down vote up
void run() throws Exception {
    List<File> files = new ArrayList<File>();
    File testSrc = new File(System.getProperty("test.src"));
    for (File f: testSrc.listFiles()) {
        if (f.isFile() && f.getName().endsWith(".java"))
            files.add(f);
    }

    JavacTool javac = JavacTool.create();
    StandardJavaFileManager fm = javac.getStandardFileManager(null, null, null);

    Iterable<? extends JavaFileObject> fos = fm.getJavaFileObjectsFromFiles(files);

    JavacTask t = javac.getTask(null, fm, null, null, null, fos);
    DocTrees trees = DocTrees.instance(t);

    Iterable<? extends CompilationUnitTree> units = t.parse();

    DeclScanner ds = new DeclScanner(trees);
    for (CompilationUnitTree unit: units) {
        ds.scan(unit, null);
    }

    if (errors > 0)
        throw new Exception(errors + " errors occurred");
}
 
Example #12
Source Project: openjdk-jdk8u-backup   Author: AdoptOpenJDK   File: T6403466.java    License: GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws IOException {
    JavacTool tool = JavacTool.create();

    StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null);
    Iterable<? extends JavaFileObject> files =
        fm.getJavaFileObjectsFromFiles(Arrays.asList(new File(testSrcDir, self + ".java")));

    Iterable<String> options = Arrays.asList("-processorpath", testClassDir,
                                             "-processor", self,
                                             "-s", ".",
                                             "-d", ".");
    JavacTask task = tool.getTask(out, fm, null, options, null, files);

    VerifyingTaskListener vtl = new VerifyingTaskListener(new File(testSrcDir, self + ".out"));
    task.setTaskListener(vtl);

    if (!task.call())
        throw new AssertionError("compilation failed");

    if (vtl.iter.hasNext() || vtl.errors)
        throw new AssertionError("comparison against golden file failed.");
}
 
Example #13
Source Project: TencentKona-8   Author: Tencent   File: AnnotatedArrayOrder.java    License: GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
    PrintWriter out = new PrintWriter(System.out, true);
    JavacTool tool = JavacTool.create();
    StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null);
    File testSrc = new File(System.getProperty("test.src"));
    Iterable<? extends JavaFileObject> f =
        fm.getJavaFileObjectsFromFiles(Arrays.asList(new File(testSrc, "AnnotatedArrayOrder.java")));
    JavacTask task = tool.getTask(out, fm, null, null, null, f);
    Iterable<? extends CompilationUnitTree> trees = task.parse();
    out.flush();

    Scanner s = new Scanner();
    for (CompilationUnitTree t: trees)
        s.scan(t, null);

}
 
Example #14
Source Project: TencentKona-8   Author: Tencent   File: ArrayPositionConsistency.java    License: GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
    PrintWriter out = new PrintWriter(System.out, true);
    JavacTool tool = JavacTool.create();
    StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null);
    File testSrc = new File(System.getProperty("test.src"));
    Iterable<? extends JavaFileObject> f =
        fm.getJavaFileObjectsFromFiles(Arrays.asList(new File(testSrc, "ArrayPositionConsistency.java")));
    JavacTask task = tool.getTask(out, fm, null, null, null, f);
    Iterable<? extends CompilationUnitTree> trees = task.parse();
    out.flush();

    Scanner s = new Scanner();
    for (CompilationUnitTree t: trees)
        s.scan(t, null);

}
 
Example #15
Source Project: openjdk-jdk9   Author: AdoptOpenJDK   File: AvoidInfiniteReattribution.java    License: GNU General Public License v2.0 6 votes vote down vote up
void run() throws IOException {
    JavacTool tool = JavacTool.create();
    JavaSource source = new JavaSource("class Test {" +
                                       "    I i = STOP -> {};" +
                                       "    interface I {" +
                                       "        public void test(int i) {}" +
                                       "    }" +
                                       "}");
    Context context = new Context();
    CrashingAttr.preRegister(context);
    List<JavaSource> inputs = Arrays.asList(source);
    JavacTaskImpl task =
            (JavacTaskImpl) tool.getTask(null, null, null, null, null, inputs, context);
    try {
        task.analyze(null);
        throw new AssertionError("Expected exception not seen.");
    } catch (StopException ex) {
        //ok
    }
}
 
Example #16
Source Project: TencentKona-8   Author: Tencent   File: T6410706.java    License: GNU General Public License v2.0 6 votes vote down vote up
public static void main(String... args) throws IOException {
    String testSrc = System.getProperty("test.src", ".");
    String testClasses = System.getProperty("test.classes", ".");
    JavacTool tool = JavacTool.create();
    MyDiagListener dl = new MyDiagListener();
    StandardJavaFileManager fm = tool.getStandardFileManager(dl, null, null);
    fm.setLocation(StandardLocation.CLASS_OUTPUT, Arrays.asList(new File(testClasses)));
    Iterable<? extends JavaFileObject> files =
        fm.getJavaFileObjectsFromFiles(Arrays.asList(new File(testSrc, T6410706.class.getName()+".java")));
    JavacTask task = tool.getTask(null, fm, dl, null, null, files);
    task.parse();
    task.analyze();
    task.generate();

    // expect 2 notes:
    // Note: T6410706.java uses or overrides a deprecated API.
    // Note: Recompile with -Xlint:deprecation for details.

    if (dl.notes != 2)
        throw new AssertionError(dl.notes + " notes given");
}
 
Example #17
Source Project: openjdk-jdk9   Author: AdoptOpenJDK   File: TwrAvoidNullCheck.java    License: GNU General Public License v2.0 6 votes vote down vote up
void run(String resourceSpecification, boolean expected) throws IOException {
    String template = "public class Test implements AutoCloseable {\n" +
                      "    void t() {\n" +
                      "        try (Test resource = RESOURCE) { }\n" +
                      "    }\n" +
                      "    public void close() { }\n" +
                      "}\n";
    String code = template.replace("RESOURCE", resourceSpecification);
    Context ctx = new Context();
    DumpLower.preRegister(ctx);
    Iterable<ToolBox.JavaSource> files = Arrays.asList(new ToolBox.JavaSource(code));
    JavacTask task = JavacTool.create().getTask(null, null, null, null, null, files, ctx);
    task.call();

    boolean hasNullCheck = ((DumpLower) DumpLower.instance(ctx)).hasNullCheck;

    if (hasNullCheck != expected) {
        throw new IllegalStateException("expected: " + expected +
                                        "; actual: " + hasNullCheck +
                                        "; code: " + code);
    }
}
 
Example #18
Source Project: openjdk-jdk9   Author: AdoptOpenJDK   File: T6358168.java    License: GNU General Public License v2.0 6 votes vote down vote up
static void testNoAnnotationProcessing(JavacFileManager fm, List<JavaFileObject> files) throws Throwable {
    Context context = new Context();

    String[] args = { "-d", "." };

    JavacTool tool = JavacTool.create();
    JavacTask task = tool.getTask(null, fm, null, List.from(args), null, files, context);
    // no need in this simple case to call task.prepareCompiler(false)

    JavaCompiler compiler = JavaCompiler.instance(context);
    compiler.compile(files);
    try {
        compiler.compile(files);
        throw new Error("Error: AssertionError not thrown after second call of compile");
    } catch (AssertionError e) {
        System.err.println("Exception from compiler (expected): " + e);
    }
}
 
Example #19
Source Project: openjdk-8   Author: bpupadhyaya   File: NativeHeaderTest.java    License: GNU General Public License v2.0 6 votes vote down vote up
/** Combo test to run all test cases in all modes. */
void run() throws Exception {
    javac = JavacTool.create();
    fm = javac.getStandardFileManager(null, null, null);

    for (RunKind rk: RunKind.values()) {
        for (GenKind gk: GenKind.values()) {
            for (Method m: getClass().getDeclaredMethods()) {
                Annotation a = m.getAnnotation(Test.class);
                if (a != null) {
                    init(rk, gk, m.getName());
                    try {
                        m.invoke(this, new Object[] { rk, gk });
                    } catch (InvocationTargetException e) {
                        Throwable cause = e.getCause();
                        throw (cause instanceof Exception) ? ((Exception) cause) : e;
                    }
                    System.err.println();
                }
            }
        }
    }
    System.err.println(testCount + " tests" + ((errorCount == 0) ? "" : ", " + errorCount + " errors"));
    if (errorCount > 0)
        throw new Exception(errorCount + " errors found");
}
 
Example #20
Source Project: openjdk-8-source   Author: keerath   File: T6430241.java    License: GNU General Public License v2.0 6 votes vote down vote up
void testTaskAPI(boolean expectWarnings, Iterable<? extends File> pcp) throws Exception {
    System.err.println("test task API: " + pcp);

    JavacTool tool = JavacTool.create();
    StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null);

    if (pcp != null)
        fm.setLocation(StandardLocation.PLATFORM_CLASS_PATH, pcp);

    Iterable<? extends JavaFileObject> files = fm.getJavaFileObjects(testFile);

    StringWriter sw = new StringWriter();
    PrintWriter pw = new PrintWriter(sw);
    JavacTask task = tool.getTask(pw, fm, null, null, null, files);
    boolean ok = task.call();
    String out = showOutput(sw.toString());

    checkCompilationOK(ok);
    checkOutput(out, expectWarnings);
}
 
Example #21
Source Project: jdk8u60   Author: chenghanpeng   File: AbstractTreeScannerTest.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Read a file.
 * @param file the file to be read
 * @return the tree for the content of the file
 * @throws IOException if any IO errors occur
 * @throws TreePosTest.ParseException if any errors occur while parsing the file
 */
JCCompilationUnit read(File file) throws IOException, ParseException {
    JavacTool tool = JavacTool.create();
    r.errors = 0;
    Iterable<? extends JavaFileObject> files = fm.getJavaFileObjects(file);
    JavacTask task = tool.getTask(pw, fm, r, Collections.<String>emptyList(), null, files);
    Iterable<? extends CompilationUnitTree> trees = task.parse();
    pw.flush();
    if (r.errors > 0)
        throw new ParseException(sw.toString());
    Iterator<? extends CompilationUnitTree> iter = trees.iterator();
    if (!iter.hasNext())
        throw new Error("no trees found");
    JCCompilationUnit t = (JCCompilationUnit) iter.next();
    if (iter.hasNext())
        throw new Error("too many trees found");
    return t;
}
 
Example #22
Source Project: openjdk-jdk9   Author: AdoptOpenJDK   File: TreePosTest.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Read a file.
 * @param file the file to be read
 * @return the tree for the content of the file
 * @throws IOException if any IO errors occur
 * @throws TreePosTest.ParseException if any errors occur while parsing the file
 */
JCCompilationUnit read(File file) throws IOException, ParseException {
    JavacTool tool = JavacTool.create();
    r.errors = 0;
    Iterable<? extends JavaFileObject> files = fm.getJavaFileObjects(file);
    JavacTask task = tool.getTask(pw, fm, r, List.of("-proc:none"), null, files);
    Iterable<? extends CompilationUnitTree> trees = task.parse();
    pw.flush();
    if (r.errors > 0)
        throw new ParseException(sw.toString());
    Iterator<? extends CompilationUnitTree> iter = trees.iterator();
    if (!iter.hasNext())
        throw new Error("no trees found");
    JCCompilationUnit t = (JCCompilationUnit) iter.next();
    if (iter.hasNext())
        throw new Error("too many trees found");
    return t;
}
 
Example #23
Source Project: openjdk-8-source   Author: keerath   File: ArrayCreationTree.java    License: GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
    PrintWriter out = new PrintWriter(System.out, true);
    JavacTool tool = JavacTool.create();
    StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null);
    File testSrc = new File(System.getProperty("test.src"));
    Iterable<? extends JavaFileObject> f =
        fm.getJavaFileObjectsFromFiles(Arrays.asList(new File(testSrc, "ArrayCreationTree.java")));
    JavacTask task = tool.getTask(out, fm, null, null, null, f);
    Iterable<? extends CompilationUnitTree> trees = task.parse();
    out.flush();

    Scanner s = new Scanner();
    for (CompilationUnitTree t: trees)
        s.scan(t, null);

}
 
Example #24
Source Project: openjdk-8   Author: bpupadhyaya   File: T6430241.java    License: GNU General Public License v2.0 6 votes vote down vote up
void testTaskAPI(boolean expectWarnings, Iterable<? extends File> pcp) throws Exception {
    System.err.println("test task API: " + pcp);

    JavacTool tool = JavacTool.create();
    StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null);

    if (pcp != null)
        fm.setLocation(StandardLocation.PLATFORM_CLASS_PATH, pcp);

    Iterable<? extends JavaFileObject> files = fm.getJavaFileObjects(testFile);

    StringWriter sw = new StringWriter();
    PrintWriter pw = new PrintWriter(sw);
    JavacTask task = tool.getTask(pw, fm, null, null, null, files);
    boolean ok = task.call();
    String out = showOutput(sw.toString());

    checkCompilationOK(ok);
    checkOutput(out, expectWarnings);
}
 
Example #25
Source Project: openjdk-jdk8u-backup   Author: AdoptOpenJDK   File: T6410706.java    License: GNU General Public License v2.0 6 votes vote down vote up
public static void main(String... args) throws IOException {
    String testSrc = System.getProperty("test.src", ".");
    String testClasses = System.getProperty("test.classes", ".");
    JavacTool tool = JavacTool.create();
    MyDiagListener dl = new MyDiagListener();
    StandardJavaFileManager fm = tool.getStandardFileManager(dl, null, null);
    fm.setLocation(StandardLocation.CLASS_OUTPUT, Arrays.asList(new File(testClasses)));
    Iterable<? extends JavaFileObject> files =
        fm.getJavaFileObjectsFromFiles(Arrays.asList(new File(testSrc, T6410706.class.getName()+".java")));
    JavacTask task = tool.getTask(null, fm, dl, null, null, files);
    task.parse();
    task.analyze();
    task.generate();

    // expect 2 notes:
    // Note: T6410706.java uses or overrides a deprecated API.
    // Note: Recompile with -Xlint:deprecation for details.

    if (dl.notes != 2)
        throw new AssertionError(dl.notes + " notes given");
}
 
Example #26
Source Project: openjdk-jdk8u   Author: AdoptOpenJDK   File: TestDocComments.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * method-run.
 */
void run() throws Exception {
    File testSrc = new File(System.getProperty("test.src"));
    File file = new File(testSrc, "TestDocComments.java");

    JavacTool tool = JavacTool.create();
    StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null);

    StringWriter sw = new StringWriter();
    PrintWriter pw = new PrintWriter(sw);
    Iterable<? extends JavaFileObject> fileObjects = fm.getJavaFileObjects(file);
    JavacTask task = tool.getTask(pw, fm, null, null, null, fileObjects);
    Iterable<? extends CompilationUnitTree> units = task.parse();
    Trees trees = Trees.instance(task);

    CommentScanner s = new CommentScanner();
    int n = s.scan(units, trees);

    if (n != 12)
        error("Unexpected number of doc comments found: " + n);

    if (errors > 0)
        throw new Exception(errors + " errors occurred");
}
 
Example #27
Source Project: jdk8u60   Author: chenghanpeng   File: DocTreePathScannerTest.java    License: GNU General Public License v2.0 6 votes vote down vote up
void run() throws Exception {
    List<File> files = new ArrayList<File>();
    File testSrc = new File(System.getProperty("test.src"));
    for (File f: testSrc.listFiles()) {
        if (f.isFile() && f.getName().endsWith(".java"))
            files.add(f);
    }

    JavacTool javac = JavacTool.create();
    StandardJavaFileManager fm = javac.getStandardFileManager(null, null, null);

    Iterable<? extends JavaFileObject> fos = fm.getJavaFileObjectsFromFiles(files);

    JavacTask t = javac.getTask(null, fm, null, null, null, fos);
    DocTrees trees = DocTrees.instance(t);

    Iterable<? extends CompilationUnitTree> units = t.parse();

    DeclScanner ds = new DeclScanner(trees);
    for (CompilationUnitTree unit: units) {
        ds.scan(unit, null);
    }

    if (errors > 0)
        throw new Exception(errors + " errors occurred");
}
 
Example #28
Source Project: openjdk-jdk8u-backup   Author: AdoptOpenJDK   File: T6993305.java    License: GNU General Public License v2.0 6 votes vote down vote up
void run() throws Exception {
    File testSrc = new File(System.getProperty("test.src"));

    JavacTool tool = JavacTool.create();
    StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null);

    File f = new File(testSrc, T6993305.class.getSimpleName() + ".java");
    Iterable<? extends JavaFileObject> fos = fm.getJavaFileObjects(f);
    JavacTask task = tool.getTask(null, fm, null, null, null, fos);
    Iterable<? extends CompilationUnitTree> cus = task.parse();

    TestScanner s = new TestScanner();
    s.scan(cus, task);

    if (errors > 0)
        throw new Exception(errors + " errors occurred");
}
 
Example #29
Source Project: openjdk-jdk9   Author: AdoptOpenJDK   File: T6993305.java    License: GNU General Public License v2.0 6 votes vote down vote up
void run() throws Exception {
    File testSrc = new File(System.getProperty("test.src"));

    JavacTool tool = JavacTool.create();
    try (StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null)) {

        File f = new File(testSrc, T6993305.class.getSimpleName() + ".java");
        Iterable<? extends JavaFileObject> fos = fm.getJavaFileObjects(f);
        JavacTask task = tool.getTask(null, fm, null, null, null, fos);
        Iterable<? extends CompilationUnitTree> cus = task.parse();

        TestScanner s = new TestScanner();
        s.scan(cus, task);

        if (errors > 0)
            throw new Exception(errors + " errors occurred");
    }
}
 
Example #30
Source Project: openjdk-jdk8u   Author: AdoptOpenJDK   File: ArrayPositionConsistency.java    License: GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
    PrintWriter out = new PrintWriter(System.out, true);
    JavacTool tool = JavacTool.create();
    StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null);
    File testSrc = new File(System.getProperty("test.src"));
    Iterable<? extends JavaFileObject> f =
        fm.getJavaFileObjectsFromFiles(Arrays.asList(new File(testSrc, "ArrayPositionConsistency.java")));
    JavacTask task = tool.getTask(out, fm, null, null, null, f);
    Iterable<? extends CompilationUnitTree> trees = task.parse();
    out.flush();

    Scanner s = new Scanner();
    for (CompilationUnitTree t: trees)
        s.scan(t, null);

}