use of scenelib.annotations.el.AnnotationDef in project checker-framework by typetools.
the class AnnotationConverter method annotationMirrorToAnnotation.
/**
* Converts an {@link javax.lang.model.element.AnnotationMirror} into an {@link
* scenelib.annotations.Annotation}.
*/
protected static Annotation annotationMirrorToAnnotation(AnnotationMirror am) {
AnnotationDef def = new AnnotationDef(AnnotationUtils.annotationName(am));
Map<String, AnnotationFieldType> fieldTypes = new HashMap<>();
// Handling cases where there are fields in annotations.
for (ExecutableElement ee : am.getElementValues().keySet()) {
AnnotationFieldType aft = getAnnotationFieldType(ee, am.getElementValues().get(ee).getValue());
if (aft == null)
return null;
// Here we just add the type of the field into fieldTypes.
fieldTypes.put(ee.getSimpleName().toString(), aft);
}
def.setFieldTypes(fieldTypes);
// Now, we handle the values of those types below
Map<? extends ExecutableElement, ? extends AnnotationValue> values = am.getElementValues();
Map<String, Object> newValues = new HashMap<>();
for (ExecutableElement ee : values.keySet()) {
Object value = values.get(ee).getValue();
if (value instanceof List) {
@SuppressWarnings("unchecked") List<Object> valueList = (List<Object>) value;
List<Object> newList = new ArrayList<>();
// Converting each AnnotatedValue to its respective Java type:
for (Object o : valueList) {
newList.add(((AnnotationValue) o).getValue());
}
value = newList;
}
newValues.put(ee.getSimpleName().toString(), value);
}
Annotation out = new Annotation(def, newValues);
return out;
}
use of scenelib.annotations.el.AnnotationDef in project checker-framework by typetools.
the class ToIndexFileConverter method extractAnnotation.
/**
* Builds simplified annotation from its declaration. Only the name is included, because
* stubfiles do not generally have access to the full definitions of annotations.
*/
private static Annotation extractAnnotation(AnnotationExpr expr) {
// leave off leading '@'
String exprName = expr.toString().substring(1);
// the JDK adds, apparently for profiling.
if (exprName.contains("+")) {
return null;
}
AnnotationDef def = new AnnotationDef(exprName);
def.setFieldTypes(Collections.emptyMap());
return new Annotation(def, Collections.emptyMap());
}
Aggregations