Search in sources :

Example 26 with ClassRef

use of io.sundr.model.ClassRef in project sundrio by sundrio.

the class SimpleClassWithInheritanceTest method testEditable.

@Test
public void testEditable() {
    TypeDef editable = ClazzAs.EDITABLE.apply(simpleClassWithDateDef);
    System.out.println(editable);
    assertEquals(Kind.CLASS, editable.getKind());
    assertEquals("EditableSimpleClassWithDate", editable.getName());
    assertEquals(1, editable.getExtendsList().size());
    ClassRef superClass = editable.getExtendsList().iterator().next();
    assertEquals(simpleClassWithDateDef.toInternalReference(), superClass);
}
Also used : TypeDef(io.sundr.model.TypeDef) RichTypeDef(io.sundr.model.RichTypeDef) ClassRef(io.sundr.model.ClassRef) Test(org.junit.Test)

Example 27 with ClassRef

use of io.sundr.model.ClassRef in project sundrio by sundrio.

the class SimpleClassWithParameterTest method testEditable.

@Test
public void testEditable() {
    TypeDef editable = ClazzAs.EDITABLE.apply(simpleClassWithParameterDef);
    System.out.println(editable);
    assertEquals(Kind.CLASS, editable.getKind());
    assertEquals("EditableSimpleClassWithParameter", editable.getName());
    assertEquals(1, editable.getExtendsList().size());
    ClassRef superClass = editable.getExtendsList().iterator().next();
    assertEquals(simpleClassWithParameterDef.toInternalReference(), superClass);
}
Also used : TypeDef(io.sundr.model.TypeDef) RichTypeDef(io.sundr.model.RichTypeDef) ClassRef(io.sundr.model.ClassRef) Test(org.junit.Test)

Example 28 with ClassRef

use of io.sundr.model.ClassRef in project sundrio by sundrio.

the class SimpleClassWithParameterTest method testFluentImpl.

@Test
public void testFluentImpl() {
    TypeDef fluentImpl = ClazzAs.FLUENT_IMPL.apply(simpleClassWithParameterDef);
    System.out.println(fluentImpl);
    assertEquals(Kind.CLASS, fluentImpl.getKind());
    assertEquals("SimpleClassWithParameterFluentImpl", fluentImpl.getName());
    assertEquals(1, fluentImpl.getExtendsList().size());
    ClassRef superClass = fluentImpl.getExtendsList().iterator().next();
    assertEquals("BaseFluent", superClass.getName());
    assertEquals(1, superClass.getArguments().size());
    assertEquals("A", superClass.getArguments().iterator().next().toString());
}
Also used : TypeDef(io.sundr.model.TypeDef) RichTypeDef(io.sundr.model.RichTypeDef) ClassRef(io.sundr.model.ClassRef) Test(org.junit.Test)

Example 29 with ClassRef

use of io.sundr.model.ClassRef 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));
        }
    }
}
Also used : TypeParamRef(io.sundr.model.TypeParamRef) List(java.util.List) ClassRefBuilder(io.sundr.model.ClassRefBuilder) TypedVisitor(io.sundr.builder.TypedVisitor) Map(java.util.Map) TypeParamRef(io.sundr.model.TypeParamRef) Optional(java.util.Optional) TypeRef(io.sundr.model.TypeRef) Collectors(java.util.stream.Collectors) MethodFluent(io.sundr.model.MethodFluent) AttributeKey(io.sundr.model.AttributeKey) ClassRef(io.sundr.model.ClassRef) Maps(io.sundr.utils.Maps) ClassRef(io.sundr.model.ClassRef) TypeRef(io.sundr.model.TypeRef) ClassRefBuilder(io.sundr.model.ClassRefBuilder) List(java.util.List)

Example 30 with ClassRef

use of io.sundr.model.ClassRef 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());
    }
}
Also used : ClassRef(io.sundr.model.ClassRef) ClassRefBuilder(io.sundr.model.ClassRefBuilder)

Aggregations

ClassRef (io.sundr.model.ClassRef)68 TypeDef (io.sundr.model.TypeDef)41 TypeRef (io.sundr.model.TypeRef)35 RichTypeDef (io.sundr.model.RichTypeDef)22 ClassRefBuilder (io.sundr.model.ClassRefBuilder)21 ArrayList (java.util.ArrayList)21 Property (io.sundr.model.Property)19 Method (io.sundr.model.Method)18 TypeDefBuilder (io.sundr.model.TypeDefBuilder)18 Test (org.junit.Test)17 List (java.util.List)12 AnnotationRef (io.sundr.model.AnnotationRef)11 MethodBuilder (io.sundr.model.MethodBuilder)11 Collectors (java.util.stream.Collectors)11 TypedVisitor (io.sundr.builder.TypedVisitor)10 TypeParamDef (io.sundr.model.TypeParamDef)10 LinkedHashSet (java.util.LinkedHashSet)10 PropertyBuilder (io.sundr.model.PropertyBuilder)9 Map (java.util.Map)9 AttributeKey (io.sundr.model.AttributeKey)8