Search in sources :

Example 16 with BLangIdentifier

use of org.wso2.ballerinalang.compiler.tree.BLangIdentifier in project ballerina by ballerina-lang.

the class BLangPackageBuilder method addXMLNSDeclaration.

public void addXMLNSDeclaration(DiagnosticPos pos, Set<Whitespace> ws, String namespaceUri, String prefix, boolean isTopLevel) {
    BLangXMLNS xmlns = (BLangXMLNS) TreeBuilder.createXMLNSNode();
    BLangIdentifier prefixIdentifer = (BLangIdentifier) TreeBuilder.createIdentifierNode();
    prefixIdentifer.pos = pos;
    prefixIdentifer.value = prefix;
    addLiteralValue(pos, removeNthFromStart(ws, 1), TypeTags.STRING, namespaceUri);
    xmlns.namespaceURI = (BLangLiteral) exprNodeStack.pop();
    xmlns.prefix = prefixIdentifer;
    xmlns.pos = pos;
    xmlns.addWS(ws);
    if (isTopLevel) {
        this.compUnit.addTopLevelNode(xmlns);
        return;
    }
    BLangXMLNSStatement xmlnsStmt = (BLangXMLNSStatement) TreeBuilder.createXMLNSDeclrStatementNode();
    xmlnsStmt.xmlnsDecl = xmlns;
    xmlnsStmt.pos = pos;
    addStmtToCurrentBlock(xmlnsStmt);
}
Also used : BLangXMLNS(org.wso2.ballerinalang.compiler.tree.BLangXMLNS) BLangXMLNSStatement(org.wso2.ballerinalang.compiler.tree.statements.BLangXMLNSStatement) BLangIdentifier(org.wso2.ballerinalang.compiler.tree.BLangIdentifier)

Example 17 with BLangIdentifier

use of org.wso2.ballerinalang.compiler.tree.BLangIdentifier in project ballerina by ballerina-lang.

the class BLangPackageBuilder method populateStructNode.

private BLangStruct populateStructNode(DiagnosticPos pos, Set<Whitespace> ws, IdentifierNode name, boolean isAnonymous) {
    BLangStruct structNode = (BLangStruct) this.structStack.pop();
    structNode.pos = pos;
    structNode.addWS(ws);
    structNode.name = (BLangIdentifier) name;
    structNode.isAnonymous = isAnonymous;
    this.varListStack.pop().forEach(variableNode -> {
        ((BLangVariable) variableNode).docTag = DocTag.FIELD;
        structNode.addField(variableNode);
    });
    return structNode;
}
Also used : BLangStruct(org.wso2.ballerinalang.compiler.tree.BLangStruct)

Example 18 with BLangIdentifier

use of org.wso2.ballerinalang.compiler.tree.BLangIdentifier in project ballerina by ballerina-lang.

the class BLangPackageBuilder method addEndpointType.

public void addEndpointType(DiagnosticPos pos, Set<Whitespace> ws) {
    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);
    addType(constraintType);
}
Also used : BLangNameReference(org.wso2.ballerinalang.compiler.tree.BLangNameReference) BLangUserDefinedType(org.wso2.ballerinalang.compiler.tree.types.BLangUserDefinedType)

Example 19 with BLangIdentifier

use of org.wso2.ballerinalang.compiler.tree.BLangIdentifier in project ballerina by ballerina-lang.

the class BLangPackageBuilder method addImportPackageDeclaration.

public void addImportPackageDeclaration(DiagnosticPos pos, Set<Whitespace> ws, String orgName, List<String> nameComps, String version, String alias) {
    List<BLangIdentifier> pkgNameComps = new ArrayList<>();
    nameComps.forEach(e -> pkgNameComps.add((BLangIdentifier) this.createIdentifier(e)));
    BLangIdentifier versionNode = (BLangIdentifier) this.createIdentifier(version);
    BLangIdentifier aliasNode = (alias != null && !alias.isEmpty()) ? (BLangIdentifier) this.createIdentifier(alias) : pkgNameComps.get(pkgNameComps.size() - 1);
    BLangImportPackage importDcl = (BLangImportPackage) TreeBuilder.createImportPackageNode();
    importDcl.pos = pos;
    importDcl.addWS(ws);
    importDcl.pkgNameComps = pkgNameComps;
    importDcl.version = versionNode;
    importDcl.orgName = (BLangIdentifier) this.createIdentifier(orgName);
    importDcl.alias = aliasNode;
    this.compUnit.addTopLevelNode(importDcl);
    if (this.imports.contains(importDcl)) {
        this.dlog.warning(pos, DiagnosticCode.REDECLARED_IMPORT_PACKAGE, importDcl.getQualifiedPackageName());
    } else {
        this.imports.add(importDcl);
    }
}
Also used : ArrayList(java.util.ArrayList) BLangImportPackage(org.wso2.ballerinalang.compiler.tree.BLangImportPackage) BLangIdentifier(org.wso2.ballerinalang.compiler.tree.BLangIdentifier)

Example 20 with BLangIdentifier

use of org.wso2.ballerinalang.compiler.tree.BLangIdentifier 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)

Aggregations

BLangIdentifier (org.wso2.ballerinalang.compiler.tree.BLangIdentifier)20 BLangNameReference (org.wso2.ballerinalang.compiler.tree.BLangNameReference)9 IdentifierNode (org.ballerinalang.model.tree.IdentifierNode)8 BLangInvocation (org.wso2.ballerinalang.compiler.tree.expressions.BLangInvocation)7 BLangSimpleVarRef (org.wso2.ballerinalang.compiler.tree.expressions.BLangSimpleVarRef)7 BLangUserDefinedType (org.wso2.ballerinalang.compiler.tree.types.BLangUserDefinedType)6 ArrayList (java.util.ArrayList)5 BLangEndpoint (org.wso2.ballerinalang.compiler.tree.BLangEndpoint)5 BLangImportPackage (org.wso2.ballerinalang.compiler.tree.BLangImportPackage)5 BVarSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BVarSymbol)4 BLangStruct (org.wso2.ballerinalang.compiler.tree.BLangStruct)4 BLangVariable (org.wso2.ballerinalang.compiler.tree.BLangVariable)4 BLangExpression (org.wso2.ballerinalang.compiler.tree.expressions.BLangExpression)4 BLangAssignment (org.wso2.ballerinalang.compiler.tree.statements.BLangAssignment)4 Name (org.wso2.ballerinalang.compiler.util.Name)4 SelectExpressionNode (org.ballerinalang.model.tree.clauses.SelectExpressionNode)3 ExpressionNode (org.ballerinalang.model.tree.expressions.ExpressionNode)3 BLangXMLQName (org.wso2.ballerinalang.compiler.tree.expressions.BLangXMLQName)3 List (java.util.List)2 Set (java.util.Set)2