use of org.ballerinalang.docgen.model.Page in project ballerina by ballerina-lang.
the class HtmlDocTest method testFunctionsWithWithoutStructBindings.
@Test(description = "Functions with struct bindings in a package should be grouped together and functions" + "without struct bindings should be isolated as shown in the constructs")
public void testFunctionsWithWithoutStructBindings() throws Exception {
BLangPackage bLangPackage = createPackage("package x.y; " + "public function <Message m>hello(){} " + "public struct Message { string message; int id;} " + "public function sayBye(){}");
Page page = generatePage(bLangPackage);
Assert.assertEquals(page.constructs.size(), 2);
Assert.assertEquals(page.constructs.get(0).name, "Message");
Assert.assertEquals(page.constructs.get(0).children.get(0).name, "hello");
Assert.assertEquals(page.constructs.get(1).name, "sayBye");
}
use of org.ballerinalang.docgen.model.Page in project ballerina by ballerina-lang.
the class HtmlDocTest method testEmptyPackage.
@Test(description = "Empty package should give an empty page")
public void testEmptyPackage() throws Exception {
BLangPackage bLangPackage = createPackage("package x.y;");
Page page = generatePage(bLangPackage);
Assert.assertTrue(page.constructs.isEmpty());
}
use of org.ballerinalang.docgen.model.Page in project ballerina by ballerina-lang.
the class HtmlDocTest method testStructDefaultValues.
@Test(description = "Tests whether default values are collected.")
public void testStructDefaultValues() {
BLangPackage bLangPackage = createPackage("package x.y; " + "public struct Person {" + " string id;" + " string address = \"20,Palm Grove\";" + "}");
Page page = generatePage(bLangPackage);
Assert.assertEquals(page.constructs.size(), 1);
Assert.assertTrue(page.constructs.get(0) instanceof StructDoc, "Documentable of type StructDoc expected.");
StructDoc personStructDoc = (StructDoc) page.constructs.get(0);
Assert.assertEquals(personStructDoc.fields.size(), 2, "2 fields are expected.");
Assert.assertEquals(personStructDoc.fields.get(0).name, "id", "Field \"id\" expected.");
Assert.assertEquals(personStructDoc.fields.get(1).name, "address", "Field \"address\" expected.");
Assert.assertEquals(personStructDoc.fields.get(1).defaultValue, "20,Palm Grove", "Unexpected address value found.");
}
use of org.ballerinalang.docgen.model.Page in project ballerina by ballerina-lang.
the class HtmlDocTest method testPrimitiveConstructsWithFunctions.
@Test(description = "Testing primitive constructs.")
public void testPrimitiveConstructsWithFunctions() {
BLangPackage bLangPackage = createPackage("package ballerina.builtin;" + "public native function <blob b> data (string encoding) returns" + "(string);" + "public native function <blob b> sample () returns (string);");
List<Link> packages = new ArrayList<>();
packages.add(new Link(new PackageName((bLangPackage.symbol).pkgID.name.value, ""), "", false));
packages.add(new Link(new StaticCaption(BallerinaDocConstants.PRIMITIVE_TYPES_PAGE_NAME), BallerinaDocConstants.PRIMITIVE_TYPES_PAGE_HREF, false));
Page primitivesPage = Generator.generatePageForPrimitives(bLangPackage, packages);
Assert.assertEquals(primitivesPage.constructs.size(), 1);
Assert.assertEquals(primitivesPage.constructs.get(0).children.size(), 2);
}
use of org.ballerinalang.docgen.model.Page in project ballerina by ballerina-lang.
the class Generator method generatePage.
/**
* Generate the page when the bal package is passed.
* @param balPackage The current package that is being viewed.
* @param packages List of available packages.
* @return A page model for the current package.
*/
public static Page generatePage(BLangPackage balPackage, List<Link> packages) {
ArrayList<Documentable> documentables = new ArrayList<>();
String currentPackageName = (balPackage.symbol).pkgID.name.value;
// Check for structs in the package
if (balPackage.getStructs().size() > 0) {
for (BLangStruct struct : balPackage.getStructs()) {
if (struct.getFlags().contains(Flag.PUBLIC)) {
documentables.add(createDocForNode(struct));
}
}
}
// Check for functions in the package
if (balPackage.getFunctions().size() > 0) {
for (BLangFunction function : balPackage.getFunctions()) {
if (function.getFlags().contains(Flag.PUBLIC)) {
if (function.getReceiver() != null) {
if (documentables.size() > 0) {
for (Documentable parentDocumentable : documentables) {
TypeNode langType = function.getReceiver().getTypeNode();
String typeName = (langType instanceof BLangUserDefinedType ? ((BLangUserDefinedType) langType).typeName.value : langType.toString());
if (typeName.equals(parentDocumentable.name)) {
parentDocumentable.children.add(createDocForNode(function));
}
}
}
} else {
// If there's no receiver type i.e. no struct binding to the function
documentables.add(createDocForNode(function));
}
}
}
}
// Check for connectors in the package
for (BLangConnector connector : balPackage.getConnectors()) {
if (connector.getFlags().contains(Flag.PUBLIC)) {
documentables.add(createDocForNode(connector));
}
}
// Check for connectors in the package
for (EnumNode enumNode : balPackage.getEnums()) {
if (enumNode.getFlags().contains(Flag.PUBLIC)) {
documentables.add(createDocForNode(enumNode));
}
}
// Check for annotations
for (BLangAnnotation annotation : balPackage.getAnnotations()) {
if (annotation.getFlags().contains(Flag.PUBLIC)) {
documentables.add(createDocForNode(annotation));
}
}
// Check for global variables
for (BLangVariable var : balPackage.getGlobalVariables()) {
if (var.getFlags().contains(Flag.PUBLIC)) {
documentables.add(createDocForNode(var));
}
}
// Create the links to select which page or package is active
List<Link> links = new ArrayList<>();
PackageName packageNameHeading = null;
for (Link pkgLink : packages) {
if (pkgLink.caption.value.equals(currentPackageName)) {
packageNameHeading = (PackageName) pkgLink.caption;
links.add(new Link(pkgLink.caption, pkgLink.href, true));
} else {
links.add(new Link(pkgLink.caption, pkgLink.href, false));
}
}
return new Page(packageNameHeading, documentables, links);
}
Aggregations