Esempio n. 1
0
  @Override
  public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
    processingEnv.getMessager().printMessage(Diagnostic.Kind.NOTE, "Processing @Implemented...");
    for (TypeElement annotation : annotations) {
      for (Element element : roundEnv.getElementsAnnotatedWith(annotation)) {
        TypeElement serviceElement = (TypeElement) element;
        PackageElement packageElement = getPackage(serviceElement);
        final String packageName =
            packageElement == null ? "" : packageElement.getQualifiedName().toString();
        Implemented implemented = serviceElement.getAnnotation(Implemented.class);
        final String implName =
            "".equals(implemented.value())
                ? serviceElement.getSimpleName().toString() + "Impl"
                : implemented.value();
        final List<FieldDescriptor> fields = createFieldList(serviceElement);
        final String localName = determineLocalName(serviceElement);
        final boolean isPublic = serviceElement.getModifiers().contains(Modifier.PUBLIC);
        ImplementedDescriptor annotationDescriptor =
            new ImplementedDescriptor(isPublic, packageName, implName, localName, fields);
        createImplSourceFile(annotationDescriptor, serviceElement, packageName + "." + implName);
      }
    }

    return true;
  }
Esempio n. 2
0
  protected boolean isExplicitTypeDefinition(Element declaration) {
    if (declaration.getKind() != ElementKind.CLASS) {
      debug("%s isn't a potential JAXB type because it's not a class.", declaration);
      return false;
    }

    PackageElement pckg =
        this.context.getProcessingEnvironment().getElementUtils().getPackageOf(declaration);
    if ((pckg != null) && (pckg.getAnnotation(Ignore.class) != null)) {
      debug(
          "%s isn't a potential JAXB type because its package is annotated as to be ignored.",
          declaration);
      return false;
    }

    if (isThrowable(declaration)) {
      debug(
          "%s isn't a potential JAXB type because it's an instance of java.lang.Throwable.",
          declaration);
      return false;
    }

    List<? extends AnnotationMirror> annotationMirrors = declaration.getAnnotationMirrors();
    boolean explicitXMLTypeOrElement = false;
    for (AnnotationMirror mirror : annotationMirrors) {
      Element annotationDeclaration = mirror.getAnnotationType().asElement();
      if (annotationDeclaration != null) {
        String fqn =
            annotationDeclaration instanceof TypeElement
                ? ((TypeElement) annotationDeclaration).getQualifiedName().toString()
                : "";
        // exclude all XmlTransient types and all jaxws types.
        if (XmlTransient.class.getName().equals(fqn)
            || fqn.startsWith("javax.xml.ws")
            || fqn.startsWith("javax.ws.rs")
            || fqn.startsWith("javax.jws")) {
          debug("%s isn't a potential JAXB type because of annotation %s.", declaration, fqn);
          return false;
        } else {
          explicitXMLTypeOrElement =
              (XmlType.class.getName().equals(fqn)) || (XmlRootElement.class.getName().equals(fqn));
        }
      }

      if (explicitXMLTypeOrElement) {
        break;
      }
    }

    return explicitXMLTypeOrElement;
  }
Esempio n. 3
0
 /**
  * {@inheritDoc} This implementation scans the enclosed elements.
  *
  * @param e {@inheritDoc}
  * @param p {@inheritDoc}
  * @return the result of scanning
  */
 public R visitPackage(PackageElement e, P p) {
   return scan(e.getEnclosedElements(), p);
 }