Search in sources :

Example 1 with Symbols

use of org.wso2.ballerinalang.compiler.semantics.model.symbols.Symbols in project siddhi by wso2.

the class DefineTableTestCase method testQuery4.

@Test(expectedExceptions = DuplicateDefinitionException.class)
public void testQuery4() throws InterruptedException {
    log.info("testTableDefinition4 - OUT 0");
    SiddhiManager siddhiManager = new SiddhiManager();
    String tables = "define table TestTable(symbol string, volume float); " + "define table TestTable(symbols string, price int, volume float); ";
    SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(tables);
    siddhiAppRuntime.shutdown();
}
Also used : SiddhiAppRuntime(org.wso2.siddhi.core.SiddhiAppRuntime) SiddhiManager(org.wso2.siddhi.core.SiddhiManager) Test(org.testng.annotations.Test)

Example 2 with Symbols

use of org.wso2.ballerinalang.compiler.semantics.model.symbols.Symbols in project ballerina by ballerina-lang.

the class BallerinaTextDocumentService method completion.

@Override
public CompletableFuture<Either<List<CompletionItem>, CompletionList>> completion(TextDocumentPositionParams position) {
    return CompletableFuture.supplyAsync(() -> {
        List<CompletionItem> completions;
        TextDocumentServiceContext completionContext = new TextDocumentServiceContext();
        completionContext.put(DocumentServiceKeys.POSITION_KEY, position);
        completionContext.put(DocumentServiceKeys.FILE_URI_KEY, position.getTextDocument().getUri());
        completionContext.put(DocumentServiceKeys.LS_PACKAGE_CACHE_KEY, lSPackageCache);
        try {
            BLangPackage bLangPackage = TextDocumentServiceUtil.getBLangPackage(completionContext, documentManager, false, CompletionCustomErrorStrategy.class, false).get(0);
            completionContext.put(DocumentServiceKeys.CURRENT_PACKAGE_NAME_KEY, bLangPackage.symbol.getName().getValue());
            completionContext.put(DocumentServiceKeys.CURRENT_BLANG_PACKAGE_CONTEXT_KEY, bLangPackage);
            // Visit the package to resolve the symbols
            TreeVisitor treeVisitor = new TreeVisitor(completionContext);
            bLangPackage.accept(treeVisitor);
            BLangNode symbolEnvNode = completionContext.get(CompletionKeys.SYMBOL_ENV_NODE_KEY);
            if (symbolEnvNode == null) {
                completions = CompletionItemResolver.getResolverByClass(TopLevelResolver.class).resolveItems(completionContext);
            } else {
                completions = CompletionItemResolver.getResolverByClass(symbolEnvNode.getClass()).resolveItems(completionContext);
            }
        } catch (Exception | AssertionError e) {
            completions = new ArrayList<>();
        }
        return Either.forLeft(completions);
    });
}
Also used : TreeVisitor(org.ballerinalang.langserver.completions.TreeVisitor) SignatureTreeVisitor(org.ballerinalang.langserver.signature.SignatureTreeVisitor) PositionTreeVisitor(org.ballerinalang.langserver.common.position.PositionTreeVisitor) BLangPackage(org.wso2.ballerinalang.compiler.tree.BLangPackage) BLangNode(org.wso2.ballerinalang.compiler.tree.BLangNode) CompletionCustomErrorStrategy(org.ballerinalang.langserver.completions.CompletionCustomErrorStrategy) CompletionItem(org.eclipse.lsp4j.CompletionItem) ArrayList(java.util.ArrayList)

Example 3 with Symbols

use of org.wso2.ballerinalang.compiler.semantics.model.symbols.Symbols in project ballerina by ballerina-lang.

the class SymbolEnter method visit.

