Search in sources :

Example 11 with PackageID

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);
}
Also used : SystemPackageRepositoryProvider(org.ballerinalang.spi.SystemPackageRepositoryProvider) Arrays(java.util.Arrays) PackageSource(org.ballerinalang.repository.PackageSource) BLangIdentifier(org.wso2.ballerinalang.compiler.tree.BLangIdentifier) PROJECT_DIR(org.ballerinalang.compiler.CompilerOptionName.PROJECT_DIR) BLangImportPackage(org.wso2.ballerinalang.compiler.tree.BLangImportPackage) IdentifierNode(org.ballerinalang.model.tree.IdentifierNode) Converter(org.wso2.ballerinalang.compiler.packaging.converters.Converter) Names(org.wso2.ballerinalang.compiler.util.Names) RepoHierarchy(org.wso2.ballerinalang.compiler.packaging.RepoHierarchy) URI(java.net.URI) Path(java.nio.file.Path) ProjectSourceRepo(org.wso2.ballerinalang.compiler.packaging.repo.ProjectSourceRepo) PackageID(org.ballerinalang.model.elements.PackageID) Set(java.util.Set) ServiceLoader(java.util.ServiceLoader) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) List(java.util.List) Manifest(org.ballerinalang.toml.model.Manifest) OFFLINE(org.ballerinalang.compiler.CompilerOptionName.OFFLINE) Resolution(org.wso2.ballerinalang.compiler.packaging.Resolution) RepoHierarchyBuilder(org.wso2.ballerinalang.compiler.packaging.RepoHierarchyBuilder) Optional(java.util.Optional) SymbolEnter(org.wso2.ballerinalang.compiler.semantics.analyzer.SymbolEnter) CompilerOptions(org.wso2.ballerinalang.compiler.util.CompilerOptions) ManifestProcessor(org.ballerinalang.toml.parser.ManifestProcessor) RemoteRepo(org.wso2.ballerinalang.compiler.packaging.repo.RemoteRepo) ArrayList(java.util.ArrayList) Dependency(org.ballerinalang.toml.model.Dependency) RepoHierarchyBuilder.node(org.wso2.ballerinalang.compiler.packaging.RepoHierarchyBuilder.node) HomeRepoUtils(org.wso2.ballerinalang.util.HomeRepoUtils) PackageRepository(org.ballerinalang.repository.PackageRepository) Repo(org.wso2.ballerinalang.compiler.packaging.repo.Repo) TreeBuilder(org.ballerinalang.model.TreeBuilder) ProgramingSourceRepo(org.wso2.ballerinalang.compiler.packaging.repo.ProgramingSourceRepo) ProjectDirs(org.wso2.ballerinalang.compiler.util.ProjectDirs) StreamSupport(java.util.stream.StreamSupport) BLangPackage(org.wso2.ballerinalang.compiler.tree.BLangPackage) BLangCompilerException(org.ballerinalang.compiler.BLangCompilerException) Name(org.wso2.ballerinalang.compiler.util.Name) ZipRepo(org.wso2.ballerinalang.compiler.packaging.repo.ZipRepo) PackageEntity(org.ballerinalang.repository.PackageEntity) Parser(org.wso2.ballerinalang.compiler.parser.Parser) Paths(java.nio.file.Paths) GenericPackageSource(org.wso2.ballerinalang.compiler.packaging.GenericPackageSource) CacheRepo(org.wso2.ballerinalang.compiler.packaging.repo.CacheRepo) Collections(java.util.Collections) CompilerContext(org.wso2.ballerinalang.compiler.util.CompilerContext) PackageID(org.ballerinalang.model.elements.PackageID) Name(org.wso2.ballerinalang.compiler.util.Name)

Example 12 with PackageID

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);
}
Also used : PackageID(org.ballerinalang.model.elements.PackageID) Name(org.wso2.ballerinalang.compiler.util.Name)

Example 13 with PackageID

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;
}
Also used : CompletionItem(org.eclipse.lsp4j.CompletionItem) ArrayList(java.util.ArrayList) LSPackageCache(org.ballerinalang.langserver.LSPackageCache) PackageID(org.ballerinalang.model.elements.PackageID)

