use of javax.lang.model.element.AnnotationValue in project squidb by yahoo.
the class ErrorLoggingProcessor method logErrors.
@SuppressWarnings("unchecked")
private void logErrors(Element element) {
AnnotationValue errorsArrayValue = utils.getAnnotationValue(element, ModelGenErrors.class, "value");
List<? extends AnnotationValue> errorsList = (List<? extends AnnotationValue>) errorsArrayValue.getValue();
for (AnnotationValue error : errorsList) {
logSingleError(error);
}
}
use of javax.lang.model.element.AnnotationValue in project j2objc by google.
the class AnnotationRewriter method addDefaultAccessors.
// Create accessors for properties that have default values.
private void addDefaultAccessors(AnnotationTypeDeclaration node, List<AnnotationTypeMemberDeclaration> members) {
TypeElement type = node.getTypeElement();
for (AnnotationTypeMemberDeclaration member : members) {
ExecutableElement memberElement = member.getExecutableElement();
AnnotationValue defaultValue = memberElement.getDefaultValue();
if (defaultValue == null || defaultValue.getValue() == null) {
continue;
}
TypeMirror memberType = memberElement.getReturnType();
String propName = NameTable.getAnnotationPropertyName(memberElement);
ExecutableElement defaultGetterElement = GeneratedExecutableElement.newMethodWithSelector(propName + "Default", memberType, type).addModifiers(Modifier.STATIC);
MethodDeclaration defaultGetter = new MethodDeclaration(defaultGetterElement);
defaultGetter.setHasDeclaration(false);
Block defaultGetterBody = new Block();
defaultGetter.setBody(defaultGetterBody);
defaultGetterBody.addStatement(new ReturnStatement(translationUtil.createAnnotationValue(memberType, defaultValue)));
node.addBodyDeclaration(defaultGetter);
}
}
use of javax.lang.model.element.AnnotationValue in project error-prone by google.
the class RequiredAnnotationProcessor method validateElement.
private void validateElement(final Element element) {
TypeMirror requiredAnnotationTypeMirror = processingEnv.getElementUtils().getTypeElement(RequiredAnnotation.class.getName()).asType();
for (final AnnotationMirror annotation : processingEnv.getElementUtils().getAllAnnotationMirrors(element)) {
AnnotationMirror requiredAnnotationMirror = getAnnotationMirror(annotation.getAnnotationType().asElement(), requiredAnnotationTypeMirror);
if (requiredAnnotationMirror == null) {
continue;
}
AnnotationValue value = getAnnotationValue(requiredAnnotationMirror, "value");
if (value == null) {
continue;
}
new SimpleAnnotationValueVisitor7<Void, Void>() {
@Override
public Void visitType(TypeMirror t, Void p) {
if (getAnnotationMirror(element, t) == null) {
printError(element, annotation, "Annotation %s on %s also requires %s", annotation, element, t);
}
return null;
}
@Override
public Void visitArray(List<? extends AnnotationValue> vals, Void p) {
for (AnnotationValue val : vals) {
visit(val);
}
return null;
}
}.visit(value);
}
validateElements(element.getEnclosedElements());
}
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();
}
Aggregations