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;
}
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;
}
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);
}
}
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;
}
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();
}
Aggregations