use of org.ballerinalang.docgen.model.Field in project ballerina by ballerina-lang.
the class Generator method createDocForNode.
/**
* Create documentation for structs.
* @param structNode ballerina struct node.
* @return documentation for structs.
*/
public static StructDoc createDocForNode(BLangStruct structNode) {
String structName = structNode.getName().value;
// Check if its an anonymous struct
if (structName.contains(ANONYMOUS_STRUCT)) {
structName = "Anonymous Struct";
}
List<Field> fields = new ArrayList<>();
// Iterate through the struct fields
if (structNode.getFields().size() > 0) {
for (BLangVariable param : structNode.getFields()) {
String dataType = type(param);
String desc = fieldAnnotation(structNode, param);
String defaultValue = "";
if (null != param.getInitialExpression()) {
defaultValue = param.getInitialExpression().toString();
}
Field variable = new Field(param.getName().value, dataType, desc, defaultValue);
fields.add(variable);
}
}
return new StructDoc(structName, description(structNode), new ArrayList<>(), fields);
}
Aggregations