
org.checkerframework.common.wholeprograminference.AnnotationConverter Maven / Gradle / Ivy
package org.checkerframework.common.wholeprograminference;
import com.sun.tools.javac.code.Attribute.Array;
import com.sun.tools.javac.code.Type;
import com.sun.tools.javac.code.Type.ArrayType;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.annotation.processing.ProcessingEnvironment;
import javax.lang.model.element.AnnotationMirror;
import javax.lang.model.element.AnnotationValue;
import javax.lang.model.element.ExecutableElement;
import javax.lang.model.element.VariableElement;
import javax.lang.model.type.TypeMirror;
import org.checkerframework.javacutil.AnnotationBuilder;
import org.checkerframework.javacutil.AnnotationUtils;
import org.checkerframework.javacutil.ErrorReporter;
import scenelib.annotations.Annotation;
import scenelib.annotations.el.AnnotationDef;
import scenelib.annotations.field.AnnotationFieldType;
import scenelib.annotations.field.ArrayAFT;
import scenelib.annotations.field.BasicAFT;
import scenelib.annotations.field.ScalarAFT;
/**
* This class has auxiliary methods that performs conversion between {@link
* scenelib.annotations.Annotation} and {@link javax.lang.model.element.AnnotationMirror}.
*
* @author pbsf
*/
public class AnnotationConverter {
/**
* 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 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 newValues = new HashMap<>();
for (ExecutableElement ee : values.keySet()) {
Object value = values.get(ee).getValue();
if (value instanceof List) {
@SuppressWarnings("unchecked")
List
© 2015 - 2025 Weber Informatics LLC | Privacy Policy