@Nullable
  private PsiClass mapClass(@NotNull PsiClass psiClass) {
    String qualifiedName = psiClass.getQualifiedName();
    if (qualifiedName == null) {
      return psiClass;
    }

    PsiFile file = psiClass.getContainingFile();
    if (file == null || !file.getViewProvider().isPhysical()) {
      return psiClass;
    }

    final VirtualFile vFile = file.getVirtualFile();
    if (vFile == null) {
      return psiClass;
    }

    final FileIndexFacade index = FileIndexFacade.getInstance(file.getProject());
    if (!index.isInSource(vFile)
        && !index.isInLibrarySource(vFile)
        && !index.isInLibraryClasses(vFile)) {
      return psiClass;
    }

    return JavaPsiFacade.getInstance(psiClass.getProject())
        .findClass(qualifiedName, myResolveScope);
  }
 private FileScope(@NotNull Project project, @Nullable VirtualFile virtualFile) {
   super(project);
   myVirtualFile = virtualFile;
   final FileIndexFacade facade = FileIndexFacade.getInstance(project);
   myModule =
       virtualFile == null || project.isDefault() ? null : facade.getModuleForFile(virtualFile);
   mySearchOutsideContent =
       virtualFile != null
           && myModule == null
           && !facade.isInLibraryClasses(virtualFile)
           && !facade.isInLibrarySource(virtualFile);
 }