use of io.crnk.gen.typescript.model.TSEnumLiteral 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.TSEnumLiteral in project crnk-framework by crnk-project.
the class TSWriter method visit.
@Override
public void visit(TSEnumType element) {
// we make use of string literal types since enums are number-based in Typescript
appendLine();
appendExported(element);
builder.append("type ");
builder.append(element.getName());
builder.append(" = ");
List<TSEnumLiteral> literals = element.getLiterals();
for (int i = 0; i < literals.size(); i++) {
if (i > 0) {
builder.append(" | ");
}
TSEnumLiteral literal = literals.get(i);
builder.append('\'');
builder.append(literal.getValue());
builder.append('\'');
}
builder.append(";");
}
Aggregations