From 35905ef42d12b58538810f9b3435f3b311ca5af0 Mon Sep 17 00:00:00 2001 From: Henri Sara Date: Wed, 22 Feb 2012 12:52:45 +0200 Subject: [PATCH] Process also fields from shared state superclasses (#8304). --- .../widgetsetutils/SerializerGenerator.java | 79 ++++++++++--------- 1 file changed, 43 insertions(+), 36 deletions(-) diff --git a/src/com/vaadin/terminal/gwt/widgetsetutils/SerializerGenerator.java b/src/com/vaadin/terminal/gwt/widgetsetutils/SerializerGenerator.java index a5be3be84d..3c52bd6a54 100644 --- a/src/com/vaadin/terminal/gwt/widgetsetutils/SerializerGenerator.java +++ b/src/com/vaadin/terminal/gwt/widgetsetutils/SerializerGenerator.java @@ -115,43 +115,50 @@ public class SerializerGenerator extends Generator { sourceWriter.println(beanTypeName + " state = GWT.create(" + beanTypeName + ".class);"); JClassType beanType = typeOracle.findType(beanTypeName); - for (JMethod method : beanType.getMethods()) { - // Process all setters that have corresponding fields - if (!method.isPublic() || method.isStatic() - || !method.getName().startsWith("set") - || method.getParameterTypes().length != 1) { - // Not setter, skip to next method - continue; - - } - String setterName = method.getName(); - String capitalizedFieldName = setterName.substring(3); - String fieldName = decapitalize(capitalizedFieldName); - JType setterParameterType = method.getParameterTypes()[0]; - - logger.log(Type.DEBUG, "* Processing field " + fieldName + " in " - + beanTypeName); - - String jsonFieldName = "json" + capitalizedFieldName; - // JSONArray jsonHeight = (JSONArray) jsonValue.get("height"); - sourceWriter.println("JSONArray " + jsonFieldName - + " = (JSONArray) jsonValue.get(\"" + fieldName + "\");"); - - // state.setHeight((String) - // JsonDecoder.convertValue(jsonFieldValue,idMapper)); - - String fieldType; - JPrimitiveType primitiveType = setterParameterType.isPrimitive(); - if (primitiveType != null) { - // This is a primitive type -> must used the boxed type - fieldType = primitiveType.getQualifiedBoxedSourceName(); - } else { - fieldType = setterParameterType.getQualifiedSourceName(); + JClassType objectType = typeOracle.findType("java.lang.Object"); + while (!objectType.equals(beanType)) { + for (JMethod method : beanType.getMethods()) { + // Process all setters that have corresponding fields + if (!method.isPublic() || method.isStatic() + || !method.getName().startsWith("set") + || method.getParameterTypes().length != 1) { + // Not setter, skip to next method + continue; + + } + String setterName = method.getName(); + String capitalizedFieldName = setterName.substring(3); + String fieldName = decapitalize(capitalizedFieldName); + JType setterParameterType = method.getParameterTypes()[0]; + + logger.log(Type.DEBUG, "* Processing field " + fieldName + + " in " + beanTypeName + " (" + beanType.getName() + + ")"); + + String jsonFieldName = "json" + capitalizedFieldName; + // JSONArray jsonHeight = (JSONArray) jsonValue.get("height"); + sourceWriter.println("JSONArray " + jsonFieldName + + " = (JSONArray) jsonValue.get(\"" + fieldName + + "\");"); + + // state.setHeight((String) + // JsonDecoder.convertValue(jsonFieldValue,idMapper)); + + String fieldType; + JPrimitiveType primitiveType = setterParameterType + .isPrimitive(); + if (primitiveType != null) { + // This is a primitive type -> must used the boxed type + fieldType = primitiveType.getQualifiedBoxedSourceName(); + } else { + fieldType = setterParameterType.getQualifiedSourceName(); + } + + sourceWriter.println("state." + setterName + "((" + fieldType + + ") JsonDecoder.convertValue(" + jsonFieldName + + ", idMapper));"); } - - sourceWriter.println("state." + setterName + "((" + fieldType - + ") JsonDecoder.convertValue(" + jsonFieldName - + ", idMapper));"); + beanType = beanType.getSuperclass(); } // return state; -- 2.39.5