1 /* |
1 /* |
2 * Copyright (c) 2005, 2012, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 2005, 2015, 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. |
24 /* |
24 /* |
25 * @test |
25 * @test |
26 * @bug 6304912 |
26 * @bug 6304912 |
27 * @summary unit test for Log |
27 * @summary unit test for Log |
28 */ |
28 */ |
|
29 import java.lang.reflect.Field; |
29 import java.io.InputStream; |
30 import java.io.InputStream; |
30 import java.io.IOException; |
|
31 import java.io.OutputStream; |
31 import java.io.OutputStream; |
32 import java.net.URI; |
32 import java.net.URI; |
|
33 import java.util.Set; |
33 import javax.tools.JavaFileObject; |
34 import javax.tools.JavaFileObject; |
34 import javax.tools.SimpleJavaFileObject; |
35 import javax.tools.SimpleJavaFileObject; |
35 import com.sun.tools.javac.file.JavacFileManager; |
36 import com.sun.tools.javac.file.JavacFileManager; |
36 import com.sun.tools.javac.parser.Parser; |
37 import com.sun.tools.javac.parser.Parser; |
37 import com.sun.tools.javac.parser.ParserFactory; |
38 import com.sun.tools.javac.parser.ParserFactory; |
39 import com.sun.tools.javac.tree.JCTree; |
40 import com.sun.tools.javac.tree.JCTree; |
40 import com.sun.tools.javac.tree.TreeScanner; |
41 import com.sun.tools.javac.tree.TreeScanner; |
41 import com.sun.tools.javac.util.Context; |
42 import com.sun.tools.javac.util.Context; |
42 import com.sun.tools.javac.util.Log; |
43 import com.sun.tools.javac.util.Log; |
43 import com.sun.tools.javac.util.JCDiagnostic; |
44 import com.sun.tools.javac.util.JCDiagnostic; |
|
45 import com.sun.tools.javac.util.JCDiagnostic.DiagnosticFlag; |
|
46 import com.sun.tools.javac.util.JCDiagnostic.Factory; |
44 import com.sun.tools.javac.util.Options; |
47 import com.sun.tools.javac.util.Options; |
45 |
48 |
46 public class TestLog |
49 public class TestLog |
47 { |
50 { |
48 public static void main(String... args) throws IOException { |
51 public static void main(String... args) throws Exception { |
49 test(false); |
52 test(false); |
50 test(true); |
53 test(true); |
51 } |
54 } |
52 |
55 |
53 static void test(boolean genEndPos) throws IOException { |
56 static void test(boolean genEndPos) throws Exception { |
54 Context context = new Context(); |
57 Context context = new Context(); |
55 |
58 |
56 Options options = Options.instance(context); |
59 Options options = Options.instance(context); |
57 options.put("diags", "%b:%s/%o/%e:%_%t%m|%p%m"); |
60 options.put("diags", "%b:%s/%o/%e:%_%t%m|%p%m"); |
58 |
61 |
59 Log log = Log.instance(context); |
62 Log log = Log.instance(context); |
60 log.multipleErrors = true; |
63 Factory diagnosticFactory = JCDiagnostic.Factory.instance(context); |
|
64 Field defaultErrorFlagsField = |
|
65 JCDiagnostic.Factory.class.getDeclaredField("defaultErrorFlags"); |
|
66 |
|
67 defaultErrorFlagsField.setAccessible(true); |
|
68 |
|
69 Set<DiagnosticFlag> defaultErrorFlags = |
|
70 (Set<DiagnosticFlag>) defaultErrorFlagsField.get(diagnosticFactory); |
|
71 |
|
72 defaultErrorFlags.add(DiagnosticFlag.MULTIPLE); |
61 |
73 |
62 JavacFileManager.preRegister(context); |
74 JavacFileManager.preRegister(context); |
63 ParserFactory pfac = ParserFactory.instance(context); |
75 ParserFactory pfac = ParserFactory.instance(context); |
64 |
76 |
65 final String text = |
77 final String text = |