use of org.wso2.ballerinalang.compiler.tree.BLangIdentifier in project ballerina by ballerina-lang.
the class BLangPackageBuilder method addNamedArgument.
public void addNamedArgument(DiagnosticPos pos, Set<Whitespace> ws, String name) {
BLangNamedArgsExpression namedArg = (BLangNamedArgsExpression) TreeBuilder.createNamedArgNode();
namedArg.pos = pos;
namedArg.addWS(ws);
namedArg.name = (BLangIdentifier) this.createIdentifier(name);
namedArg.expr = (BLangExpression) this.exprNodeStack.pop();
addExpressionNode(namedArg);
}
use of org.wso2.ballerinalang.compiler.tree.BLangIdentifier in project ballerina by ballerina-lang.
the class BLangPackageBuilder method addTypeInitExpression.
public void addTypeInitExpression(DiagnosticPos pos, Set<Whitespace> ws, String initName, boolean typeAvailable, boolean exprAvailable) {
BLangTypeInit objectInitNode = (BLangTypeInit) TreeBuilder.createObjectInitNode();
objectInitNode.pos = pos;
objectInitNode.addWS(ws);
if (typeAvailable) {
objectInitNode.userDefinedType = (BLangUserDefinedType) typeNodeStack.pop();
}
BLangInvocation invocationNode = (BLangInvocation) TreeBuilder.createInvocationNode();
invocationNode.pos = pos;
invocationNode.addWS(ws);
if (exprAvailable) {
List<ExpressionNode> exprNodes = exprNodeListStack.pop();
Set<Whitespace> cws = commaWsStack.pop();
exprNodes.forEach(exprNode -> {
invocationNode.argExprs.add((BLangExpression) exprNode);
objectInitNode.argsExpr.add((BLangExpression) exprNode);
});
invocationNode.addWS(cws);
objectInitNode.addWS(cws);
}
// TODO check whether pkgName can be be empty
IdentifierNode pkgNameNode = TreeBuilder.createIdentifierNode();
IdentifierNode nameNode = createIdentifier(initName);
BLangNameReference nameReference = new BLangNameReference(pos, ws, pkgNameNode, nameNode);
invocationNode.name = (BLangIdentifier) nameReference.name;
invocationNode.addWS(nameReference.ws);
invocationNode.pkgAlias = (BLangIdentifier) nameReference.pkgAlias;
objectInitNode.objectInitInvocation = invocationNode;
this.addExpressionNode(objectInitNode);
}
use of org.wso2.ballerinalang.compiler.tree.BLangIdentifier in project ballerina by ballerina-lang.
the class PackageLoader method addImportPkg.
// Private methods
private void addImportPkg(BLangPackage bLangPackage, String orgName, String sourcePkgName, String version) {
List<Name> nameComps = getPackageNameComps(sourcePkgName);
List<BLangIdentifier> pkgNameComps = new ArrayList<>();
nameComps.forEach(comp -> {
IdentifierNode node = TreeBuilder.createIdentifierNode();
node.setValue(comp.value);
pkgNameComps.add((BLangIdentifier) node);
});
BLangIdentifier orgNameNode = (BLangIdentifier) TreeBuilder.createIdentifierNode();
orgNameNode.setValue(orgName);
BLangIdentifier versionNode = (BLangIdentifier) TreeBuilder.createIdentifierNode();
versionNode.setValue(version);
BLangImportPackage importDcl = (BLangImportPackage) TreeBuilder.createImportPackageNode();
importDcl.pos = bLangPackage.pos;
importDcl.pkgNameComps = pkgNameComps;
importDcl.orgName = orgNameNode;
importDcl.version = versionNode;
BLangIdentifier alias = (BLangIdentifier) TreeBuilder.createIdentifierNode();
alias.setValue(names.merge(Names.DOT, nameComps.get(nameComps.size() - 1)).value);
importDcl.alias = alias;
bLangPackage.imports.add(importDcl);
}
use of org.wso2.ballerinalang.compiler.tree.BLangIdentifier in project ballerina by ballerina-lang.
the class SwaggerConverterUtils method getAlias.
/**
* Gets the alias for a given package from a bLang file root node.
* @param topCompilationUnit The root node.
* @param packageName The package name.
* @return The alias.
*/
private static String getAlias(BLangCompilationUnit topCompilationUnit, String packageName) {
for (TopLevelNode topLevelNode : topCompilationUnit.getTopLevelNodes()) {
if (topLevelNode instanceof BLangImportPackage) {
BLangImportPackage importPackage = (BLangImportPackage) topLevelNode;
String packagePath = importPackage.getPackageName().stream().map(BLangIdentifier::getValue).collect(Collectors.joining("."));
if (packageName.equals(packagePath)) {
return importPackage.getAlias().getValue();
}
}
}
return null;
}
Aggregations