diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/callhierarchy/CppCallHierarchyTest.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/callhierarchy/CppCallHierarchyTest.java index d8c727f4812..e68d8091121 100644 --- a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/callhierarchy/CppCallHierarchyTest.java +++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/callhierarchy/CppCallHierarchyTest.java @@ -273,8 +273,7 @@ public class CppCallHierarchyTest extends CallHierarchyBaseTest { catch (Throwable e) { TreeItem tmp= item0; item0= item1; item1= tmp; } - - tv.setExpandedState(item0.getData(), true); + expandTreeItem(item0); nextItem= checkTreeNode(item0, 0, "MyClass::method2()"); checkTreeNode(item0, 1, null); item0= nextItem; tv.setExpandedState(item0.getData(), true); @@ -288,4 +287,98 @@ public class CppCallHierarchyTest extends CallHierarchyBaseTest { 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); + } + } diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/includebrowser/BasicIncludeBrowserTest.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/includebrowser/BasicIncludeBrowserTest.java index 281db2ae657..0d37343fdd0 100644 --- a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/includebrowser/BasicIncludeBrowserTest.java +++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/includebrowser/BasicIncludeBrowserTest.java @@ -75,7 +75,6 @@ public class BasicIncludeBrowserTest extends IncludeBrowserBaseTest { ICProject op= CProjectHelper.createCCProject("__ibTest_other__", "bin", IPDOMManager.ID_FAST_INDEXER); try { IndexerPreferences.set(op.getProject(), IndexerPreferences.KEY_INDEX_ALL_FILES, "true"); - CCorePlugin.getIndexManager().reindex(op); fIndex= CCorePlugin.getIndexManager().getIndex(new ICProject[] {getProject(), op}); 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 system= createFile(op.getProject(), "system.h", ""); 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); Tree tree = getIBTree(); diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/selection/CPPSelectionTestsAnyIndexer.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/selection/CPPSelectionTestsAnyIndexer.java index 218a6efc32b..25c2e42b72b 100644 --- a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/selection/CPPSelectionTestsAnyIndexer.java +++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/selection/CPPSelectionTestsAnyIndexer.java @@ -964,4 +964,80 @@ public abstract class CPPSelectionTestsAnyIndexer extends BaseSelectionTestsInde IEditorInput input = part.getEditorInput(); 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()); + } } diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/callhierarchy/CHQueries.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/callhierarchy/CHQueries.java index 7811763b658..03f33108935 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/callhierarchy/CHQueries.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/callhierarchy/CHQueries.java @@ -52,7 +52,7 @@ public class CHQueries { private static void findCalledBy(IIndex index, IBinding callee, ICProject project, CalledByResult result) throws CoreException { 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++) { IIndexName rname = names[i]; IIndexName caller= rname.getEnclosingDefinition(); 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 65000bd199c..4f7ae33a0c7 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 @@ -326,7 +326,7 @@ public class OpenDeclarationsAction extends SelectionParseAction { IName[] declNames= ast.getDefinitionsInAST(binding); if (declNames.length == 0) { // 2. Try definition in index - declNames = index.findDefinitions(binding); + declNames = index.findNames(binding, IIndex.FIND_DEFINITIONS | IIndex.SEARCH_ACCROSS_LANGUAGE_BOUNDARIES); } return declNames; } @@ -341,7 +341,7 @@ public class OpenDeclarationsAction extends SelectionParseAction { } declNames= (IName[]) ArrayUtil.removeNulls(IName.class, declNames); 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; } diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/viewsupport/IndexUI.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/viewsupport/IndexUI.java index 880c16a90fc..27b76008b76 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/viewsupport/IndexUI.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/viewsupport/IndexUI.java @@ -261,7 +261,7 @@ public class IndexUI { public static ICElementHandle[] findAllDefinitions(IIndex index, IBinding binding) throws CoreException { 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(); for (int i = 0; i < defs.length; i++) {