コード例 #1
0
    private void buildTypeContents(JsonObject o, TypeElement element) {
      if ("org.springframework.web.servlet.ModelAndView"
          .equals(element.getQualifiedName().toString())) {
        return;
      }
      if (element.getSuperclass().getKind() != TypeKind.NONE) {
        // an interface's superclass is TypeKind.NONE

        DeclaredType sup = (DeclaredType) element.getSuperclass();
        if (!isJsonPrimitive(sup)) {
          buildTypeContents(o, (TypeElement) sup.asElement());
        }
      }

      for (Element e : element.getEnclosedElements()) {
        if (e instanceof ExecutableElement) {
          addFieldFromBeanMethod(o, (ExecutableElement) e);
        }
      }
    }
コード例 #2
0
    private boolean isInstanceOf(TypeMirror typeMirror, Class type) {
      if (!(typeMirror instanceof DeclaredType)) {
        return false;
      }

      if (typeMirror.toString().startsWith(type.getName())) {
        return true;
      }

      DeclaredType declaredType = (DeclaredType) typeMirror;
      TypeElement typeElement = (TypeElement) declaredType.asElement();
      for (TypeMirror iface : typeElement.getInterfaces()) {
        if (isInstanceOf(iface, type)) {
          return true;
        }
      }
      return isInstanceOf(typeElement.getSuperclass(), type);
    }