com.intellij.util.indexing.FileBasedIndexImpl Java Examples

The following examples show how to use com.intellij.util.indexing.FileBasedIndexImpl. 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: LaravelLightCodeInsightFixtureTestCase.java    From idea-php-laravel-plugin with MIT License 6 votes vote down vote up
public void assertIndex(@NotNull ID<String, ?> id, boolean notCondition, @NotNull String... keys) {
    for (String key : keys) {

        final Collection<VirtualFile> virtualFiles = new ArrayList<VirtualFile>();

        FileBasedIndexImpl.getInstance().getFilesWithKey(id, new HashSet<String>(Arrays.asList(key)), new Processor<VirtualFile>() {
            @Override
            public boolean process(VirtualFile virtualFile) {
                virtualFiles.add(virtualFile);
                return true;
            }
        }, GlobalSearchScope.allScope(getProject()));

        if(notCondition && virtualFiles.size() > 0) {
            fail(String.format("Fail that ID '%s' not contains '%s'", id.toString(), key));
        } else if(!notCondition && virtualFiles.size() == 0) {
            fail(String.format("Fail that ID '%s' contains '%s'", id.toString(), key));
        }
    }
}
 
Example #2
Source File: DrupalLightCodeInsightFixtureTestCase.java    From idea-php-drupal-symfony2-bridge with MIT License 6 votes vote down vote up
public void assertIndex(@NotNull ID<String, ?> id, boolean notCondition, @NotNull String... keys) {
    for (String key : keys) {

        final Collection<VirtualFile> virtualFiles = new ArrayList<VirtualFile>();

        FileBasedIndexImpl.getInstance().getFilesWithKey(id, new HashSet<String>(Arrays.asList(key)), new Processor<VirtualFile>() {
            @Override
            public boolean process(VirtualFile virtualFile) {
                virtualFiles.add(virtualFile);
                return true;
            }
        }, GlobalSearchScope.allScope(getProject()));

        if(notCondition && virtualFiles.size() > 0) {
            fail(String.format("Fail that ID '%s' not contains '%s'", id.toString(), key));
        } else if(!notCondition && virtualFiles.size() == 0) {
            fail(String.format("Fail that ID '%s' contains '%s'", id.toString(), key));
        }
    }
}
 
Example #3
Source File: ShopwareLightCodeInsightFixtureTestCase.java    From idea-php-shopware-plugin with MIT License 6 votes vote down vote up
public void assertIndex(@NotNull ID<String, ?> id, boolean notCondition, @NotNull String... keys) {
    for (String key : keys) {

        final Collection<VirtualFile> virtualFiles = new ArrayList<VirtualFile>();

        FileBasedIndexImpl.getInstance().getFilesWithKey(id, new HashSet<String>(Arrays.asList(key)), new Processor<VirtualFile>() {
            @Override
            public boolean process(VirtualFile virtualFile) {
                virtualFiles.add(virtualFile);
                return true;
            }
        }, GlobalSearchScope.allScope(getProject()));

        if(notCondition && virtualFiles.size() > 0) {
            fail(String.format("Fail that ID '%s' not contains '%s'", id.toString(), key));
        } else if(!notCondition && virtualFiles.size() == 0) {
            fail(String.format("Fail that ID '%s' contains '%s'", id.toString(), key));
        }
    }
}
 
Example #4
Source File: SnippetUtil.java    From idea-php-shopware-plugin with MIT License 6 votes vote down vote up
/**
 * Snippet target, only use ini files
 */
@NotNull
public static Set<PsiElement> getSnippetNamespaceTargets(@NotNull Project project, @NotNull String namespace) {
    Set<VirtualFile> files = new HashSet<>();

    FileBasedIndexImpl.getInstance().getFilesWithKey(SnippetIndex.KEY, new HashSet<>(Collections.singletonList(namespace)), virtualFile -> {
        if("ini".equalsIgnoreCase(virtualFile.getExtension())) {
            files.add(virtualFile);
        }

        return true;
    }, GlobalSearchScope.allScope(project));

    // we are not allows to resolve inside index process
    PsiManager instance = PsiManager.getInstance(project);

    return files.stream()
        .map(instance::findFile)
        .filter(Objects::nonNull)
        .collect(Collectors.toSet());
}
 
Example #5
Source File: SubscriberIndexUtil.java    From idea-php-shopware-plugin with MIT License 6 votes vote down vote up
@NotNull
public static Collection<ServiceResource> getIndexedBootstrapResources(@NotNull Project project, @NotNull BootstrapResource... bootstrapResources) {
    Collection<ServiceResource> serviceResources = new ArrayList<>();

    for (BootstrapResource bootstrapResource : bootstrapResources) {
        for (Set<String> resources : FileBasedIndexImpl.getInstance().getValues(InitResourceServiceIndex.KEY, bootstrapResource.getText(), GlobalSearchScope.allScope(project))) {
            if(resources == null) {
                continue;
            }

            for (String s : resources) {
                String[] split = s.split(String.valueOf(InitResourceServiceIndex.TRIM_KEY));
                if(split.length < 4) {
                    continue;
                }

                ServiceResource e = new ServiceResource(split[0], split[1], split[2]);
                e.setSignature(split[3]);

                serviceResources.add(e);
            }
        }
    }

    return serviceResources;
}
 
