use of com.intellij.ide.util.treeView.NodeDescriptor in project intellij-community by JetBrains.
the class GrCallReferenceProcessor method process.
@Override
public boolean process(@NotNull PsiReference reference, @NotNull JavaCallHierarchyData data) {
PsiClass originalClass = data.getOriginalClass();
PsiMethod method = data.getMethod();
Set<PsiMethod> methodsToFind = data.getMethodsToFind();
PsiMethod methodToFind = data.getMethodToFind();
PsiClassType originalType = data.getOriginalType();
Map<PsiMember, NodeDescriptor> methodToDescriptorMap = data.getResultMap();
Project project = data.getProject();
if (reference instanceof GrReferenceExpression) {
final GrExpression qualifier = ((GrReferenceExpression) reference).getQualifierExpression();
if (org.jetbrains.plugins.groovy.lang.psi.util.PsiUtil.isSuperReference(qualifier)) {
// filter super.foo() call inside foo() and similar cases (bug 8411)
assert qualifier != null;
final PsiClass superClass = PsiUtil.resolveClassInType(qualifier.getType());
if (originalClass == null || originalClass.isInheritor(superClass, true)) {
return true;
}
}
if (qualifier != null && !methodToFind.hasModifierProperty(PsiModifier.STATIC)) {
final PsiType qualifierType = qualifier.getType();
if (qualifierType instanceof PsiClassType && !TypeConversionUtil.isAssignable(qualifierType, originalType) && methodToFind != method) {
final PsiClass psiClass = ((PsiClassType) qualifierType).resolve();
if (psiClass != null) {
final PsiMethod callee = psiClass.findMethodBySignature(methodToFind, true);
if (callee != null && !methodsToFind.contains(callee)) {
// skip sibling methods
return true;
}
}
}
}
} else {
if (!(reference instanceof PsiElement)) {
return true;
}
final PsiElement parent = ((PsiElement) reference).getParent();
if (parent instanceof PsiNewExpression) {
if (((PsiNewExpression) parent).getClassReference() != reference) {
return true;
}
} else if (parent instanceof GrAnonymousClassDefinition) {
if (((GrAnonymousClassDefinition) parent).getBaseClassReferenceGroovy() != reference) {
return true;
}
} else {
return true;
}
}
final PsiElement element = reference.getElement();
final PsiMember key = CallHierarchyNodeDescriptor.getEnclosingElement(element);
synchronized (methodToDescriptorMap) {
CallHierarchyNodeDescriptor d = (CallHierarchyNodeDescriptor) methodToDescriptorMap.get(key);
if (d == null) {
d = new CallHierarchyNodeDescriptor(project, (CallHierarchyNodeDescriptor) data.getNodeDescriptor(), element, false, true);
methodToDescriptorMap.put(key, d);
} else if (!d.hasReference(reference)) {
d.incrementUsageCount();
}
d.addReference(reference);
}
return true;
}
use of com.intellij.ide.util.treeView.NodeDescriptor in project intellij-community by JetBrains.
the class HierarchyBrowserBaseEx method changeView.
public final void changeView(@NotNull final String typeName) {
setCurrentViewType(typeName);
final PsiElement element = mySmartPsiElementPointer.getElement();
if (element == null || !isApplicableElement(element)) {
return;
}
if (myContent != null) {
final String displayName = getContentDisplayName(typeName, element);
if (displayName != null) {
myContent.setDisplayName(displayName);
}
}
myCardLayout.show(myTreePanel, typeName);
if (!myType2BuilderMap.containsKey(typeName)) {
try {
setWaitCursor();
// create builder
final JTree tree = myType2TreeMap.get(typeName);
final DefaultTreeModel model = new DefaultTreeModel(new DefaultMutableTreeNode(""));
tree.setModel(model);
final HierarchyTreeStructure structure = createHierarchyTreeStructure(typeName, element);
if (structure == null) {
return;
}
final Comparator<NodeDescriptor> comparator = getComparator();
final HierarchyTreeBuilder builder = new HierarchyTreeBuilder(myProject, tree, model, structure, comparator);
myType2BuilderMap.put(typeName, builder);
Disposer.register(this, builder);
Disposer.register(builder, () -> myType2BuilderMap.remove(typeName));
final HierarchyNodeDescriptor descriptor = structure.getBaseDescriptor();
builder.select(descriptor, () -> builder.expand(descriptor, null));
} finally {
restoreCursor();
}
}
IdeFocusManager.getGlobalInstance().doWhenFocusSettlesDown(() -> {
IdeFocusManager.getGlobalInstance().requestFocus(getCurrentTree(), true);
});
}
use of com.intellij.ide.util.treeView.NodeDescriptor in project intellij-community by JetBrains.
the class ContentEntryTreeCellRenderer method customizeCellRenderer.
@Override
public void customizeCellRenderer(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) {
super.customizeCellRenderer(tree, value, selected, expanded, leaf, row, hasFocus);
final ContentEntryEditor editor = myTreeEditor.getContentEntryEditor();
if (editor != null) {
final Object userObject = ((DefaultMutableTreeNode) value).getUserObject();
if (userObject instanceof NodeDescriptor) {
final Object element = ((NodeDescriptor) userObject).getElement();
if (element instanceof FileElement) {
final VirtualFile file = ((FileElement) element).getFile();
if (file != null && file.isDirectory()) {
final ContentEntry contentEntry = editor.getContentEntry();
if (contentEntry != null) {
final String prefix = getPresentablePrefix(contentEntry, file);
if (!prefix.isEmpty()) {
append(" (" + prefix + ")", new SimpleTextAttributes(SimpleTextAttributes.STYLE_PLAIN, JBColor.GRAY));
}
setIcon(updateIcon(contentEntry, file, getIcon()));
}
}
}
}
}
}
use of com.intellij.ide.util.treeView.NodeDescriptor in project intellij-community by JetBrains.
the class ContentEntryTreeEditor method setContentEntryEditor.
/**
* @param contentEntryEditor : null means to clear the editor
*/
public void setContentEntryEditor(final ContentEntryEditor contentEntryEditor) {
if (myContentEntryEditor != null && myContentEntryEditor.equals(contentEntryEditor)) {
return;
}
if (myFileSystemTree != null) {
Disposer.dispose(myFileSystemTree);
myFileSystemTree = null;
}
if (myContentEntryEditor != null) {
myContentEntryEditor.removeContentEntryEditorListener(myContentEntryEditorListener);
myContentEntryEditor = null;
}
if (contentEntryEditor == null) {
((DefaultTreeModel) myTree.getModel()).setRoot(EMPTY_TREE_ROOT);
myTreePanel.setVisible(false);
if (myFileSystemTree != null) {
Disposer.dispose(myFileSystemTree);
}
return;
}
myTreePanel.setVisible(true);
myContentEntryEditor = contentEntryEditor;
myContentEntryEditor.addContentEntryEditorListener(myContentEntryEditorListener);
final ContentEntry entry = contentEntryEditor.getContentEntry();
assert entry != null : contentEntryEditor;
final VirtualFile file = entry.getFile();
if (file != null) {
myDescriptor.setRoots(file);
} else {
String path = VfsUtilCore.urlToPath(entry.getUrl());
myDescriptor.setTitle(FileUtil.toSystemDependentName(path));
}
final Runnable init = () -> {
//noinspection ConstantConditions
myFileSystemTree.updateTree();
myFileSystemTree.select(file, null);
};
myFileSystemTree = new FileSystemTreeImpl(myProject, myDescriptor, myTree, getContentEntryCellRenderer(), init, null) {
@Override
protected AbstractTreeBuilder createTreeBuilder(JTree tree, DefaultTreeModel treeModel, AbstractTreeStructure treeStructure, Comparator<NodeDescriptor> comparator, FileChooserDescriptor descriptor, final Runnable onInitialized) {
return new MyFileTreeBuilder(tree, treeModel, treeStructure, comparator, descriptor, onInitialized);
}
};
myFileSystemTree.showHiddens(true);
Disposer.register(myProject, myFileSystemTree);
final NewFolderAction newFolderAction = new MyNewFolderAction();
final DefaultActionGroup mousePopupGroup = new DefaultActionGroup();
mousePopupGroup.add(myEditingActionsGroup);
mousePopupGroup.addSeparator();
mousePopupGroup.add(newFolderAction);
myFileSystemTree.registerMouseListener(mousePopupGroup);
}
use of com.intellij.ide.util.treeView.NodeDescriptor in project intellij-community by JetBrains.
the class AbstractListBuilder method updateList.
protected final void updateList() {
if (myIsDisposed || myCurrentParent == null) {
return;
}
if (myTreeStructure.hasSomethingToCommit()) {
myTreeStructure.commit();
}
AbstractTreeNode parentDescriptor = myCurrentParent;
while (true) {
parentDescriptor.update();
if (parentDescriptor.getValue() != null)
break;
parentDescriptor = parentDescriptor.getParent();
}
final Object[] children = getChildren(parentDescriptor);
final HashMap<Object, Integer> elementToIndexMap = new HashMap<>();
for (int i = 0; i < children.length; i++) {
elementToIndexMap.put(children[i], Integer.valueOf(i));
}
final List<NodeDescriptor> resultDescriptors = new ArrayList<>();
final Object[] listChildren = myModel.toArray();
for (final Object child : listChildren) {
if (!(child instanceof NodeDescriptor)) {
continue;
}
final NodeDescriptor descriptor = (NodeDescriptor) child;
descriptor.update();
final Object newElement = descriptor.getElement();
final Integer index = newElement != null ? elementToIndexMap.get(newElement) : null;
if (index != null) {
resultDescriptors.add(descriptor);
descriptor.setIndex(index.intValue());
elementToIndexMap.remove(newElement);
}
}
for (final Object child : elementToIndexMap.keySet()) {
final Integer index = elementToIndexMap.get(child);
if (index != null) {
final NodeDescriptor childDescr = myTreeStructure.createDescriptor(child, parentDescriptor);
childDescr.setIndex(index.intValue());
childDescr.update();
resultDescriptors.add(childDescr);
}
}
final SelectionInfo selection = storeSelection();
if (myComparator != null) {
Collections.sort(resultDescriptors, myComparator);
} else {
Collections.sort(resultDescriptors, IndexComparator.INSTANCE);
}
if (shouldAddTopElement()) {
final List elems = new ArrayList();
elems.add(new TopLevelNode(myProject, parentDescriptor.getValue()));
elems.addAll(resultDescriptors);
myModel.replaceElements(elems);
} else {
myModel.replaceElements(resultDescriptors);
}
restoreSelection(selection);
updateParentTitle();
}
Aggregations