Search in sources :

Example 1 with BXMLAttributeSymbol

use of org.wso2.ballerinalang.compiler.semantics.model.symbols.BXMLAttributeSymbol in project ballerina by ballerina-lang.

the class SymbolEnter method visit.

public void visit(BLangXMLAttribute bLangXMLAttribute) {
    if (!(bLangXMLAttribute.name.getKind() == NodeKind.XML_QNAME)) {
        return;
    }
    BLangXMLQName qname = (BLangXMLQName) bLangXMLAttribute.name;
    // If no duplicates, then define this attribute symbol.
    if (!bLangXMLAttribute.isNamespaceDeclr) {
        BXMLAttributeSymbol attrSymbol = new BXMLAttributeSymbol(qname.localname.value, qname.namespaceURI, env.enclPkg.symbol.pkgID, env.scope.owner);
        if (symResolver.checkForUniqueMemberSymbol(bLangXMLAttribute.pos, env, attrSymbol)) {
            env.scope.define(attrSymbol.name, attrSymbol);
            bLangXMLAttribute.symbol = attrSymbol;
        }
        return;
    }
    List<BLangExpression> exprs = bLangXMLAttribute.value.textFragments;
    String nsURI = null;
    // TODO: find a better way to get the statically defined URI.
    if (exprs.size() == 1 && exprs.get(0).getKind() == NodeKind.LITERAL) {
        nsURI = (String) ((BLangLiteral) exprs.get(0)).value;
    }
    String symbolName = qname.localname.value;
    if (symbolName.equals(XMLConstants.XMLNS_ATTRIBUTE)) {
        symbolName = XMLConstants.DEFAULT_NS_PREFIX;
    }
    BXMLNSSymbol xmlnsSymbol = new BXMLNSSymbol(names.fromString(symbolName), nsURI, env.enclPkg.symbol.pkgID, env.scope.owner);
    if (symResolver.checkForUniqueMemberSymbol(bLangXMLAttribute.pos, env, xmlnsSymbol)) {
        env.scope.define(xmlnsSymbol.name, xmlnsSymbol);
        bLangXMLAttribute.symbol = xmlnsSymbol;
    }
}
Also used : BLangXMLQName(org.wso2.ballerinalang.compiler.tree.expressions.BLangXMLQName) BLangLiteral(org.wso2.ballerinalang.compiler.tree.expressions.BLangLiteral) BXMLNSSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BXMLNSSymbol) BXMLAttributeSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BXMLAttributeSymbol) BLangExpression(org.wso2.ballerinalang.compiler.tree.expressions.BLangExpression)

Aggregations

BXMLAttributeSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BXMLAttributeSymbol)1 BXMLNSSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BXMLNSSymbol)1 BLangExpression (org.wso2.ballerinalang.compiler.tree.expressions.BLangExpression)1 BLangLiteral (org.wso2.ballerinalang.compiler.tree.expressions.BLangLiteral)1 BLangXMLQName (org.wso2.ballerinalang.compiler.tree.expressions.BLangXMLQName)1