diff options
author | Manolo Carrasco <manolo@apache.org> | 2011-03-03 10:11:47 +0000 |
---|---|---|
committer | Manolo Carrasco <manolo@apache.org> | 2011-03-03 10:11:47 +0000 |
commit | 0446c769336c5e10c9db5ff83d22868b600ea806 (patch) | |
tree | 40f37fa334da8aae948763e01e71c2a7f3dca930 | |
parent | 757f6e13d525705445bd6b954bc279913946acbe (diff) | |
download | gwtquery-0446c769336c5e10c9db5ff83d22868b600ea806.tar.gz gwtquery-0446c769336c5e10c9db5ff83d22868b600ea806.zip |
Refactoring of Lightweight JSO classes and more.
22 files changed, 596 insertions, 557 deletions
diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/GQuery.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/GQuery.java index 9922eeac..ae382c92 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/GQuery.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/GQuery.java @@ -17,7 +17,11 @@ package com.google.gwt.query.client; import static com.google.gwt.query.client.plugins.Effects.Effects;
import static com.google.gwt.query.client.plugins.Events.Events;
-import static com.google.gwt.query.client.plugins.Widgets.Widgets;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
import com.google.gwt.core.client.GWT;
import com.google.gwt.core.client.JavaScriptObject;
@@ -33,15 +37,19 @@ import com.google.gwt.dom.client.Node; import com.google.gwt.dom.client.NodeList;
import com.google.gwt.dom.client.OptionElement;
import com.google.gwt.dom.client.SelectElement;
-import com.google.gwt.dom.client.TextAreaElement;
import com.google.gwt.dom.client.Style.Display;
import com.google.gwt.dom.client.Style.HasCssName;
+import com.google.gwt.dom.client.TextAreaElement;
import com.google.gwt.query.client.css.CSS;
import com.google.gwt.query.client.css.HasCssValue;
import com.google.gwt.query.client.css.TakesCssValue;
import com.google.gwt.query.client.css.TakesCssValue.CssSetter;
import com.google.gwt.query.client.impl.DocumentStyleImpl;
import com.google.gwt.query.client.impl.SelectorEngine;
+import com.google.gwt.query.client.js.JsCache;
+import com.google.gwt.query.client.js.JsMap;
+import com.google.gwt.query.client.js.JsNodeArray;
+import com.google.gwt.query.client.js.JsUtils;
import com.google.gwt.query.client.plugins.Plugin;
import com.google.gwt.query.client.plugins.events.EventsListener;
import com.google.gwt.user.client.DOM;
@@ -50,11 +58,6 @@ import com.google.gwt.user.client.EventListener; import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.Widget;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.HashMap;
-import java.util.List;
-
/**
* GwtQuery is a GWT clone of the popular jQuery library.
*/
@@ -82,82 +85,6 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> { }
/**
- * A class to store data in an element.
- */
- protected static final class DataCache extends JavaScriptObject {
-
- protected DataCache() {
- }
-
- public native void delete(int name) /*-{
- delete this[name];
- }-*/;
-
- public native void delete(String name) /*-{
- delete this[name];
- }-*/;
-
- public native boolean exists(int id) /*-{
- return !!this[id];
- }-*/;
-
- public native JavaScriptObject get(int id) /*-{
- return this[id];
- }-*/;
-
- public native JavaScriptObject get(String id) /*-{
- return this[id];
- }-*/;
-
- public DataCache getCache(int id) {
- return get(id).cast();
- }
-
- public native double getDouble(int id) /*-{
- return this[id];
- }-*/;
-
- public native double getDouble(String id) /*-{
- return this[id];
- }-*/;
-
- public native int getInt(int id) /*-{
- return this[id];
- }-*/;
-
- public native int getInt(String id) /*-{
- return this[id];
- }-*/;
-
- public native Object getObject(String id) /*-{
- return this[id];
- }-*/;
-
- public native String getString(int id) /*-{
- return this[id];
- }-*/;
-
- public native String getString(String id) /*-{
- return this[id];
- }-*/;
-
- public native boolean isEmpty() /*-{
- var foo = "";
- for (foo in this)
- break;
- return !foo;
- }-*/;
-
- public native void put(int id, Object obj) /*-{
- this[id] = obj;
- }-*/;
-
- public native void put(String id, Object obj) /*-{
- this[id] = obj;
- }-*/;
- }
-
- /**
* The body element in the current page.
*/
public static final BodyElement body = Document.get().getBody();
@@ -177,7 +104,7 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> { */
public static final Element window = window();
- private static DataCache dataCache = null;
+ private static JsCache dataCache = null;
private static SelectorEngine engine;
@@ -186,8 +113,8 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> { private static final String OLD_DATA_PREFIX = "old-";
- private static JsMap<Class<? extends GQuery>, Plugin<? extends GQuery>> plugins;;
-
+ private static JsMap<Class<? extends GQuery>, Plugin<? extends GQuery>> plugins;
+
private static DocumentStyleImpl styleImpl = GWT.create(DocumentStyleImpl.class);
private static Element windowData = null;
@@ -196,7 +123,7 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> { * Create an empty GQuery object.
*/
public static GQuery $() {
- return new GQuery(JSArray.create());
+ return new GQuery(JsNodeArray.create());
}
@@ -219,7 +146,7 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> { * Wrap a GQuery around an existing node.
*/
public static GQuery $(Node n) {
- return n == null ? $() : new GQuery(JSArray.create(n));
+ return n == null ? $() : new GQuery(JsNodeArray.create(n));
}
/**
@@ -233,7 +160,7 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> { * Create a new GQuery given a list of nodes, elements or widgets
*/
public static GQuery $(List<?> nodesOrWidgets) {
- JSArray elements = JSArray.create();
+ JsNodeArray elements = JsNodeArray.create();
if (nodesOrWidgets != null) {
for (Object o : nodesOrWidgets ) {
if (o instanceof Node) {
@@ -434,14 +361,14 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> { }
int id = item.hashCode();
if (name != null && !dataCache.exists(id)) {
- dataCache.put(id, DataCache.createObject().cast());
+ dataCache.put(id, JsCache.createObject().cast());
}
- DataCache d = dataCache.get(id).cast();
+ JsCache d = dataCache.getCache(id);
if (name != null && value != null) {
d.put(name, value);
}
- return name != null ? d.getObject(name) : id;
+ return name != null ? d.get(name) : id;
}
/**
@@ -483,8 +410,8 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> { }
}
- private static JSArray copyNodeList(NodeList<? extends Node> n) {
- JSArray res = JSArray.create();
+ private static JsNodeArray copyNodeList(NodeList<? extends Node> n) {
+ JsNodeArray res = JsNodeArray.create();
for (int i = 0; i < n.getLength(); i++) {
res.addNode(n.getItem(i));
}
@@ -530,7 +457,7 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> { engine = new SelectorEngine();
}
NodeList<Element> n = engine.select(selector, context);
- JSArray res = copyNodeList(n);
+ JsNodeArray res = copyNodeList(n);
return res;
}
@@ -549,7 +476,7 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> { private GQuery(Element element) {
if (element != null) {
- elements = JSArray.create(element);
+ elements = JsNodeArray.create(element);
}
}
@@ -557,7 +484,7 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> { this(gq == null ? null : gq.get());
}
- private GQuery(JSArray elements) {
+ private GQuery(JsNodeArray elements) {
if (elements != null) {
this.elements = elements;
}
@@ -719,18 +646,6 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> { }
/**
- * Return a GWT Widget containing the first matched element.
- *
- * If the element is already associated to a widget it returns the original
- * widget, otherwise a new GWT widget will be created depending on the
- * tagName.
- *
- */
-// public Widget asWidget() {
-// return as(Widgets).widget();
-// }
-
- /**
* Set a key/value object as properties to all matched elements.
*
* Example: $("img").attr(new
@@ -840,7 +755,7 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> { * at all ancestors, children() will only consider immediate child elements.
*/
public GQuery children() {
- JSArray result = JSArray.create();
+ JsNodeArray result = JsNodeArray.create();
for (Element e : elements()) {
allNextSiblingElements(e.getFirstChildElement(), result, null);
}
@@ -885,7 +800,7 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> { * copies of the elements to another location in the DOM.
*/
public GQuery clone() {
- JSArray result = JSArray.create();
+ JsNodeArray result = JsNodeArray.create();
for (Element e : elements()) {
result.addNode(e.cloneNode(true));
}
@@ -896,7 +811,7 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> { * Filter the set of elements to those that contain the specified text.
*/
public GQuery contains(String text) {
- JSArray array = JSArray.create();
+ JsNodeArray array = JsNodeArray.create();
for (Element e : elements()) {
if ($(e).text().contains(text)) {
array.addNode(e);
@@ -910,7 +825,7 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> { * nodes), or the content document, if the element is an iframe.
*/
public GQuery contents() {
- JSArray result = JSArray.create();
+ JsNodeArray result = JsNodeArray.create();
for (Element e : elements()) {
if (IFrameElement.is(e)) {
result.addNode(getContentDocument(e));
@@ -1218,7 +1133,7 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> { * - anything else and the element is kept.
*/
public GQuery filter(Predicate filterFn) {
- JSArray result = JSArray.create();
+ JsNodeArray result = JsNodeArray.create();
for (int i = 0; i < elements.getLength(); i++) {
Element e = elements.getItem(i);
if (filterFn.f(e, i)) {
@@ -1235,7 +1150,7 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> { * filters at once.
*/
public GQuery filter(String... filters) {
- JSArray array = JSArray.create();
+ JsNodeArray array = JsNodeArray.create();
for (String f : filters) {
for (Element e : elements()) {
for (Element c : $(f, e.getParentNode()).elements()) {
@@ -1258,7 +1173,7 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> { * once.
*/
public GQuery find(String... filters) {
- JSArray array = JSArray.create();
+ JsNodeArray array = JsNodeArray.create();
for (String selector : filters) {
for (Element e : elements()) {
for (Element c : $(selector, e).elements()) {
@@ -1659,7 +1574,7 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> { * element, not all next siblings see {#nextAll}.
*/
public GQuery next() {
- JSArray result = JSArray.create();
+ JsNodeArray result = JsNodeArray.create();
for (Element e : elements()) {
Element next = e.getNextSiblingElement();
if (next != null) {
@@ -1676,7 +1591,7 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> { * {#nextAll}.
*/
public GQuery next(String... selectors) {
- JSArray result = JSArray.create();
+ JsNodeArray result = JsNodeArray.create();
for (Element e : elements()) {
Element next = e.getNextSiblingElement();
if (next != null) {
@@ -1690,7 +1605,7 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> { * Find all sibling elements after the current element.
*/
public GQuery nextAll() {
- JSArray result = JSArray.create();
+ JsNodeArray result = JsNodeArray.create();
for (Element e : elements()) {
allNextSiblingElements(e.getNextSiblingElement(), result, null);
}
@@ -1702,7 +1617,7 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> { * is used to remove a single Element from a jQuery object.
*/
public GQuery not(Element elem) {
- JSArray array = JSArray.create();
+ JsNodeArray array = JsNodeArray.create();
for (Element e : elements()) {
if (e != elem) {
array.addNode(e);
@@ -1750,7 +1665,7 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> { * relative or absolute). This method only works with visible elements.
*/
public GQuery offsetParent() {
- Element offParent = GQUtils.or(elements.getItem(0).getOffsetParent(), body);
+ Element offParent = JsUtils.or(elements.getItem(0).getOffsetParent(), body);
while (offParent != null
&& !"body".equalsIgnoreCase(offParent.getTagName())
&& !"html".equalsIgnoreCase(offParent.getTagName())
@@ -1822,7 +1737,7 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> { * elements.
*/
public GQuery parent() {
- JSArray result = JSArray.create();
+ JsNodeArray result = JsNodeArray.create();
for (Element e : elements()) {
Element p = e.getParentElement();
if (p != null) {
@@ -1846,7 +1761,7 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> { * elements (except for the root element).
*/
public GQuery parents() {
- JSArray result = JSArray.create();
+ JsNodeArray result = JsNodeArray.create();
for (Element e : elements()) {
Node par = e.getParentNode();
while (par != null && par != document) {
@@ -1985,7 +1900,7 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> { * returned, not all previous siblings.
*/
public GQuery prev() {
- JSArray result = JSArray.create();
+ JsNodeArray result = JsNodeArray.create();
for (Element e : elements()) {
Element next = getPreviousSiblingElement(e);
if (next != null) {
@@ -2001,7 +1916,7 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> { * previous sibling is returned, not all previous siblings.
*/
public GQuery prev(String... selectors) {
- JSArray result = JSArray.create();
+ JsNodeArray result = JsNodeArray.create();
for (Element e : elements()) {
Element next = getPreviousSiblingElement(e);
if (next != null) {
@@ -2015,7 +1930,7 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> { * Find all sibling elements in front of the current element.
*/
public GQuery prevAll() {
- JSArray result = JSArray.create();
+ JsNodeArray result = JsNodeArray.create();
for (Element e : elements()) {
allPreviousSiblingElements(getPreviousSiblingElement(e), result);
}
@@ -2282,7 +2197,7 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> { */
public GQuery show() {
for (Element e : elements()) {
- styleImpl.setStyleProperty(e, "display", GQUtils.or((String) data(e,
+ styleImpl.setStyleProperty(e, "display", JsUtils.or((String) data(e,
"oldDisplay", null), ""));
// When the display=none is in the stylesheet.
if (!styleImpl.isVisible(e)) {
@@ -2297,7 +2212,7 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> { * matched set of elements.
*/
public GQuery siblings() {
- JSArray result = JSArray.create();
+ JsNodeArray result = JsNodeArray.create();
for (Element e : elements()) {
allNextSiblingElements(e.getParentElement().getFirstChildElement(),
result, e);
@@ -2324,7 +2239,7 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> { * Selects a subset of the matched elements.
*/
public GQuery slice(int start, int end) {
- JSArray slice = JSArray.create();
+ JsNodeArray slice = JsNodeArray.create();
if (end == -1 || end > elements.getLength()) {
end = elements.getLength();
}
@@ -2476,8 +2391,8 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> { * Remove all duplicate elements from an array of elements. Note that this
* only works on arrays of DOM elements, not strings or numbers.
*/
- public JSArray unique(JSArray result) {
- return GQUtils.unique(result.<JsArray<Element>> cast()).cast();
+ public JsNodeArray unique(JsNodeArray result) {
+ return JsUtils.unique(result.<JsArray<Element>> cast()).cast();
}
/**
@@ -2824,7 +2739,7 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> { return wrapInner($(html));
}
- protected GQuery pushStack(JSArray elts, String name, String selector) {
+ protected GQuery pushStack(JsNodeArray elts, String name, String selector) {
GQuery g = new GQuery(elts);
g.setPreviousObject(this);
g.setSelector(selector);
@@ -2832,7 +2747,7 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> { }
private void allNextSiblingElements(Element firstChildElement,
- JSArray result, Element elem) {
+ JsNodeArray result, Element elem) {
while (firstChildElement != null) {
if (firstChildElement != elem) {
result.addNode(firstChildElement);
@@ -2842,7 +2757,7 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> { }
private void allPreviousSiblingElements(Element firstChildElement,
- JSArray result) {
+ JsNodeArray result) {
while (firstChildElement != null) {
result.addNode(firstChildElement);
firstChildElement = getPreviousSiblingElement(firstChildElement);
@@ -2862,7 +2777,7 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> { }
private GQuery domManip(GQuery g, int func, Element... elms) {
- JSArray newNodes = JSArray.create();
+ JsNodeArray newNodes = JsNodeArray.create();
if (elms.length == 0) {
elms = elements();
}
@@ -2921,8 +2836,8 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> { return sib;
}-*/;
- private JSArray merge(NodeList<Element> first, NodeList<Element> second) {
- JSArray res = copyNodeList(first);
+ private JsNodeArray merge(NodeList<Element> first, NodeList<Element> second) {
+ JsNodeArray res = copyNodeList(first);
for (int i = 0; i < second.getLength(); i++) {
res.addNode(second.getItem(i));
}
diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/JSArray.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/JSArray.java index 18f250ac..45fec7ad 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/JSArray.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/JSArray.java @@ -15,22 +15,26 @@ */
package com.google.gwt.query.client;
-import com.google.gwt.core.client.JavaScriptObject;
-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;
/**
+ * @deprecated use JsNodeArray
*/
-public class JSArray extends NodeList<Element> {
+@Deprecated
+public final class JSArray extends JsNodeArray {
+
+ protected JSArray() {
+ }
public static JSArray create() {
- return (JSArray) JavaScriptObject.createArray();
+ return JsNodeArray.create().cast();
}
- public static native JSArray create(Node node) /*-{
- return node ? [node] : [];
- }-*/;
+ public static JSArray create(Node node) {
+ return JsNodeArray.create(node).cast();
+ }
public static JSArray create(NodeList<?> nl) {
JSArray ret = create();
@@ -40,48 +44,4 @@ public class JSArray extends NodeList<Element> { return ret;
}
- protected JSArray() {
- }
-
- public final native void addInt(int i) /*-{
- this[this.length]=i;
- }-*/;
-
- public final native void addNode(Node n) /*-{
- if (n) this[this.length]=n;
- }-*/;
-
- public final native void addNode(Node n, int i) /*-{
- if (n) this[i]=n;
- }-*/;
-
- public final native void concat(JSArray ary) /*-{
- this.concat(ary);
- }-*/;
-
- public final native Element getElement(int i) /*-{
- return this[i];
- }-*/;
-
- public final native int getInt(int i) /*-{
- return this[i] || 0;
- }-*/;
-
- public final native Node getNode(int i) /*-{
- return this[i];
- }-*/;
-
- public final native String getStr(int i) /*-{
- return this[i] || null;
- }-*/;
-
- public final void pushAll(JSArray prevElem) {
- for (int i = 0, ilen = prevElem.size(); i < ilen; i++) {
- addNode(prevElem.getNode(i));
- }
- }
-
- public final native int size() /*-{
- return this.length;
- }-*/;
}
diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/LazyGQuery.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/LazyGQuery.java index 2c62ea61..23c43914 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/LazyGQuery.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/LazyGQuery.java @@ -14,44 +14,18 @@ * the License. */ package com.google.gwt.query.client; -import static com.google.gwt.query.client.plugins.Effects.Effects; -import static com.google.gwt.query.client.plugins.Events.Events; -import static com.google.gwt.query.client.plugins.Widgets.Widgets; -import com.google.gwt.core.client.GWT; -import com.google.gwt.core.client.JavaScriptObject; -import com.google.gwt.core.client.JsArray; -import com.google.gwt.core.client.JsArrayString; -import com.google.gwt.dom.client.BodyElement; -import com.google.gwt.dom.client.ButtonElement; -import com.google.gwt.dom.client.Document; +import java.util.List; + import com.google.gwt.dom.client.Element; -import com.google.gwt.dom.client.IFrameElement; -import com.google.gwt.dom.client.InputElement; import com.google.gwt.dom.client.Node; import com.google.gwt.dom.client.NodeList; -import com.google.gwt.dom.client.OptionElement; -import com.google.gwt.dom.client.SelectElement; -import com.google.gwt.dom.client.TextAreaElement; -import com.google.gwt.dom.client.Style.Display; import com.google.gwt.dom.client.Style.HasCssName; import com.google.gwt.query.client.css.CSS; import com.google.gwt.query.client.css.HasCssValue; import com.google.gwt.query.client.css.TakesCssValue; import com.google.gwt.query.client.css.TakesCssValue.CssSetter; -import com.google.gwt.query.client.impl.DocumentStyleImpl; -import com.google.gwt.query.client.impl.SelectorEngine; -import com.google.gwt.query.client.plugins.Plugin; -import com.google.gwt.query.client.plugins.events.EventsListener; -import com.google.gwt.user.client.DOM; -import com.google.gwt.user.client.Event; -import com.google.gwt.user.client.EventListener; -import com.google.gwt.user.client.Window; +import com.google.gwt.query.client.js.JsNodeArray; import com.google.gwt.user.client.ui.Widget; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashMap; -import java.util.List; -import com.google.gwt.query.client.LazyBase; public interface LazyGQuery<T> extends LazyBase<T>{ @@ -156,16 +130,6 @@ public interface LazyGQuery<T> extends LazyBase<T>{ <T extends GQuery> T as(Class<T> plugin); /** - * Return a GWT Widget containing the first matched element. - * - * If the element is already associated to a widget it returns the original - * widget, otherwise a new GWT widget will be created depending on the - * tagName. - * - */ - // Widget asWidget(); - - /** * Set a key/value object as properties to all matched elements. * * Example: $("img").attr(new @@ -1181,7 +1145,7 @@ public interface LazyGQuery<T> extends LazyBase<T>{ * Remove all duplicate elements from an array of elements. Note that this * only works on arrays of DOM elements, not strings or numbers. */ - JSArray unique(JSArray result); + JsNodeArray unique(JsNodeArray result); /** * Gets the content of the value attribute of the first matched element, diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/DocumentStyleImpl.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/DocumentStyleImpl.java index 3eec5c5c..d3f74717 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/DocumentStyleImpl.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/DocumentStyleImpl.java @@ -16,7 +16,7 @@ package com.google.gwt.query.client.impl; import com.google.gwt.dom.client.Element; -import com.google.gwt.query.client.GQUtils; +import com.google.gwt.query.client.js.JsUtils; /** * A helper class to get computed CSS styles for elements. @@ -118,7 +118,7 @@ public class DocumentStyleImpl { public double getOpacity(Element e) { String o = e.getStyle().getOpacity(); - return GQUtils.truth(o) ? num(o) : 1; + return JsUtils.truth(o) ? num(o) : 1; } public int getWidth(Element e) { @@ -134,7 +134,7 @@ public class DocumentStyleImpl { public double num(String val) { val = val.trim().replaceAll("[^\\d\\.\\-]+.*$", ""); - return GQUtils.truth(val) ? Double.parseDouble(val) : 0; + return JsUtils.truth(val) ? Double.parseDouble(val) : 0; } /** diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/SelectorEngine.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/SelectorEngine.java index 8d7abf75..ddf66974 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/SelectorEngine.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/SelectorEngine.java @@ -20,7 +20,7 @@ import com.google.gwt.dom.client.Document; 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.JSArray;
+import com.google.gwt.query.client.js.JsNodeArray;
/**
* Core Selector engine functions, and native JS utility functions.
@@ -57,11 +57,11 @@ public class SelectorEngine { }-*/;
public static NodeList<Element> xpathEvaluate(String selector, Node ctx) {
- return xpathEvaluate(selector, ctx, JSArray.create());
+ return xpathEvaluate(selector, ctx, JsNodeArray.create());
}
public static native NodeList<Element> xpathEvaluate(String selector,
- Node ctx, JSArray r) /*-{
+ Node ctx, JsNodeArray r) /*-{
var node;
var ownerDoc = ctx && (ctx.ownerDocument || ctx );
var evalDoc = ownerDoc ? ownerDoc : $doc;
@@ -95,8 +95,8 @@ public class SelectorEngine { this.root = root;
}
- protected JSArray veryQuickId(Node context, String id) {
- JSArray r = JSArray.create();
+ protected JsNodeArray veryQuickId(Node context, String id) {
+ JsNodeArray r = JsNodeArray.create();
if (context.getNodeType() == Node.DOCUMENT_NODE) {
r.addNode(((Document) context).getElementById(id));
return r;
diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/SelectorEngineCssToXPath.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/SelectorEngineCssToXPath.java index fed3bea8..459057b6 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/SelectorEngineCssToXPath.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/SelectorEngineCssToXPath.java @@ -22,9 +22,10 @@ import com.google.gwt.core.client.JsArray; 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.GQUtils;
-import com.google.gwt.query.client.JSArray;
-import com.google.gwt.query.client.JSRegexp;
+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;
/**
* Runtime selector engine implementation which translates selectors to XPath
@@ -149,14 +150,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);
+ JsRegexp p = new JsRegexp(r);
if (o instanceof ReplaceCallback) {
ReplaceCallback callback = (ReplaceCallback) o;
while (p.test(s)) {
- JSArray a = p.match(s);
+ JsObjectArray<String> a = p.match(s);
ArrayList<String> args = new ArrayList<String>();
- for (int i = 0; i < a.getLength(); i++) {
- args.add(a.getStr(i));
+ for (int i = 0; i < a.length(); i++) {
+ args.add(a.get(i));
}
String f = callback.foundMatch(args);
s = s.replaceFirst(r, f);
@@ -186,14 +187,14 @@ public class SelectorEngineCssToXPath extends SelectorEngineImpl { }
public NodeList<Element> select(String sel, Node ctx) {
- JSArray elm = JSArray.create();
+ JsNodeArray elm = JsNodeArray.create();
String xsel = cache.get(sel);
if (xsel == null) {
xsel = sel.startsWith("./") || sel.startsWith("/") ? sel : css2Xpath(sel);
cache.put(sel, xsel);
}
SelectorEngine.xpathEvaluate(xsel, ctx, elm);
- return GQUtils.unique(elm.<JsArray<Element>> cast()).cast();
+ return JsUtils.unique(elm.<JsArray<Element>> cast()).cast();
}
}
diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/SelectorEngineImpl.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/SelectorEngineImpl.java index eee63054..d968a5ff 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/SelectorEngineImpl.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/SelectorEngineImpl.java @@ -14,12 +14,6 @@ * the License.
*/
package com.google.gwt.query.client.impl;
-import static com.google.gwt.query.client.GQUtils.eq;
-import static com.google.gwt.query.client.GQUtils.truth;
-
-import com.google.gwt.query.client.GQUtils;
-import com.google.gwt.query.client.JSArray;
-import com.google.gwt.query.client.JSRegexp;
/**
* Base/Utility class for runtime selector engine implementations.
diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/research/SelectorEngineJS.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/research/SelectorEngineJS.java index e1ac1ae7..0cf72d59 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/research/SelectorEngineJS.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/research/SelectorEngineJS.java @@ -15,8 +15,8 @@ */
package com.google.gwt.query.client.impl.research;
-import static com.google.gwt.query.client.GQUtils.eq;
-import static com.google.gwt.query.client.GQUtils.truth;
+import static com.google.gwt.query.client.js.JsUtils.eq;
+import static com.google.gwt.query.client.js.JsUtils.truth;
import com.google.gwt.core.client.JavaScriptObject;
import com.google.gwt.core.client.JsArray;
@@ -24,11 +24,12 @@ import com.google.gwt.dom.client.Document; 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.GQUtils;
-import com.google.gwt.query.client.JSArray;
-import com.google.gwt.query.client.JSRegexp;
import com.google.gwt.query.client.impl.SelectorEngine;
import com.google.gwt.query.client.impl.SelectorEngineImpl;
+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;
/**
* Runtime selector engine implementation with no-XPath/native support based on
@@ -90,35 +91,35 @@ public class SelectorEngineJS extends SelectorEngineImpl { protected static Sequence getSequence(String expression) {
int start = 0, add = 2, max = -1, modVal = -1;
- JSRegexp expressionRegExp = new JSRegexp(
+ JsRegexp expressionRegExp = new JsRegexp(
"^((odd|even)|([1-9]\\d*)|((([1-9]\\d*)?)n((\\+|\\-)(\\d+))?)|(\\-(([1-9]\\d*)?)n\\+(\\d+)))$");
- JSArray pseudoValue = expressionRegExp.exec(expression);
+ JsObjectArray<String> pseudoValue = expressionRegExp.exec(expression);
if (!truth(pseudoValue)) {
return null;
} else {
- if (truth(pseudoValue.getStr(2))) { // odd or even
- start = (eq(pseudoValue.getStr(2), "odd")) ? 1 : 2;
+ if (truth(pseudoValue.get(2))) { // odd or even
+ start = (eq(pseudoValue.get(2), "odd")) ? 1 : 2;
modVal = (start == 1) ? 1 : 0;
- } else if (GQUtils
- .truth(pseudoValue.getStr(3))) { // single digit
- start = Integer.parseInt(pseudoValue.getStr(3), 10);
+ } else if (JsUtils
+ .truth(pseudoValue.get(3))) { // single digit
+ start = Integer.parseInt(pseudoValue.get(3), 10);
add = 0;
max = start;
- } else if (truth(pseudoValue.getStr(4))) { // an+b
- add = truth(pseudoValue.getStr(6)) ? Integer
- .parseInt(pseudoValue.getStr(6), 10) : 1;
- start = truth(pseudoValue.getStr(7)) ? Integer.parseInt(
- (pseudoValue.getStr(8).charAt(0) == '+' ? ""
- : pseudoValue.getStr(8)) + pseudoValue.getStr(9), 10) : 0;
+ } else if (truth(pseudoValue.get(4))) { // an+b
+ add = truth(pseudoValue.get(6)) ? Integer
+ .parseInt(pseudoValue.get(6), 10) : 1;
+ start = truth(pseudoValue.get(7)) ? Integer.parseInt(
+ (pseudoValue.get(8).charAt(0) == '+' ? ""
+ : pseudoValue.get(8)) + pseudoValue.get(9), 10) : 0;
while (start < 1) {
start += add;
}
modVal = (start > add) ? (start - add) % add
: ((start == add) ? 0 : start);
- } else if (truth(pseudoValue.getStr(10))) { // -an+b
- add = truth(pseudoValue.getStr(12)) ? Integer
- .parseInt(pseudoValue.getStr(12), 10) : 1;
- start = max = Integer.parseInt(pseudoValue.getStr(13), 10);
+ } else if (truth(pseudoValue.get(10))) { // -an+b
+ add = truth(pseudoValue.get(12)) ? Integer
+ .parseInt(pseudoValue.get(12), 10) : 1;
+ start = max = Integer.parseInt(pseudoValue.get(13), 10);
while (start > add) {
start -= add;
}
@@ -133,7 +134,7 @@ public class SelectorEngineJS extends SelectorEngineImpl { return s;
}
- public static void clearAdded(JSArray a) {
+ public static void clearAdded(JsNodeArray a) {
for (int i = 0, len = a.size(); i < len; i++) {
clearAdded(a.getNode(i));
}
@@ -156,34 +157,34 @@ public class SelectorEngineJS extends SelectorEngineImpl { prevRef.added = added;
}-*/;
- public static native void setSkipTag(JSArray prevElem, boolean skip) /*-{
+ public static native void setSkipTag(JsNodeArray prevElem, boolean skip) /*-{
prevElem.skipTag = skip;
}-*/;
private static String attrToRegExp(String attrVal, String op) {
- if (GQUtils.eq("^", op)) {
+ if (JsUtils.eq("^", op)) {
return "^" + attrVal;
}
- if (GQUtils.eq("$", op)) {
+ if (JsUtils.eq("$", op)) {
return attrVal + "$";
}
- if (GQUtils.eq("*", op)) {
+ if (JsUtils.eq("*", op)) {
return attrVal;
}
- if (GQUtils.eq("|", op)) {
+ if (JsUtils.eq("|", op)) {
return "(^" + attrVal + "(\\-\\w+)*$)";
}
- if (GQUtils.eq("~", op)) {
+ if (JsUtils.eq("~", op)) {
return "\\b" + attrVal + "\\b";
}
- return GQUtils.truth(attrVal) ? "^" + attrVal + "$" : null;
+ return JsUtils.truth(attrVal) ? "^" + attrVal + "$" : null;
}
private static native boolean checked(Node previous) /*-{
return previous.checked || false;
}-*/;
- private static void clearChildElms(JSArray prevParents) {
+ private static void clearChildElms(JsNodeArray prevParents) {
for (int n = 0, nl = prevParents.size(); n < nl; n++) {
setHasChildElms(prevParents.getNode(n), false);
}
@@ -193,7 +194,7 @@ public class SelectorEngineJS extends SelectorEngineImpl { return !node.disabled;
}-*/;
- private static void getDescendantNodes(JSArray matchingElms,
+ private static void getDescendantNodes(JsNodeArray matchingElms,
String nextTagStr, Node prevRef) {
NodeList<Element> children = getElementsByTagName(nextTagStr, prevRef);
for (int k = 0, klen = children.getLength(); k < klen; k++) {
@@ -211,12 +212,12 @@ public class SelectorEngineJS extends SelectorEngineImpl { return ((Element) ctx).getElementsByTagName(tag);
}
- private static void getGeneralSiblingNodes(JSArray matchingElms,
- JSArray nextTag, JSRegexp nextRegExp, Node prevRef) {
+ private static void getGeneralSiblingNodes(JsNodeArray matchingElms,
+ JsObjectArray<String> nextTag, JsRegexp nextRegExp, Node prevRef) {
while (
- GQUtils.truth((prevRef = SelectorEngine.getNextSibling(prevRef)))
+ JsUtils.truth((prevRef = SelectorEngine.getNextSibling(prevRef)))
&& !isAdded(prevRef)) {
- if (!GQUtils.truth(nextTag) || nextRegExp
+ if (!JsUtils.truth(nextTag) || nextRegExp
.test(prevRef.getNodeName())) {
setAdded(prevRef, true);
matchingElms.addNode(prevRef);
@@ -224,14 +225,14 @@ public class SelectorEngineJS extends SelectorEngineImpl { }
}
- private static void getSiblingNodes(JSArray matchingElms, JSArray nextTag,
- JSRegexp nextRegExp, Node prevRef) {
+ private static void getSiblingNodes(JsNodeArray matchingElms, JsObjectArray<String> nextTag,
+ JsRegexp nextRegExp, Node prevRef) {
while (
- GQUtils.truth(prevRef = SelectorEngine.getNextSibling(prevRef))
+ JsUtils.truth(prevRef = SelectorEngine.getNextSibling(prevRef))
&& prevRef.getNodeType() != Node.ELEMENT_NODE) {
}
- if (GQUtils.truth(prevRef)) {
- if (!GQUtils.truth(nextTag) || nextRegExp
+ if (JsUtils.truth(prevRef)) {
+ if (!JsUtils.truth(nextTag) || nextRegExp
.test(prevRef.getNodeName())) {
matchingElms.addNode(prevRef);
}
@@ -242,7 +243,7 @@ public class SelectorEngineJS extends SelectorEngineImpl { return prevParent.childElms || false;
}-*/;
- private static native boolean isSkipped(JSArray prevElem) /*-{
+ private static native boolean isSkipped(JsNodeArray prevElem) /*-{
return prevElem.skipTag || false;
}-*/;
@@ -250,8 +251,8 @@ public class SelectorEngineJS extends SelectorEngineImpl { prevParent.childElms = bool ? bool : null;
}-*/;
- private static native JSArray subtractArray(JSArray previousMatch,
- JSArray elementsByPseudo) /*-{
+ private static native JsNodeArray subtractArray(JsNodeArray previousMatch,
+ JsNodeArray elementsByPseudo) /*-{
for (var i=0, src1; (src1=arr1[i]); i++) {
var found = false;
for (var j=0, src2; (src2=arr2[j]); j++) {
@@ -267,28 +268,28 @@ public class SelectorEngineJS extends SelectorEngineImpl { return arr;
}-*/;
- private JSRegexp cssSelectorRegExp;
+ private JsRegexp cssSelectorRegExp;
- private JSRegexp selectorSplitRegExp;
+ private JsRegexp selectorSplitRegExp;
- private JSRegexp childOrSiblingRefRegExp;
+ private JsRegexp childOrSiblingRefRegExp;
public SelectorEngineJS() {
- selectorSplitRegExp = new JSRegexp("[^\\s]+", "g");
- childOrSiblingRefRegExp = new JSRegexp("^(>|\\+|~)$");
- cssSelectorRegExp = new JSRegexp(
+ selectorSplitRegExp = new JsRegexp("[^\\s]+", "g");
+ childOrSiblingRefRegExp = new JsRegexp("^(>|\\+|~)$");
+ cssSelectorRegExp = new JsRegexp(
"^(\\w+)?(#[\\w\\u00C0-\\uFFFF\\-\\_]+|(\\*))?((\\.[\\w\\u00C0-\\uFFFF\\-_]+)*)?((\\[\\w+(\\^|\\$|\\*|\\||~)?(=[\"']*[\\w\\u00C0-\\uFFFF\\s\\-\\_\\.]+[\"']*)?\\]+)*)?(((:\\w+[\\w\\-]*)(\\((odd|even|\\-?\\d*n?((\\+|\\-)\\d+)?|[\\w\\u00C0-\\uFFFF\\-_]+|((\\w*\\.[\\w\\u00C0-\\uFFFF\\-_]+)*)?|(\\[#?\\w+(\\^|\\$|\\*|\\||~)?=?[\\w\\u00C0-\\uFFFF\\s\\-\\_\\.]+\\]+)|(:\\w+[\\w\\-]*))\\))?)*)?");
}
public NodeList<Element> select(String sel, Node ctx) {
String selectors[] = sel.replace("\\s*(,)\\s*", "$1").split(",");
boolean identical = false;
- JSArray elm = JSArray.create();
+ JsNodeArray elm = JsNodeArray.create();
for (int a = 0, len = selectors.length; a < len; a++) {
if (a > 0) {
identical = false;
for (int b = 0, bl = a; b < bl; b++) {
- if (GQUtils.eq(selectors[a], selectors[b])) {
+ if (JsUtils.eq(selectors[a], selectors[b])) {
identical = true;
break;
}
@@ -298,61 +299,61 @@ public class SelectorEngineJS extends SelectorEngineImpl { }
}
String currentRule = selectors[a];
- JSArray cssSelectors = selectorSplitRegExp.match(currentRule);
- JSArray prevElem = JSArray.create(ctx);
- for (int i = 0, slen = cssSelectors.size(); i < slen; i++) {
- JSArray matchingElms = JSArray.create();
- String rule = cssSelectors.getStr(i);
+ JsObjectArray<String> cssSelectors = selectorSplitRegExp.match(currentRule);
+ JsNodeArray prevElem = JsNodeArray.create(ctx);
+ for (int i = 0, slen = cssSelectors.length(); i < slen; i++) {
+ JsNodeArray matchingElms = JsNodeArray.create();
+ String rule = cssSelectors.get(i);
if (i > 0 && childOrSiblingRefRegExp.test(rule)) {
- JSArray childOrSiblingRef = childOrSiblingRefRegExp.exec(rule);
- if (GQUtils.truth(childOrSiblingRef)) {
- JSArray nextTag = new JSRegexp("^\\w+")
- .exec(cssSelectors.getStr(i + 1));
- JSRegexp nextRegExp = null;
+ JsObjectArray<String> childOrSiblingRef = childOrSiblingRefRegExp.exec(rule);
+ if (JsUtils.truth(childOrSiblingRef)) {
+ JsObjectArray<String> nextTag = new JsRegexp("^\\w+")
+ .exec(cssSelectors.get(i + 1));
+ JsRegexp nextRegExp = null;
String nextTagStr = null;
- if (GQUtils.truth(nextTag)) {
- nextTagStr = nextTag.getStr(0);
- nextRegExp = new JSRegexp("(^|\\s)" + nextTagStr + "(\\s|$)", "i");
+ if (JsUtils.truth(nextTag)) {
+ nextTagStr = nextTag.get(0);
+ nextRegExp = new JsRegexp("(^|\\s)" + nextTagStr + "(\\s|$)", "i");
}
for (int j = 0, jlen = prevElem.size(); j < jlen; j++) {
Node prevRef = prevElem.getNode(j);
- String ref = childOrSiblingRef.getStr(0);
- if (GQUtils.eq(">", ref)) {
+ String ref = childOrSiblingRef.get(0);
+ if (JsUtils.eq(">", ref)) {
getDescendantNodes(matchingElms, nextTagStr, prevRef);
- } else if (GQUtils.eq("+", ref)) {
+ } else if (JsUtils.eq("+", ref)) {
getSiblingNodes(matchingElms, nextTag, nextRegExp, prevRef);
- } else if (GQUtils.eq("~", ref)) {
+ } else if (JsUtils.eq("~", ref)) {
getGeneralSiblingNodes(matchingElms, nextTag, nextRegExp,
prevRef);
}
}
prevElem = matchingElms;
clearAdded(prevElem);
- rule = cssSelectors.getStr(++i);
- if (new JSRegexp("^\\w+$").test(rule)) {
+ rule = cssSelectors.get(++i);
+ if (new JsRegexp("^\\w+$").test(rule)) {
continue;
}
setSkipTag(prevElem, true);
}
}
- JSArray cssSelector = cssSelectorRegExp.exec(rule);
+ JsObjectArray<String> cssSelector = cssSelectorRegExp.exec(rule);
SplitRule splitRule = new SplitRule(
- !GQUtils.truth(cssSelector.getStr(1)) || GQUtils
- .eq(cssSelector.getStr(3), "*") ? "*" : cssSelector.getStr(1),
- !GQUtils.eq(cssSelector.getStr(3), "*") ? cssSelector
- .getStr(2) : null, cssSelector.getStr(4), cssSelector.getStr(6),
- cssSelector.getStr(10));
- if (GQUtils.truth(splitRule.id)) {
+ !JsUtils.truth(cssSelector.get(1)) || JsUtils
+ .eq(cssSelector.get(3), "*") ? "*" : cssSelector.get(1),
+ !JsUtils.eq(cssSelector.get(3), "*") ? cssSelector
+ .get(2) : null, cssSelector.get(4), cssSelector.get(6),
+ cssSelector.get(10));
+ if (JsUtils.truth(splitRule.id)) {
Element domelem = Document.get()
.getElementById(splitRule.id.substring(1));
- if (GQUtils.truth(domelem)) {
- matchingElms = JSArray.create(domelem);
+ if (JsUtils.truth(domelem)) {
+ matchingElms = JsNodeArray.create(domelem);
}
prevElem = matchingElms;
- } else if (GQUtils.truth(splitRule.tag) && !isSkipped(
+ } else if (JsUtils.truth(splitRule.tag) && !isSkipped(
prevElem)) {
if (i == 0 && matchingElms.size() == 0 && prevElem.size() == 1) {
- prevElem = matchingElms = JSArray.create(
+ prevElem = matchingElms = JsNodeArray.create(
getElementsByTagName(splitRule.tag, prevElem.getNode(0)));
} else {
NodeList<Element> tagCollectionMatches;
@@ -376,20 +377,20 @@ public class SelectorEngineJS extends SelectorEngineImpl { break;
}
setSkipTag(prevElem, false);
- if (GQUtils.truth(splitRule.allClasses)) {
+ if (JsUtils.truth(splitRule.allClasses)) {
String[] allClasses = splitRule.allClasses.replaceFirst("^\\.", "")
.split("\\.");
- JSRegexp[] regExpClassNames = new JSRegexp[allClasses.length];
+ JsRegexp[] regExpClassNames = new JsRegexp[allClasses.length];
for (int n = 0, nl = allClasses.length; n < nl; n++) {
- regExpClassNames[n] = new JSRegexp(
+ regExpClassNames[n] = new JsRegexp(
"(^|\\s)" + allClasses[n] + "(\\s|$)");
}
- JSArray matchingClassElms = JSArray.create();
+ JsNodeArray matchingClassElms = JsNodeArray.create();
for (int o = 0, olen = prevElem.size(); o < olen; o++) {
Element current = prevElem.getElement(o);
String elmClass = current.getClassName();
boolean addElm = false;
- if (GQUtils.truth(elmClass) && !isAdded(current)) {
+ if (JsUtils.truth(elmClass) && !isAdded(current)) {
for (int p = 0, pl = regExpClassNames.length; p < pl; p++) {
addElm = regExpClassNames[p].test(elmClass);
if (!addElm) {
@@ -405,27 +406,27 @@ public class SelectorEngineJS extends SelectorEngineImpl { clearAdded(prevElem);
prevElem = matchingElms = matchingClassElms;
}
- if (GQUtils.truth(splitRule.allAttr)) {
- JSArray allAttr = JSRegexp
+ if (JsUtils.truth(splitRule.allAttr)) {
+ JsObjectArray<String> allAttr = JsRegexp
.match("\\[[^\\]]+\\]", "g", splitRule.allAttr);
- JSRegexp[] regExpAttributes = new JSRegexp[allAttr.size()];
- String[] regExpAttributesStr = new String[allAttr.size()];
- JSRegexp attributeMatchRegExp = new JSRegexp(
+ JsRegexp[] regExpAttributes = new JsRegexp[allAttr.length()];
+ String[] regExpAttributesStr = new String[allAttr.length()];
+ JsRegexp attributeMatchRegExp = new JsRegexp(
"(\\w+)(\\^|\\$|\\*|\\||~)?=?[\"']?([\\w\u00C0-\uFFFF\\s\\-_\\.]+)?");
- for (int q = 0, ql = allAttr.size(); q < ql; q++) {
- JSArray attributeMatch = attributeMatchRegExp
- .exec(allAttr.getStr(q));
+ for (int q = 0, ql = allAttr.length(); q < ql; q++) {
+ JsObjectArray<String> attributeMatch = attributeMatchRegExp
+ .exec(allAttr.get(q));
String attributeValue =
- GQUtils.truth(attributeMatch.getStr(3))
- ? attributeMatch.getStr(3).replaceAll("\\.", "\\.")
+ JsUtils.truth(attributeMatch.get(3))
+ ? attributeMatch.get(3).replaceAll("\\.", "\\.")
: null;
String attrVal = attrToRegExp(attributeValue,
- (GQUtils.or(attributeMatch.getStr(2), null)));
- regExpAttributes[q] = (GQUtils.truth(attrVal) ? new JSRegexp(
+ (JsUtils.or(attributeMatch.get(2), null)));
+ regExpAttributes[q] = (JsUtils.truth(attrVal) ? new JsRegexp(
attrVal) : null);
- regExpAttributesStr[q] = attributeMatch.getStr(1);
+ regExpAttributesStr[q] = attributeMatch.get(1);
}
- JSArray matchingAttributeElms = JSArray.create();
+ JsNodeArray matchingAttributeElms = JsNodeArray.create();
for (int r = 0, rlen = matchingElms.size(); r < rlen; r++) {
Element current = matchingElms.getElement(r);
@@ -433,9 +434,9 @@ public class SelectorEngineJS extends SelectorEngineImpl { for (int s = 0, sl = regExpAttributes.length;
s < sl; s++) {
addElm = false;
- JSRegexp attributeRegexp = regExpAttributes[s];
+ JsRegexp attributeRegexp = regExpAttributes[s];
String currentAttr = getAttr(current, regExpAttributesStr[s]);
- if (GQUtils.truth(currentAttr)
+ if (JsUtils.truth(currentAttr)
&& currentAttr.length() != 0) {
if (attributeRegexp == null || attributeRegexp
.test(currentAttr)) {
@@ -452,19 +453,19 @@ public class SelectorEngineJS extends SelectorEngineImpl { }
prevElem = matchingElms = matchingAttributeElms;
}
- if (GQUtils.truth(splitRule.allPseudos)) {
- JSRegexp pseudoSplitRegExp = new JSRegexp(
+ if (JsUtils.truth(splitRule.allPseudos)) {
+ JsRegexp pseudoSplitRegExp = new JsRegexp(
":(\\w[\\w\\-]*)(\\(([^\\)]+)\\))?");
- JSArray allPseudos = JSRegexp
+ JsObjectArray<String> allPseudos = JsRegexp
.match("(:\\w+[\\w\\-]*)(\\([^\\)]+\\))?", "g",
splitRule.allPseudos);
- for (int t = 0, tl = allPseudos.size(); t < tl; t++) {
- JSArray pseudo = pseudoSplitRegExp.match(allPseudos.getStr(t));
- String pseudoClass = GQUtils.truth(pseudo.getStr(1))
- ? pseudo.getStr(1).toLowerCase() : null;
- String pseudoValue = GQUtils.truth(pseudo.getStr(3))
- ? pseudo.getStr(3) : null;
+ for (int t = 0, tl = allPseudos.length(); t < tl; t++) {
+ JsObjectArray<String> pseudo = pseudoSplitRegExp.match(allPseudos.get(t));
+ String pseudoClass = JsUtils.truth(pseudo.get(1))
+ ? pseudo.get(1).toLowerCase() : null;
+ String pseudoValue = JsUtils.truth(pseudo.get(3))
+ ? pseudo.get(3) : null;
matchingElms = getElementsByPseudo(matchingElms, pseudoClass,
pseudoValue);
clearAdded(matchingElms);
@@ -476,14 +477,14 @@ public class SelectorEngineJS extends SelectorEngineImpl { elm.pushAll(prevElem);
}
- return GQUtils.unique(elm.<JsArray<Element>>cast()).cast();
+ return JsUtils.unique(elm.<JsArray<Element>>cast()).cast();
}
protected String getAttr(Element current, String name) {
return current.getAttribute(name);
}
- private void getCheckedPseudo(JSArray previousMatch, JSArray matchingElms) {
+ private void getCheckedPseudo(JsNodeArray previousMatch, JsNodeArray matchingElms) {
Node previous;
for (int q = 0, qlen = previousMatch.size(); q < qlen; q++) {
previous = previousMatch.getNode(q);
@@ -493,8 +494,8 @@ public class SelectorEngineJS extends SelectorEngineImpl { }
}
- private void getContainsPseudo(JSArray previousMatch, String pseudoValue,
- JSArray matchingElms) {
+ private void getContainsPseudo(JsNodeArray previousMatch, String pseudoValue,
+ JsNodeArray matchingElms) {
Node previous;
for (int q = 0, qlen = previousMatch.size(); q < qlen; q++) {
previous = previousMatch.getNode(q);
@@ -507,19 +508,19 @@ public class SelectorEngineJS extends SelectorEngineImpl { }
}
- private void getDefaultPseudo(JSArray previousMatch, String pseudoClass,
- String pseudoValue, JSArray matchingElms) {
+ private void getDefaultPseudo(JsNodeArray previousMatch, String pseudoClass,
+ String pseudoValue, JsNodeArray matchingElms) {
Node previous;
for (int w = 0, wlen = previousMatch.size(); w < wlen; w++) {
previous = previousMatch.getElement(w);
- if (GQUtils
+ if (JsUtils
.eq(((Element) previous).getAttribute(pseudoClass), pseudoValue)) {
matchingElms.addNode(previous);
}
}
}
- private void getDisabledPseudo(JSArray previousMatch, JSArray matchingElms) {
+ private void getDisabledPseudo(JsNodeArray previousMatch, JsNodeArray matchingElms) {
Node previous;
for (int q = 0, qlen = previousMatch.size(); q < qlen; q++) {
previous = previousMatch.getNode(q);
@@ -529,38 +530,38 @@ public class SelectorEngineJS extends SelectorEngineImpl { }
}
- private JSArray getElementsByPseudo(JSArray previousMatch, String pseudoClass,
+ private JsNodeArray getElementsByPseudo(JsNodeArray previousMatch, String pseudoClass,
String pseudoValue) {
- JSArray prevParents = JSArray.create();
+ JsNodeArray prevParents = JsNodeArray.create();
boolean previousDir = pseudoClass.startsWith("first") ? true : false;
- JSArray matchingElms = JSArray.create();
- if (GQUtils.eq("first-child", pseudoClass) || GQUtils
+ JsNodeArray matchingElms = JsNodeArray.create();
+ if (JsUtils.eq("first-child", pseudoClass) || JsUtils
.eq("last-child", pseudoClass)) {
getFirstChildPseudo(previousMatch, previousDir, matchingElms);
- } else if (GQUtils.eq("only-child", pseudoClass)) {
+ } else if (JsUtils.eq("only-child", pseudoClass)) {
getOnlyChildPseudo(previousMatch, matchingElms);
- } else if (GQUtils.eq("nth-child", pseudoClass)) {
+ } else if (JsUtils.eq("nth-child", pseudoClass)) {
matchingElms = getNthChildPseudo(previousMatch, pseudoValue, prevParents,
matchingElms);
- } else if (GQUtils.eq("first-of-type", pseudoClass) || GQUtils
+ } else if (JsUtils.eq("first-of-type", pseudoClass) || JsUtils
.eq("last-of-type", pseudoClass)) {
getFirstOfTypePseudo(previousMatch, previousDir, matchingElms);
- } else if (GQUtils.eq("only-of-type", pseudoClass)) {
+ } else if (JsUtils.eq("only-of-type", pseudoClass)) {
getOnlyOfTypePseudo(previousMatch, matchingElms);
- } else if (GQUtils.eq("nth-of-type", pseudoClass)) {
+ } else if (JsUtils.eq("nth-of-type", pseudoClass)) {
matchingElms = getNthOfTypePseudo(previousMatch, pseudoValue, prevParents,
matchingElms);
- } else if (GQUtils.eq("empty", pseudoClass)) {
+ } else if (JsUtils.eq("empty", pseudoClass)) {
getEmptyPseudo(previousMatch, matchingElms);
- } else if (GQUtils.eq("enabled", pseudoClass)) {
+ } else if (JsUtils.eq("enabled", pseudoClass)) {
getEnabledPseudo(previousMatch, matchingElms);
- } else if (GQUtils.eq("disabled", pseudoClass)) {
+ } else if (JsUtils.eq("disabled", pseudoClass)) {
getDisabledPseudo(previousMatch, matchingElms);
- } else if (GQUtils.eq("checked", pseudoClass)) {
+ } else if (JsUtils.eq("checked", pseudoClass)) {
getCheckedPseudo(previousMatch, matchingElms);
- } else if (GQUtils.eq("contains", pseudoClass)) {
+ } else if (JsUtils.eq("contains", pseudoClass)) {
getContainsPseudo(previousMatch, pseudoValue, matchingElms);
- } else if (GQUtils.eq("not", pseudoClass)) {
+ } else if (JsUtils.eq("not", pseudoClass)) {
matchingElms = getNotPseudo(previousMatch, pseudoValue, matchingElms);
} else {
getDefaultPseudo(previousMatch, pseudoClass, pseudoValue, matchingElms);
@@ -568,7 +569,7 @@ public class SelectorEngineJS extends SelectorEngineImpl { return matchingElms;
}
- private void getEmptyPseudo(JSArray previousMatch, JSArray matchingElms) {
+ private void getEmptyPseudo(JsNodeArray previousMatch, JsNodeArray matchingElms) {
Node previous;
for (int q = 0, qlen = previousMatch.size(); q < qlen; q++) {
previous = previousMatch.getNode(q);
@@ -578,7 +579,7 @@ public class SelectorEngineJS extends SelectorEngineImpl { }
}
- private void getEnabledPseudo(JSArray previousMatch, JSArray matchingElms) {
+ private void getEnabledPseudo(JsNodeArray previousMatch, JsNodeArray matchingElms) {
Node previous;
for (int q = 0, qlen = previousMatch.size(); q < qlen; q++) {
previous = previousMatch.getNode(q);
@@ -588,31 +589,31 @@ public class SelectorEngineJS extends SelectorEngineImpl { }
}
- private void getFirstChildPseudo(JSArray previousMatch, boolean previousDir,
- JSArray matchingElms) {
+ private void getFirstChildPseudo(JsNodeArray previousMatch, boolean previousDir,
+ JsNodeArray matchingElms) {
Node next;
Node previous;
for (int j = 0, jlen = previousMatch.size(); j < jlen; j++) {
previous = next = previousMatch.getElement(j);
if (previousDir) {
- while (GQUtils
+ while (JsUtils
.truth((next = SelectorEngine.getPreviousSibling(next)))
&& next.getNodeType() != Node.ELEMENT_NODE) {
}
} else {
while (
- GQUtils.truth((next = SelectorEngine.getNextSibling(next)))
+ JsUtils.truth((next = SelectorEngine.getNextSibling(next)))
&& next.getNodeType() != Node.ELEMENT_NODE) {
}
}
- if (!GQUtils.truth(next)) {
+ if (!JsUtils.truth(next)) {
matchingElms.addNode(previous);
}
}
}
- private void getFirstOfTypePseudo(JSArray previousMatch, boolean previousDir,
- JSArray matchingElms) {
+ private void getFirstOfTypePseudo(JsNodeArray previousMatch, boolean previousDir,
+ JsNodeArray matchingElms) {
Node previous;
Node next;
for (int n = 0, nlen = previousMatch.size(); n < nlen; n++) {
@@ -620,63 +621,63 @@ public class SelectorEngineJS extends SelectorEngineImpl { if (previousDir) {
while (
- GQUtils.truth(next = SelectorEngine.getPreviousSibling(next))
- && !GQUtils
+ JsUtils.truth(next = SelectorEngine.getPreviousSibling(next))
+ && !JsUtils
.eq(next.getNodeName(), previous.getNodeName())) {
}
} else {
- while (GQUtils.truth(next = SelectorEngine.getNextSibling(next))
- && !GQUtils.eq(next.getNodeName(), previous.getNodeName())) {
+ while (JsUtils.truth(next = SelectorEngine.getNextSibling(next))
+ && !JsUtils.eq(next.getNodeName(), previous.getNodeName())) {
}
}
- if (!GQUtils.truth(next)) {
+ if (!JsUtils.truth(next)) {
matchingElms.addNode(previous);
}
}
}
- private JSArray getNotPseudo(JSArray previousMatch, String pseudoValue,
- JSArray matchingElms) {
- if (new JSRegexp("(:\\w+[\\w\\-]*)$").test(pseudoValue)) {
+ private JsNodeArray getNotPseudo(JsNodeArray previousMatch, String pseudoValue,
+ JsNodeArray matchingElms) {
+ if (new JsRegexp("(:\\w+[\\w\\-]*)$").test(pseudoValue)) {
matchingElms = subtractArray(previousMatch,
getElementsByPseudo(previousMatch, pseudoValue.substring(1), ""));
} else {
pseudoValue = pseudoValue
.replace("^\\[#([\\w\\u00C0-\\uFFFF\\-\\_]+)\\]$", "[id=$1]");
- JSArray notTag = new JSRegexp("^(\\w+)").exec(pseudoValue);
- JSArray notClass = new JSRegexp("^\\.([\\w\u00C0-\uFFFF\\-_]+)")
+ JsObjectArray<String> notTag = new JsRegexp("^(\\w+)").exec(pseudoValue);
+ JsObjectArray<String> notClass = new JsRegexp("^\\.([\\w\u00C0-\uFFFF\\-_]+)")
.exec(pseudoValue);
- JSArray notAttr = new JSRegexp(
+ JsObjectArray<String> notAttr = new JsRegexp(
"\\[(\\w+)(\\^|\\$|\\*|\\||~)?=?([\\w\\u00C0-\\uFFFF\\s\\-_\\.]+)?\\]")
.exec(pseudoValue);
- JSRegexp notRegExp = new JSRegexp("(^|\\s)"
- + (GQUtils.truth(notTag) ? notTag.getStr(1)
- : GQUtils.truth(notClass) ? notClass.getStr(1) : "")
+ JsRegexp notRegExp = new JsRegexp("(^|\\s)"
+ + (JsUtils.truth(notTag) ? notTag.get(1)
+ : JsUtils.truth(notClass) ? notClass.get(1) : "")
+ "(\\s|$)", "i");
- if (GQUtils.truth(notAttr)) {
- String notAttribute = GQUtils.truth(notAttr.getStr(3)) ? notAttr
- .getStr(3).replace("\\.", "\\.") : null;
+ if (JsUtils.truth(notAttr)) {
+ String notAttribute = JsUtils.truth(notAttr.get(3)) ? notAttr
+ .get(3).replace("\\.", "\\.") : null;
String notMatchingAttrVal = attrToRegExp(notAttribute,
- notAttr.getStr(2));
- notRegExp = new JSRegexp(notMatchingAttrVal, "i");
+ notAttr.get(2));
+ notRegExp = new JsRegexp(notMatchingAttrVal, "i");
}
for (int v = 0, vlen = previousMatch.size(); v < vlen; v++) {
Element notElm = previousMatch.getElement(v);
Element addElm = null;
- if (GQUtils.truth(notTag) && !notRegExp
+ if (JsUtils.truth(notTag) && !notRegExp
.test(notElm.getNodeName())) {
addElm = notElm;
- } else if (GQUtils.truth(notClass) && !notRegExp
+ } else if (JsUtils.truth(notClass) && !notRegExp
.test(notElm.getClassName())) {
addElm = notElm;
- } else if (GQUtils.truth(notAttr)) {
- String att = getAttr(notElm, notAttr.getStr(1));
- if (!GQUtils.truth(att) || !notRegExp.test(att)) {
+ } else if (JsUtils.truth(notAttr)) {
+ String att = getAttr(notElm, notAttr.get(1));
+ if (!JsUtils.truth(att) || !notRegExp.test(att)) {
addElm = notElm;
}
}
- if (GQUtils.truth(addElm) && !isAdded(addElm)) {
+ if (JsUtils.truth(addElm) && !isAdded(addElm)) {
setAdded(addElm, true);
matchingElms.addNode(addElm);
}
@@ -685,10 +686,10 @@ public class SelectorEngineJS extends SelectorEngineImpl { return matchingElms;
}
- private JSArray getNthChildPseudo(JSArray previousMatch, String pseudoValue,
- JSArray prevParents, JSArray matchingElms) {
+ private JsNodeArray getNthChildPseudo(JsNodeArray previousMatch, String pseudoValue,
+ JsNodeArray prevParents, JsNodeArray matchingElms) {
Node previous;
- if (GQUtils.eq(pseudoValue, "n")) {
+ if (JsUtils.eq(pseudoValue, "n")) {
matchingElms = previousMatch;
} else {
Sequence sequence = getSequence(pseudoValue);
@@ -704,7 +705,7 @@ public class SelectorEngineJS extends SelectorEngineImpl { || iteratorNext <= sequence.max)) {
if (childElm.getNodeType() == Node.ELEMENT_NODE) {
if (++childCount == iteratorNext) {
- if (GQUtils
+ if (JsUtils
.eq(childElm.getNodeName(), previous.getNodeName())) {
matchingElms.addNode(childElm);
}
@@ -723,8 +724,8 @@ public class SelectorEngineJS extends SelectorEngineImpl { return matchingElms;
}
- private JSArray getNthOfTypePseudo(JSArray previousMatch, String pseudoValue,
- JSArray prevParents, JSArray matchingElms) {
+ private JsNodeArray getNthOfTypePseudo(JsNodeArray previousMatch, String pseudoValue,
+ JsNodeArray prevParents, JsNodeArray matchingElms) {
Node previous;
if (pseudoValue.startsWith("n")) {
matchingElms = previousMatch;
@@ -738,9 +739,9 @@ public class SelectorEngineJS extends SelectorEngineImpl { int iteratorNext = sequence.start;
int childCount = 0;
Node childElm = prevParent.getFirstChild();
- while (GQUtils.truth(childElm) && (sequence.max < 0
+ while (JsUtils.truth(childElm) && (sequence.max < 0
|| iteratorNext <= sequence.max)) {
- if (GQUtils
+ if (JsUtils
.eq(childElm.getNodeName(), previous.getNodeName())) {
if (++childCount == iteratorNext) {
matchingElms.addNode(childElm);
@@ -759,7 +760,7 @@ public class SelectorEngineJS extends SelectorEngineImpl { return matchingElms;
}
- private void getOnlyChildPseudo(JSArray previousMatch, JSArray matchingElms) {
+ private void getOnlyChildPseudo(JsNodeArray previousMatch, JsNodeArray matchingElms) {
Node previous;
Node next;
Node prev;
@@ -769,13 +770,13 @@ public class SelectorEngineJS extends SelectorEngineImpl { Node prevParent = previous.getParentNode();
if (prevParent != kParent) {
while (
- GQUtils.truth(prev = SelectorEngine.getPreviousSibling(prev))
+ JsUtils.truth(prev = SelectorEngine.getPreviousSibling(prev))
&& prev.getNodeType() != Node.ELEMENT_NODE) {
}
- while (GQUtils.truth(next = SelectorEngine.getNextSibling(next))
+ while (JsUtils.truth(next = SelectorEngine.getNextSibling(next))
&& next.getNodeType() != Node.ELEMENT_NODE) {
}
- if (!GQUtils.truth(prev) && !GQUtils.truth(next)) {
+ if (!JsUtils.truth(prev) && !JsUtils.truth(next)) {
matchingElms.addNode(previous);
}
kParent = prevParent;
@@ -783,8 +784,8 @@ public class SelectorEngineJS extends SelectorEngineImpl { }
}
- private void getOnlyOfTypePseudo(JSArray previousMatch,
- JSArray matchingElms) {
+ private void getOnlyOfTypePseudo(JsNodeArray previousMatch,
+ JsNodeArray matchingElms) {
Node previous;
Node next;
Node prev;
@@ -794,14 +795,14 @@ public class SelectorEngineJS extends SelectorEngineImpl { Node prevParent = previous.getParentNode();
if (prevParent != oParent) {
while (
- GQUtils.truth(prev = SelectorEngine.getPreviousSibling(prev))
- && !GQUtils
+ JsUtils.truth(prev = SelectorEngine.getPreviousSibling(prev))
+ && !JsUtils
.eq(prev.getNodeName(), previous.getNodeName())) {
}
- while (GQUtils.truth(next = SelectorEngine.getNextSibling(next))
- && !GQUtils.eq(next.getNodeName(), previous.getNodeName())) {
+ while (JsUtils.truth(next = SelectorEngine.getNextSibling(next))
+ && !JsUtils.eq(next.getNodeName(), previous.getNodeName())) {
}
- if (!GQUtils.truth(prev) && !GQUtils.truth(next)) {
+ if (!JsUtils.truth(prev) && !JsUtils.truth(next)) {
matchingElms.addNode(previous);
}
oParent = prevParent;
diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/research/SelectorEngineSizzleGwt.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/research/SelectorEngineSizzleGwt.java index dd19c1c8..71438705 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/research/SelectorEngineSizzleGwt.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/research/SelectorEngineSizzleGwt.java @@ -21,8 +21,8 @@ import com.google.gwt.core.client.JsArray; 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.GQUtils; import com.google.gwt.query.client.impl.SelectorEngineImpl; +import com.google.gwt.query.client.js.JsUtils; /** * Pure Javascript Selector Engine Gwt Implementation based on @@ -734,6 +734,6 @@ public class SelectorEngineSizzleGwt extends SelectorEngineImpl { public NodeList<Element> select(String selector, Node context) { JsArray<Element> results = JavaScriptObject.createArray().cast(); - return GQUtils.unique(select(selector, context, results, null)).cast(); + return JsUtils.unique(select(selector, context, results, null)).cast(); } } diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/research/SelectorEngineXPath.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/research/SelectorEngineXPath.java index 08d9f1e9..dc1bb2b3 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/research/SelectorEngineXPath.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/research/SelectorEngineXPath.java @@ -15,20 +15,21 @@ */
package com.google.gwt.query.client.impl.research;
-import static com.google.gwt.query.client.GQUtils.eq;
-import static com.google.gwt.query.client.GQUtils.truth;
+import static com.google.gwt.query.client.js.JsUtils.eq;
+import static com.google.gwt.query.client.js.JsUtils.truth;
import com.google.gwt.core.client.JsArray;
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.GQUtils;
-import com.google.gwt.query.client.JSArray;
-import com.google.gwt.query.client.JSRegexp;
import com.google.gwt.query.client.impl.SelectorEngine;
import com.google.gwt.query.client.impl.SelectorEngineImpl;
import com.google.gwt.query.client.impl.research.SelectorEngineJS.Sequence;
import com.google.gwt.query.client.impl.research.SelectorEngineJS.SplitRule;
+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;
/**
@@ -59,11 +60,11 @@ public class SelectorEngineXPath extends SelectorEngineImpl { return "@" + p1 + (truth(p3) ? "='" + p3 + "'" : "");
}
- private JSRegexp cssSelectorRegExp;
+ private JsRegexp cssSelectorRegExp;
- private JSRegexp selectorSplitRegExp;
+ private JsRegexp selectorSplitRegExp;
- private JSRegexp combinator;
+ private JsRegexp combinator;
public SelectorEngineXPath() {
}
@@ -72,7 +73,7 @@ public class SelectorEngineXPath extends SelectorEngineImpl { init();
String selectors[] = sel.replaceAll("\\s*(,)\\s*", "$1").split(",");
boolean identical = false;
- JSArray elm = JSArray.create();
+ JsNodeArray elm = JsNodeArray.create();
for (int a = 0, len = selectors.length; a < len; a++) {
if (a > 0) {
identical = false;
@@ -87,17 +88,17 @@ public class SelectorEngineXPath extends SelectorEngineImpl { }
}
String currentRule = selectors[a];
- JSArray cssSelectors = selectorSplitRegExp.match(currentRule);
+ JsObjectArray<String> cssSelectors = selectorSplitRegExp.match(currentRule);
String xPathExpression = ".";
- for (int i = 0, slen = cssSelectors.size(); i < slen; i++) {
- String rule = cssSelectors.getStr(i);
- JSArray cssSelector = cssSelectorRegExp.exec(rule);
+ for (int i = 0, slen = cssSelectors.length(); i < slen; i++) {
+ String rule = cssSelectors.get(i);
+ JsObjectArray<String> cssSelector = cssSelectorRegExp.exec(rule);
SplitRule splitRule = new SplitRule(
- !truth(cssSelector.getStr(1)) || eq(cssSelector.getStr(3), "*")
- ? "*" : cssSelector.getStr(1),
- !eq(cssSelector.getStr(3), "*") ? cssSelector.getStr(2) : null,
- cssSelector.getStr(4), cssSelector.getStr(6),
- cssSelector.getStr(10), cssSelector.getStr(22));
+ !truth(cssSelector.get(1)) || eq(cssSelector.get(3), "*")
+ ? "*" : cssSelector.get(1),
+ !eq(cssSelector.get(3), "*") ? cssSelector.get(2) : null,
+ cssSelector.get(4), cssSelector.get(6),
+ cssSelector.get(10), cssSelector.get(22));
if (truth(splitRule.tagRelation)) {
if (eq(">", splitRule.tagRelation)) {
xPathExpression += "/child::";
@@ -108,7 +109,7 @@ public class SelectorEngineXPath extends SelectorEngineImpl { }
} else {
xPathExpression +=
- (i > 0 && combinator.test(cssSelectors.getStr(i - 1)))
+ (i > 0 && combinator.test(cssSelectors.get(i - 1)))
? splitRule.tag : ("/descendant::" + splitRule.tag);
}
if (truth(splitRule.id)) {
@@ -122,19 +123,19 @@ public class SelectorEngineXPath extends SelectorEngineImpl { }
if (truth(splitRule.allAttr)) {
xPathExpression += replaceAttr(
- GQUtils.or(splitRule.allAttr, ""));
+ JsUtils.or(splitRule.allAttr, ""));
}
if (truth(splitRule.allPseudos)) {
- JSRegexp pseudoSplitRegExp = new JSRegexp(
+ JsRegexp pseudoSplitRegExp = new JsRegexp(
":(\\w[\\w\\-]*)(\\(([^\\)]+)\\))?");
- JSRegexp pseudoMatchRegExp = new JSRegexp(
+ JsRegexp pseudoMatchRegExp = new JsRegexp(
"(:\\w+[\\w\\-]*)(\\([^\\)]+\\))?", "g");
- JSArray allPseudos = pseudoMatchRegExp.match(splitRule.allPseudos);
- for (int k = 0, kl = allPseudos.size(); k < kl; k++) {
- JSArray pseudo = pseudoSplitRegExp.match(allPseudos.getStr(k));
- String pseudoClass = truth(pseudo.getStr(1)) ? pseudo.getStr(1)
+ JsObjectArray<String> allPseudos = pseudoMatchRegExp.match(splitRule.allPseudos);
+ for (int k = 0, kl = allPseudos.length(); k < kl; k++) {
+ JsObjectArray<String> pseudo = pseudoSplitRegExp.match(allPseudos.get(k));
+ String pseudoClass = truth(pseudo.get(1)) ? pseudo.get(1)
.toLowerCase() : null;
- String pseudoValue = truth(pseudo.getStr(3)) ? pseudo.getStr(3)
+ String pseudoValue = truth(pseudo.get(3)) ? pseudo.get(3)
: null;
String xpath = pseudoToXPath(splitRule.tag, pseudoClass,
pseudoValue);
@@ -146,15 +147,15 @@ public class SelectorEngineXPath extends SelectorEngineImpl { }
SelectorEngine.xpathEvaluate(xPathExpression, ctx, elm);
}
- return GQUtils.unique(elm.<JsArray<Element>>cast()).cast();
+ return JsUtils.unique(elm.<JsArray<Element>>cast()).cast();
}
private void init() {
if (cssSelectorRegExp == null) {
- cssSelectorRegExp = new JSRegexp(
+ cssSelectorRegExp = new JsRegexp(
"^(\\w+)?(#[\\w\\u00C0-\\uFFFF\\-\\_]+|(\\*))?((\\.[\\w\\u00C0-\\uFFFF\\-_]+)*)?((\\[\\w+(\\^|\\$|\\*|\\||~)?(=[\"']*[\\w\\u00C0-\\uFFFF\\s\\-\\_\\.]+[\"']*)?\\]+)*)?(((:\\w+[\\w\\-]*)(\\((odd|even|\\-?\\d*n?((\\+|\\-)\\d+)?|[\\w\\u00C0-\\uFFFF\\-_]+|((\\w*\\.[\\w\\u00C0-\\uFFFF\\-_]+)*)?|(\\[#?\\w+(\\^|\\$|\\*|\\||~)?=?[\\w\\u00C0-\\uFFFF\\s\\-\\_\\.]+\\]+)|(:\\w+[\\w\\-]*))\\))?)*)?(>|\\+|~)?");
- selectorSplitRegExp = new JSRegexp("[^\\s]+", "g");
- combinator = new JSRegexp("(>|\\+|~)");
+ selectorSplitRegExp = new JsRegexp("[^\\s]+", "g");
+ combinator = new JsRegexp("(>|\\+|~)");
}
}
@@ -215,7 +216,7 @@ public class SelectorEngineXPath extends SelectorEngineImpl { } else if (eq("checked", pseudoClass)) {
xpath = "@checked='checked'"; // Doesn't work in Opera 9.24
} else if (eq("not", pseudoClass)) {
- if (new JSRegexp("^(:\\w+[\\w\\-]*)$").test(pseudoValue)) {
+ if (new JsRegexp("^(:\\w+[\\w\\-]*)$").test(pseudoValue)) {
xpath = "not(" + pseudoToXPath(tag, pseudoValue.substring(1), "") + ")";
} else {
diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/js/JsCache.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/js/JsCache.java new file mode 100644 index 00000000..1848f349 --- /dev/null +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/js/JsCache.java @@ -0,0 +1,90 @@ +package com.google.gwt.query.client.js; + +import com.google.gwt.core.client.JavaScriptObject; + + /** + * A Lightweight JSO class to store data. + */ +public class JsCache extends JavaScriptObject { + + protected JsCache() { + } + + public final native void concat(Object ary) /*-{ + if (ary) this.concat(ary); + }-*/; + + public final void pushAll(JavaScriptObject prevElem) { + JsCache c = prevElem.cast(); + for (int i = 0, ilen = c.length(); i < ilen; i++) { + put(length(), c.get(i)); + } + } + + public final native void delete(int name) /*-{ + delete this[name]; + }-*/; + + public final native void delete(String name) /*-{ + delete this[name]; + }-*/; + + public final native boolean exists(int id) /*-{ + return !!this[id]; + }-*/; + + public final native Object get(int id) /*-{ + return this[id] || null; + }-*/; + + public final native Object get(String id) /*-{ + return this[id] || null; + }-*/; + + public final JsCache getCache(int id) { + return (JsCache)get(id); + } + + public final native double getDouble(int id) /*-{ + return this[id] || 0; + }-*/; + + public final native double getDouble(String id) /*-{ + return this[id] || 0; + }-*/; + + public final native int getInt(int id) /*-{ + return this[id] || 0; + }-*/; + + public final native int getInt(String id) /*-{ + return this[id] || 0; + }-*/; + + public final native String getString(int id) /*-{ + return this[id]; + }-*/; + + public final native String getString(String id) /*-{ + return this[id] || null; + }-*/; + + public final native boolean isEmpty() /*-{ + var foo = ""; + for (foo in this) + break; + return !foo; + }-*/; + + public final native void put(int id, Object obj) /*-{ + if (obj && id >=0 ) this[id] = obj; + }-*/; + + public final native void put(String id, Object obj) /*-{ + if (obj && id) this[id] = obj; + }-*/; + + public final native int length() /*-{ + return this.length; + }-*/; +} diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/JsClosure.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/js/JsClosure.java index 30fd2f24..c477c6d5 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/JsClosure.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/js/JsClosure.java @@ -13,7 +13,7 @@ * License for the specific language governing permissions and limitations under * the License. */ -package com.google.gwt.query.client; +package com.google.gwt.query.client.js; import com.google.gwt.core.client.JavaScriptObject; @@ -31,4 +31,4 @@ public class JsClosure extends JavaScriptObject { public final native void invoke() /*-{ return this(); }-*/; -} +}
\ No newline at end of file diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/JsMap.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/js/JsMap.java index f57dd9f8..760326c0 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/JsMap.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/js/JsMap.java @@ -13,31 +13,38 @@ * License for the specific language governing permissions and limitations under * the License. */ -package com.google.gwt.query.client; +package com.google.gwt.query.client.js; import com.google.gwt.core.client.JavaScriptObject; + /** * Lightweight JSO backed implemented of a Map, using Object.hashCode() as key. */ final public class JsMap<S, T> extends JavaScriptObject { - + protected JsMap() { } + + private JsCache c() { + return cast(); + } + + @SuppressWarnings("unchecked") + public T get(int hashCode) { + return (T)c().get(hashCode); + } public T get(S key) { return get(key.hashCode()); } - public native T get(int hashCode) /*-{ - return this[hashCode] || null; - }-*/; - + public int length() { + return c().length(); + } + public void put(S key, T val) { - put(key.hashCode(), val); + c().put(key.hashCode(), val); } - public native void put(int hashCode, T val) /*-{ - this[hashCode]=val; - }-*/; } diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/js/JsNodeArray.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/js/JsNodeArray.java new file mode 100644 index 00000000..1b06bf14 --- /dev/null +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/js/JsNodeArray.java @@ -0,0 +1,76 @@ +/*
+ * 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.js;
+
+import com.google.gwt.core.client.JavaScriptObject;
+import com.google.gwt.dom.client.Element;
+import com.google.gwt.dom.client.Node;
+import com.google.gwt.dom.client.NodeList;
+
+/**
+ * A Lightweight JSO class easily handle a node list.
+ */
+public class JsNodeArray extends NodeList<Element> {
+
+ public static JsNodeArray create() {
+ return create((Node)null);
+ }
+
+ public static native JsNodeArray create(Node node) /*-{
+ return node ? [node] : [];
+ }-*/;
+
+ public static JsNodeArray create(NodeList<?> nl) {
+ JsNodeArray ret = create((Node)null);
+ ret.pushAll(nl);
+ return ret;
+ }
+
+ protected JsNodeArray(){
+ }
+
+ public final void addNode(Node n){
+ c().add(n);
+ }
+
+ public final void addNode(Node n, int i) {
+ c().add(i, n);
+ }
+
+ public final void concat(JsNodeArray ary) {
+ c().concat(ary.c());
+ }
+
+ public final Element getElement(int i) {
+ return c().get(i).cast();
+ }
+
+ public final Node getNode(int i) {
+ return c().get(i);
+ }
+
+ public final int size() {
+ return c().length();
+ }
+
+ private JsObjectArray<Node> c() {
+ return cast();
+ }
+
+ public final void pushAll(JavaScriptObject prevElem) {
+ c().pushAll(prevElem);
+ }
+}
diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/JsObjectArray.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/js/JsObjectArray.java index b82c6e94..839292d3 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/JsObjectArray.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/js/JsObjectArray.java @@ -13,32 +13,52 @@ * License for the specific language governing permissions and limitations under * the License. */ -package com.google.gwt.query.client; +package com.google.gwt.query.client.js; import com.google.gwt.core.client.JavaScriptObject; /** - * Lightweight JSO based array class that can store objects rather than just - * other JSOs. + * Lightweight JSO based array class that can store objects. */ public final class JsObjectArray<T> extends JavaScriptObject { - + + public static JsObjectArray<?> create() { + return JavaScriptObject.createArray().cast(); + } + protected JsObjectArray() { } + + private JsCache c() { + return cast(); + } public void add(T val) { - set(length(), val); + c().put(length(), val); } - public native T get(int i) /*-{ - return this[i]; - }-*/; + public void add(int i, T val) { + c().put(i, val); + } - public native int length() /*-{ - return this.length; - }-*/; + @SuppressWarnings("unchecked") + public T get(int hashCode) { + return (T)c().get(hashCode); + } - public native void set(int i, T val) /*-{ - this[i]=val; - }-*/; + public int length() { + return c().length(); + } + + public void set(int i, T val) { + c().put(i, val); + } + + public void concat(JsObjectArray<T> ary) { + c().concat(ary); + } + + public void pushAll(JavaScriptObject prevElem) { + c().pushAll(prevElem); + } } diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/JSRegexp.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/js/JsRegexp.java index 0e2b1f62..71dbd9c3 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/JSRegexp.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/js/JsRegexp.java @@ -13,14 +13,14 @@ * License for the specific language governing permissions and limitations under
* the License.
*/
-package com.google.gwt.query.client;
+package com.google.gwt.query.client.js;
import com.google.gwt.core.client.JavaScriptObject;
/**
* A wrapper around Javascript Regexps.
*/
-public class JSRegexp {
+public class JsRegexp {
public static native JavaScriptObject compile(String pat) /*-{
return new RegExp(pat);
@@ -30,29 +30,29 @@ public class JSRegexp { return new RegExp(pat, flags);
}-*/;
- public static JSArray match(String regexp, String flags, String string) {
- return new JSRegexp(regexp, flags).match(string);
+ public static JsObjectArray<String> match(String regexp, String flags, String string) {
+ return new JsRegexp(regexp, flags).match(string);
}
- private static native JSArray exec0(JavaScriptObject regexp, String str) /*-{
+ private static native JsObjectArray<String> exec0(JavaScriptObject regexp, String str) /*-{
return regexp.exec(str);
}-*/;
private final JavaScriptObject regexp;
- public JSRegexp(String pattern) {
+ public JsRegexp(String pattern) {
this.regexp = compile(pattern);
}
- public JSRegexp(String pat, String flags) {
+ public JsRegexp(String pat, String flags) {
this.regexp = compileFlags(pat, flags);
}
- public JSArray exec(String str) {
+ public JsObjectArray<String> exec(String str) {
return exec0(regexp, str);
}
- public JSArray match(String currentRule) {
+ public JsObjectArray<String> match(String currentRule) {
return match0(regexp, currentRule);
}
@@ -60,11 +60,15 @@ public class JSRegexp { return test0(regexp, rule);
}
- private native JSArray match0(JavaScriptObject regexp, String currentRule)/*-{
+ private native JsObjectArray<String> match0(JavaScriptObject regexp, String currentRule)/*-{
return currentRule.match(regexp);
}-*/;
private native boolean test0(JavaScriptObject regexp, String rule) /*-{
return regexp.test(rule);
}-*/;
+
+ public String getPattern(){
+ return regexp.toString();
+ };
}
diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/GQUtils.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/js/JsUtils.java index 77c5ffb1..103ae863 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/GQUtils.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/js/JsUtils.java @@ -13,13 +13,14 @@ * License for the specific language governing permissions and limitations under * the License. */ -package com.google.gwt.query.client; +package com.google.gwt.query.client.js; import java.util.HashSet; import com.google.gwt.core.client.JavaScriptObject; import com.google.gwt.core.client.JsArray; import com.google.gwt.dom.client.Element; +import com.google.gwt.query.client.GQuery; import com.google.gwt.user.client.DOM; /** @@ -28,7 +29,7 @@ import com.google.gwt.user.client.DOM; * These methods could be moved to $ class, but the class * doesn't work right now. */ -public class GQUtils { +public class JsUtils { /** * Use the method in the gquery class $(elem).cur(prop, force); diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/effects/PropertiesAnimation.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/effects/PropertiesAnimation.java index 7325bbf4..b69cfb83 100755 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/effects/PropertiesAnimation.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/effects/PropertiesAnimation.java @@ -21,9 +21,9 @@ import com.google.gwt.animation.client.Animation; import com.google.gwt.dom.client.Element;
import com.google.gwt.query.client.Function;
import com.google.gwt.query.client.GQuery;
-import com.google.gwt.query.client.JSArray;
import com.google.gwt.query.client.Properties;
-import com.google.gwt.query.client.JSRegexp;
+import com.google.gwt.query.client.js.JsObjectArray;
+import com.google.gwt.query.client.js.JsRegexp;
import com.google.gwt.query.client.plugins.Effects;
/**
@@ -71,7 +71,7 @@ public class PropertiesAnimation extends Animation { private static final String[] attrsToSave = new String[] { "overflow",
"visibility" };
- private static JSRegexp nonPxRegExp = new JSRegexp(
+ private static JsRegexp nonPxRegExp = new JsRegexp(
"z-?index|font-?weight|opacity|zoom|line-?height", "i");
@@ -104,20 +104,22 @@ public class PropertiesAnimation extends Animation { end = 0;
unit = nonPxRegExp.test(key) ? "" : "px";
} else {
- JSArray parts = new JSRegexp("^([+-]=)?([0-9+-.]+)(.*)?$").match(val);
+ JsObjectArray<String> parts = new JsRegexp("^([+-]=)?([0-9+-.]+)(.*)?$").match(val);
if (parts != null) {
- unit = nonPxRegExp.test(key) ? "" : parts.getStr(3) == null ? "px"
- : parts.getStr(3);
- end = Double.parseDouble(parts.getStr(2));
+ String $1 = parts.get(1);
+ String $2 = parts.get(2);
+ String $3 = parts.get(3);
+ end = Double.parseDouble($2);
+ unit = nonPxRegExp.test(key) ? "" : $3 == null || $3.isEmpty() ? "px" : $3;
if (!"px".equals(unit)) {
double to = end == 0 ? 1 : end;
g.css(key, to + unit);
start = to * start / g.cur(key, true);
g.css(key, start + unit);
}
- if (parts.getStr(1) != null) {
- end = (("-=".equals(parts.getStr(1)) ? -1 : 1) * end) + start;
+ if ($1 != null && !$1.isEmpty()) {
+ end = (("-=".equals($1) ? -1 : 1) * end) + start;
}
}
}
diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/events/EventsListener.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/events/EventsListener.java index a40b5b23..cf4f2e5d 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/events/EventsListener.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/events/EventsListener.java @@ -18,7 +18,7 @@ package com.google.gwt.query.client.plugins.events; import com.google.gwt.core.client.Duration; import com.google.gwt.dom.client.Element; import com.google.gwt.query.client.Function; -import com.google.gwt.query.client.JsObjectArray; +import com.google.gwt.query.client.js.JsObjectArray; import com.google.gwt.user.client.DOM; import com.google.gwt.user.client.Event; import com.google.gwt.user.client.EventListener; diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/rebind/LazyGenerator.java b/gwtquery-core/src/main/java/com/google/gwt/query/rebind/LazyGenerator.java index a293a026..c9c3ab52 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/rebind/LazyGenerator.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/rebind/LazyGenerator.java @@ -179,7 +179,7 @@ public class LazyGenerator extends Generator { composerFactory.addImport("com.google.gwt.dom.client.Element"); composerFactory.addImport("com.google.gwt.user.client.Event"); composerFactory.addImport("com.google.gwt.query.client.Function"); - composerFactory.addImport("com.google.gwt.query.client.JsClosure"); + composerFactory.addImport("com.google.gwt.query.client.js.JsClosure"); for (String interfaceName : interfaceNames) { composerFactory.addImplementedInterface(interfaceName); diff --git a/gwtquery-core/src/test/java/com/google/gwt/query/client/GQueryCoreTest.java b/gwtquery-core/src/test/java/com/google/gwt/query/client/GQueryCoreTest.java index af0c70c2..a9899f7c 100644 --- a/gwtquery-core/src/test/java/com/google/gwt/query/client/GQueryCoreTest.java +++ b/gwtquery-core/src/test/java/com/google/gwt/query/client/GQueryCoreTest.java @@ -18,6 +18,7 @@ package com.google.gwt.query.client; import static com.google.gwt.query.client.GQuery.$; import static com.google.gwt.query.client.GQuery.$$; import static com.google.gwt.query.client.GQuery.document; +import static com.google.gwt.query.client.plugins.Widgets.Widgets; import java.util.List; @@ -31,7 +32,8 @@ import com.google.gwt.event.dom.client.ClickHandler; import com.google.gwt.junit.client.GWTTestCase; import com.google.gwt.query.client.impl.SelectorEngineImpl; import com.google.gwt.query.client.impl.SelectorEngineSizzle; -import com.google.gwt.query.client.plugins.Widgets; +import com.google.gwt.query.client.js.JsNodeArray; +import com.google.gwt.query.client.js.JsUtils; import com.google.gwt.user.client.Event; import com.google.gwt.user.client.ui.Button; import com.google.gwt.user.client.ui.HTML; @@ -688,7 +690,7 @@ public class GQueryCoreTest extends GWTTestCase { public void testUnique() { SelectorEngineImpl selSizz = new SelectorEngineSizzle(); GQuery g = $(e).html("<div><p></p><p></p><span></span><p></p>"); - JSArray a; + JsNodeArray a; a = selSizz.select("p", e).cast(); assertEquals(3, a.getLength()); a.addNode(a.getNode(0)); @@ -699,41 +701,41 @@ public class GQueryCoreTest extends GWTTestCase { } public void testUtilsEq() { - assertTrue(GQUtils.eq("a", "a")); - assertTrue(GQUtils.eq(true, true)); - assertTrue(GQUtils.eq(45, 45)); - assertTrue(GQUtils.eq(45d, 45f)); - assertTrue(GQUtils.eq("", "")); - assertTrue(GQUtils.eq(0.45, 0.45)); - assertTrue(GQUtils.eq(0.45d, 0.45d)); - assertTrue(GQUtils.eq(0.45f, 0.45f)); - - assertFalse(GQUtils.eq("a", "")); - assertFalse(GQUtils.eq(true, false)); - assertFalse(GQUtils.eq(45, 42)); - assertFalse(GQUtils.eq("", null)); - assertFalse(GQUtils.eq(0.45, 0.451)); + assertTrue(JsUtils.eq("a", "a")); + assertTrue(JsUtils.eq(true, true)); + assertTrue(JsUtils.eq(45, 45)); + assertTrue(JsUtils.eq(45d, 45f)); + assertTrue(JsUtils.eq("", "")); + assertTrue(JsUtils.eq(0.45, 0.45)); + assertTrue(JsUtils.eq(0.45d, 0.45d)); + assertTrue(JsUtils.eq(0.45f, 0.45f)); + + assertFalse(JsUtils.eq("a", "")); + assertFalse(JsUtils.eq(true, false)); + assertFalse(JsUtils.eq(45, 42)); + assertFalse(JsUtils.eq("", null)); + assertFalse(JsUtils.eq(0.45, 0.451)); // assertEquals("a", GQUtils.or("a", "")); } public void testUtilsTruth() { - assertTrue(GQUtils.truth("a")); - assertTrue(GQUtils.truth(this)); - assertTrue(GQUtils.truth(45)); - assertTrue(GQUtils.truth(0.33)); - assertTrue(GQUtils.truth(45l)); - assertTrue(GQUtils.truth(45d)); - assertTrue(GQUtils.truth(45f)); - assertTrue(GQUtils.truth(0.33f)); - - assertFalse(GQUtils.truth(0)); - assertFalse(GQUtils.truth(0l)); - assertFalse(GQUtils.truth(0d)); - assertFalse(GQUtils.truth(00.00d)); - assertFalse(GQUtils.truth(00.00f)); - assertFalse(GQUtils.truth(null)); - assertFalse(GQUtils.truth("")); + assertTrue(JsUtils.truth("a")); + assertTrue(JsUtils.truth(this)); + assertTrue(JsUtils.truth(45)); + assertTrue(JsUtils.truth(0.33)); + assertTrue(JsUtils.truth(45l)); + assertTrue(JsUtils.truth(45d)); + assertTrue(JsUtils.truth(45f)); + assertTrue(JsUtils.truth(0.33f)); + + assertFalse(JsUtils.truth(0)); + assertFalse(JsUtils.truth(0l)); + assertFalse(JsUtils.truth(0d)); + assertFalse(JsUtils.truth(00.00d)); + assertFalse(JsUtils.truth(00.00f)); + assertFalse(JsUtils.truth(null)); + assertFalse(JsUtils.truth("")); } public void testWidthHeight() { @@ -792,10 +794,10 @@ public class GQueryCoreTest extends GWTTestCase { RootPanel.get().add(b1); GQuery g = $(b1); - Button b2 = (Button) g.widget(); + Button b2 = g.widget(); assertEquals(b1, b2); - b2 = $("<button>Click-me</button>").appendTo(document).as(Widgets.Widgets).button(); + b2 = $("<button>Click-me</button>").appendTo(document).as(Widgets).button(); b2.addClickHandler(new ClickHandler() { public void onClick(ClickEvent event) { $(b1).css("color", "red"); diff --git a/gwtquery-core/src/test/java/com/google/gwt/query/client/GQuerySelectorsTest.java b/gwtquery-core/src/test/java/com/google/gwt/query/client/GQuerySelectorsTest.java index aa2ca229..306869d7 100644 --- a/gwtquery-core/src/test/java/com/google/gwt/query/client/GQuerySelectorsTest.java +++ b/gwtquery-core/src/test/java/com/google/gwt/query/client/GQuerySelectorsTest.java @@ -32,6 +32,7 @@ import com.google.gwt.query.client.impl.SelectorEngineSizzle; import com.google.gwt.query.client.impl.research.SelectorEngineJS; import com.google.gwt.query.client.impl.research.SelectorEngineSizzleGwt; import com.google.gwt.query.client.impl.research.SelectorEngineXPath; +import com.google.gwt.query.client.js.JsUtils; import com.google.gwt.user.client.ui.HTML; import com.google.gwt.user.client.ui.RootPanel; @@ -348,7 +349,7 @@ public class GQuerySelectorsTest extends GWTTestCase { a.push(a.get(i)); } assertEquals(n * 2 , a.length()); - a = GQUtils.unique(a); + a = JsUtils.unique(a); assertEquals(n, a.length()); } |