Search in sources :

Example 11 with Whitespace

use of org.ballerinalang.model.Whitespace in project ballerina by ballerina-lang.

the class BLangPackageBuilder method addConstraintTypeWithTypeName.

public void addConstraintTypeWithTypeName(DiagnosticPos pos, Set<Whitespace> ws, String typeName) {
    Set<Whitespace> refTypeWS = removeNthFromLast(ws, 2);
    BLangBuiltInRefTypeNode refType = (BLangBuiltInRefTypeNode) TreeBuilder.createBuiltInReferenceTypeNode();
    refType.typeKind = TreeUtils.stringToTypeKind(typeName);
    refType.pos = pos;
    refType.addWS(refTypeWS);
    BLangConstrainedType constrainedType = (BLangConstrainedType) TreeBuilder.createConstrainedTypeNode();
    constrainedType.type = refType;
    constrainedType.constraint = (BLangType) this.typeNodeStack.pop();
    constrainedType.pos = pos;
    constrainedType.addWS(ws);
    addType(constrainedType);
}
Also used : BLangConstrainedType(org.wso2.ballerinalang.compiler.tree.types.BLangConstrainedType) BLangBuiltInRefTypeNode(org.wso2.ballerinalang.compiler.tree.types.BLangBuiltInRefTypeNode) Whitespace(org.ballerinalang.model.Whitespace)

Example 12 with Whitespace

use of org.ballerinalang.model.Whitespace in project ballerina by ballerina-lang.

the class BLangPackageBuilder method addTimeoutCause.

public void addTimeoutCause(Set<Whitespace> ws, String identifier) {
    BLangForkJoin forkJoin = (BLangForkJoin) this.forkJoinNodesStack.peek();
    forkJoin.timeoutBody = (BLangBlockStmt) this.blockNodeStack.pop();
    forkJoin.timeoutExpression = (BLangExpression) this.exprNodeStack.pop();
    Set<Whitespace> varWS = removeNthFromLast(ws, 3);
    forkJoin.addWS(ws);
    forkJoin.timeoutVariable = (BLangVariable) this.generateBasicVarNode((DiagnosticPos) this.typeNodeStack.peek().getPosition(), varWS, identifier, false);
}
Also used : BLangForkJoin(org.wso2.ballerinalang.compiler.tree.statements.BLangForkJoin) Whitespace(org.ballerinalang.model.Whitespace)

Example 13 with Whitespace

use of org.ballerinalang.model.Whitespace 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);
}
Also used : BLangMatchStmtPatternClause(org.wso2.ballerinalang.compiler.tree.statements.BLangMatch.BLangMatchStmtPatternClause) Whitespace(org.ballerinalang.model.Whitespace) BLangVariable(org.wso2.ballerinalang.compiler.tree.BLangVariable)

Example 14 with Whitespace

use of org.ballerinalang.model.Whitespace in project ballerina by ballerina-lang.

the class BLangPackageBuilder method addElseIfBlock.

public void addElseIfBlock(DiagnosticPos pos, Set<Whitespace> ws) {
    IfNode elseIfNode = ifElseStatementStack.pop();
    ((BLangIf) elseIfNode).pos = pos;
    elseIfNode.setCondition(exprNodeStack.pop());
    elseIfNode.setBody(blockNodeStack.pop());
    Set<Whitespace> elseWS = removeNthFromStart(ws, 0);
    elseIfNode.addWS(ws);
    IfNode parentIfNode = ifElseStatementStack.peek();
    while (parentIfNode.getElseStatement() != null) {
        parentIfNode = (IfNode) parentIfNode.getElseStatement();
    }
    parentIfNode.addWS(elseWS);
    parentIfNode.setElseStatement(elseIfNode);
}
Also used : IfNode(org.ballerinalang.model.tree.statements.IfNode) Whitespace(org.ballerinalang.model.Whitespace)

Example 15 with Whitespace

use of org.ballerinalang.model.Whitespace 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);
    }
}
Also used : BLangStruct(org.wso2.ballerinalang.compiler.tree.BLangStruct) Whitespace(org.ballerinalang.model.Whitespace) BLangVariable(org.wso2.ballerinalang.compiler.tree.BLangVariable)

Aggregations

Whitespace (org.ballerinalang.model.Whitespace)20 BLangVariable (org.wso2.ballerinalang.compiler.tree.BLangVariable)5 DiagnosticPos (org.wso2.ballerinalang.compiler.util.diagnotic.DiagnosticPos)4 IdentifierNode (org.ballerinalang.model.tree.IdentifierNode)3 BLangStruct (org.wso2.ballerinalang.compiler.tree.BLangStruct)3 BLangInvocation (org.wso2.ballerinalang.compiler.tree.expressions.BLangInvocation)3 CaseFormat (com.google.common.base.CaseFormat)2 JsonArray (com.google.gson.JsonArray)2 JsonElement (com.google.gson.JsonElement)2 JsonNull (com.google.gson.JsonNull)2 JsonObject (com.google.gson.JsonObject)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 Method (java.lang.reflect.Method)2 Paths (java.nio.file.Paths)2 Arrays (java.util.Arrays)2 List (java.util.List)2 Map (java.util.Map)2 Set (java.util.Set)2 Collectors (java.util.stream.Collectors)2 TerminalNode (org.antlr.v4.runtime.tree.TerminalNode)2