diff --git a/core/org.eclipse.cdt.core.tests/indexer/org/eclipse/cdt/core/indexer/tests/IndexManagerTests.java b/core/org.eclipse.cdt.core.tests/indexer/org/eclipse/cdt/core/indexer/tests/IndexManagerTests.java index 3f9d0b0aab3..658c2f15d86 100644 --- a/core/org.eclipse.cdt.core.tests/indexer/org/eclipse/cdt/core/indexer/tests/IndexManagerTests.java +++ b/core/org.eclipse.cdt.core.tests/indexer/org/eclipse/cdt/core/indexer/tests/IndexManagerTests.java @@ -94,11 +94,12 @@ public class IndexManagerTests extends TestCase { suite.addTest(new IndexManagerTests("testRemoveProjectFromIndex")); suite.addTest(new IndexManagerTests("testRefs")); suite.addTest(new IndexManagerTests("testMacros")); + suite.addTest(new IndexManagerTests("testForwardDeclarations")); suite.addTest(new IndexManagerTests("testDependencyTree")); suite.addTest(new IndexManagerTests("testIndexShutdown")); return suite; - //return new TestSuite(IndexManagerTests.class); + // return new TestSuite(IndexManagerTests.class); } /* * Utils @@ -374,7 +375,7 @@ public class IndexManagerTests extends TestCase { IIndex ind = indexManager.getIndex(testProjectPath,true,true); assertTrue("Index exists for project",ind != null); - String [] typeRefEntryResultModel ={"EntryResult: word=typeRef/C/C/B/A, refs={ 1 }", "EntryResult: word=typeRef/E/e1/B/A, refs={ 1 }", "EntryResult: word=typeRef/V/x/B/A, refs={ 1 }"}; + String [] typeRefEntryResultModel ={"EntryResult: word=typeRef/C/C/B/A, refs={ 1 }", "EntryResult: word=typeRef/C/ForwardA/A, refs={ 1 }", "EntryResult: word=typeRef/E/e1/B/A, refs={ 1 }", "EntryResult: word=typeRef/V/x/B/A, refs={ 1 }"}; IEntryResult[] typerefresults = ind.queryEntries(IIndexConstants.TYPE_REF); if (typerefresults.length != typeRefEntryResultModel.length) @@ -496,6 +497,49 @@ public class IndexManagerTests extends TestCase { } } + public void testForwardDeclarations() throws Exception{ + //Add a new file to the project, give it some time to index + importFile("refTest.cpp","resources/indexer/refTest.cpp"); + //Enable indexing on the created project + //By doing this, we force the Index Manager to indexAll() + indexManager = CCorePlugin.getDefault().getCoreModel().getIndexManager(); + indexManager.setEnabled(testProject,true); + Thread.sleep(TIMEOUT); + //Make sure project got added to index + IPath testProjectPath = testProject.getFullPath(); + IIndex ind = indexManager.getIndex(testProjectPath,true,true); + assertTrue("Index exists for project",ind != null); + + IEntryResult[] fwdDclResults = ind.queryEntries("typeDecl/C/ForwardA/A".toCharArray()); + + String [] fwdDclModel = {"EntryResult: word=typeDecl/C/ForwardA/A, refs={ 1 }"}; + + if (fwdDclResults.length != fwdDclModel.length) + fail("Entry Result length different from model for forward declarations"); + + for (int i=0;iPreferences>Java>Code Generation>Code and Comments + */ +package org.eclipse.cdt.internal.ui.editor; + +import java.util.List; + +import org.eclipse.cdt.core.model.ICElement; +import org.eclipse.cdt.internal.ui.CPluginImages; +import org.eclipse.cdt.ui.CUIPlugin; +import org.eclipse.jface.action.Action; +import org.eclipse.jface.text.ITextSelection; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.ISelectionProvider; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.search.ui.SearchUI; +import org.eclipse.ui.IEditorDescriptor; +import org.eclipse.ui.IEditorRegistry; +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.texteditor.ITextEditor; + +/** + * @author bgheorgh + * + * To change the template for this generated type comment go to + * Window>Preferences>Java>Code Generation>Code and Comments + */ +public class SearchDialogAction extends Action { + + private static final String PREFIX= "SearchDialogAction."; + private static final String C_SEARCH_PAGE_ID= "org.eclipse.cdt.ui.CSearchPage"; + + private ISelectionProvider fSelectionProvider; + private ITextEditor fEditor; + + public SearchDialogAction(ISelectionProvider provider, CEditor editor) { + super(CUIPlugin.getResourceString(PREFIX + "label")); + setDescription(CUIPlugin.getResourceString(PREFIX + "description")); + setToolTipText(CUIPlugin.getResourceString(PREFIX + "tooltip")); + + if(provider instanceof CContentOutlinePage) { + CPluginImages.setImageDescriptors(this, CPluginImages.T_LCL, CPluginImages.IMG_MENU_OPEN_INCLUDE); + setText("Dialog"); // $NON-NLS + } + + fSelectionProvider= provider; + fEditor = editor; + } + + public void run() { + String search_name; + + ISelection selection= fSelectionProvider.getSelection(); + if(selection instanceof ITextSelection) { + search_name = ((ITextSelection)selection).getText(); + if(search_name.length() == 0) return; + } else { + ICElement element= getElement(selection); + if (element == null) { + return; + } + search_name = element.getElementName(); + } + + SearchUI.openSearchDialog(fEditor.getEditorSite().getWorkbenchWindow(),C_SEARCH_PAGE_ID); + +// // @@@ we rely on the internal functions of the Search plugin, since +// // none of these are actually exported. This is probably going to change +// // with 2.0. +// TextSearchResultCollector col = new TextSearchResultCollector(); +// try { +// //TextSearchPage +// //ProgressMonitor monitor = new ProgressMonitor(); +// //col.setProgressMonitor(monitor) +// SearchUI.activateSearchResultView(); +// //col.aboutToStart(); +// +// // We now have the element, start a search on the string +// //TextSearchEngine engine = new TextSearchEngine(); +// TextSearchScope scope= TextSearchScope.newWorkspaceScope(); +// // Add the extensions from the C editor definition for now +// // FIXME: For C/C++ not all files rely on extension to be C++ for +// String[] cexts = CoreModel.getDefault().getTranslationUnitExtensions(); +// for (int i = 0; i < cexts.length; i++) { +// scope.addExtension("*." + cexts[i]); +// } +//// scope.addExtension("*.c"); +//// scope.addExtension("*.h"); +//// scope.addExtension("*.cc"); +//// scope.addExtension("*.hh"); +// +// TextSearchOperation op= new TextSearchOperation( +// CUIPlugin.getWorkspace(), +// search_name, +// "", +// scope, +// col); +// +// +// //engine.search(CUIPlugin.getWorkspace(), element.getName(), +// // null, scope, col); +// IRunnableContext context= null; +// //context= getContainer().getRunnableContext(); +// +// Shell shell= new Shell(); // getShell(); +// if (context == null) +// context= new ProgressMonitorDialog(shell); +// +// +// try { +// context.run(true, true, op); +// } catch (InvocationTargetException ex) { +// ExceptionHandler.handle(ex, "Error","Error"); //$NON-NLS-2$ //$NON-NLS-1$ +// } catch (InterruptedException e) { +// } +// } catch (Exception e) {} +// + } + + + private static ICElement getElement(ISelection sel) { + if (!sel.isEmpty() && sel instanceof IStructuredSelection) { + List list= ((IStructuredSelection)sel).toList(); + if (list.size() == 1) { + Object element= list.get(0); + if (element instanceof ICElement) { + return (ICElement)element; + } + } + } + return null; + } + + public static boolean canActionBeAdded(ISelection selection) { + if(selection instanceof ITextSelection) { + return (((ITextSelection)selection).getLength() > 0); + } else { + return getElement(selection) != null; + } + } + + + public static String getEditorID(String name) { + IEditorRegistry registry = PlatformUI.getWorkbench().getEditorRegistry(); + if (registry != null) { + IEditorDescriptor descriptor = registry.getDefaultEditor(name); + if (descriptor != null) { + return descriptor.getId(); + } else { + return registry.getDefaultEditor().getId(); + } + } + return null; + } + +} \ No newline at end of file