Package com.intellij.openapi.roots

Examples of com.intellij.openapi.roots.ProjectFileIndex


            "-s", sourcePath,
            "--line-number", String.valueOf(coord.line), "--column-number", String.valueOf(coord.column),
            "-f", file.getPath()
        );
        final List<String> srcFiles = new ArrayList<String>();
        ProjectFileIndex fileIndex = ProjectRootManager.getInstance(module.getProject()).getFileIndex();
        fileIndex.iterateContent(new ContentIterator() {
            public boolean processFile(VirtualFile virtualFile) {
                if (HaskellCompiler.isCompilableFile(virtualFile)) {
                    srcFiles.add(virtualFile.getPath());
                }
                return true;
View Full Code Here


            if (declaration == null)
                return;
            LineCol coord = declaration.coord;
            VirtualFile virtualFile = file.getVirtualFile();
            Project project = file.getProject();
            ProjectFileIndex fileIndex = ProjectRootManager.getInstance(project).getFileIndex();
            if (virtualFile == null)
                return;
            Module module = fileIndex.getModuleForFile(virtualFile);
            CompilerLocation compiler = CompilerLocation.get(module);
            if (compiler == null)
                return;
            List<String> args = compiler.getCompileOptionsList(
                "-m", "FindUsages",
                "-s", GHCUtil.rootsAsString(module, false),
                "--line-number", String.valueOf(coord.line), "--column-number", String.valueOf(coord.column),
                "-f", virtualFile.getPath()
            );
            final List<String> srcFiles = new ArrayList<String>();
            fileIndex.iterateContent(new ContentIterator() {
                public boolean processFile(VirtualFile virtualFile) {
                    if (HaskellCompiler.isCompilableFile(virtualFile)) {
                        srcFiles.add(virtualFile.getPath());
                    }
                    return true;
View Full Code Here


  @Nullable
  public static Module getModuleForFile(@NotNull final VirtualFile virtualFile, final Project project) {
    final ProjectRootManager projectRootManager = ProjectRootManager.getInstance(project);
    final ProjectFileIndex projectFileIndex = projectRootManager.getFileIndex();

    return projectFileIndex.getModuleForFile(virtualFile);
  }
View Full Code Here

    }

    final VirtualFile[] virtualFiles = PlatformDataKeys.VIRTUAL_FILE_ARRAY.getData(dataContext);
    final Project project = PlatformDataKeys.PROJECT.getData(dataContext);
    if (virtualFiles != null && project != null) { //analyze on selection
      final ProjectFileIndex fileIndex = ProjectRootManager.getInstance(project).getFileIndex();
      if (virtualFiles.length == 1) {
        final PsiDirectory psiDirectory = PsiManager.getInstance(project).findDirectory(virtualFiles[0]);
        if (psiDirectory != null && (acceptNonProjectDirectories() || psiDirectory.getManager().isInProject(psiDirectory))) {
          return new AnalysisScope(psiDirectory);
        }
      }
      final Set<VirtualFile> files = new HashSet<VirtualFile>();
      for (VirtualFile vFile : virtualFiles) {
        if (fileIndex.isInContent(vFile)) {
          if (vFile instanceof VirtualFileWindow) {
            files.add(vFile);
            vFile = ((VirtualFileWindow)vFile).getDelegate();
          }
          collectFilesUnder(vFile, files);
View Full Code Here

        public PrepareAction(CompileContext context) {
            this.context = context;
        }

        public GenerationItem[] compute() {
            ProjectFileIndex fileIndex = ProjectRootManager.getInstance(context.getProject()).getFileIndex();
            CompileScope compileScope = context.getCompileScope();
            VirtualFile[] files = compileScope.getFiles(JFlexFileType.FILE_TYPE, false);
            List<GenerationItem> items = new ArrayList<GenerationItem>(files.length);
            CompilerConfiguration compilerConfiguration = CompilerConfiguration.getInstance(context.getProject());
            for (VirtualFile file : files) {
                if (context.isMake() && compilerConfiguration.isExcludedFromCompilation(file)) {
                    continue;
                }
                JFlexGenerationItem generationItem = new JFlexGenerationItem(context.getModuleByFile(file), file, fileIndex.isInTestSourceContent(file));
                if (context.isMake()) {
                    File generatedFile = generationItem.getGeneratedFile();
                    if (!generatedFile.exists() || generatedFile.lastModified() <= file.getTimeStamp()) {
                        items.add(generationItem);
                    }
View Full Code Here

        // get all fileMatchers
        final List<AlternateFileMatcher> fileMatchers = getFileMatchers(configuration, currentFilename);
        if (!fileMatchers.isEmpty()) {
            // iterate thru files
            final ProjectFileIndex projectFileIndex = ProjectRootManager.getInstance(project).getFileIndex();
            projectFileIndex.iterateContent(new ContentIterator() {
                private PsiManager psiManager = PsiManager.getInstance(project);
                public boolean processFile(VirtualFile fileOrDir) {
                    // if not a directory
                    if (!fileOrDir.isDirectory()) {
                        // and not currentFile...
                        if (!currentFilename.equals(fileOrDir.getName()) || !currentFile.getPath().equals(fileOrDir.getPath())) {
                            // iterate thru matchers and test...
                            for (AlternateFileMatcher fileMatcher : fileMatchers) {
                                if (fileMatcher.matches(fileOrDir.getName())) {
                                    PsiFile psiFile = psiManager.findFile(fileOrDir);
                                    if (psiFile != null) {
                                        Map<String, AlternateFileGroup> workMap = module.equals(projectFileIndex.getModuleForFile(fileOrDir)) ? moduleWorkMap : projectWorkMap;
                                        // add to module or project group
                                        String baseFilename = fileMatcher.getBaseFilename(fileOrDir.getName());
                                        String groupId = groupId(baseFilename);
                                        AlternateFileGroup group = workMap.get(groupId);
                                        if (group == null) {
View Full Code Here

    /**
     * @param vf
     * @return true if file is in library
     */
    public static boolean isInLibrary(@NotNull VirtualFile vf, @NotNull Project project) {
        ProjectFileIndex projectFileIndex = ProjectRootManager.getInstance(project).getFileIndex();
        return projectFileIndex.isInLibrarySource(vf) || projectFileIndex.isInLibraryClasses(vf);
    }
View Full Code Here

        final IdeView view = e.getData(DataKeys.IDE_VIEW);
        if (view != null) {
            final Module module = e.getData(DataKeys.MODULE);
            // let user create page/panel when we have a wicket-lib (so we can detect new facet)
            if (module != null && WicketForgeFacet.isLibraryPresent(module)) {
                ProjectFileIndex projectFileIndex = ProjectRootManager.getInstance(module.getProject()).getFileIndex();
                for (PsiDirectory dir : view.getDirectories()) {
                    if (projectFileIndex.isInSourceContent(dir.getVirtualFile()) && JavaDirectoryService.getInstance().getPackage(dir) != null) {
                        return true;
                    }
                }
            }
        }
View Full Code Here

                                                  @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;

    VirtualFile[] sourceRoots = rootManager.getContentSourceRoots();
    VirtualFile[] contentRoots = rootManager.getContentRoots();
    final VirtualFile virtualRoot = existingFileRoot != null ? existingFileRoot :
                                    hasPackage && fileIndex.isInSource(sourceFile) ? fileIndex.getSourceRootForFile(sourceFile) :
                                    fileIndex.isInContent(sourceFile) ? fileIndex.getContentRootForFile(sourceFile) :
                                    getFirstElement(hasPackage && sourceRoots.length > 0? sourceRoots : contentRoots);
    if (virtualRoot == null) {
      fail(project, sourceFile, "Unable to guess target source root");
      throw new ProcessCanceledException();
    }
    try {
      boolean newGenRoot = !fileIndex.isInSourceContent(virtualRoot);
      final String relativePath = (hasPackage && newGenRoot? "gen." + targetPackage :
                                  hasPackage ? targetPackage :
                                  newGenRoot ? "gen" : "").replace('.', '/');
      if (relativePath.isEmpty()) {
        return virtualRoot;
View Full Code Here

        // Are we on IDE View and under project source folder?
        Project project = e.getData( PlatformDataKeys.PROJECT );
        IdeView view = e.getData( LangDataKeys.IDE_VIEW );
        if( view != null && project != null )
        {
            ProjectFileIndex projectFileIndex = ProjectRootManager.getInstance( project ).getFileIndex();
            PsiDirectory[] dirs = view.getDirectories();
            for( PsiDirectory dir : dirs )
            {
                if( projectFileIndex.isInSourceContent( dir.getVirtualFile() ) && JavaDirectoryService.getInstance().getPackage( dir ) != null )
                {
                    return true;
                }
            }
        }
View Full Code Here

TOP

Related Classes of com.intellij.openapi.roots.ProjectFileIndex

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.