コード例 #1
0
  @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;
  }
コード例 #2
0
  @Nullable
  static HighlightInfo checkModuleReference(@Nullable PsiJavaModuleReferenceElement refElement) {
    if (refElement != null) {
      PsiPolyVariantReference ref = refElement.getReference();
      assert ref != null : refElement.getParent();
      if (ref.multiResolve(false).length == 0) {
        String message =
            JavaErrorMessages.message("module.ref.unknown", refElement.getReferenceText());
        return HighlightInfo.newHighlightInfo(HighlightInfoType.WRONG_REF)
            .range(refElement)
            .description(message)
            .create();
      }
    }

    return null;
  }