Search in sources :

Example 1 with StructField

use of org.ballerinalang.composer.service.ballerina.parser.service.model.lang.StructField in project ballerina by ballerina-lang.

the class ParserUtils method createNewStruct.

/**
 * Create new struct.
 *
 * @param name   name of the struct
 * @param fields field definiton statements
 * @return {Function} function
 */
private static Struct createNewStruct(String name, List<BLangVariable> fields, String fileName) {
    Struct struct = new Struct(name);
    fields.forEach((field) -> {
        String defaultValue = null;
        if (field.getInitialExpression() != null) {
            defaultValue = ((BLangLiteral) field.getInitialExpression()).getValue().toString();
        }
        StructField structField = createNewStructField(field.getName().getValue(), field.getTypeNode().type.toString(), defaultValue);
        struct.addStructField(structField);
    });
    struct.setFileName(fileName);
    return struct;
}
Also used : BLangLiteral(org.wso2.ballerinalang.compiler.tree.expressions.BLangLiteral) StructField(org.ballerinalang.composer.service.ballerina.parser.service.model.lang.StructField) Struct(org.ballerinalang.composer.service.ballerina.parser.service.model.lang.Struct) BLangStruct(org.wso2.ballerinalang.compiler.tree.BLangStruct)

Aggregations

Struct (org.ballerinalang.composer.service.ballerina.parser.service.model.lang.Struct)1 StructField (org.ballerinalang.composer.service.ballerina.parser.service.model.lang.StructField)1 BLangStruct (org.wso2.ballerinalang.compiler.tree.BLangStruct)1 BLangLiteral (org.wso2.ballerinalang.compiler.tree.expressions.BLangLiteral)1