lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From uschind...@apache.org
Subject svn commit: r937360 - in /lucene/dev/trunk/lucene/contrib: CHANGES.txt queries/src/java/org/apache/lucene/search/regex/JakartaRegexpCapabilities.java queries/src/java/org/apache/regexp/
Date Fri, 23 Apr 2010 16:43:51 GMT
Author: uschindler
Date: Fri Apr 23 16:43:50 2010
New Revision: 937360

URL: http://svn.apache.org/viewvc?rev=937360&view=rev
Log:
LUCENE-2415: Use reflection instead of a shim class to access Jakarta Regex prefix

Removed:
    lucene/dev/trunk/lucene/contrib/queries/src/java/org/apache/regexp/
Modified:
    lucene/dev/trunk/lucene/contrib/CHANGES.txt
    lucene/dev/trunk/lucene/contrib/queries/src/java/org/apache/lucene/search/regex/JakartaRegexpCapabilities.java

Modified: lucene/dev/trunk/lucene/contrib/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/contrib/CHANGES.txt?rev=937360&r1=937359&r2=937360&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/contrib/CHANGES.txt (original)
+++ lucene/dev/trunk/lucene/contrib/CHANGES.txt Fri Apr 23 16:43:50 2010
@@ -184,6 +184,9 @@ Other
  * LUCENE-1845: Updated bdb-je jar from version 3.3.69 to 3.3.93.
    (Simon Willnauer via Mike McCandless)
 
+ * LUCENE-2415: Use reflection instead of a shim class to access Jakarta
+   Regex prefix.  (Uwe Schindler)
+
 ================== Release 2.9.2 / 3.0.1 2010-02-26 ====================
 
 New features

Modified: lucene/dev/trunk/lucene/contrib/queries/src/java/org/apache/lucene/search/regex/JakartaRegexpCapabilities.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/contrib/queries/src/java/org/apache/lucene/search/regex/JakartaRegexpCapabilities.java?rev=937360&r1=937359&r2=937360&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/contrib/queries/src/java/org/apache/lucene/search/regex/JakartaRegexpCapabilities.java
(original)
+++ lucene/dev/trunk/lucene/contrib/queries/src/java/org/apache/lucene/search/regex/JakartaRegexpCapabilities.java
Fri Apr 23 16:43:50 2010
@@ -18,7 +18,9 @@ package org.apache.lucene.search.regex;
  */
 
 import org.apache.regexp.RE;
-import org.apache.regexp.RegexpTunnel;
+import org.apache.regexp.REProgram;
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
 
 /**
  * Implementation tying <a href="http://jakarta.apache.org/regexp">Jakarta
@@ -29,6 +31,22 @@ import org.apache.regexp.RegexpTunnel;
  */
 public class JakartaRegexpCapabilities implements RegexCapabilities {
   private RE regexp;
+
+  private static Field prefixField;
+  private static Method getPrefixMethod;
+  static {
+    try {
+      getPrefixMethod = REProgram.class.getMethod("getPrefix");
+    } catch (Exception e) {
+      getPrefixMethod = null;
+    }
+    try {
+      prefixField = REProgram.class.getDeclaredField("prefix");
+      prefixField.setAccessible(true);
+    } catch (Exception e) {
+      prefixField = null;
+    }
+  }
   
   // Define the flags that are possible. Redefine them here
   // to avoid exposing the RE class to the caller.
@@ -70,8 +88,20 @@ public class JakartaRegexpCapabilities i
   }
 
   public String prefix() {
-    char[] prefix = RegexpTunnel.getPrefix(regexp);
-    return prefix == null ? null : new String(prefix);
+    try {
+      final char[] prefix;
+      if (getPrefixMethod != null) {
+        prefix = (char[]) getPrefixMethod.invoke(regexp.getProgram());
+      } else if (prefixField != null) {
+        prefix = (char[]) prefixField.get(regexp.getProgram());
+      } else {
+        return null;
+      }
+      return prefix == null ? null : new String(prefix);
+    } catch (Exception e) {
+      // if we cannot get the prefix, return none
+      return null;
+    }
   }
 
   @Override



Mime
View raw message