]> source.dussan.org Git - gwtquery.git/commitdiff
Deprecate gwtquery JsRegexp implementation in favor of gwt RegExp which does exactly...
authorManuel Carrasco Moñino <manuel.carrasco.m@gmail.com>
Wed, 10 Apr 2013 08:50:45 +0000 (10:50 +0200)
committerManuel Carrasco Moñino <manuel.carrasco.m@gmail.com>
Wed, 10 Apr 2013 08:50:45 +0000 (10:50 +0200)
13 files changed:
gwtquery-core/src/main/java/com/google/gwt/query/client/Properties.java
gwtquery-core/src/main/java/com/google/gwt/query/client/impl/SelectorEngine.java
gwtquery-core/src/main/java/com/google/gwt/query/client/impl/SelectorEngineCssToXPath.java
gwtquery-core/src/main/java/com/google/gwt/query/client/js/JsRegexp.java
gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/MousePlugin.java
gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/QueuePlugin.java
gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/deferred/PromiseReqBuilderJSONP.java
gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/events/EventsListener.java
gwtquery-core/src/test/java/com/google/gwt/query/client/GQueryCoreTestGwt.java
gwtquery-core/src/test/java/com/google/gwt/query/client/GQueryEffectsTestGwt.java
gwtquery-core/src/test/java/com/google/gwt/query/client/deferred/DeferredTest.java [new file with mode: 0644]
gwtquery-core/src/test/java/com/google/gwt/query/client/deferred/DeferredTestGwt.java [new file with mode: 0644]
gwtquery-core/src/test/java/com/google/gwt/query/client/impl/SelectorEnginesTest.java

index d3dbda9b62b8296020132568f03ed810fe749e33..b7e42c9aff4c2d5713594417fa9f789ba04513ba 100644 (file)
@@ -17,7 +17,7 @@ package com.google.gwt.query.client;
 
 import com.google.gwt.core.client.JavaScriptObject;
 import com.google.gwt.core.client.JsArrayMixed;
-import com.google.gwt.core.shared.GWT;
+import com.google.gwt.core.client.GWT;
 import com.google.gwt.query.client.js.JsCache;
 import com.google.gwt.query.client.js.JsUtils;
 
index 638cbf46af07acb9916e147ba2b803f0ad9beecb..3ffff97041bda00073c8050c1598bcfb5d062e99 100644 (file)
@@ -21,9 +21,9 @@ import com.google.gwt.dom.client.Element;
 import com.google.gwt.dom.client.Node;
 import com.google.gwt.dom.client.NodeList;
 import com.google.gwt.query.client.js.JsNodeArray;
-import com.google.gwt.query.client.js.JsObjectArray;
-import com.google.gwt.query.client.js.JsRegexp;
 import com.google.gwt.query.client.js.JsUtils;
