|
1 /* |
|
2 * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. |
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
|
4 * |
|
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 |
|
7 * published by the Free Software Foundation. |
|
8 * |
|
9 * This code is distributed in the hope that it will be useful, but WITHOUT |
|
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
12 * version 2 for more details (a copy is included in the LICENSE file that |
|
13 * accompanied this code). |
|
14 * |
|
15 * You should have received a copy of the GNU General Public License version |
|
16 * 2 along with this work; if not, write to the Free Software Foundation, |
|
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
18 * |
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
20 * or visit www.oracle.com if you need additional information or have any |
|
21 * questions. |
|
22 */ |
|
23 |
|
24 /* |
|
25 * @test |
|
26 * @bug 6598108 |
|
27 * @summary com.sun.source.util.Trees.isAccessible incorrect |
|
28 * @author Jan Lahoda |
|
29 */ |
|
30 |
|
31 import com.sun.source.tree.CompilationUnitTree; |
|
32 import com.sun.source.tree.Scope; |
|
33 import com.sun.source.util.JavacTask; |
|
34 import com.sun.source.util.TreePath; |
|
35 import com.sun.source.util.Trees; |
|
36 import java.net.URI; |
|
37 import java.util.Arrays; |
|
38 import javax.lang.model.element.TypeElement; |
|
39 import javax.tools.JavaCompiler; |
|
40 import javax.tools.JavaFileObject; |
|
41 import javax.tools.SimpleJavaFileObject; |
|
42 import javax.tools.ToolProvider; |
|
43 |
|
44 public class T6598108 { |
|
45 public static void main(String[] args) throws Exception { |
|
46 final String bootPath = System.getProperty("sun.boot.class.path"); //NOI18N |
|
47 final JavaCompiler tool = ToolProvider.getSystemJavaCompiler(); |
|
48 assert tool != null; |
|
49 final JavacTask ct = (JavacTask)tool.getTask(null, null, null, Arrays.asList("-bootclasspath", bootPath), null, Arrays.asList(new MyFileObject())); |
|
50 |
|
51 CompilationUnitTree cut = ct.parse().iterator().next(); |
|
52 TreePath tp = new TreePath(new TreePath(cut), cut.getTypeDecls().get(0)); |
|
53 Scope s = Trees.instance(ct).getScope(tp); |
|
54 TypeElement type = ct.getElements().getTypeElement("com.sun.java.util.jar.pack.Package.File"); |
|
55 |
|
56 if (Trees.instance(ct).isAccessible(s, type)) { |
|
57 //com.sun.java.util.jar.pack.Package.File is a public innerclass inside a non-accessible class, so |
|
58 //"false" would be expected here. |
|
59 throw new IllegalStateException(""); |
|
60 } |
|
61 } |
|
62 |
|
63 static class MyFileObject extends SimpleJavaFileObject { |
|
64 public MyFileObject() { |
|
65 super(URI.create("myfo:/Test.java"), JavaFileObject.Kind.SOURCE); |
|
66 } |
|
67 public CharSequence getCharContent(boolean ignoreEncodingErrors) { |
|
68 return "public class Test<TTT> { public void test() {TTT ttt;}}"; |
|
69 } |
|
70 } |
|
71 } |