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