summaryrefslogtreecommitdiffstats
path: root/client-compiler
diff options
context:
space:
mode:
authorLeif Åstrand <leif@vaadin.com>2012-08-22 20:14:30 +0300
committerLeif Åstrand <leif@vaadin.com>2012-08-22 20:14:30 +0300
commit38358ae25543433f8cc381101bc340adc7e5c67f (patch)
treee494d807e1031c04a3d07a0c56dd60be9ae6578a /client-compiler
parent02878bd07a38dc69fe415c7f60238817d2a7c434 (diff)
downloadvaadin-framework-38358ae25543433f8cc381101bc340adc7e5c67f.tar.gz
vaadin-framework-38358ae25543433f8cc381101bc340adc7e5c67f.zip
Support using public fields in state classes (#9324)
Diffstat (limited to 'client-compiler')
-rw-r--r--client-compiler/src/com/vaadin/terminal/gwt/widgetsetutils/ConnectorBundleLoaderFactory.java2
-rw-r--r--client-compiler/src/com/vaadin/terminal/gwt/widgetsetutils/metadata/ConnectorBundle.java1
-rw-r--r--client-compiler/src/com/vaadin/terminal/gwt/widgetsetutils/metadata/FieldProperty.java77
3 files changed, 79 insertions, 1 deletions
diff --git a/client-compiler/src/com/vaadin/terminal/gwt/widgetsetutils/ConnectorBundleLoaderFactory.java b/client-compiler/src/com/vaadin/terminal/gwt/widgetsetutils/ConnectorBundleLoaderFactory.java
index 9a5b83f460..a2e61947e8 100644
--- a/client-compiler/src/com/vaadin/terminal/gwt/widgetsetutils/ConnectorBundleLoaderFactory.java
+++ b/client-compiler/src/com/vaadin/terminal/gwt/widgetsetutils/ConnectorBundleLoaderFactory.java
@@ -219,7 +219,7 @@ public class ConnectorBundleLoaderFactory extends Generator {
writeClassLiteral(w, property.getBeanType());
w.print(", \"");
w.print(escape(property.getName()));
- w.print("\", new Invoker() {");
+ w.println("\", new Invoker() {");
w.indent();
w.println("public Object invoke(Object bean, Object[] params) {");
diff --git a/client-compiler/src/com/vaadin/terminal/gwt/widgetsetutils/metadata/ConnectorBundle.java b/client-compiler/src/com/vaadin/terminal/gwt/widgetsetutils/metadata/ConnectorBundle.java
index ad6b1eb102..7515124a5a 100644
--- a/client-compiler/src/com/vaadin/terminal/gwt/widgetsetutils/metadata/ConnectorBundle.java
+++ b/client-compiler/src/com/vaadin/terminal/gwt/widgetsetutils/metadata/ConnectorBundle.java
@@ -372,6 +372,7 @@ public class ConnectorBundle {
HashSet<Property> properties = new HashSet<Property>();
properties.addAll(MethodProperty.findProperties(type));
+ properties.addAll(FieldProperty.findProperties(type));
return properties;
}
diff --git a/client-compiler/src/com/vaadin/terminal/gwt/widgetsetutils/metadata/FieldProperty.java b/client-compiler/src/com/vaadin/terminal/gwt/widgetsetutils/metadata/FieldProperty.java
new file mode 100644
index 0000000000..31555cc30b
--- /dev/null
+++ b/client-compiler/src/com/vaadin/terminal/gwt/widgetsetutils/metadata/FieldProperty.java
@@ -0,0 +1,77 @@
+/*
+ * Copyright 2011 Vaadin Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+
+package com.vaadin.terminal.gwt.widgetsetutils.metadata;
+
+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;
+import com.google.gwt.core.ext.typeinfo.JField;
+import com.google.gwt.user.rebind.SourceWriter;
+
+public class FieldProperty extends Property {
+
+ private FieldProperty(JClassType beanType, JField field) {
+ super(field.getName(), beanType, field.getType());
+ }
+
+ @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);
+ }
+
+ @Override
+ public void writeGetterBody(TreeLogger logger, SourceWriter w,
+ String beanVariable) {
+ w.print("return ((%s) %s).%s;", getBeanType().getQualifiedSourceName(),
+ beanVariable, getName());
+ }
+
+ public static Collection<FieldProperty> findProperties(JClassType type) {
+ Collection<FieldProperty> properties = new ArrayList<FieldProperty>();
+
+ List<JField> fields = getPublicFields(type);
+ for (JField field : fields) {
+ properties.add(new FieldProperty(type, field));
+ }
+
+ return properties;
+ }
+
+ private static List<JField> getPublicFields(JClassType type) {
+ Set<String> names = new HashSet<String>();
+ ArrayList<JField> fields = new ArrayList<JField>();
+ for (JClassType subType : type.getFlattenedSupertypeHierarchy()) {
+ JField[] subFields = subType.getFields();
+ for (JField field : subFields) {
+ if (field.isPublic() && !field.isStatic()
+ && names.add(field.getName())) {
+ fields.add(field);
+ }
+ }
+ }
+ return fields;
+ }
+
+}