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