Skip to content

Commit

Permalink
Do not expand same class twice in (quick) type hierarchy
Browse files Browse the repository at this point in the history
Fixes #1830
  • Loading branch information
fedejeanne committed Jan 20, 2025
1 parent 7e83160 commit d08f10e
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 2 deletions.
8 changes: 8 additions & 0 deletions org.eclipse.jdt.ui/.settings/.api_filters
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,14 @@
</message_arguments>
</filter>
</resource>
<resource path="ui/org/eclipse/jdt/internal/ui/typehierarchy/HierarchyInformationControl.java" type="org.eclipse.jdt.internal.ui.typehierarchy.HierarchyInformationControl">
<filter id="571519004">
<message_arguments>
<message_argument value="org.eclipse.jdt.internal.ui.typehierarchy.HierarchyInformationControl.createTreeViewer(Composite, int)"/>
<message_argument value="TreeViewer"/>
</message_arguments>
</filter>
</resource>
<resource path="ui/org/eclipse/jdt/internal/ui/viewsupport/ProblemTableViewer.java" type="org.eclipse.jdt.internal.ui.viewsupport.ProblemTableViewer">
<filter id="571473929">
<message_arguments>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
package org.eclipse.jdt.internal.ui.typehierarchy;

import java.lang.reflect.InvocationTargetException;
import java.util.HashSet;
import java.util.Set;

import org.eclipse.swt.SWT;
import org.eclipse.swt.events.KeyAdapter;
Expand All @@ -23,6 +25,7 @@
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
import org.eclipse.swt.widgets.Tree;
import org.eclipse.swt.widgets.Widget;

import org.eclipse.jface.bindings.TriggerSequence;
import org.eclipse.jface.bindings.keys.KeySequence;
Expand Down Expand Up @@ -130,7 +133,32 @@ protected TreeViewer createTreeViewer(Composite parent, int style) {
gd.heightHint= tree.getItemHeight() * 12;
tree.setLayoutData(gd);

TreeViewer treeViewer= new TreeViewer(tree);
TreeViewer treeViewer= new TreeViewer(tree) {
private Set<Object> visited;

@Override
protected void inputChanged(Object input, Object oldInput) {
visited= new HashSet<>();
super.inputChanged(input, oldInput);
visited= null;
}

@Override
protected void internalExpandToLevel(Widget node, int level) {
if (!shouldExpand(node))
return;

super.internalExpandToLevel(node, level);
}

private boolean shouldExpand(Widget widget) {
if (widget == null) {
return false;
}
Object data= widget.getData();
return data == null || visited.add(data);
}
};
treeViewer.addFilter(new ViewerFilter() {
@Override
public boolean select(Viewer viewer, Object parentElement, Object element) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1212,7 +1212,12 @@ private void updateHierarchyViewer(final boolean doExpand) {
fPagebook.showPage(fNoHierarchyShownLabel);
} else {
if (getCurrentViewer().containsElements() != null) {
Runnable runnable= () -> JavaCore.runReadOnly(() -> getCurrentViewer().updateContent(doExpand));
Runnable runnable= () -> JavaCore.runReadOnly(() -> {
TypeHierarchyViewer viewer= getCurrentViewer();
viewer.preUpdateContent();
viewer.updateContent(doExpand);
viewer.postUpdateContent();
});
BusyIndicator.showWhile(getDisplay(), runnable);
if (!isChildVisible(fViewerbook, getCurrentViewer().getControl())) {
setViewerVisibility(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,14 @@
*******************************************************************************/
package org.eclipse.jdt.internal.ui.typehierarchy;

import java.util.HashSet;
import java.util.Set;

import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Menu;
import org.eclipse.swt.widgets.Tree;
import org.eclipse.swt.widgets.Widget;

import org.eclipse.core.runtime.Assert;

Expand All @@ -42,6 +46,8 @@ public abstract class TypeHierarchyViewer extends ProblemTreeViewer {

private HierarchyLabelProvider fLabelProvider;

private Set<Object> visited;


public TypeHierarchyViewer(Composite parent, IContentProvider contentProvider, TypeHierarchyLifeCycle lifeCycle) {
super(new Tree(parent, SWT.SINGLE));
Expand Down Expand Up @@ -182,4 +188,34 @@ protected TypeHierarchyContentProvider getHierarchyContentProvider() {
return (TypeHierarchyContentProvider)getContentProvider();
}

@Override
protected void inputChanged(Object input, Object oldInput) {
preUpdateContent();
super.inputChanged(input, oldInput);
postUpdateContent();
}

@Override
protected void internalExpandToLevel(Widget node, int level) {
if (!shouldExpand(node))
return;

super.internalExpandToLevel(node, level);
}

private boolean shouldExpand(Widget widget) {
if (widget == null) {
return false;
}
Object data= widget.getData();
return data == null || visited.add(data);
}

void preUpdateContent() {
visited= new HashSet<>();
}

void postUpdateContent() {
visited= null;
}
}

0 comments on commit d08f10e

Please sign in to comment.