use of io.crnk.gen.typescript.model.TSSource in project crnk-framework by crnk-project.
the class TSMetaDataObjectTransformation method setupParent.
private static void setupParent(TSMetaTransformationContext context, TSInterfaceType interfaceType, MetaDataObject metaDataObject) {
TSContainerElement parent = null;
// move links and meta information to the resource itself
boolean isMeta = TypescriptUtils.isInstance(metaDataObject.getImplementationClass(), "io.crnk.core.resource.meta.MetaInformation");
boolean isLinks = TypescriptUtils.isInstance(metaDataObject.getImplementationClass(), "io.crnk.core.resource.links.LinksInformation");
if ((isMeta || isLinks) && metaDataObject.getImplementationClass().getEnclosingClass() != null) {
MetaElement enclosingMeta = context.getMeta(metaDataObject.getImplementationClass().getEnclosingClass());
if (enclosingMeta instanceof MetaResource) {
TSType enclosingType = (TSType) context.transform(enclosingMeta, TSMetaTransformationOptions.EMPTY);
TSModule module = TypescriptUtils.getNestedTypeContainer(enclosingType, true);
interfaceType.setName(isLinks ? "Links" : "Meta");
parent = module;
}
}
if (parent == null) {
TSSource source = new TSSource();
source.setName(TypescriptUtils.toFileName(metaDataObject.getName()));
source.setNpmPackage(context.getNpmPackage(metaDataObject));
source.setDirectory(context.getDirectory(metaDataObject));
context.addSource(source);
parent = source;
}
parent.getElements().add(interfaceType);
interfaceType.setParent(parent);
}
use of io.crnk.gen.typescript.model.TSSource in project crnk-framework by crnk-project.
the class TSImportProcessor method process.
@Override
public Set<TSSource> process(Set<TSSource> sources) {
for (TSSource source : sources) {
transform(source);
sortImports(source);
}
return sources;
}
use of io.crnk.gen.typescript.model.TSSource in project crnk-framework by crnk-project.
the class TSMetaEnumTypeTransformation method transform.
@Override
public TSElement transform(MetaElement elementObj, TSMetaTransformationContext context, TSMetaTransformationOptions options) {
MetaEnumType element = (MetaEnumType) elementObj;
TSSource source = new TSSource();
source.setName(TypescriptUtils.toFileName(element.getName()));
source.setNpmPackage(context.getNpmPackage(element));
source.setDirectory(context.getDirectory(element));
Class<?> implementationClass = element.getImplementationClass();
TSEnumType enumType = new TSEnumType();
enumType.setExported(true);
enumType.setParent(source);
enumType.setName(element.getName());
for (Object literal : implementationClass.getEnumConstants()) {
enumType.getLiterals().add(new TSEnumLiteral(literal.toString()));
}
source.getElements().add(enumType);
context.putMapping(element, enumType);
context.addSource(source);
return enumType;
}
use of io.crnk.gen.typescript.model.TSSource in project crnk-framework by crnk-project.
the class TSIndexFileProcessor method process.
@Override
public Set<TSSource> process(Set<TSSource> sources) {
Set<TSSource> newSources = new HashSet<>(sources);
Map<String, List<TSSource>> directoryIndex = new HashMap<>();
for (TSSource fileSource : sources) {
String dir = fileSource.getDirectory();
if (!directoryIndex.containsKey(dir)) {
directoryIndex.put(dir, new ArrayList<TSSource>());
}
directoryIndex.get(dir).add(fileSource);
}
List<String> keys = new ArrayList<>(directoryIndex.keySet());
Collections.sort(keys);
for (String key : keys) {
List<TSSource> sourceFiles = new ArrayList<>(directoryIndex.get(key));
Collections.sort(sourceFiles, new Comparator<TSSource>() {
@Override
public int compare(TSSource o1, TSSource o2) {
return o1.getName().compareTo(o2.getName());
}
});
TSSource indexSource = new TSSource();
indexSource.setName("index");
indexSource.setNpmPackage(sourceFiles.get(0).getNpmPackage());
indexSource.setDirectory(key);
for (TSSource sourceFile : sourceFiles) {
TSExport exportElement = new TSExport();
exportElement.setAny(true);
exportElement.setPath("./" + sourceFile.getName());
indexSource.getExports().add(exportElement);
}
newSources.add(indexSource);
}
return newSources;
}
use of io.crnk.gen.typescript.model.TSSource in project crnk-framework by crnk-project.
the class TSGenerator method writeSources.
protected void writeSources() throws IOException {
for (TSSource fileSource : sources) {
TSWriter writer = new TSWriter(config.getCodeStyle());
fileSource.accept(writer);
File file = getFile(fileSource);
String source = writer.toString();
write(file, source);
}
}
Aggregations