< prev index next >

test/langtools/tools/javac/classfiles/attributes/innerclasses/InnerClassesInLocalClassTest.java

Print this page

 35  */
 36 
 37 import java.util.*;
 38 
 39 public class InnerClassesInLocalClassTest extends InnerClassesTestBase {
 40 
 41     private final static Modifier[] LOCAL_CLASS_MODIFIERS =
 42             new Modifier[]{Modifier.EMPTY, Modifier.ABSTRACT, Modifier.FINAL};
 43     private final static String CLASS_TEMPLATE =
 44             "public %CLASS% OuterClass {\n" +
 45             "%SOURCE%\n" +
 46             "}";
 47 
 48     private final List<Data> innerClassesData;
 49 
 50     public InnerClassesInLocalClassTest() {
 51         innerClassesData = new ArrayList<>();
 52         for (Modifier outerModifier : LOCAL_CLASS_MODIFIERS) {
 53             StringBuilder sb = new StringBuilder();
 54             sb.append(outerModifier.getString()).append(' ');
 55             sb.append("class Local {");
 56             Map<String, Set<String>> class2Flags = new HashMap<>();
 57             for (int i = 0; i < LOCAL_CLASS_MODIFIERS.length; ++i) {
 58                 Modifier innerModifier = LOCAL_CLASS_MODIFIERS[i];
 59                 sb.append(innerModifier.getString()).append(' ')
 60                         .append("class").append(' ')
 61                         .append('A').append(i).append("{}\n");
 62                 class2Flags.put("A" + i, getFlags(innerModifier));
 63             }
 64             sb.append("};");
 65             class2Flags.put("1Local", getFlags(outerModifier));
 66             innerClassesData.add(new Data(sb.toString(), class2Flags));
 67         }
 68     }
 69 
 70     public static void main(String[] args) throws TestFailedException {
 71         InnerClassesTestBase test = new InnerClassesInLocalClassTest();
 72         test.test("OuterClass$1Local", "1Local");
 73     }
 74 
 75     @Override

133                 list.addAll(generate(template,
134                         String.format("%s %s void method() {",
135                                 modifier.getString(),
136                                 otherMod.getString()),
137                         "}"));
138             }
139         }
140         return list;
141     }
142 
143     private List<TestCase> staticAndInstanceInitializer(String template) {
144         List<TestCase> list = new ArrayList<>();
145         for (Modifier modifier : new Modifier[]{Modifier.EMPTY, Modifier.STATIC}) {
146             list.addAll(generate(template, modifier.getString() + "{", "}"));
147         }
148         return list;
149     }
150 
151     private Set<String> getFlags(Modifier modifier) {
152         HashSet<String> set = new HashSet<>();

153         if (modifier != Modifier.EMPTY) {
154             set.add("ACC_" + modifier.getString().toUpperCase());
155         }
156         return set;
157     }
158 
159     /**
160      * Class represents part of sources which is inserted in other code.
161      */
162     private static class Data {
163         public final String sources;
164         public final Map<String, Set<String>> class2Flags;
165 
166         public Data(String sources, Map<String, Set<String>> class2Flags) {
167             this.sources = sources;
168             this.class2Flags = class2Flags;
169         }
170     }
171 }

 35  */
 36 
 37 import java.util.*;
 38 
 39 public class InnerClassesInLocalClassTest extends InnerClassesTestBase {
 40 
 41     private final static Modifier[] LOCAL_CLASS_MODIFIERS =
 42             new Modifier[]{Modifier.EMPTY, Modifier.ABSTRACT, Modifier.FINAL};
 43     private final static String CLASS_TEMPLATE =
 44             "public %CLASS% OuterClass {\n" +
 45             "%SOURCE%\n" +
 46             "}";
 47 
 48     private final List<Data> innerClassesData;
 49 
 50     public InnerClassesInLocalClassTest() {
 51         innerClassesData = new ArrayList<>();
 52         for (Modifier outerModifier : LOCAL_CLASS_MODIFIERS) {
 53             StringBuilder sb = new StringBuilder();
 54             sb.append(outerModifier.getString()).append(' ');
 55             sb.append("class Local { int f; "); // impose identity to make testing predictable.
 56             Map<String, Set<String>> class2Flags = new HashMap<>();
 57             for (int i = 0; i < LOCAL_CLASS_MODIFIERS.length; ++i) {
 58                 Modifier innerModifier = LOCAL_CLASS_MODIFIERS[i];
 59                 sb.append(innerModifier.getString()).append(' ')
 60                         .append("class").append(' ')
 61                         .append('A').append(i).append("{}\n");
 62                 class2Flags.put("A" + i, getFlags(innerModifier));
 63             }
 64             sb.append("};");
 65             class2Flags.put("1Local", getFlags(outerModifier));
 66             innerClassesData.add(new Data(sb.toString(), class2Flags));
 67         }
 68     }
 69 
 70     public static void main(String[] args) throws TestFailedException {
 71         InnerClassesTestBase test = new InnerClassesInLocalClassTest();
 72         test.test("OuterClass$1Local", "1Local");
 73     }
 74 
 75     @Override

133                 list.addAll(generate(template,
134                         String.format("%s %s void method() {",
135                                 modifier.getString(),
136                                 otherMod.getString()),
137                         "}"));
138             }
139         }
140         return list;
141     }
142 
143     private List<TestCase> staticAndInstanceInitializer(String template) {
144         List<TestCase> list = new ArrayList<>();
145         for (Modifier modifier : new Modifier[]{Modifier.EMPTY, Modifier.STATIC}) {
146             list.addAll(generate(template, modifier.getString() + "{", "}"));
147         }
148         return list;
149     }
150 
151     private Set<String> getFlags(Modifier modifier) {
152         HashSet<String> set = new HashSet<>();
153         set.add("ACC_IDENTITY");
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 }
< prev index next >