1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-23 22:52:11 +02:00

Fix for 167162, navigation from method definition to its declaration.

This commit is contained in:
Markus Schorn 2006-12-18 16:37:00 +00:00
parent 3f08b69cae
commit bc2311e1aa
2 changed files with 38 additions and 19 deletions

View file

@ -190,7 +190,6 @@ import org.eclipse.cdt.internal.ui.actions.SelectionConverter;
import org.eclipse.cdt.internal.ui.dnd.TextEditorDropAdapter;
import org.eclipse.cdt.internal.ui.dnd.TextViewerDragAdapter;
import org.eclipse.cdt.internal.ui.search.actions.OpenDeclarationsAction;
import org.eclipse.cdt.internal.ui.search.actions.OpenDefinitionAction;
import org.eclipse.cdt.internal.ui.search.actions.SelectionSearchGroup;
import org.eclipse.cdt.internal.ui.text.CHeuristicScanner;
import org.eclipse.cdt.internal.ui.text.CPairMatcher;
@ -2280,9 +2279,10 @@ public class CEditor extends TextEditor implements ISelectionChangedListener, IR
action.setActionDefinitionId(ICEditorActionDefinitionIds.OPEN_DECL);
setAction("OpenDeclarations", action); //$NON-NLS-1$
action = new OpenDefinitionAction(this);
action.setActionDefinitionId(ICEditorActionDefinitionIds.OPEN_DEF);
setAction("OpenDefinition", action); //$NON-NLS-1$
// removed, see bug 167162
// action = new OpenDefinitionAction(this);
// action.setActionDefinitionId(ICEditorActionDefinitionIds.OPEN_DEF);
// setAction("OpenDefinition", action); //$NON-NLS-1$
// action = new OpenTypeHierarchyAction(this);
// action.setActionDefinitionId(ICEditorActionDefinitionIds.OPEN_TYPE_HIERARCHY);

View file

@ -34,6 +34,7 @@ import org.eclipse.cdt.core.index.IIndex;
import org.eclipse.cdt.core.index.IIndexManager;
import org.eclipse.cdt.core.model.ITranslationUnit;
import org.eclipse.cdt.core.model.IWorkingCopy;
import org.eclipse.cdt.core.parser.util.ArrayUtil;
import org.eclipse.cdt.ui.CUIPlugin;
import org.eclipse.cdt.internal.ui.editor.CEditor;
@ -77,30 +78,23 @@ public class OpenDeclarationsAction extends SelectionParseAction {
}
try {
IASTTranslationUnit ast = workingCopy.getAST(null, ITranslationUnit.AST_SKIP_ALL_HEADERS);
IASTTranslationUnit ast = workingCopy.getAST(index, ITranslationUnit.AST_SKIP_ALL_HEADERS);
IASTName[] selectedNames = workingCopy.getLanguage().getSelectedNames(ast, selectionStart, selectionLength);
if (selectedNames.length > 0 && selectedNames[0] != null) { // just right, only one name selected
IASTName searchName = selectedNames[0];
boolean isDefinition= searchName.isDefinition();
IBinding binding = searchName.resolveBinding();
if (binding != null && !(binding instanceof IProblemBinding)) {
// 1. Try definition
IName[] declNames = ast.getDefinitions(binding);
IName[] declNames= isDefinition ?
findDeclarations(index, ast, binding) :
findDefinitions(index, ast, binding);
if (declNames.length == 0) {
// 2. Try definition
declNames = index.findDefinitions(binding);
if (declNames.length == 0) {
// 3. Try declaration in TU
declNames = ast.getDeclarations(binding);
if (declNames.length == 0) {
// 4. Try declaration in Index
declNames = index.findDeclarations(binding);
}
}
declNames= isDefinition ?
findDefinitions(index, ast, binding) :
findDeclarations(index, ast, binding);
}
if (declNames.length > 0) {
@ -132,6 +126,31 @@ public class OpenDeclarationsAction extends SelectionParseAction {
return e.getStatus();
}
}
private IName[] findDefinitions(IIndex index, IASTTranslationUnit ast,
IBinding binding) throws CoreException {
IName[] declNames= ast.getDefinitionsInAST(binding);
if (declNames.length == 0) {
// 2. Try definition in index
declNames = index.findDefinitions(binding);
}
return declNames;
}
private IName[] findDeclarations(IIndex index, IASTTranslationUnit ast,
IBinding binding) throws CoreException {
IName[] declNames= ast.getDeclarationsInAST(binding);
for (int i = 0; i < declNames.length; i++) {
IName name = declNames[i];
if (name.isDefinition())
declNames[i]= null;
}
declNames= (IName[]) ArrayUtil.removeNulls(IName.class, declNames);
if (declNames.length == 0) {
declNames= index.findNames(binding, IIndex.FIND_DECLARATIONS);
}
return declNames;
}
}
public void run() {