Search in sources :

Example 21 with Operation

use of org.wso2.ballerinalang.compiler.semantics.model.iterable.Operation in project ballerina by ballerina-lang.

the class IterableAnalyzer method calculatedGivenInputArgs.

private List<BType> calculatedGivenInputArgs(Operation operation) {
    final BType inputParam = operation.lambdaType.getParameterTypes().get(0);
    final List<BType> givenArgTypes;
    if (inputParam.tag == TypeTags.TUPLE) {
        final BTupleType bTupleType = (BTupleType) inputParam;
        givenArgTypes = bTupleType.tupleTypes;
    } else {
        givenArgTypes = operation.lambdaType.getParameterTypes();
    }
    operation.arity = givenArgTypes.size();
    return givenArgTypes;
}
Also used : BType(org.wso2.ballerinalang.compiler.semantics.model.types.BType) BTupleType(org.wso2.ballerinalang.compiler.semantics.model.types.BTupleType)

Example 22 with Operation

use of org.wso2.ballerinalang.compiler.semantics.model.iterable.Operation in project ballerina by ballerina-lang.

the class IterableCodeDesugar method desugar.

public void desugar(IterableContext ctx) {
    // Gather required data for code generation.
    processIterableContext(ctx);
    // Generate Iterable Iteration.
    generateIteratorFunction(ctx);
    // Create invocation expression to invoke iterable operation.
    final BLangInvocation iExpr = ASTBuilderUtil.createInvocationExpr(ctx.collectionExpr.pos, ctx.iteratorFuncSymbol, Collections.emptyList(), symResolver);
    iExpr.requiredArgs.add(ctx.collectionExpr);
    if (ctx.getLastOperation().expectedType == symTable.noType || ctx.getLastOperation().expectedType == symTable.voidType) {
        ctx.iteratorCaller = iExpr;
    } else {
        ctx.iteratorCaller = ASTBuilderUtil.wrapToConversionExpr(ctx.getLastOperation().expectedType, iExpr, symTable, types);
    }
}
Also used : BLangInvocation(org.wso2.ballerinalang.compiler.tree.expressions.BLangInvocation)

Example 23 with Operation

use of org.wso2.ballerinalang.compiler.semantics.model.iterable.Operation in project ballerina by ballerina-lang.

the class IterableCodeDesugar method generateSimpleIteratorBlock.

private void generateSimpleIteratorBlock(IterableContext ctx, BLangFunction funcNode) {
    final Operation firstOperation = ctx.getFirstOperation();
    final DiagnosticPos pos = firstOperation.pos;
    // return result;
    if (isReturningIteratorFunction(ctx)) {
        createCounterVarDefStmt(funcNode, ctx);
        createResultVarDefStmt(funcNode, ctx);
    }
    // Create variables required.
    final List<BLangVariable> foreachVariables = createForeachVariables(ctx, ctx.getFirstOperation().argVar, funcNode);
    ctx.iteratorResultVariables = foreachVariables;
    final BLangForeach foreachStmt = ASTBuilderUtil.createForeach(pos, funcNode.body, ASTBuilderUtil.createVariableRef(pos, ctx.collectionVar.symbol), ASTBuilderUtil.createVariableRefList(pos, foreachVariables), ctx.foreachTypes);
    if (isReturningIteratorFunction(ctx)) {
        generateAggregator(foreachStmt.body, ctx);
        generateFinalResult(funcNode.body, ctx);
    }
    final BLangReturn returnStmt = ASTBuilderUtil.createReturnStmt(firstOperation.pos, funcNode.body);
    if (isReturningIteratorFunction(ctx)) {
        returnStmt.addExpression(ASTBuilderUtil.createVariableRef(pos, ctx.resultVar.symbol));
    }
}
Also used : DiagnosticPos(org.wso2.ballerinalang.compiler.util.diagnotic.DiagnosticPos) BLangForeach(org.wso2.ballerinalang.compiler.tree.statements.BLangForeach) BLangReturn(org.wso2.ballerinalang.compiler.tree.statements.BLangReturn) Operation(org.wso2.ballerinalang.compiler.semantics.model.iterable.Operation) BLangVariable(org.wso2.ballerinalang.compiler.tree.BLangVariable)

Example 24 with Operation

use of org.wso2.ballerinalang.compiler.semantics.model.iterable.Operation in project ballerina by ballerina-lang.

the class TopLevelNodeScopeResolver method isCursorBeforeNode.

