diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/selection/CPPSelectionTestsNoIndexer.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/selection/CPPSelectionTestsNoIndexer.java index 1b23c6128ae..7bd7c2e3871 100644 --- a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/selection/CPPSelectionTestsNoIndexer.java +++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/selection/CPPSelectionTestsNoIndexer.java @@ -449,7 +449,7 @@ public class CPPSelectionTestsNoIndexer extends BaseUITestCase { assertEquals(((ASTNode)decl).getLength(), 1); } - public void _testBug86829B() throws Exception { + public void testBug86829B() throws Exception { StringBuffer buffer = new StringBuffer(); buffer.append("class X {\n"); //$NON-NLS-1$ buffer.append("public:\n"); //$NON-NLS-1$ @@ -459,8 +459,10 @@ public class CPPSelectionTestsNoIndexer extends BaseUITestCase { buffer.append("public:\n"); //$NON-NLS-1$ buffer.append("operator X();\n"); //$NON-NLS-1$ buffer.append("};\n"); //$NON-NLS-1$ + buffer.append("void test() {\n"); buffer.append("Y a;\n"); //$NON-NLS-1$ buffer.append("int c = X(a); // OK: a.operator X().operator int()\n"); //$NON-NLS-1$ + buffer.append("}\n"); //$NON-NLS-1$ String code = buffer.toString(); IFile file = importFile("testBug86829B.cpp", code); //$NON-NLS-1$ diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/actions/OpenDeclarationsAction.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/actions/OpenDeclarationsAction.java index 36ed13075b5..2dabaf23899 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/actions/OpenDeclarationsAction.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/actions/OpenDeclarationsAction.java @@ -26,6 +26,7 @@ import org.eclipse.swt.widgets.Display; import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.dom.IName; +import org.eclipse.cdt.core.dom.ast.DOMException; import org.eclipse.cdt.core.dom.ast.IASTFileLocation; import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.IASTPreprocessorIncludeStatement; @@ -33,6 +34,7 @@ import org.eclipse.cdt.core.dom.ast.IASTPreprocessorStatement; import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit; import org.eclipse.cdt.core.dom.ast.IBinding; import org.eclipse.cdt.core.dom.ast.IProblemBinding; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod; import org.eclipse.cdt.core.index.IIndex; import org.eclipse.cdt.core.index.IIndexManager; import org.eclipse.cdt.core.model.IWorkingCopy; @@ -95,17 +97,23 @@ public class OpenDeclarationsAction extends SelectionParseAction { boolean isDefinition= searchName.isDefinition(); IBinding binding = searchName.resolveBinding(); if (binding != null && !(binding instanceof IProblemBinding)) { - // 1. Try definition - IName[] declNames= isDefinition ? - findDeclarations(index, ast, binding) : - findDefinitions(index, ast, binding); - + IName[] declNames = findNames(index, ast, isDefinition, binding); if (declNames.length == 0) { - declNames= isDefinition ? - findDefinitions(index, ast, binding) : - findDeclarations(index, ast, binding); + // bug 86829, handle implicit methods. + if (binding instanceof ICPPMethod) { + ICPPMethod method= (ICPPMethod) binding; + if (method.isImplicit()) { + try { + IBinding clsBinding= method.getClassOwner(); + if (clsBinding != null && !(clsBinding instanceof IProblemBinding)) { + declNames= findNames(index, ast, false, clsBinding); + } + } catch (DOMException e) { + CCorePlugin.log(e); + } + } + } } - for (int i = 0; i < declNames.length; i++) { IASTFileLocation fileloc = declNames[i].getFileLocation(); if (fileloc != null) { @@ -183,6 +191,20 @@ public class OpenDeclarationsAction extends SelectionParseAction { } } + private IName[] findNames(IIndex index, IASTTranslationUnit ast, + boolean isDefinition, IBinding binding) throws CoreException { + IName[] declNames= isDefinition ? + findDeclarations(index, ast, binding) : + findDefinitions(index, ast, binding); + + if (declNames.length == 0) { + declNames= isDefinition ? + findDefinitions(index, ast, binding) : + findDeclarations(index, ast, binding); + } + return declNames; + } + private IName[] findDefinitions(IIndex index, IASTTranslationUnit ast, IBinding binding) throws CoreException { IName[] declNames= ast.getDefinitionsInAST(binding);