+import com.google.gwt.regexp.shared.MatchResult;
+import com.google.gwt.regexp.shared.RegExp;
 
 /**
  * Core Selector engine functions, and native JS utility functions.
@@ -122,21 +122,21 @@ public class SelectorEngine implements HasSelector {
   }
 
   // pseudo selectors which are computed by gquery
-  JsRegexp p = new JsRegexp("(.*):((visible|hidden)|((button|checkbox|file|hidden|image|password|radio|reset|submit|text)\\s*(,|$)))(.*)", "i");
+  RegExp p = RegExp.compile("(.*):((visible|hidden)|((button|checkbox|file|hidden|image|password|radio|reset|submit|text)\\s*(,|$)))(.*)", "i");
 
   public NodeList<Element> select(String selector, Node ctx) {
     if (p.test(selector)) {
       JsNodeArray res = JsNodeArray.create();
       for (String s : selector.trim().split("\\s*,\\s*")) {
         NodeList<Element> nodes;
-        JsObjectArray<String> a = p.match(s);
-        if (a.get(0) != null) {
+        MatchResult a = p.exec(s);
+        if (a != null) {
           if (s.endsWith(":visible")) {
             nodes = filterByVisibility(select(s.substring(0, s.length() - 8), ctx), true);
           } else if (s.endsWith(":hidden")) {
             nodes = filterByVisibility(select(s.substring(0, s.length() - 7), ctx), false);
           } else {
-            nodes = select((a.get(1) != null ? a.get(1) : "") + "[type=" + a.get(2) + "]", ctx);
+            nodes = select((a.getGroup(1) != null ? a.getGroup(1) : "") + "[type=" + a.getGroup(2) + "]", ctx);
           }
         } else {
           nodes = select(s, ctx);
index d6218abf8ca7b790a250efe18d3e31474408591c..e5ec73a6e7f3f295939cb79d97d8f51dc179c95a 100644 (file)
@@ -24,9 +24,8 @@ import com.google.gwt.dom.client.Node;
 import com.google.gwt.dom.client.NodeList;
 import com.google.gwt.query.client.js.JsNamedArray;
 import com.google.gwt.query.client.js.JsNodeArray;
-import com.google.gwt.query.client.js.JsObjectArray;
-import com.google.gwt.query.client.js.JsRegexp;
 import com.google.gwt.query.client.js.JsUtils;
+import com.google.gwt.regexp.shared.MatchResult;
 import com.google.gwt.regexp.shared.RegExp;
 
 /**
@@ -183,14 +182,14 @@ public class SelectorEngineCssToXPath extends SelectorEngineImpl {
   // when using this engine in generators and tests for the JVM
   private Replacer replacer = new Replacer() {
     public String replaceAll(String s, String r, Object o) {
-      JsRegexp p = new JsRegexp(r);
+      RegExp p = RegExp.compile(r);
       if (o instanceof ReplaceCallback) {
         ReplaceCallback callback = (ReplaceCallback) o;
         while (p.test(s)) {
-          JsObjectArray<String> a = p.match(s);
+          MatchResult a = p.exec(s);
           ArrayList<String> args = new ArrayList<String>();
-          for (int i = 0; i < a.length(); i++) {
-            args.add(a.get(i));
+          for (int i = 0; a != null && i < a.getGroupCount(); i++) {
+            args.add(a.getGroup(i));
           }
           String f = callback.foundMatch(args);
           s = s.replaceFirst(r, f);
index 7eeb0da580e459c65854eec69d2532e9eef52a91..b4018cf8ba07370fa56c6c561cf520dc95d1a627 100644 (file)
@@ -19,7 +19,9 @@ import com.google.gwt.core.client.JavaScriptObject;
 
 /**
  * A wrapper around Javascript Regexps.
+ * @deprecated use RegExp instead whose jsni implementation is the same
  */
