1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-24 01:15:29 +02:00

Bug 399147 - Make 'Find Reference' find using-declarations

Change-Id: I0183dfb9a19efdadd127e5014f101a38ad04ff92
This commit is contained in:
Nathan Ridge 2016-12-12 05:39:55 -05:00
parent e252be5dd5
commit 2706699543
3 changed files with 26 additions and 1 deletions

View file

@ -209,6 +209,6 @@ public class NamespaceTests extends PDOMTestBase {
assertEquals(0, decls.length);
IName[] refs = pdom.findNames(variable1, IIndex.FIND_REFERENCES);
assertEquals(2, refs.length);
assertEquals(3, refs.length);
}
}

View file

@ -18,6 +18,8 @@ import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.dom.ast.IASTFileLocation;
import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IASTPreprocessorIncludeStatement;
import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPUsingDeclaration;
import org.eclipse.cdt.core.index.IIndexFile;
import org.eclipse.cdt.core.index.IIndexName;
import org.eclipse.cdt.core.index.IndexLocationFactory;
@ -77,6 +79,17 @@ public final class PDOMName implements IIndexFragmentName, IASTFileLocation {
break;
case IS_DECLARATION:
binding.addDeclaration(this);
// The name of a using-declaration is, in addition to the declaration of
// the using-declaration binding, a reference to its delegate bindings.
if (binding instanceof ICPPUsingDeclaration) {
for (IBinding delegate : ((ICPPUsingDeclaration) binding).getDelegates()) {
if (delegate instanceof PDOMBinding) {
((PDOMBinding) delegate).addReference(this);
}
}
}
break;
case IS_REFERENCE:
binding.addReference(this);

View file

@ -95,4 +95,16 @@ public class FindReferencesTest extends SearchTestBase {
assertEquals(1, matches.length);
assertNotNull(matches[0].getEnclosingElement());
}
// namespace N {
// void foo();
// }
// using N::foo;
// // empty file
public void testUsingDeclaration_399147() throws Exception {
int offset = fHeaderContents.indexOf("void foo") + 5;
CSearchQuery query = makeProjectQuery(offset, 3);
assertOccurrences(query, 1);
}
}