use of org.wso2.ballerinalang.compiler.tree.statements.BLangVariableDef in project ballerina by ballerina-lang.
the class IterableCodeDesugar method defineRequiredVariables.
private void defineRequiredVariables(IterableContext ctx, LinkedList<Operation> streamOperations, List<BLangVariable> foreachVariables, BLangFunction funcNode) {
Set<BLangVariable> notDefinedVars = new HashSet<>();
streamOperations.forEach(operation -> {
notDefinedVars.add(operation.argVar);
if (operation.kind != IterableKind.FILTER && operation.retVar != null) {
notDefinedVars.add(operation.retVar);
}
});
notDefinedVars.addAll(ctx.iteratorResultVariables);
notDefinedVars.removeAll(foreachVariables);
notDefinedVars.forEach(var -> defineVariable(var, ctx.env.enclPkg.symbol.pkgID, funcNode));
notDefinedVars.forEach(var -> {
BLangVariableDef variableDefStmt = ASTBuilderUtil.createVariableDefStmt(funcNode.pos, funcNode.body);
variableDefStmt.var = var;
});
}
use of org.wso2.ballerinalang.compiler.tree.statements.BLangVariableDef in project ballerina by ballerina-lang.
the class BLangPackageBuilder method addDefaultableParam.
public void addDefaultableParam(DiagnosticPos pos, Set<Whitespace> ws) {
BLangVariableDef defaultableParam = (BLangVariableDef) TreeBuilder.createVariableDefinitionNode();
defaultableParam.pos = pos;
defaultableParam.addWS(ws);
List<VariableNode> params = this.varListStack.peek();
BLangVariable var = (BLangVariable) params.remove(params.size() - 1);
var.expr = (BLangExpression) this.exprNodeStack.pop();
defaultableParam.var = var;
this.defaultableParamsList.add(defaultableParam);
}
use of org.wso2.ballerinalang.compiler.tree.statements.BLangVariableDef in project ballerina by ballerina-lang.
the class BLangPackageBuilder method endObjectInitParamList.
void endObjectInitParamList(Set<Whitespace> ws, boolean paramsAvail, boolean restParamAvail) {
InvokableNode invNode = this.invokableNodeStack.peek();
invNode.addWS(ws);
if (paramsAvail) {
this.varListStack.pop().forEach(variableNode -> {
((BLangVariable) variableNode).docTag = DocTag.PARAM;
invNode.addParameter(variableNode);
});
this.defaultableParamsList.forEach(variableDef -> {
BLangVariableDef varDef = (BLangVariableDef) variableDef;
varDef.var.docTag = DocTag.PARAM;
invNode.addDefaultableParameter(varDef);
});
this.defaultableParamsList = new ArrayList<>();
if (restParamAvail) {
invNode.setRestParameter(this.restParamStack.pop());
}
}
}
use of org.wso2.ballerinalang.compiler.tree.statements.BLangVariableDef in project ballerina by ballerina-lang.
the class BLangPackageBuilder method endCallableUnitSignature.
public void endCallableUnitSignature(Set<Whitespace> ws, String identifier, boolean paramsAvail, boolean retParamsAvail, boolean restParamAvail) {
InvokableNode invNode = this.invokableNodeStack.peek();
invNode.setName(this.createIdentifier(identifier));
invNode.addWS(ws);
if (retParamsAvail) {
BLangVariable variableNode = (BLangVariable) this.varStack.pop();
variableNode.docTag = DocTag.RETURN;
invNode.addReturnParameter(variableNode);
}
if (paramsAvail) {
this.varListStack.pop().forEach(variableNode -> {
((BLangVariable) variableNode).docTag = DocTag.PARAM;
invNode.addParameter(variableNode);
});
this.defaultableParamsList.forEach(variableDef -> {
BLangVariableDef varDef = (BLangVariableDef) variableDef;
varDef.var.docTag = DocTag.PARAM;
invNode.addDefaultableParameter(varDef);
});
this.defaultableParamsList = new ArrayList<>();
if (restParamAvail) {
invNode.setRestParameter(this.restParamStack.pop());
}
}
}
use of org.wso2.ballerinalang.compiler.tree.statements.BLangVariableDef in project ballerina by ballerina-lang.
the class ConnectorScopeResolver method isWithinScopeAfterLastChildNode.
/**
* Check whether the given node is within the scope and located after the last child node.
* @param node Current Node to evaluate
* @param treeVisitor Operation Tree Visitor
* @param curLine line of the cursor
* @param curCol column of the cursor
* @return {@link Boolean} whether the last child node or not
*/
protected boolean isWithinScopeAfterLastChildNode(Node node, TreeVisitor treeVisitor, int curLine, int curCol) {
BLangConnector bLangConnector = (BLangConnector) treeVisitor.getBlockOwnerStack().peek();
List<BLangAction> actions = bLangConnector.actions;
List<BLangVariableDef> variableDefs = bLangConnector.varDefs;
int connectorEndLine = bLangConnector.pos.getEndLine();
int connectorEndCol = bLangConnector.pos.getEndColumn();
int nodeEndLine = node.getPosition().getEndLine();
int nodeEndCol = node.getPosition().getEndColumn();
boolean isLastChildNode;
if (actions.isEmpty()) {
isLastChildNode = variableDefs.indexOf(node) == (variableDefs.size() - 1);
} else {
isLastChildNode = actions.indexOf(node) == (actions.size() - 1);
}
boolean isWithinScope = (isLastChildNode && (curLine < connectorEndLine || (curLine == connectorEndLine && curCol < connectorEndCol)) && (nodeEndLine < curLine || (nodeEndLine == curLine && nodeEndCol < curCol)));
if (isWithinScope) {
treeVisitor.setPreviousNode((BLangNode) node);
}
return isWithinScope;
}
Aggregations