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;
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.
}
// 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);
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;
/**
// 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);
/**
* 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) /*-{
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);
}
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.
* 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);
}
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();
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;
/**
*/
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);
}
// 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) {
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;
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;
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;
--- /dev/null
+/*
+ * 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();
+ }
+ });
+ }
+
+
+}
--- /dev/null
+/*
+ * 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";
+ }
+
+}
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