test/tools/javac/processing/model/type/NoTypes.java

Print this page




  22  */
  23 
  24 /*
  25  * @test
  26  * @bug     6418666 6423973 6453386
  27  * @summary Test the NoTypes: VOID, PACKAGE, NONE
  28  * @author  Scott Seligman
  29  * @compile -g NoTypes.java
  30  * @compile -processor NoTypes -proc:only NoTypes.java
  31  */
  32 
  33 import java.util.Set;
  34 import javax.annotation.processing.*;
  35 import javax.lang.model.SourceVersion;
  36 import javax.lang.model.element.*;
  37 import javax.lang.model.type.*;
  38 import javax.lang.model.util.*;
  39 
  40 import static javax.lang.model.type.TypeKind.*;
  41 
  42 
  43 @SupportedSourceVersion(SourceVersion.RELEASE_6)
  44 @SupportedAnnotationTypes("*")
  45 public class NoTypes extends AbstractProcessor {
  46 
  47     Elements elements;
  48     Types types;
  49 
  50     public void init(ProcessingEnvironment penv) {
  51         super.init(penv);
  52         elements = penv.getElementUtils();
  53         types =  penv.getTypeUtils();
  54     }
  55 
  56     public boolean process(Set<? extends TypeElement> annoTypes,
  57                            RoundEnvironment round) {
  58         if (!round.processingOver())
  59             doit(annoTypes, round);
  60         return true;
  61     }
  62 





  63     private void doit(Set<? extends TypeElement> annoTypes,
  64                       RoundEnvironment round) {
  65 
  66         // The superclass of Object is NONE.
  67         TypeElement object = elements.getTypeElement("java.lang.Object");
  68         verifyKind(NONE, object.getSuperclass());
  69 
  70         // The enclosing type of a top-level class is NONE
  71         verifyKind(NONE, ((DeclaredType)object.asType()).getEnclosingType());
  72 
  73         // The superclass of an interface is NONE.
  74         TypeElement i = elements.getTypeElement("NoTypes.I");
  75         verifyKind(NONE, i.getSuperclass());
  76 
  77         // The type of a package is PACKAGE.
  78         Element pkg = i.getEnclosingElement().getEnclosingElement();
  79         verifyKind(PACKAGE, pkg.asType());
  80 
  81         // A package isn't enclosed.  Not yet, anyway.
  82         if (pkg.getEnclosingElement() != null)




  22  */
  23 
  24 /*
  25  * @test
  26  * @bug     6418666 6423973 6453386
  27  * @summary Test the NoTypes: VOID, PACKAGE, NONE
  28  * @author  Scott Seligman
  29  * @compile -g NoTypes.java
  30  * @compile -processor NoTypes -proc:only NoTypes.java
  31  */
  32 
  33 import java.util.Set;
  34 import javax.annotation.processing.*;
  35 import javax.lang.model.SourceVersion;
  36 import javax.lang.model.element.*;
  37 import javax.lang.model.type.*;
  38 import javax.lang.model.util.*;
  39 
  40 import static javax.lang.model.type.TypeKind.*;
  41 


  42 @SupportedAnnotationTypes("*")
  43 public class NoTypes extends AbstractProcessor {
  44 
  45     Elements elements;
  46     Types types;
  47 
  48     public void init(ProcessingEnvironment penv) {
  49         super.init(penv);
  50         elements = penv.getElementUtils();
  51         types =  penv.getTypeUtils();
  52     }
  53 
  54     public boolean process(Set<? extends TypeElement> annoTypes,
  55                            RoundEnvironment round) {
  56         if (!round.processingOver())
  57             doit(annoTypes, round);
  58         return true;
  59     }
  60 
  61     @Override
  62     public SourceVersion getSupportedSourceVersion() {
  63         return SourceVersion.latest();
  64     }
  65 
  66     private void doit(Set<? extends TypeElement> annoTypes,
  67                       RoundEnvironment round) {
  68 
  69         // The superclass of Object is NONE.
  70         TypeElement object = elements.getTypeElement("java.lang.Object");
  71         verifyKind(NONE, object.getSuperclass());
  72 
  73         // The enclosing type of a top-level class is NONE
  74         verifyKind(NONE, ((DeclaredType)object.asType()).getEnclosingType());
  75 
  76         // The superclass of an interface is NONE.
  77         TypeElement i = elements.getTypeElement("NoTypes.I");
  78         verifyKind(NONE, i.getSuperclass());
  79 
  80         // The type of a package is PACKAGE.
  81         Element pkg = i.getEnclosingElement().getEnclosingElement();
  82         verifyKind(PACKAGE, pkg.asType());
  83 
  84         // A package isn't enclosed.  Not yet, anyway.
  85         if (pkg.getEnclosingElement() != null)