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

Improvements for the Call Hierarchy

This commit is contained in:
Markus Schorn 2006-08-25 12:48:56 +00:00
parent cec3d1b1ef
commit 110e1adca5
12 changed files with 103 additions and 79 deletions

View file

@ -11,15 +11,21 @@
*******************************************************************************/
package org.eclipse.cdt.internal.corext.util;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.IPath;
import org.eclipse.cdt.core.model.CModelException;
import org.eclipse.cdt.core.model.CoreModel;
import org.eclipse.cdt.core.model.ICContainer;
import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.cdt.core.model.ICProject;
import org.eclipse.cdt.core.model.ISourceRoot;
import org.eclipse.cdt.core.model.ITranslationUnit;
import org.eclipse.cdt.core.model.IWorkingCopy;
import org.eclipse.cdt.ui.CUIPlugin;
import org.eclipse.cdt.internal.ui.util.EditorUtility;
@ -114,4 +120,57 @@ public class CModelUtil {
}
return null;
}
/**
* Returns the translation unit for the file given or <code>null</code>.
*/
public static ITranslationUnit findTranslationUnit(IFile file) {
if (CoreModel.isTranslationUnit(file)) {
ICProject cp= CoreModel.getDefault().getCModel().getCProject(file.getProject().getName());
if (cp != null) {
ICElement tu;
try {
tu = cp.findElement(file.getProjectRelativePath());
if (tu instanceof ITranslationUnit) {
return (ITranslationUnit) tu;
}
} catch (CModelException e) {
CUIPlugin.getDefault().log(e);
}
}
}
return null;
}
/**
* Returns the translation unit for the location given or <code>null</code>.
* @throws CModelException
*/
public static ITranslationUnit findTranslationUnitForLocation(IPath location, ICProject preferredProject) throws CModelException {
IFile[] files= ResourcesPlugin.getWorkspace().getRoot().findFilesForLocation(location);
if (files.length > 0) {
for (int i = 0; i < files.length; i++) {
IFile file = files[i];
ITranslationUnit tu= findTranslationUnit(file);
if (tu != null) {
return tu;
}
}
}
else {
CoreModel coreModel = CoreModel.getDefault();
ITranslationUnit tu= coreModel.createTranslationUnitFrom(preferredProject, location);
if (tu == null) {
ICProject[] projects= coreModel.getCModel().getCProjects();
for (int i = 0; i < projects.length && tu == null; i++) {
ICProject project = projects[i];
if (!preferredProject.equals(project)) {
tu= coreModel.createTranslationUnitFrom(project, location);
}
}
}
return tu;
}
return null;
}
}

View file