/**
 * Check whether the cursor is positioned before the given node start.
 *
 * @param nodePosition      Position of the node
 * @param node              Node
 * @param treeVisitor       {@link TreeVisitor} current tree visitor instance
 * @param completionContext Completion operation context
 * @return {@link Boolean}      Whether the cursor is before the node start or not
 */
@Override
public boolean isCursorBeforeNode(DiagnosticPos nodePosition, Node node, TreeVisitor treeVisitor, TextDocumentServiceContext completionContext) {
    int line = completionContext.get(DocumentServiceKeys.POSITION_KEY).getPosition().getLine();
    int col = completionContext.get(DocumentServiceKeys.POSITION_KEY).getPosition().getCharacter();
    DiagnosticPos zeroBasedPos = CommonUtil.toZeroBasedPosition(nodePosition);
    int nodeSLine = zeroBasedPos.sLine;
    int nodeSCol = zeroBasedPos.sCol;
    if (line < nodeSLine || (line == nodeSLine && col <= nodeSCol)) {
        treeVisitor.setTerminateVisitor(true);
        return true;
    }
    return false;
}
Also used : DiagnosticPos(org.wso2.ballerinalang.compiler.util.diagnotic.DiagnosticPos)

Example 25 with Operation

use of org.wso2.ballerinalang.compiler.semantics.model.iterable.Operation in project charon by wso2.

the class PatchOperationUtil method doPatchReplace.

/*
     * This is the main patch replace method.
     * @param operation
     * @param decoder
     * @param oldResource
     * @param copyOfOldResource
     * @param schema
     * @return
     * @throws CharonException
     * @throws NotImplementedException
     * @throws BadRequestException
     * @throws JSONException
     * @throws InternalErrorException
     */
public static AbstractSCIMObject doPatchReplace(PatchOperation operation, JSONDecoder decoder, AbstractSCIMObject oldResource, AbstractSCIMObject copyOfOldResource, SCIMResourceTypeSchema schema) throws CharonException, NotImplementedException, BadRequestException, InternalErrorException {
    if (operation.getPath() != null) {
        String path = operation.getPath();
        // split the path to extract the filter if present.
        String[] parts = path.split("[\\[\\]]");
        if (operation.getPath().contains("[")) {
            try {
                doPatchReplaceOnPathWithFilters(oldResource, schema, decoder, operation, parts);
            } catch (JSONException e) {
                throw new BadRequestException(ResponseCodeConstants.INVALID_SYNTAX);
            }
        } else {
            doPatchReplaceOnPathWithoutFilters(oldResource, schema, decoder, operation, parts);
        }
    } else {
        doPatchReplaceOnResource(oldResource, copyOfOldResource, schema, decoder, operation);
    }
    // validate the updated object
    AbstractSCIMObject validatedResource = ServerSideValidator.validateUpdatedSCIMObject(copyOfOldResource, oldResource, schema);
    return validatedResource;
}
Also used : AbstractSCIMObject(org.wso2.charon3.core.objects.AbstractSCIMObject) JSONException(org.json.JSONException) BadRequestException(org.wso2.charon3.core.exceptions.BadRequestException)

Aggregations

Test (org.testng.annotations.Test)34 HttpResponse (org.wso2.carbon.automation.test.utils.http.client.HttpResponse)29 HashMap (java.util.HashMap)19 ArrayList (java.util.ArrayList)16 BadRequestException (org.wso2.charon3.core.exceptions.BadRequestException)15 HumanTaskRuntimeException (org.wso2.carbon.humantask.core.engine.runtime.api.HumanTaskRuntimeException)12 QueryVariable (org.wso2.carbon.bpmn.rest.engine.variable.QueryVariable)11 List (java.util.List)10 RestResponseFactory (org.wso2.carbon.bpmn.rest.common.RestResponseFactory)10 DiagnosticPos (org.wso2.ballerinalang.compiler.util.diagnotic.DiagnosticPos)9 Map (java.util.Map)8 ActivitiIllegalArgumentException (org.activiti.engine.ActivitiIllegalArgumentException)8 Operation (io.swagger.models.Operation)7 Attribute (org.wso2.charon3.core.attributes.Attribute)7 ComplexAttribute (org.wso2.charon3.core.attributes.ComplexAttribute)7 MultiValuedAttribute (org.wso2.charon3.core.attributes.MultiValuedAttribute)7 SimpleAttribute (org.wso2.charon3.core.attributes.SimpleAttribute)7 Operation (org.wso2.ballerinalang.compiler.semantics.model.iterable.Operation)6 APIManagementException (org.wso2.carbon.apimgt.core.exception.APIManagementException)6 AttributeSchema (org.wso2.charon3.core.schema.AttributeSchema)6