private static boolean allowed(@NotNull GoNamedElement element) { GoFile file = element.getContainingFile(); if (GoPsiImplUtil.builtin(element) || !GoUtil.allowed(file) || GoUtil.isExcludedFile(file)) return false; PsiDirectory directory = file.getContainingDirectory(); if (directory != null) { VirtualFile vFile = directory.getVirtualFile(); if (vFile.getPath().endsWith("go/doc/testdata")) return false; } if (StringUtil.equals(file.getPackageName(), GoConstants.MAIN)) return false; return true; }
@NotNull private ExistingImportData cachedImportData( @NotNull GoNamedElement element, @Nullable ExistingImportData existingValue) { if (existingValue != null) return existingValue; GoFile declarationFile = element.getContainingFile(); String importPath = declarationFile.getImportPath(); GoImportSpec existingImport = myImportedPackages.get(importPath); boolean exists = existingImport != null; boolean isDot = exists && existingImport.isDot(); String alias = existingImport != null ? existingImport.getAlias() : null; return new ExistingImportData(exists, isDot, alias, importPath); }
@NotNull private static Set<String> sortMatching( @NotNull PrefixMatcher matcher, @NotNull Collection<String> names, @NotNull GoFile file) { ProgressManager.checkCanceled(); String prefix = matcher.getPrefix(); if (prefix.isEmpty()) return ContainerUtil.newLinkedHashSet(names); Set<String> packagesWithAliases = ContainerUtil.newHashSet(); for (Map.Entry<String, Collection<GoImportSpec>> entry : file.getImportMap().entrySet()) { for (GoImportSpec spec : entry.getValue()) { String alias = spec.getAlias(); if (spec.isDot() || alias != null) { packagesWithAliases.add(entry.getKey()); break; } } } List<String> sorted = ContainerUtil.newArrayList(); for (String name : names) { if (matcher.prefixMatches(name) || packagesWithAliases.contains(substringBefore(name, '.'))) { sorted.add(name); } } ProgressManager.checkCanceled(); Collections.sort(sorted, String.CASE_INSENSITIVE_ORDER); ProgressManager.checkCanceled(); LinkedHashSet<String> result = new LinkedHashSet<String>(); for (String name : sorted) { if (matcher.isStartMatch(name)) { result.add(name); } } ProgressManager.checkCanceled(); result.addAll(sorted); return result; }