@ -12,6 +12,7 @@
package org.eclipse.cdt.internal.ui.callhierarchy;
import java.util.ArrayList;
import java.util.Arrays;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
@ -120,6 +121,7 @@ public class CHContentProvider extends AsyncTreeContentProvider {
private CHNode createRefbyNode(CHNode parent, ICElement element, CIndexReference[] refs) {
ITranslationUnit tu= CModelUtil.getTranslationUnit(element);
CHNode node= new CHNode(parent, tu, refs[0].getTimestamp(), element);
Arrays.sort(refs, CIndexReference.COMPARE_OFFSET);
for (int i = 0; i < refs.length; i++) {
CIndexReference reference = refs[i];
node.addReference(new CHReferenceInfo(reference.getOffset(), reference.getLength()));
@ -130,6 +132,7 @@ public class CHContentProvider extends AsyncTreeContentProvider {
private CHNode createReftoNode(CHNode parent, ITranslationUnit tu, ICElement[] elements, CIndexReference[] references) {
CIndexReference firstRef= references[0];
CHNode node= new CHNode(parent, tu, firstRef.getTimestamp(), elements[0]);
Arrays.sort(references, CIndexReference.COMPARE_OFFSET);
for (int i = 0; i < references.length; i++) {
CIndexReference reference = references[i];
node.addReference(new CHReferenceInfo(reference.getOffset(), reference.getLength()));

View file

@ -24,16 +24,18 @@ import org.eclipse.swt.widgets.Display;
import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.cdt.ui.CElementImageDescriptor;
import org.eclipse.cdt.ui.CElementLabelProvider;
import org.eclipse.cdt.internal.ui.viewsupport.CElementLabels;
import org.eclipse.cdt.internal.ui.viewsupport.CUILabelProvider;
import org.eclipse.cdt.internal.ui.viewsupport.ImageImageDescriptor;
public class CHLabelProvider extends LabelProvider implements IColorProvider {
private CElementLabelProvider fCLabelProvider= new CElementLabelProvider(CElementLabelProvider.SHOW_PARAMETERS);
// private Color fColorInactive;
private final static int LABEL_OPTIONS_SIMPLE= CElementLabels.ALL_FULLY_QUALIFIED | CElementLabels.M_PARAMETER_TYPES;
private final static int LABEL_OPTIONS_SHOW_FILES= LABEL_OPTIONS_SIMPLE | CElementLabels.MF_POST_FILE_QUALIFIED;
private CUILabelProvider fCLabelProvider= new CUILabelProvider(LABEL_OPTIONS_SIMPLE, 0);
private CHContentProvider fContentProvider;
private HashMap fCachedImages= new HashMap();
private boolean fShowFiles;
public CHLabelProvider(Display display, CHContentProvider cp) {
// fColorInactive= display.getSystemColor(SWT.COLOR_DARK_GRAY);
@ -57,22 +59,7 @@ public class CHLabelProvider extends LabelProvider implements IColorProvider {
CHNode node= (CHNode) element;
ICElement decl= node.getRepresentedDeclaration();
if (decl != null) {
String text= fCLabelProvider.getText(decl);
if (fShowFiles) {
// mstodo append filenames
// ICElement tu= null;
// while (tu == null && decl != null) {
// if (decl instanceof ITranslationUnit) {
// tu= decl;
// }
// else {
// decl= decl.getParent();
// }
// }
// if (tu != null) {
//
}
return text;
return fCLabelProvider.getText(decl);
}
}
return super.getText(element);
@ -118,16 +105,10 @@ public class CHLabelProvider extends LabelProvider implements IColorProvider {
}
public Color getForeground(Object element) {
// if (element instanceof CHNode) {
// CHNode node= (CHNode) element;
// if (!node.isActiveCode()) {
// return fColorInactive;
// }
// }
return null;
}
public void setShowFiles(boolean show) {
fShowFiles= show;
fCLabelProvider.setTextFlags(show ? LABEL_OPTIONS_SHOW_FILES : LABEL_OPTIONS_SIMPLE);
}
}

View file

@ -9,8 +9,8 @@ CHViewPart_FilterVariables_label=Filter Variables
CHViewPart_FilterVariables_tooltip=Hide Variables, Constents and Enumerators
CHViewPart_HideMacros_label=Hide Macros
CHViewPart_HideMacros_tooltip=Hides Macros
CHViewPart_ShowFiles_label=Show Files
CHViewPart_ShowFiles_tooltip=Show Files
CHViewPart_ShowFiles_label=Show File Names
CHViewPart_ShowFiles_tooltip=Show File Names
CHViewPart_NextReference_label=Next Reference
CHViewPart_NextReference_tooltip=Show Next Reference
CHHistoryListAction_Remove_label=Remove

View file

@ -83,6 +83,7 @@ public class CHViewPart extends ViewPart {
private static final String KEY_WORKING_SET_FILTER = "workingSetFilter"; //$NON-NLS-1$
private static final String KEY_FILTER_VARIABLES = "variableFilter"; //$NON-NLS-1$
private static final String KEY_FILTER_MACROS = "macroFilter"; //$NON-NLS-1$
private static final String KEY_SHOW_FILES= "showFilesInLabels"; //$NON-NLS-1$
private IMemento fMemento;
private boolean fShowsMessage;
@ -208,12 +209,17 @@ public class CHViewPart extends ViewPart {
boolean referencedBy= true;
boolean filterVariables= false;
boolean filterMacros= false;
boolean showFiles= false;
if (fMemento != null) {
filterVariables= TRUE.equals(fMemento.getString(KEY_FILTER_VARIABLES));
filterMacros= TRUE.equals(fMemento.getString(KEY_FILTER_MACROS));
showFiles= TRUE.equals(fMemento.getString(KEY_SHOW_FILES));
}
fLabelProvider.setShowFiles(showFiles);
fShowFilesInLabelsAction.setChecked(showFiles);
fReferencedByAction.setChecked(referencedBy);
fMakesReferenceToAction.setChecked(!referencedBy);
fContentProvider.setComputeReferencedBy(referencedBy);
@ -237,6 +243,7 @@ public class CHViewPart extends ViewPart {
}
memento.putString(KEY_FILTER_MACROS, String.valueOf(fFilterMacrosAction.isChecked()));
memento.putString(KEY_FILTER_VARIABLES, String.valueOf(fFilterVariablesAction.isChecked()));
memento.putString(KEY_SHOW_FILES, String.valueOf(fShowFilesInLabelsAction.isChecked()));
super.saveState(memento);
}

View file

@ -192,7 +192,7 @@ public class MainActionGroup extends CViewActionGroup {
addSearchMenu(menu, celements);
menu.add(new Separator(IContextMenuConstants.GROUP_ADDITIONS));
menu.add(new Separator(IContextMenuConstants.GROUP_ADDITIONS + "-end")); //$NON-NLS-1$
menu.add(new Separator());
menu.add(new Separator(IContextMenuConstants.GROUP_PROPERTIES));
openViewActionGroup.fillContextMenu(menu);
crefactoringActionGroup.fillContextMenu(menu);

View file

@ -18,27 +18,11 @@ import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.cdt.core.model.*;
import org.eclipse.cdt.ui.CUIPlugin;
import org.eclipse.cdt.core.model.ITranslationUnit;
import org.eclipse.cdt.internal.corext.util.CModelUtil;
public class IBConversions {
public static ITranslationUnit fileToTU(IFile file) {
if (CoreModel.isTranslationUnit(file)) {
ICProject cp= CoreModel.getDefault().getCModel().getCProject(file.getProject().getName());
if (cp != null) {
ICElement tu;
try {
tu = cp.findElement(file.getProjectRelativePath());
if (tu instanceof ITranslationUnit) {
return (ITranslationUnit) tu;
}
} catch (CModelException e) {
CUIPlugin.getDefault().log(e);
}
}
}
return null;
}
public static IBNode selectionToNode(ISelection sel) {
if (sel instanceof IStructuredSelection) {
@ -79,7 +63,7 @@ public class IBConversions {
}
IFile file= (IFile) adaptable.getAdapter(IFile.class);
if (file != null) {
result= fileToTU(file);
result= CModelUtil.findTranslationUnit(file);
if (result != null) {
return result;
}

View file

@ -32,6 +32,8 @@ import org.eclipse.ui.part.ResourceTransfer;
import org.eclipse.cdt.core.model.ITranslationUnit;
import org.eclipse.cdt.internal.corext.util.CModelUtil;
public class IBDropTargetListener implements DropTargetListener {
private IBViewPart fIncludeBrowser;
@ -138,7 +140,7 @@ public class IBDropTargetListener implements DropTargetListener {
for (int i = 0; i < files.length; i++) {
IResource resource = files[i];
if (resource.getType() == IResource.FILE) {
ITranslationUnit tu= IBConversions.fileToTU((IFile) resource);
ITranslationUnit tu= CModelUtil.findTranslationUnit((IFile) resource);
if (tu != null) {
return tu;
}

View file

@ -13,14 +13,14 @@ package org.eclipse.cdt.internal.ui.includebrowser;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.IPath;
import org.eclipse.cdt.core.model.CModelException;
import org.eclipse.cdt.core.model.CoreModel;
import org.eclipse.cdt.core.model.ICProject;
import org.eclipse.cdt.core.model.ITranslationUnit;
import org.eclipse.cdt.internal.corext.util.CModelUtil;
import org.eclipse.cdt.internal.ui.util.CoreUtility;
public class IBFile {
@ -40,26 +40,7 @@ public class IBFile {
public IBFile(ICProject preferredProject, IPath location) throws CModelException {
fLocation= location;
IFile[] files= ResourcesPlugin.getWorkspace().getRoot().findFilesForLocation(location);
if (files.length > 0) {
for (int i = 0; i < files.length && fTU == null; i++) {
IFile file = files[i];
fTU= IBConversions.fileToTU(file);
}
}
else {
CoreModel coreModel = CoreModel.getDefault();
fTU= coreModel.createTranslationUnitFrom(preferredProject, location);
if (fTU == null) {
ICProject[] projects= coreModel.getCModel().getCProjects();
for (int i = 0; i < projects.length && fTU == null; i++) {
ICProject project = projects[i];
if (!preferredProject.equals(project)) {
fTU= coreModel.createTranslationUnitFrom(project, location);
}
}
}
}
fTU= CModelUtil.findTranslationUnitForLocation(location, preferredProject);
}
public IPath getLocation() {

View file

@ -49,6 +49,7 @@ import org.eclipse.cdt.internal.core.pdom.dom.PDOMBinding;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMFile;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMInclude;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMName;
import org.eclipse.cdt.internal.corext.util.CModelUtil;
public class CIndexQueries {
public static class IPDOMInclude {
@ -98,11 +99,7 @@ public class CIndexQueries {
private static ITranslationUnit toTranslationUnit(ICProject cproject, String pathStr) throws CModelException {
IPath path= Path.fromOSString(pathStr);
ICElement e= cproject.findElement(path);
if (e instanceof ITranslationUnit) {
return (ITranslationUnit) e;
}
return null;
return CModelUtil.findTranslationUnitForLocation(path, cproject);
}

View file

@ -11,10 +11,19 @@
package org.eclipse.cdt.internal.ui.missingapi;
import java.util.Comparator;
import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.model.ITranslationUnit;
public class CIndexReference {
public static final Comparator COMPARE_OFFSET = new Comparator() {
public int compare(Object o1, Object o2) {
CIndexReference r1= (CIndexReference) o1;
CIndexReference r2= (CIndexReference) o2;
return r1.fOffset - r2.fOffset;
}
};
private int fOffset;
private int fLength;
private ITranslationUnit fTranslationUnit;

View file

@ -7,6 +7,7 @@
*
* Contributors:
* QNX Software Systems - Initial API and implementation
* Markus Schorn (Wind River Systems)
*******************************************************************************/
package org.eclipse.cdt.internal.ui.util;
@ -258,7 +259,7 @@ public class EditorUtility {
}
if (input instanceof IStorage) {
return new ExternalEditorInput((IStorage)input, null);
return new ExternalEditorInput((IStorage)input);
}
return null;
}