use of io.sundr.model.ClassRefBuilder in project sundrio by sundrio.
the class TypeToTypeRef method apply.
@Override
public TypeRef apply(Type type) {
if (type instanceof VoidType) {
return new VoidRef();
} else if (type instanceof WildcardType) {
return new WildcardRef();
} else if (type instanceof ReferenceType) {
ReferenceType referenceType = (ReferenceType) type;
int dimensions = referenceType.getArrayCount();
TypeRef typeRef = apply(referenceType.getType());
if (dimensions == 0) {
return typeRef;
} else if (typeRef instanceof ClassRef) {
return new ClassRefBuilder((ClassRef) typeRef).withDimensions(dimensions).build();
} else if (typeRef instanceof PrimitiveRef) {
return new PrimitiveRefBuilder((PrimitiveRef) typeRef).withDimensions(dimensions).build();
} else if (typeRef instanceof TypeParamRef) {
return new TypeParamRefBuilder((TypeParamRef) typeRef).withDimensions(dimensions).build();
}
} else if (type instanceof PrimitiveType) {
PrimitiveType primitiveType = (PrimitiveType) type;
return new PrimitiveRefBuilder().withName(primitiveType.getType().name()).build();
} else if (type instanceof ClassOrInterfaceType) {
return classOrInterfaceToTypeRef.apply((ClassOrInterfaceType) type);
}
throw new IllegalArgumentException("Can't handle type:[" + type + "].");
}
use of io.sundr.model.ClassRefBuilder in project sundrio by sundrio.
the class ApplyTypeParamMappingToMethod method visit.
@Override
public void visit(MethodFluent<?> method) {
TypeRef typeRef = method.buildReturnType();
if (typeRef instanceof TypeParamRef) {
TypeParamRef typeParamRef = (TypeParamRef) typeRef;
String key = typeParamRef.getName();
TypeRef paramRef = mappings.get(key);
if (paramRef != null) {
method.withReturnType(paramRef);
attributeKey.ifPresent(k -> method.addToAttributes(k, typeParamRef));
}
} else if (typeRef instanceof ClassRef) {
ClassRef classRef = (ClassRef) typeRef;
if (classRef.getArguments().stream().anyMatch(a -> a instanceof TypeParamRef)) {
List<TypeRef> mappedArguments = classRef.getArguments().stream().map(a -> a instanceof TypeParamRef ? mappings.getOrDefault(((TypeParamRef) a).getName(), a) : a).collect(Collectors.toList());
method.withReturnType(new ClassRefBuilder(classRef).withArguments(mappedArguments).build());
attributeKey.ifPresent(k -> method.addToAttributes(k, classRef));
}
}
}
use of io.sundr.model.ClassRefBuilder in project sundrio by sundrio.
the class ReplacePackage method visitPropertyBuilder.
private void visitPropertyBuilder(PropertyBuilder builder) {
if (builder.getTypeRef() instanceof ClassRef) {
ClassRefBuilder classRefBuilder = new ClassRefBuilder((ClassRef) builder.getTypeRef());
builder.withTypeRef(classRefBuilder.accept(visitor, this).build());
}
}
use of io.sundr.model.ClassRefBuilder in project sundrio by sundrio.
the class CollectionsTest method testCollections.
@Test
public void testCollections() throws Exception {
DefinitionRepository.getRepository().register(LIST);
DefinitionRepository.getRepository().register(ARRAY_LIST);
DefinitionRepository.getRepository().register(LINKED_LIST);
DefinitionRepository.getRepository().register(MAP);
ClassRef list = new ClassRefBuilder().withFullyQualifiedName("java.util.List").build();
ClassRef listOfString = new ClassRefBuilder().withFullyQualifiedName("java.util.List").addNewClassRefArgument().withFullyQualifiedName("java.lang.String").endClassRefArgument().build();
ClassRef arrayList = new ClassRefBuilder().withFullyQualifiedName("java.util.ArrayList").build();
ClassRef arrayListOfString = new ClassRefBuilder().withFullyQualifiedName("java.util.ArrayList").addNewClassRefArgument().withFullyQualifiedName("java.lang.String").endClassRefArgument().build();
ClassRef linkedList = new ClassRefBuilder().withFullyQualifiedName("java.util.LinkedList").build();
ClassRef linkedListOfString = new ClassRefBuilder().withFullyQualifiedName("java.util.LinkedList").addNewClassRefArgument().withFullyQualifiedName("java.lang.String").endClassRefArgument().build();
ClassRef map = new ClassRefBuilder().withFullyQualifiedName("java.util.Map").build();
assertTrue(Collections.IS_LIST.apply(list));
assertTrue(Collections.IS_LIST.apply(listOfString));
assertTrue(Collections.IS_LIST.apply(arrayList));
assertTrue(Collections.IS_LIST.apply(arrayListOfString));
assertTrue(Collections.IS_LIST.apply(linkedList));
assertTrue(Collections.IS_LIST.apply(linkedListOfString));
assertFalse(Collections.IS_LIST.apply(map));
}
use of io.sundr.model.ClassRefBuilder in project sundrio by sundrio.
the class TypeRefTypeVisitor method visitError.
public TypeRef visitError(ErrorType t, Integer dimension) {
TypeElement element = (TypeElement) t.asElement();
String fqcn = element.toString();
return new ClassRefBuilder().withFullyQualifiedName(fqcn).build();
}
Aggregations