use of org.wso2.ballerinalang.compiler.tree.BLangVariable in project ballerina by ballerina-lang.
the class BLangPackageBuilder method addMatchStmtPattern.
public void addMatchStmtPattern(DiagnosticPos pos, Set<Whitespace> ws, String identifier) {
BLangMatchStmtPatternClause patternClause = (BLangMatchStmtPatternClause) TreeBuilder.createMatchStatementPattern();
patternClause.pos = pos;
Set<Whitespace> varDefWS = removeNthFromStart(ws, 0);
patternClause.addWS(ws);
// Create a variable node
identifier = identifier == null ? Names.IGNORE.value : identifier;
BLangVariable var = (BLangVariable) TreeBuilder.createVariableNode();
var.pos = pos;
var.setName(this.createIdentifier(identifier));
var.setTypeNode(this.typeNodeStack.pop());
var.addWS(varDefWS);
patternClause.variable = var;
patternClause.body = (BLangBlockStmt) blockNodeStack.pop();
patternClause.body.pos = pos;
this.matchStmtStack.peekFirst().patternClauses.add(patternClause);
}
use of org.wso2.ballerinalang.compiler.tree.BLangVariable 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.BLangVariable in project ballerina by ballerina-lang.
the class BLangPackageBuilder method addObjectParameter.
BLangVariable addObjectParameter(DiagnosticPos pos, Set<Whitespace> ws, boolean isField, String identifier, boolean exprAvailable, int annotCount) {
BLangVariable var = (BLangVariable) this.generateObjectVarNode(pos, ws, isField, identifier, exprAvailable);
attachAnnotations(var, annotCount);
var.pos = pos;
if (this.varListStack.empty()) {
this.varStack.push(var);
} else {
this.varListStack.peek().add(var);
}
return var;
}
use of org.wso2.ballerinalang.compiler.tree.BLangVariable 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.BLangVariable in project ballerina by ballerina-lang.
the class BLangPackageBuilder method endTransformerDef.
public void endTransformerDef(DiagnosticPos pos, Set<Whitespace> ws, boolean publicFunc, String name, boolean paramsAvailable) {
BLangTransformer transformer = (BLangTransformer) this.invokableNodeStack.pop();
transformer.pos = pos;
transformer.addWS(ws);
transformer.setName(this.createIdentifier(name));
if (paramsAvailable) {
this.varListStack.pop().forEach(variableNode -> {
((BLangVariable) variableNode).docTag = DocTag.PARAM;
transformer.addParameter(variableNode);
});
}
// get the source and the target params
List<VariableNode> mappingParams = this.varListStack.pop();
// set the first mapping-param as the source for transformer
VariableNode source = mappingParams.remove(0);
((BLangVariable) source).docTag = DocTag.RECEIVER;
transformer.setSource(source);
mappingParams.forEach(variableNode -> {
((BLangVariable) variableNode).docTag = DocTag.RECEIVER;
transformer.addReturnParameter(variableNode);
});
if (publicFunc) {
transformer.flagSet.add(Flag.PUBLIC);
}
this.compUnit.addTopLevelNode(transformer);
}
Aggregations