public AnnotationTypeDeclaration getDeclaration() { return DeclarationDecorator.decorate(((AnnotationType) delegate).getDeclaration()); }
/** * A map of annotations for this declaration. * * @return A map of annotations for this declaration. */ public Map<String, AnnotationMirror> getAnnotations() { if (this.annotations == null) { this.annotations = new HashMap<String, AnnotationMirror>(); for (AnnotationMirror annotationMirror : getAnnotationMirrors()) { AnnotationType annotationType = annotationMirror.getAnnotationType(); if ((annotationType != null) && (annotationType.getDeclaration() != null)) { annotations.put(annotationType.getDeclaration().getQualifiedName(), annotationMirror); } } } return this.annotations; }
/** * Gets all the annotations on the given declaration. */ private Annotation[] getAllAnnotations(Declaration decl, Locatable srcPos) { List<Annotation> r = new ArrayList<Annotation>(); for( AnnotationMirror m : decl.getAnnotationMirrors() ) { try { String fullName = m.getAnnotationType().getDeclaration().getQualifiedName(); Class<? extends Annotation> type = getClass().getClassLoader().loadClass(fullName).asSubclass(Annotation.class); Annotation annotation = decl.getAnnotation(type); if(annotation!=null) r.add( LocatableAnnotation.create(annotation,srcPos) ); } catch (ClassNotFoundException e) { // just continue } } return r.toArray(EMPTY_ANNOTATION); }
public static boolean isFormBeanParameter(Declaration candidate) { for (AnnotationMirror annotation : candidate.getAnnotationMirrors()) { AnnotationTypeDeclaration declaration = annotation.getAnnotationType().getDeclaration(); if (declaration != null) { String fqn = declaration.getQualifiedName(); if (FORM_BEAN_ANNOTATIONS.contains(fqn)) { return true; } } } return false; }
private void printAnnotationMirrors(Collection<AnnotationMirror> mirrors) { for (AnnotationMirror mirror : mirrors) { System.out.println("========================"); Map<AnnotationTypeElementDeclaration, AnnotationValue> elementValues = mirror.getElementValues(); printAnnotationTypeDeclaration(mirror.getAnnotationType().getDeclaration()); for (AnnotationTypeElementDeclaration decl : mirror.getAnnotationType().getDeclaration().getMethods()) { System.out.println("-------------------"); printAnnotationTypeElementDeclaration(decl); if (elementValues.containsKey(decl)) { AnnotationValue value = elementValues.get(decl); System.out.println("Type Element value=" + value.getValue()); } } } }
/** * Gets all the annotations on the given declaration. */ private Annotation[] getAllAnnotations(Declaration decl, Locatable srcPos) { List<Annotation> r = new ArrayList<Annotation>(); for( AnnotationMirror m : decl.getAnnotationMirrors() ) { try { String fullName = m.getAnnotationType().getDeclaration().getQualifiedName(); Class<? extends Annotation> type = getClass().getClassLoader().loadClass(fullName).asSubclass(Annotation.class); Annotation annotation = decl.getAnnotation(type); if(annotation!=null) r.add( LocatableAnnotation.create(annotation,srcPos) ); } catch (ClassNotFoundException e) { // just continue } } return r.toArray(EMPTY_ANNOTATION); }
/** * Whether the specified member declaration is explicitly declared to be an accessor. * * @param declaration The declaration to check whether it is explicitly declared to be an accessor. * @return Whether the specified member declaration is explicitly declared to be an accessor. */ protected boolean explicitlyDeclaredAccessor(MemberDeclaration declaration) { Collection<AnnotationMirror> annotationMirrors = declaration.getAnnotationMirrors(); for (AnnotationMirror annotationMirror : annotationMirrors) { AnnotationType annotationType = annotationMirror.getAnnotationType(); if (annotationType != null) { AnnotationTypeDeclaration annotationDeclaration = annotationType.getDeclaration(); if ((annotationDeclaration != null) && (annotationDeclaration.getQualifiedName().startsWith(XmlElement.class.getPackage().getName()))) { //if it's annotated with anything in javax.xml.bind.annotation, (exception XmlTransient) we'll consider it to be "explicitly annotated." return !annotationDeclaration.getQualifiedName().equals(XmlTransient.class.getName()); } } } return false; }
/** * Whether the specified member declaration is explicitly declared to be an accessor. * * @param declaration The declaration to check whether it is explicitly declared to be an accessor. * @return Whether the specified member declaration is explicitly declared to be an accessor. */ protected boolean explicitlyDeclaredAccessor(MemberDeclaration declaration) { Collection<AnnotationMirror> annotationMirrors = declaration.getAnnotationMirrors(); for (AnnotationMirror annotationMirror : annotationMirrors) { AnnotationType annotationType = annotationMirror.getAnnotationType(); if (annotationType != null) { AnnotationTypeDeclaration annotationDeclaration = annotationType.getDeclaration(); if ((annotationDeclaration != null) && (annotationDeclaration.getQualifiedName().startsWith(XmlElement.class.getPackage().getName()))) { //if it's annotated with anything in javax.xml.bind.annotation, (exception XmlTransient) we'll consider it to be "explicitly annotated." return !annotationDeclaration.getQualifiedName().equals(XmlTransient.class.getName()); } } } return false; }
private void printAnnotationMirrors(Collection<AnnotationMirror> mirrors) { for (AnnotationMirror mirror : mirrors) { System.out.println("========================"); Map<AnnotationTypeElementDeclaration, AnnotationValue> elementValues = mirror.getElementValues(); printAnnotationTypeDeclaration(mirror.getAnnotationType().getDeclaration()); for (AnnotationTypeElementDeclaration decl : mirror.getAnnotationType().getDeclaration().getMethods()) { System.out.println("-------------------"); printAnnotationTypeElementDeclaration(decl); if (elementValues.containsKey(decl)) { AnnotationValue value = elementValues.get(decl); System.out.println("Type Element value=" + value.getValue()); } } } }
public static boolean isResourceParameter(Declaration candidate) { if (!isSystemParameter(candidate)) { for (AnnotationMirror annotation : candidate.getAnnotationMirrors()) { AnnotationTypeDeclaration declaration = annotation.getAnnotationType().getDeclaration(); if (declaration != null) { String fqn = declaration.getQualifiedName(); if ((MatrixParam.class.getName().equals(fqn)) || QueryParam.class.getName().equals(fqn) || PathParam.class.getName().equals(fqn) || CookieParam.class.getName().equals(fqn) || HeaderParam.class.getName().equals(fqn) || FormParam.class.getName().equals(fqn)) { return true; } EnunciateConfiguration config = ((EnunciateFreemarkerModel) FreemarkerModel.get()).getEnunciateConfig(); if (config != null && config.getSystemResourceParameterAnnotations().contains(fqn)) { return false; } if (config != null && config.getCustomResourceParameterAnnotations().contains(fqn)) { return true; } } } } return false; }
/** * Whether the given declaration is annotated with an annotation that has the given * (fully-qualified) annotation name. * * @param declaration The declaration. * @param annotationName The annotation name. * @return Whether the declaration has the annotation. */ protected boolean hasAnnotation(D declaration, String annotationName) { for (AnnotationMirror mirror : declaration.getAnnotationMirrors()) { AnnotationTypeDeclaration annotation = mirror.getAnnotationType().getDeclaration(); if ((annotation != null) && (annotation.getQualifiedName().equals(annotationName))) { return true; } } return false; }
public void visitClassDeclaration(ClassDeclaration d) { String className = ((ClassDeclaration)d).getQualifiedName(); for (AnnotationMirror anno : d.getAnnotationMirrors()) { AnnotationTypeDeclaration adecl = anno.getAnnotationType().getDeclaration(); if (!supportedAnnotations.contains(adecl.getQualifiedName())) { continue; List<String> indexes = null; for (AnnotationMirror aa : adecl.getAnnotationMirrors()) { if (aa.getAnnotationType().getDeclaration().getQualifiedName().equals("org.nuxeo.runtime.annotations.loader.Indexable")) { List<AnnotationValue> values = (List<AnnotationValue>)aa.getElementValues().values().iterator().next().getValue(); indexes = new ArrayList<String>(values.size());
public static boolean isSystemParameter(Declaration candidate) { for (AnnotationMirror annotation : candidate.getAnnotationMirrors()) { AnnotationTypeDeclaration declaration = annotation.getAnnotationType().getDeclaration(); if (declaration != null) { String fqn = declaration.getQualifiedName(); if (Context.class.getName().equals(fqn) && candidate.getAnnotation(TypeHint.class) == null) { return true; } EnunciateConfiguration config = ((EnunciateFreemarkerModel) FreemarkerModel.get()).getEnunciateConfig(); if (config != null && config.getSystemResourceParameterAnnotations().contains(fqn)) { return true; } } } return false; }
/** * Whether the specified type is a JAX-RS support class (resource and/or provider). * * @param declaration The declaration. * @return Whether the specified type is a JAX-RS support class. */ public boolean isJAXRSSupport(TypeDeclaration declaration) { if (declaration.getAnnotation(XmlTransient.class) != null) { return false; } //it's a JAX-RS resource if any method has either a @Path or a resource method designator. Collection<? extends MethodDeclaration> methods = declaration.getMethods(); for (MethodDeclaration method : methods) { for (AnnotationMirror mirror : method.getAnnotationMirrors()) { AnnotationType type = mirror.getAnnotationType(); if (type.getDeclaration() != null && type.getDeclaration().getAnnotation(HttpMethod.class) != null) { return true; } } } //otherwise it's a JAX-RS provider if it's annotated as such. return declaration.getAnnotation(Provider.class) != null; }
@Override protected void setupModelForLoop(TemplateModel model, D declaration, int index) throws TemplateException { super.setupModelForLoop(model, declaration, index); if (annotationVar != null) { Collection<AnnotationMirror> annotations = getCurrentDeclaration().getAnnotationMirrors(); for (AnnotationMirror mirror : annotations) { AnnotationTypeDeclaration annotation = mirror.getAnnotationType().getDeclaration(); if (annotation != null) { if (annotation.getQualifiedName().equals(this.annotation)) { model.setVariable(annotationVar, mirror); } } } } }
boolean explicitXMLTypeOrElement = false; for (AnnotationMirror mirror : annotationMirrors) { AnnotationTypeDeclaration annotationDeclaration = mirror.getAnnotationType().getDeclaration(); if (annotationDeclaration != null) { String fqn = annotationDeclaration.getQualifiedName();
public DecoratedAnnotationMirror(AnnotationMirror delegate) { if (delegate == null) { throw new IllegalArgumentException("A delegate must be provided."); } this.delegate = delegate; AnnotationType annotationType = delegate.getAnnotationType(); Collection<AnnotationTypeElementDeclaration> allElements = annotationType.getDeclaration() != null? annotationType.getDeclaration().getMethods() : Collections.<AnnotationTypeElementDeclaration>emptyList(); Map<AnnotationTypeElementDeclaration, AnnotationValue> elementValues = getElementValues(); put("annotationType", annotationType); put("position", delegate.getPosition()); put("elementValues", elementValues); allElementValues = new HashMap<String, Object>(); for (AnnotationTypeElementDeclaration element : allElements) { if (elementValues.containsKey(element)) { Object value = elementValues.get(element).getValue(); allElementValues.put(element.getSimpleName(), value); put(element.getSimpleName(), value); } else { AnnotationValue defaultValue = element.getDefaultValue(); if (defaultValue == null) { throw new IllegalStateException(delegate.getPosition() + ": the element '" + element.getSimpleName() + "' must have a value specified."); } Object value = defaultValue.getValue(); allElementValues.put(element.getSimpleName(), value); put(element.getSimpleName(), value); } } }
AnnotationTypeDeclaration annotationDeclaration = annotationMirror.getAnnotationType().getDeclaration(); if (annotationDeclaration != null) { String fqn = annotationDeclaration.getQualifiedName(); AnnotationTypeDeclaration annotationDeclaration = annotationMirror.getAnnotationType().getDeclaration(); if (annotationDeclaration != null) { String fqn = annotationDeclaration.getQualifiedName();
boolean explicitXMLTypeOrElement = false; for (AnnotationMirror mirror : annotationMirrors) { AnnotationTypeDeclaration annotationDeclaration = mirror.getAnnotationType().getDeclaration(); if (annotationDeclaration != null) { String fqn = annotationDeclaration.getQualifiedName();
if (methodDeclaration.getModifiers().contains(Modifier.PUBLIC)) { for (AnnotationMirror annotation : methodDeclaration.getAnnotationMirrors()) { AnnotationTypeDeclaration annotationDeclaration = annotation.getAnnotationType().getDeclaration(); if (annotationDeclaration != null) { if (annotationDeclaration.getAnnotation(HttpMethod.class) != null) {