author | jlahoda |
Wed, 09 Oct 2013 13:09:31 +0200 | |
changeset 21006 | 534673718919 |
child 36526 | 3b41f1c69604 |
permissions | -rw-r--r-- |
21006
534673718919
8025087: Annotation processing api returns default modifier for interface static method
jlahoda
parents:
diff
changeset
|
1 |
/* |
534673718919
8025087: Annotation processing api returns default modifier for interface static method
jlahoda
parents:
diff
changeset
|
2 |
* Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. |
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 |
import com.sun.tools.classfile.*; |
534673718919
8025087: Annotation processing api returns default modifier for interface static method
jlahoda
parents:
diff
changeset
|
25 |
import com.sun.tools.classfile.ConstantPool.CONSTANT_Class_info; |
534673718919
8025087: Annotation processing api returns default modifier for interface static method
jlahoda
parents:
diff
changeset
|
26 |
import com.sun.tools.classfile.ConstantPool.CONSTANT_Utf8_info; |
534673718919
8025087: Annotation processing api returns default modifier for interface static method
jlahoda
parents:
diff
changeset
|
27 |
import com.sun.tools.classfile.ConstantPool.CPInfo; |
534673718919
8025087: Annotation processing api returns default modifier for interface static method
jlahoda
parents:
diff
changeset
|
28 |
import java.io.*; |
534673718919
8025087: Annotation processing api returns default modifier for interface static method
jlahoda
parents:
diff
changeset
|
29 |
import java.util.*; |
534673718919
8025087: Annotation processing api returns default modifier for interface static method
jlahoda
parents:
diff
changeset
|
30 |
import javax.annotation.processing.*; |
534673718919
8025087: Annotation processing api returns default modifier for interface static method
jlahoda
parents:
diff
changeset
|
31 |
import javax.lang.model.*; |
534673718919
8025087: Annotation processing api returns default modifier for interface static method
jlahoda
parents:
diff
changeset
|
32 |
import javax.lang.model.element.*; |
534673718919
8025087: Annotation processing api returns default modifier for interface static method
jlahoda
parents:
diff
changeset
|
33 |
import javax.tools.*; |
534673718919
8025087: Annotation processing api returns default modifier for interface static method
jlahoda
parents:
diff
changeset
|
34 |
|
534673718919
8025087: Annotation processing api returns default modifier for interface static method
jlahoda
parents:
diff
changeset
|
35 |
/* Create an invalid classfile with version 51.0 and a static method in an interface.*/ |
534673718919
8025087: Annotation processing api returns default modifier for interface static method
jlahoda
parents:
diff
changeset
|
36 |
@SupportedAnnotationTypes("*") |
534673718919
8025087: Annotation processing api returns default modifier for interface static method
jlahoda
parents:
diff
changeset
|
37 |
public class CreateBadClassFile extends AbstractProcessor { |
534673718919
8025087: Annotation processing api returns default modifier for interface static method
jlahoda
parents:
diff
changeset
|
38 |
public boolean process(Set<? extends TypeElement> elems, RoundEnvironment renv) { |
534673718919
8025087: Annotation processing api returns default modifier for interface static method
jlahoda
parents:
diff
changeset
|
39 |
if (++round == 1) { |
534673718919
8025087: Annotation processing api returns default modifier for interface static method
jlahoda
parents:
diff
changeset
|
40 |
ConstantPool cp = new ConstantPool(new CPInfo[] { |
534673718919
8025087: Annotation processing api returns default modifier for interface static method
jlahoda
parents:
diff
changeset
|
41 |
new CONSTANT_Utf8_info(""), //0 |
534673718919
8025087: Annotation processing api returns default modifier for interface static method
jlahoda
parents:
diff
changeset
|
42 |
new CONSTANT_Utf8_info("Test"), //1 |
534673718919
8025087: Annotation processing api returns default modifier for interface static method
jlahoda
parents:
diff
changeset
|
43 |
new CONSTANT_Class_info(null, 1), //2 |
534673718919
8025087: Annotation processing api returns default modifier for interface static method
jlahoda
parents:
diff
changeset
|
44 |
new CONSTANT_Utf8_info("java/lang/Object"), //3 |
534673718919
8025087: Annotation processing api returns default modifier for interface static method
jlahoda
parents:
diff
changeset
|
45 |
new CONSTANT_Class_info(null, 3), //4 |
534673718919
8025087: Annotation processing api returns default modifier for interface static method
jlahoda
parents:
diff
changeset
|
46 |
new CONSTANT_Utf8_info("test"), //5 |
534673718919
8025087: Annotation processing api returns default modifier for interface static method
jlahoda
parents:
diff
changeset
|
47 |
new CONSTANT_Utf8_info("()V"), //6 |
534673718919
8025087: Annotation processing api returns default modifier for interface static method
jlahoda
parents:
diff
changeset
|
48 |
}); |
534673718919
8025087: Annotation processing api returns default modifier for interface static method
jlahoda
parents:
diff
changeset
|
49 |
ClassFile cf = new ClassFile(0xCAFEBABE, |
534673718919
8025087: Annotation processing api returns default modifier for interface static method
jlahoda
parents:
diff
changeset
|
50 |
0, |
534673718919
8025087: Annotation processing api returns default modifier for interface static method
jlahoda
parents:
diff
changeset
|
51 |
51, |
534673718919
8025087: Annotation processing api returns default modifier for interface static method
jlahoda
parents:
diff
changeset
|
52 |
cp, |
534673718919
8025087: Annotation processing api returns default modifier for interface static method
jlahoda
parents:
diff
changeset
|
53 |
new AccessFlags(AccessFlags.ACC_ABSTRACT | |
534673718919
8025087: Annotation processing api returns default modifier for interface static method
jlahoda
parents:
diff
changeset
|
54 |
AccessFlags.ACC_INTERFACE | |
534673718919
8025087: Annotation processing api returns default modifier for interface static method
jlahoda
parents:
diff
changeset
|
55 |
AccessFlags.ACC_PUBLIC), |
534673718919
8025087: Annotation processing api returns default modifier for interface static method
jlahoda
parents:
diff
changeset
|
56 |
2, |
534673718919
8025087: Annotation processing api returns default modifier for interface static method
jlahoda
parents:
diff
changeset
|
57 |
4, |
534673718919
8025087: Annotation processing api returns default modifier for interface static method
jlahoda
parents:
diff
changeset
|
58 |
new int[0], |
534673718919
8025087: Annotation processing api returns default modifier for interface static method
jlahoda
parents:
diff
changeset
|
59 |
new Field[0], |
534673718919
8025087: Annotation processing api returns default modifier for interface static method
jlahoda
parents:
diff
changeset
|
60 |
new Method[] { |
534673718919
8025087: Annotation processing api returns default modifier for interface static method
jlahoda
parents:
diff
changeset
|
61 |
//creating static method in 51.0 classfile: |
534673718919
8025087: Annotation processing api returns default modifier for interface static method
jlahoda
parents:
diff
changeset
|
62 |
new Method(new AccessFlags(AccessFlags.ACC_PUBLIC | |
534673718919
8025087: Annotation processing api returns default modifier for interface static method
jlahoda
parents:
diff
changeset
|
63 |
AccessFlags.ACC_STATIC), |
534673718919
8025087: Annotation processing api returns default modifier for interface static method
jlahoda
parents:
diff
changeset
|
64 |
5, |
534673718919
8025087: Annotation processing api returns default modifier for interface static method
jlahoda
parents:
diff
changeset
|
65 |
new Descriptor(6), |
534673718919
8025087: Annotation processing api returns default modifier for interface static method
jlahoda
parents:
diff
changeset
|
66 |
new Attributes(cp, new Attribute[0])) |
534673718919
8025087: Annotation processing api returns default modifier for interface static method
jlahoda
parents:
diff
changeset
|
67 |
}, |
534673718919
8025087: Annotation processing api returns default modifier for interface static method
jlahoda
parents:
diff
changeset
|
68 |
new Attributes(cp, new Attribute[0])); |
534673718919
8025087: Annotation processing api returns default modifier for interface static method
jlahoda
parents:
diff
changeset
|
69 |
try { |
534673718919
8025087: Annotation processing api returns default modifier for interface static method
jlahoda
parents:
diff
changeset
|
70 |
JavaFileObject clazz = processingEnv.getFiler().createClassFile("Test"); |
534673718919
8025087: Annotation processing api returns default modifier for interface static method
jlahoda
parents:
diff
changeset
|
71 |
try (OutputStream out = clazz.openOutputStream()) { |
534673718919
8025087: Annotation processing api returns default modifier for interface static method
jlahoda
parents:
diff
changeset
|
72 |
new ClassWriter().write(cf, out); |
534673718919
8025087: Annotation processing api returns default modifier for interface static method
jlahoda
parents:
diff
changeset
|
73 |
} |
534673718919
8025087: Annotation processing api returns default modifier for interface static method
jlahoda
parents:
diff
changeset
|
74 |
} catch (IOException ex) { |
534673718919
8025087: Annotation processing api returns default modifier for interface static method
jlahoda
parents:
diff
changeset
|
75 |
ex.printStackTrace(); |
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 |
return false; |
534673718919
8025087: Annotation processing api returns default modifier for interface static method
jlahoda
parents:
diff
changeset
|
79 |
} |
534673718919
8025087: Annotation processing api returns default modifier for interface static method
jlahoda
parents:
diff
changeset
|
80 |
|
534673718919
8025087: Annotation processing api returns default modifier for interface static method
jlahoda
parents:
diff
changeset
|
81 |
public SourceVersion getSupportedSourceVersion() { |
534673718919
8025087: Annotation processing api returns default modifier for interface static method
jlahoda
parents:
diff
changeset
|
82 |
return SourceVersion.latest(); |
534673718919
8025087: Annotation processing api returns default modifier for interface static method
jlahoda
parents:
diff
changeset
|
83 |
} |
534673718919
8025087: Annotation processing api returns default modifier for interface static method
jlahoda
parents:
diff
changeset
|
84 |
|
534673718919
8025087: Annotation processing api returns default modifier for interface static method
jlahoda
parents:
diff
changeset
|
85 |
int round = 0; |
534673718919
8025087: Annotation processing api returns default modifier for interface static method
jlahoda
parents:
diff
changeset
|
86 |
} |