Java Code Examples for com.intellij.openapi.roots.ProjectFileIndex#isInSourceContent()

The following examples show how to use com.intellij.openapi.roots.ProjectFileIndex#isInSourceContent() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PackageFileAction.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Nonnull
private static List<VirtualFile> getFilesToPackage(@Nonnull AnActionEvent e, @Nonnull Project project) {
  final VirtualFile[] files = e.getData(PlatformDataKeys.VIRTUAL_FILE_ARRAY);
  if (files == null) return Collections.emptyList();

  List<VirtualFile> result = new ArrayList<VirtualFile>();
  ProjectFileIndex fileIndex = ProjectRootManager.getInstance(project).getFileIndex();
  final CompilerManager compilerManager = CompilerManager.getInstance(project);
  for (VirtualFile file : files) {
    if (file == null || file.isDirectory() ||
        fileIndex.isInSourceContent(file) && compilerManager.isCompilableFileType(file.getFileType())) {
      return Collections.emptyList();
    }
    final Collection<? extends Artifact> artifacts = ArtifactBySourceFileFinder.getInstance(project).findArtifacts(file);
    for (Artifact artifact : artifacts) {
      if (!StringUtil.isEmpty(artifact.getOutputPath())) {
        result.add(file);
        break;
      }
    }
  }
  return result;
}
 
Example 2
Source File: MakeUtil.java    From consulo with Apache License 2.0 6 votes vote down vote up
public static VirtualFile getSourceRoot(CompileContext context, Module module, VirtualFile file) {
  final ProjectFileIndex fileIndex = ProjectRootManager.getInstance(module.getProject()).getFileIndex();
  final VirtualFile root = fileIndex.getSourceRootForFile(file);
  if (root != null) {
    return root;
  }
  // try to find among roots of generated files.
  final VirtualFile[] sourceRoots = context.getSourceRoots(module);
  for (final VirtualFile sourceRoot : sourceRoots) {
    if (fileIndex.isInSourceContent(sourceRoot)) {
      continue; // skip content source roots, need only roots for generated files
    }
    if (VfsUtil.isAncestor(sourceRoot, file, false)) {
      return sourceRoot;
    }
  }
  return null;
}
 
Example 3
Source File: DocCommentProcessor.java    From markdown-doclet with GNU General Public License v3.0 6 votes vote down vote up
public DocCommentProcessor(PsiFile file) {
    this.file = file;
    if ( file == null ) {
        project = null;
        markdownOptions = null;
        psiElementFactory = null;
    }
    else {
        project = file.getProject();
        psiElementFactory = JavaPsiFacade.getInstance(project).getElementFactory();
        ProjectFileIndex fileIndex = ProjectRootManager.getInstance(project).getFileIndex();
        Module module = fileIndex.getModuleForFile(file.getVirtualFile());
        if ( module == null ) {
            markdownOptions = null;
        }
        else if ( !fileIndex.isInSourceContent(file.getVirtualFile()) ) {
            markdownOptions = null;
        }
        else if ( !Plugin.moduleConfiguration(module).isMarkdownEnabled() ) {
            markdownOptions = null;
        }
        else {
            markdownOptions = Plugin.moduleConfiguration(module).getRenderingOptions();
        }
    }
}
 
Example 4
Source File: PolygeneCreateActionGroup.java    From attic-polygene-java with Apache License 2.0 5 votes vote down vote up
private boolean shouldActionGroupVisible( AnActionEvent e )
    {
        Module module = e.getData( LangDataKeys.MODULE );
        if( module == null )
        {
            return false;
        }

        // TODO: Enable this once PolygeneFacet can be automatically added/removed
//        if( PolygeneFacet.getInstance( module ) == null )
//        {
//            return false;
//        }

        // 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;
                }
            }
        }

        return false;
    }
 
