Search in sources :

Example 1 with BLangXMLNS

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

the class SymbolEnter method createNamespaceDeclrStatement.

private BLangXMLNSStatement createNamespaceDeclrStatement(BLangXMLNS xmlns) {
    BLangXMLNSStatement xmlnsStmt = (BLangXMLNSStatement) TreeBuilder.createXMLNSDeclrStatementNode();
    xmlnsStmt.xmlnsDecl = xmlns;
    xmlnsStmt.pos = xmlns.pos;
    return xmlnsStmt;
}
Also used : BLangXMLNSStatement(org.wso2.ballerinalang.compiler.tree.statements.BLangXMLNSStatement)

Example 2 with BLangXMLNS

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

the class SymbolEnter method visit.

@Override
public void visit(BLangXMLNS xmlnsNode) {
    String nsURI = (String) ((BLangLiteral) xmlnsNode.namespaceURI).value;
    if (xmlnsNode.prefix.value != null && nsURI.isEmpty()) {
        dlog.error(xmlnsNode.pos, DiagnosticCode.INVALID_NAMESPACE_DECLARATION, xmlnsNode.prefix);
    }
    // set the prefix of the default namespace
    if (xmlnsNode.prefix.value == null) {
        xmlnsNode.prefix.value = XMLConstants.DEFAULT_NS_PREFIX;
    }
    BXMLNSSymbol xmlnsSymbol = Symbols.createXMLNSSymbol(names.fromIdNode(xmlnsNode.prefix), nsURI, env.enclPkg.symbol.pkgID, env.scope.owner);
    xmlnsNode.symbol = xmlnsSymbol;
    // First check for package-imports with the same alias.
    // Here we do not check for owner equality, since package import is always at the package
    // level, but the namespace declaration can be at any level.
    BSymbol foundSym = symResolver.lookupSymbol(env, xmlnsSymbol.name, SymTag.PACKAGE);
    if (foundSym != symTable.notFoundSymbol) {
        dlog.error(xmlnsNode.pos, DiagnosticCode.REDECLARED_SYMBOL, xmlnsSymbol.name);
        return;
    }
    // Define it in the enclosing scope. Here we check for the owner equality,
    // to support overriding of namespace declarations defined at package level.
    defineSymbol(xmlnsNode.pos, xmlnsSymbol);
}
Also used : BXMLNSSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BXMLNSSymbol) BSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BSymbol)

Example 3 with BLangXMLNS

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

the class Desugar method visit.

@Override
public void visit(BLangXMLNS xmlnsNode) {
    BLangXMLNS generatedXMLNSNode;
    xmlnsNode.namespaceURI = rewriteExpr(xmlnsNode.namespaceURI);
    BSymbol ownerSymbol = xmlnsNode.symbol.owner;
    // Local namespace declaration in a function/resource/action/worker
    if ((ownerSymbol.tag & SymTag.INVOKABLE) == SymTag.INVOKABLE) {
        generatedXMLNSNode = new BLangLocalXMLNS();
    } else {
        generatedXMLNSNode = new BLangPackageXMLNS();
    }
    generatedXMLNSNode.namespaceURI = xmlnsNode.namespaceURI;
    generatedXMLNSNode.prefix = xmlnsNode.prefix;
    generatedXMLNSNode.symbol = xmlnsNode.symbol;
    result = generatedXMLNSNode;
}
Also used : BLangPackageXMLNS(org.wso2.ballerinalang.compiler.tree.BLangXMLNS.BLangPackageXMLNS) BLangXMLNS(org.wso2.ballerinalang.compiler.tree.BLangXMLNS) BSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BSymbol) BLangLocalXMLNS(org.wso2.ballerinalang.compiler.tree.BLangXMLNS.BLangLocalXMLNS)

Example 4 with BLangXMLNS

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

Aggregations

BSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BSymbol)2 BLangXMLNS (org.wso2.ballerinalang.compiler.tree.BLangXMLNS)2 BLangXMLNSStatement (org.wso2.ballerinalang.compiler.tree.statements.BLangXMLNSStatement)2 BXMLNSSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BXMLNSSymbol)1 BLangIdentifier (org.wso2.ballerinalang.compiler.tree.BLangIdentifier)1 BLangLocalXMLNS (org.wso2.ballerinalang.compiler.tree.BLangXMLNS.BLangLocalXMLNS)1 BLangPackageXMLNS (org.wso2.ballerinalang.compiler.tree.BLangXMLNS.BLangPackageXMLNS)1