1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

Fix for 201279, [Call Hierarchy] no indication for multiple calls

This commit is contained in:
Markus Schorn 2007-08-28 09:24:35 +00:00
parent 883825add9
commit 259d11d79b
8 changed files with 91 additions and 36 deletions

View file

@ -232,7 +232,7 @@ public class BasicCallHierarchyTest extends CallHierarchyBaseTest {
editor.selectAndReveal(content.indexOf("mem2"), 0); editor.selectAndReveal(content.indexOf("mem2"), 0);
openCallHierarchy(editor); openCallHierarchy(editor);
checkTreeNode(tree, 0, "s2::mem2"); checkTreeNode(tree, 0, "s2::mem2");
checkTreeNode(tree, 0, 0, "main()"); checkTreeNode(tree, 0, 0, "main() (2 matches)");
editor.selectAndReveal(content.indexOf("mem3"), 0); editor.selectAndReveal(content.indexOf("mem3"), 0);
openCallHierarchy(editor); openCallHierarchy(editor);
@ -255,7 +255,7 @@ public class BasicCallHierarchyTest extends CallHierarchyBaseTest {
editor.selectAndReveal(content.indexOf("mem2; //ref"), 0); editor.selectAndReveal(content.indexOf("mem2; //ref"), 0);
openCallHierarchy(editor); openCallHierarchy(editor);
checkTreeNode(tree, 0, "s2::mem2"); checkTreeNode(tree, 0, "s2::mem2");
checkTreeNode(tree, 0, 0, "main()"); checkTreeNode(tree, 0, 0, "main() (2 matches)");
editor.selectAndReveal(content.indexOf("mem4."), 0); editor.selectAndReveal(content.indexOf("mem4."), 0);
openCallHierarchy(editor); openCallHierarchy(editor);
@ -279,7 +279,7 @@ public class BasicCallHierarchyTest extends CallHierarchyBaseTest {
editor.selectAndReveal(content.indexOf("mem2"), 0); editor.selectAndReveal(content.indexOf("mem2"), 0);
openCallHierarchy(editor); openCallHierarchy(editor);
checkTreeNode(tree, 0, "s2::mem2"); checkTreeNode(tree, 0, "s2::mem2");
checkTreeNode(tree, 0, 0, "main()"); checkTreeNode(tree, 0, 0, "main() (2 matches)");
editor.selectAndReveal(content.indexOf("mem3"), 0); editor.selectAndReveal(content.indexOf("mem3"), 0);
openCallHierarchy(editor); openCallHierarchy(editor);
@ -302,7 +302,7 @@ public class BasicCallHierarchyTest extends CallHierarchyBaseTest {
editor.selectAndReveal(content.indexOf("mem2; //ref"), 0); editor.selectAndReveal(content.indexOf("mem2; //ref"), 0);
openCallHierarchy(editor); openCallHierarchy(editor);
checkTreeNode(tree, 0, "s2::mem2"); checkTreeNode(tree, 0, "s2::mem2");
checkTreeNode(tree, 0, 0, "main()"); checkTreeNode(tree, 0, 0, "main() (2 matches)");
editor.selectAndReveal(content.indexOf("mem4."), 0); editor.selectAndReveal(content.indexOf("mem4."), 0);
openCallHierarchy(editor); openCallHierarchy(editor);
@ -418,7 +418,7 @@ public class BasicCallHierarchyTest extends CallHierarchyBaseTest {
editor.selectAndReveal(content.indexOf("mem2"), 0); editor.selectAndReveal(content.indexOf("mem2"), 0);
openCallHierarchy(editor); openCallHierarchy(editor);
checkTreeNode(tree, 0, "u2::mem2"); checkTreeNode(tree, 0, "u2::mem2");
checkTreeNode(tree, 0, 0, "main()"); checkTreeNode(tree, 0, 0, "main() (2 matches)");
editor.selectAndReveal(content.indexOf("mem3"), 0); editor.selectAndReveal(content.indexOf("mem3"), 0);
openCallHierarchy(editor); openCallHierarchy(editor);
@ -441,7 +441,7 @@ public class BasicCallHierarchyTest extends CallHierarchyBaseTest {
editor.selectAndReveal(content.indexOf("mem2; //ref"), 0); editor.selectAndReveal(content.indexOf("mem2; //ref"), 0);
openCallHierarchy(editor); openCallHierarchy(editor);
checkTreeNode(tree, 0, "u2::mem2"); checkTreeNode(tree, 0, "u2::mem2");
checkTreeNode(tree, 0, 0, "main()"); checkTreeNode(tree, 0, 0, "main() (2 matches)");
editor.selectAndReveal(content.indexOf("mem4."), 0); editor.selectAndReveal(content.indexOf("mem4."), 0);
openCallHierarchy(editor); openCallHierarchy(editor);
@ -465,7 +465,7 @@ public class BasicCallHierarchyTest extends CallHierarchyBaseTest {
editor.selectAndReveal(content.indexOf("mem2"), 0); editor.selectAndReveal(content.indexOf("mem2"), 0);
openCallHierarchy(editor); openCallHierarchy(editor);
checkTreeNode(tree, 0, "u2::mem2"); checkTreeNode(tree, 0, "u2::mem2");
checkTreeNode(tree, 0, 0, "main()"); checkTreeNode(tree, 0, 0, "main() (2 matches)");
editor.selectAndReveal(content.indexOf("mem3"), 0); editor.selectAndReveal(content.indexOf("mem3"), 0);
openCallHierarchy(editor); openCallHierarchy(editor);
@ -488,7 +488,7 @@ public class BasicCallHierarchyTest extends CallHierarchyBaseTest {
editor.selectAndReveal(content.indexOf("mem2; //ref"), 0); editor.selectAndReveal(content.indexOf("mem2; //ref"), 0);
openCallHierarchy(editor); openCallHierarchy(editor);
checkTreeNode(tree, 0, "u2::mem2"); checkTreeNode(tree, 0, "u2::mem2");
checkTreeNode(tree, 0, 0, "main()"); checkTreeNode(tree, 0, 0, "main() (2 matches)");
editor.selectAndReveal(content.indexOf("mem4."), 0); editor.selectAndReveal(content.indexOf("mem4."), 0);
openCallHierarchy(editor); openCallHierarchy(editor);

View file

@ -17,6 +17,7 @@ import org.eclipse.jface.text.ITextSelection;
import org.eclipse.jface.viewers.TreeViewer; import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.swt.SWTException; import org.eclipse.swt.SWTException;
import org.eclipse.swt.widgets.TreeItem; import org.eclipse.swt.widgets.TreeItem;
import org.eclipse.ui.IViewReference;
import org.eclipse.ui.IWorkbenchPage; import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.PartInitException; import org.eclipse.ui.PartInitException;
import org.eclipse.ui.PlatformUI; import org.eclipse.ui.PlatformUI;
@ -52,6 +53,12 @@ public class CallHierarchyBaseTest extends BaseUITestCase {
fCProject= CProjectHelper.createCCProject(prjName, "bin", IPDOMManager.ID_FAST_INDEXER); fCProject= CProjectHelper.createCCProject(prjName, "bin", IPDOMManager.ID_FAST_INDEXER);
CCorePlugin.getIndexManager().joinIndexer(INDEXER_WAIT_TIME, NPM); CCorePlugin.getIndexManager().joinIndexer(INDEXER_WAIT_TIME, NPM);
fIndex= CCorePlugin.getIndexManager().getIndex(fCProject); 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 { protected void tearDown() throws Exception {

View file

@ -17,6 +17,7 @@ import java.util.Iterator;
import org.eclipse.jface.resource.ImageDescriptor; import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.viewers.IColorProvider; import org.eclipse.jface.viewers.IColorProvider;
import org.eclipse.jface.viewers.LabelProvider; import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.osgi.util.NLS;
import org.eclipse.swt.SWT; import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Color; import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Image; import org.eclipse.swt.graphics.Image;
@ -72,17 +73,23 @@ public class CHLabelProvider extends LabelProvider implements IColorProvider {
CHNode node= (CHNode) element; CHNode node= (CHNode) element;
ICElement decl= node.getOneRepresentedDeclaration(); ICElement decl= node.getOneRepresentedDeclaration();
if (decl != null) { if (decl != null) {
String label;
if (node.isMultiDef()) { if (node.isMultiDef()) {
int options= fCLabelProvider.getTextFlags(); int options= fCLabelProvider.getTextFlags();
fCLabelProvider.setTextFlags(LABEL_OPTIONS_SIMPLE); fCLabelProvider.setTextFlags(LABEL_OPTIONS_SIMPLE);
String result= fCLabelProvider.getText(decl); label= fCLabelProvider.getText(decl);
fCLabelProvider.setTextFlags(options); fCLabelProvider.setTextFlags(options);
return result;
} }
String label= fCLabelProvider.getText(decl); else {
label= fCLabelProvider.getText(decl);
if (node.isInitializer()) { if (node.isInitializer()) {
label= addInitializerDecoration(label); 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; return label;
} }
} }

View file

@ -22,6 +22,7 @@ public class CHMessages extends NLS {
public static String CHHistoryListAction_HistoryList_label; public static String CHHistoryListAction_HistoryList_label;
public static String CHHistoryListAction_OpenHistory_label; public static String CHHistoryListAction_OpenHistory_label;
public static String CHHistoryListAction_Remove_label; public static String CHHistoryListAction_Remove_label;
public static String CHLabelProvider_matches;
public static String CHViewPart_emptyPageMessage; public static String CHViewPart_emptyPageMessage;
public static String CHViewPart_FilterVariables_label; public static String CHViewPart_FilterVariables_label;
public static String CHViewPart_FilterVariables_tooltip; public static String CHViewPart_FilterVariables_tooltip;

View file

@ -34,6 +34,7 @@ CHViewPart_Title_callees=Calls from {0} - in {1}
CHViewPart_FocusOn_label=Focus On ''{0}'' CHViewPart_FocusOn_label=Focus On ''{0}''
CHViewPart_Open_label=Open CHViewPart_Open_label=Open
CHViewPart_Open_tooltip=Open CHViewPart_Open_tooltip=Open
CHLabelProvider_matches=matches
CHViewPart_OpenReference_label=Open Reference CHViewPart_OpenReference_label=Open Reference
CHHistoryDropDownAction_ClearHistory_label=Clear History CHHistoryDropDownAction_ClearHistory_label=Clear History
CHHistoryListAction_HistoryDialog_title=Call Hierarchy History CHHistoryListAction_HistoryDialog_title=Call Hierarchy History

View file

@ -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;
}
}

View file

@ -26,7 +26,7 @@ public class CHMultiDefNode extends CHNode {
fChildren= new CHNode[elements.length]; fChildren= new CHNode[elements.length];
for (int i = 0; i < elements.length; i++) { for (int i = 0; i < elements.length; i++) {
ICElement element = elements[i]; ICElement element = elements[i];
fChildren[i]= new CHNode(this, null, 0, element); fChildren[i]= new CHMultiDefChildNode(this, tu, timestamp, element);
} }
} }

View file

@ -332,7 +332,7 @@ public class CHViewPart extends ViewPart {
} }
private void createActions() { private void createActions() {
// action gruops // action groups
fOpenViewActionGroup= new OpenViewActionGroup(this); fOpenViewActionGroup= new OpenViewActionGroup(this);
fOpenViewActionGroup.setSuppressCallHierarchy(true); fOpenViewActionGroup.setSuppressCallHierarchy(true);
fOpenViewActionGroup.setSuppressProperties(true); fOpenViewActionGroup.setSuppressProperties(true);
@ -564,8 +564,14 @@ public class CHViewPart extends ViewPart {
} }
protected void onShowSelectedReference(ISelection selection) { protected void onShowSelectedReference(ISelection selection) {
CHNode node= selectionToNode(selection);
if (node != null && node == fNavigationNode && node.getReferenceCount() > 0) {
fNavigationDetail= (fNavigationDetail + 1) % node.getReferenceCount();
}
else {
fNavigationDetail= 0; fNavigationDetail= 0;
fNavigationNode= selectionToNode(selection); }
fNavigationNode= node;
showReference(); showReference();
} }
@ -719,27 +725,26 @@ public class CHViewPart extends ViewPart {
} }
private void showReference() { private void showReference() {
CHNode node= getReferenceNode(); if (fNavigationNode != null) {
if (node != null) { ITranslationUnit file= fNavigationNode.getFileOfReferences();
ITranslationUnit file= node.getFileOfReferences();
if (file != null) { if (file != null) {
IWorkbenchPage page= getSite().getPage(); IWorkbenchPage page= getSite().getPage();
if (node.getReferenceCount() > 0) { if (fNavigationNode.getReferenceCount() > 0) {
long timestamp= node.getTimestamp(); long timestamp= fNavigationNode.getTimestamp();
if (fNavigationDetail < 0) { if (fNavigationDetail < 0) {
fNavigationDetail= 0; fNavigationDetail= 0;
} }
else if (fNavigationDetail >= node.getReferenceCount()-1) { else if (fNavigationDetail >= fNavigationNode.getReferenceCount()-1) {
fNavigationDetail= node.getReferenceCount()-1; fNavigationDetail= fNavigationNode.getReferenceCount()-1;
} }
CHReferenceInfo ref= node.getReference(fNavigationDetail); CHReferenceInfo ref= fNavigationNode.getReference(fNavigationDetail);
Region region= new Region(ref.getOffset(), ref.getLength()); Region region= new Region(ref.getOffset(), ref.getLength());
EditorOpener.open(page, file, region, timestamp); EditorOpener.open(page, file, region, timestamp);
} }
else { else {
try { try {
EditorOpener.open(page, node.getRepresentedDeclaration()); EditorOpener.open(page, fNavigationNode.getRepresentedDeclaration());
} catch (CModelException e) { } catch (CModelException e) {
CUIPlugin.getDefault().log(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) { private int getReferenceCount(CHNode node) {
if (node != null) { if (node != null) {
CHNode parent = node.getParent(); CHNode parent = node.getParent();