Search in sources :

Example 1 with TSMetaTransformation

use of io.crnk.gen.typescript.transform.TSMetaTransformation in project crnk-framework by crnk-project.

the class TSGenerator method transformMetaToTypescript.

public void transformMetaToTypescript() {
    Collection<MetaElement> elements = lookup.getMetaById().values();
    LOGGER.debug("transforming {} elements", elements.size());
    for (MetaElement element : elements) {
        boolean isRoot = isRoot(element);
        boolean isGenerated = isGenerated(element);
        if (isRoot && isGenerated) {
            LOGGER.debug("transforming {}", element.getId());
            transform(element, TSMetaTransformationOptions.EMPTY);
        } else {
            LOGGER.debug("ignoring {}, root={}, generated={}", element.getId(), isRoot, isGenerated);
        }
    }
    try {
        postProcessing = true;
        for (TSElement transformedElement : new ArrayList<>(transformedElements)) {
            for (TSMetaTransformation transformation : transformations) {
                transformation.postTransform(transformedElement, createMetaTransformationContext());
            }
        }
    } finally {
        postProcessing = false;
    }
}
Also used : MetaElement(io.crnk.meta.model.MetaElement) ArrayList(java.util.ArrayList) TSMetaTransformation(io.crnk.gen.typescript.transform.TSMetaTransformation) TSElement(io.crnk.gen.typescript.model.TSElement)

Example 2 with TSMetaTransformation

use of io.crnk.gen.typescript.transform.TSMetaTransformation in project crnk-framework by crnk-project.

the class TSGenerator method transform.

protected TSElement transform(MetaElement element, TSMetaTransformationOptions options) {
    if (elementSourceMap.containsKey(element)) {
        return elementSourceMap.get(element);
    }
    if (postProcessing) {
        throw new IllegalStateException("cannot add further element while post processing: " + element.getId());
    }
    for (TSMetaTransformation transformation : transformations) {
        if (transformation.accepts(element)) {
            TSElement tsElement = transformation.transform(element, createMetaTransformationContext(), options);
            transformedElements.add(tsElement);
            return tsElement;
        }
    }
    throw new IllegalStateException("unexpected element: " + element);
}
Also used : TSMetaTransformation(io.crnk.gen.typescript.transform.TSMetaTransformation) TSElement(io.crnk.gen.typescript.model.TSElement)

Aggregations

TSElement (io.crnk.gen.typescript.model.TSElement)2 TSMetaTransformation (io.crnk.gen.typescript.transform.TSMetaTransformation)2 MetaElement (io.crnk.meta.model.MetaElement)1 ArrayList (java.util.ArrayList)1