author | jjg |
Sun, 18 May 2014 19:59:10 -0700 | |
changeset 24604 | 7f68545b5128 |
parent 21006 | 534673718919 |
child 30730 | d3ce7619db2c |
permissions | -rw-r--r-- |
21006
534673718919
8025087: Annotation processing api returns default modifier for interface static method
jlahoda
parents:
diff
changeset
|
1 |
/* |
24604
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
21006
diff
changeset
|
2 |
* Copyright (c) 2013, 2014, Oracle and/or its affiliates. All rights reserved. |
21006
534673718919
8025087: Annotation processing api returns default modifier for interface static method
jlahoda
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
534673718919
8025087: Annotation processing api returns default modifier for interface static method
jlahoda
parents:
diff
changeset
|
4 |
* |
534673718919
8025087: Annotation processing api returns default modifier for interface static method
jlahoda
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
534673718919
8025087: Annotation processing api returns default modifier for interface static method
jlahoda
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
534673718919
8025087: Annotation processing api returns default modifier for interface static method
jlahoda
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
534673718919
8025087: Annotation processing api returns default modifier for interface static method
jlahoda
parents:
diff
changeset
|
8 |
* |
534673718919
8025087: Annotation processing api returns default modifier for interface static method
jlahoda
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
534673718919
8025087: Annotation processing api returns default modifier for interface static method
jlahoda
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
534673718919
8025087: Annotation processing api returns default modifier for interface static method
jlahoda
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
534673718919
8025087: Annotation processing api returns default modifier for interface static method
jlahoda
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
534673718919
8025087: Annotation processing api returns default modifier for interface static method
jlahoda
parents:
diff
changeset
|
13 |
* accompanied this code). |
534673718919
8025087: Annotation processing api returns default modifier for interface static method
jlahoda
parents:
diff
changeset
|
14 |
* |
534673718919
8025087: Annotation processing api returns default modifier for interface static method
jlahoda
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
534673718919
8025087: Annotation processing api returns default modifier for interface static method
jlahoda
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
534673718919
8025087: Annotation processing api returns default modifier for interface static method
jlahoda
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
534673718919
8025087: Annotation processing api returns default modifier for interface static method
jlahoda
parents:
diff
changeset
|
18 |
* |
534673718919
8025087: Annotation processing api returns default modifier for interface static method
jlahoda
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
534673718919
8025087: Annotation processing api returns default modifier for interface static method
jlahoda
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
534673718919
8025087: Annotation processing api returns default modifier for interface static method
jlahoda
parents:
diff
changeset
|
21 |
* questions. |
534673718919
8025087: Annotation processing api returns default modifier for interface static method
jlahoda
parents:
diff
changeset
|
22 |
*/ |
534673718919
8025087: Annotation processing api returns default modifier for interface static method
jlahoda
parents:
diff
changeset
|
23 |
|
534673718919
8025087: Annotation processing api returns default modifier for interface static method
jlahoda
parents:
diff
changeset
|
24 |
/* |
534673718919
8025087: Annotation processing api returns default modifier for interface static method
jlahoda
parents:
diff
changeset
|
25 |
* @test |
534673718919
8025087: Annotation processing api returns default modifier for interface static method
jlahoda
parents:
diff
changeset
|
26 |
* @bug 8025087 |
534673718919
8025087: Annotation processing api returns default modifier for interface static method
jlahoda
parents:
diff
changeset
|
27 |
* @summary Verify that pre-JDK8 classfiles with default and/or static methods |
534673718919
8025087: Annotation processing api returns default modifier for interface static method
jlahoda
parents:
diff
changeset
|
28 |
* are refused correctly. |
534673718919
8025087: Annotation processing api returns default modifier for interface static method
jlahoda
parents:
diff
changeset
|
29 |
* @build BadClassfile |
534673718919
8025087: Annotation processing api returns default modifier for interface static method
jlahoda
parents:
diff
changeset
|
30 |
* @run main BadClassfile |
534673718919
8025087: Annotation processing api returns default modifier for interface static method
jlahoda
parents:
diff
changeset
|
31 |
*/ |
534673718919
8025087: Annotation processing api returns default modifier for interface static method
jlahoda
parents:
diff
changeset
|
32 |
|
534673718919
8025087: Annotation processing api returns default modifier for interface static method
jlahoda
parents:
diff
changeset
|
33 |
import com.sun.tools.classfile.*; |
534673718919
8025087: Annotation processing api returns default modifier for interface static method
jlahoda
parents:
diff
changeset
|
34 |
import com.sun.tools.javac.api.JavacTaskImpl; |
24604
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
21006
diff
changeset
|
35 |
import com.sun.tools.javac.code.ClassFinder.BadClassFile; |
21006
534673718919
8025087: Annotation processing api returns default modifier for interface static method
jlahoda
parents:
diff
changeset
|
36 |
import com.sun.tools.javac.code.Symbol; |
534673718919
8025087: Annotation processing api returns default modifier for interface static method
jlahoda
parents:
diff
changeset
|
37 |
import com.sun.tools.javac.jvm.Target; |
534673718919
8025087: Annotation processing api returns default modifier for interface static method
jlahoda
parents:
diff
changeset
|
38 |
import com.sun.tools.javac.util.Assert; |
534673718919
8025087: Annotation processing api returns default modifier for interface static method
jlahoda
parents:
diff
changeset
|
39 |
import com.sun.tools.javac.util.JCDiagnostic; |
534673718919
8025087: Annotation processing api returns default modifier for interface static method
jlahoda
parents:
diff
changeset
|
40 |
import java.io.File; |
534673718919
8025087: Annotation processing api returns default modifier for interface static method
jlahoda
parents:
diff
changeset
|
41 |
import java.util.Arrays; |
534673718919
8025087: Annotation processing api returns default modifier for interface static method
jlahoda
parents:
diff
changeset
|
42 |
import java.util.Objects; |
534673718919
8025087: Annotation processing api returns default modifier for interface static method
jlahoda
parents:
diff
changeset
|
43 |
import javax.tools.JavaCompiler; |
534673718919
8025087: Annotation processing api returns default modifier for interface static method
jlahoda
parents:
diff
changeset
|
44 |
import javax.tools.ToolProvider; |
534673718919
8025087: Annotation processing api returns default modifier for interface static method
jlahoda
parents:
diff
changeset
|
45 |
|
534673718919
8025087: Annotation processing api returns default modifier for interface static method
jlahoda
parents:
diff
changeset
|
46 |
public class BadClassfile { |
534673718919
8025087: Annotation processing api returns default modifier for interface static method
jlahoda
parents:
diff
changeset
|
47 |
public static void main(String... args) throws Exception { |
534673718919
8025087: Annotation processing api returns default modifier for interface static method
jlahoda
parents:
diff
changeset
|
48 |
test("BadClassfile$DefaultMethodTest", "compiler.misc.invalid.default.interface"); |
534673718919
8025087: Annotation processing api returns default modifier for interface static method
jlahoda
parents:
diff
changeset
|
49 |
test("BadClassfile$StaticMethodTest", "compiler.misc.invalid.static.interface"); |
534673718919
8025087: Annotation processing api returns default modifier for interface static method
jlahoda
parents:
diff
changeset
|
50 |
} |
534673718919
8025087: Annotation processing api returns default modifier for interface static method
jlahoda
parents:
diff
changeset
|
51 |
|
534673718919
8025087: Annotation processing api returns default modifier for interface static method
jlahoda
parents:
diff
changeset
|
52 |
private static void test(String classname, String expected) throws Exception { |
534673718919
8025087: Annotation processing api returns default modifier for interface static method
jlahoda
parents:
diff
changeset
|
53 |
File classfile = new File(System.getProperty("test.classes", "."), classname + ".class"); |
534673718919
8025087: Annotation processing api returns default modifier for interface static method
jlahoda
parents:
diff
changeset
|
54 |
ClassFile cf = ClassFile.read(classfile); |
534673718919
8025087: Annotation processing api returns default modifier for interface static method
jlahoda
parents:
diff
changeset
|
55 |
|
534673718919
8025087: Annotation processing api returns default modifier for interface static method
jlahoda
parents:
diff
changeset
|
56 |
cf = new ClassFile(cf.magic, Target.JDK1_7.minorVersion, |
534673718919
8025087: Annotation processing api returns default modifier for interface static method
jlahoda
parents:
diff
changeset
|
57 |
Target.JDK1_7.majorVersion, cf.constant_pool, cf.access_flags, |
534673718919
8025087: Annotation processing api returns default modifier for interface static method
jlahoda
parents:
diff
changeset
|
58 |
cf.this_class, cf.super_class, cf.interfaces, cf.fields, |
534673718919
8025087: Annotation processing api returns default modifier for interface static method
jlahoda
parents:
diff
changeset
|
59 |
cf.methods, cf.attributes); |
534673718919
8025087: Annotation processing api returns default modifier for interface static method
jlahoda
parents:
diff
changeset
|
60 |
|
534673718919
8025087: Annotation processing api returns default modifier for interface static method
jlahoda
parents:
diff
changeset
|
61 |
new ClassWriter().write(cf, classfile); |
534673718919
8025087: Annotation processing api returns default modifier for interface static method
jlahoda
parents:
diff
changeset
|
62 |
|
534673718919
8025087: Annotation processing api returns default modifier for interface static method
jlahoda
parents:
diff
changeset
|
63 |
JavaCompiler c = ToolProvider.getSystemJavaCompiler(); |
534673718919
8025087: Annotation processing api returns default modifier for interface static method
jlahoda
parents:
diff
changeset
|
64 |
JavacTaskImpl task = (JavacTaskImpl) c.getTask(null, null, null, Arrays.asList("-classpath", System.getProperty("test.classes", ".")), null, null); |
534673718919
8025087: Annotation processing api returns default modifier for interface static method
jlahoda
parents:
diff
changeset
|
65 |
|
534673718919
8025087: Annotation processing api returns default modifier for interface static method
jlahoda
parents:
diff
changeset
|
66 |
try { |
534673718919
8025087: Annotation processing api returns default modifier for interface static method
jlahoda
parents:
diff
changeset
|
67 |
Symbol clazz = com.sun.tools.javac.main.JavaCompiler.instance(task.getContext()).resolveIdent(classname); |
534673718919
8025087: Annotation processing api returns default modifier for interface static method
jlahoda
parents:
diff
changeset
|
68 |
|
534673718919
8025087: Annotation processing api returns default modifier for interface static method
jlahoda
parents:
diff
changeset
|
69 |
clazz.complete(); |
534673718919
8025087: Annotation processing api returns default modifier for interface static method
jlahoda
parents:
diff
changeset
|
70 |
} catch (BadClassFile f) { |
534673718919
8025087: Annotation processing api returns default modifier for interface static method
jlahoda
parents:
diff
changeset
|
71 |
JCDiagnostic embeddedDiag = (JCDiagnostic) f.diag.getArgs()[1]; |
534673718919
8025087: Annotation processing api returns default modifier for interface static method
jlahoda
parents:
diff
changeset
|
72 |
assertEquals(expected, embeddedDiag.getCode()); |
534673718919
8025087: Annotation processing api returns default modifier for interface static method
jlahoda
parents:
diff
changeset
|
73 |
assertEquals(Integer.toString(Target.JDK1_7.majorVersion), embeddedDiag.getArgs()[0]); |
534673718919
8025087: Annotation processing api returns default modifier for interface static method
jlahoda
parents:
diff
changeset
|
74 |
assertEquals(Integer.toString(Target.JDK1_7.minorVersion), embeddedDiag.getArgs()[1]); |
534673718919
8025087: Annotation processing api returns default modifier for interface static method
jlahoda
parents:
diff
changeset
|
75 |
} |
534673718919
8025087: Annotation processing api returns default modifier for interface static method
jlahoda
parents:
diff
changeset
|
76 |
} |
534673718919
8025087: Annotation processing api returns default modifier for interface static method
jlahoda
parents:
diff
changeset
|
77 |
|
534673718919
8025087: Annotation processing api returns default modifier for interface static method
jlahoda
parents:
diff
changeset
|
78 |
private static void assertEquals(Object expected, Object actual) { |
534673718919
8025087: Annotation processing api returns default modifier for interface static method
jlahoda
parents:
diff
changeset
|
79 |
Assert.check(Objects.equals(expected, actual), |
534673718919
8025087: Annotation processing api returns default modifier for interface static method
jlahoda
parents:
diff
changeset
|
80 |
"expected: " + expected + ", but was: " + actual); |
534673718919
8025087: Annotation processing api returns default modifier for interface static method
jlahoda
parents:
diff
changeset
|
81 |
} |
534673718919
8025087: Annotation processing api returns default modifier for interface static method
jlahoda
parents:
diff
changeset
|
82 |
|
534673718919
8025087: Annotation processing api returns default modifier for interface static method
jlahoda
parents:
diff
changeset
|
83 |
interface DefaultMethodTest { |
534673718919
8025087: Annotation processing api returns default modifier for interface static method
jlahoda
parents:
diff
changeset
|
84 |
default void test() { } |
534673718919
8025087: Annotation processing api returns default modifier for interface static method
jlahoda
parents:
diff
changeset
|
85 |
} |
534673718919
8025087: Annotation processing api returns default modifier for interface static method
jlahoda
parents:
diff
changeset
|
86 |
interface StaticMethodTest { |
534673718919
8025087: Annotation processing api returns default modifier for interface static method
jlahoda
parents:
diff
changeset
|
87 |
static void test() { } |
534673718919
8025087: Annotation processing api returns default modifier for interface static method
jlahoda
parents:
diff
changeset
|
88 |
} |
534673718919
8025087: Annotation processing api returns default modifier for interface static method
jlahoda
parents:
diff
changeset
|
89 |
} |