Search in sources :

Example 51 with Variable

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;
}
Also used : DiagnosticPos(org.wso2.ballerinalang.compiler.util.diagnotic.DiagnosticPos) BLangBlockStmt(org.wso2.ballerinalang.compiler.tree.statements.BLangBlockStmt) BLangAssignment(org.wso2.ballerinalang.compiler.tree.statements.BLangAssignment) BLangVariableDef(org.wso2.ballerinalang.compiler.tree.statements.BLangVariableDef) BLangExpression(org.wso2.ballerinalang.compiler.tree.expressions.BLangExpression) BLangVariable(org.wso2.ballerinalang.compiler.tree.BLangVariable)

Example 52 with Variable

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;
}
Also used : BType(org.wso2.ballerinalang.compiler.semantics.model.types.BType) ArrayList(java.util.ArrayList) BTupleType(org.wso2.ballerinalang.compiler.semantics.model.types.BTupleType) BLangVariable(org.wso2.ballerinalang.compiler.tree.BLangVariable)

Example 53 with Variable

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));
}
Also used : VariableNode(org.ballerinalang.model.tree.VariableNode) BLangStatement(org.wso2.ballerinalang.compiler.tree.statements.BLangStatement) StatementNode(org.ballerinalang.model.tree.statements.StatementNode) VariableSymbol(org.ballerinalang.model.symbols.VariableSymbol) BLangVariable(org.wso2.ballerinalang.compiler.tree.BLangVariable)

Example 54 with Variable

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 "";
}
Also used : BSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BSymbol) BVarSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BVarSymbol) SymbolInfo(org.ballerinalang.langserver.completions.SymbolInfo)

Example 55 with Variable

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;
}
Also used : RestVariable(org.wso2.carbon.bpmn.rest.engine.variable.RestVariable) ActivitiIllegalArgumentException(org.activiti.engine.ActivitiIllegalArgumentException)

Aggregations

RestVariable (org.wso2.carbon.bpmn.rest.engine.variable.RestVariable)37 ArrayList (java.util.ArrayList)31 RestResponseFactory (org.wso2.carbon.bpmn.rest.common.RestResponseFactory)31 BLangVariable (org.wso2.ballerinalang.compiler.tree.BLangVariable)30 Test (org.testng.annotations.Test)28 HTTPTestRequest (org.ballerinalang.test.services.testutils.HTTPTestRequest)26 HTTPCarbonMessage (org.wso2.transport.http.netty.message.HTTPCarbonMessage)26 HttpMessageDataStreamer (org.wso2.transport.http.netty.message.HttpMessageDataStreamer)26 ActivitiIllegalArgumentException (org.activiti.engine.ActivitiIllegalArgumentException)23 BJSON (org.ballerinalang.model.values.BJSON)22 BLangExpression (org.wso2.ballerinalang.compiler.tree.expressions.BLangExpression)18 IOException (java.io.IOException)17 BVarSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BVarSymbol)17 BType (org.wso2.ballerinalang.compiler.semantics.model.types.BType)17 Variable (org.wso2.siddhi.query.api.expression.Variable)17 ActivitiObjectNotFoundException (org.activiti.engine.ActivitiObjectNotFoundException)16 BLangSimpleVarRef (org.wso2.ballerinalang.compiler.tree.expressions.BLangSimpleVarRef)15 DataResponse (org.wso2.carbon.bpmn.rest.model.common.DataResponse)15 Response (javax.ws.rs.core.Response)14 VariableExpressionExecutor (org.wso2.siddhi.core.executor.VariableExpressionExecutor)13