Search in sources :

Example 11 with FileBasedIndex

use of com.intellij.util.indexing.FileBasedIndex in project android by JetBrains.

the class ResourceManager method getValueResourceEntries.

@NotNull
public Collection<ResourceEntry> getValueResourceEntries(@NotNull final ResourceType resourceType) {
    final FileBasedIndex index = FileBasedIndex.getInstance();
    final ResourceEntry typeMarkerEntry = AndroidValueResourcesIndex.createTypeMarkerKey(resourceType.getName());
    final GlobalSearchScope scope = GlobalSearchScope.allScope(myProject);
    final Map<VirtualFile, Set<ResourceEntry>> file2resourceSet = new HashMap<VirtualFile, Set<ResourceEntry>>();
    index.processValues(AndroidValueResourcesIndex.INDEX_ID, typeMarkerEntry, null, new FileBasedIndex.ValueProcessor<ImmutableSet<AndroidValueResourcesIndex.MyResourceInfo>>() {

        @Override
        public boolean process(@NotNull VirtualFile file, ImmutableSet<AndroidValueResourcesIndex.MyResourceInfo> infos) {
            for (AndroidValueResourcesIndex.MyResourceInfo info : infos) {
                Set<ResourceEntry> resourcesInFile = file2resourceSet.get(file);
                if (resourcesInFile == null) {
                    resourcesInFile = new HashSet<ResourceEntry>();
                    file2resourceSet.put(file, resourcesInFile);
                }
                resourcesInFile.add(info.getResourceEntry());
            }
            return true;
        }
    }, scope);
    final List<ResourceEntry> result = new ArrayList<ResourceEntry>();
    for (VirtualFile file : getAllValueResourceFiles()) {
        final Set<ResourceEntry> entries = file2resourceSet.get(file);
        if (entries != null) {
            for (ResourceEntry entry : entries) {
                if (isResourcePublic(entry.getType(), entry.getName())) {
                    result.add(entry);
                }
            }
        }
    }
    return result;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) HashSet(com.intellij.util.containers.HashSet) ImmutableSet(com.google.common.collect.ImmutableSet) HashMap(com.intellij.util.containers.HashMap) ImmutableSet(com.google.common.collect.ImmutableSet) ResourceEntry(org.jetbrains.android.util.ResourceEntry) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) AndroidValueResourcesIndex(org.jetbrains.android.AndroidValueResourcesIndex) FileBasedIndex(com.intellij.util.indexing.FileBasedIndex) HashSet(com.intellij.util.containers.HashSet) NotNull(org.jetbrains.annotations.NotNull)

Example 12 with FileBasedIndex

use of com.intellij.util.indexing.FileBasedIndex in project android by JetBrains.

the class ResourceManager method getIds.

@NotNull
public Collection<String> getIds(boolean declarationsOnly) {
    if (myProject.isDisposed()) {
        return Collections.emptyList();
    }
    final GlobalSearchScope scope = GlobalSearchScope.allScope(myProject);
    final FileBasedIndex index = FileBasedIndex.getInstance();
    final Map<VirtualFile, Set<String>> file2idEntries = new HashMap<VirtualFile, Set<String>>();
    index.processValues(AndroidIdIndex.INDEX_ID, AndroidIdIndex.MARKER, null, new FileBasedIndex.ValueProcessor<Set<String>>() {

        @Override
        public boolean process(@NotNull VirtualFile file, Set<String> value) {
            file2idEntries.put(file, value);
            return true;
        }
    }, scope);
    final Set<String> result = new HashSet<String>();
    for (VirtualFile resSubdir : getResourceSubdirsToSearchIds()) {
        for (VirtualFile resFile : resSubdir.getChildren()) {
            final Set<String> idEntries = file2idEntries.get(resFile);
            if (idEntries != null) {
                for (String idEntry : idEntries) {
                    if (idEntry.startsWith("+")) {
                        idEntry = idEntry.substring(1);
                    } else if (declarationsOnly) {
                        continue;
                    }
                    if (isResourcePublic(ResourceType.ID.getName(), idEntry)) {
                        result.add(idEntry);
                    }
                }
            }
        }
    }
    return result;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) HashSet(com.intellij.util.containers.HashSet) ImmutableSet(com.google.common.collect.ImmutableSet) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) HashMap(com.intellij.util.containers.HashMap) FileBasedIndex(com.intellij.util.indexing.FileBasedIndex) HashSet(com.intellij.util.containers.HashSet) NotNull(org.jetbrains.annotations.NotNull)

