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;
}
Aggregations