use of com.intellij.ide.structureView.StructureViewTreeElement 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;
}
use of com.intellij.ide.structureView.StructureViewTreeElement 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.structureView.StructureViewTreeElement in project intellij-community by JetBrains.
the class RestStructureViewElement method getChildren.
@NotNull
public StructureViewTreeElement[] getChildren() {
final Set<RestElement> childrenElements = new LinkedHashSet<>();
myElement.acceptChildren(new PsiElementVisitor() {
@Override
public void visitElement(PsiElement element) {
if (element instanceof RestTitle && ((RestTitle) element).getName() != null)
childrenElements.add((RestElement) element);
else
element.acceptChildren(this);
}
});
StructureViewTreeElement[] children = new StructureViewTreeElement[childrenElements.size()];
int i = 0;
for (RestElement element : childrenElements) {
children[i] = new RestStructureViewElement(element);
i += 1;
}
return children;
}
use of com.intellij.ide.structureView.StructureViewTreeElement in project intellij-community by JetBrains.
the class XmlFileTreeElement method getChildrenBase.
@Override
@NotNull
public Collection<StructureViewTreeElement> getChildrenBase() {
final XmlDocument document = getElement().getDocument();
List<XmlTag> rootTags = new ArrayList<>();
if (document != null) {
for (PsiElement element : document.getChildren()) if (element instanceof XmlTag)
rootTags.add((XmlTag) element);
}
Collection<StructureViewTreeElement> structureViewTreeElements = getStructureViewTreeElements(rootTags.toArray(new XmlTag[rootTags.size()]));
Collection<StructureViewTreeElement> dtdStructureViewTreeElements = null;
final XmlProlog prolog = document != null ? document.getProlog() : null;
if (prolog != null) {
final XmlDoctype doctype = prolog.getDoctype();
if (doctype != null) {
final XmlMarkupDecl xmlMarkupDecl = doctype.getMarkupDecl();
if (xmlMarkupDecl != null) {
dtdStructureViewTreeElements = DtdFileTreeElement.collectElements(xmlMarkupDecl);
}
}
}
if (dtdStructureViewTreeElements != null) {
final ArrayList<StructureViewTreeElement> result = new ArrayList<>(dtdStructureViewTreeElements.size() + structureViewTreeElements.size());
result.addAll(dtdStructureViewTreeElements);
result.addAll(structureViewTreeElements);
structureViewTreeElements = result;
}
return structureViewTreeElements;
}
use of com.intellij.ide.structureView.StructureViewTreeElement in project intellij-community by JetBrains.
the class PyStructureViewElement method getChildren.
@NotNull
public StructureViewTreeElement[] getChildren() {
final PyElement element = getValue();
if (element == null) {
return EMPTY_ARRAY;
}
final Collection<StructureViewTreeElement> children = new ArrayList<>();
for (PyElement e : getElementChildren(element)) {
children.add(createChild(e, getElementVisibility(e), false, elementIsField(e)));
}
PyPsiUtils.assertValid(element);
if (element instanceof PyClass) {
for (PyClass c : ((PyClass) element).getAncestorClasses(null)) {
for (PyElement e : getElementChildren(c)) {
final StructureViewTreeElement inherited = createChild(e, getElementVisibility(e), true, elementIsField(e));
if (!children.contains(inherited)) {
children.add(inherited);
}
}
}
}
return children.toArray(new StructureViewTreeElement[children.size()]);
}
Aggregations