static Parameter forVariableElement(VariableElement variable) { ImmutableSet.Builder<String> qualifiers = ImmutableSet.builder(); for (AnnotationMirror annotationMirror : variable.getAnnotationMirrors()) { DeclaredType annotationType = annotationMirror.getAnnotationType(); if (annotationType.asElement().getAnnotation(Qualifier.class) != null) { qualifiers.add(Mirrors.getQualifiedName(annotationType).toString()); } } return new Parameter( FluentIterable.from(qualifiers.build()).first(), variable.asType().toString(), variable.getSimpleName().toString()); }
private void processLabels(TypeElement resourcesType, List<LabelTemplateMethod> methods) { for (Element element : resourcesType.getEnclosedElements()) { if (element.getKind() != ElementKind.METHOD) { continue; } final ExecutableElement method = (ExecutableElement) element; Message labelAnnotation = element.getAnnotation(Message.class); final TemplateParam returnType = new TemplateParam(method.getReturnType().toString()); final boolean deprecated = method.getAnnotation(Deprecated.class) != null; final LabelTemplateMethod labelMethod; try { labelMethod = new LabelTemplateMethod( method.getSimpleName().toString(), deprecated, returnType, labelAnnotation.value(), labelAnnotation.mobile()); } catch (Throwable t) { processingEnv.getMessager().printMessage(Kind.WARNING, t.getMessage(), resourcesType); continue; } for (VariableElement variable : method.getParameters()) { final String paramName = variable.getSimpleName().toString(); final String paramType = variable.asType().toString(); List<TemplateAnnotation> annotations = new ArrayList<TemplateAnnotation>(); for (AnnotationMirror annotationMirrors : variable.getAnnotationMirrors()) { annotations.add(new TemplateAnnotation(annotationMirrors.getAnnotationType().toString())); } labelMethod.getParams().add(new TemplateParam(paramType, paramName, annotations)); } methods.add(labelMethod); } }
/** INTERNAL: Visit a variable and create a MetadataField object. */ @Override public MetadataField visitVariable(VariableElement variableElement, MetadataClass metadataClass) { MetadataField field = new MetadataField(metadataClass); // Set the name. field.setName(variableElement.getSimpleName().toString()); // Set the attribute name (same as name in this case) field.setAttributeName(field.getName()); // Visit the variable element for type and generic type. variableElement.asType().accept(typeVisitor, field); // Set the modifiers. field.setModifiers(getModifiers(variableElement.getModifiers())); // Set the annotations. buildMetadataAnnotations(field, variableElement.getAnnotationMirrors()); // Add the field to the class and return the field. metadataClass.addField(field); return field; }