예제 #1
0
 private boolean fileInRoots(VirtualFile file) {
   final ProjectFileIndex index = ProjectRootManager.getInstance(myProject).getFileIndex();
   return file != null
       && (index.isInSourceContent(file)
           || index.isInLibraryClasses(file)
           || index.isInLibrarySource(file));
 }
예제 #2
0
 public static boolean isProduction(VirtualFile virtualFile, Project project) {
   if (virtualFile == null) {
     return false;
   }
   final ProjectRootManager rootManager = ProjectRootManager.getInstance(project);
   final ProjectFileIndex fileIndex = rootManager.getFileIndex();
   return fileIndex.isInSourceContent(virtualFile)
       && !fileIndex.isInTestSourceContent(virtualFile);
 }
예제 #3
0
 @Override
 public boolean isInSourceContent(@NotNull final VirtualFile fileOrDir) {
   if (myProjectFileIndex.isInSourceContent(fileOrDir)
       || myProjectFileIndex.isInResource(fileOrDir)) {
     return true;
   }
   if (isUnderRoots(myRootToModuleMap.keySet(), fileOrDir)) {
     return true;
   }
   return false;
 }
예제 #4
0
  public static boolean isInsideProjectSources(AnActionEvent event) {
    ProjectFileIndex projectFileIndex =
        ProjectRootManager.getInstance(event.getProject()).getFileIndex();
    final IdeView view = event.getData(DataKeys.IDE_VIEW);

    for (PsiDirectory dir : view.getDirectories()) {
      if (projectFileIndex.isInSourceContent(dir.getVirtualFile())
          && JavaDirectoryService.getInstance().getPackage(dir) != null) {
        return true;
      }
    }
    return false;
  }
 @Override
 public boolean process(IndexTree.Unit unit) {
   VirtualFile file = PersistentFS.getInstance().findFileById(unit.myFileId);
   if (file == null) {
     return true;
   }
   boolean process =
       isInSourceMode
           ? myProjectIndex.isInSourceContent(file)
           : myProjectIndex.isInLibraryClasses(file);
   if (process) {
     myHierarchyService.processUnit(unit);
     myProcessedSet.set(unit.myFileId);
   }
   return true;
 }
  private boolean toResolve(VirtualFile virtualFile, @NotNull Project project) {
    if (virtualFile != null
        && virtualFile.isValid()
        && project.isInitialized()
        && myProjectFileIndex.isInSourceContent(virtualFile)
        && isSupportedFileType(virtualFile)) {
      return true;
    }

    // else mark it as resolved so we will not have to check it again
    if (virtualFile instanceof VirtualFileWithId) {
      int id = getAbsId(virtualFile);
      fileIsResolved.set(id);
    }

    return false;
  }
