use of org.wso2.ballerinalang.compiler.tree.BLangPackage in project ballerina by ballerina-lang.
the class BallerinaDocGenerator method generatePackageDocsFromBallerina.
/**
* Generates {@link BLangPackage} objects for each Ballerina package from the given ballerina files.
*
* @param sourceRoot points to the folder relative to which package path is given
* @param packagePath a {@link Path} object pointing either to a ballerina file or a folder with ballerina files.
* @param packageFilter comma separated list of package names/patterns to be filtered from the documentation.
* @param isNative whether the given packages are native or not.
* @return a map of {@link BLangPackage} objects. Key - Ballerina package name Value - {@link BLangPackage}
*/
protected static Map<String, BLangPackage> generatePackageDocsFromBallerina(String sourceRoot, Path packagePath, String packageFilter, boolean isNative) throws IOException {
final List<Path> packagePaths = new ArrayList<>();
if (Files.isDirectory(packagePath)) {
BallerinaSubPackageVisitor subPackageVisitor = new BallerinaSubPackageVisitor(packagePath, packagePaths);
Files.walkFileTree(packagePath, subPackageVisitor);
} else {
packagePaths.add(packagePath);
}
BallerinaDocDataHolder dataHolder = BallerinaDocDataHolder.getInstance();
if (!isNative) {
// This is necessary to be true in order to Ballerina to work properly
System.setProperty("skipNatives", "true");
}
BLangPackage bLangPackage;
for (Path path : packagePaths) {
CompilerContext context = new CompilerContext();
CompilerOptions options = CompilerOptions.getInstance(context);
options.put(CompilerOptionName.PROJECT_DIR, sourceRoot);
options.put(CompilerOptionName.COMPILER_PHASE, CompilerPhase.DESUGAR.toString());
options.put(CompilerOptionName.PRESERVE_WHITESPACE, "false");
Compiler compiler = Compiler.getInstance(context);
// TODO: Remove this and the related constants once these are properly handled in the core
if (BAL_BUILTIN.equals(path) || BAL_BUILTIN_CORE.equals(path)) {
bLangPackage = loadBuiltInPackage(context);
} else {
// compile the given file
bLangPackage = compiler.compile(getPackageNameFromPath(path));
}
if (bLangPackage == null) {
out.println(String.format("docerina: invalid Ballerina package: %s", packagePath));
} else {
String packageName = bLangPackage.symbol.pkgID.name.value;
if (isFilteredPackage(packageName, packageFilter)) {
if (BallerinaDocUtils.isDebugEnabled()) {
out.println("Package " + packageName + " excluded");
}
continue;
}
dataHolder.getPackageMap().put(packageName, bLangPackage);
}
}
return dataHolder.getPackageMap();
}
use of org.wso2.ballerinalang.compiler.tree.BLangPackage in project ballerina by ballerina-lang.
the class BallerinaDocGenerator method loadBuiltInPackage.
private static BLangPackage loadBuiltInPackage(CompilerContext context) {
SymbolTable symbolTable = SymbolTable.getInstance(context);
// Load built-in packages.
BLangPackage builtInPkg = getBuiltInPackage(context);
symbolTable.builtInPackageSymbol = builtInPkg.symbol;
return builtInPkg;
}
use of org.wso2.ballerinalang.compiler.tree.BLangPackage in project ballerina by ballerina-lang.
the class HtmlDocTest method testFunctions.
@Test(description = "Functions in a package should be shown in the constructs")
public void testFunctions() throws Exception {
BLangPackage bLangPackage = createPackage("package x.y; public function hello(string name) returns (string){}");
Page page = generatePage(bLangPackage);
Assert.assertEquals(page.constructs.size(), 1);
Assert.assertEquals(page.constructs.get(0).name, "hello");
Assert.assertTrue(page.constructs.get(0) instanceof FunctionDoc, "Invalid documentable type");
FunctionDoc functionDoc = (FunctionDoc) page.constructs.get(0);
Assert.assertEquals(functionDoc.parameters.get(0).toString(), "string name", "Invalid parameter string value");
Assert.assertEquals(functionDoc.returnParams.get(0).toString(), "string", "Invalid return type");
}
use of org.wso2.ballerinalang.compiler.tree.BLangPackage in project ballerina by ballerina-lang.
the class HtmlDocTest method testPrivateConstructsInPackage.
@Test(description = "Private constructs should not appear at all.")
public void testPrivateConstructsInPackage() {
BLangPackage bLangPackage = createPackage("package x.y; " + "function hello(){}" + "enum Direction { IN,OUT}" + "enum Money { USD,LKR}" + "annotation ParameterInfo;" + "annotation ReturnInfo;" + "int total = 98;" + "string content = \"Name\";" + "struct Message {}" + "struct Response {}");
Page page = generatePage(bLangPackage);
Assert.assertEquals(page.constructs.size(), 0);
}
use of org.wso2.ballerinalang.compiler.tree.BLangPackage 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