36 */
37
38 import java.util.*;
39
40 public class InnerClassesInLocalClassTest extends InnerClassesTestBase {
41
42 private final static Modifier[] LOCAL_CLASS_MODIFIERS =
43 new Modifier[]{Modifier.EMPTY, Modifier.ABSTRACT, Modifier.FINAL};
44 private final static String CLASS_TEMPLATE =
45 "public %CLASS% OuterClass {\n" +
46 "%SOURCE%\n" +
47 "}";
48
49 private final List<Data> innerClassesData;
50
51 public InnerClassesInLocalClassTest() {
52 innerClassesData = new ArrayList<>();
53 for (Modifier outerModifier : LOCAL_CLASS_MODIFIERS) {
54 StringBuilder sb = new StringBuilder();
55 sb.append(outerModifier.getString()).append(' ');
56 sb.append("class Local {");
57 Map<String, Set<String>> class2Flags = new HashMap<>();
58 for (int i = 0; i < LOCAL_CLASS_MODIFIERS.length; ++i) {
59 Modifier innerModifier = LOCAL_CLASS_MODIFIERS[i];
60 sb.append(innerModifier.getString()).append(' ')
61 .append("class").append(' ')
62 .append('A').append(i).append("{}\n");
63 class2Flags.put("A" + i, getFlags(innerModifier));
64 }
65 sb.append("};");
66 class2Flags.put("1Local", getFlags(outerModifier));
67 innerClassesData.add(new Data(sb.toString(), class2Flags));
68 }
69 }
70
71 public static void main(String[] args) throws TestFailedException {
72 InnerClassesTestBase test = new InnerClassesInLocalClassTest();
73 test.test("OuterClass$1Local", "1Local");
74 }
75
76 @Override
134 list.addAll(generate(template,
135 String.format("%s %s void method() {",
136 modifier.getString(),
137 otherMod.getString()),
138 "}"));
139 }
140 }
141 return list;
142 }
143
144 private List<TestCase> staticAndInstanceInitializer(String template) {
145 List<TestCase> list = new ArrayList<>();
146 for (Modifier modifier : new Modifier[]{Modifier.EMPTY, Modifier.STATIC}) {
147 list.addAll(generate(template, modifier.getString() + "{", "}"));
148 }
149 return list;
150 }
151
152 private Set<String> getFlags(Modifier modifier) {
153 HashSet<String> set = new HashSet<>();
154 if (modifier != Modifier.EMPTY) {
155 set.add("ACC_" + modifier.getString().toUpperCase());
156 }
157 return set;
158 }
159
160 /**
161 * Class represents part of sources which is inserted in other code.
162 */
163 private static class Data {
164 public final String sources;
165 public final Map<String, Set<String>> class2Flags;
166
167 public Data(String sources, Map<String, Set<String>> class2Flags) {
168 this.sources = sources;
169 this.class2Flags = class2Flags;
170 }
171 }
172 }
|
36 */
37
38 import java.util.*;
39
40 public class InnerClassesInLocalClassTest extends InnerClassesTestBase {
41
42 private final static Modifier[] LOCAL_CLASS_MODIFIERS =
43 new Modifier[]{Modifier.EMPTY, Modifier.ABSTRACT, Modifier.FINAL};
44 private final static String CLASS_TEMPLATE =
45 "public %CLASS% OuterClass {\n" +
46 "%SOURCE%\n" +
47 "}";
48
49 private final List<Data> innerClassesData;
50
51 public InnerClassesInLocalClassTest() {
52 innerClassesData = new ArrayList<>();
53 for (Modifier outerModifier : LOCAL_CLASS_MODIFIERS) {
54 StringBuilder sb = new StringBuilder();
55 sb.append(outerModifier.getString()).append(' ');
56 sb.append("class Local { int f; "); // impose identity to make testing predictable.
57 Map<String, Set<String>> class2Flags = new HashMap<>();
58 for (int i = 0; i < LOCAL_CLASS_MODIFIERS.length; ++i) {
59 Modifier innerModifier = LOCAL_CLASS_MODIFIERS[i];
60 sb.append(innerModifier.getString()).append(' ')
61 .append("class").append(' ')
62 .append('A').append(i).append("{}\n");
63 class2Flags.put("A" + i, getFlags(innerModifier));
64 }
65 sb.append("};");
66 class2Flags.put("1Local", getFlags(outerModifier));
67 innerClassesData.add(new Data(sb.toString(), class2Flags));
68 }
69 }
70
71 public static void main(String[] args) throws TestFailedException {
72 InnerClassesTestBase test = new InnerClassesInLocalClassTest();
73 test.test("OuterClass$1Local", "1Local");
74 }
75
76 @Override
134 list.addAll(generate(template,
135 String.format("%s %s void method() {",
136 modifier.getString(),
137 otherMod.getString()),
138 "}"));
139 }
140 }
141 return list;
142 }
143
144 private List<TestCase> staticAndInstanceInitializer(String template) {
145 List<TestCase> list = new ArrayList<>();
146 for (Modifier modifier : new Modifier[]{Modifier.EMPTY, Modifier.STATIC}) {
147 list.addAll(generate(template, modifier.getString() + "{", "}"));
148 }
149 return list;
150 }
151
152 private Set<String> getFlags(Modifier modifier) {
153 HashSet<String> set = new HashSet<>();
154 set.add("ACC_IDENTITY");
155 if (modifier != Modifier.EMPTY) {
156 set.add("ACC_" + modifier.getString().toUpperCase());
157 }
158 return set;
159 }
160
161 /**
162 * Class represents part of sources which is inserted in other code.
163 */
164 private static class Data {
165 public final String sources;
166 public final Map<String, Set<String>> class2Flags;
167
168 public Data(String sources, Map<String, Set<String>> class2Flags) {
169 this.sources = sources;
170 this.class2Flags = class2Flags;
171 }
172 }
173 }
|