langtools/test/tools/javac/processing/model/type/InheritedAP.java
changeset 25690 b1dac768ab79
parent 20606 a8910a0bdbe6
child 30730 d3ce7619db2c
equal deleted inserted replaced
25608:e1be1d88a557 25690:b1dac768ab79
     1 /*
     1 /*
     2  * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 2012, 2014, 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.
    23 
    23 
    24 /*
    24 /*
    25  * @test
    25  * @test
    26  * @bug 8024513
    26  * @bug 8024513
    27  * @library /tools/javac/lib
    27  * @library /tools/javac/lib
    28  * @build InheritedAP
    28  * @build JavacTestingAbstractProcessor InheritedAP
    29  * @compile -cp . -processor InheritedAP -proc:only InheritedAP.java
    29  * @compile -cp . -processor InheritedAP -proc:only InheritedAP.java
    30  * @summary NPE in annotation processing
    30  * @summary NPE in annotation processing
    31  */
    31  */
    32 import java.util.*;
    32 import java.util.*;
    33 import javax.annotation.processing.*;
    33 import javax.annotation.processing.*;
    38 import static javax.lang.model.type.TypeKind.*;
    38 import static javax.lang.model.type.TypeKind.*;
    39 import static javax.lang.model.SourceVersion.*;
    39 import static javax.lang.model.SourceVersion.*;
    40 import static javax.lang.model.util.ElementFilter.*;
    40 import static javax.lang.model.util.ElementFilter.*;
    41 
    41 
    42 @SupportedAnnotationTypes("testclass")
    42 @SupportedAnnotationTypes("testclass")
    43 @SupportedSourceVersion(RELEASE_8)
    43 public class InheritedAP extends JavacTestingAbstractProcessor {
    44 public class InheritedAP extends AbstractProcessor {
       
    45     static Types types;
    44     static Types types;
    46     public void init(ProcessingEnvironment penv) {super.init(penv);}
    45     public void init(ProcessingEnvironment penv) {super.init(penv);}
    47     public static Types getTypes() { return types; }
    46     public static Types getTypes() { return types; }
    48 
    47 
    49     public boolean process(Set<? extends TypeElement> typeElementSet,RoundEnvironment renv) {
    48     public boolean process(Set<? extends TypeElement> typeElementSet,RoundEnvironment renv) {
    52             return true;
    51             return true;
    53         }
    52         }
    54         types=processingEnv.getTypeUtils();
    53         types=processingEnv.getTypeUtils();
    55         for (TypeElement typeElem: typesIn(renv.getRootElements())) {
    54         for (TypeElement typeElem: typesIn(renv.getRootElements())) {
    56             if (typeElem.getAnnotation(testclass.class) != null) {
    55             if (typeElem.getAnnotation(testclass.class) != null) {
    57                 new ElementScanner( new SimpleTypeMirrorVisitor()).scan(typeElem, null);
    56                 new LocalElementScanner( new SimpleTypeMirrorVisitor()).scan(typeElem, null);
    58             }
    57             }
    59         }
    58         }
    60         return true ;
    59         return true ;
    61     }
    60     }
    62 }
    61 }
    63 
    62 
    64 class SimpleTypeMirrorVisitor extends SimpleTypeVisitor6 <Void, Void> {
    63 class SimpleTypeMirrorVisitor extends JavacTestingAbstractProcessor.SimpleTypeVisitor<Void, Void> {
    65     protected Void defaultAction(TypeMirror mirror, Void p ) {
    64     protected Void defaultAction(TypeMirror mirror, Void p ) {
    66         try {
    65         try {
    67             System.out.println( "InheritedAP.getTypes().directSupertypes( "+mirror.toString()+" );" );
    66             System.out.println( "InheritedAP.getTypes().directSupertypes( "+mirror.toString()+" );" );
    68             InheritedAP.getTypes().directSupertypes(mirror);
    67             InheritedAP.getTypes().directSupertypes(mirror);
    69             System.out.println("PASS");
    68             System.out.println("PASS");
    70         }catch(java.lang.IllegalArgumentException iae) {/*stuff*/ }
    69         }catch(java.lang.IllegalArgumentException iae) {/*stuff*/ }
    71         return p;
    70         return p;
    72     }
    71     }
    73 }
    72 }
    74 
    73 
    75 class ElementScanner <T extends SimpleTypeVisitor6<Void, Void> >
    74 class LocalElementScanner <T extends JavacTestingAbstractProcessor.SimpleTypeVisitor<Void, Void> >
    76                     extends ElementScanner6<Void, Void> {
    75                     extends JavacTestingAbstractProcessor.ElementScanner<Void, Void> {
    77     SimpleTypeVisitor6<Void, Void> typeVisitor;
    76     JavacTestingAbstractProcessor.SimpleTypeVisitor<Void, Void> typeVisitor;
    78 
    77 
    79     public ElementScanner(T typeVisitor) { this.typeVisitor=typeVisitor;}
    78     public LocalElementScanner(T typeVisitor) { this.typeVisitor=typeVisitor;}
    80 
    79 
    81     @Override
    80     @Override
    82     public Void scan(Element e, Void p) {
    81     public Void scan(Element e, Void p) {
    83          if (e instanceof TypeElement ) {
    82          if (e instanceof TypeElement ) {
    84             TypeElement te = (TypeElement) e;
    83             TypeElement te = (TypeElement) e;
    85             te.getSuperclass().accept(typeVisitor,p);
    84             te.getSuperclass().accept(typeVisitor,p);
    86         }
    85         }
    87         return p;
    86         return p;
    88     }
    87     }
    89 
       
    90 }
    88 }
    91 
    89 
    92 
    90 
    93 @interface testclass { }
    91 @interface testclass { }
    94 
    92