+@Deprecated
 public class JsRegexp {
 
   public static native JavaScriptObject compile(String pat) /*-{
@@ -40,10 +42,18 @@ public class JsRegexp {
 
   private final JavaScriptObject regexp;
 
+  /**
+   * @deprecated use RegExp.compile(pattern) instead
+   */
+  @Deprecated
   public JsRegexp(String pattern) {
     this.regexp = compile(pattern);
   }
 
+  /**
+   * @deprecated use RegExp.compile(pattern, flags) instead
+   */
+  @Deprecated
   public JsRegexp(String pat, String flags) {
     this.regexp = compileFlags(pat, flags);
   }
index 25a74334e7bb168063b4e7642947075c4f61ca9b..aca8db0594182b31dc9a74f3a5c1838f2c91f0c0 100755 (executable)
@@ -20,8 +20,6 @@ import com.google.gwt.query.client.Function;
 import com.google.gwt.query.client.GQuery;
 import com.google.gwt.query.client.plugins.events.GqEvent;
 import com.google.gwt.user.client.Event;
-import com.google.gwt.user.client.ui.Label;
-import com.google.gwt.user.client.ui.RootPanel;
 
 /**
  * Base class for all plug-in that need to handle some mouse interactions.
index 0834a3d816c6ba00ffba95b490e403e9e6e657fd..9227d699e36b0adc140e063a2dfdbb50b1a7396e 100644 (file)
@@ -352,6 +352,7 @@ public class QueuePlugin<T extends QueuePlugin<?>> extends GQuery {
    * in the queue.
    */
   public void dequeueIfNotDoneYet(Element elem, String name, Object object) {
+    @SuppressWarnings("rawtypes")
     Queue queue = queue(elem, name, null);
     if (queue != null && object.equals(queue.peek())) {
       dequeueCurrentAndRunNext(elem, name);
@@ -374,6 +375,7 @@ public class QueuePlugin<T extends QueuePlugin<?>> extends GQuery {
   }
 
   private void stop(Element elem, String name, boolean clear, boolean jumpToEnd) {
+    @SuppressWarnings("rawtypes")
     Queue q = queue(elem, name, null);
     if (q != null) {
       Object f = q.peek();
index 8ce184f393fd09a983ea386cca641baf2784d1f0..9278bf7bd217a4df49d69e78244376a5eb08dcf0 100644 (file)
@@ -14,9 +14,9 @@
 package com.google.gwt.query.client.plugins.deferred;
 
 import com.google.gwt.jsonp.client.JsonpRequestBuilder;
-import com.google.gwt.query.client.js.JsObjectArray;
-import com.google.gwt.query.client.js.JsRegexp;
 import com.google.gwt.query.client.plugins.deferred.Deferred.DeferredPromiseImpl;
+import com.google.gwt.regexp.shared.MatchResult;
+import com.google.gwt.regexp.shared.RegExp;
 import com.google.gwt.user.client.rpc.AsyncCallback;
 
 /**
@@ -37,7 +37,7 @@ import com.google.gwt.user.client.rpc.AsyncCallback;
  */
 public class PromiseReqBuilderJSONP extends DeferredPromiseImpl {
   
-  private static final JsRegexp callbackRegex = new JsRegexp("^(.+[\\?&])([^=]+)=\\?(.*)$");
+  private static final RegExp callbackRegex = RegExp.compile("^(.+[\\?&])([^=]+)=\\?(.*)$");
   
   public PromiseReqBuilderJSONP(String url) {
     this(url, null, 0);
@@ -54,10 +54,10 @@ public class PromiseReqBuilderJSONP extends DeferredPromiseImpl {
     }
     // jQuery allows a parameter callback=? to figure out the callback parameter
     if (callbackParam == null) {
-      JsObjectArray<String> tmp = callbackRegex.exec(url);
-      if  (tmp.length() == 4) {
-        callbackParam = tmp.get(2);
-        url = tmp.get(1) + tmp.get(3);
+      MatchResult tmp = callbackRegex.exec(url);
+      if  (tmp != null && tmp.getGroupCount() == 4) {
+        callbackParam = tmp.getGroup(2);
+        url = tmp.getGroup(1) + tmp.getGroup(3);
       }
     }
     if (callbackParam != null) {
index 1f239fdc2be56eb3fe75ad828a105ef8a4d073d7..5fbe5544eca47940473f1fa2d68a03470dacb369 100644 (file)
@@ -16,7 +16,6 @@ package com.google.gwt.query.client.plugins.events;
 import static com.google.gwt.query.client.GQuery.$;
 
 import com.google.gwt.core.client.Duration;
-import com.google.gwt.core.client.JsArrayString;
 import com.google.gwt.dom.client.Element;
 import com.google.gwt.dom.client.EventTarget;
 import com.google.gwt.dom.client.NodeList;
index d5d587931d869e21d4ba596b443748dc29728cbe..c87a00258140497f6ef6bfa4b9a604a4c982ffba 100644 (file)
@@ -49,7 +49,6 @@ import com.google.gwt.query.client.js.JsNodeArray;
 import com.google.gwt.query.client.js.JsUtils;
 import com.google.gwt.user.client.DOM;
 import com.google.gwt.user.client.Event;
-import com.google.gwt.user.client.Window;
 import com.google.gwt.user.client.ui.Button;
 import com.google.gwt.user.client.ui.HTML;
 import com.google.gwt.user.client.ui.Label;
index 531f58c39d710c598510bd63cd0f996699364ae8..b71b2300ae5f5dbd29f6b8dea5c489d54a085a5d 100644 (file)
@@ -19,8 +19,6 @@ import static com.google.gwt.query.client.GQuery.$;
 import static com.google.gwt.query.client.GQuery.$$;
 
 import com.google.gwt.dom.client.Element;
-import com.google.gwt.junit.DoNotRunWith;
-import com.google.gwt.junit.Platform;
 import com.google.gwt.junit.client.GWTTestCase;
 import com.google.gwt.query.client.GQuery.Offset;
 import com.google.gwt.query.client.plugins.Effects;
diff --git a/gwtquery-core/src/test/java/com/google/gwt/query/client/deferred/DeferredTest.java b/gwtquery-core/src/test/java/com/google/gwt/query/client/deferred/DeferredTest.java
new file mode 100644 (file)
index 0000000..b2ce198
--- /dev/null
@@ -0,0 +1,208 @@
+/*
+ * Copyright 2011, The gwtquery team.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package com.google.gwt.query.client.deferred;
+
+import com.google.gwt.junit.client.GWTTestCase;
+import com.google.gwt.query.client.Function;
+import com.google.gwt.query.client.GQuery;
+import com.google.gwt.query.client.plugins.deferred.Callbacks;
+import com.google.gwt.query.client.plugins.deferred.Callbacks.Callback;
+import com.google.gwt.query.client.plugins.deferred.PromiseFunction;
+
+/**
+ * Tests for Deferred which can run either in JVM and GWT
+ */
+public class DeferredTest extends GWTTestCase {
+
+  public String getModuleName() {
+    return null;
+  }
+
+  private String result = "";
+  public void testCallbacks() {
+    Function fn1 = new Function() {
+      public Object f(Object...arguments) {
+        String s = " f1:";
+        for (Object o: arguments){
+          s += " " + o;
+        }
+        result += s;
+        return false;
+      }
+    };
+    
+    Callback fn2 = new Callback() {
+      public boolean f(Object... objects) {
+        String s = " f2:";
+        for (Object o: objects){
+          s += " " + o;
+        }
+        result += s;
+        return false;
+      }
+    };
+    
+    com.google.gwt.core.client.Callback<Object, Object> fn3 = new com.google.gwt.core.client.Callback<Object, Object>() {
+      public void onFailure(Object reason) {
+        result += " f3_fail: " + reason;
+      }
+      public void onSuccess(Object objects) {
+        String s = " f3_success:";
+        for (Object o: (Object[])objects){
+          s += " " + o;
+        }
+        result += s;
+      }
+    };
+    
+    result = "";
+    Callbacks callbacks = new Callbacks();
+    callbacks.add( fn1 );
+    callbacks.fire( "foo" );
+    assertEquals(" f1: foo", result);
+    
+    result = "";
+    callbacks.add( fn2 );
+    callbacks.fire( "bar" );
+    assertEquals(" f1: bar f2: bar", result);
+
+    result = "";
+    callbacks.remove( fn2 );
+    callbacks.fire( "foobar" );
+    assertEquals(" f1: foobar", result);
+
+    result = "";
+    callbacks.add( fn1 );
+    callbacks.fire( "foo" );
+    assertEquals(" f1: foo f1: foo", result);
+
+    result = "";
+    callbacks = new Callbacks("unique");
+    callbacks.add( fn1 );
+    callbacks.add( fn1 );
+    callbacks.fire( "foo" );
+    assertEquals(" f1: foo", result);
+
+    result = "";
+    callbacks.add( fn3 );
+    callbacks.fire( "bar" );
+    assertEquals(" f1: bar f3_success: bar", result);
+    
+    result = "";
+    callbacks = new Callbacks("memory");
+    callbacks.add( fn1 );
+    callbacks.fire( "foo" );
+    callbacks.add( fn2 );
+    callbacks.fire( "bar" );
+    callbacks.remove(fn2);
+    callbacks.fire( "foobar" );
+    assertEquals(" f1: foo f2: foo f1: bar f2: bar f1: foobar", result);
+
+    result = "";
+    callbacks = new Callbacks("stopOnFalse");
+    callbacks.add( fn1 );
+    callbacks.add( fn2 );
+    callbacks.fire( "bar" );
+    assertEquals(" f1: bar", result);
+    
+    result = "";
+    callbacks.disable();
+    callbacks.fire( "bar" );
+    assertEquals("", result);
+
+    result = "";
+    callbacks = new Callbacks("memory once unique");
+    callbacks.add( fn1 );
+    callbacks.add( fn1 );
+    callbacks.fire( "bar" );
+    assertEquals(" f1: bar", result);
+    callbacks.fire( "foo" );
+    assertEquals(" f1: bar", result);
+    callbacks.add( fn2 );
+    callbacks.add( fn2 );
+    assertEquals(" f1: bar f2: bar f2: bar", result);
+    callbacks.remove( fn1 );
+    callbacks.add( fn1 );
+    assertEquals(" f1: bar f2: bar f2: bar f1: bar", result);
+    callbacks.remove( fn1 );
+    callbacks.disable();
+    callbacks.add( fn1 );
+    assertEquals(" f1: bar f2: bar f2: bar f1: bar", result);
+  }
+  
+  public void testThen() {
+    new PromiseFunction() {
+      public void f(final Deferred dfd) {
+        dfd.resolve(5d);
+      }
+    }.done(new Function() {
+      public void f() {
+        assertEquals(5d, arguments(0));
+      }
+    }).then(new Function() {
+      public Object f(Object... args) {
+        return (Double)args[0] * 2;
+      }
+    }).done(new Function() {
+      public void f() {
+        assertEquals(10d, arguments(0));
+      }
+    });
+  }
+  
+  public void testDeferredAjaxThenFail() {
+    delayTestFinish(5000);
+    
+    GQuery
+      .when(new PromiseFunction() {
+        public void f(Deferred dfd) {
+          dfd.resolve("message");
+        }
+      })
+      .then(new Function() {
+        public Object f(Object... args) {
+          return new PromiseFunction() {
+            public void f(Deferred dfd) {
+              dfd.resolve(arguments);
+            }
+          };
+        }
+      })
+      .then(new Function() {
+        public Object f(Object... args) {
+          return new PromiseFunction() {
+            public void f(Deferred dfd) {
+              dfd.reject(arguments);
+            }
+          };
+        }
+      })
+      .done(new Function() {
+        public void f() {
+          finishTest();
+          fail();
+        }
+      })
+      .fail(new Function() {
+        public void f() {
+          assertEquals("message", arguments(0));
+          finishTest();
+        }
+      });
+  }
+  
+
+}
diff --git a/gwtquery-core/src/test/java/com/google/gwt/query/client/deferred/DeferredTestGwt.java b/gwtquery-core/src/test/java/com/google/gwt/query/client/deferred/DeferredTestGwt.java
new file mode 100644 (file)
index 0000000..de6375d
--- /dev/null
@@ -0,0 +1,29 @@
+/*
+ * Copyright 2013, The gwtquery team.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package com.google.gwt.query.client.deferred;
+
+
+/**
+ * Test for deferred/callbacks shared code run in gwt
+ */
+public class DeferredTestGwt extends DeferredTest {
+
+  @Override
+  public String getModuleName() {
+    return "com.google.gwt.query.Query";
+  }
+
+}
index 2f1171c1ed77a530fc4666515d63acfded22e086..7b8199ee185c95fe8b891e5b31e7eeaa75e3130a 100644 (file)
@@ -16,7 +16,6 @@
 package com.google.gwt.query.client.impl;
 
 import com.google.gwt.junit.client.GWTTestCase;
-import com.google.gwt.query.rebind.SelectorGeneratorCssToXPath;
 
 /**
  * Test for selector engine implementations