List of usage examples for javax.lang.model.element PackageElement getAnnotation
@Override
<A extends Annotation> A getAnnotation(Class<A> annotationType);
From source file:com.webcohesion.enunciate.modules.jaxb.JaxbModule.java
protected boolean isExplicitTypeDefinition(Element declaration) { if (declaration.getKind() != ElementKind.CLASS && declaration.getKind() != ElementKind.ENUM) { debug("%s isn't a potential JAXB type because it's not a class or an enum.", declaration); return false; }/*w w w .j a va 2 s . com*/ 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; }
From source file:com.webcohesion.enunciate.modules.jackson.JacksonModule.java
protected boolean isExplicitTypeDefinition(Element declaration, boolean honorJaxb) { if (declaration.getKind() != ElementKind.CLASS && declaration.getKind() != ElementKind.ENUM) { debug("%s isn't a potential Jackson type because it's not a class or an enum.", declaration); return false; }//from www . j av a2 s . co m PackageElement pckg = this.context.getProcessingEnvironment().getElementUtils().getPackageOf(declaration); if ((pckg != null) && (pckg.getAnnotation(Ignore.class) != null)) { debug("%s isn't a potential Jackson type because its package is annotated as to be ignored.", declaration); return false; } if (isThrowable(declaration)) { debug("%s isn't a potential Jackson 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 (JsonIgnore.class.getName().equals(fqn) || fqn.startsWith("javax.xml.ws") || fqn.startsWith("javax.ws.rs") || fqn.startsWith("javax.jws")) { debug("%s isn't a potential Jackson type because of annotation %s.", declaration, fqn); return false; } else { if (honorJaxb) { if (XmlTransient.class.getName().equals(fqn)) { debug("%s isn't a potential Jackson type because of annotation %s.", declaration, fqn); return false; } if ((XmlType.class.getName().equals(fqn)) || (XmlRootElement.class.getName().equals(fqn))) { debug("%s will be considered a Jackson type because we're honoring the %s annotation.", declaration, fqn); explicitXMLTypeOrElement = true; } } explicitXMLTypeOrElement = explicitXMLTypeOrElement || isJacksonSerializationAnnotation(fqn); } } if (explicitXMLTypeOrElement) { break; } } return explicitXMLTypeOrElement; }