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