use of com.intellij.ide.util.treeView.smartTree.TreeElement in project intellij-elixir by KronicDeth.
the class File method getChildren.
/*
* Public Instance Methods
*/
@NotNull
@Override
public TreeElement[] getChildren() {
Call[] calls = PsiTreeUtil.getChildrenOfType(navigationItem, Call.class);
TreeElement[] children;
if (calls != null) {
List<TreeElement> treeElementList = new ArrayList<TreeElement>(calls.length);
for (Call call : calls) {
if (Implementation.is(call)) {
treeElementList.add(new Implementation(call));
} else if (Module.is(call)) {
treeElementList.add(new Module(call));
} else if (Protocol.is(call)) {
treeElementList.add(new Protocol(call));
} else if (Quote.is(call)) {
treeElementList.add(new Quote(call));
} else if (Unknown.is(call)) {
// should always be last because it will match all macro calls
treeElementList.add(new Unknown(call));
}
}
children = treeElementList.toArray(new TreeElement[treeElementList.size()]);
} else {
children = new TreeElement[0];
}
return children;
}
use of com.intellij.ide.util.treeView.smartTree.TreeElement in project intellij-elixir by KronicDeth.
the class Overridable method getChildren.
/**
* Returns the list of children of the tree element.
*
* @return the list of children.
*/
@NotNull
@Override
public TreeElement[] getChildren() {
QuotableKeywordList keywordArguments = ElixirPsiImplUtil.keywordArguments(navigationItem);
TreeElement[] children;
if (keywordArguments != null) {
List<QuotableKeywordPair> quotableKeywordPairList = keywordArguments.quotableKeywordPairList();
List<TreeElement> treeElementList = new ArrayList<TreeElement>(quotableKeywordPairList.size());
for (QuotableKeywordPair quotableKeywordPair : quotableKeywordPairList) {
Quotable keywordKey = quotableKeywordPair.getKeywordKey();
OtpErlangObject quotedKeywordKey = keywordKey.quote();
String name;
if (quotedKeywordKey instanceof OtpErlangAtom) {
OtpErlangAtom keywordKeyAtom = (OtpErlangAtom) quotedKeywordKey;
name = keywordKeyAtom.atomValue();
} else {
name = keywordKey.getText();
}
Quotable keywordValue = quotableKeywordPair.getKeywordValue();
OtpErlangObject quotedKeywordValue = keywordValue.quote();
Integer arity = null;
if (quotedKeywordValue instanceof OtpErlangLong) {
OtpErlangLong keywordValueErlangLong = (OtpErlangLong) quotedKeywordValue;
try {
arity = keywordValueErlangLong.intValue();
} catch (OtpErlangRangeException e) {
arity = null;
}
}
boolean overridable = true;
//noinspection ConstantConditions
treeElementList.add(new CallReference(modular, quotableKeywordPair, Timed.Time.RUN, overridable, name, arity));
}
children = treeElementList.toArray(new TreeElement[treeElementList.size()]);
} else {
children = new TreeElement[0];
}
return children;
}
use of com.intellij.ide.util.treeView.smartTree.TreeElement in project intellij-community by JetBrains.
the class ResourceBundleEditorRenderer method customize.
private boolean customize(Object value) {
final Object userObject = ((DefaultMutableTreeNode) value).getUserObject();
if (!(userObject instanceof TreeElementWrapper)) {
return false;
}
final TreeElement treeElement = ((TreeElementWrapper) userObject).getValue();
if (treeElement == null) {
return false;
}
final ItemPresentation presentation = treeElement.getPresentation();
if (presentation instanceof TextAttributesPresentation) {
final TextAttributesPresentation textAttributesPresentation = (TextAttributesPresentation) presentation;
final String text = textAttributesPresentation.getPresentableText();
if (text != null) {
final SimpleTextAttributes attr = SimpleTextAttributes.fromTextAttributes(textAttributesPresentation.getTextAttributes(getColorsScheme()));
append(text, new SimpleTextAttributes(attr.getBgColor(), attr.getFgColor(), attr.getWaveColor(), attr.getStyle() | SimpleTextAttributes.STYLE_OPAQUE));
return true;
}
}
return false;
}
use of com.intellij.ide.util.treeView.smartTree.TreeElement in project intellij-community by JetBrains.
the class ResourceBundleEditor method setStructureViewSelection.
private void setStructureViewSelection(@NotNull final String propertyName) {
if (myStructureViewComponent.isDisposed()) {
return;
}
JTree tree = myStructureViewComponent.getTree();
if (tree == null) {
return;
}
Object root = tree.getModel().getRoot();
if (AbstractTreeUi.isLoadingChildrenFor(root)) {
boolean isEditorVisible = false;
for (FileEditor editor : FileEditorManager.getInstance(myProject).getSelectedEditors()) {
if (editor == this) {
isEditorVisible = true;
break;
}
}
if (!isEditorVisible) {
myPropertyToSelectWhenVisible = propertyName;
return;
}
mySelectionChangeAlarm.cancelAllRequests();
mySelectionChangeAlarm.addRequest(() -> {
mySelectionChangeAlarm.cancelAllRequests();
setStructureViewSelection(propertyName);
}, 500);
return;
}
Stack<TreeElement> toCheck = ContainerUtilRt.newStack();
toCheck.push(myStructureViewComponent.getTreeModel().getRoot());
while (!toCheck.isEmpty()) {
TreeElement element = toCheck.pop();
PsiElement value = element instanceof ResourceBundlePropertyStructureViewElement ? ((ResourceBundlePropertyStructureViewElement) element).getProperty().getPsiElement() : null;
if (value != null) {
final IProperty property = PropertiesImplUtil.getProperty(value);
if (propertyName.equals(property.getUnescapedKey())) {
myStructureViewComponent.select(property, true);
selectionChanged();
return;
}
} else {
for (TreeElement treeElement : element.getChildren()) {
toCheck.push(treeElement);
}
}
}
}
use of com.intellij.ide.util.treeView.smartTree.TreeElement in project ideavim by JetBrains.
the class PsiHelper method addNavigationElements.
private static void addNavigationElements(@NotNull TreeElement root, @NotNull TIntArrayList navigationOffsets, boolean start) {
if (root instanceof PsiTreeElementBase) {
PsiElement element = ((PsiTreeElementBase) root).getValue();
int offset;
if (start) {
offset = element.getTextRange().getStartOffset();
if (element.getLanguage().getID().equals("JAVA")) {
// HACK: for Java classes and methods, we want to jump to the opening brace
int textOffset = element.getTextOffset();
int braceIndex = element.getText().indexOf('{', textOffset - offset);
if (braceIndex >= 0) {
offset += braceIndex;
}
}
} else {
offset = element.getTextRange().getEndOffset() - 1;
}
if (!navigationOffsets.contains(offset)) {
navigationOffsets.add(offset);
}
}
for (TreeElement child : root.getChildren()) {
addNavigationElements(child, navigationOffsets, start);
}
}
Aggregations