Search in sources :

Example 66 with Function

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;
}
Also used : BSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BSymbol) ArrayList(java.util.ArrayList) StatementTemplateFilter(org.ballerinalang.langserver.completions.util.filters.StatementTemplateFilter) BInvokableSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BInvokableSymbol) SymbolInfo(org.ballerinalang.langserver.completions.SymbolInfo) BPackageSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BPackageSymbol) PackageActionFunctionAndTypesFilter(org.ballerinalang.langserver.completions.util.filters.PackageActionFunctionAndTypesFilter) CompletionItem(org.eclipse.lsp4j.CompletionItem)

Example 67 with Function

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);
}
Also used : WebElement(org.openqa.selenium.WebElement) LoginPage(org.wso2.iot.integration.ui.pages.login.LoginPage)

Example 68 with Function

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);
}
Also used : IOTHomePage(org.wso2.iot.integration.ui.pages.home.IOTHomePage) Test(org.testng.annotations.Test)

Example 69 with Function

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.");
}
Also used : Path(java.nio.file.Path) Compiler(org.wso2.ballerinalang.compiler.Compiler) BLangPackage(org.wso2.ballerinalang.compiler.tree.BLangPackage)

Example 70 with Function

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);
}
Also used : BLangVariable(org.wso2.ballerinalang.compiler.tree.BLangVariable) Variable(org.ballerinalang.docgen.model.Variable) FunctionDoc(org.ballerinalang.docgen.model.FunctionDoc) ArrayList(java.util.ArrayList) BLangVariable(org.wso2.ballerinalang.compiler.tree.BLangVariable)

Aggregations

Test (org.testng.annotations.Test)94 HTTPCarbonMessage (org.wso2.transport.http.netty.message.HTTPCarbonMessage)49 HTTPTestRequest (org.ballerinalang.test.services.testutils.HTTPTestRequest)44 HttpMessageDataStreamer (org.wso2.transport.http.netty.message.HttpMessageDataStreamer)39 ArrayList (java.util.ArrayList)37 BLangFunction (org.wso2.ballerinalang.compiler.tree.BLangFunction)35 BString (org.ballerinalang.model.values.BString)30 BLangPackage (org.wso2.ballerinalang.compiler.tree.BLangPackage)29 BLangEndpoint (org.wso2.ballerinalang.compiler.tree.BLangEndpoint)26 BLangVariable (org.wso2.ballerinalang.compiler.tree.BLangVariable)25 BInvokableSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BInvokableSymbol)20 BSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BSymbol)20 BJSON (org.ballerinalang.model.values.BJSON)19 BLangExpression (org.wso2.ballerinalang.compiler.tree.expressions.BLangExpression)19 List (java.util.List)18 BType (org.wso2.ballerinalang.compiler.semantics.model.types.BType)18 BLangStruct (org.wso2.ballerinalang.compiler.tree.BLangStruct)16 BStructSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BStructSymbol)15 BPackageSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BPackageSymbol)14 BLangSimpleVarRef (org.wso2.ballerinalang.compiler.tree.expressions.BLangSimpleVarRef)14