コード例 #1
0
  @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);
  }
コード例 #2
0
 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;
 }
コード例 #3
0
 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);
 }
コード例 #4
0
 @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);
         }
       });
 }
コード例 #5
0
 @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));
 }
コード例 #6
0
 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;
 }
コード例 #7
0
  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();
              }
            });
  }
コード例 #8
0
  @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()]);
  }
コード例 #9
0
 @NotNull
 @Override
 public GlobalSearchScope buildContentScope() {
   return new CoreProjectScopeBuilder.ContentSearchScope(
       myProject, FileIndexFacade.getInstance(myProject));
 }