mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Navigation and CallHierarchy for 'extern "C"' declarations (bug 191989).
This commit is contained in:
parent
911444625c
commit
c835ad9217
6 changed files with 177 additions and 8 deletions
|
@ -273,8 +273,7 @@ public class CppCallHierarchyTest extends CallHierarchyBaseTest {
|
||||||
catch (Throwable e) {
|
catch (Throwable e) {
|
||||||
TreeItem tmp= item0; item0= item1; item1= tmp;
|
TreeItem tmp= item0; item0= item1; item1= tmp;
|
||||||
}
|
}
|
||||||
|
expandTreeItem(item0);
|
||||||
tv.setExpandedState(item0.getData(), true);
|
|
||||||
nextItem= checkTreeNode(item0, 0, "MyClass::method2()");
|
nextItem= checkTreeNode(item0, 0, "MyClass::method2()");
|
||||||
checkTreeNode(item0, 1, null); item0= nextItem;
|
checkTreeNode(item0, 1, null); item0= nextItem;
|
||||||
tv.setExpandedState(item0.getData(), true);
|
tv.setExpandedState(item0.getData(), true);
|
||||||
|
@ -288,4 +287,98 @@ public class CppCallHierarchyTest extends CallHierarchyBaseTest {
|
||||||
checkTreeNode(item1, 0, null);
|
checkTreeNode(item1, 0, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// void cfunc();
|
||||||
|
// void cxcpp() {
|
||||||
|
// cfunc();
|
||||||
|
// }
|
||||||
|
|
||||||
|
// extern "C" void cxcpp();
|
||||||
|
// void cppfunc() {
|
||||||
|
// cxcpp();
|
||||||
|
// }
|
||||||
|
public void testCPPCallsC() throws Exception {
|
||||||
|
StringBuffer[] content= getContentsForTest(2);
|
||||||
|
String cSource= content[0].toString();
|
||||||
|
String cppSource = content[1].toString();
|
||||||
|
IFile cFile= createFile(getProject(), "s.c", cSource);
|
||||||
|
IFile cppFile= createFile(getProject(), "s.cpp", cppSource);
|
||||||
|
IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
|
||||||
|
CEditor editor= (CEditor) IDE.openEditor(page, cFile);
|
||||||
|
waitForIndexer(fIndex, cppFile, CallHierarchyBaseTest.INDEXER_WAIT_TIME);
|
||||||
|
CCorePlugin.getIndexManager().joinIndexer(INDEXER_WAIT_TIME, NPM);
|
||||||
|
|
||||||
|
editor.selectAndReveal(cSource.indexOf("cfunc"), 2);
|
||||||
|
openCallHierarchy(editor);
|
||||||
|
Tree tree = getCHTreeViewer().getTree();
|
||||||
|
|
||||||
|
checkTreeNode(tree, 0, "cfunc()");
|
||||||
|
TreeItem node= checkTreeNode(tree, 0, 0, "cxcpp()");
|
||||||
|
checkTreeNode(tree, 0, 1, null);
|
||||||
|
|
||||||
|
expandTreeItem(node);
|
||||||
|
checkTreeNode(node, 0, "cppfunc()");
|
||||||
|
checkTreeNode(node, 1, null);
|
||||||
|
|
||||||
|
|
||||||
|
editor= (CEditor) IDE.openEditor(page, cppFile);
|
||||||
|
editor.selectAndReveal(cppSource.indexOf("cppfunc"), 2);
|
||||||
|
openCallHierarchy(editor, false);
|
||||||
|
tree = getCHTreeViewer().getTree();
|
||||||
|
|
||||||
|
checkTreeNode(tree, 0, "cppfunc()");
|
||||||
|
node= checkTreeNode(tree, 0, 0, "cxcpp()");
|
||||||
|
checkTreeNode(tree, 0, 1, null);
|
||||||
|
|
||||||
|
expandTreeItem(node);
|
||||||
|
checkTreeNode(node, 0, "cfunc()");
|
||||||
|
checkTreeNode(node, 1, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
// void cfunc() {
|
||||||
|
// cxcpp();
|
||||||
|
// }
|
||||||
|
|
||||||
|
// void cppfunc() {}
|
||||||
|
// extern "C" {void cxcpp() {
|
||||||
|
// cppfunc();
|
||||||
|
// }}
|
||||||
|
public void testCCallsCPP() throws Exception {
|
||||||
|
StringBuffer[] content= getContentsForTest(2);
|
||||||
|
String cSource= content[0].toString();
|
||||||
|
String cppSource = content[1].toString();
|
||||||
|
IFile cFile= createFile(getProject(), "s.c", cSource);
|
||||||
|
IFile cppFile= createFile(getProject(), "s.cpp", cppSource);
|
||||||
|
IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
|
||||||
|
CEditor editor= (CEditor) IDE.openEditor(page, cFile);
|
||||||
|
waitForIndexer(fIndex, cppFile, CallHierarchyBaseTest.INDEXER_WAIT_TIME);
|
||||||
|
CCorePlugin.getIndexManager().joinIndexer(INDEXER_WAIT_TIME, NPM);
|
||||||
|
|
||||||
|
editor.selectAndReveal(cSource.indexOf("cfunc"), 2);
|
||||||
|
openCallHierarchy(editor, false);
|
||||||
|
Tree tree = getCHTreeViewer().getTree();
|
||||||
|
|
||||||
|
checkTreeNode(tree, 0, "cfunc()");
|
||||||
|
TreeItem node= checkTreeNode(tree, 0, 0, "cxcpp()");
|
||||||
|
checkTreeNode(tree, 0, 1, null);
|
||||||
|
|
||||||
|
expandTreeItem(node);
|
||||||
|
checkTreeNode(node, 0, "cppfunc()");
|
||||||
|
checkTreeNode(node, 1, null);
|
||||||
|
|
||||||
|
|
||||||
|
editor= (CEditor) IDE.openEditor(page, cppFile);
|
||||||
|
editor.selectAndReveal(cppSource.indexOf("cppfunc"), 2);
|
||||||
|
openCallHierarchy(editor, true);
|
||||||
|
tree = getCHTreeViewer().getTree();
|
||||||
|
|
||||||
|
checkTreeNode(tree, 0, "cppfunc()");
|
||||||
|
node= checkTreeNode(tree, 0, 0, "cxcpp()");
|
||||||
|
checkTreeNode(tree, 0, 1, null);
|
||||||
|
|
||||||
|
expandTreeItem(node);
|
||||||
|
checkTreeNode(node, 0, "cfunc()");
|
||||||
|
checkTreeNode(node, 1, null);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -75,7 +75,6 @@ public class BasicIncludeBrowserTest extends IncludeBrowserBaseTest {
|
||||||
ICProject op= CProjectHelper.createCCProject("__ibTest_other__", "bin", IPDOMManager.ID_FAST_INDEXER);
|
ICProject op= CProjectHelper.createCCProject("__ibTest_other__", "bin", IPDOMManager.ID_FAST_INDEXER);
|
||||||
try {
|
try {
|
||||||
IndexerPreferences.set(op.getProject(), IndexerPreferences.KEY_INDEX_ALL_FILES, "true");
|
IndexerPreferences.set(op.getProject(), IndexerPreferences.KEY_INDEX_ALL_FILES, "true");
|
||||||
CCorePlugin.getIndexManager().reindex(op);
|
|
||||||
fIndex= CCorePlugin.getIndexManager().getIndex(new ICProject[] {getProject(), op});
|
fIndex= CCorePlugin.getIndexManager().getIndex(new ICProject[] {getProject(), op});
|
||||||
|
|
||||||
TestScannerProvider.sIncludes= new String[]{op.getProject().getLocation().toOSString()};
|
TestScannerProvider.sIncludes= new String[]{op.getProject().getLocation().toOSString()};
|
||||||
|
@ -84,7 +83,8 @@ public class BasicIncludeBrowserTest extends IncludeBrowserBaseTest {
|
||||||
IFile user= createFile(op.getProject(), "user.h", "");
|
IFile user= createFile(op.getProject(), "user.h", "");
|
||||||
IFile system= createFile(op.getProject(), "system.h", "");
|
IFile system= createFile(op.getProject(), "system.h", "");
|
||||||
IFile source= createFile(getProject().getProject(), "source.cpp", contents[0].toString());
|
IFile source= createFile(getProject().getProject(), "source.cpp", contents[0].toString());
|
||||||
waitForIndexer(fIndex, source, INDEXER_WAIT_TIME);
|
CCorePlugin.getIndexManager().reindex(op);
|
||||||
|
CCorePlugin.getIndexManager().joinIndexer(INDEXER_WAIT_TIME, NPM);
|
||||||
|
|
||||||
openIncludeBrowser(source);
|
openIncludeBrowser(source);
|
||||||
Tree tree = getIBTree();
|
Tree tree = getIBTree();
|
||||||
|
|
|
@ -964,4 +964,80 @@ public abstract class CPPSelectionTestsAnyIndexer extends BaseSelectionTestsInde
|
||||||
IEditorInput input = part.getEditorInput();
|
IEditorInput input = part.getEditorInput();
|
||||||
assertEquals("aheader.h", ((FileEditorInput)input).getFile().getName());
|
assertEquals("aheader.h", ((FileEditorInput)input).getFile().getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// void cfunc();
|
||||||
|
// void cxcpp() {
|
||||||
|
// cfunc();
|
||||||
|
// }
|
||||||
|
|
||||||
|
// extern "C" void cxcpp();
|
||||||
|
// void cppfunc() {
|
||||||
|
// cxcpp();
|
||||||
|
// }
|
||||||
|
public void testNavigationCppCallsC() throws Exception {
|
||||||
|
StringBuffer[] buffers= getContents(2);
|
||||||
|
String ccode= buffers[0].toString();
|
||||||
|
String scode= buffers[1].toString();
|
||||||
|
IFile cfile = importFile("s.c", ccode);
|
||||||
|
IFile cppfile = importFile("s.cpp", scode);
|
||||||
|
TestSourceReader.waitUntilFileIsIndexed(index, cppfile, MAX_WAIT_TIME);
|
||||||
|
IASTNode decl;
|
||||||
|
int offset1, offset2;
|
||||||
|
|
||||||
|
offset1 = scode.indexOf("cxcpp");
|
||||||
|
offset2 = scode.indexOf("cxcpp", offset1+1);
|
||||||
|
testF3(cppfile, offset1);
|
||||||
|
IEditorPart part = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
|
||||||
|
IEditorInput input = part.getEditorInput();
|
||||||
|
assertEquals("s.c", ((FileEditorInput)input).getFile().getName());
|
||||||
|
|
||||||
|
testF3(cppfile, offset2);
|
||||||
|
part = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
|
||||||
|
input = part.getEditorInput();
|
||||||
|
assertEquals("s.c", ((FileEditorInput)input).getFile().getName());
|
||||||
|
|
||||||
|
offset1 = ccode.indexOf("cxcpp");
|
||||||
|
testF3(cfile, offset1);
|
||||||
|
part = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
|
||||||
|
input = part.getEditorInput();
|
||||||
|
assertEquals("s.cpp", ((FileEditorInput)input).getFile().getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
// void cxcpp();
|
||||||
|
// void cfunc() {
|
||||||
|
// cxcpp();
|
||||||
|
// }
|
||||||
|
|
||||||
|
// void cppfunc() {}
|
||||||
|
// extern "C" {void cxcpp() {
|
||||||
|
// cppfunc();
|
||||||
|
// }}
|
||||||
|
public void testNavigationCCallsCpp() throws Exception {
|
||||||
|
StringBuffer[] buffers= getContents(2);
|
||||||
|
String ccode= buffers[0].toString();
|
||||||
|
String scode= buffers[1].toString();
|
||||||
|
IFile cfile = importFile("s.c", ccode);
|
||||||
|
IFile cppfile = importFile("s.cpp", scode);
|
||||||
|
TestSourceReader.waitUntilFileIsIndexed(index, cppfile, MAX_WAIT_TIME);
|
||||||
|
IASTNode decl;
|
||||||
|
int offset1, offset2;
|
||||||
|
|
||||||
|
offset1 = ccode.indexOf("cxcpp");
|
||||||
|
offset2 = ccode.indexOf("cxcpp", offset1+1);
|
||||||
|
testF3(cfile, offset1);
|
||||||
|
IEditorPart part = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
|
||||||
|
IEditorInput input = part.getEditorInput();
|
||||||
|
assertEquals("s.cpp", ((FileEditorInput)input).getFile().getName());
|
||||||
|
|
||||||
|
testF3(cfile, offset2);
|
||||||
|
part = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
|
||||||
|
input = part.getEditorInput();
|
||||||
|
assertEquals("s.cpp", ((FileEditorInput)input).getFile().getName());
|
||||||
|
|
||||||
|
offset1 = scode.indexOf("cxcpp");
|
||||||
|
testF3(cppfile, offset1);
|
||||||
|
part = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
|
||||||
|
input = part.getEditorInput();
|
||||||
|
assertEquals("s.c", ((FileEditorInput)input).getFile().getName());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -52,7 +52,7 @@ public class CHQueries {
|
||||||
private static void findCalledBy(IIndex index, IBinding callee, ICProject project, CalledByResult result)
|
private static void findCalledBy(IIndex index, IBinding callee, ICProject project, CalledByResult result)
|
||||||
throws CoreException {
|
throws CoreException {
|
||||||
if (callee != null) {
|
if (callee != null) {
|
||||||
IIndexName[] names= index.findReferences(callee);
|
IIndexName[] names= index.findNames(callee, IIndex.FIND_REFERENCES | IIndex.SEARCH_ACCROSS_LANGUAGE_BOUNDARIES);
|
||||||
for (int i = 0; i < names.length; i++) {
|
for (int i = 0; i < names.length; i++) {
|
||||||
IIndexName rname = names[i];
|
IIndexName rname = names[i];
|
||||||
IIndexName caller= rname.getEnclosingDefinition();
|
IIndexName caller= rname.getEnclosingDefinition();
|
||||||
|
|
|
@ -326,7 +326,7 @@ public class OpenDeclarationsAction extends SelectionParseAction {
|
||||||
IName[] declNames= ast.getDefinitionsInAST(binding);
|
IName[] declNames= ast.getDefinitionsInAST(binding);
|
||||||
if (declNames.length == 0) {
|
if (declNames.length == 0) {
|
||||||
// 2. Try definition in index
|
// 2. Try definition in index
|
||||||
declNames = index.findDefinitions(binding);
|
declNames = index.findNames(binding, IIndex.FIND_DEFINITIONS | IIndex.SEARCH_ACCROSS_LANGUAGE_BOUNDARIES);
|
||||||
}
|
}
|
||||||
return declNames;
|
return declNames;
|
||||||
}
|
}
|
||||||
|
@ -341,7 +341,7 @@ public class OpenDeclarationsAction extends SelectionParseAction {
|
||||||
}
|
}
|
||||||
declNames= (IName[]) ArrayUtil.removeNulls(IName.class, declNames);
|
declNames= (IName[]) ArrayUtil.removeNulls(IName.class, declNames);
|
||||||
if (declNames.length == 0) {
|
if (declNames.length == 0) {
|
||||||
declNames= index.findNames(binding, IIndex.FIND_DECLARATIONS);
|
declNames= index.findNames(binding, IIndex.FIND_DECLARATIONS | IIndex.SEARCH_ACCROSS_LANGUAGE_BOUNDARIES);
|
||||||
}
|
}
|
||||||
return declNames;
|
return declNames;
|
||||||
}
|
}
|
||||||
|
|
|
@ -261,7 +261,7 @@ public class IndexUI {
|
||||||
|
|
||||||
public static ICElementHandle[] findAllDefinitions(IIndex index, IBinding binding) throws CoreException {
|
public static ICElementHandle[] findAllDefinitions(IIndex index, IBinding binding) throws CoreException {
|
||||||
if (binding != null) {
|
if (binding != null) {
|
||||||
IIndexName[] defs= index.findDefinitions(binding);
|
IIndexName[] defs= index.findNames(binding, IIndex.FIND_DEFINITIONS | IIndex.SEARCH_ACCROSS_LANGUAGE_BOUNDARIES);
|
||||||
|
|
||||||
ArrayList result= new ArrayList();
|
ArrayList result= new ArrayList();
|
||||||
for (int i = 0; i < defs.length; i++) {
|
for (int i = 0; i < defs.length; i++) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue