@Override
  public @NotNull Collection<AbstractTreeNode<?>> modify(@NotNull AbstractTreeNode<?> parent,
                                                         @NotNull Collection<AbstractTreeNode<?>> children,
                                                         ViewSettings settings) {
    List<AbstractTreeNode<?>> result = new ArrayList<>();
    for (AbstractTreeNode<?> child : children) {
      ProgressManager.checkCanceled();

      Object o = child.getValue();
      if (o instanceof PsiClassOwner classOwner && !(o instanceof ServerPageFile)) {
        ViewSettings settings1 = ((ProjectViewNode<?>)parent).getSettings();
        VirtualFile file = classOwner.getVirtualFile();

        if (!(classOwner instanceof PsiCompiledElement)) {
          //do not show duplicated items if jar file contains classes and sources
          ProjectFileIndex fileIndex = ProjectRootManager.getInstance(myProject).getFileIndex();
          if (file != null && fileIndex.isInLibrarySource(file)) {
            PsiElement originalElement = classOwner.getOriginalElement();
            if (originalElement instanceof PsiFile classFile) {
              VirtualFile virtualClassFile = classFile.getVirtualFile();
              if (virtualClassFile != null && fileIndex.isInLibraryClasses(virtualClassFile)
                  && !classOwner.getManager().areElementsEquivalent(classOwner, classFile)
                  && classOwner.getManager().areElementsEquivalent(classOwner.getContainingDirectory(), classFile.getContainingDirectory())) {
                continue;
              }
            }
          }
        }

        if (classOwner instanceof PsiCompiledElement || fileInRoots(file)) {
          PsiClass[] classes = ReadAction.compute(classOwner::getClasses);
          Collection<? extends AbstractTreeNode<?>> nestedFileNodes = child instanceof FileNodeWithNestedFileNodes
                                                                      ? ((FileNodeWithNestedFileNodes)child).getNestedFileNodes()
                                                                      : Collections.emptyList();
          if (classes.length == 1 && isClassForTreeNode(file, classes[0])) {
            result.add(new ClassTreeNode(myProject, classes[0], settings1, nestedFileNodes));
          } else {
            result.add(new PsiClassOwnerTreeNode(classOwner, settings1, nestedFileNodes));
          }
          continue;
        }
      }
      result.add(child);
    }
    return result;
  }
@Override
  public @NotNull Collection<AbstractTreeNode<?>> modify(@NotNull AbstractTreeNode<?> parent,
                                                         @NotNull Collection<AbstractTreeNode<?>> children,
                                                         ViewSettings settings)