use of org.wso2.carbon.apimgt.core.models.Function in project ballerina by ballerina-lang.
the class StatementContextResolver method resolveItems.
@Override
@SuppressWarnings("unchecked")
public ArrayList<CompletionItem> resolveItems(TextDocumentServiceContext completionContext) {
ArrayList<CompletionItem> completionItems = new ArrayList<>();
// action invocation or worker invocation
if (isInvocationOrFieldAccess(completionContext)) {
ArrayList<SymbolInfo> actionAndFunctions = new ArrayList<>();
PackageActionFunctionAndTypesFilter actionFunctionTypeFilter = new PackageActionFunctionAndTypesFilter();
actionAndFunctions.addAll(actionFunctionTypeFilter.filterItems(completionContext));
this.populateCompletionItemList(actionAndFunctions, completionItems);
} else {
CompletionItem xmlns = new CompletionItem();
xmlns.setLabel(ItemResolverConstants.XMLNS);
xmlns.setInsertText(Snippet.NAMESPACE_DECLARATION.toString());
xmlns.setInsertTextFormat(InsertTextFormat.Snippet);
xmlns.setDetail(ItemResolverConstants.SNIPPET_TYPE);
completionItems.add(xmlns);
// Add the var keyword
CompletionItem varKeyword = new CompletionItem();
varKeyword.setInsertText("var ");
varKeyword.setLabel("var");
varKeyword.setDetail(ItemResolverConstants.KEYWORD_TYPE);
completionItems.add(varKeyword);
StatementTemplateFilter statementTemplateFilter = new StatementTemplateFilter();
// Add the statement templates
completionItems.addAll(statementTemplateFilter.filterItems(completionContext));
// We need to remove the functions having a receiver symbol and the bTypes of the following
// ballerina.coordinator, ballerina.runtime, and anonStructs
ArrayList<String> invalidPkgs = new ArrayList<>(Arrays.asList("ballerina.runtime", "ballerina.transactions.coordinator"));
completionContext.get(CompletionKeys.VISIBLE_SYMBOLS_KEY).removeIf(symbolInfo -> {
BSymbol bSymbol = symbolInfo.getScopeEntry().symbol;
String symbolName = bSymbol.getName().getValue();
return (bSymbol instanceof BInvokableSymbol && ((BInvokableSymbol) bSymbol).receiverSymbol != null) || (bSymbol instanceof BPackageSymbol && invalidPkgs.contains(symbolName)) || (symbolName.startsWith("$anonStruct"));
});
populateCompletionItemList(completionContext.get(CompletionKeys.VISIBLE_SYMBOLS_KEY), completionItems);
// Now we need to sort the completion items and populate the completion items specific to the scope owner
// as an example, resource, action, function scopes are different from the if-else, while, and etc
Class itemSorter = completionContext.get(CompletionKeys.BLOCK_OWNER_KEY).getClass();
ItemSorters.getSorterByClass(itemSorter).sortItems(completionContext, completionItems);
}
return completionItems;
}
use of org.wso2.carbon.apimgt.core.models.Function in project product-iots by wso2.
the class IOTHomePage method logout.
/**
* Performs the logout function.
* @return : IOT login page.
*/
public LoginPage logout() throws IOException {
driver.findElement(By.xpath(uiElementMapper.getElement("iot.user.registered.name"))).click();
WebElement logout = driver.findElement(By.xpath(uiElementMapper.getElement("iot.user.logout.link.xpath")));
logout.click();
return new LoginPage(driver);
}
use of org.wso2.carbon.apimgt.core.models.Function in project product-iots by wso2.
the class NewUserRegistrationTest method logoutTest.
@Test(description = "Test user logout function", dependsOnMethods = { "userRegisterTest" })
public void logoutTest() throws IOException {
IOTHomePage homePage = new IOTHomePage(driver);
homePage.logout();
Assert.assertEquals(driver.getTitle(), Constants.User.Login.PAGE_TITLE);
}
use of org.wso2.carbon.apimgt.core.models.Function in project ballerina by ballerina-lang.
the class WorkspacePackageRepositoryTest method testCompilePackageWithDirtyContent.
// @Test
public void testCompilePackageWithDirtyContent() {
Compiler compiler = Compiler.getInstance(prepareCompilerContext());
BLangPackage packageNode = compiler.compile(pkg);
Assert.assertEquals(packageNode.getFunctions().size(), 1, "Package should contain one function which is in persisted file.");
Assert.assertEquals(packageNode.getFunctions().get(0).getName().getValue(), "sayHello", "Name of the function should be equal to sayHello.");
// open the file in document manager and set content without the function
final Path filePath = Paths.get(sourceRoot, "org.pkg1", "file1.bal");
documentManager.openFile(filePath, "package org.pkg1;");
compiler = Compiler.getInstance(prepareCompilerContext());
compiler.compile(pkg);
Assert.assertEquals(packageNode.getFunctions().size(), 0, "Package should now contain no functions as we removed it in file1.bal dirty content.");
// now update the file and add two public functions
documentManager.updateFile(filePath, "package org.pkg1; public function f1(){} " + "public function f2(){}");
compiler = Compiler.getInstance(prepareCompilerContext());
compiler.compile(pkg);
Assert.assertEquals(packageNode.getFunctions().size(), 2, "Package should now contain two functions.");
Assert.assertEquals(packageNode.getFunctions().get(0).getName().getValue(), "f1", "Name of the first function should be equal to f1.");
Assert.assertEquals(packageNode.getFunctions().get(1).getName().getValue(), "f2", "Name of the first function should be equal to f2.");
// now close file without saving new content to disk
documentManager.closeFile(filePath);
compiler = Compiler.getInstance(prepareCompilerContext());
compiler.compile(pkg);
Assert.assertEquals(packageNode.getFunctions().size(), 1, "Package should now contain a single function which is in the file on disk.");
Assert.assertEquals(packageNode.getFunctions().get(0).getName().getValue(), "sayHello", "Name of the function should be equal to sayHello.");
}
use of org.wso2.carbon.apimgt.core.models.Function in project ballerina by ballerina-lang.
the class Generator method createDocForNode.
/**
* Create documentation for functions.
* @param functionNode ballerina function node.
* @return documentation for functions.
*/
public static FunctionDoc createDocForNode(BLangFunction functionNode) {
String functionName = functionNode.getName().value;
List<Variable> parameters = new ArrayList<>();
List<Variable> returnParams = new ArrayList<>();
// Iterate through the parameters
if (functionNode.getParameters().size() > 0) {
for (BLangVariable param : functionNode.getParameters()) {
String dataType = type(param);
String desc = paramAnnotation(functionNode, param);
Variable variable = new Variable(param.getName().value, dataType, desc);
parameters.add(variable);
}
}
// Iterate through the return types
if (functionNode.getReturnParameters().size() > 0) {
for (int i = 0; i < functionNode.getReturnParameters().size(); i++) {
BLangVariable returnParam = functionNode.getReturnParameters().get(i);
String dataType = type(returnParam);
String desc = returnParamAnnotation(functionNode, i);
Variable variable = new Variable(returnParam.getName().value, dataType, desc);
returnParams.add(variable);
}
}
return new FunctionDoc(functionName, description(functionNode), new ArrayList<>(), parameters, returnParams);
}
Aggregations