aboutsummaryrefslogtreecommitdiffstats
path: root/client-compiler
diff options
context:
space:
mode:
authordenisanisimov <denis@vaadin.com>2014-02-04 13:11:39 +0200
committerLeif Åstrand <leif@vaadin.com>2014-02-12 07:32:02 +0000
commit5592f056be51e2d18498c067fa5232963677d32e (patch)
tree64d04247b678a979101b45202a81f989ca80875b /client-compiler
parent0ffcdf782ebeb72a345f5d737960258fc6581ef9 (diff)
downloadvaadin-framework-5592f056be51e2d18498c067fa5232963677d32e.tar.gz
vaadin-framework-5592f056be51e2d18498c067fa5232963677d32e.zip
Reduce generated ConnectorBundleLoaderImpl size. (#9379)
Change-Id: I49411e6893f3adc1c41cc690aca35cd919769625
Diffstat (limited to 'client-compiler')
-rw-r--r--client-compiler/src/com/vaadin/server/widgetsetutils/ConnectorBundleLoaderFactory.java288
-rw-r--r--client-compiler/src/com/vaadin/server/widgetsetutils/metadata/ConnectorBundle.java92
-rw-r--r--client-compiler/src/com/vaadin/server/widgetsetutils/metadata/FieldProperty.java19
-rw-r--r--client-compiler/src/com/vaadin/server/widgetsetutils/metadata/MethodProperty.java78
-rw-r--r--client-compiler/src/com/vaadin/server/widgetsetutils/metadata/Property.java24
5 files changed, 296 insertions, 205 deletions
diff --git a/client-compiler/src/com/vaadin/server/widgetsetutils/ConnectorBundleLoaderFactory.java b/client-compiler/src/com/vaadin/server/widgetsetutils/ConnectorBundleLoaderFactory.java
index f8aa586064..1c06cea3fa 100644
--- a/client-compiler/src/com/vaadin/server/widgetsetutils/ConnectorBundleLoaderFactory.java
+++ b/client-compiler/src/com/vaadin/server/widgetsetutils/ConnectorBundleLoaderFactory.java
@@ -19,6 +19,8 @@ import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
+import java.util.Collections;
+import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
@@ -74,6 +76,7 @@ public class ConnectorBundleLoaderFactory extends Generator {
private final SourceWriter target;
private final String baseName;
private final int splitSize;
+ private final List<String> methodNames;
// Seems to be undercounted by about 15%
private int approximateChars = 0;
@@ -84,6 +87,8 @@ public class ConnectorBundleLoaderFactory extends Generator {
this.target = target;
this.baseName = baseName;
this.splitSize = splitSize;
+ methodNames = new ArrayList<String>();
+ methodNames.add(baseName);
}
@Override
@@ -169,17 +174,34 @@ public class ConnectorBundleLoaderFactory extends Generator {
}
public void splitIfNeeded() {
+ splitIfNeeded(false, null);
+ }
+
+ public void splitIfNeeded(boolean isNative, String params) {
if (approximateChars > splitSize) {
String newMethod = baseName + wrapCount++;
- println("%s();", newMethod);
- outdent();
- println("}");
- println("private void %s() {", newMethod);
+ String args = params == null ? "" : params;
+ if (isNative) {
+ outdent();
+ println("}-*/;");
+ println("private native void %s(%s) /*-{", newMethod, args);
+ } else {
+ println("%s();", newMethod);
+ outdent();
+ println("}");
+ println("private void %s(%s) {", newMethod, args);
+ }
+ methodNames.add(newMethod);
indent();
approximateChars = 0;
}
}
+
+ public List<String> getMethodNames() {
+ return Collections.unmodifiableList(methodNames);
+ }
+
}
@Override
@@ -227,6 +249,8 @@ public class ConnectorBundleLoaderFactory extends Generator {
w.indent();
for (ConnectorBundle bundle : bundles) {
+ detectBadProperties(bundle, logger);
+
String name = bundle.getName();
boolean isEager = name
.equals(ConnectorBundleLoader.EAGER_BUNDLE_NAME);
@@ -275,12 +299,34 @@ public class ConnectorBundleLoaderFactory extends Generator {
w.println("private void load() {");
w.indent();
- printBundleData(logger, w, bundle);
+ String loadNativeJsBundle = "loadJsBundle";
+ printBundleData(logger, w, bundle, loadNativeJsBundle);
// Close load method
w.outdent();
w.println("}");
+ // Separate method for loading native JS stuff (e.g. callbacks)
+ String loadNativeJsMethodName = "loadNativeJs";
+ w.println("private native void %s(%s store) /*-{",
+ loadNativeJsMethodName, TypeDataStore.class.getName());
+ w.indent();
+ List<String> jsMethodNames = printJsBundleData(logger, w, bundle,
+ loadNativeJsMethodName);
+
+ w.outdent();
+ w.println("}-*/;");
+
+ // Call all generated native method inside one Java method to avoid
+ // refercences inside native methods to each other
+ w.println("private void %s(%s store) {", loadNativeJsBundle,
+ TypeDataStore.class.getName());
+ w.indent();
+ printLoadJsBundleData(w, loadNativeJsBundle, jsMethodNames);
+ w.outdent();
+ w.println("}");
+
+ // onFailure method declaration starts
w.println("public void onFailure(Throwable reason) {");
w.indent();
@@ -315,27 +361,153 @@ public class ConnectorBundleLoaderFactory extends Generator {
w.commit(logger);
}
+ private void printLoadJsBundleData(SourceWriter w, String methodName,
+ List<String> methods) {
+ SplittingSourceWriter writer = new SplittingSourceWriter(w, methodName,
+ 30000);
+
+ for (String method : methods) {
+ writer.println("%s(store);", method);
+ writer.splitIfNeeded();
+ }
+ }
+
+ private void detectBadProperties(ConnectorBundle bundle, TreeLogger logger)
+ throws UnableToCompleteException {
+ Map<JClassType, Set<String>> definedProperties = new HashMap<JClassType, Set<String>>();
+
+ for (Property property : bundle.getNeedsProperty()) {
+ JClassType beanType = property.getBeanType();
+ Set<String> usedPropertyNames = definedProperties.get(beanType);
+ if (usedPropertyNames == null) {
+ usedPropertyNames = new HashSet<String>();
+ definedProperties.put(beanType, usedPropertyNames);
+ }
+
+ String name = property.getName();
+ if (!usedPropertyNames.add(name)) {
+ logger.log(Type.ERROR, beanType.getQualifiedSourceName()
+ + " has multiple properties with the name " + name
+ + ". This can happen if there are multiple "
+ + "setters with identical names ignoring case.");
+ throw new UnableToCompleteException();
+ }
+ if (!property.hasAccessorMethods()) {
+ logger.log(Type.ERROR, beanType.getQualifiedSourceName()
+ + " has the property '" + name
+ + "' without getter defined.");
+ throw new UnableToCompleteException();
+ }
+ }
+ }
+
+ private List<String> printJsBundleData(TreeLogger logger, SourceWriter w,
+ ConnectorBundle bundle, String methodName) {
+ SplittingSourceWriter writer = new SplittingSourceWriter(w, methodName,
+ 30000);
+ Set<Property> needsProperty = bundle.getNeedsProperty();
+ for (Property property : needsProperty) {
+ writer.println("var data = {");
+ writer.indent();
+
+ writer.println("setter: function(bean, value) {");
+ writer.indent();
+ property.writeSetterBody(logger, writer, "bean", "value");
+ writer.outdent();
+ writer.println("},");
+
+ writer.println("getter: function(bean) {");
+ writer.indent();
+ property.writeGetterBody(logger, writer, "bean");
+ writer.outdent();
+ writer.println("}");
+
+ writer.outdent();
+ writer.println("};");
+
+ // Method declaration
+ writer.print(
+ "store.@%s::setPropertyData(Ljava/lang/Class;Ljava/lang/String;Lcom/google/gwt/core/client/JavaScriptObject;)",
+ TypeDataStore.class.getName());
+ writer.println("(@%s::class, '%s', data);", property.getBeanType()
+ .getQualifiedSourceName(), property.getName());
+ writer.println();
+ writer.splitIfNeeded(true,
+ String.format("%s store", TypeDataStore.class.getName()));
+ }
+ return writer.getMethodNames();
+ }
+
private void printBundleData(TreeLogger logger, SourceWriter sourceWriter,
- ConnectorBundle bundle) throws UnableToCompleteException {
+ ConnectorBundle bundle, String loadNativeJsMethodName)
+ throws UnableToCompleteException {
// Split into new load method when reaching approximately 30000 bytes
SplittingSourceWriter w = new SplittingSourceWriter(sourceWriter,
"load", 30000);
+ writeSuperClasses(w, bundle);
writeIdentifiers(w, bundle);
writeGwtConstructors(w, bundle);
writeReturnTypes(w, bundle);
writeInvokers(w, bundle);
writeParamTypes(w, bundle);
writeProxys(w, bundle);
- wirteDelayedInfo(w, bundle);
- writeProperites(logger, w, bundle);
- writePropertyTypes(w, bundle);
- writeSetters(logger, w, bundle);
- writeGetters(logger, w, bundle);
+ writeDelayedInfo(w, bundle);
+
+ w.println("%s(store);", loadNativeJsMethodName);
+
+ // Must use Java code to generate Type data (because of Type[]), doing
+ // this after the JS property data has been initialized
+ writePropertyTypes(logger, w, bundle);
writeSerializers(logger, w, bundle);
writeDelegateToWidget(logger, w, bundle);
}
+ private void writeSuperClasses(SplittingSourceWriter w,
+ ConnectorBundle bundle) {
+ List<JClassType> needsSuperclass = new ArrayList<JClassType>(
+ bundle.getNeedsSuperclass());
+ // Emit in hierarchy order to ensure superclass is defined when
+ // referenced
+ Collections.sort(needsSuperclass, new Comparator<JClassType>() {
+
+ @Override
+ public int compare(JClassType type1, JClassType type2) {
+ int depthDiff = getDepth(type1) - getDepth(type2);
+ if (depthDiff != 0) {
+ return depthDiff;
+ } else {
+ // Just something to get a stable compare
+ return type1.getName().compareTo(type2.getName());
+ }
+ }
+
+ private int getDepth(JClassType type) {
+ int depth = 0;
+ while (type != null) {
+ depth++;
+ type = type.getSuperclass();
+ }
+ return depth;
+ }
+ });
+
+ for (JClassType jClassType : needsSuperclass) {
+ JClassType superclass = jClassType.getSuperclass();
+ while (superclass != null && !superclass.isPublic()) {
+ superclass = superclass.getSuperclass();
+ }
+ String classLiteralString;
+ if (superclass == null) {
+ classLiteralString = "null";
+ } else {
+ classLiteralString = getClassLiteralString(superclass);
+ }
+ w.println("store.setSuperClass(%s, %s);",
+ getClassLiteralString(jClassType), classLiteralString);
+ }
+ }
+
private void writeDelegateToWidget(TreeLogger logger,
SplittingSourceWriter w, ConnectorBundle bundle) {
Set<Property> needsDelegateToWidget = bundle.getNeedsDelegateToWidget();
@@ -378,64 +550,9 @@ public class ConnectorBundleLoaderFactory extends Generator {
}
}
- private void writeGetters(TreeLogger logger, SplittingSourceWriter w,
+ private void writePropertyTypes(TreeLogger logger, SplittingSourceWriter w,
ConnectorBundle bundle) {
- Set<Property> properties = bundle.getNeedsSetter();
- for (Property property : properties) {
- w.print("store.setGetter(");
- writeClassLiteral(w, property.getBeanType());
- w.print(", \"");
- w.print(escape(property.getName()));
- w.println("\", new Invoker() {");
- w.indent();
-
- w.println("public Object invoke(Object bean, Object[] params) {");
- w.indent();
-
- property.writeGetterBody(logger, w, "bean");
- w.println();
-
- w.outdent();
- w.println("}");
-
- w.outdent();
- w.println("});");
-
- w.splitIfNeeded();
- }
- }
-
- private void writeSetters(TreeLogger logger, SplittingSourceWriter w,
- ConnectorBundle bundle) {
- Set<Property> properties = bundle.getNeedsSetter();
- for (Property property : properties) {
- w.print("store.setSetter(");
- writeClassLiteral(w, property.getBeanType());
- w.print(", \"");
- w.print(escape(property.getName()));
- w.println("\", new Invoker() {");
- w.indent();
-
- w.println("public Object invoke(Object bean, Object[] params) {");
- w.indent();
-
- property.writeSetterBody(logger, w, "bean", "params[0]");
-
- w.println("return null;");
-
- w.outdent();
- w.println("}");
-
- w.outdent();
- w.println("});");
-
- w.splitIfNeeded();
- }
- }
-
- private void writePropertyTypes(SplittingSourceWriter w,
- ConnectorBundle bundle) {
- Set<Property> properties = bundle.getNeedsType();
+ Set<Property> properties = bundle.getNeedsProperty();
for (Property property : properties) {
w.print("store.setPropertyType(");
writeClassLiteral(w, property.getBeanType());
@@ -449,40 +566,7 @@ public class ConnectorBundleLoaderFactory extends Generator {
}
}
- private void writeProperites(TreeLogger logger, SplittingSourceWriter w,
- ConnectorBundle bundle) throws UnableToCompleteException {
- Set<JClassType> needsPropertyListing = bundle.getNeedsPropertyListing();
- for (JClassType type : needsPropertyListing) {
- w.print("store.setProperties(");
- writeClassLiteral(w, type);
- w.print(", new String[] {");
-
- Set<String> usedPropertyNames = new HashSet<String>();
- Collection<Property> properties = bundle.getProperties(type);
- for (Property property : properties) {
- String name = property.getName();
- if (!usedPropertyNames.add(name)) {
- logger.log(
- Type.ERROR,
- type.getQualifiedSourceName()
- + " has multiple properties with the name "
- + name
- + ". This can happen if there are multiple setters with identical names exect casing.");
- throw new UnableToCompleteException();
- }
-
- w.print("\"");
- w.print(name);
- w.print("\", ");
- }
-
- w.println("});");
-
- w.splitIfNeeded();
- }
- }
-
- private void wirteDelayedInfo(SplittingSourceWriter w,
+ private void writeDelayedInfo(SplittingSourceWriter w,
ConnectorBundle bundle) {
Map<JClassType, Set<JMethod>> needsDelayedInfo = bundle
.getNeedsDelayedInfo();
diff --git a/client-compiler/src/com/vaadin/server/widgetsetutils/metadata/ConnectorBundle.java b/client-compiler/src/com/vaadin/server/widgetsetutils/metadata/ConnectorBundle.java
index 4d6a7ff6d7..0064a24aef 100644
--- a/client-compiler/src/com/vaadin/server/widgetsetutils/metadata/ConnectorBundle.java
+++ b/client-compiler/src/com/vaadin/server/widgetsetutils/metadata/ConnectorBundle.java
@@ -59,7 +59,7 @@ public class ConnectorBundle {
private final Set<JType> needsSerializeSupport = new HashSet<JType>();
private final Map<JType, GeneratedSerializer> serializers = new HashMap<JType, GeneratedSerializer>();
- private final Set<JClassType> needsPropertyList = new HashSet<JClassType>();
+ private final Set<JClassType> needsSuperClass = new HashSet<JClassType>();
private final Set<JClassType> needsGwtConstructor = new HashSet<JClassType>();
private final Set<JClassType> visitedTypes = new HashSet<JClassType>();
private final Set<JClassType> needsProxySupport = new HashSet<JClassType>();
@@ -70,9 +70,7 @@ public class ConnectorBundle {
private final Map<JClassType, Set<JMethod>> needsParamTypes = new HashMap<JClassType, Set<JMethod>>();
private final Map<JClassType, Set<JMethod>> needsDelayedInfo = new HashMap<JClassType, Set<JMethod>>();
- private final Set<Property> needsSetter = new HashSet<Property>();
- private final Set<Property> needsType = new HashSet<Property>();
- private final Set<Property> needsGetter = new HashSet<Property>();
+ private final Set<Property> needsProperty = new HashSet<Property>();
private final Set<Property> needsDelegateToWidget = new HashSet<Property>();
private ConnectorBundle(String name, ConnectorBundle previousBundle,
@@ -246,16 +244,18 @@ public class ConnectorBundle {
logger.log(Type.INFO, "Will serialize " + type + " as a bean");
- setNeedsPropertyList(typeAsClass);
+ JClassType needsSuperClass = typeAsClass;
+ while (needsSuperClass != null) {
+ if (needsSuperClass.isPublic()) {
+ setNeedsSuperclass(needsSuperClass);
+ }
+ needsSuperClass = needsSuperClass.getSuperclass();
+ }
for (Property property : getProperties(typeAsClass)) {
setNeedsGwtConstructor(property.getBeanType());
- setNeedsSetter(property);
- // Getters needed for reading previous value that should be
- // passed to sub encoder
- setNeedsGetter(property);
- setNeedsType(property);
+ setNeedsProperty(property);
JType propertyType = property.getPropertyType();
setNeedsSerialize(propertyType);
@@ -304,80 +304,42 @@ public class ConnectorBundle {
return Collections.unmodifiableMap(serializers);
}
- private void setNeedsGetter(Property property) {
- if (!isNeedsGetter(property)) {
- needsGetter.add(property);
- }
- }
-
- private boolean isNeedsGetter(Property property) {
- if (needsGetter.contains(property)) {
- return true;
- } else {
- return previousBundle != null
- && previousBundle.isNeedsGetter(property);
- }
- }
-
- public Set<Property> getNeedsGetter() {
- return Collections.unmodifiableSet(needsGetter);
- }
-
- private void setNeedsType(Property property) {
- if (!isNeedsType(property)) {
- needsType.add(property);
- }
- }
-
- public Set<Property> getNeedsType() {
- return Collections.unmodifiableSet(needsType);
- }
-
- private boolean isNeedsType(Property property) {
- if (needsType.contains(property)) {
- return true;
- } else {
- return previousBundle != null
- && previousBundle.isNeedsType(property);
- }
- }
-
- public void setNeedsSetter(Property property) {
- if (!isNeedsSetter(property)) {
- needsSetter.add(property);
+ private void setNeedsSuperclass(JClassType typeAsClass) {
+ if (!isNeedsSuperClass(typeAsClass)) {
+ needsSuperClass.add(typeAsClass);
}
}
- private boolean isNeedsSetter(Property property) {
- if (needsSetter.contains(property)) {
+ private boolean isNeedsSuperClass(JClassType typeAsClass) {
+ if (needsSuperClass.contains(typeAsClass)) {
return true;
} else {
return previousBundle != null
- && previousBundle.isNeedsSetter(property);
+ && previousBundle.isNeedsSuperClass(typeAsClass);
}
}
- public Set<Property> getNeedsSetter() {
- return Collections.unmodifiableSet(needsSetter);
+ public Set<JClassType> getNeedsSuperclass() {
+ return Collections.unmodifiableSet(needsSuperClass);
}
- private void setNeedsPropertyList(JClassType type) {
- if (!isNeedsPropertyList(type)) {
- needsPropertyList.add(type);
+ private void setNeedsProperty(Property property) {
+ if (!isNeedsProperty(property)) {
+ needsProperty.add(property);
}
}
- private boolean isNeedsPropertyList(JClassType type) {
- if (needsPropertyList.contains(type)) {
+ private boolean isNeedsProperty(Property property) {
+ if (needsProperty.contains(property)) {
return true;
} else {
return previousBundle != null
- && previousBundle.isNeedsPropertyList(type);
+ && previousBundle.isNeedsProperty(property);
}
}
- public Set<JClassType> getNeedsPropertyListing() {
- return Collections.unmodifiableSet(needsPropertyList);
+ public Set<Property> getNeedsProperty() {
+ return Collections.unmodifiableSet(needsProperty);
}
public Collection<Property> getProperties(JClassType type) {
@@ -623,4 +585,4 @@ public class ConnectorBundle {
return Collections.unmodifiableSet(needsDelegateToWidget);
}
-} \ No newline at end of file
+}
diff --git a/client-compiler/src/com/vaadin/server/widgetsetutils/metadata/FieldProperty.java b/client-compiler/src/com/vaadin/server/widgetsetutils/metadata/FieldProperty.java
index 86b8260885..e9ff4587fb 100644
--- a/client-compiler/src/com/vaadin/server/widgetsetutils/metadata/FieldProperty.java
+++ b/client-compiler/src/com/vaadin/server/widgetsetutils/metadata/FieldProperty.java
@@ -38,18 +38,25 @@ public class FieldProperty extends Property {
}
@Override
+ public boolean hasAccessorMethods() {
+ return true;
+ }
+
+ @Override
public void writeSetterBody(TreeLogger logger, SourceWriter w,
String beanVariable, String valueVariable) {
- w.print("((%s) %s).%s = (%s)%s;", getBeanType()
- .getQualifiedSourceName(), beanVariable, getName(),
- getUnboxedPropertyTypeName(), valueVariable);
+ w.println("%s.@%s::%s = %s;", beanVariable, getBeanType()
+ .getQualifiedSourceName(), getName(), unboxValue(valueVariable));
}
@Override
public void writeGetterBody(TreeLogger logger, SourceWriter w,
String beanVariable) {
- w.print("return ((%s) %s).%s;", getBeanType().getQualifiedSourceName(),
- beanVariable, getName());
+ String value = String.format("%s.@%s::%s", beanVariable, getBeanType()
+ .getQualifiedSourceName(), getName());
+ w.print("return ");
+ w.print(boxValue(value));
+ w.println(";");
}
public static Collection<FieldProperty> findProperties(JClassType type) {
@@ -57,7 +64,7 @@ public class FieldProperty extends Property {
List<JField> fields = getPublicFields(type);
for (JField field : fields) {
- properties.add(new FieldProperty(type, field));
+ properties.add(new FieldProperty(field.getEnclosingType(), field));
}
return properties;
diff --git a/client-compiler/src/com/vaadin/server/widgetsetutils/metadata/MethodProperty.java b/client-compiler/src/com/vaadin/server/widgetsetutils/metadata/MethodProperty.java
index 3c317e033e..1d9deef265 100644
--- a/client-compiler/src/com/vaadin/server/widgetsetutils/metadata/MethodProperty.java
+++ b/client-compiler/src/com/vaadin/server/widgetsetutils/metadata/MethodProperty.java
@@ -19,7 +19,9 @@ package com.vaadin.server.widgetsetutils.metadata;
import java.lang.annotation.Annotation;
import java.util.ArrayList;
import java.util.Collection;
+import java.util.HashSet;
import java.util.List;
+import java.util.Set;
import com.google.gwt.core.ext.TreeLogger;
import com.google.gwt.core.ext.typeinfo.JClassType;
@@ -31,18 +33,29 @@ public class MethodProperty extends Property {
private final JMethod setter;
- private MethodProperty(JClassType beanType, JMethod setter) {
+ private final String getter;
+
+ private MethodProperty(JClassType beanType, JMethod setter, String getter) {
super(getTransportFieldName(setter), beanType, setter
.getParameterTypes()[0]);
this.setter = setter;
+ this.getter = getter;
+ }
+
+ @Override
+ public boolean hasAccessorMethods() {
+ return getter != null;
}
public static Collection<MethodProperty> findProperties(JClassType type) {
Collection<MethodProperty> properties = new ArrayList<MethodProperty>();
- List<JMethod> setters = getSetters(type);
+ Set<String> getters = new HashSet<String>();
+ List<JMethod> setters = getSetters(type, getters);
for (JMethod setter : setters) {
- properties.add(new MethodProperty(type, setter));
+ String getter = findGetter(type, setter);
+ properties.add(new MethodProperty(setter.getEnclosingType(),
+ setter, getters.contains(getter) ? getter : null));
}
return properties;
@@ -53,9 +66,12 @@ public class MethodProperty extends Property {
*
* @param beanType
* The type to check
+ * @param getters
+ * Set that will be filled with names of getters.
* @return A list of setter methods from the class and its parents
*/
- private static List<JMethod> getSetters(JClassType beanType) {
+ private static List<JMethod> getSetters(JClassType beanType,
+ Set<String> getters) {
List<JMethod> setterMethods = new ArrayList<JMethod>();
while (beanType != null
@@ -63,13 +79,19 @@ public class MethodProperty extends Property {
Object.class.getName())) {
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
+ if (!method.isPublic() || method.isStatic()) {
+ // Not getter/setter, skip to next method
continue;
}
- setterMethods.add(method);
+ String methodName = method.getName();
+ if (methodName.startsWith("set")
+ && method.getParameterTypes().length == 1) {
+ setterMethods.add(method);
+ } else if (method.getParameterTypes().length == 0
+ && methodName.startsWith("is")
+ || methodName.startsWith("get")) {
+ getters.add(methodName);
+ }
}
beanType = beanType.getSuperclass();
}
@@ -78,34 +100,26 @@ public class MethodProperty extends Property {
}
@Override
- public void writeSetterBody(TreeLogger logger, SourceWriter w,
- String beanVariable, String valueVariable) {
- w.print("((");
- w.print(getBeanType().getQualifiedSourceName());
- w.print(") ");
- w.print(beanVariable);
- w.print(").");
- w.print(setter.getName());
- w.print("((");
- w.print(getUnboxedPropertyTypeName());
- w.print(") ");
- w.print(valueVariable);
- w.println(");");
+ public void writeGetterBody(TreeLogger logger, SourceWriter w,
+ String beanVariable) {
+ String value = String.format("%s.@%s::%s()()", beanVariable,
+ getBeanType().getQualifiedSourceName(), getter);
+ w.print("return ");
+ w.print(boxValue(value));
+ w.println(";");
}
@Override
- public void writeGetterBody(TreeLogger logger, SourceWriter w,
- String beanVariable) {
- w.print("return ((");
- w.print(getBeanType().getQualifiedSourceName());
- w.print(") ");
- w.print(beanVariable);
- w.print(").");
- w.print(findGetter(getBeanType(), setter));
- w.print("();");
+ public void writeSetterBody(TreeLogger logger, SourceWriter w,
+ String beanVariable, String valueVariable) {
+ w.println("%s.@%s::%s(%s)(%s);", beanVariable, getBeanType()
+ .getQualifiedSourceName(), setter.getName(), setter
+ .getParameterTypes()[0].getJNISignature(),
+ unboxValue(valueVariable));
+
}
- private String findGetter(JClassType beanType, JMethod setterMethod) {
+ private static String findGetter(JClassType beanType, JMethod setterMethod) {
JType setterParameterType = setterMethod.getParameterTypes()[0];
String fieldName = setterMethod.getName().substring(3);
if (setterParameterType.getQualifiedSourceName().equals(
diff --git a/client-compiler/src/com/vaadin/server/widgetsetutils/metadata/Property.java b/client-compiler/src/com/vaadin/server/widgetsetutils/metadata/Property.java
index 02aad7bdf2..381af23b42 100644
--- a/client-compiler/src/com/vaadin/server/widgetsetutils/metadata/Property.java
+++ b/client-compiler/src/com/vaadin/server/widgetsetutils/metadata/Property.java
@@ -53,6 +53,28 @@ public abstract class Property {
}
}
+ public String boxValue(String codeSnippet) {
+ JPrimitiveType primitive = propertyType.isPrimitive();
+ if (primitive == null) {
+ return codeSnippet;
+ } else {
+ return String.format("@%s::valueOf(%s)(%s)",
+ primitive.getQualifiedBoxedSourceName(),
+ propertyType.getJNISignature(), codeSnippet);
+ }
+ }
+
+ public String unboxValue(String codeSnippet) {
+ JPrimitiveType primitive = propertyType.isPrimitive();
+ if (primitive == null) {
+ return codeSnippet;
+ } else {
+ return String.format("%s.@%s::%sValue()()", codeSnippet,
+ primitive.getQualifiedBoxedSourceName(),
+ primitive.getSimpleSourceName());
+ }
+ }
+
public JClassType getBeanType() {
return beanType;
}
@@ -63,6 +85,8 @@ public abstract class Property {
public abstract void writeGetterBody(TreeLogger logger, SourceWriter w,
String beanVariable);
+ public abstract boolean hasAccessorMethods();
+
@Override
public boolean equals(Object obj) {
if (this == obj) {