1 /* |
1 /* |
2 * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 2013, 2014, 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. |
64 if (f.isFile() && f.getName().endsWith(".java")) |
64 if (f.isFile() && f.getName().endsWith(".java")) |
65 files.add(f); |
65 files.add(f); |
66 } |
66 } |
67 |
67 |
68 JavacTool javac = JavacTool.create(); |
68 JavacTool javac = JavacTool.create(); |
69 StandardJavaFileManager fm = javac.getStandardFileManager(null, null, null); |
69 try (StandardJavaFileManager fm = javac.getStandardFileManager(null, null, null)) { |
70 |
70 |
71 Iterable<? extends JavaFileObject> fos = fm.getJavaFileObjectsFromFiles(files); |
71 Iterable<? extends JavaFileObject> fos = fm.getJavaFileObjectsFromFiles(files); |
72 |
72 |
73 JavacTask t = javac.getTask(null, fm, null, null, null, fos); |
73 JavacTask t = javac.getTask(null, fm, null, null, null, fos); |
74 DocTrees trees = DocTrees.instance(t); |
74 DocTrees trees = DocTrees.instance(t); |
75 |
75 |
76 Iterable<? extends CompilationUnitTree> units = t.parse(); |
76 Iterable<? extends CompilationUnitTree> units = t.parse(); |
77 |
77 |
78 DeclScanner ds = new DeclScanner(trees); |
78 DeclScanner ds = new DeclScanner(trees); |
79 for (CompilationUnitTree unit: units) { |
79 for (CompilationUnitTree unit: units) { |
80 ds.scan(unit, null); |
80 ds.scan(unit, null); |
|
81 } |
|
82 |
|
83 if (errors > 0) |
|
84 throw new Exception(errors + " errors occurred"); |
81 } |
85 } |
82 |
|
83 if (errors > 0) |
|
84 throw new Exception(errors + " errors occurred"); |
|
85 } |
86 } |
86 |
87 |
87 void error(String msg) { |
88 void error(String msg) { |
88 System.err.println("Error: " + msg); |
89 System.err.println("Error: " + msg); |
89 errors++; |
90 errors++; |