1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

Bug 380197 - F3 prefers using declaration to a real one

This commit is contained in:
Sergey Prigogin 2012-05-21 21:06:26 -07:00
parent 9a4f1087e2
commit cd8ca24457
2 changed files with 47 additions and 7 deletions

View file

@ -1247,4 +1247,32 @@ public abstract class CPPSelectionTestsAnyIndexer extends BaseSelectionTestsInde
assertEquals("ambiguous input: 2", e.getMessage());
}
}
// namespace ns {
// void func();
// }
// #include "test.h"
// using ns::func;
//
// void test() {
// func();
// }
public void testBug380197() throws Exception {
StringBuilder[] buffers= getContents(2);
String hcode= buffers[0].toString();
String scode= buffers[1].toString();
IFile hfile = importFile("test.h", hcode);
IFile file = importFile("test.cpp", scode);
waitUntilFileIsIndexed(index, file, MAX_WAIT_TIME);
int hoffset= hcode.indexOf("func");
int offset = scode.indexOf("func()");
IASTNode def = testF3(file, offset + 1);
assertTrue(def instanceof IASTName);
assertEquals("func", def.toString());
IASTFileLocation location = def.getFileLocation();
assertEquals(hfile.getLocation().toOSString(), location.getFileName());
assertEquals(hoffset, location.getNodeOffset());
}
}

View file

@ -57,6 +57,7 @@ import org.eclipse.cdt.core.dom.ast.IProblemBinding;
import org.eclipse.cdt.core.dom.ast.IType;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateDeclaration;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTranslationUnit;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTUsingDeclaration;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunction;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPSpecialization;
@ -321,15 +322,26 @@ class OpenDeclarationsJob extends Job implements ASTRunnable {
}
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;
IASTName[] astNames= ast.getDeclarationsInAST(binding);
ArrayList<IASTName> usingDeclarations = null;
for (int i = 0; i < astNames.length; i++) {
IASTName name = astNames[i];
if (name.isDefinition()) {
astNames[i]= null;
} else if (CPPVisitor.findAncestorWithType(name, ICPPASTUsingDeclaration.class) != null) {
if (usingDeclarations == null)
usingDeclarations = new ArrayList<IASTName>(1);
usingDeclarations.add(name);
astNames[i]= null;
}
}
declNames= ArrayUtil.removeNulls(IName.class, declNames);
IName[] declNames= ArrayUtil.removeNulls(astNames);
if (declNames.length == 0) {
declNames= index.findNames(binding, IIndex.FIND_DECLARATIONS | IIndex.SEARCH_ACROSS_LANGUAGE_BOUNDARIES);
declNames = index.findNames(binding, IIndex.FIND_DECLARATIONS | IIndex.SEARCH_ACROSS_LANGUAGE_BOUNDARIES);
}
// 'using' declarations are considered only when there are no other declarations.
if (declNames.length == 0 && usingDeclarations != null) {
declNames = usingDeclarations.toArray(new IName[usingDeclarations.size()]);
}
return declNames;
}