// Visitor methods
@Override
public void visit(BLangPackage pkgNode) {
    if (pkgNode.completedPhases.contains(CompilerPhase.DEFINE)) {
        return;
    }
    // Create PackageSymbol.
    BPackageSymbol pSymbol = createPackageSymbol(pkgNode);
    SymbolEnv builtinEnv = this.symTable.pkgEnvMap.get(symTable.builtInPackageSymbol);
    SymbolEnv pkgEnv = SymbolEnv.createPkgEnv(pkgNode, pSymbol.scope, builtinEnv);
    this.symTable.pkgEnvMap.put(pSymbol, pkgEnv);
    createPackageInitFunctions(pkgNode);
    // visit the package node recursively and define all package level symbols.
    // And maintain a list of created package symbols.
    pkgNode.imports.forEach(importNode -> defineNode(importNode, pkgEnv));
    // Define struct nodes.
    pkgNode.enums.forEach(enumNode -> defineNode(enumNode, pkgEnv));
    // Define struct nodes.
    pkgNode.structs.forEach(struct -> defineNode(struct, pkgEnv));
    // Define object nodes
    pkgNode.objects.forEach(object -> defineNode(object, pkgEnv));
    // Define connector nodes.
    pkgNode.connectors.forEach(con -> defineNode(con, pkgEnv));
    // Define connector params and type.
    defineConnectorParams(pkgNode.connectors, pkgEnv);
    // Define transformer nodes.
    pkgNode.transformers.forEach(tansformer -> defineNode(tansformer, pkgEnv));
    // Define service and resource nodes.
    pkgNode.services.forEach(service -> defineNode(service, pkgEnv));
    // Define struct field nodes.
    defineStructFields(pkgNode.structs, pkgEnv);
    // Define object field nodes.
    defineObjectFields(pkgNode.objects, pkgEnv);
    // Define connector action nodes.
    defineConnectorMembers(pkgNode.connectors, pkgEnv);
    // Define object functions
    defineObjectMembers(pkgNode.objects, pkgEnv);
    // Define function nodes.
    pkgNode.functions.forEach(func -> defineNode(func, pkgEnv));
    // Define transformer params
    defineTransformerMembers(pkgNode.transformers, pkgEnv);
    // Define service resource nodes.
    defineServiceMembers(pkgNode.services, pkgEnv);
    // Define annotation nodes.
    pkgNode.annotations.forEach(annot -> defineNode(annot, pkgEnv));
    resolveAnnotationAttributeTypes(pkgNode.annotations, pkgEnv);
    pkgNode.globalVars.forEach(var -> defineNode(var, pkgEnv));
    pkgNode.globalEndpoints.forEach(ep -> defineNode(ep, pkgEnv));
    definePackageInitFunctions(pkgNode, pkgEnv);
    pkgNode.completedPhases.add(CompilerPhase.DEFINE);
}
Also used : BPackageSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BPackageSymbol) SymbolEnv(org.wso2.ballerinalang.compiler.semantics.model.SymbolEnv)

Example 4 with Symbols

use of org.wso2.ballerinalang.compiler.semantics.model.symbols.Symbols in project ballerina by ballerina-lang.

the class TaintAnalyzer method visitAssignment.

private void visitAssignment(BLangExpression varRefExpr, boolean varTaintedStatus, DiagnosticPos pos) {
    // Generate error if a global variable has been assigned with a tainted value.
    if (varTaintedStatus && varRefExpr instanceof BLangVariableReference) {
        BLangVariableReference varRef = (BLangVariableReference) varRefExpr;
        if (varRef.symbol != null && varRef.symbol.owner != null) {
            if (varRef.symbol.owner instanceof BPackageSymbol || SymbolKind.SERVICE.equals(varRef.symbol.owner.kind) || SymbolKind.CONNECTOR.equals(varRef.symbol.owner.kind)) {
                addTaintError(pos, varRef.symbol.name.value, DiagnosticCode.TAINTED_VALUE_PASSED_TO_GLOBAL_VARIABLE);
                return;
            }
        }
    }
    // TODO: Re-evaluating the full data-set (array) when a change occur.
    if (varRefExpr instanceof BLangIndexBasedAccess) {
        nonOverridingAnalysis = true;
        updatedVarRefTaintedState((BLangIndexBasedAccess) varRefExpr, varTaintedStatus);
        nonOverridingAnalysis = false;
    } else if (varRefExpr instanceof BLangFieldBasedAccess) {
        BLangFieldBasedAccess fieldBasedAccessExpr = (BLangFieldBasedAccess) varRefExpr;
        // Propagate tainted status to fields, when field symbols are present (Example: structs).
        if (fieldBasedAccessExpr.symbol != null) {
            setTaintedStatus(fieldBasedAccessExpr, varTaintedStatus);
        }
        nonOverridingAnalysis = true;
        updatedVarRefTaintedState(fieldBasedAccessExpr, varTaintedStatus);
        nonOverridingAnalysis = false;
    } else {
        BLangVariableReference varRef = (BLangVariableReference) varRefExpr;
        setTaintedStatus(varRef, varTaintedStatus);
    }
}
Also used : BLangIndexBasedAccess(org.wso2.ballerinalang.compiler.tree.expressions.BLangIndexBasedAccess) BPackageSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BPackageSymbol) BLangFieldBasedAccess(org.wso2.ballerinalang.compiler.tree.expressions.BLangFieldBasedAccess) BLangVariableReference(org.wso2.ballerinalang.compiler.tree.expressions.BLangVariableReference)

