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);
}
}
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);
}
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);
}
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;
}
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);
}
}
Aggregations