Example 13 with FileBasedIndex

use of com.intellij.util.indexing.FileBasedIndex in project intellij-plugins by JetBrains.

the class AngularUiRouterDiagramBuilder method getRootPages.

private void getRootPages() {
    final List<VirtualFile> roots = new ArrayList<>();
    Collections.sort(roots, (o1, o2) -> Integer.compare(o2.getUrl().length(), o1.getUrl().length()));
    final Map<PsiFile, AngularNamedItemDefinition> files = new HashMap<>();
    final FileBasedIndex instance = FileBasedIndex.getInstance();
    final Collection<String> keys = instance.getAllKeys(AngularAppIndex.ANGULAR_APP_INDEX, myProject);
    if (keys.isEmpty())
        return;
    final PsiManager psiManager = PsiManager.getInstance(myProject);
    final GlobalSearchScope projectScope = GlobalSearchScope.projectScope(myProject);
    for (String key : keys) {
        instance.processValues(AngularAppIndex.ANGULAR_APP_INDEX, key, null, (file, value) -> {
            final PsiFile psiFile = psiManager.findFile(file);
            if (psiFile != null) {
                files.put(psiFile, value);
            }
            return true;
        }, projectScope);
    }
    for (Map.Entry<PsiFile, AngularNamedItemDefinition> entry : files.entrySet()) {
        final PsiFile file = entry.getKey();
        final String relativeUrl = findPossibleRelativeUrl(roots, file.getVirtualFile());
        // not clear how then it can be part of application
        if (relativeUrl == null)
            continue;
        final Template template = readTemplateFromFile(myProject, relativeUrl, file);
        final String mainModule = entry.getValue().getName();
        final Set<VirtualFile> moduleFiles = getModuleFiles(file, mainModule);
        final RootTemplate rootTemplate = new RootTemplate(mySmartPointerManager.createSmartPsiElementPointer(file), relativeUrl, template, moduleFiles);
        myRootTemplates.put(file.getVirtualFile(), rootTemplate);
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) FileBasedIndex(com.intellij.util.indexing.FileBasedIndex)

Example 14 with FileBasedIndex

use of com.intellij.util.indexing.FileBasedIndex in project intellij-plugins by JetBrains.

the class AngularUiRouterDiagramBuilder method readTemplateFromFile.

@NotNull
static Template readTemplateFromFile(@NotNull Project project, @NotNull String url, PsiElement templateElement) {
    final PsiFile templateFile = templateElement.getContainingFile();
    final Map<String, SmartPsiElementPointer<PsiElement>> placeholders = new HashMap<>();
    final Set<String> placeholdersSet = new HashSet<>();
    final FileBasedIndex instance = FileBasedIndex.getInstance();
    final GlobalSearchScope scope = GlobalSearchScope.fileScope(project, templateFile.getVirtualFile());
    instance.processAllKeys(AngularUiRouterViewsIndex.UI_ROUTER_VIEWS_CACHE_INDEX, view -> {
        placeholdersSet.add(view);
        return true;
    }, scope, null);
    final SmartPointerManager smartPointerManager = SmartPointerManager.getInstance(project);
    for (String key : placeholdersSet) {
        instance.processValues(AngularUiRouterViewsIndex.UI_ROUTER_VIEWS_CACHE_INDEX, key, null, (file, value) -> {
            final JSImplicitElementImpl.Builder builder = new JSImplicitElementImpl.Builder(JSQualifiedNameImpl.fromQualifiedName(key), null);
            final JSOffsetBasedImplicitElement implicitElement = new JSOffsetBasedImplicitElement(builder, (int) value.getStartOffset(), templateFile);
            if (templateElement instanceof PsiFile || PsiTreeUtil.isAncestor(templateElement, implicitElement, false)) {
                placeholders.put(key, smartPointerManager.createSmartPsiElementPointer(implicitElement));
            }
            return true;
        }, scope);
    }
    final Template template = new Template(url, smartPointerManager.createSmartPsiElementPointer(templateElement));
    template.setViewPlaceholders(placeholders);
    return template;
}
Also used : JSImplicitElementImpl(com.intellij.lang.javascript.psi.stubs.impl.JSImplicitElementImpl) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) JSOffsetBasedImplicitElement(com.intellij.lang.javascript.psi.impl.JSOffsetBasedImplicitElement) FileBasedIndex(com.intellij.util.indexing.FileBasedIndex) NotNull(org.jetbrains.annotations.NotNull)

