|
From: <jbo...@li...> - 2006-06-02 00:40:15
|
Author: mic...@jb...
Date: 2006-06-01 20:39:56 -0400 (Thu, 01 Jun 2006)
New Revision: 4554
Modified:
labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/semantics/java/FunctionFixer.java
labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/semantics/java/FunctionFixerTest.java
Log:
JBRULES-278
Modified: labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/semantics/java/FunctionFixer.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/semantics/java/FunctionFixer.java 2006-06-01 17:59:36 UTC (rev 4553)
+++ labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/semantics/java/FunctionFixer.java 2006-06-02 00:39:56 UTC (rev 4554)
@@ -27,12 +27,15 @@
* stuff like that.
* A better future solution is to use a static import as found in Java 5, then ALL THIS can
* disappear. Oh Happy day.
+ *
* @author Michael Neale (sadly..)
+ * @author Ricardo Barone
+ * (Ricardo actually made this all work !).
*
*/
public class FunctionFixer {
- static Pattern FUNCTION = Pattern.compile( "(\\S*\\s*|\\.\\s*)\\b([\\S&&[^\\.]]+)\\s*\\(([^)]*)\\)",
+ static Pattern FUNCTION = Pattern.compile( "(\\S*\\s*|\\.\\s*)\\b([\\S&&[^\\.\\(\\)]]+)\\s*\\(([^)]*)\\)",
Pattern.DOTALL );
static final Set KEYWORDS = getJavaKeywords();
@@ -90,8 +93,11 @@
if ( function == null ) {
function = matcher.group( 2 ).trim();
- // if we have a reserve d work, DO NOT TOUCH !
- if ( FunctionFixer.KEYWORDS.contains( function ) ) {
+ // if we have a reserved work, DO NOT TOUCH !
+ // if we have no function name, DO NOT TOUCH !
+ if ( function == null ||
+ function.length() == 0 ||
+ FunctionFixer.KEYWORDS.contains( function ) ) {
function = raw.substring( matcher.start( 2 ),
matcher.start( 3 ) - 1 );
} else {
Modified: labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/semantics/java/FunctionFixerTest.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/semantics/java/FunctionFixerTest.java 2006-06-01 17:59:36 UTC (rev 4553)
+++ labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/semantics/java/FunctionFixerTest.java 2006-06-02 00:39:56 UTC (rev 4554)
@@ -99,5 +99,17 @@
assertEquals( "System.out.println(\"foo(\" + Foo.foo(bar) + Bar.bar(baz)",
fixer.fix( "System.out.println(\"foo(\" + foo(bar) + bar(baz)" ) );
}
+
+ public void testXPath() {
+ final FunctionFixer fixer = new FunctionFixer();
+ assertEquals( "foo.executeXpath(\"//node1/node2/text()\")",
+ fixer.fix("foo.executeXpath(\"//node1/node2/text()\")" ) );
+ }
+
+ public void testExpressionGrouping() {
+ final FunctionFixer fixer = new FunctionFixer();
+ assertEquals( "while((foo = bar.baz()) != null)",
+ fixer.fix( "while((foo = bar.baz()) != null)" ) );
+ }
}
\ No newline at end of file
|