예제 #7
0
  @Override
  public boolean contains(VirtualFile file) {
    if (!super.contains(file)) {
      return false;
    }

    if (includeLibraries && StdFileTypes.CLASS == file.getFileType()) {
      return index.isInLibraryClasses(file);
    }

    if (JetPluginUtil.isKtFileInGradleProjectInWrongFolder(file, getProject())) {
      return false;
    }

    return file.getFileType().equals(JetFileType.INSTANCE)
        && (index.isInSourceContent(file) || includeLibraries && index.isInLibrarySource(file));
  }
 private boolean isInScopeOf(DebugProcessImpl debugProcess, String className) {
   final SourcePosition position = getSourcePosition();
   if (position != null) {
     final VirtualFile breakpointFile = position.getFile().getVirtualFile();
     final ProjectFileIndex fileIndex = ProjectRootManager.getInstance(myProject).getFileIndex();
     if (breakpointFile != null && fileIndex.isInSourceContent(breakpointFile)) {
       // apply filtering to breakpoints from content sources only, not for sources attached to
       // libraries
       final Collection<VirtualFile> candidates =
           findClassCandidatesInSourceContent(className, debugProcess.getSearchScope(), fileIndex);
       if (candidates == null) {
         return true;
       }
       for (VirtualFile classFile : candidates) {
         if (breakpointFile.equals(classFile)) {
           return true;
         }
       }
       return false;
     }
   }
   return true;
 }
  @NotNull
  public static VirtualFile getTargetDirectoryFor(
      @NotNull Project project,
      @NotNull VirtualFile sourceFile,
      @Nullable String targetFile,
      @Nullable String targetPackage,
      boolean returnRoot) {
    boolean hasPackage = StringUtil.isNotEmpty(targetPackage);
    ProjectRootManager rootManager = ProjectRootManager.getInstance(project);
    ProjectFileIndex fileIndex = ProjectFileIndex.SERVICE.getInstance(project);
    Collection<VirtualFile> files =
        targetFile == null
            ? Collections.<VirtualFile>emptyList()
            : FilenameIndex.getVirtualFilesByName(
                project, targetFile, ProjectScope.getAllScope(project));

    VirtualFile existingFile = null;
    for (VirtualFile file : files) {
      String existingFilePackage = fileIndex.getPackageNameByDirectory(file.getParent());
      if (!hasPackage || existingFilePackage == null || targetPackage.equals(existingFilePackage)) {
        existingFile = file;
        break;
      }
    }

    VirtualFile existingFileRoot =
        existingFile == null
            ? null
            : fileIndex.isInSourceContent(existingFile)
                ? fileIndex.getSourceRootForFile(existingFile)
                : fileIndex.isInContent(existingFile)
                    ? fileIndex.getContentRootForFile(existingFile)
                    : null;

    boolean preferGenRoot =
        sourceFile.getFileType() == BnfFileType.INSTANCE
            || sourceFile.getFileType() == JFlexFileType.INSTANCE;
    boolean preferSourceRoot = hasPackage && !preferGenRoot;
    VirtualFile[] sourceRoots = rootManager.getContentSourceRoots();
    VirtualFile[] contentRoots = rootManager.getContentRoots();
    final VirtualFile virtualRoot =
        existingFileRoot != null
            ? existingFileRoot
            : preferSourceRoot && fileIndex.isInSource(sourceFile)
                ? fileIndex.getSourceRootForFile(sourceFile)
                : fileIndex.isInContent(sourceFile)
                    ? fileIndex.getContentRootForFile(sourceFile)
                    : getFirstElement(
                        preferSourceRoot && sourceRoots.length > 0 ? sourceRoots : contentRoots);
    if (virtualRoot == null) {
      fail(project, sourceFile, "Unable to guess target source root");
      throw new ProcessCanceledException();
    }
    try {
      String genDirName = Options.GEN_DIR.get();
      boolean newGenRoot = !fileIndex.isInSourceContent(virtualRoot);
      final String relativePath =
          (hasPackage && newGenRoot
                  ? genDirName + "/" + targetPackage
                  : hasPackage ? targetPackage : newGenRoot ? genDirName : "")
              .replace('.', '/');
      if (relativePath.isEmpty()) {
        return virtualRoot;
      } else {
        VirtualFile result =
            new WriteAction<VirtualFile>() {
              @Override
              protected void run(@NotNull Result<VirtualFile> result) throws Throwable {
                result.setResult(VfsUtil.createDirectoryIfMissing(virtualRoot, relativePath));
              }
            }.execute().throwException().getResultObject();
        VfsUtil.markDirtyAndRefresh(false, true, true, result);
        return returnRoot && newGenRoot
            ? ObjectUtils.assertNotNull(virtualRoot.findChild(genDirName))
            : returnRoot ? virtualRoot : result;
      }
    } catch (ProcessCanceledException ex) {
      throw ex;
    } catch (Exception ex) {
      fail(project, sourceFile, ex.getMessage());
      throw new ProcessCanceledException();
    }
  }
예제 #10
0
 public boolean contains(final VirtualFile file) {
   final FileType fileType = file.getFileType();
   return (myDelegate == null || myDelegate.contains(file))
       && (StdFileTypes.JAVA == fileType && myIndex.isInSourceContent(file)
           || StdFileTypes.CLASS == fileType && myIndex.isInLibraryClasses(file));
 }