Java Code Examples for com.sun.tools.javac.tree.TreeScanner#scan()
The following examples show how to use
com.sun.tools.javac.tree.TreeScanner#scan() .
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 File: CompilerBasedTest.java From Refaster with Apache License 2.0 | 6 votes |
protected void compile(TreeScanner scanner, JavaFileObject fileObject) { JavaCompiler compiler = JavacTool.create(); DiagnosticCollector<JavaFileObject> diagnosticsCollector = new DiagnosticCollector<JavaFileObject>(); StandardJavaFileManager fileManager = compiler.getStandardFileManager(diagnosticsCollector, Locale.ENGLISH, UTF_8); JavacTaskImpl task = (JavacTaskImpl) compiler.getTask(CharStreams.nullWriter(), fileManager, diagnosticsCollector, ImmutableList.<String>of(), null, ImmutableList.of(fileObject)); try { this.sourceFile = SourceFile.create(fileObject); Iterable<? extends CompilationUnitTree> trees = task.parse(); task.analyze(); for (CompilationUnitTree tree : trees) { scanner.scan((JCCompilationUnit) tree); } } catch (IOException e) { throw new RuntimeException(e); } this.context = task.getContext(); }
Example 2
Source File: TestLog.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
static void test(boolean genEndPos) throws IOException { Context context = new Context(); Options options = Options.instance(context); options.put("diags", "%b:%s/%o/%e:%_%t%m|%p%m"); Log log = Log.instance(context); log.multipleErrors = true; JavacFileManager.preRegister(context); ParserFactory pfac = ParserFactory.instance(context); final String text = "public class Foo {\n" + " public static void main(String[] args) {\n" + " if (args.length == 0)\n" + " System.out.println(\"no args\");\n" + " else\n" + " System.out.println(args.length + \" args\");\n" + " }\n" + "}\n"; JavaFileObject fo = new StringJavaFileObject("Foo", text); log.useSource(fo); CharSequence cs = fo.getCharContent(true); Parser parser = pfac.newParser(cs, false, genEndPos, false); JCTree.JCCompilationUnit tree = parser.parseCompilationUnit(); log.setEndPosTable(fo, tree.endPositions); TreeScanner ts = new LogTester(log, tree.endPositions); ts.scan(tree); check(log.nerrors, 4, "errors"); check(log.nwarnings, 4, "warnings"); }
Example 3
Source File: TestLog.java From jdk8u60 with GNU General Public License v2.0 | 5 votes |
static void test(boolean genEndPos) throws IOException { Context context = new Context(); Options options = Options.instance(context); options.put("diags", "%b:%s/%o/%e:%_%t%m|%p%m"); Log log = Log.instance(context); log.multipleErrors = true; JavacFileManager.preRegister(context); ParserFactory pfac = ParserFactory.instance(context); final String text = "public class Foo {\n" + " public static void main(String[] args) {\n" + " if (args.length == 0)\n" + " System.out.println(\"no args\");\n" + " else\n" + " System.out.println(args.length + \" args\");\n" + " }\n" + "}\n"; JavaFileObject fo = new StringJavaFileObject("Foo", text); log.useSource(fo); CharSequence cs = fo.getCharContent(true); Parser parser = pfac.newParser(cs, false, genEndPos, false); JCTree.JCCompilationUnit tree = parser.parseCompilationUnit(); log.setEndPosTable(fo, tree.endPositions); TreeScanner ts = new LogTester(log, tree.endPositions); ts.scan(tree); check(log.nerrors, 4, "errors"); check(log.nwarnings, 4, "warnings"); }
Example 4
Source File: TestLog.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
static void test(boolean genEndPos) throws IOException { Context context = new Context(); Options options = Options.instance(context); options.put("diags", "%b:%s/%o/%e:%_%t%m|%p%m"); Log log = Log.instance(context); log.multipleErrors = true; JavacFileManager.preRegister(context); ParserFactory pfac = ParserFactory.instance(context); final String text = "public class Foo {\n" + " public static void main(String[] args) {\n" + " if (args.length == 0)\n" + " System.out.println(\"no args\");\n" + " else\n" + " System.out.println(args.length + \" args\");\n" + " }\n" + "}\n"; JavaFileObject fo = new StringJavaFileObject("Foo", text); log.useSource(fo); CharSequence cs = fo.getCharContent(true); Parser parser = pfac.newParser(cs, false, genEndPos, false); JCTree.JCCompilationUnit tree = parser.parseCompilationUnit(); log.setEndPosTable(fo, tree.endPositions); TreeScanner ts = new LogTester(log, tree.endPositions); ts.scan(tree); check(log.nerrors, 4, "errors"); check(log.nwarnings, 4, "warnings"); }
Example 5
Source File: TestLog.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 5 votes |
static void test(boolean genEndPos) throws IOException { Context context = new Context(); Options options = Options.instance(context); options.put("diags", "%b:%s/%o/%e:%_%t%m|%p%m"); Log log = Log.instance(context); log.multipleErrors = true; JavacFileManager.preRegister(context); ParserFactory pfac = ParserFactory.instance(context); final String text = "public class Foo {\n" + " public static void main(String[] args) {\n" + " if (args.length == 0)\n" + " System.out.println(\"no args\");\n" + " else\n" + " System.out.println(args.length + \" args\");\n" + " }\n" + "}\n"; JavaFileObject fo = new StringJavaFileObject("Foo", text); log.useSource(fo); CharSequence cs = fo.getCharContent(true); Parser parser = pfac.newParser(cs, false, genEndPos, false); JCTree.JCCompilationUnit tree = parser.parseCompilationUnit(); log.setEndPosTable(fo, tree.endPositions); TreeScanner ts = new LogTester(log, tree.endPositions); ts.scan(tree); check(log.nerrors, 4, "errors"); check(log.nwarnings, 4, "warnings"); }
Example 6
Source File: TestLog.java From hottub with GNU General Public License v2.0 | 5 votes |
static void test(boolean genEndPos) throws IOException { Context context = new Context(); Options options = Options.instance(context); options.put("diags", "%b:%s/%o/%e:%_%t%m|%p%m"); Log log = Log.instance(context); log.multipleErrors = true; JavacFileManager.preRegister(context); ParserFactory pfac = ParserFactory.instance(context); final String text = "public class Foo {\n" + " public static void main(String[] args) {\n" + " if (args.length == 0)\n" + " System.out.println(\"no args\");\n" + " else\n" + " System.out.println(args.length + \" args\");\n" + " }\n" + "}\n"; JavaFileObject fo = new StringJavaFileObject("Foo", text); log.useSource(fo); CharSequence cs = fo.getCharContent(true); Parser parser = pfac.newParser(cs, false, genEndPos, false); JCTree.JCCompilationUnit tree = parser.parseCompilationUnit(); log.setEndPosTable(fo, tree.endPositions); TreeScanner ts = new LogTester(log, tree.endPositions); ts.scan(tree); check(log.nerrors, 4, "errors"); check(log.nwarnings, 4, "warnings"); }
Example 7
Source File: TestLog.java From openjdk-8-source with GNU General Public License v2.0 | 5 votes |
static void test(boolean genEndPos) throws IOException { Context context = new Context(); Options options = Options.instance(context); options.put("diags", "%b:%s/%o/%e:%_%t%m|%p%m"); Log log = Log.instance(context); log.multipleErrors = true; JavacFileManager.preRegister(context); ParserFactory pfac = ParserFactory.instance(context); final String text = "public class Foo {\n" + " public static void main(String[] args) {\n" + " if (args.length == 0)\n" + " System.out.println(\"no args\");\n" + " else\n" + " System.out.println(args.length + \" args\");\n" + " }\n" + "}\n"; JavaFileObject fo = new StringJavaFileObject("Foo", text); log.useSource(fo); CharSequence cs = fo.getCharContent(true); Parser parser = pfac.newParser(cs, false, genEndPos, false); JCTree.JCCompilationUnit tree = parser.parseCompilationUnit(); log.setEndPosTable(fo, tree.endPositions); TreeScanner ts = new LogTester(log, tree.endPositions); ts.scan(tree); check(log.nerrors, 4, "errors"); check(log.nwarnings, 4, "warnings"); }
Example 8
Source File: TestLog.java From openjdk-8 with GNU General Public License v2.0 | 5 votes |
static void test(boolean genEndPos) throws IOException { Context context = new Context(); Options options = Options.instance(context); options.put("diags", "%b:%s/%o/%e:%_%t%m|%p%m"); Log log = Log.instance(context); log.multipleErrors = true; JavacFileManager.preRegister(context); ParserFactory pfac = ParserFactory.instance(context); final String text = "public class Foo {\n" + " public static void main(String[] args) {\n" + " if (args.length == 0)\n" + " System.out.println(\"no args\");\n" + " else\n" + " System.out.println(args.length + \" args\");\n" + " }\n" + "}\n"; JavaFileObject fo = new StringJavaFileObject("Foo", text); log.useSource(fo); CharSequence cs = fo.getCharContent(true); Parser parser = pfac.newParser(cs, false, genEndPos, false); JCTree.JCCompilationUnit tree = parser.parseCompilationUnit(); log.setEndPosTable(fo, tree.endPositions); TreeScanner ts = new LogTester(log, tree.endPositions); ts.scan(tree); check(log.nerrors, 4, "errors"); check(log.nwarnings, 4, "warnings"); }
Example 9
Source File: TestLog.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
static void test(boolean genEndPos) throws Exception { Context context = new Context(); Options options = Options.instance(context); options.put("diags", "%b:%s/%o/%e:%_%t%m|%p%m"); Log log = Log.instance(context); Factory diagnosticFactory = JCDiagnostic.Factory.instance(context); Field defaultErrorFlagsField = JCDiagnostic.Factory.class.getDeclaredField("defaultErrorFlags"); defaultErrorFlagsField.setAccessible(true); Set<DiagnosticFlag> defaultErrorFlags = (Set<DiagnosticFlag>) defaultErrorFlagsField.get(diagnosticFactory); defaultErrorFlags.add(DiagnosticFlag.MULTIPLE); JavacFileManager.preRegister(context); ParserFactory pfac = ParserFactory.instance(context); final String text = "public class Foo {\n" + " public static void main(String[] args) {\n" + " if (args.length == 0)\n" + " System.out.println(\"no args\");\n" + " else\n" + " System.out.println(args.length + \" args\");\n" + " }\n" + "}\n"; JavaFileObject fo = new StringJavaFileObject("Foo", text); log.useSource(fo); CharSequence cs = fo.getCharContent(true); Parser parser = pfac.newParser(cs, false, genEndPos, false); JCTree.JCCompilationUnit tree = parser.parseCompilationUnit(); log.setEndPosTable(fo, tree.endPositions); TreeScanner ts = new LogTester(log, tree.endPositions); ts.scan(tree); check(log.nerrors, 4, "errors"); check(log.nwarnings, 4, "warnings"); }