mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-23 00:45:28 +02:00
Fix for 86829, navigation of implicit class members.
This commit is contained in:
parent
0f535611ee
commit
3855937321
2 changed files with 34 additions and 10 deletions
|
@ -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$
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Add table
Reference in a new issue