@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);
    }
コード例 #2
0
 @NotNull
 public static Set<PsiElement> findRedundantImportIdentifiers(
     @NotNull MultiMap<String, GoImportSpec> importMap) {
   Set<PsiElement> importIdentifiersToDelete = ContainerUtil.newLinkedHashSet();
   for (PsiElement importEntry : importMap.values()) {
     GoImportSpec importSpec = getImportSpec(importEntry);
     if (importSpec != null) {
       String localPackageName = importSpec.getLocalPackageName();
       if (!StringUtil.isEmpty(localPackageName)) {
         if (Comparing.equal(importSpec.getAlias(), localPackageName)) {
           importIdentifiersToDelete.add(importSpec.getIdentifier());
         }
       }
     }
   }
   return importIdentifiersToDelete;
 }
  @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;
  }