mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-21 16:05:25 +02:00
Fix for 167162, navigation from method definition to its declaration.
This commit is contained in:
parent
3f08b69cae
commit
bc2311e1aa
2 changed files with 38 additions and 19 deletions
|
@ -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.TextEditorDropAdapter;
|
||||||
import org.eclipse.cdt.internal.ui.dnd.TextViewerDragAdapter;
|
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.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.search.actions.SelectionSearchGroup;
|
||||||
import org.eclipse.cdt.internal.ui.text.CHeuristicScanner;
|
import org.eclipse.cdt.internal.ui.text.CHeuristicScanner;
|
||||||
import org.eclipse.cdt.internal.ui.text.CPairMatcher;
|
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);
|
action.setActionDefinitionId(ICEditorActionDefinitionIds.OPEN_DECL);
|
||||||
setAction("OpenDeclarations", action); //$NON-NLS-1$
|
setAction("OpenDeclarations", action); //$NON-NLS-1$
|
||||||
|
|
||||||
action = new OpenDefinitionAction(this);
|
// removed, see bug 167162
|
||||||
action.setActionDefinitionId(ICEditorActionDefinitionIds.OPEN_DEF);
|
// action = new OpenDefinitionAction(this);
|
||||||
setAction("OpenDefinition", action); //$NON-NLS-1$
|
// action.setActionDefinitionId(ICEditorActionDefinitionIds.OPEN_DEF);
|
||||||
|
// setAction("OpenDefinition", action); //$NON-NLS-1$
|
||||||
|
|
||||||
// action = new OpenTypeHierarchyAction(this);
|
// action = new OpenTypeHierarchyAction(this);
|
||||||
// action.setActionDefinitionId(ICEditorActionDefinitionIds.OPEN_TYPE_HIERARCHY);
|
// action.setActionDefinitionId(ICEditorActionDefinitionIds.OPEN_TYPE_HIERARCHY);
|
||||||
|
|
|
@ -34,6 +34,7 @@ import org.eclipse.cdt.core.index.IIndex;
|
||||||
import org.eclipse.cdt.core.index.IIndexManager;
|
import org.eclipse.cdt.core.index.IIndexManager;
|
||||||
import org.eclipse.cdt.core.model.ITranslationUnit;
|
import org.eclipse.cdt.core.model.ITranslationUnit;
|
||||||
import org.eclipse.cdt.core.model.IWorkingCopy;
|
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.ui.CUIPlugin;
|
||||||
|
|
||||||
import org.eclipse.cdt.internal.ui.editor.CEditor;
|
import org.eclipse.cdt.internal.ui.editor.CEditor;
|
||||||
|
@ -77,30 +78,23 @@ public class OpenDeclarationsAction extends SelectionParseAction {
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
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);
|
IASTName[] selectedNames = workingCopy.getLanguage().getSelectedNames(ast, selectionStart, selectionLength);
|
||||||
|
|
||||||
if (selectedNames.length > 0 && selectedNames[0] != null) { // just right, only one name selected
|
if (selectedNames.length > 0 && selectedNames[0] != null) { // just right, only one name selected
|
||||||
IASTName searchName = selectedNames[0];
|
IASTName searchName = selectedNames[0];
|
||||||
|
boolean isDefinition= searchName.isDefinition();
|
||||||
IBinding binding = searchName.resolveBinding();
|
IBinding binding = searchName.resolveBinding();
|
||||||
if (binding != null && !(binding instanceof IProblemBinding)) {
|
if (binding != null && !(binding instanceof IProblemBinding)) {
|
||||||
// 1. Try definition
|
// 1. Try definition
|
||||||
IName[] declNames = ast.getDefinitions(binding);
|
IName[] declNames= isDefinition ?
|
||||||
|
findDeclarations(index, ast, binding) :
|
||||||
|
findDefinitions(index, ast, binding);
|
||||||
|
|
||||||
if (declNames.length == 0) {
|
if (declNames.length == 0) {
|
||||||
// 2. Try definition
|
declNames= isDefinition ?
|
||||||
declNames = index.findDefinitions(binding);
|
findDefinitions(index, ast, binding) :
|
||||||
|
findDeclarations(index, ast, 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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (declNames.length > 0) {
|
if (declNames.length > 0) {
|
||||||
|
@ -132,6 +126,31 @@ public class OpenDeclarationsAction extends SelectionParseAction {
|
||||||
return e.getStatus();
|
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() {
|
public void run() {
|
||||||
|
|
Loading…
Add table
Reference in a new issue