use of org.ballerinalang.model.elements.PackageID in project ballerina by ballerina-lang.
the class PackageLoader method loadAndDefinePackage.
public BLangPackage loadAndDefinePackage(BLangIdentifier orgName, List<BLangIdentifier> pkgNameComps, BLangIdentifier version) {
// TODO This method is only used by the composer. Can we refactor the composer code?
List<Name> nameComps = pkgNameComps.stream().map(identifier -> names.fromIdNode(identifier)).collect(Collectors.toList());
PackageID pkgID = new PackageID(names.fromIdNode(orgName), nameComps, names.fromIdNode(version));
return loadAndDefinePackage(pkgID);
}
use of org.ballerinalang.model.elements.PackageID in project ballerina by ballerina-lang.
the class PackageLoader method getPackageID.
private PackageID getPackageID(String org, String sourcePkg) {
// split from '.', '\' and '/'
List<Name> pkgNameComps = getPackageNameComps(sourcePkg);
Name orgName = new Name(org);
return new PackageID(orgName, pkgNameComps, Names.DEFAULT_VERSION);
}
use of org.ballerinalang.model.elements.PackageID in project ballerina by ballerina-lang.
the class PackageNameContextResolver method resolveItems.
@Override
public ArrayList<CompletionItem> resolveItems(TextDocumentServiceContext completionContext) {
ArrayList<CompletionItem> completionItems = new ArrayList<>();
LSPackageCache lsPackageCache = completionContext.get(DocumentServiceKeys.LS_PACKAGE_CACHE_KEY);
lsPackageCache.getPackageMap().entrySet().forEach(pkgEntry -> {
PackageID packageID = pkgEntry.getValue().packageID;
String label = packageID.getOrgName().getValue() + "/" + packageID.getName().getValue();
String insertText = label + ";";
fillImportCompletion(label, insertText, completionItems);
});
return completionItems;
}
use of org.ballerinalang.model.elements.PackageID in project ballerina by ballerina-lang.
the class SymbolEnter method visit.
@Override
public void visit(BLangImportPackage importPkgNode) {
Name pkgAlias = names.fromIdNode(importPkgNode.alias);
if (symResolver.lookupSymbol(env, pkgAlias, SymTag.IMPORT) != symTable.notFoundSymbol) {
dlog.error(importPkgNode.pos, DiagnosticCode.REDECLARED_SYMBOL, pkgAlias);
return;
}
// TODO Clean this code up. Can we move the this to BLangPackageBuilder class
// Create import package symbol
Name orgName;
if (importPkgNode.orgName.value == null || importPkgNode.orgName.value.isEmpty()) {
// means it's in 'import <pkg-name>' style
orgName = Names.ANON_ORG;
} else {
// means it's in 'import <org-name>/<pkg-name>' style
orgName = names.fromIdNode(importPkgNode.orgName);
}
List<Name> nameComps = importPkgNode.pkgNameComps.stream().map(identifier -> names.fromIdNode(identifier)).collect(Collectors.toList());
String version = names.fromIdNode(importPkgNode.version).getValue().replaceAll("[^\\d.]", "");
PackageID pkgId = new PackageID(orgName, nameComps, new Name(version));
if (pkgId.name.getValue().startsWith(Names.BUILTIN_PACKAGE.value)) {
dlog.error(importPkgNode.pos, DiagnosticCode.PACKAGE_NOT_FOUND, importPkgNode.getQualifiedPackageName());
return;
}
// Attempt to load the imported package.
BLangPackage pkgNode = pkgLoader.loadPackage(pkgId, env.enclPkg.packageRepository);
if (pkgNode == null) {
dlog.error(importPkgNode.pos, DiagnosticCode.PACKAGE_NOT_FOUND, importPkgNode.getQualifiedPackageName());
return;
}
// This import package is not defined.
if (pkgNode.symbol == null) {
// Define import package now.
definePackage(pkgNode);
populateInitFunctionInvocation(importPkgNode, pkgNode.symbol);
}
// define the import package symbol in the current package scope
importPkgNode.symbol = pkgNode.symbol;
this.env.scope.define(pkgAlias, pkgNode.symbol);
}
use of org.ballerinalang.model.elements.PackageID in project ballerina by ballerina-lang.
the class CompilerPluginRunner method isValidEndpoints.
private boolean isValidEndpoints(DefinitionID endpoint, CompilerPlugin plugin) {
PackageID pkdID = new PackageID(Names.ANON_ORG, names.fromString(endpoint.pkgName), Names.EMPTY);
BLangPackage pkgNode = this.packageCache.get(pkdID);
if (pkgNode == null) {
return false;
}
SymbolEnv pkgEnv = symTable.pkgEnvMap.get(pkgNode.symbol);
final BSymbol bSymbol = symResolver.lookupSymbol(pkgEnv, names.fromString(endpoint.name), SymTag.VARIABLE_NAME);
return bSymbol != symTable.notFoundSymbol;
}
Aggregations