diff options
author | John Camelon | 2003-09-05 18:31:52 +0000 |
---|---|---|
committer | John Camelon | 2003-09-05 18:31:52 +0000 |
commit | d1d3dec2feb20881d256ba2b313387a0f71254d1 (patch) | |
tree | 935dc6a723eeb7127b893dccce09cb3d3713ce3a /core | |
parent | 4a6ab5ef38c2fe9813c6b824af7e82e3082c1fc4 (diff) | |
download | org.eclipse.cdt-d1d3dec2feb20881d256ba2b313387a0f71254d1.tar.gz org.eclipse.cdt-d1d3dec2feb20881d256ba2b313387a0f71254d1.tar.xz org.eclipse.cdt-d1d3dec2feb20881d256ba2b313387a0f71254d1.zip |
Patch for Andrew Niefer
Core:
- fix patterns & indexing for Enumerators
Core.Tests:
- Added testEnumerators to OtherPatternTests.java
- Modified resources/search/classDecl.cpp to include some enumerators
UI:
- enable Selected Resources scope
- populate dialog base on selection when opened from outline view
- fix small bug that found namespaces when searching for enumerations
- tweak sorting by path to consider line number second
Diffstat (limited to 'core')
16 files changed, 170 insertions, 100 deletions
diff --git a/core/org.eclipse.cdt.core.tests/ChangeLog b/core/org.eclipse.cdt.core.tests/ChangeLog index 5797c17151c..99c3e2d3473 100644 --- a/core/org.eclipse.cdt.core.tests/ChangeLog +++ b/core/org.eclipse.cdt.core.tests/ChangeLog @@ -1,3 +1,7 @@ +2003-09-05 Andrew Niefer
+ Added testEnumerators to OtherPatternTests.java
+ Modified resources/search/classDecl.cpp to include some enumerators
+
2003-09-05 John Camelon
Updated CompleteParseASTTest::testSimpleForLoop()
diff --git a/core/org.eclipse.cdt.core.tests/resources/search/classDecl.cpp b/core/org.eclipse.cdt.core.tests/resources/search/classDecl.cpp index 7932b7a79c9..8d4761548eb 100644 --- a/core/org.eclipse.cdt.core.tests/resources/search/classDecl.cpp +++ b/core/org.eclipse.cdt.core.tests/resources/search/classDecl.cpp @@ -16,7 +16,11 @@ namespace NS { }
class B: public A {
struct AA {};
- enum e {};
+ enum e {
+ One,
+ Two,
+ Three
+ };
using namespace NS2;
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 58cac22532a..2cabe76c4ba 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 @@ -176,4 +176,21 @@ public class OtherPatternTests extends BaseSearchTest { Set matches = resultCollector.getSearchResults(); assertEquals( matches.size(), 1 ); } + + public void testEnumerators(){ + ICSearchPattern pattern = SearchEngine.createSearchPattern( "One", FIELD, DECLARATIONS, true ); + + search( workspace, pattern, scope, resultCollector ); + + Set matches = resultCollector.getSearchResults(); + assertEquals( matches.size(), 1 ); + + pattern = SearchEngine.createSearchPattern( "NS::B::Two", FIELD, DECLARATIONS, true ); + + search( workspace, pattern, scope, resultCollector ); + + matches = resultCollector.getSearchResults(); + assertEquals( matches.size(), 1 ); + } + } diff --git a/core/org.eclipse.cdt.core/index/ChangeLog b/core/org.eclipse.cdt.core/index/ChangeLog index 1de62993f0c..a98ef4dd2ca 100644 --- a/core/org.eclipse.cdt.core/index/ChangeLog +++ b/core/org.eclipse.cdt.core/index/ChangeLog @@ -1,3 +1,6 @@ +2003-09-05 Andrew Niefer
+ - Modified how AbstractIndexer creates the fully qualified name for an enumerator (spec 7.2-10)
+
2003-08-26 Bogdan Gheorghe
- Removed header file extensions from being indexed (they
will be indexed via inclusion)
diff --git a/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/search/indexing/AbstractIndexer.java b/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/search/indexing/AbstractIndexer.java index fd705b5e053..963b92b61fc 100644 --- a/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/search/indexing/AbstractIndexer.java +++ b/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/search/indexing/AbstractIndexer.java @@ -78,11 +78,14 @@ public abstract class AbstractIndexer implements IIndexer, IIndexConstants, ICSe String name = en.getName(); IASTEnumerationSpecifier parent = en.getOwnerEnumerationSpecifier(); String[] parentName = parent.getFullyQualifiedName(); - String[] enumeratorFullName = new String[parentName.length + 1]; - int pos; - System.arraycopy(parentName, 0, enumeratorFullName, 0, pos = parentName.length); - enumeratorFullName[pos++] = name; - this.output.addRef(encodeEntry(enumeratorFullName,FIELD_DECL,FIELD_DECL_LENGTH)); + + //See spec 7.2-10, the the scope of the enumerator is the same level as the enumeration + String[] enumeratorFullName = new String[ parentName.length ]; + + System.arraycopy( parentName, 0, enumeratorFullName, 0, parentName.length); + enumeratorFullName[ parentName.length - 1 ] = name; + + this.output.addRef(encodeEntry( enumeratorFullName, FIELD_DECL, FIELD_DECL_LENGTH )); } } diff --git a/core/org.eclipse.cdt.core/search/ChangeLog b/core/org.eclipse.cdt.core/search/ChangeLog index a6e7b705d77..5fcf42bd3d2 100644 --- a/core/org.eclipse.cdt.core/search/ChangeLog +++ b/core/org.eclipse.cdt.core/search/ChangeLog @@ -1,3 +1,6 @@ +2003-09-05 Andrew Niefer
+ - fix searching for enumerators
+
2003-09-03 Andrew Niefer
- added CLASS_STRUCT to the SearchFor constants
- Modified CSearchPattern to handle CLASS_STRUCT
diff --git a/core/org.eclipse.cdt.core/search/org/eclipse/cdt/core/search/SearchEngine.java b/core/org.eclipse.cdt.core/search/org/eclipse/cdt/core/search/SearchEngine.java index 1cef9bb40c1..117c297ecab 100644 --- a/core/org.eclipse.cdt.core/search/org/eclipse/cdt/core/search/SearchEngine.java +++ b/core/org.eclipse.cdt.core/search/org/eclipse/cdt/core/search/SearchEngine.java @@ -163,17 +163,4 @@ public class SearchEngine implements ICSearchConstants{ collector.done(); } } - - /** - * @param _workspace - * @param _elementPattern - * @param _limitTo - * @param _scope - * @param _collector - */ - public void search(IWorkspace workspace, ICElement elementPattern, LimitTo limitTo, ICSearchScope scope, ICSearchResultCollector collector) { - // TODO Auto-generated method stub - - } - } diff --git a/core/org.eclipse.cdt.core/search/org/eclipse/cdt/internal/core/search/matching/FieldDeclarationPattern.java b/core/org.eclipse.cdt.core/search/org/eclipse/cdt/internal/core/search/matching/FieldDeclarationPattern.java index 121aa97fe3e..45eb9db0dd3 100644 --- a/core/org.eclipse.cdt.core/search/org/eclipse/cdt/internal/core/search/matching/FieldDeclarationPattern.java +++ b/core/org.eclipse.cdt.core/search/org/eclipse/cdt/internal/core/search/matching/FieldDeclarationPattern.java @@ -16,6 +16,8 @@ package org.eclipse.cdt.internal.core.search.matching; import java.io.IOException; import org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate; +import org.eclipse.cdt.core.parser.ast.IASTEnumerationSpecifier; +import org.eclipse.cdt.core.parser.ast.IASTEnumerator; import org.eclipse.cdt.core.parser.ast.IASTField; import org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement; import org.eclipse.cdt.core.parser.ast.IASTQualifiedNameElement; @@ -59,7 +61,10 @@ public class FieldDeclarationPattern extends CSearchPattern { } else if ( node instanceof IASTVariable ){ if( searchFor != VAR || !canAccept( limit ) ) return IMPOSSIBLE_MATCH; - } else return IMPOSSIBLE_MATCH; + } else if ( node instanceof IASTEnumerator ){ + if( searchFor != FIELD || !canAccept( limit ) ) + return IMPOSSIBLE_MATCH; + } else return IMPOSSIBLE_MATCH; String nodeName = ((IASTOffsetableNamedElement)node).getName(); @@ -70,7 +75,26 @@ public class FieldDeclarationPattern extends CSearchPattern { //check containing scopes //create char[][] out of full name, - String [] fullName = ((IASTQualifiedNameElement) node).getFullyQualifiedName(); + String [] fullName = null; + + if( node instanceof IASTEnumerator ){ + //Enumerators don't derive from IASTQualifiedElement, so make the fullName + //from the enumerations name. + // 7.2 - 10 : each enumerator declared by an enum-specifier is declared in the + //scope that immediately contains the enum-specifier. + IASTEnumerationSpecifier enumeration = ((IASTEnumerator)node).getOwnerEnumerationSpecifier(); + fullName = enumeration.getFullyQualifiedName(); + + String[] enumeratorFullName = new String[ fullName.length ]; + + System.arraycopy( fullName, 0, enumeratorFullName, 0, fullName.length); + enumeratorFullName[ fullName.length - 1 ] = nodeName; + + fullName = enumeratorFullName; + } else { + fullName = ((IASTQualifiedNameElement) node).getFullyQualifiedName(); + } + char [][] qualName = new char [ fullName.length - 1 ][]; for( int i = 0; i < fullName.length - 1; i++ ){ qualName[i] = fullName[i].toCharArray(); diff --git a/core/org.eclipse.cdt.ui/ChangeLog b/core/org.eclipse.cdt.ui/ChangeLog index a486b285f19..8cedadcd4e1 100644 --- a/core/org.eclipse.cdt.ui/ChangeLog +++ b/core/org.eclipse.cdt.ui/ChangeLog @@ -1,3 +1,10 @@ +2003-09-05 Andrew Niefer + C++ Search: + - enable Selected Resource Scope + - populate dialog base on selection when opened from outline view + - fix small bug that found namespaces when searching for enumerations + - tweak sorting by path to consider line number second + 2003-09-04 John Camelon First pass of parsing function bodies with X-Reference information. Updated IASTFactory/ISourceElementRequestor to include IASTCodeScope diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/CPluginResources.properties b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/CPluginResources.properties index c2ff084494f..1f619a48631 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/CPluginResources.properties +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/CPluginResources.properties @@ -299,7 +299,7 @@ SearchForReferencesAction.tooltip=Search for References to Name in Workspace SearchForReferencesAction.description=Searches for references to name in workspace # ------- SearchDialogAction --------------- -SearchDialogAction.label=Dialog +SearchDialogAction.label=C++ Search Dialog SearchDialogAction.tooltip=Opens Search Dialog SearchDialogAction.description=Opens Search Dialog diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/SearchDialogAction.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/SearchDialogAction.java index 680485ad26b..7b19bc1bf3a 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/SearchDialogAction.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/SearchDialogAction.java @@ -43,7 +43,6 @@ public class SearchDialogAction extends Action { if(provider instanceof CContentOutlinePage) { CPluginImages.setImageDescriptors(this, CPluginImages.T_LCL, CPluginImages.IMG_MENU_OPEN_INCLUDE); - setText("Dialog"); // $NON-NLS } fSelectionProvider= provider; diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/CSearchOperation.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/CSearchOperation.java index 117a09f0e12..8b94162781c 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/CSearchOperation.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/CSearchOperation.java @@ -17,7 +17,6 @@ import java.lang.reflect.InvocationTargetException; import java.util.Iterator; import java.util.List; -import org.eclipse.cdt.core.model.ICElement; import org.eclipse.cdt.core.search.ICSearchConstants; import org.eclipse.cdt.core.search.ICSearchPattern; import org.eclipse.cdt.core.search.ICSearchScope; @@ -38,12 +37,6 @@ import org.eclipse.ui.actions.WorkspaceModifyOperation; * Window>Preferences>Java>Code Generation>Code and Comments */ public class CSearchOperation extends WorkspaceModifyOperation implements ICSearchConstants{ - - public CSearchOperation(IWorkspace workspace, ICElement element, LimitTo limitTo, ICSearchScope scope, String scopeDescription, CSearchResultCollector collector) { - this( workspace, limitTo, scope, scopeDescription, collector ); - _elementPattern = element; - } - public CSearchOperation(IWorkspace workspace, String pattern, boolean caseSensitive, List searchFor, LimitTo limitTo, ICSearchScope scope, String scopeDescription, CSearchResultCollector collector) { this( workspace, limitTo, scope, scopeDescription, collector ); _stringPattern = pattern; @@ -69,27 +62,23 @@ public class CSearchOperation extends WorkspaceModifyOperation implements ICSear _collector.setProgressMonitor( monitor ); SearchEngine engine = new SearchEngine( CUIPlugin.getSharedWorkingCopies() ); - if( _elementPattern != null ){ - engine.search( _workspace, _elementPattern, _limitTo, _scope, _collector ); - } else { - ICSearchPattern pattern = null; - if( _searchFor.size() > 1 ){ - OrPattern orPattern = new OrPattern(); - for (Iterator iter = _searchFor.iterator(); iter.hasNext();) { - SearchFor element = (SearchFor)iter.next(); - orPattern.addPattern( SearchEngine.createSearchPattern( _stringPattern, element, _limitTo, _caseSensitive ) ); - } - - pattern = orPattern; - - } else { - Iterator iter = _searchFor.iterator(); - pattern = SearchEngine.createSearchPattern( _stringPattern, (SearchFor)iter.next(), _limitTo, _caseSensitive ); + + ICSearchPattern pattern = null; + if( _searchFor.size() > 1 ){ + OrPattern orPattern = new OrPattern(); + for (Iterator iter = _searchFor.iterator(); iter.hasNext();) { + SearchFor element = (SearchFor)iter.next(); + orPattern.addPattern( SearchEngine.createSearchPattern( _stringPattern, element, _limitTo, _caseSensitive ) ); } - engine.search( _workspace, pattern, _scope, _collector ); + pattern = orPattern; + + } else { + Iterator iter = _searchFor.iterator(); + pattern = SearchEngine.createSearchPattern( _stringPattern, (SearchFor)iter.next(), _limitTo, _caseSensitive ); } - + + engine.search( _workspace, pattern, _scope, _collector ); } /** @@ -98,11 +87,11 @@ public class CSearchOperation extends WorkspaceModifyOperation implements ICSear public String getSingularLabel() { String desc = null; - if( _elementPattern != null ){ - desc = _elementPattern.getElementName(); - } else { + //if( _elementPattern != null ){ + // desc = _elementPattern.getElementName(); + //} else { desc = _stringPattern; - } + //} String [] args = new String [] { desc, _scopeDescription }; @@ -111,7 +100,7 @@ public class CSearchOperation extends WorkspaceModifyOperation implements ICSear } else if( _limitTo == REFERENCES ){ return CSearchMessages.getFormattedString( "CSearchOperation.singularReferencesPostfix", args ); //$NON_NLS-1$ } else { - return CSearchMessages.getFormattedString( "CSearchOperation.singularOccurencesPostfix", args ); //$NON_NLS-1$ + return CSearchMessages.getFormattedString( "CSearchOperation.singularOccurrencesPostfix", args ); //$NON_NLS-1$ } } @@ -121,11 +110,11 @@ public class CSearchOperation extends WorkspaceModifyOperation implements ICSear public String getPluralLabelPattern() { String desc = null; - if( _elementPattern != null ){ - desc = _elementPattern.getElementName(); - } else { + // if( _elementPattern != null ){ + // desc = _elementPattern.getElementName(); + // } else { desc = _stringPattern; - } + // } String [] args = new String [] { desc, "{0}", _scopeDescription }; if( _limitTo == DECLARATIONS ){ @@ -133,7 +122,7 @@ public class CSearchOperation extends WorkspaceModifyOperation implements ICSear } else if ( _limitTo == REFERENCES ){ return CSearchMessages.getFormattedString( "CSearchOperation.pluralReferencesPostfix", args ); //$NON_NLS-1$ } else { - return CSearchMessages.getFormattedString( "CSearchOperation.pluralOccurencesPostfix", args ); //$NON_NLS-1$ + return CSearchMessages.getFormattedString( "CSearchOperation.pluralOccurrencesPostfix", args ); //$NON_NLS-1$ } } @@ -150,7 +139,7 @@ public class CSearchOperation extends WorkspaceModifyOperation implements ICSear private CSearchResultCollector _collector; private IWorkspace _workspace; - private ICElement _elementPattern; + //private ICElement _elementPattern; private ICSearchScope _scope; private String _stringPattern; private String _scopeDescription; diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/CSearchPage.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/CSearchPage.java index 65eae4c61d4..566325e2e78 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/CSearchPage.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/CSearchPage.java @@ -35,6 +35,7 @@ import org.eclipse.jface.dialogs.DialogPage; import org.eclipse.jface.dialogs.IDialogSettings; 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.jface.viewers.StructuredSelection; import org.eclipse.search.internal.ui.util.RowLayouter; @@ -103,14 +104,14 @@ public class CSearchPage extends DialogPage implements ISearchPage, ICSearchCons CSearchResultCollector collector= new CSearchResultCollector(); CSearchOperation op = null; - if (data.cElement != null && getPattern().equals(fInitialData.pattern)) { - op = new CSearchOperation(workspace, data.cElement, data.limitTo, scope, scopeDescription, collector); - if (data.limitTo == ICSearchConstants.REFERENCES) - CSearchUtil.warnIfBinaryConstant(data.cElement, getShell()); - } else { +// if (data.cElement != null && getPattern().equals(fInitialData.pattern)) { +// op = new CSearchOperation(workspace, data.cElement, data.limitTo, scope, scopeDescription, collector); +// if (data.limitTo == ICSearchConstants.REFERENCES) +// CSearchUtil.warnIfBinaryConstant(data.cElement, getShell()); +// } else { data.cElement= null; op = new CSearchOperation(workspace, data.pattern, data.isCaseSensitive, data.searchFor, data.limitTo, scope, scopeDescription, collector); - } + //} try { getContainer().getRunnableContext().run(true, true, op); @@ -484,6 +485,7 @@ public class CSearchPage extends DialogPage implements ISearchPage, ICSearchCons patterns[i]= ((SearchPatternData) fgPreviousSearchPatterns.get(patternCount - 1 - i)).pattern; return patterns; } + private IStructuredSelection asStructuredSelection() { IWorkbenchWindow wbWindow= PlatformUI.getWorkbench().getActiveWorkbenchWindow(); if (wbWindow != null) { @@ -491,10 +493,13 @@ public class CSearchPage extends DialogPage implements ISearchPage, ICSearchCons if (page != null) { IWorkbenchPart part= page.getActivePart(); if (part != null){ - //try { - // return SelectionConverter.getStructuredSelection(part); - //} catch (JavaModelException ex) { - //} + ISelectionProvider provider = part.getSite().getSelectionProvider(); + if( provider != null ){ + ISelection selection = provider.getSelection(); + if( selection instanceof IStructuredSelection ){ + return (IStructuredSelection)selection; + } + } } } } @@ -504,23 +509,31 @@ public class CSearchPage extends DialogPage implements ISearchPage, ICSearchCons private SearchPatternData determineInitValuesFrom( ICElement element ) { if( element == null ) return null; - //TODO search pattern data from element -// SearchFor searchFor = UNKNOWN_SEARCH_FOR; -// LimitTo limitTo = UNKNOWN_LIMIT_TO; -// -// String pattern = null; -// switch( element.getElementType() ) { -// /*case ICElement.PACKAGE_FRAGMENT: -// searchFor= PACKAGE; -// limitTo= REFERENCES; -// pattern= element.getElementName(); -// break;*/ -// } -// -// if( searchFor != UNKNOWN_SEARCH_FOR && limitTo != UNKNOWN_LIMIT_TO && pattern != null ) -// return new SearchPatternData( searchFor, limitTo, true, pattern, element ); -// - return null; + + List searchFor = new LinkedList(); + + //outliune view will confuse methods with functions, so if the + //name contains a "::", treat it as a method + String pattern = element.getElementName(); + boolean forceMethod = ( pattern.indexOf("::") != -1 ); + + switch ( element.getElementType() ){ + case ICElement.C_FUNCTION: if( forceMethod ) searchFor.add( METHOD ); + else searchFor.add( FUNCTION ); + break; + case ICElement.C_VARIABLE: searchFor.add( VAR ); break; + case ICElement.C_STRUCT: /* fall through to CLASS */ + case ICElement.C_CLASS: searchFor.add( CLASS_STRUCT ); break; + case ICElement.C_UNION: searchFor.add( UNION ); break; + case ICElement.C_ENUMERATOR: /* fall through to FIELD */ + case ICElement.C_FIELD: searchFor.add( FIELD ); break; + case ICElement.C_METHOD: searchFor.add( METHOD ); break; + case ICElement.C_NAMESPACE: searchFor.add( NAMESPACE ); break; + } + + LimitTo limitTo = ALL_OCCURRENCES; + + return new SearchPatternData( searchFor, limitTo, true, pattern, element ); } private SearchPatternData getPatternData() { @@ -587,7 +600,7 @@ public class CSearchPage extends DialogPage implements ISearchPage, ICSearchCons private static List fgPreviousSearchPatterns = new ArrayList(20); private Button[] fSearchFor; - private SearchFor[] fSearchForValues = { CLASS_STRUCT, FUNCTION, VAR, UNION, METHOD, FIELD, NAMESPACE, ENUM, null }; + private SearchFor[] fSearchForValues = { CLASS_STRUCT, FUNCTION, VAR, UNION, METHOD, FIELD, ENUM, NAMESPACE, null }; private String[] fSearchForText= { CSearchMessages.getString("CSearchPage.searchFor.classStruct"), //$NON-NLS-1$ 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 a1bb32adabc..4f8c5ef4f3a 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 @@ -55,7 +55,7 @@ public class CSearchResultCollector extends BasicSearchResultCollector{ _view = SearchUI.getSearchResultView(); CSearchResultLabelProvider labelProvider = new CSearchResultLabelProvider(); - labelProvider.setOrder( CSearchResultLabelProvider.SHOW_ELEMENT_CONTAINER ); + labelProvider.setOrder( CSearchResultLabelProvider.SHOW_PATH ); if( _view != null ){ _view.searchStarted( diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/CSearchScopeFactory.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/CSearchScopeFactory.java index b50f1e39d85..4cfeea7110d 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/CSearchScopeFactory.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/CSearchScopeFactory.java @@ -14,6 +14,7 @@ package org.eclipse.cdt.internal.ui.search; import java.util.HashSet; +import java.util.Iterator; import java.util.Set; import org.eclipse.cdt.core.model.ICElement; @@ -105,8 +106,14 @@ public class CSearchScopeFactory { * @return */ public ICSearchScope createCSearchScope(IStructuredSelection fStructuredSelection) { - // TODO Auto-generated method stub - return null; + Set cElements = new HashSet( fStructuredSelection.size() ); + + Iterator iter = fStructuredSelection.iterator(); + while( iter.hasNext() ){ + addCElements( cElements, (IAdaptable)iter.next() ); + } + + return createCSearchScope( cElements ); } } diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/PathNameSorter.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/PathNameSorter.java index f94383847c4..ea55a52dc75 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/PathNameSorter.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/PathNameSorter.java @@ -13,8 +13,9 @@ */ package org.eclipse.cdt.internal.ui.search; +import org.eclipse.cdt.core.search.IMatch; import org.eclipse.cdt.ui.CSearchResultLabelProvider; -import org.eclipse.core.resources.IMarker; +import org.eclipse.core.runtime.CoreException; import org.eclipse.jface.viewers.ILabelProvider; import org.eclipse.jface.viewers.Viewer; import org.eclipse.jface.viewers.ViewerSorter; @@ -38,14 +39,25 @@ public class PathNameSorter extends ViewerSorter { String name2 = null; ISearchResultViewEntry entry1 = null; ISearchResultViewEntry entry2 = null; + IMatch match1 = null; + IMatch match2 = null; if( e1 instanceof ISearchResultViewEntry ) { entry1 = (ISearchResultViewEntry)e1; - name1 = _labelProvider.getText( e1 ); + try { + match1 = (IMatch)entry1.getSelectedMarker().getAttribute( CSearchResultCollector.IMATCH ); + } catch (CoreException e) { + } + name1 = match1.getLocation().toString(); } if( e2 instanceof ISearchResultViewEntry ) { entry2 = (ISearchResultViewEntry)e2; - name2 = _labelProvider.getText( e2 ); + try { + match2 = (IMatch)entry2.getSelectedMarker().getAttribute( CSearchResultCollector.IMATCH ); + } catch (CoreException e) { + } + //name2 = _labelProvider.getText( e2 ); + name2 = match2.getLocation().toString(); } if( name1 == null ) @@ -59,13 +71,11 @@ public class PathNameSorter extends ViewerSorter { if( compare == 0 ){ int startPos1 = -1; int startPos2 = -1; - IMarker marker1 = entry1.getSelectedMarker(); - IMarker marker2 = entry2.getSelectedMarker(); - - if (marker1 != null) - startPos1 = marker1.getAttribute( IMarker.CHAR_START, -1 ); - if (marker2 != null) - startPos2 = marker2.getAttribute( IMarker.CHAR_START, -1 ); + + if (match1 != null) + startPos1 = match1.getStartOffset(); + if (match2 != null) + startPos2 = match2.getStartOffset(); compare = startPos1 - startPos2; } |