use of javax.lang.model.element.AnnotationMirror in project auto by google.
the class GwtCompatibility method gwtCompatibleAnnotationString.
String gwtCompatibleAnnotationString() {
if (gwtCompatibleAnnotation.isPresent()) {
AnnotationMirror annotation = gwtCompatibleAnnotation.get();
TypeElement annotationElement = (TypeElement) annotation.getAnnotationType().asElement();
String annotationArguments;
if (annotation.getElementValues().isEmpty()) {
annotationArguments = "";
} else {
List<String> elements = Lists.newArrayList();
for (Map.Entry<ExecutableElement, AnnotationValue> entry : getElementValues(annotation).entrySet()) {
elements.add(entry.getKey().getSimpleName() + " = " + entry.getValue());
}
annotationArguments = "(" + Joiner.on(", ").join(elements) + ")";
}
return "@" + annotationElement.getQualifiedName() + annotationArguments;
} else {
return "";
}
}
use of javax.lang.model.element.AnnotationMirror in project auto by google.
the class AutoServiceProcessor method processAnnotations.
private void processAnnotations(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
Set<? extends Element> elements = roundEnv.getElementsAnnotatedWith(AutoService.class);
log(annotations.toString());
log(elements.toString());
for (Element e : elements) {
// TODO(gak): check for error trees?
TypeElement providerImplementer = (TypeElement) e;
AnnotationMirror providerAnnotation = getAnnotationMirror(e, AutoService.class).get();
DeclaredType providerInterface = getProviderInterface(providerAnnotation);
TypeElement providerType = (TypeElement) providerInterface.asElement();
log("provider interface: " + providerType.getQualifiedName());
log("provider implementer: " + providerImplementer.getQualifiedName());
if (!checkImplementer(providerImplementer, providerType)) {
String message = "ServiceProviders must implement their service provider interface. " + providerImplementer.getQualifiedName() + " does not implement " + providerType.getQualifiedName();
error(message, e, providerAnnotation);
}
String providerTypeName = getBinaryName(providerType);
String providerImplementerName = getBinaryName(providerImplementer);
log("provider interface binary name: " + providerTypeName);
log("provider implementer binary name: " + providerImplementerName);
providers.put(providerTypeName, providerImplementerName);
}
}
use of javax.lang.model.element.AnnotationMirror in project auto by google.
the class Parameter method forVariableElement.
static Parameter forVariableElement(VariableElement variable, TypeMirror type, Types types) {
Optional<AnnotationMirror> nullable = Optional.absent();
Iterable<? extends AnnotationMirror> annotations = variable.getAnnotationMirrors();
for (AnnotationMirror annotation : annotations) {
if (annotation.getAnnotationType().asElement().getSimpleName().contentEquals("Nullable")) {
nullable = Optional.of(annotation);
break;
}
}
Key key = Key.create(type, annotations, types);
return new AutoValue_Parameter(type, variable.getSimpleName().toString(), key, wrapOptionalInEquivalence(AnnotationMirrors.equivalence(), nullable));
}
use of javax.lang.model.element.AnnotationMirror in project j2objc by google.
the class TranslationUtil method createAnnotationValue.
public Expression createAnnotationValue(TypeMirror type, AnnotationValue aValue) {
Object value = aValue.getValue();
if (value == null) {
return new NullLiteral(typeUtil.getNull());
} else if (value instanceof VariableElement) {
return new SimpleName((VariableElement) value);
} else if (TypeUtil.isArray(type)) {
assert value instanceof List;
ArrayType arrayType = (ArrayType) type;
@SuppressWarnings("unchecked") List<? extends AnnotationValue> list = (List<? extends AnnotationValue>) value;
List<Expression> generatedValues = new ArrayList<>();
for (AnnotationValue elem : list) {
generatedValues.add(createAnnotationValue(arrayType.getComponentType(), elem));
}
return createObjectArray(generatedValues, arrayType);
} else if (TypeUtil.isAnnotation(type)) {
assert value instanceof AnnotationMirror;
return createAnnotation((AnnotationMirror) value);
} else if (value instanceof TypeMirror) {
return new TypeLiteral((TypeMirror) value, typeUtil);
} else {
// Boolean, Character, Number, String
return TreeUtil.newLiteral(value, typeUtil);
}
}
use of javax.lang.model.element.AnnotationMirror in project j2objc by google.
the class NameTable method getFullNameImpl.
private String getFullNameImpl(TypeElement element) {
// have a dash character.
if (ElementUtil.isPackageInfo(element)) {
return camelCaseQualifiedName(ElementUtil.getName(ElementUtil.getPackage(element))) + PACKAGE_INFO_OBJC_NAME;
}
// Use ObjectiveCName annotation, if it exists.
AnnotationMirror annotation = ElementUtil.getAnnotation(element, ObjectiveCName.class);
if (annotation != null) {
return (String) ElementUtil.getAnnotationValue(annotation, "value");
}
TypeElement outerClass = ElementUtil.getDeclaringClass(element);
if (outerClass != null) {
return getFullName(outerClass) + '_' + getTypeSubName(element);
}
// Use mapping file entry, if it exists.
String mappedName = classMappings.get(ElementUtil.getQualifiedName(element));
if (mappedName != null) {
return mappedName;
}
// Use camel-cased package+class name.
return getPrefix(ElementUtil.getPackage(element)) + getTypeSubName(element);
}
Aggregations