Search in sources :

Example 1 with TsBooleanLiteral

use of cz.habarta.typescript.generator.emitter.TsBooleanLiteral in project typescript-generator by vojtechhabarta.

the class DecoratorsTest method testDecoratorsOnParameterAndMethod.

@Test
public void testDecoratorsOnParameterAndMethod() {
    final Settings settings = TestUtils.settings();
    settings.outputFileType = TypeScriptFileType.implementationFile;
    settings.outputKind = TypeScriptOutputKind.module;
    settings.mapClasses = ClassMapping.asClasses;
    settings.generateConstructors = true;
    final TypeScriptGenerator typeScriptGenerator = new TypeScriptGenerator(settings);
    final Model model = typeScriptGenerator.getModelParser().parseModel(City.class);
    final TsModel tsModel = typeScriptGenerator.getModelCompiler().javaToTypeScript(model);
    final TsBeanModel bean = tsModel.getBean(City.class);
    final TsBeanModel bean2 = bean.withConstructor(bean.getConstructor().withParameters(Arrays.asList(bean.getConstructor().getParameters().get(0).withDecorators(Arrays.asList(new TsDecorator(new TsIdentifierReference("Inject"), Arrays.asList(new TsStringLiteral("token")))))))).withMethods(Arrays.asList(new TsMethodModel("greet", null, null, Collections.emptyList(), TsType.Void, Collections.emptyList(), null).withDecorators(Arrays.asList(new TsDecorator(new TsIdentifierReference("enumerable"), Arrays.asList(new TsBooleanLiteral(false)))))));
    final TsModel tsModel2 = tsModel.withBeans(Arrays.asList(bean2));
    final String output = emit(typeScriptGenerator.getEmitter(), tsModel2);
    Assertions.assertTrue(output.contains("@Inject(\"token\")"));
    Assertions.assertTrue(output.contains("@enumerable(false)"));
}
Also used : TsModel(cz.habarta.typescript.generator.emitter.TsModel) TsStringLiteral(cz.habarta.typescript.generator.emitter.TsStringLiteral) TsBeanModel(cz.habarta.typescript.generator.emitter.TsBeanModel) TsMethodModel(cz.habarta.typescript.generator.emitter.TsMethodModel) TsModel(cz.habarta.typescript.generator.emitter.TsModel) Model(cz.habarta.typescript.generator.parser.Model) TsPropertyModel(cz.habarta.typescript.generator.emitter.TsPropertyModel) TsBooleanLiteral(cz.habarta.typescript.generator.emitter.TsBooleanLiteral) TsIdentifierReference(cz.habarta.typescript.generator.emitter.TsIdentifierReference) TsBeanModel(cz.habarta.typescript.generator.emitter.TsBeanModel) TsMethodModel(cz.habarta.typescript.generator.emitter.TsMethodModel) TsDecorator(cz.habarta.typescript.generator.emitter.TsDecorator) Test(org.junit.jupiter.api.Test)

Aggregations

TsBeanModel (cz.habarta.typescript.generator.emitter.TsBeanModel)1 TsBooleanLiteral (cz.habarta.typescript.generator.emitter.TsBooleanLiteral)1 TsDecorator (cz.habarta.typescript.generator.emitter.TsDecorator)1 TsIdentifierReference (cz.habarta.typescript.generator.emitter.TsIdentifierReference)1 TsMethodModel (cz.habarta.typescript.generator.emitter.TsMethodModel)1 TsModel (cz.habarta.typescript.generator.emitter.TsModel)1 TsPropertyModel (cz.habarta.typescript.generator.emitter.TsPropertyModel)1 TsStringLiteral (cz.habarta.typescript.generator.emitter.TsStringLiteral)1 Model (cz.habarta.typescript.generator.parser.Model)1 Test (org.junit.jupiter.api.Test)1