use of org.wso2.ballerinalang.compiler.tree.BLangVariable in project ballerina by ballerina-lang.
the class BLangPackageBuilder method addRestParam.
public void addRestParam(DiagnosticPos pos, Set<Whitespace> ws, String identifier, int annotCount) {
BLangVariable restParam = (BLangVariable) this.generateBasicVarNode(pos, ws, identifier, false);
attachAnnotations(restParam, annotCount);
restParam.pos = pos;
BLangArrayType typeNode = (BLangArrayType) TreeBuilder.createArrayTypeNode();
typeNode.elemtype = restParam.typeNode;
typeNode.dimensions = 1;
restParam.typeNode = typeNode;
this.restParamStack.push(restParam);
}
use of org.wso2.ballerinalang.compiler.tree.BLangVariable 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.BLangVariable in project ballerina by ballerina-lang.
the class BLangPackageBuilder method addVarToStruct.
public void addVarToStruct(DiagnosticPos pos, Set<Whitespace> ws, String identifier, boolean exprAvailable, int annotCount, boolean isPrivate) {
Set<Whitespace> wsForSemiColon = removeNthFromLast(ws, 0);
BLangStruct structNode = (BLangStruct) this.structStack.peek();
structNode.addWS(wsForSemiColon);
BLangVariable field = addVar(pos, ws, identifier, exprAvailable, annotCount);
if (!isPrivate) {
field.flagSet.add(Flag.PUBLIC);
}
}
use of org.wso2.ballerinalang.compiler.tree.BLangVariable in project ballerina by ballerina-lang.
the class BLangPackageBuilder method endResourceDef.
public void endResourceDef(DiagnosticPos pos, Set<Whitespace> ws, String resourceName, boolean docExists, boolean isDeprecated, boolean hasParameters) {
BLangResource resourceNode = (BLangResource) invokableNodeStack.pop();
endEndpointDeclarationScope();
resourceNode.pos = pos;
resourceNode.addWS(ws);
resourceNode.setName(createIdentifier(resourceName));
if (docExists) {
attachDocumentations(resourceNode);
}
if (isDeprecated) {
attachDeprecatedNode(resourceNode);
}
if (hasParameters) {
BLangVariable firstParam = (BLangVariable) varListStack.peek().get(0);
if (firstParam.name.value.startsWith("$")) {
// This is an endpoint variable
Set<Whitespace> wsBeforeComma = removeNthFromLast(firstParam.getWS(), 0);
resourceNode.addWS(wsBeforeComma);
}
varListStack.pop().forEach(variableNode -> {
((BLangVariable) variableNode).docTag = DocTag.PARAM;
resourceNode.addParameter(variableNode);
});
}
serviceNodeStack.peek().addResource(resourceNode);
}
use of org.wso2.ballerinalang.compiler.tree.BLangVariable in project ballerina by ballerina-lang.
the class Desugar method generateIfElseStmt.
private BLangStatement generateIfElseStmt(BLangMatch matchStmt, BLangVariable matchExprVar) {
List<BLangMatchStmtPatternClause> patterns = matchStmt.patternClauses;
if (patterns.size() == 1) {
return getMatchPatternBody(patterns.get(0), matchExprVar);
}
BLangIf parentIfNode = generateIfElseStmt(patterns.get(0), matchExprVar);
BLangIf currentIfNode = parentIfNode;
for (int i = 1; i < patterns.size(); i++) {
if (i == patterns.size() - 1) {
// This is the last pattern
currentIfNode.elseStmt = getMatchPatternBody(patterns.get(i), matchExprVar);
} else {
currentIfNode.elseStmt = generateIfElseStmt(patterns.get(i), matchExprVar);
currentIfNode = (BLangIf) currentIfNode.elseStmt;
}
}
//
return parentIfNode;
}
Aggregations