From 939af66d2ee04152675a7e96c17320b1a9826134 Mon Sep 17 00:00:00 2001 From: John Camelon Date: Thu, 25 Sep 2003 19:51:50 +0000 Subject: [PATCH] Patch for Andrew Niefer partial fix for bug 43664 - Search cannot report matches outside of workspace. This enables non-ui reporting of matches outside the workspace. So clients of search, like code assist will get external results. We still need a resource to report a match to the search view so no external matches in the UI. core: Modify Matchlocator to not try and create a link if we have no resource, instead just use the path core.tests: added testNoResourceSearching() to OtherPatternTests ui: modify CSearchResultCollector to accept matches without resources, but not attempt to report them in the UI. * src/org/eclipse/cdt/internal/ui/search/CSearchResultCollector.java --- core/org.eclipse.cdt.core.tests/ChangeLog | 3 ++ .../core/search/tests/OtherPatternTests.java | 20 ++++++++++++ core/org.eclipse.cdt.core/search/ChangeLog | 4 +++ .../core/search/matching/MatchLocator.java | 32 ++++++++----------- core/org.eclipse.cdt.ui/ChangeLog | 5 +++ .../ui/search/CSearchResultCollector.java | 9 +++--- 6 files changed, 51 insertions(+), 22 deletions(-) diff --git a/core/org.eclipse.cdt.core.tests/ChangeLog b/core/org.eclipse.cdt.core.tests/ChangeLog index 4cd32fa10fa..9da3062a507 100644 --- a/core/org.eclipse.cdt.core.tests/ChangeLog +++ b/core/org.eclipse.cdt.core.tests/ChangeLog @@ -1,6 +1,9 @@ 2003-09-25 Hoda Amer Enabled CompleteParseASTExpressionTest.testPostfixTypenameIdentifier() +2003-09-25 Andrew Niefer + added testNoResourceSearching() to OtherPatternTests + 2003-09-24 Hoda Amer Added testNewTypeId(), testCastExpression(), testPostfixDynamicCast(), testPostfixReinterpretCast(), testPostfixStaticCast(), and testPostfixConstCast() diff --git a/core/org.eclipse.cdt.core.tests/search/org/eclipse/cdt/core/search/tests/OtherPatternTests.java b/core/org.eclipse.cdt.core.tests/search/org/eclipse/cdt/core/search/tests/OtherPatternTests.java index bd82287d193..4f85fe0ff6d 100644 --- a/core/org.eclipse.cdt.core.tests/search/org/eclipse/cdt/core/search/tests/OtherPatternTests.java +++ b/core/org.eclipse.cdt.core.tests/search/org/eclipse/cdt/core/search/tests/OtherPatternTests.java @@ -22,8 +22,10 @@ import org.eclipse.cdt.core.search.IMatch; import org.eclipse.cdt.core.search.SearchEngine; import org.eclipse.cdt.internal.core.CharOperation; import org.eclipse.cdt.internal.core.search.matching.FieldDeclarationPattern; +import org.eclipse.cdt.internal.core.search.matching.MatchLocator; import org.eclipse.cdt.internal.core.search.matching.NamespaceDeclarationPattern; import org.eclipse.cdt.internal.core.search.matching.OrPattern; +import org.eclipse.core.runtime.Path; /** * @author aniefer @@ -237,4 +239,22 @@ public class OtherPatternTests extends BaseSearchTest { Set matches = resultCollector.getSearchResults(); assertEquals( matches.size(), 3 ); } + + public void testNoResourceSearching(){ + String pluginRoot = org.eclipse.core.runtime.Platform.getPlugin("org.eclipse.cdt.core.tests").find(new Path("/")).getFile(); + String path = pluginRoot + "resources/search/include.h"; + + ICSearchPattern pattern = SearchEngine.createSearchPattern( "Head", CLASS, REFERENCES, true ); + + resultCollector.setProgressMonitor( monitor ); + + resultCollector.aboutToStart(); + MatchLocator matchLocator = new MatchLocator( pattern, resultCollector, scope, monitor ); + matchLocator.locateMatches( new String [] { path }, workspace, null ); + resultCollector.done(); + + Set matches = resultCollector.getSearchResults(); + assertEquals( matches.size(), 4 ); + } + } diff --git a/core/org.eclipse.cdt.core/search/ChangeLog b/core/org.eclipse.cdt.core/search/ChangeLog index 3ec796b272c..ac388b59b86 100644 --- a/core/org.eclipse.cdt.core/search/ChangeLog +++ b/core/org.eclipse.cdt.core/search/ChangeLog @@ -1,3 +1,7 @@ +2003-09-25 Andrew Niefer + - partial fix for 43664 Modify Matchlocator to not try and create a link if we have no + resource, instead just use the path + 2003-09-23 Andrew Niefer fix bug 43498 Search with ? fails on first letter of second word -modifications to CSearchPattern.scanForNames() diff --git a/core/org.eclipse.cdt.core/search/org/eclipse/cdt/internal/core/search/matching/MatchLocator.java b/core/org.eclipse.cdt.core/search/org/eclipse/cdt/internal/core/search/matching/MatchLocator.java index 7fd5df9fe74..4d694358253 100644 --- a/core/org.eclipse.cdt.core/search/org/eclipse/cdt/internal/core/search/matching/MatchLocator.java +++ b/core/org.eclipse.cdt.core/search/org/eclipse/cdt/internal/core/search/matching/MatchLocator.java @@ -277,15 +277,16 @@ public class MatchLocator implements ISourceElementRequestor, ICSearchConstants if( workspaceRoot != null ){ resource = workspaceRoot.getFileForLocation( path ); - if( resource == null ){ - IFile file = workspaceRoot.getFile( path ); - try{ - file.createLink( path, 0, null ); - } catch ( CoreException e ){ - file = null; - } - resource = file; - } +// if( resource == null ){ +// //TODO:What to do if the file is not in the workspace? +// IFile file = currentResource.getProject().getFile( inclusion.getName() ); +// try{ +// file.createLink( path, 0, null ); +// } catch ( CoreException e ){ +// file = null; +// } +// resource = file; +// } } resourceStack.addFirst( ( currentResource != null ) ? (Object)currentResource : (Object)currentPath ); @@ -368,23 +369,18 @@ public class MatchLocator implements ISourceElementRequestor, ICSearchConstants currentResource = workspaceRoot.findMember( pathString, true ); try{ - if( currentResource == null ){ - IPath path = new Path( pathString ); - IFile file = workspaceRoot.getFile( path ); - file.createLink( path, 0, null ); - project = file.getProject(); - } if( currentResource != null && currentResource instanceof IFile ){ IFile file = (IFile) currentResource; reader = new InputStreamReader( file.getContents() ); realPath = currentResource.getLocation(); project = file.getProject(); - } else continue; + } } catch ( CoreException e ){ continue; } } - } else { + } + if( currentResource == null ) { IPath path = new Path( pathString ); try { currentPath = path; @@ -407,7 +403,7 @@ public class MatchLocator implements ISourceElementRequestor, ICSearchConstants if( project != null ){ language = CoreModel.getDefault().hasCCNature( project ) ? ParserLanguage.CPP : ParserLanguage.C; } else { - //TODO no probject, what language do we use? + //TODO no project, what language do we use? language = ParserLanguage.CPP; } IScanner scanner = ParserFactory.createScanner( reader, realPath.toOSString(), scanInfo, ParserMode.COMPLETE_PARSE, language, this ); diff --git a/core/org.eclipse.cdt.ui/ChangeLog b/core/org.eclipse.cdt.ui/ChangeLog index d29a0223411..5dfa36fc154 100644 --- a/core/org.eclipse.cdt.ui/ChangeLog +++ b/core/org.eclipse.cdt.ui/ChangeLog @@ -1,6 +1,11 @@ 2003-09-25 Hoda Amer Solution to bug#43646: Code Assist won't work if missing end bracket +2003-09-25 Andrew Niefer + modify CSearchResultCollector to accept matches without resources, but not attempt to report + them in the UI. Addresses 43664 for non-ui clients of search + * src/org/eclipse/cdt/internal/ui/search/CSearchResultCollector.java + 2003-09-25 Alain Magloire Add HelpContext IDs in the preference page. diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/CSearchResultCollector.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/CSearchResultCollector.java index 19567d3213f..3b42c412ec0 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/CSearchResultCollector.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/CSearchResultCollector.java @@ -82,12 +82,13 @@ public class CSearchResultCollector extends BasicSearchResultCollector{ public boolean acceptMatch( IMatch match ) throws CoreException { BasicSearchMatch searchMatch = (BasicSearchMatch) match; - if( searchMatch.resource == null ) - return false; - + if( !super.acceptMatch( match ) ) return false; - + + if( searchMatch.resource == null ) + return false; + IMarker marker = searchMatch.resource.createMarker( SearchUI.SEARCH_MARKER ); HashMap markerAttributes = new HashMap( 2 );