private boolean doesClassContainNoArgsConstructor(Element el) {
   for (Element subelement : el.getEnclosedElements()) {
     if (subelement.getKind() == ElementKind.CONSTRUCTOR
         && subelement.getModifiers().contains(Modifier.PUBLIC)) {
       TypeMirror mirror = subelement.asType();
       if (mirror.accept(noArgsVisitor, null)) return true;
     }
   }
   return false;
 }
示例#2
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;
 }
示例#3
0
    @Override
    public JsonType visitDeclared(DeclaredType declaredType, Void o) {
      if (isJsonPrimitive(declaredType)) {
        // 'primitive'-ish things
        return new JsonPrimitive(declaredType.toString());

      } else if (isInstanceOf(declaredType, Collection.class)) {

        if (declaredType.getTypeArguments().size() == 0) {
          return new JsonArray(new JsonPrimitive(Object.class.getName()));
        } else {
          TypeMirror elem = declaredType.getTypeArguments().get(0);
          return new JsonArray(elem.accept(this, o));
        }

      } else if (isInstanceOf(declaredType, Map.class)) {

        if (declaredType.getTypeArguments().size() == 0) {
          return new JsonDict(
              new JsonPrimitive(Object.class.getName()), new JsonPrimitive(Object.class.getName()));
        } else {
          TypeMirror key = declaredType.getTypeArguments().get(0);
          TypeMirror val = declaredType.getTypeArguments().get(1);
          return new JsonDict(key.accept(this, o), val.accept(this, o));
        }

      } else {
        TypeElement element = (TypeElement) declaredType.asElement();
        if (element.getKind() == ElementKind.ENUM) {
          List<String> enumConstants = new ArrayList();
          for (Element e : element.getEnclosedElements()) {
            if (e.getKind() == ElementKind.ENUM_CONSTANT) {
              enumConstants.add(e.toString());
            }
          }
          JsonPrimitive primitive =
              new JsonPrimitive(String.class.getName()); // TODO is this always a string?
          primitive.setRestrictions(enumConstants);
          return primitive;
        } else {
          return buildType(declaredType, element);
        }
      }
    }
示例#4
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);
  }
示例#5
0
 private boolean isSimpleName(Element e, String name) {
   return e.getSimpleName().contentEquals(name);
 }
示例#6
0
 boolean isUnnamedPackage(Element e) {
   return (e != null && e.getKind() == ElementKind.PACKAGE && ((PackageElement) e).isUnnamed());
 }