Search in sources :

Example 1 with Field

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);
}
Also used : Field(org.ballerinalang.docgen.model.Field) ArrayList(java.util.ArrayList) StructDoc(org.ballerinalang.docgen.model.StructDoc) BLangVariable(org.wso2.ballerinalang.compiler.tree.BLangVariable)

Aggregations

ArrayList (java.util.ArrayList)1 Field (org.ballerinalang.docgen.model.Field)1 StructDoc (org.ballerinalang.docgen.model.StructDoc)1 BLangVariable (org.wso2.ballerinalang.compiler.tree.BLangVariable)1