Search in sources :

Example 1 with CustomResourceBundle

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;
    });
}
Also used : AbstractTreeNode(com.intellij.ide.util.treeView.AbstractTreeNode) CustomResourceBundle(com.intellij.lang.properties.CustomResourceBundle) THashMap(gnu.trove.THashMap) PropertiesImplUtil(com.intellij.lang.properties.PropertiesImplUtil) ResourceBundle(com.intellij.lang.properties.ResourceBundle) CustomResourceBundle(com.intellij.lang.properties.CustomResourceBundle) PsiFile(com.intellij.psi.PsiFile) PropertiesFile(com.intellij.lang.properties.psi.PropertiesFile) THashMap(gnu.trove.THashMap) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

AbstractTreeNode (com.intellij.ide.util.treeView.AbstractTreeNode)1 CustomResourceBundle (com.intellij.lang.properties.CustomResourceBundle)1 PropertiesImplUtil (com.intellij.lang.properties.PropertiesImplUtil)1 ResourceBundle (com.intellij.lang.properties.ResourceBundle)1 PropertiesFile (com.intellij.lang.properties.psi.PropertiesFile)1 PsiFile (com.intellij.psi.PsiFile)1 THashMap (gnu.trove.THashMap)1 NotNull (org.jetbrains.annotations.NotNull)1