1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-25 18:05:33 +02:00

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
This commit is contained in:
John Camelon 2003-09-05 18:31:52 +00:00
parent 4a6ab5ef38
commit d1d3dec2fe
16 changed files with 170 additions and 100 deletions

View file

@ -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()

View file

@ -16,7 +16,11 @@ namespace NS {
}
class B: public A {
struct AA {};
enum e {};
enum e {
One,
Two,
Three
};
using namespace NS2;

View file

@ -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 );
}
}

View file

@ -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)

View file

@ -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 ));
}
}

View file

@ -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

View file

@ -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
}
}

View file

@ -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();

View file

@ -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

View file

@ -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

View file

@ -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;

View file

@ -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;

View file

@ -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$

View file

@ -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(

View file

@ -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 );
}
}

View file

@ -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;
}