void (@NotNull PsiFile file, @NotNull Consumer<? super @NotNull PsiDocCommentBase> sink) { if (!(file instanceof PsiJavaFile)) return; if (file instanceof PsiCompiledElement) return; String fileName = file.getName(); if (PsiPackage.PACKAGE_INFO_FILE.equals(fileName)) { PsiPackageStatement packageStatement = ((PsiJavaFile)file).getPackageStatement(); if (packageStatement != null) { PsiElement prevElement = PsiTreeUtil.skipWhitespacesBackward(packageStatement); if (prevElement instanceof PsiDocCommentBase) { sink.accept((PsiDocCommentBase)prevElement); } } } else if (PsiJavaModule.MODULE_INFO_FILE.equals(fileName)) { PsiJavaModule module = ((PsiJavaFile)file).getModuleDeclaration(); if (module != null) { collectDocComment(module, sink); } } else { PsiClass[] classes = ((PsiJavaFile)file).getClasses(); for (PsiClass aClass : classes) { collectDocComments(aClass, sink); } } }