From b55a024ad1629d2db2b1cda04b8d585862c9c07b Mon Sep 17 00:00:00 2001 From: Julien Dramaix Date: Tue, 19 Jun 2012 20:16:03 +0000 Subject: [PATCH] fix issue 140 + support Long, Double, Integer, Float and Byte objects --- .../query/rebind/JsonBuilderGenerator.java | 23 +++++++++++++++---- .../gwt/query/rebind/XmlBuilderGenerator.java | 9 +++++--- 2 files changed, 25 insertions(+), 7 deletions(-) diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/rebind/JsonBuilderGenerator.java b/gwtquery-core/src/main/java/com/google/gwt/query/rebind/JsonBuilderGenerator.java index 552da37b..bbb7e80c 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/rebind/JsonBuilderGenerator.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/rebind/JsonBuilderGenerator.java @@ -71,7 +71,7 @@ public class JsonBuilderGenerator extends Generator { GeneratorContext generatorContext, String requestedClass) throws UnableToCompleteException { oracle = generatorContext.getTypeOracle(); - JClassType clazz = oracle.findType(requestedClass); + JClassType clazz = oracle.findType(requestedClass); jsonBuilderType = oracle.findType(JsonBuilder.class.getName()); stringType = oracle.findType(String.class.getName()); jsType = oracle.findType(JavaScriptObject.class.getName()); @@ -85,8 +85,13 @@ public class JsonBuilderGenerator extends Generator { requestedClass); if (sw != null) { Set attrs = new HashSet(); - for (JMethod method : clazz.getMethods()) { + for (JMethod method : clazz.getInheritableMethods()) { String methName = method.getName(); + //skip method from JsonBuilder + if(jsonBuilderType.findMethod(method.getName(), method.getParameterTypes()) != null){ + continue; + } + Name nameAnnotation = method.getAnnotation(Name.class); String name = nameAnnotation != null ? nameAnnotation.value() @@ -124,7 +129,6 @@ public class JsonBuilderGenerator extends Generator { throws UnableToCompleteException { String ifaceName = method.getEnclosingType().getQualifiedSourceName(); - String retType = method.getReturnType().getParameterizedQualifiedSourceName(); sw.print("public final " + retType + " " + method.getName()); JParameter[] params = method.getParameters(); @@ -137,9 +141,20 @@ public class JsonBuilderGenerator extends Generator { if (retType.matches("(java.lang.Boolean|boolean)")) { sw.println("return p.getBoolean(\"" + name + "\");"); } else if (retType.matches("java.util.Date")) { - sw.println("return new Date(Long.parseLong(p.getStr(\"" + name + "\")));"); + sw.println("return new Date(java.lang.Long.parseLong(p.getStr(\"" + name + "\")));"); } else if (method.getReturnType().isPrimitive() != null) { sw.println("return (" + retType + ")p.getFloat(\"" + name + "\");"); + } else if (retType.equals("java.lang.Integer")) { + sw.println("return (int) p.getFloat(\"" + name + "\");"); + } else if (retType.equals("java.lang.Float")) { + sw.println("return p.getFloat(\"" + name + "\");"); + } else if (retType.equals("java.lang.Double")) { + sw.println("return (double) p.getFloat(\"" + name + "\");"); + } else if (retType.equals("java.lang.Long")) { + sw.println("return (long) p.getFloat(\"" + name + "\");"); + } else if (retType.equals("java.lang.Byte")) { + sw.println("return (byte) p.getFloat(\"" + name + "\");"); + } else if (isTypeAssignableTo(method.getReturnType(), stringType)) { sw.println("return p.getStr(\"" + name + "\");"); } else if (isTypeAssignableTo(method.getReturnType(), jsonBuilderType)) { diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/rebind/XmlBuilderGenerator.java b/gwtquery-core/src/main/java/com/google/gwt/query/rebind/XmlBuilderGenerator.java index 831ec96b..a14d7901 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/rebind/XmlBuilderGenerator.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/rebind/XmlBuilderGenerator.java @@ -25,12 +25,11 @@ import com.google.gwt.core.ext.typeinfo.JArrayType; import com.google.gwt.core.ext.typeinfo.JClassType; import com.google.gwt.core.ext.typeinfo.JMethod; import com.google.gwt.core.ext.typeinfo.JParameter; -import com.google.gwt.core.ext.typeinfo.JPrimitiveType; import com.google.gwt.core.ext.typeinfo.JType; import com.google.gwt.core.ext.typeinfo.TypeOracle; import com.google.gwt.query.client.Properties; -import com.google.gwt.query.client.builders.XmlBuilder; import com.google.gwt.query.client.builders.Name; +import com.google.gwt.query.client.builders.XmlBuilder; import com.google.gwt.user.rebind.ClassSourceFileComposerFactory; import com.google.gwt.user.rebind.SourceWriter; @@ -54,7 +53,11 @@ public class XmlBuilderGenerator extends Generator { SourceWriter sw = getSourceWriter(treeLogger, generatorContext, t[0], t[1], requestedClass); if (sw != null) { - for (JMethod method : clazz.getMethods()) { + for (JMethod method : clazz.getInheritableMethods()) { + //skip method from JsonBuilder + if(xmlBuilderType.findMethod(method.getName(), method.getParameterTypes()) != null){ + continue; + } generateMethod(sw, method, treeLogger); } sw.commit(treeLogger); -- 2.39.5