Ejemplo n.º 1
0
 @Override
 public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
   for (TypeElement te : ElementFilter.typesIn(roundEnv.getRootElements())) {
     if (isSimpleName(te, "InvalidSource")) {
       for (Element c : te.getEnclosedElements()) {
         for (AnnotationMirror am : c.getAnnotationMirrors()) {
           Element ate = am.getAnnotationType().asElement();
           if (isSimpleName(ate, "ExpectInterfaces")) {
             checkInterfaces((TypeElement) c, getValue(am));
           } else if (isSimpleName(ate, "ExpectSupertype")) {
             checkSupertype((TypeElement) c, getValue(am));
           }
         }
       }
     }
   }
   return true;
 }
Ejemplo n.º 2
0
  private String asString(Element e) {
    if (e == null) return "[elt:null]";
    return e.accept(
        new SimpleElementVisitor<String, Void>() {
          @Override
          public String defaultAction(Element e, Void ignore) {
            return "[elt:" + e.getKind() + " " + e.toString() + "]";
          }

          @Override
          public String visitPackage(PackageElement e, Void ignore) {
            return "pkg " + e.getQualifiedName();
          }

          @Override
          public String visitType(TypeElement e, Void ignore) {
            StringBuilder sb = new StringBuilder();
            if (e.getEnclosedElements().isEmpty()) sb.append("empty ");
            ElementKind ek = e.getKind();
            switch (ek) {
              case CLASS:
                sb.append("clss");
                break;
              case INTERFACE:
                sb.append("intf");
                break;
              default:
                sb.append(ek);
                break;
            }
            sb.append(" ");
            Element encl = e.getEnclosingElement();
            if (!isUnnamedPackage(encl) && encl.asType().getKind() != TypeKind.NONE) {
              sb.append("(");
              sb.append(asString(encl));
              sb.append(")");
              sb.append(".");
            }
            sb.append(e.getSimpleName());
            if (e.asType().getKind() == TypeKind.ERROR) sb.append("!");
            return sb.toString();
          }
        },
        null);
  }
Ejemplo n.º 3
0
 private boolean isSimpleName(Element e, String name) {
   return e.getSimpleName().contentEquals(name);
 }
Ejemplo n.º 4
0
 boolean isUnnamedPackage(Element e) {
   return (e != null && e.getKind() == ElementKind.PACKAGE && ((PackageElement) e).isUnnamed());
 }