author | darcy |
Thu, 17 Jul 2014 09:47:25 -0700 | |
changeset 25690 | b1dac768ab79 |
parent 20606 | a8910a0bdbe6 |
child 30730 | d3ce7619db2c |
permissions | -rw-r--r-- |
20606 | 1 |
/* |
25690
b1dac768ab79
8050430: Provided new utility visitors supporting SourceVersion.RELEASE_9
darcy
parents:
20606
diff
changeset
|
2 |
* Copyright (c) 2012, 2014, Oracle and/or its affiliates. All rights reserved. |
20606 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
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 |
|
7 |
* published by the Free Software Foundation. |
|
8 |
* |
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
13 |
* accompanied this code). |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License version |
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
18 |
* |
|
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. |
|
22 |
*/ |
|
23 |
||
24 |
/* |
|
25 |
* @test |
|
26 |
* @bug 8024513 |
|
27 |
* @library /tools/javac/lib |
|
25690
b1dac768ab79
8050430: Provided new utility visitors supporting SourceVersion.RELEASE_9
darcy
parents:
20606
diff
changeset
|
28 |
* @build JavacTestingAbstractProcessor InheritedAP |
20606 | 29 |
* @compile -cp . -processor InheritedAP -proc:only InheritedAP.java |
30 |
* @summary NPE in annotation processing |
|
31 |
*/ |
|
32 |
import java.util.*; |
|
33 |
import javax.annotation.processing.*; |
|
34 |
import javax.lang.model.element.*; |
|
35 |
import javax.lang.model.type.*; |
|
36 |
import javax.lang.model.util.*; |
|
37 |
import java.lang.annotation.*; |
|
38 |
import static javax.lang.model.type.TypeKind.*; |
|
39 |
import static javax.lang.model.SourceVersion.*; |
|
40 |
import static javax.lang.model.util.ElementFilter.*; |
|
41 |
||
42 |
@SupportedAnnotationTypes("testclass") |
|
25690
b1dac768ab79
8050430: Provided new utility visitors supporting SourceVersion.RELEASE_9
darcy
parents:
20606
diff
changeset
|
43 |
public class InheritedAP extends JavacTestingAbstractProcessor { |
20606 | 44 |
static Types types; |
45 |
public void init(ProcessingEnvironment penv) {super.init(penv);} |
|
46 |
public static Types getTypes() { return types; } |
|
47 |
||
48 |
public boolean process(Set<? extends TypeElement> typeElementSet,RoundEnvironment renv) { |
|
49 |
if ( renv.errorRaised()) { System.out.println("Error!"); return false; } |
|
50 |
if ( typeElementSet.size() <=0 && typesIn(renv.getRootElements()).size() <= 0 ) { |
|
51 |
return true; |
|
52 |
} |
|
53 |
types=processingEnv.getTypeUtils(); |
|
54 |
for (TypeElement typeElem: typesIn(renv.getRootElements())) { |
|
55 |
if (typeElem.getAnnotation(testclass.class) != null) { |
|
25690
b1dac768ab79
8050430: Provided new utility visitors supporting SourceVersion.RELEASE_9
darcy
parents:
20606
diff
changeset
|
56 |
new LocalElementScanner( new SimpleTypeMirrorVisitor()).scan(typeElem, null); |
20606 | 57 |
} |
58 |
} |
|
59 |
return true ; |
|
60 |
} |
|
61 |
} |
|
62 |
||
25690
b1dac768ab79
8050430: Provided new utility visitors supporting SourceVersion.RELEASE_9
darcy
parents:
20606
diff
changeset
|
63 |
class SimpleTypeMirrorVisitor extends JavacTestingAbstractProcessor.SimpleTypeVisitor<Void, Void> { |
20606 | 64 |
protected Void defaultAction(TypeMirror mirror, Void p ) { |
65 |
try { |
|
66 |
System.out.println( "InheritedAP.getTypes().directSupertypes( "+mirror.toString()+" );" ); |
|
67 |
InheritedAP.getTypes().directSupertypes(mirror); |
|
68 |
System.out.println("PASS"); |
|
69 |
}catch(java.lang.IllegalArgumentException iae) {/*stuff*/ } |
|
70 |
return p; |
|
71 |
} |
|
72 |
} |
|
73 |
||
25690
b1dac768ab79
8050430: Provided new utility visitors supporting SourceVersion.RELEASE_9
darcy
parents:
20606
diff
changeset
|
74 |
class LocalElementScanner <T extends JavacTestingAbstractProcessor.SimpleTypeVisitor<Void, Void> > |
b1dac768ab79
8050430: Provided new utility visitors supporting SourceVersion.RELEASE_9
darcy
parents:
20606
diff
changeset
|
75 |
extends JavacTestingAbstractProcessor.ElementScanner<Void, Void> { |
b1dac768ab79
8050430: Provided new utility visitors supporting SourceVersion.RELEASE_9
darcy
parents:
20606
diff
changeset
|
76 |
JavacTestingAbstractProcessor.SimpleTypeVisitor<Void, Void> typeVisitor; |
20606 | 77 |
|
25690
b1dac768ab79
8050430: Provided new utility visitors supporting SourceVersion.RELEASE_9
darcy
parents:
20606
diff
changeset
|
78 |
public LocalElementScanner(T typeVisitor) { this.typeVisitor=typeVisitor;} |
20606 | 79 |
|
80 |
@Override |
|
81 |
public Void scan(Element e, Void p) { |
|
82 |
if (e instanceof TypeElement ) { |
|
83 |
TypeElement te = (TypeElement) e; |
|
84 |
te.getSuperclass().accept(typeVisitor,p); |
|
85 |
} |
|
86 |
return p; |
|
87 |
} |
|
88 |
} |
|
89 |
||
90 |
||
91 |
@interface testclass { } |
|
92 |
||
93 |
@testclass |
|
94 |
@interface iface { } |