From 85400d4025e455ce13f7c69ec34bd26c0c548235 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Manuel=20Carrasco=20Mo=C3=B1ino?= Date: Mon, 4 Nov 2013 13:07:11 +0100 Subject: [PATCH] Define Browser implementation in GQueryMin. Fix NPE when visiting BrowserGenerator multiple times with the same ua --- .../com/google/gwt/query/QueryMin.gwt.xml | 5 ++ .../gwt/query/rebind/BrowserGenerator.java | 48 ++++++++++--------- 2 files changed, 30 insertions(+), 23 deletions(-) diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/QueryMin.gwt.xml b/gwtquery-core/src/main/java/com/google/gwt/query/QueryMin.gwt.xml index 4a9b0fd0..385adde8 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/QueryMin.gwt.xml +++ b/gwtquery-core/src/main/java/com/google/gwt/query/QueryMin.gwt.xml @@ -41,6 +41,11 @@ + + + + + diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/rebind/BrowserGenerator.java b/gwtquery-core/src/main/java/com/google/gwt/query/rebind/BrowserGenerator.java index a1953677..6c627cf5 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/rebind/BrowserGenerator.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/rebind/BrowserGenerator.java @@ -50,30 +50,32 @@ public class BrowserGenerator extends Generator { String cName = clz.getName() + "_" + ua; PrintWriter pWriter = context.tryCreate(logger, pName, cName); - - ClassSourceFileComposerFactory cFact = new ClassSourceFileComposerFactory(pName, cName); - cFact.setSuperclass(pName + "." + clz.getName()); - - SourceWriter writer = cFact.createSourceWriter(context, pWriter); - writer.println("protected boolean isWebkit() {return " + "safari".equals(ua) + ";}"); - writer.println("protected boolean isSafari() {return " + "safari".equals(ua) + ";}"); - writer.println("protected boolean isOpera() {return " + "opera".equals(ua) + ";}"); - writer.println("protected boolean isMozilla() {return " + ua.contains("gecko") + ";}"); - writer.println("protected boolean isMsie() {return " + ua.contains("ie") + ";}"); - writer.println("protected boolean isIe6() {return " + "ie6".equals(ua) + ";}"); - writer.println("protected boolean isIe8() {return " + "ie8".equals(ua) + ";}"); - writer.println("protected boolean isIe9() {return " + "ie9".equals(ua) + ";}"); - writer.println("public String toString() {return \"Browser:\"" + - " + \" webkit=\" + webkit" + - " + \" mozilla=\" + mozilla" + - " + \" opera=\" + opera" + - " + \" msie=\" + msie" + - " + \" ie6=\" + ie6" + - " + \" ie8=\" + ie8" + - " + \" ie9=\" + ie9" + - ";}"); - writer.commit(logger); + if (pWriter != null) { + ClassSourceFileComposerFactory cFact = new ClassSourceFileComposerFactory(pName, cName); + cFact.setSuperclass(pName + "." + clz.getName()); + + SourceWriter writer = cFact.createSourceWriter(context, pWriter); + + writer.println("protected boolean isWebkit() {return " + "safari".equals(ua) + ";}"); + writer.println("protected boolean isSafari() {return " + "safari".equals(ua) + ";}"); + writer.println("protected boolean isOpera() {return " + "opera".equals(ua) + ";}"); + writer.println("protected boolean isMozilla() {return " + ua.contains("gecko") + ";}"); + writer.println("protected boolean isMsie() {return " + ua.contains("ie") + ";}"); + writer.println("protected boolean isIe6() {return " + "ie6".equals(ua) + ";}"); + writer.println("protected boolean isIe8() {return " + "ie8".equals(ua) + ";}"); + writer.println("protected boolean isIe9() {return " + "ie9".equals(ua) + ";}"); + writer.println("public String toString() {return \"Browser:\"" + + " + \" webkit=\" + webkit" + + " + \" mozilla=\" + mozilla" + + " + \" opera=\" + opera" + + " + \" msie=\" + msie" + + " + \" ie6=\" + ie6" + + " + \" ie8=\" + ie8" + + " + \" ie9=\" + ie9" + + ";}"); + writer.commit(logger); + } return pName + "." + cName; } -- 2.39.5