Search in sources :

Example 1 with PackageName

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

the class HtmlDocTest method testMultiPackage.

@Test(description = "Multiple packages should be shown even when one page is generated")
public void testMultiPackage() throws Exception {
    List<Link> packages = new ArrayList<>();
    packages.add(new Link(new PackageName("a.b.c", ""), "", false));
    packages.add(new Link(new PackageName("x.y", ""), "", false));
    packages.add(new Link(new PackageName("x.y.z", ""), "", false));
    BLangPackage bLangPackage = createPackage("package x.y;");
    Page page = Generator.generatePage(bLangPackage, packages);
    Assert.assertEquals(page.links.size(), 3);
    Assert.assertFalse(page.links.get(0).active);
    Assert.assertTrue(page.links.get(1).active);
}
Also used : BLangPackage(org.wso2.ballerinalang.compiler.tree.BLangPackage) PackageName(org.ballerinalang.docgen.model.PackageName) ArrayList(java.util.ArrayList) Page(org.ballerinalang.docgen.model.Page) Link(org.ballerinalang.docgen.model.Link) Test(org.testng.annotations.Test)

Example 2 with PackageName

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

the class HtmlDocTest method generatePage.

/**
 * Generate the api page using the package
 * @param balPackage bal package
 * @return page generated
 */
private Page generatePage(BLangPackage balPackage) {
    List<Link> packages = new ArrayList<>();
    packages.add(new Link(new PackageName((balPackage.symbol).pkgID.name.value, ""), "", false));
    return Generator.generatePage(balPackage, packages);
}
Also used : PackageName(org.ballerinalang.docgen.model.PackageName) ArrayList(java.util.ArrayList) Link(org.ballerinalang.docgen.model.Link)

Example 3 with PackageName

use of org.ballerinalang.docgen.model.PackageName 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);
}
Also used : BLangPackage(org.wso2.ballerinalang.compiler.tree.BLangPackage) PackageName(org.ballerinalang.docgen.model.PackageName) ArrayList(java.util.ArrayList) Page(org.ballerinalang.docgen.model.Page) Link(org.ballerinalang.docgen.model.Link) StaticCaption(org.ballerinalang.docgen.model.StaticCaption) Test(org.testng.annotations.Test)

Example 4 with PackageName

use of org.ballerinalang.docgen.model.PackageName 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);
}
Also used : BLangFunction(org.wso2.ballerinalang.compiler.tree.BLangFunction) PackageName(org.ballerinalang.docgen.model.PackageName) ArrayList(java.util.ArrayList) EnumNode(org.ballerinalang.model.tree.EnumNode) BLangStruct(org.wso2.ballerinalang.compiler.tree.BLangStruct) Page(org.ballerinalang.docgen.model.Page) BLangVariable(org.wso2.ballerinalang.compiler.tree.BLangVariable) Documentable(org.ballerinalang.docgen.model.Documentable) BLangAnnotation(org.wso2.ballerinalang.compiler.tree.BLangAnnotation) TypeNode(org.ballerinalang.model.tree.types.TypeNode) BLangUserDefinedType(org.wso2.ballerinalang.compiler.tree.types.BLangUserDefinedType) BLangConnector(org.wso2.ballerinalang.compiler.tree.BLangConnector) Link(org.ballerinalang.docgen.model.Link)

Aggregations

ArrayList (java.util.ArrayList)4 Link (org.ballerinalang.docgen.model.Link)4 PackageName (org.ballerinalang.docgen.model.PackageName)4 Page (org.ballerinalang.docgen.model.Page)3 Test (org.testng.annotations.Test)2 BLangPackage (org.wso2.ballerinalang.compiler.tree.BLangPackage)2 Documentable (org.ballerinalang.docgen.model.Documentable)1 StaticCaption (org.ballerinalang.docgen.model.StaticCaption)1 EnumNode (org.ballerinalang.model.tree.EnumNode)1 TypeNode (org.ballerinalang.model.tree.types.TypeNode)1 BLangAnnotation (org.wso2.ballerinalang.compiler.tree.BLangAnnotation)1 BLangConnector (org.wso2.ballerinalang.compiler.tree.BLangConnector)1 BLangFunction (org.wso2.ballerinalang.compiler.tree.BLangFunction)1 BLangStruct (org.wso2.ballerinalang.compiler.tree.BLangStruct)1 BLangVariable (org.wso2.ballerinalang.compiler.tree.BLangVariable)1 BLangUserDefinedType (org.wso2.ballerinalang.compiler.tree.types.BLangUserDefinedType)1