use of com.intellij.lang.properties.CustomResourceBundle in project intellij-community by JetBrains.
the class ResourceBundleGrouper method modify.
@Override
@NotNull
public Collection<AbstractTreeNode> modify(@NotNull AbstractTreeNode parent, @NotNull final Collection<AbstractTreeNode> children, final ViewSettings settings) {
if (parent instanceof ResourceBundleNode)
return children;
return ReadAction.compute(() -> {
Map<ResourceBundle, Collection<PropertiesFile>> childBundles = new THashMap<>();
for (AbstractTreeNode child : children) {
Object f = child.getValue();
if (f instanceof PsiFile) {
PropertiesFile propertiesFile = PropertiesImplUtil.getPropertiesFile((PsiFile) f);
if (propertiesFile != null) {
boolean isProcessed = false;
for (Collection<PropertiesFile> files : childBundles.values()) {
if (files.contains(propertiesFile)) {
isProcessed = true;
break;
}
}
if (isProcessed)
continue;
PropertiesImplUtil.ResourceBundleWithCachedFiles resourceBundleWithCachedFiles = PropertiesImplUtil.getResourceBundleWithCachedFiles(propertiesFile);
final ResourceBundle bundle = resourceBundleWithCachedFiles.getBundle();
Collection<PropertiesFile> files = childBundles.get(bundle);
if (files == null) {
files = new LinkedHashSet<>();
childBundles.put(bundle, files);
}
files.add(propertiesFile);
files.addAll(resourceBundleWithCachedFiles.getFiles());
}
}
}
List<AbstractTreeNode> result = new ArrayList<>();
for (Map.Entry<ResourceBundle, Collection<PropertiesFile>> entry : childBundles.entrySet()) {
ResourceBundle resourceBundle = entry.getKey();
Collection<PropertiesFile> files = entry.getValue();
if (files.size() != 1) {
result.add(new ResourceBundleNode(myProject, resourceBundle, settings));
}
}
for (AbstractTreeNode child : children) {
Object f = child.getValue();
if (f instanceof PsiFile) {
PropertiesFile propertiesFile = PropertiesImplUtil.getPropertiesFile((PsiFile) f);
if (propertiesFile != null) {
ResourceBundle bundle = null;
for (Map.Entry<ResourceBundle, Collection<PropertiesFile>> e : childBundles.entrySet()) {
if (e.getValue().contains(propertiesFile)) {
bundle = e.getKey();
break;
}
}
LOG.assertTrue(bundle != null);
if (childBundles.get(bundle).size() != 1) {
continue;
} else if (bundle instanceof CustomResourceBundle) {
final CustomResourceBundlePropertiesFileNode node = new CustomResourceBundlePropertiesFileNode(myProject, (PsiFile) f, settings);
result.add(node);
}
}
}
result.add(child);
}
return result;
});
}
Aggregations