author | jjg |
Tue, 19 Oct 2010 15:02:48 -0700 | |
changeset 7072 | 4863847e93a5 |
parent 6720 | f16f91662ad8 |
child 8851 | e630c590eb10 |
permissions | -rw-r--r-- |
5012
405341b6e9c5
6449781: TypeElement.getQualifiedName for anonymous classes returns null instead of an empty name
darcy
parents:
diff
changeset
|
1 |
/* |
5520 | 2 |
* Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. |
5012
405341b6e9c5
6449781: TypeElement.getQualifiedName for anonymous classes returns null instead of an empty name
darcy
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
405341b6e9c5
6449781: TypeElement.getQualifiedName for anonymous classes returns null instead of an empty name
darcy
parents:
diff
changeset
|
4 |
* |
405341b6e9c5
6449781: TypeElement.getQualifiedName for anonymous classes returns null instead of an empty name
darcy
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
405341b6e9c5
6449781: TypeElement.getQualifiedName for anonymous classes returns null instead of an empty name
darcy
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
405341b6e9c5
6449781: TypeElement.getQualifiedName for anonymous classes returns null instead of an empty name
darcy
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
405341b6e9c5
6449781: TypeElement.getQualifiedName for anonymous classes returns null instead of an empty name
darcy
parents:
diff
changeset
|
8 |
* |
405341b6e9c5
6449781: TypeElement.getQualifiedName for anonymous classes returns null instead of an empty name
darcy
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
405341b6e9c5
6449781: TypeElement.getQualifiedName for anonymous classes returns null instead of an empty name
darcy
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
405341b6e9c5
6449781: TypeElement.getQualifiedName for anonymous classes returns null instead of an empty name
darcy
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
405341b6e9c5
6449781: TypeElement.getQualifiedName for anonymous classes returns null instead of an empty name
darcy
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
405341b6e9c5
6449781: TypeElement.getQualifiedName for anonymous classes returns null instead of an empty name
darcy
parents:
diff
changeset
|
13 |
* accompanied this code). |
405341b6e9c5
6449781: TypeElement.getQualifiedName for anonymous classes returns null instead of an empty name
darcy
parents:
diff
changeset
|
14 |
* |
405341b6e9c5
6449781: TypeElement.getQualifiedName for anonymous classes returns null instead of an empty name
darcy
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
405341b6e9c5
6449781: TypeElement.getQualifiedName for anonymous classes returns null instead of an empty name
darcy
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
405341b6e9c5
6449781: TypeElement.getQualifiedName for anonymous classes returns null instead of an empty name
darcy
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
405341b6e9c5
6449781: TypeElement.getQualifiedName for anonymous classes returns null instead of an empty name
darcy
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. |
|
5012
405341b6e9c5
6449781: TypeElement.getQualifiedName for anonymous classes returns null instead of an empty name
darcy
parents:
diff
changeset
|
22 |
*/ |
405341b6e9c5
6449781: TypeElement.getQualifiedName for anonymous classes returns null instead of an empty name
darcy
parents:
diff
changeset
|
23 |
|
405341b6e9c5
6449781: TypeElement.getQualifiedName for anonymous classes returns null instead of an empty name
darcy
parents:
diff
changeset
|
24 |
/* |
405341b6e9c5
6449781: TypeElement.getQualifiedName for anonymous classes returns null instead of an empty name
darcy
parents:
diff
changeset
|
25 |
* @test |
405341b6e9c5
6449781: TypeElement.getQualifiedName for anonymous classes returns null instead of an empty name
darcy
parents:
diff
changeset
|
26 |
* @bug 6449781 |
405341b6e9c5
6449781: TypeElement.getQualifiedName for anonymous classes returns null instead of an empty name
darcy
parents:
diff
changeset
|
27 |
* @summary Test that reported names of anonymous classes are non-null. |
405341b6e9c5
6449781: TypeElement.getQualifiedName for anonymous classes returns null instead of an empty name
darcy
parents:
diff
changeset
|
28 |
* @author Joseph D. Darcy |
6720 | 29 |
* @library ../../../lib |
30 |
* @build JavacTestingAbstractProcessor TestAnonSourceNames |
|
6590
f745e683da2c
6930507: Symbols for anonymous and local classes made too late for use by java tree API
jjg
parents:
5520
diff
changeset
|
31 |
* @compile -processor TestAnonSourceNames TestAnonClassNames.java |
5012
405341b6e9c5
6449781: TypeElement.getQualifiedName for anonymous classes returns null instead of an empty name
darcy
parents:
diff
changeset
|
32 |
* @run main TestAnonClassNames |
405341b6e9c5
6449781: TypeElement.getQualifiedName for anonymous classes returns null instead of an empty name
darcy
parents:
diff
changeset
|
33 |
*/ |
405341b6e9c5
6449781: TypeElement.getQualifiedName for anonymous classes returns null instead of an empty name
darcy
parents:
diff
changeset
|
34 |
|
405341b6e9c5
6449781: TypeElement.getQualifiedName for anonymous classes returns null instead of an empty name
darcy
parents:
diff
changeset
|
35 |
/* |
405341b6e9c5
6449781: TypeElement.getQualifiedName for anonymous classes returns null instead of an empty name
darcy
parents:
diff
changeset
|
36 |
* This test operates in phases to test retrieving the qualified name |
405341b6e9c5
6449781: TypeElement.getQualifiedName for anonymous classes returns null instead of an empty name
darcy
parents:
diff
changeset
|
37 |
* of anonymous classes from type elements modeling the anonymous |
405341b6e9c5
6449781: TypeElement.getQualifiedName for anonymous classes returns null instead of an empty name
darcy
parents:
diff
changeset
|
38 |
* class. The type elements are generated using both source files and |
405341b6e9c5
6449781: TypeElement.getQualifiedName for anonymous classes returns null instead of an empty name
darcy
parents:
diff
changeset
|
39 |
* class files as the basis of constructing the elements. |
405341b6e9c5
6449781: TypeElement.getQualifiedName for anonymous classes returns null instead of an empty name
darcy
parents:
diff
changeset
|
40 |
* |
405341b6e9c5
6449781: TypeElement.getQualifiedName for anonymous classes returns null instead of an empty name
darcy
parents:
diff
changeset
|
41 |
* Source files will be tested by the @compile line which runs |
405341b6e9c5
6449781: TypeElement.getQualifiedName for anonymous classes returns null instead of an empty name
darcy
parents:
diff
changeset
|
42 |
* TestAnonSourceNames as an annotation processor over this file. |
405341b6e9c5
6449781: TypeElement.getQualifiedName for anonymous classes returns null instead of an empty name
darcy
parents:
diff
changeset
|
43 |
* |
405341b6e9c5
6449781: TypeElement.getQualifiedName for anonymous classes returns null instead of an empty name
darcy
parents:
diff
changeset
|
44 |
* Class files are tested by the @run command on this type. This |
405341b6e9c5
6449781: TypeElement.getQualifiedName for anonymous classes returns null instead of an empty name
darcy
parents:
diff
changeset
|
45 |
* class gets the names of classes with different nesting kinds, |
405341b6e9c5
6449781: TypeElement.getQualifiedName for anonymous classes returns null instead of an empty name
darcy
parents:
diff
changeset
|
46 |
* including anonymous classes, and then invokes the compiler with an |
405341b6e9c5
6449781: TypeElement.getQualifiedName for anonymous classes returns null instead of an empty name
darcy
parents:
diff
changeset
|
47 |
* annotation processor having the class files names as inputs. The |
405341b6e9c5
6449781: TypeElement.getQualifiedName for anonymous classes returns null instead of an empty name
darcy
parents:
diff
changeset
|
48 |
* compiler is invoked via the javax.tools mechanism. |
405341b6e9c5
6449781: TypeElement.getQualifiedName for anonymous classes returns null instead of an empty name
darcy
parents:
diff
changeset
|
49 |
*/ |
405341b6e9c5
6449781: TypeElement.getQualifiedName for anonymous classes returns null instead of an empty name
darcy
parents:
diff
changeset
|
50 |
|
405341b6e9c5
6449781: TypeElement.getQualifiedName for anonymous classes returns null instead of an empty name
darcy
parents:
diff
changeset
|
51 |
import java.lang.annotation.*; |
405341b6e9c5
6449781: TypeElement.getQualifiedName for anonymous classes returns null instead of an empty name
darcy
parents:
diff
changeset
|
52 |
import javax.lang.model.element.*; |
405341b6e9c5
6449781: TypeElement.getQualifiedName for anonymous classes returns null instead of an empty name
darcy
parents:
diff
changeset
|
53 |
import javax.annotation.processing.*; |
405341b6e9c5
6449781: TypeElement.getQualifiedName for anonymous classes returns null instead of an empty name
darcy
parents:
diff
changeset
|
54 |
import javax.lang.model.SourceVersion; |
405341b6e9c5
6449781: TypeElement.getQualifiedName for anonymous classes returns null instead of an empty name
darcy
parents:
diff
changeset
|
55 |
import javax.lang.model.element.*; |
405341b6e9c5
6449781: TypeElement.getQualifiedName for anonymous classes returns null instead of an empty name
darcy
parents:
diff
changeset
|
56 |
import javax.lang.model.util.*; |
405341b6e9c5
6449781: TypeElement.getQualifiedName for anonymous classes returns null instead of an empty name
darcy
parents:
diff
changeset
|
57 |
import javax.tools.*; |
405341b6e9c5
6449781: TypeElement.getQualifiedName for anonymous classes returns null instead of an empty name
darcy
parents:
diff
changeset
|
58 |
import java.util.*; |
405341b6e9c5
6449781: TypeElement.getQualifiedName for anonymous classes returns null instead of an empty name
darcy
parents:
diff
changeset
|
59 |
|
405341b6e9c5
6449781: TypeElement.getQualifiedName for anonymous classes returns null instead of an empty name
darcy
parents:
diff
changeset
|
60 |
import static java.lang.annotation.RetentionPolicy.*; |
405341b6e9c5
6449781: TypeElement.getQualifiedName for anonymous classes returns null instead of an empty name
darcy
parents:
diff
changeset
|
61 |
import static javax.lang.model.element.NestingKind.*; |
405341b6e9c5
6449781: TypeElement.getQualifiedName for anonymous classes returns null instead of an empty name
darcy
parents:
diff
changeset
|
62 |
import static javax.lang.model.util.ElementFilter.*; |
405341b6e9c5
6449781: TypeElement.getQualifiedName for anonymous classes returns null instead of an empty name
darcy
parents:
diff
changeset
|
63 |
import static javax.tools.Diagnostic.Kind.*; |
405341b6e9c5
6449781: TypeElement.getQualifiedName for anonymous classes returns null instead of an empty name
darcy
parents:
diff
changeset
|
64 |
import static javax.tools.StandardLocation.*; |
405341b6e9c5
6449781: TypeElement.getQualifiedName for anonymous classes returns null instead of an empty name
darcy
parents:
diff
changeset
|
65 |
|
405341b6e9c5
6449781: TypeElement.getQualifiedName for anonymous classes returns null instead of an empty name
darcy
parents:
diff
changeset
|
66 |
@Nesting(TOP_LEVEL) |
405341b6e9c5
6449781: TypeElement.getQualifiedName for anonymous classes returns null instead of an empty name
darcy
parents:
diff
changeset
|
67 |
public class TestAnonClassNames { |
405341b6e9c5
6449781: TypeElement.getQualifiedName for anonymous classes returns null instead of an empty name
darcy
parents:
diff
changeset
|
68 |
@Nesting(MEMBER) |
405341b6e9c5
6449781: TypeElement.getQualifiedName for anonymous classes returns null instead of an empty name
darcy
parents:
diff
changeset
|
69 |
static class MemberClass1{} |
405341b6e9c5
6449781: TypeElement.getQualifiedName for anonymous classes returns null instead of an empty name
darcy
parents:
diff
changeset
|
70 |
|
405341b6e9c5
6449781: TypeElement.getQualifiedName for anonymous classes returns null instead of an empty name
darcy
parents:
diff
changeset
|
71 |
@Nesting(MEMBER) |
405341b6e9c5
6449781: TypeElement.getQualifiedName for anonymous classes returns null instead of an empty name
darcy
parents:
diff
changeset
|
72 |
class MemberClass2{} |
405341b6e9c5
6449781: TypeElement.getQualifiedName for anonymous classes returns null instead of an empty name
darcy
parents:
diff
changeset
|
73 |
|
405341b6e9c5
6449781: TypeElement.getQualifiedName for anonymous classes returns null instead of an empty name
darcy
parents:
diff
changeset
|
74 |
@Nesting(MEMBER) |
405341b6e9c5
6449781: TypeElement.getQualifiedName for anonymous classes returns null instead of an empty name
darcy
parents:
diff
changeset
|
75 |
class Win$$AtVegas { } // Class with funny name. |
405341b6e9c5
6449781: TypeElement.getQualifiedName for anonymous classes returns null instead of an empty name
darcy
parents:
diff
changeset
|
76 |
|
405341b6e9c5
6449781: TypeElement.getQualifiedName for anonymous classes returns null instead of an empty name
darcy
parents:
diff
changeset
|
77 |
public static void main(String... argv) { |
405341b6e9c5
6449781: TypeElement.getQualifiedName for anonymous classes returns null instead of an empty name
darcy
parents:
diff
changeset
|
78 |
@Nesting(LOCAL) |
405341b6e9c5
6449781: TypeElement.getQualifiedName for anonymous classes returns null instead of an empty name
darcy
parents:
diff
changeset
|
79 |
class LocalClass{}; |
405341b6e9c5
6449781: TypeElement.getQualifiedName for anonymous classes returns null instead of an empty name
darcy
parents:
diff
changeset
|
80 |
|
7072 | 81 |
Object o = new /*@Nesting(ANONYMOUS)*/ Object() { // An anonymous annotated class |
5012
405341b6e9c5
6449781: TypeElement.getQualifiedName for anonymous classes returns null instead of an empty name
darcy
parents:
diff
changeset
|
82 |
public String toString() { |
405341b6e9c5
6449781: TypeElement.getQualifiedName for anonymous classes returns null instead of an empty name
darcy
parents:
diff
changeset
|
83 |
return "I have no name!"; |
405341b6e9c5
6449781: TypeElement.getQualifiedName for anonymous classes returns null instead of an empty name
darcy
parents:
diff
changeset
|
84 |
} |
405341b6e9c5
6449781: TypeElement.getQualifiedName for anonymous classes returns null instead of an empty name
darcy
parents:
diff
changeset
|
85 |
}; |
405341b6e9c5
6449781: TypeElement.getQualifiedName for anonymous classes returns null instead of an empty name
darcy
parents:
diff
changeset
|
86 |
|
405341b6e9c5
6449781: TypeElement.getQualifiedName for anonymous classes returns null instead of an empty name
darcy
parents:
diff
changeset
|
87 |
Class<?>[] classes = { |
405341b6e9c5
6449781: TypeElement.getQualifiedName for anonymous classes returns null instead of an empty name
darcy
parents:
diff
changeset
|
88 |
MemberClass1.class, |
405341b6e9c5
6449781: TypeElement.getQualifiedName for anonymous classes returns null instead of an empty name
darcy
parents:
diff
changeset
|
89 |
MemberClass2.class, |
405341b6e9c5
6449781: TypeElement.getQualifiedName for anonymous classes returns null instead of an empty name
darcy
parents:
diff
changeset
|
90 |
LocalClass.class, |
405341b6e9c5
6449781: TypeElement.getQualifiedName for anonymous classes returns null instead of an empty name
darcy
parents:
diff
changeset
|
91 |
Win$$AtVegas.class, |
405341b6e9c5
6449781: TypeElement.getQualifiedName for anonymous classes returns null instead of an empty name
darcy
parents:
diff
changeset
|
92 |
o.getClass(), |
405341b6e9c5
6449781: TypeElement.getQualifiedName for anonymous classes returns null instead of an empty name
darcy
parents:
diff
changeset
|
93 |
TestAnonClassNames.class, |
405341b6e9c5
6449781: TypeElement.getQualifiedName for anonymous classes returns null instead of an empty name
darcy
parents:
diff
changeset
|
94 |
}; |
405341b6e9c5
6449781: TypeElement.getQualifiedName for anonymous classes returns null instead of an empty name
darcy
parents:
diff
changeset
|
95 |
|
405341b6e9c5
6449781: TypeElement.getQualifiedName for anonymous classes returns null instead of an empty name
darcy
parents:
diff
changeset
|
96 |
for(Class<?> clazz : classes) { |
405341b6e9c5
6449781: TypeElement.getQualifiedName for anonymous classes returns null instead of an empty name
darcy
parents:
diff
changeset
|
97 |
String name = clazz.getName(); |
7072 | 98 |
Nesting anno = clazz.getAnnotation(Nesting.class); |
5012
405341b6e9c5
6449781: TypeElement.getQualifiedName for anonymous classes returns null instead of an empty name
darcy
parents:
diff
changeset
|
99 |
System.out.format("%s is %s%n", |
405341b6e9c5
6449781: TypeElement.getQualifiedName for anonymous classes returns null instead of an empty name
darcy
parents:
diff
changeset
|
100 |
clazz.getName(), |
7072 | 101 |
anno == null ? "(unset/ANONYMOUS)" : anno.value()); |
5012
405341b6e9c5
6449781: TypeElement.getQualifiedName for anonymous classes returns null instead of an empty name
darcy
parents:
diff
changeset
|
102 |
testClassName(name); |
405341b6e9c5
6449781: TypeElement.getQualifiedName for anonymous classes returns null instead of an empty name
darcy
parents:
diff
changeset
|
103 |
} |
405341b6e9c5
6449781: TypeElement.getQualifiedName for anonymous classes returns null instead of an empty name
darcy
parents:
diff
changeset
|
104 |
} |
405341b6e9c5
6449781: TypeElement.getQualifiedName for anonymous classes returns null instead of an empty name
darcy
parents:
diff
changeset
|
105 |
|
405341b6e9c5
6449781: TypeElement.getQualifiedName for anonymous classes returns null instead of an empty name
darcy
parents:
diff
changeset
|
106 |
/** |
405341b6e9c5
6449781: TypeElement.getQualifiedName for anonymous classes returns null instead of an empty name
darcy
parents:
diff
changeset
|
107 |
* Perform annotation processing on the class file name and verify |
405341b6e9c5
6449781: TypeElement.getQualifiedName for anonymous classes returns null instead of an empty name
darcy
parents:
diff
changeset
|
108 |
* the existence of different flavors of class names when the |
405341b6e9c5
6449781: TypeElement.getQualifiedName for anonymous classes returns null instead of an empty name
darcy
parents:
diff
changeset
|
109 |
* input classes are modeled as elements. |
405341b6e9c5
6449781: TypeElement.getQualifiedName for anonymous classes returns null instead of an empty name
darcy
parents:
diff
changeset
|
110 |
*/ |
405341b6e9c5
6449781: TypeElement.getQualifiedName for anonymous classes returns null instead of an empty name
darcy
parents:
diff
changeset
|
111 |
static void testClassName(String className) { |
405341b6e9c5
6449781: TypeElement.getQualifiedName for anonymous classes returns null instead of an empty name
darcy
parents:
diff
changeset
|
112 |
JavaCompiler javaCompiler = ToolProvider.getSystemJavaCompiler(); |
5320
e2aaa958b02d
6939618: Revert 'simple' diamond implementation
mcimadamore
parents:
5012
diff
changeset
|
113 |
List<String> classNames = new ArrayList<String>(); |
5012
405341b6e9c5
6449781: TypeElement.getQualifiedName for anonymous classes returns null instead of an empty name
darcy
parents:
diff
changeset
|
114 |
classNames.add(className); |
405341b6e9c5
6449781: TypeElement.getQualifiedName for anonymous classes returns null instead of an empty name
darcy
parents:
diff
changeset
|
115 |
|
5320
e2aaa958b02d
6939618: Revert 'simple' diamond implementation
mcimadamore
parents:
5012
diff
changeset
|
116 |
List<String> options = new ArrayList<String>(); |
5012
405341b6e9c5
6449781: TypeElement.getQualifiedName for anonymous classes returns null instead of an empty name
darcy
parents:
diff
changeset
|
117 |
options.add("-proc:only"); |
405341b6e9c5
6449781: TypeElement.getQualifiedName for anonymous classes returns null instead of an empty name
darcy
parents:
diff
changeset
|
118 |
options.add("-classpath"); |
405341b6e9c5
6449781: TypeElement.getQualifiedName for anonymous classes returns null instead of an empty name
darcy
parents:
diff
changeset
|
119 |
options.add(System.getProperty("test.classes")); |
405341b6e9c5
6449781: TypeElement.getQualifiedName for anonymous classes returns null instead of an empty name
darcy
parents:
diff
changeset
|
120 |
|
405341b6e9c5
6449781: TypeElement.getQualifiedName for anonymous classes returns null instead of an empty name
darcy
parents:
diff
changeset
|
121 |
JavaCompiler.CompilationTask compileTask = |
405341b6e9c5
6449781: TypeElement.getQualifiedName for anonymous classes returns null instead of an empty name
darcy
parents:
diff
changeset
|
122 |
javaCompiler.getTask(null, // Output |
405341b6e9c5
6449781: TypeElement.getQualifiedName for anonymous classes returns null instead of an empty name
darcy
parents:
diff
changeset
|
123 |
null, // File manager |
405341b6e9c5
6449781: TypeElement.getQualifiedName for anonymous classes returns null instead of an empty name
darcy
parents:
diff
changeset
|
124 |
null, // Diagnostics |
405341b6e9c5
6449781: TypeElement.getQualifiedName for anonymous classes returns null instead of an empty name
darcy
parents:
diff
changeset
|
125 |
options, |
405341b6e9c5
6449781: TypeElement.getQualifiedName for anonymous classes returns null instead of an empty name
darcy
parents:
diff
changeset
|
126 |
classNames, |
405341b6e9c5
6449781: TypeElement.getQualifiedName for anonymous classes returns null instead of an empty name
darcy
parents:
diff
changeset
|
127 |
null); // Sources |
5320
e2aaa958b02d
6939618: Revert 'simple' diamond implementation
mcimadamore
parents:
5012
diff
changeset
|
128 |
List<Processor> processors = new ArrayList<Processor>(); |
5012
405341b6e9c5
6449781: TypeElement.getQualifiedName for anonymous classes returns null instead of an empty name
darcy
parents:
diff
changeset
|
129 |
processors.add(new ClassNameProber()); |
405341b6e9c5
6449781: TypeElement.getQualifiedName for anonymous classes returns null instead of an empty name
darcy
parents:
diff
changeset
|
130 |
compileTask.setProcessors(processors); |
405341b6e9c5
6449781: TypeElement.getQualifiedName for anonymous classes returns null instead of an empty name
darcy
parents:
diff
changeset
|
131 |
Boolean goodResult = compileTask.call(); |
405341b6e9c5
6449781: TypeElement.getQualifiedName for anonymous classes returns null instead of an empty name
darcy
parents:
diff
changeset
|
132 |
if (!goodResult) { |
405341b6e9c5
6449781: TypeElement.getQualifiedName for anonymous classes returns null instead of an empty name
darcy
parents:
diff
changeset
|
133 |
throw new RuntimeException("Errors found during compile."); |
405341b6e9c5
6449781: TypeElement.getQualifiedName for anonymous classes returns null instead of an empty name
darcy
parents:
diff
changeset
|
134 |
} |
405341b6e9c5
6449781: TypeElement.getQualifiedName for anonymous classes returns null instead of an empty name
darcy
parents:
diff
changeset
|
135 |
} |
405341b6e9c5
6449781: TypeElement.getQualifiedName for anonymous classes returns null instead of an empty name
darcy
parents:
diff
changeset
|
136 |
} |
405341b6e9c5
6449781: TypeElement.getQualifiedName for anonymous classes returns null instead of an empty name
darcy
parents:
diff
changeset
|
137 |
|
405341b6e9c5
6449781: TypeElement.getQualifiedName for anonymous classes returns null instead of an empty name
darcy
parents:
diff
changeset
|
138 |
@Retention(RUNTIME) |
405341b6e9c5
6449781: TypeElement.getQualifiedName for anonymous classes returns null instead of an empty name
darcy
parents:
diff
changeset
|
139 |
@interface Nesting { |
405341b6e9c5
6449781: TypeElement.getQualifiedName for anonymous classes returns null instead of an empty name
darcy
parents:
diff
changeset
|
140 |
NestingKind value(); |
405341b6e9c5
6449781: TypeElement.getQualifiedName for anonymous classes returns null instead of an empty name
darcy
parents:
diff
changeset
|
141 |
} |
405341b6e9c5
6449781: TypeElement.getQualifiedName for anonymous classes returns null instead of an empty name
darcy
parents:
diff
changeset
|
142 |
|
405341b6e9c5
6449781: TypeElement.getQualifiedName for anonymous classes returns null instead of an empty name
darcy
parents:
diff
changeset
|
143 |
/** |
405341b6e9c5
6449781: TypeElement.getQualifiedName for anonymous classes returns null instead of an empty name
darcy
parents:
diff
changeset
|
144 |
* Probe at the various kinds of names of a type element. |
405341b6e9c5
6449781: TypeElement.getQualifiedName for anonymous classes returns null instead of an empty name
darcy
parents:
diff
changeset
|
145 |
*/ |
6720 | 146 |
class ClassNameProber extends JavacTestingAbstractProcessor { |
5012
405341b6e9c5
6449781: TypeElement.getQualifiedName for anonymous classes returns null instead of an empty name
darcy
parents:
diff
changeset
|
147 |
public ClassNameProber(){super();} |
405341b6e9c5
6449781: TypeElement.getQualifiedName for anonymous classes returns null instead of an empty name
darcy
parents:
diff
changeset
|
148 |
|
405341b6e9c5
6449781: TypeElement.getQualifiedName for anonymous classes returns null instead of an empty name
darcy
parents:
diff
changeset
|
149 |
private boolean classesFound=false; |
405341b6e9c5
6449781: TypeElement.getQualifiedName for anonymous classes returns null instead of an empty name
darcy
parents:
diff
changeset
|
150 |
|
405341b6e9c5
6449781: TypeElement.getQualifiedName for anonymous classes returns null instead of an empty name
darcy
parents:
diff
changeset
|
151 |
public boolean process(Set<? extends TypeElement> annotations, |
405341b6e9c5
6449781: TypeElement.getQualifiedName for anonymous classes returns null instead of an empty name
darcy
parents:
diff
changeset
|
152 |
RoundEnvironment roundEnv) { |
405341b6e9c5
6449781: TypeElement.getQualifiedName for anonymous classes returns null instead of an empty name
darcy
parents:
diff
changeset
|
153 |
if (!roundEnv.processingOver()) { |
405341b6e9c5
6449781: TypeElement.getQualifiedName for anonymous classes returns null instead of an empty name
darcy
parents:
diff
changeset
|
154 |
for(TypeElement typeElt : typesIn(roundEnv.getRootElements())) { |
405341b6e9c5
6449781: TypeElement.getQualifiedName for anonymous classes returns null instead of an empty name
darcy
parents:
diff
changeset
|
155 |
classesFound = true; |
405341b6e9c5
6449781: TypeElement.getQualifiedName for anonymous classes returns null instead of an empty name
darcy
parents:
diff
changeset
|
156 |
|
405341b6e9c5
6449781: TypeElement.getQualifiedName for anonymous classes returns null instead of an empty name
darcy
parents:
diff
changeset
|
157 |
// Verify different names are non-null; an NPE will |
405341b6e9c5
6449781: TypeElement.getQualifiedName for anonymous classes returns null instead of an empty name
darcy
parents:
diff
changeset
|
158 |
// result in failed compile status being reported. |
405341b6e9c5
6449781: TypeElement.getQualifiedName for anonymous classes returns null instead of an empty name
darcy
parents:
diff
changeset
|
159 |
NestingKind nestingKind = typeElt.getNestingKind(); |
405341b6e9c5
6449781: TypeElement.getQualifiedName for anonymous classes returns null instead of an empty name
darcy
parents:
diff
changeset
|
160 |
System.out.printf("\tSimple name: ''%s''\tQualified Name: ''%s''\tKind ''%s''\tNesting ''%s''%n", |
405341b6e9c5
6449781: TypeElement.getQualifiedName for anonymous classes returns null instead of an empty name
darcy
parents:
diff
changeset
|
161 |
typeElt.getSimpleName().toString(), |
405341b6e9c5
6449781: TypeElement.getQualifiedName for anonymous classes returns null instead of an empty name
darcy
parents:
diff
changeset
|
162 |
typeElt.getQualifiedName().toString(), |
405341b6e9c5
6449781: TypeElement.getQualifiedName for anonymous classes returns null instead of an empty name
darcy
parents:
diff
changeset
|
163 |
typeElt.getKind().toString(), |
405341b6e9c5
6449781: TypeElement.getQualifiedName for anonymous classes returns null instead of an empty name
darcy
parents:
diff
changeset
|
164 |
nestingKind.toString()); |
7072 | 165 |
Nesting anno = typeElt.getAnnotation(Nesting.class); |
166 |
if ((anno == null ? NestingKind.ANONYMOUS : anno.value()) != nestingKind) { |
|
5012
405341b6e9c5
6449781: TypeElement.getQualifiedName for anonymous classes returns null instead of an empty name
darcy
parents:
diff
changeset
|
167 |
throw new RuntimeException("Mismatch of expected and reported nesting kind."); |
405341b6e9c5
6449781: TypeElement.getQualifiedName for anonymous classes returns null instead of an empty name
darcy
parents:
diff
changeset
|
168 |
} |
405341b6e9c5
6449781: TypeElement.getQualifiedName for anonymous classes returns null instead of an empty name
darcy
parents:
diff
changeset
|
169 |
} |
405341b6e9c5
6449781: TypeElement.getQualifiedName for anonymous classes returns null instead of an empty name
darcy
parents:
diff
changeset
|
170 |
|
405341b6e9c5
6449781: TypeElement.getQualifiedName for anonymous classes returns null instead of an empty name
darcy
parents:
diff
changeset
|
171 |
} |
405341b6e9c5
6449781: TypeElement.getQualifiedName for anonymous classes returns null instead of an empty name
darcy
parents:
diff
changeset
|
172 |
|
405341b6e9c5
6449781: TypeElement.getQualifiedName for anonymous classes returns null instead of an empty name
darcy
parents:
diff
changeset
|
173 |
if (!classesFound) { |
405341b6e9c5
6449781: TypeElement.getQualifiedName for anonymous classes returns null instead of an empty name
darcy
parents:
diff
changeset
|
174 |
throw new RuntimeException("Error: no classes processed."); |
405341b6e9c5
6449781: TypeElement.getQualifiedName for anonymous classes returns null instead of an empty name
darcy
parents:
diff
changeset
|
175 |
} |
405341b6e9c5
6449781: TypeElement.getQualifiedName for anonymous classes returns null instead of an empty name
darcy
parents:
diff
changeset
|
176 |
return true; |
405341b6e9c5
6449781: TypeElement.getQualifiedName for anonymous classes returns null instead of an empty name
darcy
parents:
diff
changeset
|
177 |
} |
405341b6e9c5
6449781: TypeElement.getQualifiedName for anonymous classes returns null instead of an empty name
darcy
parents:
diff
changeset
|
178 |
} |