Example 14 with PackageID

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);
}
Also used : BInvokableType(org.wso2.ballerinalang.compiler.semantics.model.types.BInvokableType) BLangReturn(org.wso2.ballerinalang.compiler.tree.statements.BLangReturn) BAttachedFunction(org.wso2.ballerinalang.compiler.semantics.model.symbols.BStructSymbol.BAttachedFunction) BLangIdentifier(org.wso2.ballerinalang.compiler.tree.BLangIdentifier) BConnectorType(org.wso2.ballerinalang.compiler.semantics.model.types.BConnectorType) BTypeSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BTypeSymbol) BVarSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BVarSymbol) BLangImportPackage(org.wso2.ballerinalang.compiler.tree.BLangImportPackage) Flag(org.ballerinalang.model.elements.Flag) IdentifierNode(org.ballerinalang.model.tree.IdentifierNode) TopLevelNode(org.ballerinalang.model.tree.TopLevelNode) BLangCompilationUnit(org.wso2.ballerinalang.compiler.tree.BLangCompilationUnit) BAnnotationSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BAnnotationSymbol) Names(org.wso2.ballerinalang.compiler.util.Names) BServiceSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BServiceSymbol) BEnumType(org.wso2.ballerinalang.compiler.semantics.model.types.BEnumType) EnumSet(java.util.EnumSet) BLangAssignment(org.wso2.ballerinalang.compiler.tree.statements.BLangAssignment) BLangDiagnosticLog(org.wso2.ballerinalang.compiler.util.diagnotic.BLangDiagnosticLog) BLangSimpleVarRef(org.wso2.ballerinalang.compiler.tree.expressions.BLangSimpleVarRef) BXMLNSSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BXMLNSSymbol) BConnectorSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BConnectorSymbol) BStructType(org.wso2.ballerinalang.compiler.semantics.model.types.BStructType) BLangExpression(org.wso2.ballerinalang.compiler.tree.expressions.BLangExpression) CompilerPhase(org.ballerinalang.compiler.CompilerPhase) BXMLAttributeSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BXMLAttributeSymbol) BSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BSymbol) PackageID(org.ballerinalang.model.elements.PackageID) Set(java.util.Set) BPackageSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BPackageSymbol) BLangXMLNS(org.wso2.ballerinalang.compiler.tree.BLangXMLNS) BLangAnnotAttribute(org.wso2.ballerinalang.compiler.tree.BLangAnnotAttribute) Collectors(java.util.stream.Collectors) BLangTransformer(org.wso2.ballerinalang.compiler.tree.BLangTransformer) BLangNode(org.wso2.ballerinalang.compiler.tree.BLangNode) BLangService(org.wso2.ballerinalang.compiler.tree.BLangService) List(java.util.List) IMPORT(org.ballerinalang.model.tree.NodeKind.IMPORT) Scope(org.wso2.ballerinalang.compiler.semantics.model.Scope) BLangEnum(org.wso2.ballerinalang.compiler.tree.BLangEnum) NodeKind(org.ballerinalang.model.tree.NodeKind) BAnnotationAttributeSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BAnnotationAttributeSymbol) StatementNode(org.ballerinalang.model.tree.statements.StatementNode) BStructSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BStructSymbol) BLangWorker(org.wso2.ballerinalang.compiler.tree.BLangWorker) BLangEndpoint(org.wso2.ballerinalang.compiler.tree.BLangEndpoint) BLangXMLNSStatement(org.wso2.ballerinalang.compiler.tree.statements.BLangXMLNSStatement) BLangInvokableNode(org.wso2.ballerinalang.compiler.tree.BLangInvokableNode) BLangAction(org.wso2.ballerinalang.compiler.tree.BLangAction) BStructField(org.wso2.ballerinalang.compiler.semantics.model.types.BStructType.BStructField) BLangUserDefinedType(org.wso2.ballerinalang.compiler.tree.types.BLangUserDefinedType) BAnnotationType(org.wso2.ballerinalang.compiler.semantics.model.types.BAnnotationType) BLangVariable(org.wso2.ballerinalang.compiler.tree.BLangVariable) BLangExpressionStmt(org.wso2.ballerinalang.compiler.tree.statements.BLangExpressionStmt) BLangAnnotation(org.wso2.ballerinalang.compiler.tree.BLangAnnotation) BLangXMLAttribute(org.wso2.ballerinalang.compiler.tree.expressions.BLangXMLAttribute) BLangStatement(org.wso2.ballerinalang.compiler.tree.statements.BLangStatement) BLangNodeVisitor(org.wso2.ballerinalang.compiler.tree.BLangNodeVisitor) PackageLoader(org.wso2.ballerinalang.compiler.PackageLoader) TypeTags(org.wso2.ballerinalang.compiler.util.TypeTags) BServiceType(org.wso2.ballerinalang.compiler.semantics.model.types.BServiceType) Flags(org.wso2.ballerinalang.util.Flags) BLangResource(org.wso2.ballerinalang.compiler.tree.BLangResource) DocTag(org.ballerinalang.model.elements.DocTag) TreeBuilder(org.ballerinalang.model.TreeBuilder) BType(org.wso2.ballerinalang.compiler.semantics.model.types.BType) BInvokableSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BInvokableSymbol) DiagnosticPos(org.wso2.ballerinalang.compiler.util.diagnotic.DiagnosticPos) XMLConstants(javax.xml.XMLConstants) BLangPackage(org.wso2.ballerinalang.compiler.tree.BLangPackage) SymbolEnv(org.wso2.ballerinalang.compiler.semantics.model.SymbolEnv) BTransformerSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BTransformerSymbol) BLangObject(org.wso2.ballerinalang.compiler.tree.BLangObject) BLangXMLQName(org.wso2.ballerinalang.compiler.tree.expressions.BLangXMLQName) Symbols(org.wso2.ballerinalang.compiler.semantics.model.symbols.Symbols) BLangFunction(org.wso2.ballerinalang.compiler.tree.BLangFunction) Name(org.wso2.ballerinalang.compiler.util.Name) SymTag(org.wso2.ballerinalang.compiler.semantics.model.symbols.SymTag) DiagnosticCode(org.ballerinalang.util.diagnostic.DiagnosticCode) BLangLiteral(org.wso2.ballerinalang.compiler.tree.expressions.BLangLiteral) BLangEnumerator(org.wso2.ballerinalang.compiler.tree.BLangEnum.BLangEnumerator) BLangInvocation(org.wso2.ballerinalang.compiler.tree.expressions.BLangInvocation) BLangConnector(org.wso2.ballerinalang.compiler.tree.BLangConnector) BEndpointVarSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BEndpointVarSymbol) BLangStruct(org.wso2.ballerinalang.compiler.tree.BLangStruct) BLangBlockStmt(org.wso2.ballerinalang.compiler.tree.statements.BLangBlockStmt) SymbolTable(org.wso2.ballerinalang.compiler.semantics.model.SymbolTable) CompilerContext(org.wso2.ballerinalang.compiler.util.CompilerContext) BLangPackage(org.wso2.ballerinalang.compiler.tree.BLangPackage) PackageID(org.ballerinalang.model.elements.PackageID) BLangXMLQName(org.wso2.ballerinalang.compiler.tree.expressions.BLangXMLQName) Name(org.wso2.ballerinalang.compiler.util.Name)

