|
1 /* |
|
2 * Copyright (c) 2018, 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 8209865 |
|
27 * @summary Verify that when reading from ct.sym, classes are only visible from modules from which |
|
28 * they are exported. |
|
29 * @modules jdk.compiler |
|
30 * @build ReleaseModulesAndTypeElement |
|
31 * @compile -processor ReleaseModulesAndTypeElement --release 11 ReleaseModulesAndTypeElement.java |
|
32 */ |
|
33 |
|
34 import java.util.Set; |
|
35 |
|
36 import javax.annotation.processing.AbstractProcessor; |
|
37 import javax.annotation.processing.RoundEnvironment; |
|
38 import javax.annotation.processing.SupportedAnnotationTypes; |
|
39 import javax.lang.model.SourceVersion; |
|
40 import javax.lang.model.element.ModuleElement; |
|
41 import javax.lang.model.element.TypeElement; |
|
42 import javax.lang.model.util.Elements; |
|
43 |
|
44 @SupportedAnnotationTypes("*") |
|
45 public class ReleaseModulesAndTypeElement extends AbstractProcessor { |
|
46 |
|
47 @Override |
|
48 public boolean process(Set<? extends TypeElement> roots, RoundEnvironment roundEnv) { |
|
49 Elements elements = processingEnv.getElementUtils(); |
|
50 if (elements.getTypeElement(JX_A_P_GENERATED) == null) { |
|
51 throw new AssertionError("jx.a.p.Generated not found by unqualified search!"); |
|
52 } |
|
53 ModuleElement javaBase = elements.getModuleElement("java.base"); |
|
54 if (elements.getTypeElement(javaBase, JX_A_P_GENERATED) != null) { |
|
55 throw new AssertionError("jx.a.p.Generated found in java.base!"); |
|
56 } |
|
57 ModuleElement javaCompiler = elements.getModuleElement("java.compiler"); |
|
58 if (elements.getTypeElement(javaCompiler, JX_A_P_GENERATED) == null) { |
|
59 throw new AssertionError("jx.a.p.Generated not found in java.compiler!"); |
|
60 } |
|
61 return false; |
|
62 } |
|
63 //where: |
|
64 private static final String JX_A_P_GENERATED = "javax.annotation.processing.Generated"; |
|
65 |
|
66 @Override |
|
67 public SourceVersion getSupportedSourceVersion() { |
|
68 return SourceVersion.latestSupported(); |
|
69 } |
|
70 |
|
71 } |