diff options
6 files changed, 78 insertions, 27 deletions
diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/Console.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/Console.java index 52c71d35..dcd0300d 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/Console.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/Console.java @@ -38,6 +38,11 @@ public interface Console { void error(Object arg); /** + * Outputs an error message. You may use string substitution and additional arguments with this method. + */ + void error(Object... args); + + /** * Creates a new inline group, indenting all following output by another level. To move back out a * level, call groupEnd(). */ @@ -62,12 +67,24 @@ public interface Console { void info(Object arg); /** + * Informative logging information. You may use string substitution and additional arguments with + * this method. + */ + void info(Object... args); + + /** * For general output of logging information. You may use string substitution and additional * arguments with this method. */ void log(Object arg); /** + * For general output of logging information. You may use string substitution and additional + * arguments with this method. + */ + void log(Object... args); + + /** * Starts a JavaScript CPU profile with a name. To complete the profile, call console.profileEnd(). */ void profile(String title); @@ -84,7 +101,7 @@ public interface Console { void time(String title); /** - * Stops the specified timer and logs the elapsed time in seconds since its start. + * Stops the specified timer and logs the elapsed time in seconds since its start. */ void timeEnd(String title); @@ -98,4 +115,10 @@ public interface Console { * method. */ void warn(Object arg); + + /** + * Outputs a warning message. You may use string substitution and additional arguments with this + * method. + */ + void warn(Object... args); } diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/ConsoleBrowser.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/ConsoleBrowser.java index dd67bd1a..0c3b1090 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/ConsoleBrowser.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/ConsoleBrowser.java @@ -18,6 +18,7 @@ package com.google.gwt.query.client.impl; import com.google.gwt.core.client.JavaScriptObject; import com.google.gwt.query.client.Console; import com.google.gwt.query.client.GQuery; +import com.google.gwt.query.client.js.JsObjectArray; /** * Implementation of the Console interface based on the @@ -70,11 +71,11 @@ public class ConsoleBrowser implements Console { if (initialized) super.dir(arg); } @Override - public void error(Object arg) { + public void error(JavaScriptObject arg) { if (initialized) super.error(arg); } @Override - public void info(Object arg) { + public void info(JavaScriptObject arg) { if (initialized) super.info(arg); } @Override @@ -86,7 +87,7 @@ public class ConsoleBrowser implements Console { if (initialized) super.profileEnd(title); } @Override - public void warn(Object arg) { + public void warn(JavaScriptObject arg) { if (initialized) super.warn(arg); } @Override @@ -115,8 +116,8 @@ public class ConsoleBrowser implements Console { $wnd.console.dir(arg); }-*/; - public native void error(Object arg) /*-{ - $wnd.console.error(arg); + public native void error(JavaScriptObject arg) /*-{ + $wnd.console.error.apply($wnd.console, arg); }-*/; public native void group(Object arg) /*-{ @@ -131,12 +132,12 @@ public class ConsoleBrowser implements Console { $wnd.console.groupEnd(); }-*/; - public native void info(Object arg) /*-{ - $wnd.console.info(arg); + public native void info(JavaScriptObject arg) /*-{ + $wnd.console.info.apply($wnd.console, arg); }-*/; - public native void log(Object arg) /*-{ - $wnd.console.log(arg); + public native void log(JavaScriptObject arg) /*-{ + $wnd.console.log.apply($wnd.console, arg); }-*/; public native void profile(String title) /*-{ @@ -159,8 +160,8 @@ public class ConsoleBrowser implements Console { $wnd.console.timeStamp(arg); }-*/; - public native void warn(Object arg) /*-{ - $wnd.console.warn(arg); + public native void warn(JavaScriptObject arg) /*-{ + $wnd.console.warn.apply($wnd.console, arg); }-*/; } @@ -186,6 +187,11 @@ public class ConsoleBrowser implements Console { } @Override + public void error(Object... args) { + impl.error(toJs(args)); + } + + @Override public void group(Object arg) { impl.group(toJs(arg)); } @@ -206,11 +212,21 @@ public class ConsoleBrowser implements Console { } @Override + public void info(Object... args) { + impl.info(toJs(args)); + } + + @Override public void log(Object arg) { impl.log(toJs(arg)); } @Override + public void log(Object... args) { + impl.log(toJs(args)); + } + + @Override public void profile(String title) { impl.profile(title); } @@ -240,14 +256,16 @@ public class ConsoleBrowser implements Console { impl.warn(toJs(arg)); } - /** - * Don't pass GWT Objects to JS methods - */ - private Object toJs(Object arg) { - if (arg instanceof JavaScriptObject || arg instanceof String) { - return arg; - } else { - return String.valueOf(arg); + @Override + public void warn(Object... arg) { + impl.warn(toJs(arg)); + } + + private JsObjectArray<?> toJs(Object... arg) { + JsObjectArray<Object> ret = JsObjectArray.createArray().cast(); + for (Object o : arg) { + ret.add(o); } + return ret; } } 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 a78c1b5d..cbee96f1 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 @@ -15,6 +15,8 @@ */ package com.google.gwt.query.client.impl; +import static com.google.gwt.query.client.GQuery.console; + import java.util.ArrayList; import com.google.gwt.core.client.GWT; @@ -265,9 +267,8 @@ public class SelectorEngineCssToXPath extends SelectorEngineImpl { if (!SelectorEngine.hasXpathEvaluate()) { throw new RuntimeException("This Browser does not support Xpath selectors.", e); } - System.err.println("ERROR: xpathEvaluate invalid xpath expression:" - + xsel + " css-selector:" + sel + "\n"); - e.printStackTrace(); + console.error("ERROR: xpathEvaluate invalid xpath expression:" + + xsel + " css-selector:" + sel + " " + e.getMessage() + "\n"); } return elm; } diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/SelectorEngineNative.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/SelectorEngineNative.java index 0c5880ba..c8058878 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/SelectorEngineNative.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/SelectorEngineNative.java @@ -15,6 +15,8 @@ */ package com.google.gwt.query.client.impl; +import static com.google.gwt.query.client.GQuery.console; + import com.google.gwt.core.client.GWT; import com.google.gwt.dom.client.Element; import com.google.gwt.dom.client.Node; @@ -64,7 +66,7 @@ public class SelectorEngineNative extends SelectorEngineImpl { try { return SelectorEngine.querySelectorAllImpl(selector, ctx); } catch (Exception e) { - System.err.println("ERROR SelectorEngineNative " + e.getMessage() + console.info("ERROR SelectorEngineNative " + e.getMessage() + " " + selector + ", falling back to " + impl.getClass().getName().replaceAll(".*\\.", "")); return impl.select(selector, ctx); diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/SelectorEngineNativeMin.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/SelectorEngineNativeMin.java index b5986e34..68d9764f 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/SelectorEngineNativeMin.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/SelectorEngineNativeMin.java @@ -15,7 +15,8 @@ */ package com.google.gwt.query.client.impl; -import com.google.gwt.core.client.GWT; +import static com.google.gwt.query.client.GQuery.console; + import com.google.gwt.dom.client.Element; import com.google.gwt.dom.client.Node; import com.google.gwt.dom.client.NodeList; @@ -33,7 +34,9 @@ public class SelectorEngineNativeMin extends SelectorEngineImpl { try { return SelectorEngine.querySelectorAllImpl(selector, ctx); } catch (Exception e) { - GWT.log("GwtQuery: Selector '" + selector + "' is unsupported in this Native engine, do not use this syntax or configure your module to use JS fallback"); + console.error("GwtQuery: Selector '" + selector + + "' is unsupported in this SelectorEngineNativeMin engine." + + " Do not use this syntax or configure your module to use a JS fallback. " + e.getMessage()); return null; } } diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/SelectorEngineNativeMinIE8.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/SelectorEngineNativeMinIE8.java index ce599c71..604ce517 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/SelectorEngineNativeMinIE8.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/SelectorEngineNativeMinIE8.java @@ -15,6 +15,8 @@ */ package com.google.gwt.query.client.impl; +import static com.google.gwt.query.client.GQuery.console; + import com.google.gwt.core.client.GWT; import com.google.gwt.dom.client.Element; import com.google.gwt.dom.client.Node; @@ -33,7 +35,9 @@ public class SelectorEngineNativeMinIE8 extends SelectorEngineImpl { try { return SelectorEngine.querySelectorAllImpl(selector, ctx); } catch (Exception e) { - GWT.log("GwtQuery: Selector '" + selector + "' is unsupported in this IE8 engine, check that you are in 'standards mode' or configure your module to use JS fallback"); + console.error("GwtQuery: Selector '" + selector + "' is unsupported in this SelectorEngineNativeMinIE8 engine," + + " check that you are in 'standards mode' or configure your module to use JS fallback. " + + e.getMessage()); return null; } } |