Search in sources :

Example 1 with TypeRefTypeVisitor

use of io.sundr.adapter.apt.visitors.TypeRefTypeVisitor in project sundrio by sundrio.

the class AnnotationMirrorToAnnotationRef method apply.

@Override
public AnnotationRef apply(AnnotationMirror item) {
    TypeRef annotationType = item.getAnnotationType().accept(new TypeRefTypeVisitor(context), 0);
    Map<String, Object> parameters = new HashMap<String, Object>();
    if (annotationType instanceof ClassRef) {
        for (Map.Entry<? extends ExecutableElement, ? extends AnnotationValue> entry : item.getElementValues().entrySet()) {
            checkEntry(entry);
            String key = entry.getKey().toString().replace(EMPTY_PARENTHESIS, EMPTY);
            Object value = mapAnnotationValue(entry.getValue().getValue());
            parameters.put(key, value);
        }
        return new AnnotationRefBuilder().withClassRef((ClassRef) annotationType).withParameters(parameters).build();
    }
    throw new IllegalStateException("Annotation type: [" + annotationType + "] is not a class reference.");
}
Also used : ClassRef(io.sundr.model.ClassRef) HashMap(java.util.HashMap) AnnotationRefBuilder(io.sundr.model.AnnotationRefBuilder) TypeRef(io.sundr.model.TypeRef) TypeRefTypeVisitor(io.sundr.adapter.apt.visitors.TypeRefTypeVisitor) HashMap(java.util.HashMap) Map(java.util.Map)

Example 2 with TypeRefTypeVisitor

use of io.sundr.adapter.apt.visitors.TypeRefTypeVisitor in project sundrio by sundrio.

the class TypeMirrorToTypeRef method apply.

@Override
public TypeRef apply(TypeMirror item) {
    if (item instanceof NoType) {
        return new VoidRef();
    }
    if (item == null) {
        throw new IllegalArgumentException("TypeMirror cannot be null.");
    }
    Element element = AptContext.getContext().getTypes().asElement(item);
    TypeRef typeRef = item.accept(new TypeRefTypeVisitor(context), 0);
    if (typeRef instanceof ClassRef && element instanceof TypeElement) {
        TypeElement typeElement = (TypeElement) element;
        String fqcn = typeElement.toString();
        context.getReferences().add((TypeElement) element);
        return new ClassRefBuilder((ClassRef) typeRef).withNewFullyQualifiedName(fqcn).build();
    }
    return typeRef;
}
Also used : ClassRef(io.sundr.model.ClassRef) NoType(javax.lang.model.type.NoType) TypeRef(io.sundr.model.TypeRef) TypeElement(javax.lang.model.element.TypeElement) VoidRef(io.sundr.model.VoidRef) Element(javax.lang.model.element.Element) TypeElement(javax.lang.model.element.TypeElement) ClassRefBuilder(io.sundr.model.ClassRefBuilder) TypeRefTypeVisitor(io.sundr.adapter.apt.visitors.TypeRefTypeVisitor)

Aggregations

TypeRefTypeVisitor (io.sundr.adapter.apt.visitors.TypeRefTypeVisitor)2 ClassRef (io.sundr.model.ClassRef)2 TypeRef (io.sundr.model.TypeRef)2 AnnotationRefBuilder (io.sundr.model.AnnotationRefBuilder)1 ClassRefBuilder (io.sundr.model.ClassRefBuilder)1 VoidRef (io.sundr.model.VoidRef)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Element (javax.lang.model.element.Element)1 TypeElement (javax.lang.model.element.TypeElement)1 NoType (javax.lang.model.type.NoType)1