Example 15 with FileBasedIndex

use of com.intellij.util.indexing.FileBasedIndex in project intellij-plugins by JetBrains.

the class AngularJSTemplateCacheReference method resolveInner.

@Override
@Nullable
public PsiElement resolveInner() {
    final FileBasedIndex instance = FileBasedIndex.getInstance();
    final Project project = getElement().getProject();
    final String id = getCanonicalText();
    final Collection<VirtualFile> files = instance.getContainingFiles(AngularTemplateCacheIndex.TEMPLATE_CACHE_INDEX, id, GlobalSearchScope.allScope(project));
    final Ref<PsiElement> result = new Ref<>();
    for (VirtualFile file : files) {
        final PsiFile psiFile = PsiManager.getInstance(project).findFile(file);
        AngularTemplateCacheIndex.processTemplates(psiFile, attribute -> {
            if (id.equals(attribute.getValue())) {
                result.set(attribute.getValueElement());
            }
            return result.isNull();
        });
    }
    return result.get();
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) Ref(com.intellij.openapi.util.Ref) PsiFile(com.intellij.psi.PsiFile) FileBasedIndex(com.intellij.util.indexing.FileBasedIndex) PsiElement(com.intellij.psi.PsiElement) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

FileBasedIndex (com.intellij.util.indexing.FileBasedIndex)18 VirtualFile (com.intellij.openapi.vfs.VirtualFile)12 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)9 NotNull (org.jetbrains.annotations.NotNull)7 PsiFile (com.intellij.psi.PsiFile)4 Project (com.intellij.openapi.project.Project)3 Nullable (org.jetbrains.annotations.Nullable)3 ImmutableSet (com.google.common.collect.ImmutableSet)2 DetectedFrameworkDescription (com.intellij.framework.detection.DetectedFrameworkDescription)2 DetectionExcludesConfiguration (com.intellij.framework.detection.DetectionExcludesConfiguration)2 JSOffsetBasedImplicitElement (com.intellij.lang.javascript.psi.impl.JSOffsetBasedImplicitElement)2 JSImplicitElementImpl (com.intellij.lang.javascript.psi.stubs.impl.JSImplicitElementImpl)2 Module (com.intellij.openapi.module.Module)2 PsiElement (com.intellij.psi.PsiElement)2 XmlFile (com.intellij.psi.xml.XmlFile)2 HashMap (com.intellij.util.containers.HashMap)2 HashSet (com.intellij.util.containers.HashSet)2 THashSet (gnu.trove.THashSet)2 InsertHandler (com.intellij.codeInsight.completion.InsertHandler)1 InsertionContext (com.intellij.codeInsight.completion.InsertionContext)1