use of io.sundr.model.TypeRef in project sundrio by sundrio.
the class TypeRefTypeVisitor method visitDeclared.
public TypeRef visitDeclared(DeclaredType t, Integer dimension) {
List<TypeRef> arguments = new ArrayList<TypeRef>();
for (TypeMirror typeMirror : t.getTypeArguments()) {
TypeRef arg = typeMirror.accept(this, dimension);
if (arg != null) {
arguments.add(arg);
}
}
TypeElement element = (TypeElement) t.asElement();
// TODO: need a cleaner way to get this registered.
if (!context.getDefinitionRepository().hasDefinition(element.toString())) {
context.getReferences().add(element);
}
String fqcn = element.toString();
return new ClassRefBuilder().withFullyQualifiedName(fqcn).withDimensions(dimension).withArguments(arguments).build();
}
use of io.sundr.model.TypeRef 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.");
}
use of io.sundr.model.TypeRef in project sundrio by sundrio.
the class AnnotationMirrorToAnnotationRef method checkEntry.
/**
* Checks if there is error extracting the specified annotation parameter
*
* @param entry the entry that represents the annotation param.
*/
private void checkEntry(Map.Entry<? extends ExecutableElement, ? extends AnnotationValue> entry) {
ExecutableElement key = entry.getKey();
Object value = entry.getValue().getValue();
if (ERROR.equals(value)) {
TypeRef returnType = referenceAdapterFunction.apply(key.getReturnType());
if (returnType.equals(Types.CLASS)) {
throw new SundrException("Failed to extract class parameter from annotation. " + Messages.POTENTIAL_UNRESOLVED_SYMBOL);
}
}
}
use of io.sundr.model.TypeRef 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;
}
use of io.sundr.model.TypeRef in project sundrio by sundrio.
the class AbstractAdapterTest method testWithPrimitiveArray.
@Test
public void testWithPrimitiveArray() {
T input = getInput(ClassWithPrimitiveArray.class);
TypeDef typeDef = Adapters.adaptType(input, getContext());
assertNotNull(typeDef);
assertEquals("ClassWithPrimitiveArray", typeDef.getName());
assertEquals(1, typeDef.getProperties().size());
TypeRef typeRef = typeDef.getProperties().iterator().next().getTypeRef();
assertTrue(typeRef instanceof PrimitiveRef);
assertEquals(1, ((PrimitiveRef) typeRef).getDimensions());
}
Aggregations