Search in sources :

Example 6 with TSModule

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

the class TypescriptUtilsTest method getNestedInterfacesReturnsNullIfDoesNotExistsAndNonCreateRequested.

@Test
public void getNestedInterfacesReturnsNullIfDoesNotExistsAndNonCreateRequested() {
    TSModule module = new TSModule();
    module.setName("TestModule");
    TSClassType classType = new TSClassType();
    classType.setParent(module);
    classType.setName("TestClass");
    module.getElements().add(classType);
    TSInterfaceType testInterface = TypescriptUtils.getNestedInterface(classType, "TestInterface", false);
    Assert.assertNull(testInterface);
}
Also used : TSModule(io.crnk.gen.typescript.model.TSModule) TSClassType(io.crnk.gen.typescript.model.TSClassType) TSInterfaceType(io.crnk.gen.typescript.model.TSInterfaceType) Test(org.junit.Test)

Example 7 with TSModule

use of io.crnk.gen.typescript.model.TSModule 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)

Example 8 with TSModule

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

the class TSImportProcessor method processType.

private static void processType(TSSource source, TSNamedElement type) {
    TSSource refSource = getSource(type);
    // no need for inclusions of primitive types and within same file
    if (!(type instanceof TSPrimitiveType || source == refSource)) {
        TSNamedElement importedType = type;
        if (type.getParent() instanceof TSModule) {
            importedType = (TSNamedElement) type.getParent();
        }
        addImport(refSource, source, importedType);
    }
}
Also used : TSPrimitiveType(io.crnk.gen.typescript.model.TSPrimitiveType) TSModule(io.crnk.gen.typescript.model.TSModule) TSSource(io.crnk.gen.typescript.model.TSSource) TSNamedElement(io.crnk.gen.typescript.model.TSNamedElement)

Aggregations

TSModule (io.crnk.gen.typescript.model.TSModule)8 TSInterfaceType (io.crnk.gen.typescript.model.TSInterfaceType)4 TSClassType (io.crnk.gen.typescript.model.TSClassType)2 TSElement (io.crnk.gen.typescript.model.TSElement)2 TSSource (io.crnk.gen.typescript.model.TSSource)2 TSType (io.crnk.gen.typescript.model.TSType)2 Test (org.junit.Test)2 TSContainerElement (io.crnk.gen.typescript.model.TSContainerElement)1 TSField (io.crnk.gen.typescript.model.TSField)1 TSIndexSignature (io.crnk.gen.typescript.model.TSIndexSignature)1 TSNamedElement (io.crnk.gen.typescript.model.TSNamedElement)1 TSParameterizedType (io.crnk.gen.typescript.model.TSParameterizedType)1 TSPrimitiveType (io.crnk.gen.typescript.model.TSPrimitiveType)1 MetaAttribute (io.crnk.meta.model.MetaAttribute)1 MetaElement (io.crnk.meta.model.MetaElement)1 MetaKey (io.crnk.meta.model.MetaKey)1 MetaResource (io.crnk.meta.model.resource.MetaResource)1