@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);
  }
 @Override
 public boolean isIgnored(VirtualFile vf) {
   if (Registry.is("ide.hide.excluded.files")) {
     return myExcludedIndex.isExcludedFile(vf);
   } else {
     return myExcludedIndex.isUnderIgnored(vf);
   }
 }
Beispiel #3
0
  @Override
  public boolean contains(@NotNull VirtualFile file) {
    if (file instanceof VirtualFileWindow) return true;

    if (myFileIndex.isInLibraryClasses(file) && !myFileIndex.isInSourceContent(file)) return false;

    return myFileIndex.isInContent(file);
  }
 private boolean checkClassUnderSources(final PsiElement element, final Project project) {
   final PsiFile file = element.getContainingFile();
   if (file != null && file.getVirtualFile() != null) {
     final FileIndexFacade indexFacade = FileIndexFacade.getInstance(project);
     final VirtualFile vf = file.getVirtualFile();
     return indexFacade.isInSource(vf) || indexFacade.isInSourceContent(vf);
   }
   return false;
 }
  public static boolean isClassEquivalentTo(@NotNull PsiClass aClass, PsiElement another) {
    if (aClass == another) return true;
    if (!(another instanceof PsiClass)) return false;
    String name1 = aClass.getName();
    if (name1 == null) return false;
    if (!another.isValid()) return false;
    String name2 = ((PsiClass) another).getName();
    if (name2 == null) return false;
    if (name1.hashCode() != name2.hashCode()) return false;
    if (!name1.equals(name2)) return false;
    String qName1 = aClass.getQualifiedName();
    String qName2 = ((PsiClass) another).getQualifiedName();
    if (qName1 == null || qName2 == null) {
      //noinspection StringEquality
      if (qName1 != qName2) return false;

      if (aClass instanceof PsiTypeParameter && another instanceof PsiTypeParameter) {
        PsiTypeParameter p1 = (PsiTypeParameter) aClass;
        PsiTypeParameter p2 = (PsiTypeParameter) another;

        return p1.getIndex() == p2.getIndex()
            && aClass.getManager().areElementsEquivalent(p1.getOwner(), p2.getOwner());
      } else {
        return false;
      }
    }
    if (qName1.hashCode() != qName2.hashCode() || !qName1.equals(qName2)) {
      return false;
    }

    if (originalElement(aClass).equals(originalElement((PsiClass) another))) {
      return true;
    }

    final PsiFile file1 = aClass.getContainingFile().getOriginalFile();
    final PsiFile file2 = another.getContainingFile().getOriginalFile();

    // see com.intellij.openapi.vcs.changes.PsiChangeTracker
    // see com.intellij.psi.impl.PsiFileFactoryImpl#createFileFromText(CharSequence,PsiFile)
    final PsiFile original1 = file1.getUserData(PsiFileFactory.ORIGINAL_FILE);
    final PsiFile original2 = file2.getUserData(PsiFileFactory.ORIGINAL_FILE);
    if (original1 == original2 && original1 != null
        || original1 == file2
        || original2 == file1
        || file1 == file2) {
      return compareClassSeqNumber(aClass, (PsiClass) another);
    }

    final FileIndexFacade fileIndex =
        ServiceManager.getService(file1.getProject(), FileIndexFacade.class);
    final VirtualFile vfile1 = file1.getViewProvider().getVirtualFile();
    final VirtualFile vfile2 = file2.getViewProvider().getVirtualFile();
    boolean lib1 = fileIndex.isInLibraryClasses(vfile1);
    boolean lib2 = fileIndex.isInLibraryClasses(vfile2);

    return (fileIndex.isInSource(vfile1) || lib1) && (fileIndex.isInSource(vfile2) || lib2);
  }
 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);
 }
  @Override
  public boolean isInProject(@NotNull PsiElement element) {
    PsiFile file = element.getContainingFile();
    if (file != null
        && file.isPhysical()
        && file.getViewProvider().getVirtualFile() instanceof LightVirtualFile) return true;

    if (element instanceof PsiDirectoryContainer) {
      PsiDirectory[] dirs = ((PsiDirectoryContainer) element).getDirectories();
      for (PsiDirectory dir : dirs) {
        if (!isInProject(dir)) return false;
      }
      return true;
    }

    VirtualFile virtualFile = null;
    if (file != null) {
      virtualFile = file.getViewProvider().getVirtualFile();
    } else if (element instanceof PsiFileSystemItem) {
      virtualFile = ((PsiFileSystemItem) element).getVirtualFile();
    }

    if (virtualFile != null) {
      return myExcludedFileIndex.isInContent(virtualFile);
    }
    return false;
  }
 @NotNull
 private static Collection<VirtualFile> filterOutIgnored(
     @NotNull Project project, @NotNull Collection<VirtualFile> files) {
   final ChangeListManager changeListManager = ChangeListManager.getInstance(project);
   final FileIndexFacade fileIndex = FileIndexFacade.getInstance(project);
   return ContainerUtil.filter(
       files,
       new Condition<VirtualFile>() {
         @Override
         public boolean value(VirtualFile file) {
           return !changeListManager.isIgnoredFile(file) && !fileIndex.isExcludedFile(file);
         }
       });
 }
 @NotNull
 @Override
 public GlobalSearchScope buildProjectScope() {
   final ProjectRootManager projectRootManager = ProjectRootManager.getInstance(myProject);
   if (projectRootManager == null) {
     return new EverythingGlobalScope(myProject) {
       @Override
       public boolean isSearchInLibraries() {
         return false;
       }
     };
   }
   return new ProjectScopeImpl(myProject, FileIndexFacade.getInstance(myProject));
 }
 private boolean hasFilesOutOfProjectRoots() {
   if (myHasFilesOutOfProjectRoots == null) {
     myHasFilesOutOfProjectRoots = false;
     Project project = getProject();
     if (project != null && !project.isDefault()) {
       for (VirtualFile file : myFiles) {
         if (FileIndexFacade.getInstance(project).getModuleForFile(file) == null) {
           myHasFilesOutOfProjectRoots = true;
           break;
         }
       }
     }
   }
   return myHasFilesOutOfProjectRoots;
 }
  void handleCommitWithoutPsi(@NotNull Document document) {
    final Pair<CharSequence, Long> prevPair = myLastCommittedTexts.remove(document);
    if (prevPair == null) {
      return;
    }

    if (!myProject.isInitialized() || myProject.isDisposed()) {
      return;
    }

    myUncommittedDocuments.remove(document);

    VirtualFile virtualFile = FileDocumentManager.getInstance().getFile(document);
    if (virtualFile == null || !FileIndexFacade.getInstance(myProject).isInContent(virtualFile)) {
      return;
    }

    final PsiFile psiFile = getPsiFile(document);
    if (psiFile == null) {
      return;
    }

    // we can end up outside write action here if the document has forUseInNonAWTThread=true
    ApplicationManager.getApplication()
        .runWriteAction(
            new ExternalChangeAction() {
              @Override
              public void run() {
                psiFile.getViewProvider().beforeContentsSynchronized();
                synchronized (PsiLock.LOCK) {
                  final int oldLength = prevPair.first.length();
                  PsiManagerImpl manager = (PsiManagerImpl) psiFile.getManager();
                  BlockSupportImpl.sendBeforeChildrenChangeEvent(manager, psiFile, true);
                  BlockSupportImpl.sendBeforeChildrenChangeEvent(manager, psiFile, false);
                  if (psiFile instanceof PsiFileImpl) {
                    ((PsiFileImpl) psiFile).onContentReload();
                  }
                  BlockSupportImpl.sendAfterChildrenChangedEvent(
                      manager, psiFile, oldLength, false);
                  BlockSupportImpl.sendAfterChildrenChangedEvent(manager, psiFile, oldLength, true);
                }
                psiFile.getViewProvider().contentsSynchronized();
              }
            });
  }
  @NotNull
  @Override
  public PsiClass[] getClasses(@NotNull PsiDirectory dir) {
    LOG.assertTrue(dir.isValid());

    boolean onlyCompiled =
        FileIndexFacade.getInstance(dir.getProject()).isInLibraryClasses(dir.getVirtualFile());

    List<PsiClass> classes = null;
    for (PsiFile file : dir.getFiles()) {
      if (onlyCompiled && !(file instanceof ClsFileImpl)) {
        continue;
      }
      if (file instanceof PsiClassOwner && file.getViewProvider().getLanguages().size() == 1) {
        PsiClass[] psiClasses = ((PsiClassOwner) file).getClasses();
        if (psiClasses.length == 0) continue;
        if (classes == null) classes = new ArrayList<PsiClass>();
        ContainerUtil.addAll(classes, psiClasses);
      }
    }
    return classes == null ? PsiClass.EMPTY_ARRAY : classes.toArray(new PsiClass[classes.size()]);
  }
 @NotNull
 @Override
 public GlobalSearchScope buildContentScope() {
   return new CoreProjectScopeBuilder.ContentSearchScope(
       myProject, FileIndexFacade.getInstance(myProject));
 }