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

Print this page




  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)
  86             throw new AssertionError();
  87 
  88         verifyKind(VOID, types.getNoType(VOID));
  89         verifyKind(NONE, types.getNoType(NONE));
  90 
  91         // The return type of a constructor or void method is VOID.
  92         class Scanner extends ElementScanner6<Void, Void> {
  93             @Override
  94             public Void visitExecutable(ExecutableElement e, Void p) {
  95                 verifyKind(VOID, e.getReturnType());
  96                 ExecutableType t = (ExecutableType) e.asType();
  97                 verifyKind(VOID, t.getReturnType());
  98                 return null;
  99             }
 100         }
 101         TypeElement c = elements.getTypeElement("NoTypes.C");
 102         new Scanner().scan(c);
 103     }
 104 
 105     /**
 106      * Verify that a NoType instance is of a particular kind,
 107      * and that TypeKindVisitor6 properly dispatches on it.
 108      */
 109     private void verifyKind(TypeKind kind, TypeMirror type) {
 110         class Vis extends TypeKindVisitor6<TypeKind, Void> {
 111             @Override
 112             public TypeKind visitNoTypeAsVoid(NoType t, Void p) {
 113                 return VOID;
 114             }
 115             @Override
 116             public TypeKind visitNoTypeAsPackage(NoType t, Void p) {
 117                 return PACKAGE;
 118             }
 119             @Override
 120             public TypeKind visitNoTypeAsNone(NoType t, Void p) {
 121                 return NONE;
 122             }
 123         }
 124         if (kind != type.getKind() || kind != new Vis().visit(type))
 125             throw new AssertionError();
 126     }
 127 
 128 
 129     // Fodder for the tests
 130 


  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)
  86             throw new AssertionError();
  87 
  88         verifyKind(VOID, types.getNoType(VOID));
  89         verifyKind(NONE, types.getNoType(NONE));
  90 
  91         // The return type of a constructor or void method is VOID.
  92         class Scanner extends ElementScanner7<Void, Void> {
  93             @Override
  94             public Void visitExecutable(ExecutableElement e, Void p) {
  95                 verifyKind(VOID, e.getReturnType());
  96                 ExecutableType t = (ExecutableType) e.asType();
  97                 verifyKind(VOID, t.getReturnType());
  98                 return null;
  99             }
 100         }
 101         TypeElement c = elements.getTypeElement("NoTypes.C");
 102         new Scanner().scan(c);
 103     }
 104 
 105     /**
 106      * Verify that a NoType instance is of a particular kind,
 107      * and that TypeKindVisitor7 properly dispatches on it.
 108      */
 109     private void verifyKind(TypeKind kind, TypeMirror type) {
 110         class Vis extends TypeKindVisitor7<TypeKind, Void> {
 111             @Override
 112             public TypeKind visitNoTypeAsVoid(NoType t, Void p) {
 113                 return VOID;
 114             }
 115             @Override
 116             public TypeKind visitNoTypeAsPackage(NoType t, Void p) {
 117                 return PACKAGE;
 118             }
 119             @Override
 120             public TypeKind visitNoTypeAsNone(NoType t, Void p) {
 121                 return NONE;
 122             }
 123         }
 124         if (kind != type.getKind() || kind != new Vis().visit(type))
 125             throw new AssertionError();
 126     }
 127 
 128 
 129     // Fodder for the tests
 130