Example 5
Source File: CompileAction.java    From consulo with Apache License 2.0 5 votes vote down vote up
private static VirtualFile[] getCompilableFiles(Project project, VirtualFile[] files) {
  if (files == null || files.length == 0) {
    return VirtualFile.EMPTY_ARRAY;
  }
  final PsiManager psiManager = PsiManager.getInstance(project);
  final ProjectFileIndex fileIndex = ProjectRootManager.getInstance(project).getFileIndex();
  final CompilerManager compilerManager = CompilerManager.getInstance(project);
  final List<VirtualFile> filesToCompile = new ArrayList<VirtualFile>();
  for (final VirtualFile file : files) {
    if (!fileIndex.isInSourceContent(file)) {
      continue;
    }
    if (!file.isInLocalFileSystem()) {
      continue;
    }
    if (file.isDirectory()) {
      final PsiDirectory directory = psiManager.findDirectory(file);
      if (directory == null || PsiPackageManager.getInstance(project).findAnyPackage(directory) == null) {
        continue;
      }
    }
    else {
      FileType fileType = file.getFileType();
      if (!(compilerManager.isCompilableFileType(fileType) || isCompilableResourceFile(project, file))) {
        continue;
      }
    }
    filesToCompile.add(file);
  }
  return VfsUtil.toVirtualFileArray(filesToCompile);
}
 
Example 6
Source File: PackagesPaneSelectInTarget.java    From consulo with Apache License 2.0 5 votes vote down vote up
private boolean canSelect(final VirtualFile vFile) {
  if (vFile != null && vFile.isValid()) {
    final ProjectFileIndex fileIndex = ProjectRootManager.getInstance(myProject).getFileIndex();
    return fileIndex.isInSourceContent(vFile) || isInLibraryContentOnly(vFile);
  }
  else {
    return false;
  }
}
 
Example 7
Source File: PackagesPaneSelectInTarget.java    From consulo with Apache License 2.0 5 votes vote down vote up
private boolean isInLibraryContentOnly(final VirtualFile vFile) {
  if (vFile == null) {
    return false;
  }
  ProjectFileIndex projectFileIndex = ProjectRootManager.getInstance(myProject).getFileIndex();
  return (projectFileIndex.isInLibraryClasses(vFile) || projectFileIndex.isInLibrarySource(vFile)) && !projectFileIndex.isInSourceContent(vFile);
}
 
Example 8
Source File: CppSupportLoader.java    From CppTools with Apache License 2.0 5 votes vote down vote up
public static boolean isInSource(VirtualFile virtualFile, ProjectFileIndex fileIndex) {
  if (fileIndex.isInSourceContent(virtualFile)) {
    return !fileIndex.isInTestSourceContent(virtualFile) &&
      fileIndex.getModuleForFile(virtualFile) != null;
  } else if (!EnvironmentFacade.isJavaIde()) {
    return fileIndex.getModuleForFile(virtualFile) != null;
  }
  return false;
}
 
Example 9
Source File: ProjectRootsUtil.java    From consulo with Apache License 2.0 4 votes vote down vote up
public static boolean isInSource(final VirtualFile directoryFile, final Project project) {
  final ProjectFileIndex projectFileIndex = ProjectRootManager.getInstance(project).getFileIndex();
  return projectFileIndex.isInSourceContent(directoryFile);
}
 
Example 10
Source File: PsiFileReferenceHelper.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
public boolean isMine(final Project project, @Nonnull final VirtualFile file) {
  final ProjectFileIndex index = ProjectRootManager.getInstance(project).getFileIndex();
  return index.isInSourceContent(file);
}
 
Example 11
Source File: CreateTemplateInPackageAction.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
protected boolean isAvailable(final DataContext dataContext) {
  final Project project = dataContext.getData(CommonDataKeys.PROJECT);
  final IdeView view = dataContext.getData(LangDataKeys.IDE_VIEW);
  if (project == null || view == null || view.getDirectories().length == 0) {
    return false;
  }

  final Module module = dataContext.getData(LangDataKeys.MODULE);
  if (module == null) {
    return false;
  }

  final Class moduleExtensionClass = getModuleExtensionClass();
  if (moduleExtensionClass != null && ModuleUtilCore.getExtension(module, moduleExtensionClass) == null) {
    return false;
  }

  if (!myInSourceOnly) {
    return true;
  }

  PsiPackageSupportProvider[] extensions = PsiPackageSupportProvider.EP_NAME.getExtensions();

  ProjectFileIndex projectFileIndex = ProjectRootManager.getInstance(project).getFileIndex();
  for (PsiDirectory dir : view.getDirectories()) {
    boolean accepted = false;
    for (PsiPackageSupportProvider provider : extensions) {
      if (provider.acceptVirtualFile(module, dir.getVirtualFile())) {
        accepted = true;
        break;
      }
    }

    if (accepted && projectFileIndex.isInSourceContent(dir.getVirtualFile()) && checkPackageExists(dir)) {
      return true;
    }
  }

  return false;
}