author | jlahoda |
Tue, 17 Dec 2013 10:55:59 +0100 | |
changeset 22153 | f9f06fcca59d |
parent 18000 | 5d29ce00a7a2 |
child 22442 | 8fd30fc4e3a3 |
permissions | -rw-r--r-- |
4077
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
1 |
/* |
18000
5d29ce00a7a2
6695379: Copy method annotations and parameter annotations to synthetic bridge methods
vromero
parents:
14359
diff
changeset
|
2 |
* Copyright (c) 2009, 2013, Oracle and/or its affiliates. All rights reserved. |
4077
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
4 |
* |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
8 |
* |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
13 |
* accompanied this code). |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
14 |
* |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
18 |
* |
5520 | 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. |
|
4077
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
22 |
*/ |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
23 |
|
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
24 |
/* |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
25 |
* @test |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
26 |
* @bug 6889255 |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
27 |
* @summary ClassReader does not read parameter names correctly |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
28 |
*/ |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
29 |
|
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
30 |
import java.io.*; |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
31 |
import java.util.*; |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
32 |
import javax.tools.StandardLocation; |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
33 |
import com.sun.tools.javac.code.Flags; |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
34 |
import com.sun.tools.javac.code.Kinds; |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
35 |
import com.sun.tools.javac.code.Scope; |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
36 |
import com.sun.tools.javac.code.Symbol.*; |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
37 |
import com.sun.tools.javac.code.Type; |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
38 |
import com.sun.tools.javac.code.Type.ClassType; |
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
5520
diff
changeset
|
39 |
import com.sun.tools.javac.code.TypeTag; |
4077
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
40 |
import com.sun.tools.javac.file.JavacFileManager; |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
41 |
import com.sun.tools.javac.jvm.ClassReader; |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
42 |
import com.sun.tools.javac.util.Context; |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
43 |
import com.sun.tools.javac.util.Names; |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
44 |
|
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
45 |
public class T6889255 { |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
46 |
boolean testInterfaces = true; |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
47 |
boolean testSyntheticMethods = true; |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
48 |
|
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
49 |
// The following enums control the generation of the test methods to be compiled. |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
50 |
enum GenericKind { |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
51 |
NOT_GENERIC, |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
52 |
GENERIC |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
53 |
}; |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
54 |
|
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
55 |
enum ClassKind { |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
56 |
CLASS("Clss"), |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
57 |
INTERFACE("Intf"), |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
58 |
ENUM("Enum"); |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
59 |
final String base; |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
60 |
ClassKind(String base) { this.base = base; } |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
61 |
}; |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
62 |
|
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
63 |
enum NestedKind { |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
64 |
/** Declare methods inside the outermost container. */ |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
65 |
NONE, |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
66 |
/** Declare methods inside a container with a 'static' modifier. */ |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
67 |
NESTED, |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
68 |
/** Declare methods inside a container without a 'static' modifier. */ |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
69 |
INNER, |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
70 |
/** Declare methods inside a local class in an initializer. */ |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
71 |
INIT_LOCAL, |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
72 |
/** Declare methods inside an anonymous class in an initializer. */ |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
73 |
INIT_ANON, |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
74 |
/** Declare methods inside a local class in a method. */ |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
75 |
METHOD_LOCAL, |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
76 |
/** Declare methods inside an anonymous class in a method. */ |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
77 |
METHOD_ANON |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
78 |
}; |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
79 |
|
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
80 |
enum MethodKind { |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
81 |
ABSTRACT, |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
82 |
CONSTRUCTOR, |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
83 |
METHOD, |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
84 |
STATIC_METHOD, |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
85 |
BRIDGE_METHOD |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
86 |
}; |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
87 |
|
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
88 |
enum FinalKind { |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
89 |
/** Method body does not reference external final variables. */ |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
90 |
NO_FINAL, |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
91 |
/** Method body references external final variables. */ |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
92 |
USE_FINAL |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
93 |
}; |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
94 |
|
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
95 |
public static void main(String... args) throws Exception { |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
96 |
new T6889255().run(); |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
97 |
} |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
98 |
|
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
99 |
void run() throws Exception { |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
100 |
genTest(); |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
101 |
|
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
102 |
test("no-args", false); |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
103 |
test("g", true, "-g"); |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
104 |
|
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
105 |
if (errors > 0) |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
106 |
throw new Exception(errors + " errors found"); |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
107 |
} |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
108 |
|
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
109 |
/** |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
110 |
* Create a file containing lots of method definitions to be tested. |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
111 |
* There are 3 sets of nested loops that generate the methods. |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
112 |
* 1. The outermost set declares [generic] (class | interface | enum) |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
113 |
* 2. The middle set declares [(nested | inner | anon | local)] class |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
114 |
* 3. The innermost set declares |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
115 |
* [generic] (constructor|method|static-method|bridge-method) [using final variables in outer scope] |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
116 |
* Invalid combinations are filtered out. |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
117 |
*/ |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
118 |
void genTest() throws Exception { |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
119 |
BufferedWriter out = new BufferedWriter(new FileWriter("Test.java")); |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
120 |
|
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
121 |
// This interface is used to force bridge methods to be generated, by |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
122 |
// implementing its methods with subtypes of Object |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
123 |
out.write("interface Base {\n"); |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
124 |
out.write(" Object base_m1(int i1);\n"); |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
125 |
out.write(" Object base_m2(int i1);\n"); |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
126 |
out.write("}\n"); |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
127 |
|
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
128 |
int outerNum = 0; |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
129 |
// Outermost set of loops, to generate a top level container |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
130 |
for (GenericKind outerGenericKind: GenericKind.values()) { |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
131 |
for (ClassKind outerClassKind: ClassKind.values()) { |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
132 |
if (outerGenericKind == GenericKind.GENERIC && outerClassKind == ClassKind.ENUM) |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
133 |
continue; |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
134 |
String outerClassName = outerClassKind.base + (outerNum++); |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
135 |
String outerTypeArg = outerClassKind.toString().charAt(0) + "T"; |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
136 |
if (outerClassKind == ClassKind.CLASS) |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
137 |
out.write("abstract "); |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
138 |
out.write(outerClassKind.toString().toLowerCase() + " " + outerClassName); |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
139 |
if (outerGenericKind == GenericKind.GENERIC) |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
140 |
out.write("<" + outerTypeArg + ">"); |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
141 |
if (outerClassKind == ClassKind.INTERFACE) |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
142 |
out.write(" extends Base"); |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
143 |
else |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
144 |
out.write(" implements Base"); |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
145 |
out.write(" {\n"); |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
146 |
if (outerClassKind == ClassKind.ENUM) { |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
147 |
out.write(" E1(0,0,0), E2(0,0,0), E3(0,0,0);\n"); |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
148 |
out.write(" " + outerClassName + "(int i1, int i2, int i3) { }\n"); |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
149 |
} |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
150 |
// Middle set of loops, to generate an optional nested container |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
151 |
int nestedNum = 0; |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
152 |
int methodNum = 0; |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
153 |
for (GenericKind nestedGenericKind: GenericKind.values()) { |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
154 |
nextNestedKind: |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
155 |
for (NestedKind nestedKind: NestedKind.values()) { |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
156 |
// if the nested kind is none, there is no point iterating over all |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
157 |
// nested generic kinds, so arbitarily limit it to just one kind |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
158 |
if (nestedKind == NestedKind.NONE && nestedGenericKind != GenericKind.NOT_GENERIC) |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
159 |
continue; |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
160 |
if ((nestedKind == NestedKind.METHOD_ANON || nestedKind == NestedKind.INIT_ANON) |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
161 |
&& nestedGenericKind == GenericKind.GENERIC) |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
162 |
continue; |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
163 |
String indent = " "; |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
164 |
boolean haveFinal = false; |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
165 |
switch (nestedKind) { |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
166 |
case METHOD_ANON: case METHOD_LOCAL: |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
167 |
if (outerClassKind == ClassKind.INTERFACE) |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
168 |
continue nextNestedKind; |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
169 |
out.write(indent + "void m" + + (nestedNum++) + "() {\n"); |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
170 |
indent += " "; |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
171 |
out.write(indent + "final int fi1 = 0;\n"); |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
172 |
haveFinal = true; |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
173 |
break; |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
174 |
case INIT_ANON: case INIT_LOCAL: |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
175 |
if (outerClassKind == ClassKind.INTERFACE) |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
176 |
continue nextNestedKind; |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
177 |
out.write(indent + "{\n"); |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
178 |
indent += " "; |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
179 |
break; |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
180 |
} |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
181 |
for (ClassKind nestedClassKind: ClassKind.values()) { |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
182 |
if ((nestedGenericKind == GenericKind.GENERIC) |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
183 |
&& (nestedClassKind == ClassKind.ENUM)) |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
184 |
continue; |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
185 |
if ((nestedKind == NestedKind.METHOD_ANON || nestedKind == NestedKind.METHOD_LOCAL |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
186 |
|| nestedKind == NestedKind.INIT_ANON || nestedKind == NestedKind.INIT_LOCAL) |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
187 |
&& nestedClassKind != ClassKind.CLASS) |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
188 |
continue; |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
189 |
// if the nested kind is none, there is no point iterating over all |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
190 |
// nested class kinds, so arbitarily limit it to just one kind |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
191 |
if (nestedKind == NestedKind.NONE && nestedClassKind != ClassKind.CLASS) |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
192 |
continue; |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
193 |
|
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
194 |
ClassKind methodClassKind; |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
195 |
String methodClassName; |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
196 |
boolean allowAbstractMethods; |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
197 |
boolean allowStaticMethods; |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
198 |
switch (nestedKind) { |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
199 |
case NONE: |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
200 |
methodClassKind = outerClassKind; |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
201 |
methodClassName = outerClassName; |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
202 |
allowAbstractMethods = (outerClassKind == ClassKind.CLASS); |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
203 |
allowStaticMethods = (outerClassKind != ClassKind.INTERFACE); |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
204 |
break; |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
205 |
case METHOD_ANON: |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
206 |
case INIT_ANON: |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
207 |
out.write(indent + "new Base() {\n"); |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
208 |
indent += " "; |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
209 |
methodClassKind = ClassKind.CLASS; |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
210 |
methodClassName = null; |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
211 |
allowAbstractMethods = false; |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
212 |
allowStaticMethods = false; |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
213 |
break; |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
214 |
default: { // INNER, NESTED, LOCAL |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
215 |
String nestedClassName = "N" + nestedClassKind.base + (nestedNum++); |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
216 |
String nestedTypeArg = nestedClassKind.toString().charAt(0) + "T"; |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
217 |
out.write(indent); |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
218 |
if (nestedKind == NestedKind.NESTED) |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
219 |
out.write("static "); |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
220 |
if (nestedClassKind == ClassKind.CLASS) |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
221 |
out.write("abstract "); |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
222 |
out.write(nestedClassKind.toString().toLowerCase() + " " + nestedClassName); |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
223 |
if (nestedGenericKind == GenericKind.GENERIC) |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
224 |
out.write("<" + nestedTypeArg + ">"); |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
225 |
if (nestedClassKind == ClassKind.INTERFACE) |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
226 |
out.write(" extends Base "); |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
227 |
else |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
228 |
out.write(" implements Base "); |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
229 |
out.write(" {\n"); |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
230 |
indent += " "; |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
231 |
if (nestedClassKind == ClassKind.ENUM) { |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
232 |
out.write(indent + "E1(0,0,0), E2(0,0,0), E3(0,0,0);\n"); |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
233 |
out.write(indent + nestedClassName + "(int i1, int i2, int i3) { }\n"); |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
234 |
} |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
235 |
methodClassKind = nestedClassKind; |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
236 |
methodClassName = nestedClassName; |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
237 |
allowAbstractMethods = (nestedClassKind == ClassKind.CLASS); |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
238 |
allowStaticMethods = (nestedKind == NestedKind.NESTED && nestedClassKind != ClassKind.INTERFACE); |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
239 |
break; |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
240 |
} |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
241 |
} |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
242 |
|
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
243 |
// Innermost loops, to generate methods |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
244 |
for (GenericKind methodGenericKind: GenericKind.values()) { |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
245 |
for (FinalKind finalKind: FinalKind.values()) { |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
246 |
for (MethodKind methodKind: MethodKind.values()) { |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
247 |
// out.write("// " + outerGenericKind |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
248 |
// + " " + outerClassKind |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
249 |
// + " " + nestedKind |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
250 |
// + " " + nestedGenericKind |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
251 |
// + " " + nestedClassKind |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
252 |
// + " " + methodGenericKind |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
253 |
// + " " + finalKind |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
254 |
// + " " + methodKind |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
255 |
// + "\n"); |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
256 |
switch (methodKind) { |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
257 |
case CONSTRUCTOR: |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
258 |
if (nestedKind == NestedKind.METHOD_ANON || nestedKind == NestedKind.INIT_ANON) |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
259 |
break; |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
260 |
if (methodClassKind != ClassKind.CLASS) |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
261 |
break; |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
262 |
if (finalKind == FinalKind.USE_FINAL && !haveFinal) |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
263 |
break; |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
264 |
out.write(indent); |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
265 |
if (methodGenericKind == GenericKind.GENERIC) { |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
266 |
out.write("<CT> " + methodClassName + "(CT c1, CT c2"); |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
267 |
} else { |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
268 |
out.write(methodClassName + "(boolean b1, char c2"); |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
269 |
} |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
270 |
if (finalKind == FinalKind.USE_FINAL) { |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
271 |
// add a dummy parameter to avoid duplicate declaration |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
272 |
out.write(", int i3) { int i = fi1; }\n"); |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
273 |
} else |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
274 |
out.write(") { }\n"); |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
275 |
break; |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
276 |
case ABSTRACT: |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
277 |
if (!allowAbstractMethods) |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
278 |
continue; |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
279 |
// fallthrough |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
280 |
case METHOD: |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
281 |
if (finalKind == FinalKind.USE_FINAL && !haveFinal) |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
282 |
break; |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
283 |
out.write(indent); |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
284 |
if (methodKind == MethodKind.ABSTRACT) |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
285 |
out.write("abstract "); |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
286 |
if (methodGenericKind == GenericKind.GENERIC) |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
287 |
out.write("<MT> "); |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
288 |
out.write("void m" + (methodNum++) + "(int i1, long l2, float f3)"); |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
289 |
if (methodKind == MethodKind.ABSTRACT || methodClassKind == ClassKind.INTERFACE) |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
290 |
out.write(";\n"); |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
291 |
else { |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
292 |
out.write(" {"); |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
293 |
if (finalKind == FinalKind.USE_FINAL) |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
294 |
out.write(" int i = fi1;"); |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
295 |
out.write(" }\n"); |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
296 |
} |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
297 |
break; |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
298 |
case BRIDGE_METHOD: |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
299 |
if (methodGenericKind == GenericKind.GENERIC) |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
300 |
break; |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
301 |
out.write(indent); |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
302 |
// methods Base.base_m1 and Base.base_m2 are declared for the |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
303 |
// benefit of bridge methods. They need to be implemented |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
304 |
// whether or not a final variable is used. |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
305 |
String methodName = (finalKind == FinalKind.NO_FINAL ? "base_m1" : "base_m2"); |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
306 |
out.write("public String " + methodName + "(int i1)"); |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
307 |
if (methodClassKind == ClassKind.INTERFACE) |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
308 |
out.write(";\n"); |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
309 |
else { |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
310 |
out.write(" {"); |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
311 |
if (finalKind == FinalKind.USE_FINAL && haveFinal) |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
312 |
out.write(" int i = fi1;"); |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
313 |
out.write(" return null; }\n"); |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
314 |
} |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
315 |
break; |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
316 |
case STATIC_METHOD: |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
317 |
if (!allowStaticMethods) |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
318 |
break; |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
319 |
if (finalKind == FinalKind.USE_FINAL && !haveFinal) |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
320 |
break; |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
321 |
out.write(indent + "static "); |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
322 |
if (methodGenericKind == GenericKind.GENERIC) |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
323 |
out.write("<MT> "); |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
324 |
out.write("void m" + (methodNum++) + "(int i1, long l2, float f3) {"); |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
325 |
if (finalKind == FinalKind.USE_FINAL) |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
326 |
out.write(" int i = fi1;"); |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
327 |
out.write(" }\n"); |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
328 |
break; |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
329 |
} |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
330 |
|
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
331 |
} |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
332 |
} |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
333 |
} |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
334 |
if (nestedKind != NestedKind.NONE) { |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
335 |
indent = indent.substring(0, indent.length() - 4); |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
336 |
out.write(indent + "};\n"); |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
337 |
} |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
338 |
} |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
339 |
switch (nestedKind) { |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
340 |
case METHOD_ANON: case METHOD_LOCAL: |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
341 |
case INIT_ANON: case INIT_LOCAL: |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
342 |
indent = indent.substring(0, indent.length() - 4); |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
343 |
out.write(indent + "}\n\n"); |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
344 |
} |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
345 |
} |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
346 |
} |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
347 |
out.write("}\n\n"); |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
348 |
} |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
349 |
} |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
350 |
out.close(); |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
351 |
} |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
352 |
|
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
353 |
|
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
354 |
void test(String testName, boolean expectNames, String... opts) throws Exception { |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
355 |
System.err.println("Test " + testName |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
356 |
+ ": expectNames:" + expectNames |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
357 |
+ " javacOpts:" + Arrays.asList(opts)); |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
358 |
|
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
359 |
File outDir = new File(testName); |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
360 |
outDir.mkdirs(); |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
361 |
compile(outDir, opts); |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
362 |
|
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
363 |
Context ctx = new Context(); |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
364 |
JavacFileManager fm = new JavacFileManager(ctx, true, null); |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
365 |
fm.setLocation(StandardLocation.CLASS_PATH, Arrays.asList(outDir)); |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
366 |
ClassReader cr = ClassReader.instance(ctx); |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
367 |
cr.saveParameterNames = true; |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
368 |
Names names = Names.instance(ctx); |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
369 |
|
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
370 |
Set<String> classes = getTopLevelClasses(outDir); |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
371 |
Deque<String> work = new LinkedList<String>(classes); |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
372 |
String classname; |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
373 |
while ((classname = work.poll()) != null) { |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
374 |
System.err.println("Checking class " + classname); |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
375 |
ClassSymbol sym = cr.enterClass(names.table.fromString(classname)); |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
376 |
sym.complete(); |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
377 |
|
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
378 |
if ((sym.flags() & Flags.INTERFACE) != 0 && !testInterfaces) |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
379 |
continue; |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
380 |
|
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
381 |
for (Scope.Entry e = sym.members_field.elems; e != null; e = e.sibling) { |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
382 |
System.err.println("Checking member " + e.sym); |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
383 |
switch (e.sym.kind) { |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
384 |
case Kinds.TYP: { |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
385 |
String name = e.sym.flatName().toString(); |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
386 |
if (!classes.contains(name)) { |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
387 |
classes.add(name); |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
388 |
work.add(name); |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
389 |
} |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
390 |
break; |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
391 |
} |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
392 |
case Kinds.MTH: |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
393 |
verify((MethodSymbol) e.sym, expectNames); |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
394 |
break; |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
395 |
} |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
396 |
|
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
397 |
} |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
398 |
} |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
399 |
} |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
400 |
|
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
401 |
void verify(MethodSymbol m, boolean expectNames) { |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
402 |
if ((m.flags() & Flags.SYNTHETIC) != 0 && !testSyntheticMethods) |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
403 |
return; |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
404 |
|
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
405 |
//System.err.println("verify: " + m.params()); |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
406 |
int i = 1; |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
407 |
for (VarSymbol v: m.params()) { |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
408 |
String expectName; |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
409 |
if (expectNames) |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
410 |
expectName = getExpectedName(v, i); |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
411 |
else |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
412 |
expectName = "arg" + (i - 1); |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
413 |
checkEqual(expectName, v.name.toString()); |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
414 |
i++; |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
415 |
} |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
416 |
} |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
417 |
|
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
418 |
String getExpectedName(VarSymbol v, int i) { |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
419 |
// special cases: |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
420 |
// synthetic method |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
421 |
if (((v.owner.owner.flags() & Flags.ENUM) != 0) |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
422 |
&& v.owner.name.toString().equals("valueOf")) |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
423 |
return "name"; |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
424 |
// interfaces don't have saved names |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
425 |
// -- no Code attribute for the LocalVariableTable attribute |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
426 |
if ((v.owner.owner.flags() & Flags.INTERFACE) != 0) |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
427 |
return "arg" + (i - 1); |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
428 |
// abstract methods don't have saved names |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
429 |
// -- no Code attribute for the LocalVariableTable attribute |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
430 |
if ((v.owner.flags() & Flags.ABSTRACT) != 0) |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
431 |
return "arg" + (i - 1); |
18000
5d29ce00a7a2
6695379: Copy method annotations and parameter annotations to synthetic bridge methods
vromero
parents:
14359
diff
changeset
|
432 |
// bridge methods use argN. No LVT for them anymore |
4077
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
433 |
if ((v.owner.flags() & Flags.BRIDGE) != 0) |
18000
5d29ce00a7a2
6695379: Copy method annotations and parameter annotations to synthetic bridge methods
vromero
parents:
14359
diff
changeset
|
434 |
return "arg" + (i - 1); |
4077
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
435 |
|
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
436 |
// The rest of this method assumes the local conventions in the test program |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
437 |
Type t = v.type; |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
438 |
String s; |
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
5520
diff
changeset
|
439 |
if (t.hasTag(TypeTag.CLASS)) |
4077
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
440 |
s = ((ClassType) t).tsym.name.toString(); |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
441 |
else |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
442 |
s = t.toString(); |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
443 |
return String.valueOf(Character.toLowerCase(s.charAt(0))) + i; |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
444 |
} |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
445 |
|
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
446 |
void compile(File outDir, String... opts) throws Exception { |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
447 |
//File testSrc = new File(System.getProperty("test.src"), "."); |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
448 |
List<String> args = new ArrayList<String>(); |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
449 |
args.add("-d"); |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
450 |
args.add(outDir.getPath()); |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
451 |
args.addAll(Arrays.asList(opts)); |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
452 |
//args.add(new File(testSrc, "Test.java").getPath()); |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
453 |
args.add("Test.java"); |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
454 |
StringWriter sw = new StringWriter(); |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
455 |
PrintWriter pw = new PrintWriter(sw); |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
456 |
int rc = com.sun.tools.javac.Main.compile(args.toArray(new String[args.size()]), pw); |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
457 |
pw.close(); |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
458 |
if (rc != 0) { |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
459 |
System.err.println(sw.toString()); |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
460 |
throw new Exception("compilation failed unexpectedly"); |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
461 |
} |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
462 |
} |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
463 |
|
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
464 |
Set<String> getTopLevelClasses(File outDir) { |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
465 |
Set<String> classes = new HashSet<String>(); |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
466 |
for (String f: outDir.list()) { |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
467 |
if (f.endsWith(".class") && !f.contains("$")) |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
468 |
classes.add(f.replace(".class", "")); |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
469 |
} |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
470 |
return classes; |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
471 |
} |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
472 |
|
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
473 |
void checkEqual(String expect, String found) { |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
474 |
if (!expect.equals(found)) |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
475 |
error("mismatch: expected:" + expect + " found:" + found); |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
476 |
} |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
477 |
|
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
478 |
void error(String msg) { |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
479 |
System.err.println(msg); |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
480 |
errors++; |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
481 |
throw new Error(); |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
482 |
} |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
483 |
|
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
484 |
int errors; |
0096541a388e
6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents:
diff
changeset
|
485 |
} |