Search in sources :

Example 1 with ProjectFileIndex

use of com.intellij.openapi.roots.ProjectFileIndex in project intellij-community by JetBrains.

the class IndexedRelevantResource method getResources.

public static <K, V extends Comparable> List<IndexedRelevantResource<K, V>> getResources(ID<K, V> indexId, final K key, @Nullable final Module module, @NotNull Project project, @Nullable final GlobalSearchScope additionalScope) {
    if (project.isDefault())
        return Collections.emptyList();
    final ArrayList<IndexedRelevantResource<K, V>> resources = new ArrayList<>();
    final ProjectFileIndex fileIndex = ProjectRootManager.getInstance(project).getFileIndex();
    FileBasedIndex.getInstance().processValues(indexId, key, null, new FileBasedIndex.ValueProcessor<V>() {

        @Override
        public boolean process(VirtualFile file, V value) {
            ResourceRelevance relevance = ResourceRelevance.getRelevance(file, module, fileIndex, additionalScope);
            resources.add(new IndexedRelevantResource<>(file, key, value, relevance));
            return true;
        }
    }, new AdditionalIndexedRootsScope(GlobalSearchScope.allScope(project)));
    return resources;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ProjectFileIndex(com.intellij.openapi.roots.ProjectFileIndex) ArrayList(java.util.ArrayList) AdditionalIndexedRootsScope(com.intellij.util.indexing.AdditionalIndexedRootsScope) FileBasedIndex(com.intellij.util.indexing.FileBasedIndex)

Example 2 with ProjectFileIndex

use of com.intellij.openapi.roots.ProjectFileIndex in project intellij-community by JetBrains.

the class MavenActionUtil method getMavenProjects.

public static List<MavenProject> getMavenProjects(DataContext context) {
    Project project = CommonDataKeys.PROJECT.getData(context);
    if (project == null)
        return Collections.emptyList();
    VirtualFile[] virtualFiles = CommonDataKeys.VIRTUAL_FILE_ARRAY.getData(context);
    if (virtualFiles == null || virtualFiles.length == 0)
        return Collections.emptyList();
    MavenProjectsManager projectsManager = MavenProjectsManager.getInstance(project);
    if (!projectsManager.isMavenizedProject())
        return Collections.emptyList();
    Set<MavenProject> res = new LinkedHashSet<>();
    ProjectFileIndex fileIndex = ProjectRootManager.getInstance(project).getFileIndex();
    for (VirtualFile file : virtualFiles) {
        MavenProject mavenProject;
        if (file.isDirectory()) {
            VirtualFile contentRoot = fileIndex.getContentRootForFile(file);
            if (!file.equals(contentRoot))
                return Collections.emptyList();
            Module module = fileIndex.getModuleForFile(file);
            if (module == null || !projectsManager.isMavenizedModule(module))
                return Collections.emptyList();
            mavenProject = projectsManager.findProject(module);
        } else {
            mavenProject = projectsManager.findProject(file);
        }
        if (mavenProject == null)
            return Collections.emptyList();
        res.add(mavenProject);
    }
    return new ArrayList<>(res);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) MavenProject(org.jetbrains.idea.maven.project.MavenProject) Project(com.intellij.openapi.project.Project) MavenProjectsManager(org.jetbrains.idea.maven.project.MavenProjectsManager) MavenProject(org.jetbrains.idea.maven.project.MavenProject) ProjectFileIndex(com.intellij.openapi.roots.ProjectFileIndex) Module(com.intellij.openapi.module.Module)

Example 3 with ProjectFileIndex

use of com.intellij.openapi.roots.ProjectFileIndex in project intellij-community by JetBrains.

the class JavaFxApplicationIconsDialog method doOKAction.

@Override
protected void doOKAction() {
    final ProjectFileIndex index = ProjectRootManager.getInstance(myProject).getFileIndex();
    if (!isValidPath(myPanel.myLinuxIconPath, index, "Linux"))
        return;
    if (!isValidPath(myPanel.myMacIconPath, index, "Mac"))
        return;
    if (!isValidPath(myPanel.myWindowsIconPath, index, "Windows"))
        return;
    super.doOKAction();
}
Also used : ProjectFileIndex(com.intellij.openapi.roots.ProjectFileIndex)

Example 4 with ProjectFileIndex

use of com.intellij.openapi.roots.ProjectFileIndex in project intellij-community by JetBrains.

the class CreateSnapShotAction method hasDirectoryInPackage.

private static boolean hasDirectoryInPackage(final Project project, final IdeView view) {
    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;
}
Also used : ProjectFileIndex(com.intellij.openapi.roots.ProjectFileIndex)

Example 5 with ProjectFileIndex

use of com.intellij.openapi.roots.ProjectFileIndex in project intellij-community by JetBrains.

the class Generator method createBeanClass.

@NotNull
private static PsiClass createBeanClass(final WizardData wizardData) throws MyException {
    final PsiManager psiManager = PsiManager.getInstance(wizardData.myProject);
    final ProjectRootManager projectRootManager = ProjectRootManager.getInstance(wizardData.myProject);
    final ProjectFileIndex fileIndex = projectRootManager.getFileIndex();
    final VirtualFile sourceRoot = fileIndex.getSourceRootForFile(wizardData.myFormFile);
    if (sourceRoot == null) {
        throw new MyException(UIDesignerBundle.message("error.form.file.is.not.in.source.root"));
    }
    final PsiDirectory rootDirectory = psiManager.findDirectory(sourceRoot);
    LOG.assertTrue(rootDirectory != null);
    final PsiPackage aPackage = JavaPsiFacade.getInstance(psiManager.getProject()).findPackage(wizardData.myPackageName);
    if (aPackage == null) {
        throw new MyException(UIDesignerBundle.message("error.package.does.not.exist", wizardData.myPackageName));
    }
    PsiDirectory targetDir = null;
    final PsiDirectory[] directories = aPackage.getDirectories();
    for (final PsiDirectory psiDirectory : directories) {
        if (PsiTreeUtil.isAncestor(rootDirectory, psiDirectory, false)) {
            targetDir = psiDirectory;
            break;
        }
    }
    if (targetDir == null) {
        // todo
        throw new MyException(UIDesignerBundle.message("error.cannot.find.package", wizardData.myPackageName));
    }
    //noinspection HardCodedStringLiteral
    final String body = "public class " + wizardData.myShortClassName + "{\n" + "public " + wizardData.myShortClassName + "(){}\n" + "}";
    try {
        PsiFile sourceFile = PsiFileFactory.getInstance(psiManager.getProject()).createFileFromText(wizardData.myShortClassName + ".java", body);
        sourceFile = (PsiFile) targetDir.add(sourceFile);
        final PsiClass beanClass = ((PsiJavaFile) sourceFile).getClasses()[0];
        final ArrayList<String> properties = new ArrayList<>();
        final HashMap<String, String> property2fqClassName = new HashMap<>();
        final FormProperty2BeanProperty[] bindings = wizardData.myBindings;
        for (final FormProperty2BeanProperty binding : bindings) {
            if (binding == null || binding.myBeanProperty == null) {
                continue;
            }
            properties.add(binding.myBeanProperty.myName);
            // todo: handle "casts" ?
            final String propertyClassName = binding.myFormProperty.getComponentPropertyClassName();
            property2fqClassName.put(binding.myBeanProperty.myName, propertyClassName);
        }
        generateBean(beanClass, ArrayUtil.toStringArray(properties), property2fqClassName);
        return beanClass;
    } catch (IncorrectOperationException e) {
        throw new MyException(e.getMessage());
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ProjectFileIndex(com.intellij.openapi.roots.ProjectFileIndex) IncorrectOperationException(com.intellij.util.IncorrectOperationException) ProjectRootManager(com.intellij.openapi.roots.ProjectRootManager) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

ProjectFileIndex (com.intellij.openapi.roots.ProjectFileIndex)164 VirtualFile (com.intellij.openapi.vfs.VirtualFile)124 Module (com.intellij.openapi.module.Module)54 Project (com.intellij.openapi.project.Project)51 Nullable (org.jetbrains.annotations.Nullable)38 PsiDirectory (com.intellij.psi.PsiDirectory)24 NotNull (org.jetbrains.annotations.NotNull)24 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)16 PsiFile (com.intellij.psi.PsiFile)15 ArrayList (java.util.ArrayList)15 IdeView (com.intellij.ide.IdeView)11 OrderEntry (com.intellij.openapi.roots.OrderEntry)10 ProjectRootManager (com.intellij.openapi.roots.ProjectRootManager)7 THashSet (gnu.trove.THashSet)6 PropertiesFile (com.intellij.lang.properties.psi.PropertiesFile)5 AbstractTreeNode (com.intellij.ide.util.treeView.AbstractTreeNode)4 List (java.util.List)4 JSClass (com.intellij.lang.javascript.psi.ecmal4.JSClass)3 Presentation (com.intellij.openapi.actionSystem.Presentation)3 CompilerManager (com.intellij.openapi.compiler.CompilerManager)3