Search in sources :

Example 1 with ResourceBundlePropertyStructureViewElement

use of com.intellij.lang.properties.editor.ResourceBundlePropertyStructureViewElement in project intellij-community by JetBrains.

the class PropertiesPrefixGroup method getChildren.

@NotNull
public Collection<TreeElement> getChildren() {
    Collection<TreeElement> result = new ArrayList<>();
    List<String> prefixWords = StringUtil.split(myPrefix, mySeparator);
    for (TreeElement treeElement : myProperties) {
        if (!(treeElement instanceof StructureViewTreeElement)) {
            continue;
        }
        Object value = ((StructureViewTreeElement) treeElement).getValue();
        if (!(value instanceof IProperty)) {
            continue;
        }
        final String key = ((IProperty) value).getUnescapedKey();
        if (key == null) {
            continue;
        }
        boolean startsWith;
        if (!key.equals(myPrefix)) {
            List<String> keyWords = StringUtil.split(key, mySeparator);
            startsWith = prefixWords.size() < keyWords.size();
            if (startsWith) {
                for (int i = 0; i < prefixWords.size(); i++) {
                    String prefixWord = prefixWords.get(i);
                    String keyWord = keyWords.get(i);
                    if (!Comparing.strEqual(keyWord, prefixWord)) {
                        startsWith = false;
                        break;
                    }
                }
            }
        } else {
            startsWith = true;
        }
        if (startsWith) {
            result.add(treeElement);
            String presentableName = key.substring(myPrefix.length());
            presentableName = StringUtil.trimStart(presentableName, mySeparator);
            if (treeElement instanceof PropertiesStructureViewElement) {
                ((PropertiesStructureViewElement) treeElement).setPresentableName(presentableName);
            }
            if (treeElement instanceof ResourceBundlePropertyStructureViewElement) {
                ((ResourceBundlePropertyStructureViewElement) treeElement).setPresentableName(presentableName);
            }
        }
    }
    return result;
}
Also used : IProperty(com.intellij.lang.properties.IProperty) ArrayList(java.util.ArrayList) StructureViewTreeElement(com.intellij.ide.structureView.StructureViewTreeElement) ResourceBundlePropertyStructureViewElement(com.intellij.lang.properties.editor.ResourceBundlePropertyStructureViewElement) TreeElement(com.intellij.ide.util.treeView.smartTree.TreeElement) StructureViewTreeElement(com.intellij.ide.structureView.StructureViewTreeElement) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

StructureViewTreeElement (com.intellij.ide.structureView.StructureViewTreeElement)1 TreeElement (com.intellij.ide.util.treeView.smartTree.TreeElement)1 IProperty (com.intellij.lang.properties.IProperty)1 ResourceBundlePropertyStructureViewElement (com.intellij.lang.properties.editor.ResourceBundlePropertyStructureViewElement)1 ArrayList (java.util.ArrayList)1 NotNull (org.jetbrains.annotations.NotNull)1