Example #6
Source File: SmartyTemplateLineMarkerProvider.java    From idea-php-shopware-plugin with MIT License 6 votes vote down vote up
public void attachExtends(final SmartyFile smartyFile, final List<GotoRelatedItem> gotoRelatedItems) {

        final String templateName = TemplateUtil.getTemplateName(smartyFile.getProject(), smartyFile.getVirtualFile());
        if(templateName == null) {
            return;
        }

        FileBasedIndexImpl.getInstance().getFilesWithKey(SmartyExtendsStubIndex.KEY, new HashSet<>(Collections.singletonList(templateName)), virtualFile -> {

            PsiFile psiFile = PsiManager.getInstance(smartyFile.getProject()).findFile(virtualFile);
            if(psiFile != null) {
                gotoRelatedItems.add(new RelatedPopupGotoLineMarker.PopupGotoRelatedItem(psiFile, TemplateUtil.getTemplateName(psiFile.getProject(), psiFile.getVirtualFile())).withIcon(PhpIcons.IMPLEMENTED, PhpIcons.IMPLEMENTED));
            }

            return true;
        }, GlobalSearchScope.getScopeRestrictedByFileTypes(GlobalSearchScope.allScope(smartyFile.getProject()), SmartyFileType.INSTANCE));

    }
 
Example #7
Source File: SmartyTemplateLineMarkerProvider.java    From idea-php-shopware-plugin with MIT License 6 votes vote down vote up
private void getImplementedBlocks(final Project project, VirtualFile virtualFile, final Set<VirtualFile> templatePathFiles, int depth) {
    if(templatePathFiles.contains(virtualFile) || depth-- <= 0) {
        return;
    }

    final String templateName = TemplateUtil.getTemplateName(project, virtualFile);
    if(templateName == null) {
        return;
    }

    final int finalDepth = depth;
    FileBasedIndexImpl.getInstance().getFilesWithKey(SmartyExtendsStubIndex.KEY, new HashSet<>(Collections.singletonList(templateName)), virtualFile1 -> {

        templatePathFiles.add(virtualFile1);
        getImplementedBlocks(project, virtualFile1, templatePathFiles, finalDepth);

        return true;
    }, GlobalSearchScope.getScopeRestrictedByFileTypes(GlobalSearchScope.allScope(project), SmartyFileType.INSTANCE));
}
 
Example #8
Source File: DotEnvLightCodeInsightFixtureTestCase.java    From idea-php-dotenv-plugin with MIT License 6 votes vote down vote up
private void assertIndex(@NotNull ID<String, ?> id, boolean notCondition, @NotNull String... keys) {
    for (String key : keys) {
        final Collection<VirtualFile> virtualFiles = new ArrayList<>();

        FileBasedIndexImpl.getInstance().getFilesWithKey(id, new HashSet<>(Collections.singletonList(key)), virtualFile -> {
            virtualFiles.add(virtualFile);
            return true;
        }, GlobalSearchScope.allScope(getProject()));

        if(notCondition && virtualFiles.size() > 0) {
            fail(String.format("Fail that ID '%s' not contains '%s'", id.toString(), key));
        } else if(!notCondition && virtualFiles.size() == 0) {
            fail(String.format("Fail that ID '%s' contains '%s'", id.toString(), key));
        }
    }
}
 
Example #9
Source File: LaravelLightCodeInsightFixtureTestCase.java    From idea-php-laravel-plugin with MIT License 5 votes vote down vote up
public <T> void assertIndexContainsKeyWithValue(@NotNull ID<String, T> id, @NotNull String key, @NotNull IndexValue.Assert<T> tAssert) {
    List<T> values = FileBasedIndexImpl.getInstance().getValues(id, key, GlobalSearchScope.allScope(getProject()));
    for (T t : values) {
        if(tAssert.match(t)) {
            return;
        }
    }

    fail(String.format("Fail that Key '%s' matches on of '%s' values", key, values.size()));
}
 
Example #10
Source File: ShopwareLightCodeInsightFixtureTestCase.java    From idea-php-shopware-plugin with MIT License 5 votes vote down vote up
public <T> void assertIndexContainsKeyWithValue(@NotNull ID<String, T> id, @NotNull String key, @NotNull IndexValue.Assert<T> tAssert) {
    List<T> values = FileBasedIndexImpl.getInstance().getValues(id, key, GlobalSearchScope.allScope(getProject()));
    for (T t : values) {
        if(tAssert.match(t)) {
            return;
        }
    }

    fail(String.format("Fail that Key '%s' matches on of '%s' values", key, values.size()));
}
 
