use of com.intellij.util.indexing.FileBasedIndex in project intellij-plugins by JetBrains.
the class LibraryStyleInfoCollector method collectInherited.
private byte[] collectInherited(final VirtualFile jarFile) {
bytes.allocateShort();
final VirtualFile libraryFile = Library.getSwfFile(jarFile);
final FileBasedIndex fileBasedIndex = FileBasedIndex.getInstance();
final GlobalSearchScope searchScope = GlobalSearchScope.fileScope(module.getProject(), libraryFile);
final List<String> dataKeys = new ArrayList<>(32);
fileBasedIndex.processAllKeys(FlexStyleIndex.INDEX_ID, dataKey -> {
dataKeys.add(dataKey);
return true;
}, module.getProject());
final THashSet<String> uniqueGuard = new THashSet<>();
final FileBasedIndex.ValueProcessor<Set<FlexStyleIndexInfo>> processor = (file, value) -> {
final FlexStyleIndexInfo firstInfo = value.iterator().next();
if (firstInfo.getInherit().charAt(0) == 'y' && uniqueGuard.add(firstInfo.getAttributeName())) {
bytes.writeUInt29(stringWriter.getReference(firstInfo.getAttributeName()) - 1);
}
// may not be in a class stylePName be inherited, and another class of the same library not inherited
return false;
};
for (String dataKey : dataKeys) {
fileBasedIndex.processValues(FlexStyleIndex.INDEX_ID, dataKey, libraryFile, processor, searchScope);
}
if (uniqueGuard.isEmpty()) {
return null;
} else {
bytes.putShort(uniqueGuard.size(), 0);
return bytes.getByteArrayOut().toByteArray();
}
}
use of com.intellij.util.indexing.FileBasedIndex in project intellij-plugins by JetBrains.
the class FlexCssElementDescriptorProvider method getPropertyDescriptorsDynamically.
@NotNull
private static Collection<? extends CssPropertyDescriptor> getPropertyDescriptorsDynamically(@NotNull List<CssSimpleSelector> selectors, @NotNull Module module) {
FileBasedIndex fileBasedIndex = FileBasedIndex.getInstance();
GlobalSearchScope scope = module.getModuleWithDependenciesAndLibrariesScope(false);
Set<JSClass> visited = ContainerUtil.newLinkedHashSet();
Set<CssPropertyDescriptor> result = ContainerUtil.newLinkedHashSet();
Project project = module.getProject();
for (CssSimpleSelector selector : selectors) {
final JSClass jsClass = getClassFromMxmlDescriptor(selector, module);
if (jsClass != null) {
fillPropertyDescriptorsDynamically(jsClass, visited, result);
continue;
}
final String shortClassName = selector.getElementName();
Collection<JSQualifiedNamedElement> candidates = JSResolveUtil.findElementsByName(shortClassName, project, scope);
for (JSQualifiedNamedElement candidate : candidates) {
if (candidate instanceof JSClass) {
fillPropertyDescriptorsDynamically((JSClass) candidate, visited, result);
}
}
}
for (Iterator<CssPropertyDescriptor> iterator = result.iterator(); iterator.hasNext(); ) {
CssPropertyDescriptor propertyDescriptor = iterator.next();
List<Set<FlexStyleIndexInfo>> values = fileBasedIndex.getValues(FlexStyleIndex.INDEX_ID, propertyDescriptor.getPropertyName(), scope);
if (values.size() == 0) {
iterator.remove();
}
}
return result;
}
use of com.intellij.util.indexing.FileBasedIndex in project intellij-plugins by JetBrains.
the class FlexCssElementDescriptorProvider method getAllPropertyDescriptors.
@NotNull
public Collection<? extends CssPropertyDescriptor> getAllPropertyDescriptors(@Nullable PsiElement context) {
if (context == null || DumbService.getInstance(context.getProject()).isDumb()) {
return Collections.emptyList();
}
Module module = findModuleForPsiElement(context);
List<CssSimpleSelector> simpleSelectors = findSimpleSelectorsAbove(context);
if (simpleSelectors.size() > 0 && !containsGlobalSelectors(simpleSelectors)) {
if (module != null) {
return getPropertyDescriptorsDynamically(simpleSelectors, module);
}
}
FileBasedIndex index = FileBasedIndex.getInstance();
Collection<String> keys = ContainerUtil.sorted(index.getAllKeys(FlexStyleIndex.INDEX_ID, context.getProject()));
List<FlexCssPropertyDescriptor> result = new ArrayList<>();
GlobalSearchScope scope = FlexCssUtil.getResolveScope(context);
for (String key : keys) {
if (!isInClassicForm(key)) {
for (Set<FlexStyleIndexInfo> infos : index.getValues(FlexStyleIndex.INDEX_ID, key, scope)) {
result.add(new FlexCssPropertyDescriptor(infos));
}
}
}
return result;
}
Aggregations