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; }
/** * Whether the specified declaration is throwable. * * @param declaration The declaration to determine whether it is throwable. * @return Whether the specified declaration is throwable. */ protected boolean isThrowable(Element declaration) { return declaration.getKind() == ElementKind.CLASS && ((DecoratedTypeMirror) declaration.asType()).isInstanceOf(Throwable.class); }