Search in sources :

Example 1 with TSParameterizedType

use of io.crnk.gen.typescript.model.TSParameterizedType in project crnk-framework by crnk-project.

the class TSMetaDataObjectTransformation method generateResourceField.

private static void generateResourceField(MetaAttribute attr, TSMetaTransformationContext context, TSInterfaceType interfaceType, TSInterfaceType attributesType, TSInterfaceType relationshipsType) {
    MetaType metaElementType = attr.getType().getElementType();
    TSType elementType = (TSType) context.transform(metaElementType, TSMetaTransformationOptions.EMPTY);
    TSField field = new TSField();
    field.setName(attr.getName());
    field.setType(elementType);
    field.setNullable(true);
    if (attr.isAssociation()) {
        TSType relationshipType = attr.getType().isCollection() ? NgrxJsonApiLibrary.TYPED_MANY_RESOURCE_RELATIONSHIP : NgrxJsonApiLibrary.TYPED_ONE_RESOURCE_RELATIONSHIP;
        field.setType(new TSParameterizedType(relationshipType, elementType));
        relationshipsType.getDeclaredMembers().add(field);
        field.setParent(relationshipsType);
    } else if (attr instanceof MetaResourceField && ((MetaResourceField) attr).isMeta()) {
        field.setName("meta");
        interfaceType.getDeclaredMembers().add(field);
        field.setParent(interfaceType);
    } else if (attr instanceof MetaResourceField && ((MetaResourceField) attr).isLinks()) {
        field.setName("links");
        interfaceType.getDeclaredMembers().add(field);
        field.setParent(interfaceType);
    } else {
        attributesType.getDeclaredMembers().add(field);
        field.setParent(attributesType);
    }
}
Also used : MetaResourceField(io.crnk.meta.model.resource.MetaResourceField) TSField(io.crnk.gen.typescript.model.TSField) TSParameterizedType(io.crnk.gen.typescript.model.TSParameterizedType) TSType(io.crnk.gen.typescript.model.TSType) MetaType(io.crnk.meta.model.MetaType)

Example 2 with TSParameterizedType

use of io.crnk.gen.typescript.model.TSParameterizedType in project crnk-framework by crnk-project.

the class TSWriter method visitReference.

public void visitReference(TSType type) {
    if (type instanceof TSParameterizedType) {
        TSParameterizedType paramType = (TSParameterizedType) type;
        visitReference(paramType.getBaseType());
        builder.append("<");
        List<TSType> parameters = paramType.getParameters();
        for (int i = 0; i < parameters.size(); i++) {
            if (i > 0) {
                builder.append(", ");
            }
            visitReference(parameters.get(i));
        }
        builder.append(">");
    } else {
        if (type.getParent() instanceof TSModule) {
            visitReference((TSModule) type.getParent());
            builder.append(".");
        }
        builder.append(type.getName());
    }
}
Also used : TSParameterizedType(io.crnk.gen.typescript.model.TSParameterizedType) TSModule(io.crnk.gen.typescript.model.TSModule) TSType(io.crnk.gen.typescript.model.TSType)

Aggregations

TSParameterizedType (io.crnk.gen.typescript.model.TSParameterizedType)2 TSType (io.crnk.gen.typescript.model.TSType)2 TSField (io.crnk.gen.typescript.model.TSField)1 TSModule (io.crnk.gen.typescript.model.TSModule)1 MetaType (io.crnk.meta.model.MetaType)1 MetaResourceField (io.crnk.meta.model.resource.MetaResourceField)1