IG: anonymous -> lambda
authorBas Leijdekkers <basleijdekkers@gmail.com>
Wed, 26 Oct 2016 16:00:10 +0000 (18:00 +0200)
committerBas Leijdekkers <basleijdekkers@gmail.com>
Thu, 27 Oct 2016 12:57:47 +0000 (14:57 +0200)
plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/packaging/EmptyDirectoryInspection.java

index 2d0f81eb12d50fe10e53a68b0fa40b3fcc1b30c2..4cdf27d7894c652de83e3bbf1cdcf9722ef181a7 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2011-2015 Bas Leijdekkers
+ * Copyright 2011-2016 Bas Leijdekkers
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -19,13 +19,10 @@ import com.intellij.analysis.AnalysisScope;
 import com.intellij.codeInspection.*;
 import com.intellij.codeInspection.reference.RefElement;
 import com.intellij.codeInspection.ui.SingleCheckboxOptionsPanel;
-import com.intellij.openapi.application.Application;
-import com.intellij.openapi.application.ApplicationManager;
+import com.intellij.openapi.application.ReadAction;
 import com.intellij.openapi.project.Project;
-import com.intellij.openapi.roots.ContentIterator;
 import com.intellij.openapi.roots.ProjectFileIndex;
 import com.intellij.openapi.roots.ProjectRootManager;
-import com.intellij.openapi.util.Computable;
 import com.intellij.openapi.vfs.VfsUtilCore;
 import com.intellij.openapi.vfs.VirtualFile;
 import com.intellij.openapi.vfs.VirtualFileManager;
@@ -77,56 +74,40 @@ public class EmptyDirectoryInspection extends BaseGlobalInspection {
     }
     final GlobalSearchScope globalSearchScope = (GlobalSearchScope)searchScope;
     final PsiManager psiManager = PsiManager.getInstance(project);
-    index.iterateContent(new ContentIterator() {
-      @Override
-      public boolean processFile(final VirtualFile fileOrDir) {
-        if (!fileOrDir.isDirectory()) {
-          return true;
-        }
-        if (!globalSearchScope.contains(fileOrDir)) {
-          return true;
-        }
-        if (onlyReportDirectoriesUnderSourceRoots && !index.isInSourceContent(fileOrDir)) {
-          return true;
-        }
-        final VirtualFile[] children = fileOrDir.getChildren();
-        if (children.length != 0) {
-          return true;
-        }
-        final Application application = ApplicationManager.getApplication();
-        final PsiDirectory directory = application.runReadAction(
-          new Computable<PsiDirectory>() {
-            @Override
-            public PsiDirectory compute() {
-              return psiManager.findDirectory(fileOrDir);
-            }
-          });
-        final RefElement refDirectory = context.getRefManager().getReference(directory);
-        if (context.shouldCheck(refDirectory, EmptyDirectoryInspection.this)) {
-          return true;
-        }
-        final String relativePath = getPathRelativeToModule(fileOrDir, project);
-        if (relativePath == null) {
-          return true;
-        }
-        processor.addProblemElement(refDirectory, manager.createProblemDescriptor(InspectionGadgetsBundle.message(
-          "empty.directories.problem.descriptor", relativePath), new EmptyPackageFix(fileOrDir.getUrl(), fileOrDir.getName())));
+    index.iterateContent(fileOrDir -> {
+      if (!fileOrDir.isDirectory()) {
         return true;
       }
+      if (!globalSearchScope.contains(fileOrDir)) {
+        return true;
+      }
+      if (onlyReportDirectoriesUnderSourceRoots && !index.isInSourceContent(fileOrDir)) {
+        return true;
+      }
+      final VirtualFile[] children = fileOrDir.getChildren();
+      if (children.length != 0) {
+        return true;
+      }
+      final PsiDirectory directory = ReadAction.compute(() -> psiManager.findDirectory(fileOrDir));
+      final RefElement refDirectory = context.getRefManager().getReference(directory);
+      if (refDirectory == null || context.shouldCheck(refDirectory, this)) {
+        return true;
+      }
+      final String relativePath = getPathRelativeToModule(fileOrDir, project);
+      if (relativePath == null) {
+        return true;
+      }
+      processor.addProblemElement(refDirectory, manager.createProblemDescriptor(
+        InspectionGadgetsBundle.message("empty.directories.problem.descriptor", relativePath),
+        new EmptyPackageFix(fileOrDir.getUrl(), fileOrDir.getName())));
+      return true;
     });
   }
 
   @Nullable
   private static String getPathRelativeToModule(VirtualFile file, Project project) {
     final ProjectRootManager rootManager = ProjectRootManager.getInstance(project);
-    final Application application = ApplicationManager.getApplication();
-    final VirtualFile[] contentRoots = application.runReadAction(
-      new Computable<VirtualFile[]>() {
-        @Override
-        public VirtualFile[] compute() {
-          return rootManager.getContentRootsFromAllModules();
-        }
-      });
+    final VirtualFile[] contentRoots = ReadAction.compute(() -> rootManager.getContentRootsFromAllModules());
     for (VirtualFile otherRoot : contentRoots) {
       if (VfsUtilCore.isAncestor(otherRoot, file, false)) {
         return VfsUtilCore.getRelativePath(file, otherRoot, '/');