use of com.intellij.ide.util.treeView.smartTree.TreeElement in project intellij-community by JetBrains.
the class GotoClassAction method findMember.
@Nullable
private static Navigatable findMember(String pattern, PsiElement psiElement, VirtualFile file) {
final PsiStructureViewFactory factory = LanguageStructureViewBuilder.INSTANCE.forLanguage(psiElement.getLanguage());
final StructureViewBuilder builder = factory == null ? null : factory.getStructureViewBuilder(psiElement.getContainingFile());
final FileEditor[] editors = FileEditorManager.getInstance(psiElement.getProject()).getEditors(file);
if (builder == null || editors.length == 0) {
return null;
}
final StructureView view = builder.createStructureView(editors[0], psiElement.getProject());
try {
final StructureViewTreeElement element = findElement(view.getTreeModel().getRoot(), psiElement, 4);
if (element == null) {
return null;
}
final MinusculeMatcher matcher = NameUtil.buildMatcher(pattern).build();
int max = Integer.MIN_VALUE;
Object target = null;
for (TreeElement treeElement : element.getChildren()) {
if (treeElement instanceof StructureViewTreeElement) {
String presentableText = treeElement.getPresentation().getPresentableText();
if (presentableText != null) {
final int degree = matcher.matchingDegree(presentableText);
if (degree > max) {
max = degree;
target = ((StructureViewTreeElement) treeElement).getValue();
}
}
}
}
return target instanceof Navigatable ? (Navigatable) target : null;
} finally {
Disposer.dispose(view);
}
}
use of com.intellij.ide.util.treeView.smartTree.TreeElement in project intellij-community by JetBrains.
the class JsonStructureViewTest method testSimpleStructure.
// Moved from JavaScript
public void testSimpleStructure() {
myFixture.configureByFile("structureView/" + getTestName(false) + ".json");
final StructureViewBuilder builder = LanguageStructureViewBuilder.INSTANCE.getStructureViewBuilder(myFixture.getFile());
assertNotNull(builder);
StructureViewComponent component = null;
try {
final FileEditor editor = FileEditorManager.getInstance(getProject()).getSelectedEditor(myFixture.getFile().getVirtualFile());
component = (StructureViewComponent) builder.createStructureView(editor, myFixture.getProject());
final StructureViewModel model = component.getTreeModel();
TreeElement[] children = model.getRoot().getChildren();
assertEquals(2, children.length);
assertEquals("aaa", children[0].getPresentation().getPresentableText());
assertEquals(PlatformIcons.PROPERTY_ICON, children[0].getPresentation().getIcon(false));
assertEquals("bbb", children[1].getPresentation().getPresentableText());
assertEquals(AllIcons.Json.Property_braces, children[1].getPresentation().getIcon(false));
children = children[1].getChildren();
assertEquals(1, children.length);
assertEquals("ccc", children[0].getPresentation().getPresentableText());
assertEquals(PlatformIcons.PROPERTY_ICON, children[0].getPresentation().getIcon(false));
} finally {
if (component != null) {
Disposer.dispose(component);
}
}
}
use of com.intellij.ide.util.treeView.smartTree.TreeElement 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.util.treeView.smartTree.TreeElement 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;
}
Aggregations