/** * Get the current file's imports. * * @param pkg BLangPackage to extract content from * @param ctx LS Operation Context * @return {@link List} List of imports in the current file */ public static List<BLangImportPackage> getCurrentFileImports(BLangPackage pkg, LSContext ctx) { String currentFile = ctx.get(DocumentServiceKeys.RELATIVE_FILE_PATH_KEY); return getCurrentFileTopLevelNodes(pkg, ctx).stream() .filter(topLevelNode -> topLevelNode instanceof BLangImportPackage) .map(topLevelNode -> (BLangImportPackage) topLevelNode) .filter(bLangImportPackage -> bLangImportPackage.pos.getSource().cUnitName.replace("/", FILE_SEPARATOR).equals(currentFile) && !(bLangImportPackage.getOrgName().getValue().equals("ballerina") && getPackageNameComponentsCombined(bLangImportPackage).equals("transaction"))) .collect(Collectors.toList()); }
/** * Gets the alias for a given module from a bLang file root node. * * @param topCompilationUnit The root node. * @param packageName The module 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(".")); packagePath = importPackage.getOrgName().toString() + '/' + packagePath; if (packageName.equals(packagePath)) { return importPackage.getAlias().getValue(); } } } return null; } }
realOrgName = ((BLangImportPackage) bLangImport.get()).getOrgName().getValue(); } else { realPackageName = pkgName;
realOrgName = ((BLangImportPackage) bLangImport.get()).getOrgName().getValue(); } else { realPkgName = pkgName;