Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[cdt-patch] Fix for bug 51291: Search looking for function/method with no parameters


Modified search to look for functions/methods with no parameters. Apply to head only.

Suite on Windows.

- Bogdan

Index: ChangeLog
===================================================================
retrieving revision 1.178
diff -u -r1.178 ChangeLog
--- ChangeLog	5 Feb 2004 03:57:49 -0000	1.178
+++ ChangeLog	6 Feb 2004 21:04:50 -0000
@@ -1,3 +1,6 @@
+2004-02-06 Bogdan Gheorghe
+	Added FunctionMethodPatternTests.testMethodDeclarationWithNoParameters
+	
 2004-02-04 John Camelon
 	Added preliminary SelectionParseTests to test SELECTION_PARSE clients. 
 	Added SelectionParseTests to ParserTestSuite.  
Index: resources/search/include.h
===================================================================
retrieving revision 1.6
diff -u -r1.6 include.h
--- resources/search/include.h	3 Dec 2003 21:48:12 -0000	1.6
+++ resources/search/include.h	6 Feb 2004 21:04:52 -0000
@@ -27,6 +27,8 @@
 
 class Direction{
    void turn();
+   void turn(int);
+   void turnAgain(void);
 };
 class Right : public Direction  {
    void turn() { }
Index: search/org/eclipse/cdt/core/search/tests/FunctionMethodPatternTests.java
===================================================================
retrieving revision 1.12
diff -u -r1.12 FunctionMethodPatternTests.java
--- search/org/eclipse/cdt/core/search/tests/FunctionMethodPatternTests.java	3 Dec 2003 21:48:12 -0000	1.12
+++ search/org/eclipse/cdt/core/search/tests/FunctionMethodPatternTests.java	6 Feb 2004 21:04:52 -0000
@@ -105,6 +105,27 @@
 		assertEquals( matches.size(), 1 );
 	}
 	
+	public void testMethodWithNoParameters(){
+		ICSearchPattern pattern = SearchEngine.createSearchPattern( "turn( )", METHOD, DECLARATIONS, true );
+		
+		search( workspace, pattern, scope, resultCollector );
+		Set matches = resultCollector.getSearchResults();
+		assertEquals( matches.size(), 2 );
+		
+		pattern = SearchEngine.createSearchPattern( "turn(void)", METHOD, DECLARATIONS, true );
+		
+		search( workspace, pattern, scope, resultCollector );
+		matches = resultCollector.getSearchResults();
+		assertEquals( matches.size(), 2 );
+		
+		pattern = SearchEngine.createSearchPattern( "turnAgain()", METHOD, DECLARATIONS, true );
+		
+		search( workspace, pattern, scope, resultCollector );
+		matches = resultCollector.getSearchResults();
+		assertEquals( matches.size(), 1 );
+		
+	}
+	
 	public void testOperators_bug43063_bug42979(){
 		ICSearchPattern pattern = SearchEngine.createSearchPattern( "operator \\*", METHOD, DECLARATIONS, true );
 		
@@ -196,7 +217,7 @@
 		ICSearchPattern pattern = SearchEngine.createSearchPattern( "turn", METHOD, DECLARATIONS, true );
 		search( workspace, pattern, scope, resultCollector );
 		Set matches = resultCollector.getSearchResults();
-		assertEquals( matches.size(), 2 );
+		assertEquals( matches.size(), 3 );
 		
 		pattern = SearchEngine.createSearchPattern( "Direction::turn", METHOD, DEFINITIONS, true );
 		search( workspace, pattern, scope, resultCollector );
Index: search/ChangeLog
===================================================================
retrieving revision 1.41
diff -u -r1.41 ChangeLog
--- search/ChangeLog	5 Feb 2004 19:56:27 -0000	1.41
+++ search/ChangeLog	6 Feb 2004 21:22:56 -0000
@@ -1,3 +1,10 @@
+2004-02-06 Bogdan Gheorghe
+
+	- Modified CSearchPattern.scanforParameters. If no parameters are passed in
+	  as part of a function/method search, void is assigned as a parameter type.
+	  
+	- Modified MethodDeclarationPattern to check for void parameter types
+	
 2004-02-05 Alain Magloire
 	PR 51221
 	Reformat Patch from Bogdan base on Thomas Fletcher original patch
Index: search/org/eclipse/cdt/internal/core/search/matching/CSearchPattern.java
===================================================================
retrieving revision 1.33
diff -u -r1.33 CSearchPattern.java
--- search/org/eclipse/cdt/internal/core/search/matching/CSearchPattern.java	27 Jan 2004 01:21:18 -0000	1.33
+++ search/org/eclipse/cdt/internal/core/search/matching/CSearchPattern.java	6 Feb 2004 21:22:56 -0000
@@ -452,6 +452,12 @@
 				param = getParamString( (IASTParameterDeclaration)parameters.next() );
 				list.add( param );
 			}
+			
+			if (param == null){
+				//This means that no params have been added (i.e. empty brackets - void case)
+				param = "void ".toCharArray();
+				list.add (param); 
+			}
 		}
 		
 		return list;
Index: search/org/eclipse/cdt/internal/core/search/matching/MethodDeclarationPattern.java
===================================================================
retrieving revision 1.11
diff -u -r1.11 MethodDeclarationPattern.java
--- search/org/eclipse/cdt/internal/core/search/matching/MethodDeclarationPattern.java	24 Sep 2003 13:36:40 -0000	1.11
+++ search/org/eclipse/cdt/internal/core/search/matching/MethodDeclarationPattern.java	6 Feb 2004 21:22:56 -0000
@@ -96,11 +96,17 @@
 			}
 		}
 		
+		
 		//parameters
 		if( parameterNames != null && parameterNames.length > 0  &&	parameterNames[0].length > 0 ){
 
 			Iterator params = function.getParameters();
 				
+			if (!params.hasNext() && CharOperation.equals(parameterNames[0], "void ".toCharArray())){
+			//All empty lists have transformed to void, this function has no parms
+				return ACCURATE_MATCH;
+			}
+			
 			for( int i = 0; i < parameterNames.length; i++ ){
 			
 				//if this function doesn't have this many parameters, it is not a match.

Back to the top