Search in sources :

Example 1 with TsArrowFunction

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

the class JsonDeserializationExtension method createDeserializationGenericFunctionConstructor.

private static TsMethodModel createDeserializationGenericFunctionConstructor(SymbolTable symbolTable, TsModel tsModel, TsBeanModel bean) {
    final Symbol beanIdentifier = symbolTable.getSymbol(bean.getOrigin());
    List<TsType.GenericVariableType> typeParameters = getTypeParameters(bean.getOrigin());
    final TsType.ReferenceType dataType = new TsType.GenericReferenceType(beanIdentifier, typeParameters);
    final List<TsParameterModel> constructorFnOfParameters = getConstructorFnOfParameters(typeParameters);
    final List<TsExpression> arguments = new ArrayList<>();
    arguments.add(new TsIdentifierReference("data"));
    for (TsParameterModel constructorFnOfParameter : constructorFnOfParameters) {
        arguments.add(new TsIdentifierReference(constructorFnOfParameter.name));
    }
    final List<TsStatement> body = new ArrayList<>();
    body.add(new TsReturnStatement(new TsArrowFunction(Arrays.asList(new TsParameter("data", null)), new TsCallExpression(new TsMemberExpression(new TsTypeReferenceExpression(new TsType.ReferenceType(beanIdentifier)), "fromData"), null, arguments))));
    return new TsMethodModel("fromDataFn", TsModifierFlags.None.setStatic(), typeParameters, constructorFnOfParameters, new TsType.FunctionType(Arrays.asList(new TsParameter("data", dataType)), dataType), body, null);
}
Also used : TsStatement(cz.habarta.typescript.generator.emitter.TsStatement) TsMemberExpression(cz.habarta.typescript.generator.emitter.TsMemberExpression) TsExpression(cz.habarta.typescript.generator.emitter.TsExpression) Symbol(cz.habarta.typescript.generator.compiler.Symbol) ArrayList(java.util.ArrayList) TsType(cz.habarta.typescript.generator.TsType) TsReturnStatement(cz.habarta.typescript.generator.emitter.TsReturnStatement) TsArrowFunction(cz.habarta.typescript.generator.emitter.TsArrowFunction) TsCallExpression(cz.habarta.typescript.generator.emitter.TsCallExpression) TsTypeReferenceExpression(cz.habarta.typescript.generator.emitter.TsTypeReferenceExpression) TsParameter(cz.habarta.typescript.generator.TsParameter) TsIdentifierReference(cz.habarta.typescript.generator.emitter.TsIdentifierReference) TsMethodModel(cz.habarta.typescript.generator.emitter.TsMethodModel) TsParameterModel(cz.habarta.typescript.generator.emitter.TsParameterModel)

Aggregations

TsParameter (cz.habarta.typescript.generator.TsParameter)1 TsType (cz.habarta.typescript.generator.TsType)1 Symbol (cz.habarta.typescript.generator.compiler.Symbol)1 TsArrowFunction (cz.habarta.typescript.generator.emitter.TsArrowFunction)1 TsCallExpression (cz.habarta.typescript.generator.emitter.TsCallExpression)1 TsExpression (cz.habarta.typescript.generator.emitter.TsExpression)1 TsIdentifierReference (cz.habarta.typescript.generator.emitter.TsIdentifierReference)1 TsMemberExpression (cz.habarta.typescript.generator.emitter.TsMemberExpression)1 TsMethodModel (cz.habarta.typescript.generator.emitter.TsMethodModel)1 TsParameterModel (cz.habarta.typescript.generator.emitter.TsParameterModel)1 TsReturnStatement (cz.habarta.typescript.generator.emitter.TsReturnStatement)1 TsStatement (cz.habarta.typescript.generator.emitter.TsStatement)1 TsTypeReferenceExpression (cz.habarta.typescript.generator.emitter.TsTypeReferenceExpression)1 ArrayList (java.util.ArrayList)1