use of com.intellij.ide.structureView.StructureViewTreeElement in project intellij-plugins by JetBrains.
the class DartStructureViewElement method getChildrenBase.
@NotNull
@Override
public Collection<StructureViewTreeElement> getChildrenBase() {
final NavigatablePsiElement element = getElement();
final List<StructureViewTreeElement> result = new ArrayList<>();
if (element instanceof DartFile || element instanceof DartEmbeddedContent) {
THashSet<DartComponentName> componentNames = new THashSet<>();
DartPsiCompositeElementImpl.processDeclarationsImpl(element, new ComponentNameScopeProcessor(componentNames), ResolveState.initial(), null);
for (DartComponentName componentName : componentNames) {
PsiElement parent = componentName.getParent();
if (parent instanceof DartComponent) {
result.add(new DartStructureViewElement((DartComponent) parent));
}
}
} else if (element instanceof DartClass) {
for (DartComponent subNamedComponent : DartResolveUtil.getNamedSubComponents((DartClass) element)) {
result.add(new DartStructureViewElement(subNamedComponent));
}
}
Collections.sort(result, (o1, o2) -> {
PsiElement element1, element2;
if (o1 instanceof DartStructureViewElement && o2 instanceof DartStructureViewElement && (element1 = ((DartStructureViewElement) o1).getElement()) != null && (element2 = ((DartStructureViewElement) o2).getElement()) != null) {
return element1.getTextRange().getStartOffset() - element2.getTextRange().getStartOffset();
}
return 0;
});
return result;
}
use of com.intellij.ide.structureView.StructureViewTreeElement in project intellij-community by JetBrains.
the class StructureTreeBuilder method isAutoExpandNode.
@Override
protected final boolean isAutoExpandNode(NodeDescriptor nodeDescriptor) {
StructureViewModel model = myStructureModel;
if (model instanceof TreeModelWrapper) {
model = ((TreeModelWrapper) model).getModel();
}
if (model instanceof StructureViewModel.ExpandInfoProvider) {
StructureViewModel.ExpandInfoProvider provider = (StructureViewModel.ExpandInfoProvider) model;
Object element = nodeDescriptor.getElement();
if (element instanceof StructureViewComponent.StructureViewTreeElementWrapper) {
StructureViewComponent.StructureViewTreeElementWrapper wrapper = (StructureViewComponent.StructureViewTreeElementWrapper) element;
if (wrapper.getValue() instanceof StructureViewTreeElement) {
final StructureViewTreeElement value = (StructureViewTreeElement) wrapper.getValue();
if (value != null) {
return provider.isAutoExpand(value);
}
}
} else if (element instanceof GroupWrapper) {
final Group group = ((GroupWrapper) element).getValue();
for (TreeElement treeElement : group.getChildren()) {
if (treeElement instanceof StructureViewTreeElement && !provider.isAutoExpand((StructureViewTreeElement) treeElement)) {
return false;
}
}
}
}
// expand root node & its immediate children
final NodeDescriptor parent = nodeDescriptor.getParentDescriptor();
return super.isAutoExpandNode(parent == null ? nodeDescriptor : parent);
}
use of com.intellij.ide.structureView.StructureViewTreeElement in project intellij-community by JetBrains.
the class JavaFileTreeElement method getChildrenBase.
@Override
@NotNull
public Collection<StructureViewTreeElement> getChildrenBase() {
PsiClassOwner element = getElement();
if (element == null)
return Collections.emptyList();
PsiClass[] classes = element.getClasses();
ArrayList<StructureViewTreeElement> result = new ArrayList<>();
for (PsiClass aClass : classes) {
result.add(new JavaClassTreeElement(aClass, false, new HashSet<>()));
}
return result;
}
use of com.intellij.ide.structureView.StructureViewTreeElement in project intellij-community by JetBrains.
the class GroupByWordPrefixes method group.
@Override
@NotNull
public Collection<Group> group(@NotNull final AbstractTreeNode parent, @NotNull Collection<TreeElement> children) {
List<Key> keys = new ArrayList<>();
String parentPrefix;
int parentPrefixLength;
if (parent.getValue() instanceof PropertiesPrefixGroup) {
parentPrefix = ((PropertiesPrefixGroup) parent.getValue()).getPrefix();
parentPrefixLength = StringUtil.split(parentPrefix, mySeparator).size();
} else {
parentPrefix = "";
parentPrefixLength = 0;
}
for (TreeElement element : children) {
if (!(element instanceof StructureViewTreeElement)) {
continue;
}
Object value = ((StructureViewTreeElement) element).getValue();
if (!(value instanceof IProperty)) {
continue;
}
final String text = ((IProperty) value).getUnescapedKey();
if (text == null)
continue;
LOG.assertTrue(text.startsWith(parentPrefix) || text.startsWith(mySeparator));
List<String> words = StringUtil.split(text, mySeparator);
keys.add(new Key(words, element));
}
Collections.sort(keys, (k1, k2) -> {
List<String> o1 = k1.words;
List<String> o2 = k2.words;
for (int i = 0; i < Math.max(o1.size(), o2.size()); i++) {
if (i == o1.size())
return 1;
if (i == o2.size())
return -1;
String s1 = o1.get(i);
String s2 = o2.get(i);
int res = s1.compareTo(s2);
if (res != 0)
return res;
}
return 0;
});
List<Group> groups = new ArrayList<>();
int groupStart = 0;
for (int i = 0; i <= keys.size(); i++) {
if (!isEndOfGroup(i, keys, parentPrefixLength)) {
continue;
}
// find longest group prefix
List<String> firstKey = groupStart == keys.size() ? Collections.<String>emptyList() : keys.get(groupStart).words;
int prefixLen = firstKey.size();
for (int j = groupStart + 1; j < i; j++) {
List<String> prevKey = keys.get(j - 1).words;
List<String> nextKey = keys.get(j).words;
for (int k = parentPrefixLength; k < prefixLen; k++) {
String word = k < nextKey.size() ? nextKey.get(k) : null;
String wordInPrevKey = k < prevKey.size() ? prevKey.get(k) : null;
if (!Comparing.strEqual(word, wordInPrevKey)) {
prefixLen = k;
break;
}
}
}
String[] strings = firstKey.subList(0, prefixLen).toArray(new String[prefixLen]);
String prefix = StringUtil.join(strings, mySeparator);
String presentableName = prefix.substring(parentPrefix.length());
presentableName = StringUtil.trimStart(presentableName, mySeparator);
if (i - groupStart > 1) {
groups.add(new PropertiesPrefixGroup(children, prefix, presentableName, mySeparator));
} else if (groupStart != keys.size()) {
TreeElement node = keys.get(groupStart).node;
if (node instanceof PropertiesStructureViewElement) {
((PropertiesStructureViewElement) node).setPresentableName(presentableName);
} else {
((ResourceBundlePropertyStructureViewElement) node).setPresentableName(presentableName);
}
}
groupStart = i;
}
return groups;
}
use of com.intellij.ide.structureView.StructureViewTreeElement in project intellij-community by JetBrains.
the class PropertiesFileStructureViewElement method getChildrenBase.
@NotNull
public Collection<StructureViewTreeElement> getChildrenBase() {
List<? extends IProperty> properties = getElement().getProperties();
Collection<StructureViewTreeElement> elements = new ArrayList<>(properties.size());
for (IProperty property : properties) {
elements.add(new PropertiesStructureViewElement((Property) property));
}
return elements;
}
Aggregations