@NotNull
  static List<HighlightInfo> checkDuplicateRequires(@NotNull PsiJavaModule module) {
    List<HighlightInfo> results = ContainerUtil.newSmartList();

    Map<String, PsiElement> map = ContainerUtil.newHashMap();
    for (PsiElement child = module.getFirstChild(); child != null; child = child.getNextSibling()) {
      if (child instanceof PsiRequiresStatement) {
        PsiJavaModuleReferenceElement ref = ((PsiRequiresStatement) child).getReferenceElement();
        if (ref != null) {
          String text = ref.getReferenceText();
          if (!map.containsKey(text)) {
            map.put(text, child);
          } else {
            String message = JavaErrorMessages.message("module.duplicate.requires", text);
            HighlightInfo info =
                HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR)
                    .range(child)
                    .description(message)
                    .create();
            QuickFixAction.registerQuickFixAction(info, new DeleteElementFix(child));
            results.add(info);
          }
        }
      }
    }

    return results;
  }
Esempio n. 2
0
  public static class DiagnosedRange {
    private final int start;
    private int end;
    private final List<TextDiagnostic> diagnostics = ContainerUtil.newSmartList();

    protected DiagnosedRange(int start) {
      this.start = start;
    }

    public int getStart() {
      return start;
    }

    public int getEnd() {
      return end;
    }

    public List<TextDiagnostic> getDiagnostics() {
      return diagnostics;
    }

    public void setEnd(int end) {
      this.end = end;
    }

    public void addDiagnostic(String diagnostic) {
      diagnostics.add(TextDiagnostic.parseDiagnostic(diagnostic));
    }
  }
  final boolean allowVisitChildren(@NotNull VirtualFile file) {
    if (!file.is(VFileProperty.SYMLINK)) {
      return true;
    }

    if (!myFollowSymLinks || VfsUtilCore.isInvalidLink(file)) {
      return false;
    }

    VirtualFile target = file.getCanonicalFile();
    List<VirtualFile> links = myVisitedTargets.get(target);
    if (links == null) {
      myVisitedTargets.put(target, ContainerUtil.newSmartList(file));
      return true;
    }

    boolean hasLoop = false;
    for (VirtualFile link : links) {
      if (VfsUtilCore.isAncestor(link, file, true)) {
        hasLoop = true;
        break;
      }
    }
    links.add(file);
    return !hasLoop;
  }
Esempio n. 4
0
 @NotNull
 public static PsiMethod[] getConstructors(@NotNull PsiClass aClass) {
   List<PsiMethod> result = null;
   for (PsiMethod method : aClass.getMethods()) {
     if (method.isConstructor()) {
       if (result == null) result = ContainerUtil.newSmartList();
       result.add(method);
     }
   }
   return result == null ? PsiMethod.EMPTY_ARRAY : result.toArray(new PsiMethod[result.size()]);
 }
Esempio n. 5
0
  @Override
  @NotNull
  public VirtualFile[] getLocalRoots() {
    List<VirtualFile> roots = ContainerUtil.newSmartList();

    myRootsLock.readLock().lock();
    try {
      for (NewVirtualFile root : myRoots.values()) {
        if (root.isInLocalFileSystem() && !(root.getFileSystem() instanceof TempFileSystem)) {
          roots.add(root);
        }
      }
    } finally {
      myRootsLock.readLock().unlock();
    }

    return VfsUtilCore.toVirtualFileArray(roots);
  }
  @NotNull
  private Map<String, PsiMethod[]> getMethodsMap() {
    PsiMethod[] methods = getMethods();
    if (methods.length == 0) return Collections.emptyMap();

    Map<String, List<PsiMethod>> collectedMethods = ContainerUtil.newHashMap();
    for (PsiMethod method : methods) {
      List<PsiMethod> list = collectedMethods.get(method.getName());
      if (list == null) {
        collectedMethods.put(method.getName(), list = ContainerUtil.newSmartList());
      }
      list.add(method);
    }

    Map<String, PsiMethod[]> cachedMethods = ContainerUtil.newTroveMap();
    for (Map.Entry<String, List<PsiMethod>> entry : collectedMethods.entrySet()) {
      List<PsiMethod> list = entry.getValue();
      cachedMethods.put(entry.getKey(), list.toArray(new PsiMethod[list.size()]));
    }
    return cachedMethods;
  }
  private static void addGetterSetterElements(
      CompletionResultSet result, PsiClass parent, Set<MethodSignature> addedSignatures) {
    int count = 0;
    for (PsiField field : parent.getFields()) {
      if (field instanceof PsiEnumConstant) continue;

      List<PsiMethod> prototypes = ContainerUtil.newSmartList();
      Collections.addAll(
          prototypes, GetterSetterPrototypeProvider.generateGetterSetters(field, true));
      Collections.addAll(
          prototypes, GetterSetterPrototypeProvider.generateGetterSetters(field, false));
      for (final PsiMethod prototype : prototypes) {
        if (parent.findMethodBySignature(prototype, false) == null
            && addedSignatures.add(prototype.getSignature(PsiSubstitutor.EMPTY))) {
          Icon icon = prototype.getIcon(Iconable.ICON_FLAG_VISIBILITY);
          result.addElement(
              createGenerateMethodElement(
                  prototype,
                  PsiSubstitutor.EMPTY,
                  icon,
                  "",
                  new InsertHandler<LookupElement>() {
                    @Override
                    public void handleInsert(InsertionContext context, LookupElement item) {
                      removeLookupString(context);

                      insertGenerationInfos(
                          context,
                          Collections.singletonList(new PsiGenerationInfo<PsiMethod>(prototype)));
                    }
                  }));

          if (count++ > 100) return;
        }
      }
    }
  }