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();
}
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);
});
}
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);
}
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);
}
}
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();
}
Aggregations