From 259d11d79b4bb6a13950b73c5c4437817630040d Mon Sep 17 00:00:00 2001 From: Markus Schorn Date: Tue, 28 Aug 2007 09:24:35 +0000 Subject: [PATCH] Fix for 201279, [Call Hierarchy] no indication for multiple calls --- .../callhierarchy/BasicCallHierarchyTest.java | 16 +++---- .../callhierarchy/CallHierarchyBaseTest.java | 7 +++ .../ui/callhierarchy/CHLabelProvider.java | 17 ++++--- .../internal/ui/callhierarchy/CHMessages.java | 1 + .../ui/callhierarchy/CHMessages.properties | 1 + .../ui/callhierarchy/CHMultiDefChildNode.java | 44 +++++++++++++++++++ .../ui/callhierarchy/CHMultiDefNode.java | 2 +- .../internal/ui/callhierarchy/CHViewPart.java | 39 +++++++--------- 8 files changed, 91 insertions(+), 36 deletions(-) create mode 100644 core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/callhierarchy/CHMultiDefChildNode.java diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/callhierarchy/BasicCallHierarchyTest.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/callhierarchy/BasicCallHierarchyTest.java index a224b71338a..f202b122969 100644 --- a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/callhierarchy/BasicCallHierarchyTest.java +++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/callhierarchy/BasicCallHierarchyTest.java @@ -232,7 +232,7 @@ public class BasicCallHierarchyTest extends CallHierarchyBaseTest { editor.selectAndReveal(content.indexOf("mem2"), 0); openCallHierarchy(editor); checkTreeNode(tree, 0, "s2::mem2"); - checkTreeNode(tree, 0, 0, "main()"); + checkTreeNode(tree, 0, 0, "main() (2 matches)"); editor.selectAndReveal(content.indexOf("mem3"), 0); openCallHierarchy(editor); @@ -255,7 +255,7 @@ public class BasicCallHierarchyTest extends CallHierarchyBaseTest { editor.selectAndReveal(content.indexOf("mem2; //ref"), 0); openCallHierarchy(editor); checkTreeNode(tree, 0, "s2::mem2"); - checkTreeNode(tree, 0, 0, "main()"); + checkTreeNode(tree, 0, 0, "main() (2 matches)"); editor.selectAndReveal(content.indexOf("mem4."), 0); openCallHierarchy(editor); @@ -279,7 +279,7 @@ public class BasicCallHierarchyTest extends CallHierarchyBaseTest { editor.selectAndReveal(content.indexOf("mem2"), 0); openCallHierarchy(editor); checkTreeNode(tree, 0, "s2::mem2"); - checkTreeNode(tree, 0, 0, "main()"); + checkTreeNode(tree, 0, 0, "main() (2 matches)"); editor.selectAndReveal(content.indexOf("mem3"), 0); openCallHierarchy(editor); @@ -302,7 +302,7 @@ public class BasicCallHierarchyTest extends CallHierarchyBaseTest { editor.selectAndReveal(content.indexOf("mem2; //ref"), 0); openCallHierarchy(editor); checkTreeNode(tree, 0, "s2::mem2"); - checkTreeNode(tree, 0, 0, "main()"); + checkTreeNode(tree, 0, 0, "main() (2 matches)"); editor.selectAndReveal(content.indexOf("mem4."), 0); openCallHierarchy(editor); @@ -418,7 +418,7 @@ public class BasicCallHierarchyTest extends CallHierarchyBaseTest { editor.selectAndReveal(content.indexOf("mem2"), 0); openCallHierarchy(editor); checkTreeNode(tree, 0, "u2::mem2"); - checkTreeNode(tree, 0, 0, "main()"); + checkTreeNode(tree, 0, 0, "main() (2 matches)"); editor.selectAndReveal(content.indexOf("mem3"), 0); openCallHierarchy(editor); @@ -441,7 +441,7 @@ public class BasicCallHierarchyTest extends CallHierarchyBaseTest { editor.selectAndReveal(content.indexOf("mem2; //ref"), 0); openCallHierarchy(editor); checkTreeNode(tree, 0, "u2::mem2"); - checkTreeNode(tree, 0, 0, "main()"); + checkTreeNode(tree, 0, 0, "main() (2 matches)"); editor.selectAndReveal(content.indexOf("mem4."), 0); openCallHierarchy(editor); @@ -465,7 +465,7 @@ public class BasicCallHierarchyTest extends CallHierarchyBaseTest { editor.selectAndReveal(content.indexOf("mem2"), 0); openCallHierarchy(editor); checkTreeNode(tree, 0, "u2::mem2"); - checkTreeNode(tree, 0, 0, "main()"); + checkTreeNode(tree, 0, 0, "main() (2 matches)"); editor.selectAndReveal(content.indexOf("mem3"), 0); openCallHierarchy(editor); @@ -488,7 +488,7 @@ public class BasicCallHierarchyTest extends CallHierarchyBaseTest { editor.selectAndReveal(content.indexOf("mem2; //ref"), 0); openCallHierarchy(editor); checkTreeNode(tree, 0, "u2::mem2"); - checkTreeNode(tree, 0, 0, "main()"); + checkTreeNode(tree, 0, 0, "main() (2 matches)"); editor.selectAndReveal(content.indexOf("mem4."), 0); openCallHierarchy(editor); diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/callhierarchy/CallHierarchyBaseTest.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/callhierarchy/CallHierarchyBaseTest.java index e8582e3bc69..37d768926e0 100644 --- a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/callhierarchy/CallHierarchyBaseTest.java +++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/callhierarchy/CallHierarchyBaseTest.java @@ -17,6 +17,7 @@ import org.eclipse.jface.text.ITextSelection; import org.eclipse.jface.viewers.TreeViewer; import org.eclipse.swt.SWTException; import org.eclipse.swt.widgets.TreeItem; +import org.eclipse.ui.IViewReference; import org.eclipse.ui.IWorkbenchPage; import org.eclipse.ui.PartInitException; import org.eclipse.ui.PlatformUI; @@ -52,6 +53,12 @@ public class CallHierarchyBaseTest extends BaseUITestCase { fCProject= CProjectHelper.createCCProject(prjName, "bin", IPDOMManager.ID_FAST_INDEXER); CCorePlugin.getIndexManager().joinIndexer(INDEXER_WAIT_TIME, NPM); fIndex= CCorePlugin.getIndexManager().getIndex(fCProject); + IWorkbenchPage page= PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); + IViewReference[] refs= page.getViewReferences(); + for (int i = 0; i < refs.length; i++) { + IViewReference viewReference = refs[i]; + page.setPartState(viewReference, IWorkbenchPage.STATE_RESTORED); + } } protected void tearDown() throws Exception { diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/callhierarchy/CHLabelProvider.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/callhierarchy/CHLabelProvider.java index 04e014014a3..cd62b7f47bf 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/callhierarchy/CHLabelProvider.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/callhierarchy/CHLabelProvider.java @@ -17,6 +17,7 @@ import java.util.Iterator; import org.eclipse.jface.resource.ImageDescriptor; import org.eclipse.jface.viewers.IColorProvider; import org.eclipse.jface.viewers.LabelProvider; +import org.eclipse.osgi.util.NLS; import org.eclipse.swt.SWT; import org.eclipse.swt.graphics.Color; import org.eclipse.swt.graphics.Image; @@ -72,16 +73,22 @@ public class CHLabelProvider extends LabelProvider implements IColorProvider { CHNode node= (CHNode) element; ICElement decl= node.getOneRepresentedDeclaration(); if (decl != null) { + String label; if (node.isMultiDef()) { int options= fCLabelProvider.getTextFlags(); fCLabelProvider.setTextFlags(LABEL_OPTIONS_SIMPLE); - String result= fCLabelProvider.getText(decl); + label= fCLabelProvider.getText(decl); fCLabelProvider.setTextFlags(options); - return result; } - String label= fCLabelProvider.getText(decl); - if (node.isInitializer()) { - label= addInitializerDecoration(label); + else { + label= fCLabelProvider.getText(decl); + if (node.isInitializer()) { + label= addInitializerDecoration(label); + } + } + int refCount= node.getReferenceCount(); + if (refCount > 1) { + label += NLS.bind(" ({0} {1})", new Integer(refCount), CHMessages.CHLabelProvider_matches); //$NON-NLS-1$ } return label; } diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/callhierarchy/CHMessages.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/callhierarchy/CHMessages.java index 5801646d364..b8d84f3300c 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/callhierarchy/CHMessages.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/callhierarchy/CHMessages.java @@ -22,6 +22,7 @@ public class CHMessages extends NLS { public static String CHHistoryListAction_HistoryList_label; public static String CHHistoryListAction_OpenHistory_label; public static String CHHistoryListAction_Remove_label; + public static String CHLabelProvider_matches; public static String CHViewPart_emptyPageMessage; public static String CHViewPart_FilterVariables_label; public static String CHViewPart_FilterVariables_tooltip; diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/callhierarchy/CHMessages.properties b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/callhierarchy/CHMessages.properties index e95b883c1e6..98425868c36 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/callhierarchy/CHMessages.properties +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/callhierarchy/CHMessages.properties @@ -34,6 +34,7 @@ CHViewPart_Title_callees=Calls from {0} - in {1} CHViewPart_FocusOn_label=Focus On ''{0}'' CHViewPart_Open_label=Open CHViewPart_Open_tooltip=Open +CHLabelProvider_matches=matches CHViewPart_OpenReference_label=Open Reference CHHistoryDropDownAction_ClearHistory_label=Clear History CHHistoryListAction_HistoryDialog_title=Call Hierarchy History diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/callhierarchy/CHMultiDefChildNode.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/callhierarchy/CHMultiDefChildNode.java new file mode 100644 index 00000000000..5f00627d158 --- /dev/null +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/callhierarchy/CHMultiDefChildNode.java @@ -0,0 +1,44 @@ +/******************************************************************************* + * Copyright (c) 2007 Wind River Systems, Inc. and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Markus Schorn - initial API and implementation + *******************************************************************************/ + +package org.eclipse.cdt.internal.ui.callhierarchy; + +import org.eclipse.cdt.core.model.ICElement; +import org.eclipse.cdt.core.model.ITranslationUnit; + +/** + * Represents a node in the include browser + */ +public class CHMultiDefChildNode extends CHNode { + + /** + * Creates a new node for the include browser + */ + public CHMultiDefChildNode(CHMultiDefNode parent, ITranslationUnit fileOfReferences, long timestamp, ICElement decl) { + super(parent, fileOfReferences, timestamp, decl); + } + + public int getReferenceCount() { + return getParent().getReferenceCount(); + } + + public CHReferenceInfo getReference(int idx) { + return getParent().getReference(idx); + } + + public int getFirstReferenceOffset() { + return getParent().getFirstReferenceOffset(); + } + + public void addReference(CHReferenceInfo info) { + assert false; + } +} diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/callhierarchy/CHMultiDefNode.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/callhierarchy/CHMultiDefNode.java index 0f71e18434f..5a025bd39ac 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/callhierarchy/CHMultiDefNode.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/callhierarchy/CHMultiDefNode.java @@ -26,7 +26,7 @@ public class CHMultiDefNode extends CHNode { fChildren= new CHNode[elements.length]; for (int i = 0; i < elements.length; i++) { ICElement element = elements[i]; - fChildren[i]= new CHNode(this, null, 0, element); + fChildren[i]= new CHMultiDefChildNode(this, tu, timestamp, element); } } diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/callhierarchy/CHViewPart.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/callhierarchy/CHViewPart.java index a070230819c..e47c198a41b 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/callhierarchy/CHViewPart.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/callhierarchy/CHViewPart.java @@ -332,7 +332,7 @@ public class CHViewPart extends ViewPart { } private void createActions() { - // action gruops + // action groups fOpenViewActionGroup= new OpenViewActionGroup(this); fOpenViewActionGroup.setSuppressCallHierarchy(true); fOpenViewActionGroup.setSuppressProperties(true); @@ -564,8 +564,14 @@ public class CHViewPart extends ViewPart { } protected void onShowSelectedReference(ISelection selection) { - fNavigationDetail= 0; - fNavigationNode= selectionToNode(selection); + CHNode node= selectionToNode(selection); + if (node != null && node == fNavigationNode && node.getReferenceCount() > 0) { + fNavigationDetail= (fNavigationDetail + 1) % node.getReferenceCount(); + } + else { + fNavigationDetail= 0; + } + fNavigationNode= node; showReference(); } @@ -719,27 +725,26 @@ public class CHViewPart extends ViewPart { } private void showReference() { - CHNode node= getReferenceNode(); - if (node != null) { - ITranslationUnit file= node.getFileOfReferences(); + if (fNavigationNode != null) { + ITranslationUnit file= fNavigationNode.getFileOfReferences(); if (file != null) { IWorkbenchPage page= getSite().getPage(); - if (node.getReferenceCount() > 0) { - long timestamp= node.getTimestamp(); + if (fNavigationNode.getReferenceCount() > 0) { + long timestamp= fNavigationNode.getTimestamp(); if (fNavigationDetail < 0) { fNavigationDetail= 0; } - else if (fNavigationDetail >= node.getReferenceCount()-1) { - fNavigationDetail= node.getReferenceCount()-1; + else if (fNavigationDetail >= fNavigationNode.getReferenceCount()-1) { + fNavigationDetail= fNavigationNode.getReferenceCount()-1; } - CHReferenceInfo ref= node.getReference(fNavigationDetail); + CHReferenceInfo ref= fNavigationNode.getReference(fNavigationDetail); Region region= new Region(ref.getOffset(), ref.getLength()); EditorOpener.open(page, file, region, timestamp); } else { try { - EditorOpener.open(page, node.getRepresentedDeclaration()); + EditorOpener.open(page, fNavigationNode.getRepresentedDeclaration()); } catch (CModelException e) { CUIPlugin.getDefault().log(e); } @@ -748,16 +753,6 @@ public class CHViewPart extends ViewPart { } } - private CHNode getReferenceNode() { - if (fNavigationNode != null) { - CHNode parent = fNavigationNode.getParent(); - if (parent instanceof CHMultiDefNode) { - return parent; - } - } - return fNavigationNode; - } - private int getReferenceCount(CHNode node) { if (node != null) { CHNode parent = node.getParent();