use of javax.lang.model.element.AnnotationValue in project robolectric by robolectric.
the class RobolectricModel method getImplementedClass.
public TypeMirror getImplementedClass(AnnotationMirror am) {
if (am == null) {
return null;
}
// RobolectricWiringTest prefers className (if provided) to value, so we do the same here.
TypeMirror impType = getImplementedClassName(am);
if (impType != null) {
return impType;
}
AnnotationValue av = getAnnotationValue(am, "value");
if (av == null) {
return null;
}
TypeMirror type = valueVisitor.visit(av);
if (type == null) {
return null;
}
// If the class is Robolectric.Anything, treat as if it wasn't specified at all.
if (ANYTHING_MIRROR != null && types.isSameType(type, ANYTHING_MIRROR)) {
return null;
}
return type;
}
use of javax.lang.model.element.AnnotationValue in project robolectric by robolectric.
the class RobolectricModel method getImplementedClassName.
private TypeMirror getImplementedClassName(AnnotationMirror am) {
AnnotationValue className = getAnnotationValue(am, "className");
if (className == null) {
return null;
}
String classNameString = classNameVisitor.visit(className);
if (classNameString == null) {
return null;
}
TypeElement impElement = elements.getTypeElement(classNameString.replace('$', '.'));
if (impElement == null) {
return null;
}
return impElement.asType();
}
use of javax.lang.model.element.AnnotationValue in project androidannotations by androidannotations.
the class AnnotationHelper method extractAnnotationClassParameter.
public DeclaredType extractAnnotationClassParameter(Element element, String annotationName, String methodName) {
AnnotationMirror annotationMirror = findAnnotationMirror(element, annotationName);
Map<? extends ExecutableElement, ? extends AnnotationValue> elementValues = annotationMirror.getElementValues();
for (Map.Entry<? extends ExecutableElement, ? extends AnnotationValue> entry : elementValues.entrySet()) {
/*
* "methodName" is unset when the default value is used
*/
if (methodName.equals(entry.getKey().getSimpleName().toString())) {
AnnotationValue annotationValue = entry.getValue();
return (DeclaredType) annotationValue.getValue();
}
}
return null;
}
use of javax.lang.model.element.AnnotationValue in project androidannotations by androidannotations.
the class RoboGuiceHandler method extractListenerTypeMirrors.
private List<TypeMirror> extractListenerTypeMirrors(Element activityElement) {
List<? extends AnnotationMirror> annotationMirrors = activityElement.getAnnotationMirrors();
String annotationName = RoboGuice.class.getName();
for (AnnotationMirror annotationMirror : annotationMirrors) {
if (annotationName.equals(annotationMirror.getAnnotationType().toString())) {
for (Map.Entry<? extends ExecutableElement, ? extends AnnotationValue> entry : annotationMirror.getElementValues().entrySet()) {
if ("value".equals(entry.getKey().getSimpleName().toString())) {
AnnotationValue action = entry.getValue();
@SuppressWarnings("unchecked") List<AnnotationValue> elements = (List<AnnotationValue>) action.getValue();
List<TypeMirror> listenerTypeMirrors = new ArrayList<>(elements.size());
for (AnnotationValue annotationValue : elements) {
listenerTypeMirrors.add((TypeMirror) annotationValue.getValue());
}
return listenerTypeMirrors;
}
}
}
}
return Collections.emptyList();
}
use of javax.lang.model.element.AnnotationValue in project javapoet by square.
the class AnnotationSpec method get.
public static AnnotationSpec get(AnnotationMirror annotation) {
TypeElement element = (TypeElement) annotation.getAnnotationType().asElement();
AnnotationSpec.Builder builder = AnnotationSpec.builder(ClassName.get(element));
Visitor visitor = new Visitor(builder);
for (ExecutableElement executableElement : annotation.getElementValues().keySet()) {
String name = executableElement.getSimpleName().toString();
AnnotationValue value = annotation.getElementValues().get(executableElement);
value.accept(visitor, name);
}
return builder.build();
}
Aggregations