Example #11
Source File: DrupalLightCodeInsightFixtureTestCase.java    From idea-php-drupal-symfony2-bridge with MIT License 5 votes vote down vote up
public <T> void assertIndexContainsKeyWithValue(@NotNull ID<String, T> id, @NotNull String key, @NotNull IndexValue.Assert<T> tAssert) {
    List<T> values = FileBasedIndexImpl.getInstance().getValues(id, key, GlobalSearchScope.allScope(getProject()));
    for (T t : values) {
        if(tAssert.match(t)) {
            return;
        }
    }

    fail(String.format("Fail that Key '%s' matches on of '%s' values", key, values.size()));
}
 
Example #12
Source File: ProjectRootManagerComponent.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
protected void doSynchronizeRoots() {
  if (!myStartupActivityPerformed) return;

  if (myDoLogCachesUpdate) {
    LOG.debug(new Throwable("sync roots"));
  }
  else if (!ApplicationManager.getApplication().isUnitTestMode()) LOG.info("project roots have changed");

  DumbServiceImpl dumbService = DumbServiceImpl.getInstance(myProject);
  if (FileBasedIndex.getInstance() instanceof FileBasedIndexImpl) {
    dumbService.queueTask(new UnindexedFilesUpdater(myProject));
  }
}
 
Example #13
Source File: SmartyTemplateLineMarkerProvider.java    From idea-php-shopware-plugin with MIT License 4 votes vote down vote up
public void attachInclude(final SmartyFile smartyFile, final List<GotoRelatedItem> gotoRelatedItems) {

        final String templateName = TemplateUtil.getTemplateName(smartyFile.getProject(), smartyFile.getVirtualFile());
        if(templateName == null) {
            return;
        }

        FileBasedIndexImpl.getInstance().getFilesWithKey(SmartyIncludeStubIndex.KEY, new HashSet<>(Collections.singletonList(templateName)), virtualFile -> {

            PsiFile psiFile = PsiManager.getInstance(smartyFile.getProject()).findFile(virtualFile);
            if(psiFile != null) {

                for(PsiElement psiElement: getIncludePsiElement(psiFile, templateName)) {
                    gotoRelatedItems.add(new RelatedPopupGotoLineMarker.PopupGotoRelatedItem(psiElement, "Navigate to include").withIcon(PhpIcons.IMPLEMENTED, PhpIcons.IMPLEMENTED));
                }

            }

            return true;
        }, GlobalSearchScope.getScopeRestrictedByFileTypes(GlobalSearchScope.allScope(smartyFile.getProject()), SmartyFileType.INSTANCE));

    }
 
Example #14
Source File: SmartyBlockGoToHandler.java    From idea-php-shopware-plugin with MIT License 4 votes vote down vote up
public void attachIncludeTemplateGoto(final PsiElement sourceElement, final PsiFile psiFile, final List<PsiElement> psiTargets) {

        final String text = sourceElement.getText();

        FileBasedIndexImpl.getInstance().getFilesWithKey(SmartyBlockStubIndex.KEY, new HashSet<>(Collections.singletonList(text)), virtualFile -> {

            if(psiFile.getVirtualFile().equals(virtualFile)) {
                return true;
            }

            PsiFile psiFile1 = PsiManager.getInstance(sourceElement.getProject()).findFile(virtualFile);
            if(psiFile1 != null) {
                psiTargets.addAll(getBlockPsiElement(psiFile1, text));
            }

            return true;
        }, GlobalSearchScope.getScopeRestrictedByFileTypes(GlobalSearchScope.allScope(psiFile.getProject()), SmartyFileType.INSTANCE));


    }
 
Example #15
Source File: LaravelLightCodeInsightFixtureTestCase.java    From idea-php-laravel-plugin with MIT License 4 votes vote down vote up
public void assertIndexContainsKeyWithValue(@NotNull ID<String, String> id, @NotNull String key, @NotNull String value) {
    assertContainsElements(FileBasedIndexImpl.getInstance().getValues(id, key, GlobalSearchScope.allScope(getProject())), value);
}
 
Example #16
Source File: ShopwareLightCodeInsightFixtureTestCase.java    From idea-php-shopware-plugin with MIT License 4 votes vote down vote up
public void assertIndexContainsKeyWithValue(@NotNull ID<String, String> id, @NotNull String key, @NotNull String value) {
    assertContainsElements(FileBasedIndexImpl.getInstance().getValues(id, key, GlobalSearchScope.allScope(getProject())), value);
}
 
Example #17
Source File: DrupalLightCodeInsightFixtureTestCase.java    From idea-php-drupal-symfony2-bridge with MIT License 4 votes vote down vote up
public void assertIndexContainsKeyWithValue(@NotNull ID<String, String> id, @NotNull String key, @NotNull String value) {
    assertContainsElements(FileBasedIndexImpl.getInstance().getValues(id, key, GlobalSearchScope.allScope(getProject())), value);
}