test/tools/javac/processing/model/element/TestAnonClassNames.java

changeset 1521
71f35e4b93a5
parent 1466
b52a38d4536c
child 2525
2eb010b6cb22
equal deleted inserted replaced
1520:5c956be64b9e 1521:71f35e4b93a5
1 /* 1 /*
2 * Copyright (c) 2010, 2011, Oracle and/or its affiliates. All rights reserved. 2 * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 * 4 *
5 * This code is free software; you can redistribute it and/or modify it 5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as 6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
76 76
77 public static void main(String... argv) { 77 public static void main(String... argv) {
78 @Nesting(LOCAL) 78 @Nesting(LOCAL)
79 class LocalClass{}; 79 class LocalClass{};
80 80
81 Object o = new /*@Nesting(ANONYMOUS)*/ Object() { // An anonymous annotated class 81 Object o = new @Nesting(ANONYMOUS) Object() { // An anonymous annotated class
82 public String toString() { 82 public String toString() {
83 return "I have no name!"; 83 return "I have no name!";
84 } 84 }
85 }; 85 };
86 86
94 }; 94 };
95 95
96 List<String> names = new ArrayList<String>(); 96 List<String> names = new ArrayList<String>();
97 for(Class<?> clazz : classes) { 97 for(Class<?> clazz : classes) {
98 String name = clazz.getName(); 98 String name = clazz.getName();
99 Nesting anno = clazz.getAnnotation(Nesting.class);
100 System.out.format("%s is %s%n", 99 System.out.format("%s is %s%n",
101 clazz.getName(), 100 clazz.getName(),
102 anno == null ? "(unset/ANONYMOUS)" : anno.value()); 101 clazz.getAnnotation(Nesting.class).value());
103 testClassName(name); 102 testClassName(name);
104 names.add(name); 103 names.add(name);
105 } 104 }
106 105
107 // test all names together 106 // test all names together
156 System.out.println("Error: " + msg); 155 System.out.println("Error: " + msg);
157 errors++; 156 errors++;
158 } 157 }
159 } 158 }
160 159
160 @Target({ElementType.TYPE, ElementType.TYPE_USE})
161 @Retention(RUNTIME) 161 @Retention(RUNTIME)
162 @interface Nesting { 162 @interface Nesting {
163 NestingKind value(); 163 NestingKind value();
164 } 164 }
165 165
183 System.out.printf("\tSimple name: ''%s''\tQualified Name: ''%s''\tKind ''%s''\tNesting ''%s''%n", 183 System.out.printf("\tSimple name: ''%s''\tQualified Name: ''%s''\tKind ''%s''\tNesting ''%s''%n",
184 typeElt.getSimpleName().toString(), 184 typeElt.getSimpleName().toString(),
185 typeElt.getQualifiedName().toString(), 185 typeElt.getQualifiedName().toString(),
186 typeElt.getKind().toString(), 186 typeElt.getKind().toString(),
187 nestingKind.toString()); 187 nestingKind.toString());
188 Nesting anno = typeElt.getAnnotation(Nesting.class); 188
189 if ((anno == null ? NestingKind.ANONYMOUS : anno.value()) != nestingKind) { 189 if (typeElt.getAnnotation(Nesting.class).value() != nestingKind) {
190 throw new RuntimeException("Mismatch of expected and reported nesting kind."); 190 throw new RuntimeException("Mismatch of expected and reported nesting kind.");
191 } 191 }
192 } 192 }
193 193
194 } 194 }

mercurial