[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
[cdt-patch] Refactor C++ Search result collecting
|
This patch is a refactoring of the C++ search result collecting.
There are 2 new classes:
- BasicSearchMatch implements IMatch
- BasicSearchResultCollector implements ICSearchResultCollector
IMatch itself has been modified to reflect a minimum set of information
that will be returned by the search.
The old CSearchResultCollector now extends BasicSearchResultCollector and
the old Match is now gone.
The CSearchResultLabelProvider has been moved from
org.eclipse.cdt.internal.ui.search to org.eclipse.cdt.ui, and it has
been modified to reflect changes to IMatch.
The result of this is that anyone wishing to take advantage of the search
engine (ie ClassWizard ) can now do it without implementing their own
ICSearchResultCollector and IMatch objects.
-Andrew
Index: ChangeLog
===================================================================
RCS file: /home/tools/org.eclipse.cdt.ui/ChangeLog,v
retrieving revision 1.129
diff -u -r1.129 ChangeLog
--- ChangeLog 29 Jul 2003 14:28:40 -0000 1.129
+++ ChangeLog 29 Jul 2003 20:55:09 -0000
@@ -1,3 +1,10 @@
+2003-07-29 Andrew Niefer
+ - Refactoring Search Result Collecting:
+ * CSearchResultCollector now extends BasicSearchResultCollector
+ * CSearchResultLabelProvider moved to org.eclipse.cdt.ui
+ * CSearchResultLabelProvider modified to reflect changes to IMatch interface
+ * Deleted the class Match
+
2003-07-28 Sean Evoy
In order to meet certain internal guidelines and to test the makefile
generator, the build model replied to some answers with hard-coded information.
Index: src/org/eclipse/cdt/internal/ui/search/CSearchResultCollector.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/CSearchResultCollector.java,v
retrieving revision 1.6
diff -u -r1.6 CSearchResultCollector.java
--- src/org/eclipse/cdt/internal/ui/search/CSearchResultCollector.java 24 Jul 2003 14:20:05 -0000 1.6
+++ src/org/eclipse/cdt/internal/ui/search/CSearchResultCollector.java 29 Jul 2003 20:55:09 -0000
@@ -15,24 +15,17 @@
import java.text.MessageFormat;
import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Set;
-import org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate;
-import org.eclipse.cdt.core.parser.ast.*;
-import org.eclipse.cdt.core.search.ICSearchResultCollector;
+import org.eclipse.cdt.core.search.BasicSearchMatch;
+import org.eclipse.cdt.core.search.BasicSearchResultCollector;
import org.eclipse.cdt.core.search.IMatch;
-import org.eclipse.cdt.internal.ui.CPluginImages;
-import org.eclipse.cdt.ui.CElementImageDescriptor;
+import org.eclipse.cdt.ui.*;
import org.eclipse.core.resources.IMarker;
-import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.search.ui.ISearchResultView;
import org.eclipse.search.ui.SearchUI;
-import org.eclipse.swt.graphics.Point;
+
/**
* @author aniefer
@@ -40,10 +33,9 @@
* To change the template for this generated type comment go to
* Window>Preferences>Java>Code Generation>Code and Comments
*/
-public class CSearchResultCollector implements ICSearchResultCollector {
+public class CSearchResultCollector extends BasicSearchResultCollector{
public static final String IMATCH = "IMatchObject";
- private static final Point SMALL_SIZE= new Point(16, 16);
/**
*
@@ -51,20 +43,20 @@
public CSearchResultCollector() {
super();
}
-
- public CSearchResultCollector( boolean maintain ){
- this();
- _maintainOwnCollection = maintain;
- }
/* (non-Javadoc)
* @see org.eclipse.cdt.core.search.ICSearchResultCollector#aboutToStart()
*/
public void aboutToStart() {
+ super.aboutToStart();
+
_matchCount = 0;
_view = SearchUI.getSearchResultView();
+ CSearchResultLabelProvider labelProvider = new CSearchResultLabelProvider();
+ labelProvider.setOrder( CSearchResultLabelProvider.SHOW_ELEMENT_CONTAINER );
+
if( _view != null ){
_view.searchStarted(
null,//new ActionGroupFactory(),
@@ -72,7 +64,7 @@
_operation.getPluralLabelPattern(),
_operation.getImageDescriptor(),
CSearchPage.EXTENSION_POINT_ID,
- new CSearchResultLabelProvider(),
+ labelProvider,
new GotoMarkerAction(),
new GroupByKeyComputer(),
_operation
@@ -82,161 +74,36 @@
if( getProgressMonitor() != null && !getProgressMonitor().isCanceled() ){
getProgressMonitor().subTask( SEARCHING );
}
-
- if( _maintainOwnCollection ){
- _matches = new HashSet();
- }
}
- /* (non-Javadoc)
- * @see org.eclipse.cdt.core.search.ICSearchResultCollector#accept(org.eclipse.core.resources.IResource, int, int, java.lang.Object, int)
- */
- public void accept(
- IResource resource,
- int start,
- int end,
- IMatch enclosingObject,
- int accuracy)
- throws CoreException
+ public void acceptMatch( IMatch match ) throws CoreException
{
- IMarker marker = resource.createMarker( SearchUI.SEARCH_MARKER );
+ super.acceptMatch( match );
+
+ BasicSearchMatch searchMatch = (BasicSearchMatch) match;
+ if( searchMatch.resource == null )
+ return;
- Match match = (Match) enclosingObject;
+
+ IMarker marker = searchMatch.resource.createMarker( SearchUI.SEARCH_MARKER );
Object groupKey = match;
HashMap markerAttributes = new HashMap( 2 );
//we can hang any other info we want off the marker
- markerAttributes.put( IMarker.CHAR_START, new Integer( Math.max( start, 0 ) ) );
- markerAttributes.put( IMarker.CHAR_END, new Integer( Math.max( end, 0 ) ) );
- markerAttributes.put( IMATCH, enclosingObject );
+ markerAttributes.put( IMarker.CHAR_START, new Integer( Math.max( searchMatch.startOffset, 0 ) ) );
+ markerAttributes.put( IMarker.CHAR_END, new Integer( Math.max( searchMatch.endOffset, 0 ) ) );
+ markerAttributes.put( IMATCH, searchMatch );
marker.setAttributes( markerAttributes );
if( _view != null )
- _view.addMatch( match.name, groupKey, resource, marker );
+ _view.addMatch( searchMatch.name, groupKey, searchMatch.resource, marker );
- if( _maintainOwnCollection ){
- _matches.add( enclosingObject );
- }
_matchCount++;
}
- public void accept(
- IPath path,
- int start,
- int end,
- IMatch match,
- int accuracy)
- throws CoreException
- {
- if( _maintainOwnCollection )
- _matches.add( match );
- }
-
-
- /* (non-Javadoc)
- * @see org.eclipse.cdt.core.search.ICSearchResultCollector#createMatch(org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement)
- */
- public IMatch createMatch(ISourceElementCallbackDelegate node, IASTScope parent ) {
- String name = null;
- String parentName = "";
- IASTOffsetableNamedElement offsetable = null;
-
- if( parent instanceof IASTQualifiedNameElement ){
- String [] names = ((IASTQualifiedNameElement)parent).getFullyQualifiedName();
- for( int i = 0; i < names.length; i++ ){
- if( i > 0 )
- parentName += "::";
-
- parentName += names[ i ];
- }
- }
-
- if( node instanceof IASTReference ){
- offsetable = (IASTOffsetableNamedElement) ((IASTReference)node).getReferencedElement();
- name = ((IASTReference)node).getName();
- } else if( node instanceof IASTOffsetableNamedElement ){
- offsetable = (IASTOffsetableNamedElement)node;
- name = offsetable.getName();
- } else {
- return null;
- }
-
- ImageDescriptor image = getImageDescriptor( offsetable );
- int adornmentFlags = computeAdornmentFlags( offsetable );
- IMatch match = new Match(name, parentName, image );//, node.getNameOffset(), name.length() );
-
- return match;
- }
-
- private ImageDescriptor getImageDescriptor( IASTOffsetableElement node ){
- ImageDescriptor imageDescriptor = null;
- if( node instanceof IASTClassSpecifier ){
- ASTClassKind kind = ((IASTClassSpecifier)node).getClassKind();
- if( kind == ASTClassKind.CLASS ){
- imageDescriptor = CPluginImages.DESC_OBJS_CLASS;
- } else if ( kind == ASTClassKind.STRUCT ){
- imageDescriptor = CPluginImages.DESC_OBJS_STRUCT;
- } else if ( kind == ASTClassKind.UNION ){
- imageDescriptor = CPluginImages.DESC_OBJS_UNION;
- }
- } else if ( node instanceof IASTNamespaceDefinition ){
- imageDescriptor = CPluginImages.DESC_OBJS_CONTAINER;
- } else if ( node instanceof IASTEnumerationSpecifier ){
- imageDescriptor = CPluginImages.DESC_OBJS_ENUMERATION;
- } else if ( node instanceof IASTField ){
- IASTField field = (IASTField)node;
- ASTAccessVisibility visibility = field.getVisiblity();
- if( visibility == ASTAccessVisibility.PUBLIC ){
- imageDescriptor = CPluginImages.DESC_OBJS_PUBLIC_FIELD;
- } else if ( visibility == ASTAccessVisibility.PROTECTED) {
- imageDescriptor = CPluginImages.DESC_OBJS_PROTECTED_FIELD;
- } else if ( visibility == ASTAccessVisibility.PRIVATE ) {
- imageDescriptor = CPluginImages.DESC_OBJS_PRIVATE_FIELD;
- }
- } else if ( node instanceof IASTVariable ){
- imageDescriptor = CPluginImages.DESC_OBJS_FIELD;
- } else if ( node instanceof IASTEnumerator ){
- imageDescriptor = CPluginImages.DESC_OBJS_ENUMERATOR;
- } else if ( node instanceof IASTMethod ){
- IASTMethod method = (IASTMethod) node;
- ASTAccessVisibility visibility = method.getVisiblity();
- if( visibility == ASTAccessVisibility.PUBLIC ){
- imageDescriptor = CPluginImages.DESC_OBJS_PUBLIC_METHOD;
- } else if ( visibility == ASTAccessVisibility.PROTECTED) {
- imageDescriptor = CPluginImages.DESC_OBJS_PROTECTED_METHOD;
- } else if ( visibility == ASTAccessVisibility.PRIVATE ) {
- imageDescriptor = CPluginImages.DESC_OBJS_PRIVATE_METHOD;
- }
- } else if ( node instanceof IASTFunction ){
- imageDescriptor = CPluginImages.DESC_OBJS_FUNCTION;
- }
-
- if( imageDescriptor != null) {
- int adornmentFlags = computeAdornmentFlags( node );
- return new CElementImageDescriptor( imageDescriptor, adornmentFlags, SMALL_SIZE );
- }
- return imageDescriptor;
- }
-
- private int computeAdornmentFlags(IASTOffsetableElement element ) {
- int flags = 0;
-
- if( element instanceof IASTVariable ){
- flags |= ((IASTVariable) element).isStatic() ? 0 : CElementImageDescriptor.STATIC;
- } else if ( element instanceof IASTMethod ){
- flags |= ((IASTMethod) element).isStatic() ? 0 : CElementImageDescriptor.STATIC;
- flags |= ((IASTMethod) element).isConst() ? 0 : CElementImageDescriptor.CONSTANT;
- flags |= ((IASTMethod) element).isVolatile() ? 0 : CElementImageDescriptor.VOLATILE;
- } else if( element instanceof IASTFunction ){
- flags |= ((IASTFunction) element).isStatic() ? 0 : CElementImageDescriptor.STATIC;
- }
-
- return flags;
- }
-
/* (non-Javadoc)
* @see org.eclipse.cdt.core.search.ICSearchResultCollector#done()
*/
@@ -275,10 +142,6 @@
_operation = operation;
}
- public Set getMatches(){
- return _matches;
- }
-
private static final String SEARCHING = CSearchMessages.getString("CSearchResultCollector.searching"); //$NON-NLS-1$
private static final String MATCH = CSearchMessages.getString("CSearchResultCollector.match"); //$NON-NLS-1$
private static final String MATCHES = CSearchMessages.getString("CSearchResultCollector.matches"); //$NON-NLS-1$
@@ -288,6 +151,4 @@
private CSearchOperation _operation;
private ISearchResultView _view;
private int _matchCount;
- private Set _matches;
- private boolean _maintainOwnCollection = false;
}
Index: src/org/eclipse/cdt/internal/ui/search/CSearchResultLabelProvider.java
===================================================================
RCS file: src/org/eclipse/cdt/internal/ui/search/CSearchResultLabelProvider.java
diff -N src/org/eclipse/cdt/internal/ui/search/CSearchResultLabelProvider.java
--- src/org/eclipse/cdt/internal/ui/search/CSearchResultLabelProvider.java 24 Jul 2003 14:20:05 -0000 1.4
+++ /dev/null 1 Jan 1970 00:00:00 -0000
@@ -1,133 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2003 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Common Public License v0.5
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v05.html
- *
- * Contributors:
- * IBM Corp. - Rational Software - initial implementation
- ******************************************************************************/
-/*
- * Created on Jun 18, 2003
- */
-package org.eclipse.cdt.internal.ui.search;
-
-import org.eclipse.cdt.internal.ui.CElementImageProvider;
-import org.eclipse.cdt.ui.CElementLabelProvider;
-import org.eclipse.cdt.ui.CUIPlugin;
-import org.eclipse.core.resources.IMarker;
-import org.eclipse.core.resources.IResource;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.jface.resource.ImageDescriptor;
-import org.eclipse.jface.viewers.LabelProvider;
-import org.eclipse.search.ui.ISearchResultViewEntry;
-import org.eclipse.swt.graphics.Image;
-
-/**
- * @author aniefer
- *
- * To change the template for this generated type comment go to
- * Window>Preferences>Java>Code Generation>Code and Comments
- */
-public class CSearchResultLabelProvider extends LabelProvider {
-
- public static final int SHOW_ELEMENT_CONTAINER = 1; //default
- public static final int SHOW_CONTAINER_ELEMENT = 2;
- public static final int SHOW_PATH = 3;
-
- public final static int DEFAULT_TEXTFLAGS = CElementLabels.ROOT_VARIABLE |
- CElementLabels.M_PARAMETER_TYPES |
- CElementLabels.M_APP_RETURNTYPE |
- CElementLabels.REFERENCED_ROOT_POST_QUALIFIED;
-
- public static final String POTENTIAL_MATCH = CSearchMessages.getString("CSearchResultLabelProvider.potentialMatch"); //$NON-NLS-1$
-
- public CSearchResultLabelProvider(){
- _sortOrder = SHOW_ELEMENT_CONTAINER;
- //_imageProvider = new CElementImageProvider();
- //_labelProvider = new CElementLabelProvider();
- }
-
- public Image getImage( Object element ) {
- if( !( element instanceof ISearchResultViewEntry ) ){
- return null;
- }
-
- ISearchResultViewEntry viewEntry = (ISearchResultViewEntry)element;
- IMarker marker = viewEntry.getSelectedMarker();
- Match match = null;
- try {
- match = (Match) marker.getAttribute( CSearchResultCollector.IMATCH );
- } catch (CoreException e) {
- return null;
- }
-
- ImageDescriptor imageDescriptor = match.imageDesc;
-
- Image image = CUIPlugin.getImageDescriptorRegistry().get( imageDescriptor );
-
- return image;
- }
-
- public String getText( Object element ) {
- if( ! (element instanceof ISearchResultViewEntry ) ){
- return null;
- }
-
- ISearchResultViewEntry viewEntry = (ISearchResultViewEntry) element;
-
- IMarker marker = viewEntry.getSelectedMarker();
-
- Match match = null;
-
- try {
- match = (Match) marker.getAttribute(CSearchResultCollector.IMATCH);
- } catch (CoreException e) {
- return null;
- }
-
- IResource resource = marker.getResource();
-
- String result = null;
- String path = (resource != null ) ? resource.getFullPath().toString() : "";
-
- switch( getOrder() ){
- case SHOW_ELEMENT_CONTAINER:
- result = match.name + " - " + match.parent + " ( " + path + " )";
- break;
- case SHOW_PATH:
- result = path + " - " + match.parent + "::" + match.name;
- break;
- case SHOW_CONTAINER_ELEMENT:
- result = match.parent + "::" + match.name + " ( " + path + " )";
- break;
- }
-
- return result;
- }
-
- public int getOrder(){
- return _sortOrder;
- }
- public void setOrder(int orderFlag) {
- _sortOrder = orderFlag;
- }
-
- protected IMarker getMarker( Object o ){
- if( !( o instanceof ISearchResultViewEntry ) ){
- return null;
- }
-
- return ( (ISearchResultViewEntry)o ).getSelectedMarker();
- }
-
-
- private CElementImageProvider _imageProvider;
- private CElementLabelProvider _labelProvider;
-
- private int _sortOrder;
- private int _textFlags;
- private int _imageFlags;
-
-}
Index: src/org/eclipse/cdt/internal/ui/search/ElementNameSorter.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/ElementNameSorter.java,v
retrieving revision 1.1
diff -u -r1.1 ElementNameSorter.java
--- src/org/eclipse/cdt/internal/ui/search/ElementNameSorter.java 28 Jun 2003 19:56:52 -0000 1.1
+++ src/org/eclipse/cdt/internal/ui/search/ElementNameSorter.java 29 Jul 2003 20:55:09 -0000
@@ -13,6 +13,7 @@
*/
package org.eclipse.cdt.internal.ui.search;
+import org.eclipse.cdt.ui.*;
import org.eclipse.jface.viewers.ILabelProvider;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.jface.viewers.ViewerSorter;
Index: src/org/eclipse/cdt/internal/ui/search/GroupByKeyComputer.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/GroupByKeyComputer.java,v
retrieving revision 1.2
diff -u -r1.2 GroupByKeyComputer.java
--- src/org/eclipse/cdt/internal/ui/search/GroupByKeyComputer.java 15 Jul 2003 14:43:48 -0000 1.2
+++ src/org/eclipse/cdt/internal/ui/search/GroupByKeyComputer.java 29 Jul 2003 20:55:09 -0000
@@ -13,6 +13,7 @@
*/
package org.eclipse.cdt.internal.ui.search;
+import org.eclipse.cdt.core.search.IMatch;
import org.eclipse.core.resources.IMarker;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.search.ui.IGroupByKeyComputer;
@@ -34,13 +35,13 @@
return null;
}
- Match match = null;
+ IMatch match = null;
try {
- match = (Match) marker.getAttribute(CSearchResultCollector.IMATCH);
+ match = (IMatch) marker.getAttribute(CSearchResultCollector.IMATCH);
} catch (CoreException e) {
}
- return match.parent;
+ return match.getParentName();
}
}
Index: src/org/eclipse/cdt/internal/ui/search/Match.java
===================================================================
RCS file: src/org/eclipse/cdt/internal/ui/search/Match.java
diff -N src/org/eclipse/cdt/internal/ui/search/Match.java
--- src/org/eclipse/cdt/internal/ui/search/Match.java 24 Jul 2003 14:20:05 -0000 1.2
+++ /dev/null 1 Jan 1970 00:00:00 -0000
@@ -1,45 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2003 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Common Public License v0.5
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v05.html
- *
- * Contributors:
- * IBM Corp. - Rational Software - initial implementation
- ******************************************************************************/
-/*
- * Created on Jul 10, 2003
- */
-package org.eclipse.cdt.internal.ui.search;
-
-import org.eclipse.cdt.core.search.IMatch;
-import org.eclipse.jface.resource.ImageDescriptor;
-
-/**
- * @author aniefer
- *
- * To change the template for this generated type comment go to
- * Window>Preferences>Java>Code Generation>Code and Comments
- */
-public class Match implements IMatch{
-
- public String name;
- public String parent;
- public ImageDescriptor imageDesc;
- public int start;
- public int end;
-
- public Match( String name, String parent, ImageDescriptor image ){
- this.name = name;
- this.parent = parent;
- this.imageDesc = image;
- }
-
- public Match( String name, String parent, ImageDescriptor image, int start, int end ){
- this( name, parent, image );
- this.start = start;
- this.end = end;
- }
-
-}
\ No newline at end of file
Index: src/org/eclipse/cdt/internal/ui/search/ParentNameSorter.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/ParentNameSorter.java,v
retrieving revision 1.1
diff -u -r1.1 ParentNameSorter.java
--- src/org/eclipse/cdt/internal/ui/search/ParentNameSorter.java 28 Jun 2003 19:56:52 -0000 1.1
+++ src/org/eclipse/cdt/internal/ui/search/ParentNameSorter.java 29 Jul 2003 20:55:09 -0000
@@ -13,6 +13,7 @@
*/
package org.eclipse.cdt.internal.ui.search;
+import org.eclipse.cdt.ui.*;
import org.eclipse.jface.viewers.ILabelProvider;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.jface.viewers.ViewerSorter;
Index: src/org/eclipse/cdt/internal/ui/search/PathNameSorter.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/PathNameSorter.java,v
retrieving revision 1.1
diff -u -r1.1 PathNameSorter.java
--- src/org/eclipse/cdt/internal/ui/search/PathNameSorter.java 28 Jun 2003 19:56:52 -0000 1.1
+++ src/org/eclipse/cdt/internal/ui/search/PathNameSorter.java 29 Jul 2003 20:55:10 -0000
@@ -13,6 +13,7 @@
*/
package org.eclipse.cdt.internal.ui.search;
+import org.eclipse.cdt.ui.*;
import org.eclipse.core.resources.IMarker;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
Index: src/org/eclipse/cdt/ui/CSearchResultLabelProvider.java
===================================================================
RCS file: src/org/eclipse/cdt/ui/CSearchResultLabelProvider.java
diff -N src/org/eclipse/cdt/ui/CSearchResultLabelProvider.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ src/org/eclipse/cdt/ui/CSearchResultLabelProvider.java 29 Jul 2003 20:55:10 -0000
@@ -0,0 +1,165 @@
+/*******************************************************************************
+ * Copyright (c) 2003 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Common Public License v0.5
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v05.html
+ *
+ * Contributors:
+ * IBM Corp. - Rational Software - initial implementation
+ ******************************************************************************/
+/*
+ * Created on Jun 18, 2003
+ */
+package org.eclipse.cdt.ui;
+
+import org.eclipse.cdt.core.model.ICElement;
+import org.eclipse.cdt.core.search.IMatch;
+import org.eclipse.cdt.internal.ui.CPluginImages;
+import org.eclipse.cdt.internal.ui.search.CSearchMessages;
+import org.eclipse.cdt.internal.ui.search.CSearchResultCollector;
+import org.eclipse.core.resources.IMarker;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.jface.viewers.LabelProvider;
+import org.eclipse.search.ui.ISearchResultViewEntry;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.graphics.Point;
+
+/**
+ * @author aniefer
+ *
+ * To change the template for this generated type comment go to
+ * Window>Preferences>Java>Code Generation>Code and Comments
+ */
+public class CSearchResultLabelProvider extends LabelProvider {
+
+ public static final int SHOW_NAME_ONLY = 0; //default
+ public static final int SHOW_ELEMENT_CONTAINER = 1;
+ public static final int SHOW_CONTAINER_ELEMENT = 2;
+ public static final int SHOW_PATH = 3;
+
+ public static final String POTENTIAL_MATCH = CSearchMessages.getString("CSearchResultLabelProvider.potentialMatch"); //$NON-NLS-1$
+
+ public CSearchResultLabelProvider(){
+ _sortOrder = SHOW_NAME_ONLY;
+ }
+
+ public Image getImage( Object element ) {
+ IMatch match = null;
+
+ if( element instanceof ISearchResultViewEntry ){
+ ISearchResultViewEntry viewEntry = (ISearchResultViewEntry)element;
+ IMarker marker = viewEntry.getSelectedMarker();
+ try {
+ match = (IMatch) marker.getAttribute( CSearchResultCollector.IMATCH );
+ } catch (CoreException e) {
+ return null;
+ }
+ } else if ( element instanceof IMatch ){
+ match = (IMatch) element;
+ }
+
+ if( match == null )
+ return null;
+
+ ImageDescriptor imageDescriptor = null;
+
+ switch( match.getElementType() ){
+ case ICElement.C_CLASS: imageDescriptor = CPluginImages.DESC_OBJS_CLASS; break;
+ case ICElement.C_STRUCT: imageDescriptor = CPluginImages.DESC_OBJS_STRUCT; break;
+ case ICElement.C_UNION: imageDescriptor = CPluginImages.DESC_OBJS_UNION; break;
+ case ICElement.C_NAMESPACE: imageDescriptor = CPluginImages.DESC_OBJS_CONTAINER; break;
+ case ICElement.C_ENUMERATION: imageDescriptor = CPluginImages.DESC_OBJS_ENUMERATION; break;
+ case ICElement.C_FUNCTION: imageDescriptor = CPluginImages.DESC_OBJS_FUNCTION; break;
+ case ICElement.C_VARIABLE: imageDescriptor = CPluginImages.DESC_OBJS_FIELD; break;
+ case ICElement.C_ENUMERATOR: imageDescriptor = CPluginImages.DESC_OBJS_ENUMERATOR; break;
+ case ICElement.C_FIELD:
+ {
+ switch( match.getVisibility() ){
+ case ICElement.CPP_PUBLIC: imageDescriptor = CPluginImages.DESC_OBJS_PUBLIC_FIELD; break;
+ case ICElement.CPP_PRIVATE: imageDescriptor = CPluginImages.DESC_OBJS_PRIVATE_FIELD; break;
+ default: imageDescriptor = CPluginImages.DESC_OBJS_PROTECTED_FIELD; break;
+ }
+ break;
+ }
+ case ICElement.C_METHOD:
+ {
+ switch( match.getVisibility() ){
+ case ICElement.CPP_PUBLIC: imageDescriptor = CPluginImages.DESC_OBJS_PUBLIC_METHOD; break;
+ case ICElement.CPP_PRIVATE: imageDescriptor = CPluginImages.DESC_OBJS_PRIVATE_METHOD; break;
+ default: imageDescriptor = CPluginImages.DESC_OBJS_PROTECTED_METHOD; break;
+ }
+ break;
+ }
+ }
+
+ int flags = 0;
+ if( match.isStatic() ) flags |= CElementImageDescriptor.STATIC;
+ if( match.isConst() ) flags |= CElementImageDescriptor.CONSTANT;
+ if( match.isVolatile() ) flags |= CElementImageDescriptor.VOLATILE;
+
+ imageDescriptor = new CElementImageDescriptor( imageDescriptor, flags, SMALL_SIZE );
+
+ Image image = CUIPlugin.getImageDescriptorRegistry().get( imageDescriptor );
+
+ return image;
+ }
+
+ public String getText( Object element ) {
+ IMatch match = null;
+
+ if( element instanceof ISearchResultViewEntry ){
+ ISearchResultViewEntry viewEntry = (ISearchResultViewEntry) element;
+
+ IMarker marker = viewEntry.getSelectedMarker();
+
+ try {
+ match = (IMatch) marker.getAttribute(CSearchResultCollector.IMATCH);
+ } catch (CoreException e) {
+ return null;
+ }
+ } else if( element instanceof IMatch ){
+ match = (IMatch) element;
+ }
+
+ if( match == null )
+ return null;
+
+ IResource resource = match.getResource();
+
+ String result = null;
+ String path = (resource != null ) ? resource.getFullPath().toString() : "";
+
+ switch( getOrder() ){
+ case SHOW_NAME_ONLY:
+ result = match.getName();
+ case SHOW_ELEMENT_CONTAINER:
+ result = match.getName() + " - " + match.getParentName() + " ( " + path + " )";
+ break;
+ case SHOW_PATH:
+ result = path + " - " + match.getParentName()+ "::" + match.getName();
+ break;
+ case SHOW_CONTAINER_ELEMENT:
+ result = match.getParentName() + "::" + match.getName() + " ( " + path + " )";
+ break;
+ }
+
+ return result;
+ }
+
+ public int getOrder(){
+ return _sortOrder;
+ }
+ public void setOrder(int orderFlag) {
+ _sortOrder = orderFlag;
+ }
+
+ private int _sortOrder;
+ private int _textFlags;
+ private int _imageFlags;
+
+ private static final Point SMALL_SIZE= new Point(16, 16);
+
+}
Index: search/org/eclipse/cdt/core/search/tests/BaseSearchTest.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.core.tests/search/org/eclipse/cdt/core/search/tests/BaseSearchTest.java,v
retrieving revision 1.1
diff -u -r1.1 BaseSearchTest.java
--- search/org/eclipse/cdt/core/search/tests/BaseSearchTest.java 24 Jul 2003 14:20:11 -0000 1.1
+++ search/org/eclipse/cdt/core/search/tests/BaseSearchTest.java 29 Jul 2003 20:54:57 -0000
@@ -84,7 +84,7 @@
IndexManager indexManager = CCorePlugin.getDefault().getCoreModel().getIndexManager();
indexManager.setEnabled(testProject,true);
- resultCollector = new CSearchResultCollector( true );
+ resultCollector = new CSearchResultCollector();
resultCollector.setProgressMonitor( monitor );
searchEngine = new SearchEngine();
Index: search/org/eclipse/cdt/core/search/tests/ClassDeclarationPatternTests.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.core.tests/search/org/eclipse/cdt/core/search/tests/ClassDeclarationPatternTests.java,v
retrieving revision 1.7
diff -u -r1.7 ClassDeclarationPatternTests.java
--- search/org/eclipse/cdt/core/search/tests/ClassDeclarationPatternTests.java 29 Jul 2003 12:40:10 -0000 1.7
+++ search/org/eclipse/cdt/core/search/tests/ClassDeclarationPatternTests.java 29 Jul 2003 20:54:57 -0000
@@ -14,15 +14,16 @@
package org.eclipse.cdt.core.search.tests;
import java.util.Iterator;
-import java.util.Set;
+import java.util.List;
import org.eclipse.cdt.core.search.ICSearchConstants;
import org.eclipse.cdt.core.search.ICSearchPattern;
+import org.eclipse.cdt.core.search.IMatch;
import org.eclipse.cdt.core.search.SearchEngine;
import org.eclipse.cdt.internal.core.search.CharOperation;
import org.eclipse.cdt.internal.core.search.matching.ClassDeclarationPattern;
import org.eclipse.cdt.internal.core.search.matching.MatchLocator;
-import org.eclipse.cdt.internal.ui.search.Match;
+//import org.eclipse.cdt.internal.ui.search.Match;
/**
@@ -48,7 +49,7 @@
search( workspace, pattern, scope, resultCollector );
- Set matches = resultCollector.getMatches();
+ List matches = resultCollector.getSearchResults();
assertEquals( matches.size(), 2 );
}
@@ -65,7 +66,7 @@
search( workspace, pattern, scope, resultCollector );
- Set matches = resultCollector.getMatches();
+ List matches = resultCollector.getSearchResults();
assertEquals( matches.size(), 1 );
}
@@ -73,7 +74,7 @@
ICSearchPattern pattern = SearchEngine.createSearchPattern( "A::B", TYPE, DECLARATIONS, true );
search( workspace, pattern, scope, resultCollector );
- Set matches = resultCollector.getMatches();
+ List matches = resultCollector.getSearchResults();
/* Test should find 1 match */
assertTrue( matches != null );
@@ -82,13 +83,13 @@
pattern = SearchEngine.createSearchPattern( "NS::NS2::a", TYPE, DECLARATIONS, true );
search( workspace, pattern, scope, resultCollector );
- matches = resultCollector.getMatches();
+ matches = resultCollector.getSearchResults();
assertTrue( matches != null );
pattern = SearchEngine.createSearchPattern( "NS::B::A", TYPE, DECLARATIONS, true );
search( workspace, pattern, scope, resultCollector );
- matches = resultCollector.getMatches();
+ matches = resultCollector.getSearchResults();
assertTrue( matches != null );
}
@@ -99,38 +100,38 @@
search( workspace, pattern, scope, resultCollector );
- Set matches = resultCollector.getMatches();
+ List matches = resultCollector.getSearchResults();
assertEquals( matches.size(), 1 );
pattern = SearchEngine.createSearchPattern( "NS::B::A", TYPE, DECLARATIONS, true );
search( workspace, pattern, scope, resultCollector );
- Set matches2 = resultCollector.getMatches();
+ List matches2 = resultCollector.getSearchResults();
assertTrue( matches2 != null );
assertEquals( matches2.size(), 1 );
Iterator iter = matches.iterator();
Iterator iter2 = matches2.iterator();
- Match match = (Match)iter.next();
- Match match2 = (Match)iter2.next();
+ IMatch match = (IMatch)iter.next();
+ IMatch match2 = (IMatch)iter2.next();
//assertTrue( match.path.equals( match2.path ) );
- assertEquals( match.start, match2.start );
- assertEquals( match.end, match2.end );
+ assertEquals( match.getStartOffset(), match2.getStartOffset() );
+ assertEquals( match.getEndOffset(), match2.getEndOffset() );
}
public void testWildcardQualification() {
ICSearchPattern pattern = SearchEngine.createSearchPattern( "::*::A", TYPE, DECLARATIONS, true );
search( workspace, pattern, scope, resultCollector );
- Set matches = resultCollector.getMatches();
+ List matches = resultCollector.getSearchResults();
assertEquals( matches.size(), 0 );
pattern = SearchEngine.createSearchPattern( "NS::*::A", TYPE, DECLARATIONS, false );
search( workspace, pattern, scope, resultCollector );
- matches = resultCollector.getMatches();
+ matches = resultCollector.getSearchResults();
assertEquals( matches.size(), 2 );
}
@@ -138,19 +139,19 @@
ICSearchPattern pattern = SearchEngine.createSearchPattern( "struct A", TYPE, DECLARATIONS, true );
search( workspace, pattern, scope, resultCollector );
- Set matches = resultCollector.getMatches();
+ List matches = resultCollector.getSearchResults();
assertEquals( matches.size(), 1 );
pattern = SearchEngine.createSearchPattern( "union u", TYPE, DECLARATIONS, true );
search( workspace, pattern, scope, resultCollector );
- matches = resultCollector.getMatches();
+ matches = resultCollector.getSearchResults();
assertEquals( matches.size(), 2 );
pattern = SearchEngine.createSearchPattern( "union ::*::u", TYPE, DECLARATIONS, true );
search( workspace, pattern, scope, resultCollector );
- matches = resultCollector.getMatches();
+ matches = resultCollector.getSearchResults();
assertEquals( matches.size(), 1 );
}
@@ -177,7 +178,7 @@
search( workspace, pattern, scope, resultCollector );
- Set matches = resultCollector.getMatches();
+ List matches = resultCollector.getSearchResults();
assertEquals( matches.size(), 1 );
@@ -186,7 +187,7 @@
search( workspace, pattern, scope, resultCollector );
- matches = resultCollector.getMatches();
+ matches = resultCollector.getSearchResults();
assertEquals( matches.size(), 1 );
}
@@ -196,7 +197,7 @@
search( workspace, pattern, scope, resultCollector );
- Set matches = resultCollector.getMatches();
+ List matches = resultCollector.getSearchResults();
assertEquals( matches.size(), 3 );
}
@@ -205,22 +206,22 @@
search( workspace, pattern, scope, resultCollector );
- Set matches = resultCollector.getMatches();
+ List matches = resultCollector.getSearchResults();
assertEquals( matches.size(), 1 );
- Match match = (Match) matches.iterator().next();
- assertTrue( match.parent.equals( "NS::B" ) );
+ IMatch match = (IMatch) matches.iterator().next();
+ assertTrue( match.getParentName().equals( "NS::B" ) );
}
public void testTypeReferenceVisibleByUsingDirective(){
ICSearchPattern pattern = SearchEngine.createSearchPattern( "::NS::NS2::a", STRUCT, REFERENCES, true );
search( workspace, pattern, scope, resultCollector );
- Set matches = resultCollector.getMatches();
+ List matches = resultCollector.getSearchResults();
assertEquals( matches.size(), 1 );
- Match match = (Match) matches.iterator().next();
- assertTrue( match.parent.equals( "NS::B" ) );
+ IMatch match = (IMatch) matches.iterator().next();
+ assertTrue( match.getParentName().equals( "NS::B" ) );
}
public void testEnumerationReferenceVisibleByInheritance(){
@@ -228,11 +229,11 @@
search( workspace, pattern, scope, resultCollector );
- Set matches = resultCollector.getMatches();
+ List matches = resultCollector.getSearchResults();
assertEquals( matches.size(), 1 );
- Match match = (Match) matches.iterator().next();
- assertTrue( match.parent.equals( "NS3::C" ) );
+ IMatch match = (IMatch) matches.iterator().next();
+ assertTrue( match.getParentName().equals( "NS3::C" ) );
}
}
Index: search/org/eclipse/cdt/core/search/tests/FunctionMethodPatternTests.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.core.tests/search/org/eclipse/cdt/core/search/tests/FunctionMethodPatternTests.java,v
retrieving revision 1.2
diff -u -r1.2 FunctionMethodPatternTests.java
--- search/org/eclipse/cdt/core/search/tests/FunctionMethodPatternTests.java 29 Jul 2003 12:40:10 -0000 1.2
+++ search/org/eclipse/cdt/core/search/tests/FunctionMethodPatternTests.java 29 Jul 2003 20:54:58 -0000
@@ -13,7 +13,7 @@
*/
package org.eclipse.cdt.core.search.tests;
-import java.util.Set;
+import java.util.List;
import org.eclipse.cdt.core.search.ICSearchPattern;
import org.eclipse.cdt.core.search.SearchEngine;
@@ -73,7 +73,7 @@
search( workspace, pattern, scope, resultCollector );
- Set matches = resultCollector.getMatches();
+ List matches = resultCollector.getSearchResults();
assertEquals( matches.size(), 1 );
}
@@ -83,7 +83,7 @@
search( workspace, pattern, scope, resultCollector );
- Set matches = resultCollector.getMatches();
+ List matches = resultCollector.getSearchResults();
assertEquals( matches.size(), 1 ); }
}
Index: search/org/eclipse/cdt/core/search/tests/OtherPatternTests.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.core.tests/search/org/eclipse/cdt/core/search/tests/OtherPatternTests.java,v
retrieving revision 1.2
diff -u -r1.2 OtherPatternTests.java
--- search/org/eclipse/cdt/core/search/tests/OtherPatternTests.java 29 Jul 2003 12:40:10 -0000 1.2
+++ search/org/eclipse/cdt/core/search/tests/OtherPatternTests.java 29 Jul 2003 20:54:58 -0000
@@ -13,15 +13,15 @@
*/
package org.eclipse.cdt.core.search.tests;
-import java.util.Set;
+import java.util.List;
import org.eclipse.cdt.core.search.ICSearchPattern;
+import org.eclipse.cdt.core.search.IMatch;
import org.eclipse.cdt.core.search.SearchEngine;
import org.eclipse.cdt.internal.core.search.CharOperation;
import org.eclipse.cdt.internal.core.search.matching.FieldDeclarationPattern;
import org.eclipse.cdt.internal.core.search.matching.NamespaceDeclarationPattern;
import org.eclipse.cdt.internal.core.search.matching.VariableDeclarationPattern;
-import org.eclipse.cdt.internal.ui.search.Match;
/**
* @author aniefer
@@ -95,7 +95,7 @@
search( workspace, pattern, scope, resultCollector );
- Set matches = resultCollector.getMatches();
+ List matches = resultCollector.getSearchResults();
assertEquals( matches.size(), 3 );
}
@@ -105,12 +105,12 @@
search( workspace, pattern, scope, resultCollector );
- Set matches = resultCollector.getMatches();
+ List matches = resultCollector.getSearchResults();
assertEquals( matches.size(), 1 );
- Match match = (Match) matches.iterator().next();
- assertTrue( match.parent.equals( "NS::B" ) );
+ IMatch match = (IMatch) matches.iterator().next();
+ assertTrue( match.getParentName().equals( "NS::B" ) );
}
public void testNamespaceReferenceInClassBaseClause(){
@@ -118,7 +118,7 @@
search( workspace, pattern, scope, resultCollector );
- Set matches = resultCollector.getMatches();
+ List matches = resultCollector.getSearchResults();
assertEquals( matches.size(), 2 );
}
@@ -127,11 +127,11 @@
search( workspace, pattern, scope, resultCollector );
- Set matches = resultCollector.getMatches();
+ List matches = resultCollector.getSearchResults();
assertEquals( matches.size(), 2 );
- Match match = (Match) matches.iterator().next();
- assertTrue( match.parent.equals( "NS::B" ) );
+ IMatch match = (IMatch) matches.iterator().next();
+ assertTrue( match.getParentName().equals( "NS::B" ) );
}
public void testVariableDeclaration(){
@@ -139,11 +139,11 @@
search( workspace, pattern, scope, resultCollector );
- Set matches = resultCollector.getMatches();
+ List matches = resultCollector.getSearchResults();
assertEquals( matches.size(), 2 );
- Match match = (Match) matches.iterator().next();
- assertTrue( match.parent.equals( "" ) );
+ IMatch match = (IMatch) matches.iterator().next();
+ assertTrue( match.getParentName().equals( "" ) );
}
}
Index: search/ChangeLog
===================================================================
RCS file: /home/tools/org.eclipse.cdt.core/search/ChangeLog,v
retrieving revision 1.10
diff -u -r1.10 ChangeLog
--- search/ChangeLog 29 Jul 2003 12:40:17 -0000 1.10
+++ search/ChangeLog 29 Jul 2003 20:54:44 -0000
@@ -1,3 +1,11 @@
+2003-07-29 Andrew Niefer
+ Refactoring Search result collection:
+ - Modified ICSearchResultCollector
+ - Modified IMatch
+ - Modified MatchLocator to reflect changes in ICSearchResultCollector
+ - Created BasicSearchMatch implements IMatch
+ - Created BasicSearchResultCollector implements ICSearchResultCollector
+
2003-07-28 Andrew Niefer
- added abstract CSearchPattern.resetIndexInfo fix bug with searching with globally
qualified names
Index: search/org/eclipse/cdt/core/search/BasicSearchMatch.java
===================================================================
RCS file: search/org/eclipse/cdt/core/search/BasicSearchMatch.java
diff -N search/org/eclipse/cdt/core/search/BasicSearchMatch.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ search/org/eclipse/cdt/core/search/BasicSearchMatch.java 29 Jul 2003 20:54:44 -0000
@@ -0,0 +1,93 @@
+/*******************************************************************************
+ * Copyright (c) 2003 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Common Public License v0.5
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v05.html
+ *
+ * Contributors:
+ * IBM Corp. - Rational Software - initial implementation
+ ******************************************************************************/
+/*
+ * Created on Jul 29, 2003
+ */
+package org.eclipse.cdt.core.search;
+
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.IPath;
+
+/**
+ * @author aniefer
+ *
+ * To change the template for this generated type comment go to
+ * Window>Preferences>Java>Code Generation>Code and Comments
+ */
+public class BasicSearchMatch implements IMatch {
+
+ public BasicSearchMatch() {
+ }
+
+ public BasicSearchMatch(BasicSearchMatch basicMatch) {
+ name = basicMatch.name;
+ parentName = basicMatch.parentName;
+ resource = basicMatch.resource;
+ path = basicMatch.path;
+ startOffset = basicMatch.startOffset;
+ endOffset = basicMatch.endOffset;
+ }
+
+ public String name = null;
+ public String parentName = null;
+
+ public IResource resource = null;
+ public IPath path = null;
+
+ public int startOffset = 0;
+ public int endOffset = 0;
+
+ public int type = 0;
+ public int visibility = 0;
+
+ boolean isConst = false;
+ boolean isVolatile = false;
+ boolean isStatic = false;
+
+ public int getElementType() {
+ return type;
+ }
+
+ public int getVisibility() {
+ return visibility;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public String getParentName() {
+ return parentName;
+ }
+
+ public IResource getResource() {
+ return resource;
+ }
+
+ public int getStartOffset() {
+ return startOffset;
+ }
+
+ public int getEndOffset() {
+ return endOffset;
+ }
+
+ public boolean isStatic() {
+ return isStatic;
+ }
+ public boolean isConst() {
+ return isConst;
+ }
+
+ public boolean isVolatile() {
+ return isVolatile;
+ }
+}
Index: search/org/eclipse/cdt/core/search/BasicSearchResultCollector.java
===================================================================
RCS file: search/org/eclipse/cdt/core/search/BasicSearchResultCollector.java
diff -N search/org/eclipse/cdt/core/search/BasicSearchResultCollector.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ search/org/eclipse/cdt/core/search/BasicSearchResultCollector.java 29 Jul 2003 20:54:44 -0000
@@ -0,0 +1,145 @@
+/*******************************************************************************
+ * Copyright (c) 2003 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Common Public License v0.5
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v05.html
+ *
+ * Contributors:
+ * IBM Corp. - Rational Software - initial implementation
+ ******************************************************************************/
+/*
+ * Created on Jul 29, 2003
+ */
+package org.eclipse.cdt.core.search;
+
+import java.util.LinkedList;
+import java.util.List;
+
+import org.eclipse.cdt.core.model.ICElement;
+import org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate;
+import org.eclipse.cdt.core.parser.ast.*;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IProgressMonitor;
+
+/**
+ * @author aniefer
+ *
+ * To change the template for this generated type comment go to
+ * Window>Preferences>Java>Code Generation>Code and Comments
+ */
+public class BasicSearchResultCollector implements ICSearchResultCollector {
+
+ public void aboutToStart() {
+ results = new LinkedList();
+ }
+
+ public void done() {
+ }
+
+ public IProgressMonitor getProgressMonitor() {
+ return null;
+ }
+
+ public IMatch createMatch(Object fileResource, int start, int end, ISourceElementCallbackDelegate node, IASTScope parent) throws CoreException {
+ BasicSearchMatch result = new BasicSearchMatch();
+
+ if( fileResource instanceof IResource )
+ result.resource = (IResource) fileResource;
+ else if( fileResource instanceof IPath )
+ result.path = (IPath) fileResource;
+
+ result.startOffset = start;
+ result.endOffset = end;
+
+ result.parentName = "";
+ if( parent instanceof IASTQualifiedNameElement ){
+ String [] names = ((IASTQualifiedNameElement)parent).getFullyQualifiedName();
+ for( int i = 0; i < names.length; i++ ){
+ if( i > 0 )
+ result.parentName += "::";
+
+ result.parentName += names[ i ];
+ }
+ }
+
+ IASTOffsetableNamedElement offsetable = null;
+
+ if( node instanceof IASTReference ){
+ offsetable = (IASTOffsetableNamedElement) ((IASTReference)node).getReferencedElement();
+ result.name = ((IASTReference)node).getName();
+ } else if( node instanceof IASTOffsetableNamedElement ){
+ offsetable = (IASTOffsetableNamedElement)node;
+ result.name = offsetable.getName();
+ }
+
+ setElementInfo( result, offsetable );
+
+ return result;
+ }
+
+
+ public void acceptMatch(IMatch match) throws CoreException {
+ results.add( match );
+ }
+
+ public List getSearchResults(){
+ return results;
+ }
+
+ private void setElementInfo( BasicSearchMatch match, IASTOffsetableElement node ){
+ //ImageDescriptor imageDescriptor = null;
+ if( node instanceof IASTClassSpecifier ){
+ ASTClassKind kind = ((IASTClassSpecifier)node).getClassKind();
+ if( kind == ASTClassKind.CLASS ){
+ match.type = ICElement.C_CLASS;
+ } else if ( kind == ASTClassKind.STRUCT ){
+ match.type = ICElement.C_STRUCT;
+ } else if ( kind == ASTClassKind.UNION ){
+ match.type = ICElement.C_UNION;
+ }
+ } else if ( node instanceof IASTNamespaceDefinition ){
+ match.type = ICElement.C_NAMESPACE;
+ } else if ( node instanceof IASTEnumerationSpecifier ){
+ match.type = ICElement.C_ENUMERATION;
+ } else if ( node instanceof IASTField ){
+ match.type = ICElement.C_FIELD;
+ IASTField field = (IASTField)node;
+ ASTAccessVisibility visibility = field.getVisiblity();
+ if( visibility == ASTAccessVisibility.PUBLIC ){
+ match.visibility = ICElement.CPP_PUBLIC;
+ } else if ( visibility == ASTAccessVisibility.PRIVATE ) {
+ match.visibility = ICElement.CPP_PRIVATE;
+ } // else protected, there is no ICElement.CPP_PROTECTED
+ match.isConst = field.getAbstractDeclaration().isConst();
+ match.isStatic = field.isStatic();
+ } else if ( node instanceof IASTVariable ){
+ match.type = ICElement.C_VARIABLE;
+ IASTVariable variable = (IASTVariable)node;
+ match.isConst = variable.getAbstractDeclaration().isConst();
+ } else if ( node instanceof IASTEnumerator ){
+ match.type = ICElement.C_ENUMERATOR;
+ } else if ( node instanceof IASTMethod ){
+ match.type = ICElement.C_METHOD;
+ IASTMethod method = (IASTMethod) node;
+ ASTAccessVisibility visibility = method.getVisiblity();
+ if( visibility == ASTAccessVisibility.PUBLIC ){
+ match.visibility = ICElement.CPP_PUBLIC;
+ } else if ( visibility == ASTAccessVisibility.PRIVATE ) {
+ match.visibility = ICElement.CPP_PRIVATE;
+ } // else protected, there is no ICElement.CPP_PROTECTED
+ match.isConst = method.isConst();
+ match.isVolatile = method.isVolatile();
+ match.isStatic = method.isStatic();
+ } else if ( node instanceof IASTFunction ){
+ match.type = ICElement.C_FUNCTION;
+ IASTFunction function = (IASTFunction)node;
+ match.isStatic = function.isStatic();
+ }
+ }
+
+ private List results;
+
+}
Index: search/org/eclipse/cdt/core/search/ICSearchResultCollector.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.core/search/org/eclipse/cdt/core/search/ICSearchResultCollector.java,v
retrieving revision 1.5
diff -u -r1.5 ICSearchResultCollector.java
--- search/org/eclipse/cdt/core/search/ICSearchResultCollector.java 24 Jul 2003 14:20:16 -0000 1.5
+++ search/org/eclipse/cdt/core/search/ICSearchResultCollector.java 29 Jul 2003 20:54:44 -0000
@@ -15,9 +15,7 @@
import org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate;
import org.eclipse.cdt.core.parser.ast.IASTScope;
-import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
/**
@@ -43,6 +41,12 @@
* Called before the actual search starts.
*/
public void aboutToStart();
+
+ /**
+ * Called when the search has ended.
+ */
+ public void done();
+
/**
* Accepts the given search result.
*
@@ -58,36 +62,18 @@
* <code>EXACT_MATCH</code> or <code>POTENTIAL_MATCH</code>
* @exception CoreException if this collector had a problem accepting the search result
*/
- public void accept(
- IResource resource,
- int start,
- int end,
- IMatch enclosingObject,
- int accuracy)
- throws CoreException;
-
- /**
- * Called when the search has ended.
- */
- public void done();
+ public IMatch createMatch( Object fileResource, int start, int end,
+ ISourceElementCallbackDelegate node, IASTScope parent) throws CoreException;
+
+ public void acceptMatch( IMatch match ) throws CoreException;
+
/**
* Returns the progress monitor used to report progress.
*
* @return a progress monitor or null if no progress monitor is provided
*/
public IProgressMonitor getProgressMonitor();
- /**
- * @param currentPath
- * @param start
- * @param end
- * @param object
- * @param accuracyLevel
- */
- public void accept(IPath currentPath,
- int start,
- int end,
- IMatch enclosingObject,
- int accuracyLevel) throws CoreException;
+
/**
* returns an IMatch object that contains any information the client cared
@@ -97,5 +83,5 @@
* @param node
* @return
*/
- public IMatch createMatch(ISourceElementCallbackDelegate node, IASTScope parent );
+ //public IMatch createMatch(ISourceElementCallbackDelegate node, IASTScope parent );
}
Index: search/org/eclipse/cdt/core/search/IMatch.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.core/search/org/eclipse/cdt/core/search/IMatch.java,v
retrieving revision 1.1
diff -u -r1.1 IMatch.java
--- search/org/eclipse/cdt/core/search/IMatch.java 15 Jul 2003 14:43:50 -0000 1.1
+++ search/org/eclipse/cdt/core/search/IMatch.java 29 Jul 2003 20:54:44 -0000
@@ -13,6 +13,8 @@
*/
package org.eclipse.cdt.core.search;
+import org.eclipse.core.resources.IResource;
+
/**
* @author aniefer
*
@@ -21,4 +23,21 @@
*/
public interface IMatch {
+ int getElementType();
+
+ int getVisibility();
+
+ String getName();
+
+ String getParentName();
+
+ IResource getResource();
+
+ int getStartOffset();
+
+ int getEndOffset();
+
+ boolean isStatic();
+ boolean isConst();
+ boolean isVolatile();
}
Index: search/org/eclipse/cdt/internal/core/search/matching/MatchLocator.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.core/search/org/eclipse/cdt/internal/core/search/matching/MatchLocator.java,v
retrieving revision 1.13
diff -u -r1.13 MatchLocator.java
--- search/org/eclipse/cdt/internal/core/search/matching/MatchLocator.java 25 Jul 2003 16:45:49 -0000 1.13
+++ search/org/eclipse/cdt/internal/core/search/matching/MatchLocator.java 29 Jul 2003 20:54:44 -0000
@@ -34,6 +34,7 @@
import org.eclipse.cdt.core.search.ICSearchPattern;
import org.eclipse.cdt.core.search.ICSearchResultCollector;
import org.eclipse.cdt.core.search.ICSearchScope;
+import org.eclipse.cdt.core.search.IMatch;
import org.eclipse.cdt.internal.core.model.IWorkingCopy;
import org.eclipse.cdt.internal.core.parser.ScannerInfo;
import org.eclipse.core.resources.IFile;
@@ -323,23 +324,17 @@
: offsetableElement.getStartingOffset();
length = offsetableElement.getName().length();
}
-
- if( currentResource != null ){
- resultCollector.accept( currentResource,
- offset,
- offset + length,
- resultCollector.createMatch( node, currentScope ),
- accuracyLevel );
-
+ IMatch match = null;
+ if( currentResource != null ){
+ match = resultCollector.createMatch( currentResource, offset, offset + length, node, currentScope );
} else if( currentPath != null ){
-
- resultCollector.accept( currentPath,
- offset,
- offset + length,
- resultCollector.createMatch( node, currentScope ),
- accuracyLevel );
+ match = resultCollector.createMatch( currentPath, offset, offset + length, node, currentScope );
}
+ if( match != null ){
+ resultCollector.acceptMatch( match );
+ }
+
} catch (CoreException e) {
}
}