Example 15 with PackageID

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;
}
Also used : BLangPackage(org.wso2.ballerinalang.compiler.tree.BLangPackage) BSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BSymbol) PackageID(org.ballerinalang.model.elements.PackageID) SymbolEnv(org.wso2.ballerinalang.compiler.semantics.model.SymbolEnv)

Aggregations

PackageID (org.ballerinalang.model.elements.PackageID)23 Name (org.wso2.ballerinalang.compiler.util.Name)10 ArrayList (java.util.ArrayList)9 Test (org.testng.annotations.Test)8 Path (java.nio.file.Path)7 BLangPackage (org.wso2.ballerinalang.compiler.tree.BLangPackage)7 CompilerContext (org.wso2.ballerinalang.compiler.util.CompilerContext)7 List (java.util.List)6 Patten (org.wso2.ballerinalang.compiler.packaging.Patten)6 RepoHierarchy (org.wso2.ballerinalang.compiler.packaging.RepoHierarchy)6 IOException (java.io.IOException)5 URI (java.net.URI)5 Collectors (java.util.stream.Collectors)5 BLangCompilerException (org.ballerinalang.compiler.BLangCompilerException)5 Resolution (org.wso2.ballerinalang.compiler.packaging.Resolution)5 Names (org.wso2.ballerinalang.compiler.util.Names)5 Arrays (java.util.Arrays)4 Collections (java.util.Collections)4 Set (java.util.Set)4 CacheRepo (org.wso2.ballerinalang.compiler.packaging.repo.CacheRepo)4