Search in sources :

Example 1 with EnumDoc

use of org.ballerinalang.docgen.model.EnumDoc in project ballerina by ballerina-lang.

the class Generator method createDocForNode.

/**
 * Create documentation for enums.
 * @param enumNode ballerina enum node.
 * @return documentation for enum.
 */
public static EnumDoc createDocForNode(EnumNode enumNode) {
    String enumName = enumNode.getName().getValue();
    List<Variable> enumerators = new ArrayList<>();
    // Iterate through the enumerators
    if (enumNode.getEnumerators().size() > 0) {
        for (EnumNode.Enumerator enumerator : enumNode.getEnumerators()) {
            String desc = fieldAnnotation((BLangNode) enumNode, (BLangNode) enumerator);
            Variable variable = new Variable(enumerator.getName().getValue(), "", desc);
            enumerators.add(variable);
        }
    }
    return new EnumDoc(enumName, description((BLangNode) enumNode), new ArrayList<>(), enumerators);
}
Also used : EnumDoc(org.ballerinalang.docgen.model.EnumDoc) BLangNode(org.wso2.ballerinalang.compiler.tree.BLangNode) BLangVariable(org.wso2.ballerinalang.compiler.tree.BLangVariable) Variable(org.ballerinalang.docgen.model.Variable) ArrayList(java.util.ArrayList) EnumNode(org.ballerinalang.model.tree.EnumNode)

Example 2 with EnumDoc

use of org.ballerinalang.docgen.model.EnumDoc in project ballerina by ballerina-lang.

the class HtmlDocTest method testEnums.

@Test(description = "Enums in a package should be shown in the constructs")
public void testEnums() throws Exception {
    BLangPackage bLangPackage = createPackage("package x.y; " + "public enum Direction {IN,OUT}" + "public enum Money {USD,LKR}");
    Page page = generatePage(bLangPackage);
    Assert.assertEquals(page.constructs.size(), 2);
    Assert.assertEquals(page.constructs.get(0).name, "Direction");
    Assert.assertTrue(page.constructs.get(0) instanceof EnumDoc, "Invalid documentable type.");
    Assert.assertEquals(((EnumDoc) page.constructs.get(0)).enumerators.get(0).toString(), "IN", "Invalid enum val");
    Assert.assertEquals(((EnumDoc) page.constructs.get(0)).enumerators.get(1).toString(), "OUT", "Invalid enum val");
    Assert.assertEquals(page.constructs.get(1).name, "Money");
}
Also used : EnumDoc(org.ballerinalang.docgen.model.EnumDoc) BLangPackage(org.wso2.ballerinalang.compiler.tree.BLangPackage) Page(org.ballerinalang.docgen.model.Page) Test(org.testng.annotations.Test)

Example 3 with EnumDoc

use of org.ballerinalang.docgen.model.EnumDoc in project ballerina by ballerina-lang.

the class HtmlDocTest method testEnumPropertiesExtracted.

@Test(description = "Enum properties should be available via construct")
public void testEnumPropertiesExtracted() throws Exception {
    BLangPackage bLangPackage = createPackage("package x.y; " + "@Description { value:\"The direction of the parameter\"}\n" + "@Field { value:\"IN: IN parameters are used to send values to stored procedures\"}\n" + "@Field { value:\"OUT: OUT parameters are used to get values from stored procedures\"}\n" + "public enum Direction { IN,OUT}");
    EnumDoc enumDoc = Generator.createDocForNode(bLangPackage.getEnums().get(0));
    Assert.assertEquals(enumDoc.name, "Direction", "Enum name should be extracted");
    Assert.assertEquals(enumDoc.description, "The direction of the parameter", "Description of the " + "enum should be extracted");
    // Enumerators inside the enum
    Assert.assertEquals(enumDoc.enumerators.get(0).name, "IN", "Enumerator name should be extracted");
    Assert.assertEquals(enumDoc.enumerators.get(0).description, "IN parameters are used to send values to " + "stored procedures", "Description of the enumerator should be extracted");
}
Also used : EnumDoc(org.ballerinalang.docgen.model.EnumDoc) BLangPackage(org.wso2.ballerinalang.compiler.tree.BLangPackage) Test(org.testng.annotations.Test)

Aggregations

EnumDoc (org.ballerinalang.docgen.model.EnumDoc)3 Test (org.testng.annotations.Test)2 BLangPackage (org.wso2.ballerinalang.compiler.tree.BLangPackage)2 ArrayList (java.util.ArrayList)1 Page (org.ballerinalang.docgen.model.Page)1 Variable (org.ballerinalang.docgen.model.Variable)1 EnumNode (org.ballerinalang.model.tree.EnumNode)1 BLangNode (org.wso2.ballerinalang.compiler.tree.BLangNode)1 BLangVariable (org.wso2.ballerinalang.compiler.tree.BLangVariable)1