Search in sources :

Example 6 with Whitespace

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

the class BLangParserListener method exitObjectFieldDefinition.

/**
 * {@inheritDoc}
 *
 * <p>The default implementation does nothing.</p>
 */
@Override
public void exitObjectFieldDefinition(BallerinaParser.ObjectFieldDefinitionContext ctx) {
    if (ctx.exception != null) {
        return;
    }
    DiagnosticPos currentPos = getCurrentPos(ctx);
    Set<Whitespace> ws = getWS(ctx);
    String name = ctx.Identifier().getText();
    boolean exprAvailable = ctx.expression() != null;
    if (ctx.parent instanceof BallerinaParser.PublicObjectFieldsContext) {
        this.pkgBuilder.addFieldToObject(currentPos, ws, name, exprAvailable, 0, false);
    } else if (ctx.parent instanceof BallerinaParser.PrivateObjectFieldsContext) {
        this.pkgBuilder.addFieldToObject(currentPos, ws, name, exprAvailable, 0, true);
    }
}
Also used : DiagnosticPos(org.wso2.ballerinalang.compiler.util.diagnotic.DiagnosticPos) Whitespace(org.ballerinalang.model.Whitespace) BallerinaParser(org.wso2.ballerinalang.compiler.parser.antlr4.BallerinaParser)

Example 7 with Whitespace

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

the class BLangPackageBuilder method addConstraintType.

public void addConstraintType(DiagnosticPos pos, Set<Whitespace> ws, String typeName) {
    BLangNameReference nameReference = nameReferenceStack.pop();
    BLangUserDefinedType constraintType = (BLangUserDefinedType) TreeBuilder.createUserDefinedTypeNode();
    constraintType.pos = pos;
    constraintType.pkgAlias = (BLangIdentifier) nameReference.pkgAlias;
    constraintType.typeName = (BLangIdentifier) nameReference.name;
    constraintType.addWS(nameReference.ws);
    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 = constraintType;
    constrainedType.pos = pos;
    constrainedType.addWS(ws);
    addType(constrainedType);
}
Also used : BLangConstrainedType(org.wso2.ballerinalang.compiler.tree.types.BLangConstrainedType) BLangNameReference(org.wso2.ballerinalang.compiler.tree.BLangNameReference) BLangBuiltInRefTypeNode(org.wso2.ballerinalang.compiler.tree.types.BLangBuiltInRefTypeNode) BLangUserDefinedType(org.wso2.ballerinalang.compiler.tree.types.BLangUserDefinedType) Whitespace(org.ballerinalang.model.Whitespace)

Example 8 with Whitespace

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

the class BLangPackageBuilder method addJoinCause.

public void addJoinCause(Set<Whitespace> ws, String identifier) {
    BLangForkJoin forkJoin = (BLangForkJoin) this.forkJoinNodesStack.peek();
    forkJoin.joinedBody = (BLangBlockStmt) this.blockNodeStack.pop();
    Set<Whitespace> varWS = removeNthFromLast(ws, 3);
    forkJoin.addWS(ws);
    forkJoin.joinResultVar = (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 9 with Whitespace

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

the class BLangPackageBuilder method removeNth.

private Set<Whitespace> removeNth(Iterator<Whitespace> iterator, int n) {
    int i = 0;
    while (iterator.hasNext()) {
        Whitespace next = iterator.next();
        if (i++ == n) {
            Set<Whitespace> varWS = new TreeSet<>();
            varWS.add(next);
            iterator.remove();
            return varWS;
        }
    }
    return null;
}
Also used : TreeSet(java.util.TreeSet) BLangAnnotationAttachmentPoint(org.wso2.ballerinalang.compiler.tree.BLangAnnotationAttachmentPoint) BLangEndpoint(org.wso2.ballerinalang.compiler.tree.BLangEndpoint) Whitespace(org.ballerinalang.model.Whitespace)

Example 10 with Whitespace

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

the class BLangPackageBuilder method addFieldToObject.

void addFieldToObject(DiagnosticPos pos, Set<Whitespace> ws, String identifier, boolean exprAvailable, int annotCount, boolean isPrivate) {
    Set<Whitespace> wsForSemiColon = removeNthFromLast(ws, 0);
    BLangObject objectNode = (BLangObject) this.objectStack.peek();
    objectNode.addWS(wsForSemiColon);
    BLangVariable field = addVar(pos, ws, identifier, exprAvailable, annotCount);
    if (!isPrivate) {
        field.flagSet.add(Flag.PUBLIC);
    }
}
Also used : BLangObject(org.wso2.ballerinalang.compiler.tree.BLangObject) 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