use of org.wso2.siddhi.query.api.expression.Variable in project ballerina by ballerina-lang.
the class EndpointDesugar method generateEndpointInit.
private BLangBlockStmt generateEndpointInit(BLangEndpoint endpoint, SymbolEnv env, BSymbol encSymbol) {
final String epName = endpoint.name.value;
final DiagnosticPos pos = endpoint.pos;
BLangBlockStmt temp = new BLangBlockStmt();
final BLangVariable epVariable = ASTBuilderUtil.createVariable(pos, epName, endpoint.symbol.type);
epVariable.symbol = (BVarSymbol) symResolver.lookupMemberSymbol(pos, encSymbol.scope, env, names.fromString(epName), SymTag.VARIABLE);
final BLangExpression newExpr;
if (endpoint.configurationExpr != null && endpoint.configurationExpr.getKind() != NodeKind.RECORD_LITERAL_EXPR) {
// Handle Endpoint Assignment.
newExpr = endpoint.configurationExpr;
} else if (endpoint.configurationExpr != null && endpoint.configurationExpr.getKind() == NodeKind.RECORD_LITERAL_EXPR) {
// Handle Endpoint initialization.
newExpr = ASTBuilderUtil.createEmptyRecordLiteral(pos, endpoint.symbol.type);
} else {
newExpr = null;
}
// EPType ep_name = {};
if (env.enclInvokable != null) {
// In callable unit, endpoint is same scope variable.
final BLangVariableDef epNewStmt = ASTBuilderUtil.createVariableDefStmt(pos, temp);
epNewStmt.var = epVariable;
epNewStmt.var.expr = newExpr;
} else {
// This is an init function. ep variable is defined in outside.
if (env.enclService != null) {
// Add to endpoint variable to relevant location
final BLangVariableDef epVarDef = ASTBuilderUtil.createVariableDef(pos);
epVarDef.var = epVariable;
env.enclService.vars.add(epVarDef);
}
final BLangAssignment assignmentStmt = ASTBuilderUtil.createAssignmentStmt(pos, temp);
assignmentStmt.varRefs.add(ASTBuilderUtil.createVariableRef(pos, epVariable.symbol));
assignmentStmt.expr = newExpr;
}
return temp;
}
use of org.wso2.siddhi.query.api.expression.Variable in project ballerina by ballerina-lang.
the class IterableCodeDesugar method createIteratorResultVariables.
private List<BLangVariable> createIteratorResultVariables(IterableContext ctx, BLangVariable lastOperationArg, BLangFunction funcNode) {
List<BLangVariable> resultVariables = new ArrayList<>();
if (lastOperationArg.type.tag != TypeTags.TUPLE) {
resultVariables.add(lastOperationArg);
defineVariable(lastOperationArg, ctx.env.enclPkg.symbol.pkgID, funcNode);
return resultVariables;
}
final List<BType> tupleTypes = ((BTupleType) lastOperationArg.type).tupleTypes;
int index = 0;
for (BType type : tupleTypes) {
String varName = VAR_RESULT_VAL + index++;
final BLangVariable variable = ASTBuilderUtil.createVariable(funcNode.pos, varName, type);
resultVariables.add(variable);
defineVariable(variable, ctx.env.enclPkg.symbol.pkgID, funcNode);
}
return resultVariables;
}
use of org.wso2.siddhi.query.api.expression.Variable in project ballerina by ballerina-lang.
the class SiddhiQueryBuilder method visit.
public void visit(BLangForever foreverStatement) {
siddhiQuery = new StringBuilder();
streamDefinitionQuery = new StringBuilder();
streamIds = new HashSet<>();
inStreamRefs = new ArrayList<>();
outStreamRefs = new ArrayList<>();
inTableRefs = new ArrayList<>();
outTableRefs = new ArrayList<>();
binaryExpr = null;
setExpr = null;
orderByClause = null;
whereClause = null;
windowClause = null;
joinStreamingInputClause = null;
streamingInputClause = null;
selectExprClause = null;
selectExpr = null;
setAssignmentClause = null;
groupByClause = null;
havingClause = null;
patternStreamingClause = null;
streamActionClause = null;
intRangeExpr = null;
List<VariableNode> globalVariables = foreverStatement.getGlobalVariables();
if (globalVariables != null) {
for (VariableNode variable : globalVariables) {
((BLangVariable) variable).accept(this);
}
}
List<VariableSymbol> functionVariables = foreverStatement.getFunctionVariables();
if (functionVariables != null) {
for (VariableSymbol variable : functionVariables) {
getStreamDefintionForFuntionVariable((BVarSymbol) variable);
}
}
List<? extends StatementNode> statementNodes = foreverStatement.gettreamingQueryStatements();
for (StatementNode statementNode : statementNodes) {
((BLangStatement) statementNode).accept(this);
}
foreverStatement.setSiddhiQuery(this.getSiddhiQuery());
foreverStatement.setStreamIdsAsString(String.join(",", streamIds));
}
use of org.wso2.siddhi.query.api.expression.Variable in project ballerina by ballerina-lang.
the class AssignmentStmtContextSorter method getVariableType.
/**
* Get the variable type.
*
* @param ctx Document Service context (Completion context)
* @return {@link String} type of the variable
*/
@Override
String getVariableType(TextDocumentServiceContext ctx) {
String variableName = ctx.get(DocumentServiceKeys.PARSER_RULE_CONTEXT_KEY).getStart().getText();
List<SymbolInfo> visibleSymbols = ctx.get(CompletionKeys.VISIBLE_SYMBOLS_KEY);
SymbolInfo filteredSymbol = visibleSymbols.stream().filter(symbolInfo -> {
BSymbol bSymbol = symbolInfo.getScopeEntry().symbol;
String symbolName = symbolInfo.getSymbolName();
return bSymbol instanceof BVarSymbol && symbolName.equals(variableName);
}).findFirst().orElse(null);
if (filteredSymbol != null) {
return filteredSymbol.getScopeEntry().symbol.type.toString();
}
return "";
}
use of org.wso2.siddhi.query.api.expression.Variable in project carbon-business-process by wso2.
the class RestResponseFactory method getVariableValue.
public Object getVariableValue(QueryVariable restVariable) {
Object value;
if (restVariable.getType() != null) {
// Try locating a converter if the type has been specified
RestVariableConverter converter = null;
for (RestVariableConverter conv : variableConverters) {
if (conv.getRestTypeName().equals(restVariable.getType())) {
converter = conv;
break;
}
}
if (converter == null) {
throw new ActivitiIllegalArgumentException("Variable '" + restVariable.getName() + "' has unsupported type: '" + restVariable.getType() + "'.");
}
RestVariable temp = new RestVariable();
temp.setValue(restVariable.getValue());
temp.setType(restVariable.getType());
temp.setName(restVariable.getName());
value = converter.getVariableValue(temp);
} else {
// Revert to type determined by REST-to-Java mapping when no explicit type has been provided
value = restVariable.getValue();
}
return value;
}
Aggregations