Example 5 with Symbols

use of org.wso2.ballerinalang.compiler.semantics.model.symbols.Symbols in project siddhi by wso2.

the class StdDevAttributeAggregatorTestCase method stdDevAggregatorTest4.

@Test
public void stdDevAggregatorTest4() throws InterruptedException {
    log.info("stdDevAggregator Test #4: Two symbols in the stream with same stdDev");
    SiddhiManager siddhiManager = new SiddhiManager();
    String execPlan = "" + "@app:name('stdDevAggregatorTests') " + "" + "define stream cseEventStream (symbol string, price double);" + "" + "@info(name = 'query1') " + "from cseEventStream#window.lengthBatch(6) " + "select stdDev(price) as deviation " + "group by symbol " + "insert into outputStream;";
    SiddhiAppRuntime execPlanRunTime = siddhiManager.createSiddhiAppRuntime(execPlan);
    execPlanRunTime.addCallback("query1", new QueryCallback() {

        @Override
        public void receive(long timestamp, Event[] inEvents, Event[] removeEvents) {
            EventPrinter.print(timestamp, inEvents, removeEvents);
            AssertJUnit.assertTrue(Math.abs((Double) inEvents[0].getData(0) - 0.40825) < epsilon);
            AssertJUnit.assertTrue(Math.abs((Double) inEvents[1].getData(0) - 0.40825) < epsilon);
        }
    });
    InputHandler inputHandler = execPlanRunTime.getInputHandler("cseEventStream");
    execPlanRunTime.start();
    inputHandler.send(new Object[] { "WSO2", 10000.0 });
    inputHandler.send(new Object[] { "WSO2", 10000.5 });
    inputHandler.send(new Object[] { "WSO2", 10001.0 });
    inputHandler.send(new Object[] { "IBM", 1.0 });
    inputHandler.send(new Object[] { "IBM", 1.5 });
    inputHandler.send(new Object[] { "IBM", 2.0 });
    Thread.sleep(600);
    execPlanRunTime.shutdown();
}
Also used : InputHandler(org.wso2.siddhi.core.stream.input.InputHandler) SiddhiAppRuntime(org.wso2.siddhi.core.SiddhiAppRuntime) Event(org.wso2.siddhi.core.event.Event) SiddhiManager(org.wso2.siddhi.core.SiddhiManager) QueryCallback(org.wso2.siddhi.core.query.output.callback.QueryCallback) Test(org.testng.annotations.Test)

Aggregations

ArrayList (java.util.ArrayList)6 BPackageSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BPackageSymbol)5 BLangNode (org.wso2.ballerinalang.compiler.tree.BLangNode)5 BLangPackage (org.wso2.ballerinalang.compiler.tree.BLangPackage)5 List (java.util.List)4 Map (java.util.Map)4 JsonObject (com.google.gson.JsonObject)3 Paths (java.nio.file.Paths)3 Arrays (java.util.Arrays)3 HashMap (java.util.HashMap)3 Collectors (java.util.stream.Collectors)3 TokenStream (org.antlr.v4.runtime.TokenStream)3 TextDocumentServiceContext (org.ballerinalang.langserver.TextDocumentServiceContext)3 CompletionCustomErrorStrategy (org.ballerinalang.langserver.completions.CompletionCustomErrorStrategy)3 SymbolInfo (org.ballerinalang.langserver.completions.SymbolInfo)3 TreeVisitor (org.ballerinalang.langserver.completions.TreeVisitor)3 BInvokableSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BInvokableSymbol)3 BType (org.wso2.ballerinalang.compiler.semantics.model.types.BType)3 BLangCompilationUnit (org.wso2.ballerinalang.compiler.tree.BLangCompilationUnit)3 BLangInvocation (org.wso2.ballerinalang.compiler.tree.expressions.BLangInvocation)3