summaryrefslogtreecommitdiffstats
path: root/client-compiler
diff options
context:
space:
mode:
authorLeif Åstrand <leif@vaadin.com>2012-08-17 19:22:16 +0300
committerLeif Åstrand <leif@vaadin.com>2012-08-22 19:25:31 +0300
commita34ddd875812ca2c3d1006555a33b72a4e438da3 (patch)
treed971d1098c906b141a50e0d74d93ac8251b1f31e /client-compiler
parent1a7d126e358d92850a41060b06d53309f2ac58f0 (diff)
downloadvaadin-framework-a34ddd875812ca2c3d1006555a33b72a4e438da3.tar.gz
vaadin-framework-a34ddd875812ca2c3d1006555a33b72a4e438da3.zip
Use ConnectorBundle for creating state and widget (#9371)
Diffstat (limited to 'client-compiler')
-rw-r--r--client-compiler/src/com/vaadin/terminal/gwt/widgetsetutils/AbstractConnectorClassBasedFactoryGenerator.java157
-rw-r--r--client-compiler/src/com/vaadin/terminal/gwt/widgetsetutils/ConnectorBundleLoaderFactory.java47
-rw-r--r--client-compiler/src/com/vaadin/terminal/gwt/widgetsetutils/ConnectorStateFactoryGenerator.java41
-rw-r--r--client-compiler/src/com/vaadin/terminal/gwt/widgetsetutils/ConnectorWidgetFactoryGenerator.java41
-rw-r--r--client-compiler/src/com/vaadin/terminal/gwt/widgetsetutils/metadata/ConnectorBundle.java66
-rw-r--r--client-compiler/src/com/vaadin/terminal/gwt/widgetsetutils/metadata/ConnectorInitVisitor.java16
-rw-r--r--client-compiler/src/com/vaadin/terminal/gwt/widgetsetutils/metadata/StateInitVisitor.java25
-rw-r--r--client-compiler/src/com/vaadin/terminal/gwt/widgetsetutils/metadata/TypeVisitor.java51
-rw-r--r--client-compiler/src/com/vaadin/terminal/gwt/widgetsetutils/metadata/WidgetInitVisitor.java25
9 files changed, 196 insertions, 273 deletions
diff --git a/client-compiler/src/com/vaadin/terminal/gwt/widgetsetutils/AbstractConnectorClassBasedFactoryGenerator.java b/client-compiler/src/com/vaadin/terminal/gwt/widgetsetutils/AbstractConnectorClassBasedFactoryGenerator.java
deleted file mode 100644
index 78579b7e54..0000000000
--- a/client-compiler/src/com/vaadin/terminal/gwt/widgetsetutils/AbstractConnectorClassBasedFactoryGenerator.java
+++ /dev/null
@@ -1,157 +0,0 @@
-/*
- * 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;
-
-import java.io.PrintWriter;
-import java.util.Date;
-
-import com.google.gwt.core.client.GWT;
-import com.google.gwt.core.ext.Generator;
-import com.google.gwt.core.ext.GeneratorContext;
-import com.google.gwt.core.ext.TreeLogger;
-import com.google.gwt.core.ext.TreeLogger.Type;
-import com.google.gwt.core.ext.UnableToCompleteException;
-import com.google.gwt.core.ext.typeinfo.JClassType;
-import com.google.gwt.core.ext.typeinfo.JMethod;
-import com.google.gwt.core.ext.typeinfo.JType;
-import com.google.gwt.core.ext.typeinfo.NotFoundException;
-import com.google.gwt.core.ext.typeinfo.TypeOracle;
-import com.google.gwt.user.rebind.ClassSourceFileComposerFactory;
-import com.google.gwt.user.rebind.SourceWriter;
-import com.vaadin.terminal.gwt.client.ServerConnector;
-import com.vaadin.terminal.gwt.client.ui.ConnectorClassBasedFactory;
-import com.vaadin.terminal.gwt.client.ui.ConnectorClassBasedFactory.Creator;
-
-/**
- * GWT generator that creates a lookup method for
- * {@link ConnectorClassBasedFactory} instances.
- *
- * @since 7.0
- */
-public abstract class AbstractConnectorClassBasedFactoryGenerator extends
- Generator {
-
- @Override
- public String generate(TreeLogger logger, GeneratorContext context,
- String typeName) throws UnableToCompleteException {
-
- try {
- // get classType and save instance variables
- return generateConnectorClassBasedFactory(typeName, logger, context);
- } catch (Exception e) {
- logger.log(TreeLogger.ERROR, typeName + " creation failed", e);
- throw new UnableToCompleteException();
- }
- }
-
- private String generateConnectorClassBasedFactory(String typeName,
- TreeLogger logger, GeneratorContext context)
- throws NotFoundException {
- TypeOracle typeOracle = context.getTypeOracle();
-
- JClassType classType = typeOracle.getType(typeName);
- String superName = classType.getSimpleSourceName();
- String packageName = classType.getPackage().getName();
- String className = superName + "Impl";
-
- // get print writer that receives the source code
- PrintWriter printWriter = null;
- printWriter = context.tryCreate(logger, packageName, className);
- // print writer if null, source code has ALREADY been generated
- if (printWriter == null) {
- return packageName + "." + className;
- }
-
- Date date = new Date();
-
- // init composer, set class properties, create source writer
- ClassSourceFileComposerFactory composer = null;
- composer = new ClassSourceFileComposerFactory(packageName, className);
- composer.addImport(GWT.class.getName());
- composer.addImport(Creator.class.getCanonicalName());
- composer.setSuperclass(superName);
-
- SourceWriter sourceWriter = composer.createSourceWriter(context,
- printWriter);
- sourceWriter.indent();
-
- // public ConnectorStateFactoryImpl() {
- sourceWriter.println("public " + className + "() {");
- sourceWriter.indent();
-
- JClassType serverConnectorType = typeOracle.getType(getConnectorType()
- .getCanonicalName());
- for (JClassType connector : serverConnectorType.getSubtypes()) {
- // addCreator(TextAreaConnector.class, new Creator<SharedState>() {
- if (connector.isInterface() != null || connector.isAbstract()) {
- continue;
- }
-
- JClassType targetType = getTargetType(connector);
- if (targetType.isAbstract()) {
- continue;
- }
-
- sourceWriter.println("addCreator("
- + connector.getQualifiedSourceName()
- + ".class, new Creator<"
- + targetType.getQualifiedSourceName() + ">() {");
- // public SharedState create() {
- sourceWriter.println("public "
- + targetType.getQualifiedSourceName() + " create() {");
- // return GWT.create(TextAreaState.class);
- sourceWriter.println("return GWT.create("
- + targetType.getQualifiedSourceName() + ".class);");
- // }
- sourceWriter.println("}");
- // });
- sourceWriter.println("});");
- }
-
- // End of constructor
- sourceWriter.outdent();
- sourceWriter.println("}");
-
- // close generated class
- sourceWriter.outdent();
- sourceWriter.println("}");
-
- // commit generated class
- context.commit(logger, printWriter);
- logger.log(Type.INFO,
- "Done. (" + (new Date().getTime() - date.getTime()) / 1000
- + "seconds)");
- return packageName + "." + className;
-
- }
-
- protected abstract Class<? extends ServerConnector> getConnectorType();
-
- protected abstract JClassType getTargetType(JClassType connectorType);
-
- protected JClassType getGetterReturnType(JClassType connector,
- String getterName) {
- try {
- JMethod getMethod = connector.getMethod(getterName, new JType[] {});
- return (JClassType) getMethod.getReturnType();
- } catch (NotFoundException e) {
- return getGetterReturnType(connector.getSuperclass(), getterName);
- }
-
- }
-
-}
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 cb967dff86..893bebfd0d 100644
--- a/client-compiler/src/com/vaadin/terminal/gwt/widgetsetutils/ConnectorBundleLoaderFactory.java
+++ b/client-compiler/src/com/vaadin/terminal/gwt/widgetsetutils/ConnectorBundleLoaderFactory.java
@@ -22,6 +22,7 @@ import com.google.gwt.core.ext.TreeLogger;
import com.google.gwt.core.ext.TreeLogger.Type;
import com.google.gwt.core.ext.UnableToCompleteException;
import com.google.gwt.core.ext.typeinfo.JClassType;
+import com.google.gwt.core.ext.typeinfo.JMethod;
import com.google.gwt.core.ext.typeinfo.NotFoundException;
import com.google.gwt.core.ext.typeinfo.TypeOracle;
import com.google.gwt.user.rebind.ClassSourceFileComposerFactory;
@@ -36,7 +37,9 @@ import com.vaadin.terminal.gwt.client.metadata.TypeDataBundle;
import com.vaadin.terminal.gwt.client.metadata.TypeDataStore;
import com.vaadin.terminal.gwt.widgetsetutils.metadata.ConnectorBundle;
import com.vaadin.terminal.gwt.widgetsetutils.metadata.ConnectorInitVisitor;
+import com.vaadin.terminal.gwt.widgetsetutils.metadata.StateInitVisitor;
import com.vaadin.terminal.gwt.widgetsetutils.metadata.TypeVisitor;
+import com.vaadin.terminal.gwt.widgetsetutils.metadata.WidgetInitVisitor;
public class ConnectorBundleLoaderFactory extends Generator {
@@ -158,6 +161,30 @@ public class ConnectorBundleLoaderFactory extends Generator {
private void printBundleData(SourceWriter w, ConnectorBundle bundle) {
writeIdentifiers(w, bundle);
writeGwtConstructors(w, bundle);
+ writeReturnTypes(w, bundle);
+ }
+
+ private void writeReturnTypes(SourceWriter w, ConnectorBundle bundle) {
+ Map<JClassType, Set<JMethod>> methodReturnTypes = bundle
+ .getMethodReturnTypes();
+ for (Entry<JClassType, Set<JMethod>> entry : methodReturnTypes
+ .entrySet()) {
+ JClassType type = entry.getKey();
+
+ Set<JMethod> methods = entry.getValue();
+ for (JMethod method : methods) {
+ // setReturnType(Class<?> type, String methodName, Type
+ // returnType)
+ w.print("store.setReturnType(");
+ printClassLiteral(w, type);
+ w.print(", \"");
+ w.print(method.getName());
+ w.print("\", ");
+ GeneratedRpcMethodProviderGenerator.writeTypeCreator(w,
+ method.getReturnType());
+ w.println(");");
+ }
+ }
}
private void writeGwtConstructors(SourceWriter w, ConnectorBundle bundle) {
@@ -206,7 +233,8 @@ public class ConnectorBundleLoaderFactory extends Generator {
}
private List<ConnectorBundle> buildBundles(TreeLogger logger,
- TypeOracle typeOracle) throws NotFoundException {
+ TypeOracle typeOracle) throws NotFoundException,
+ UnableToCompleteException {
Map<LoadStyle, Collection<JClassType>> connectorsByLoadStyle = new HashMap<LoadStyle, Collection<JClassType>>();
for (LoadStyle loadStyle : LoadStyle.values()) {
@@ -234,18 +262,18 @@ public class ConnectorBundleLoaderFactory extends Generator {
ConnectorBundleLoader.EAGER_BUNDLE_NAME, null);
// Eager connectors and all RPC interfaces are loaded by default
- eagerBundle.visitTypes(connectorsByLoadStyle.get(LoadStyle.EAGER),
- visitors);
- eagerBundle.visitSubTypes(
+ eagerBundle.visitTypes(logger,
+ connectorsByLoadStyle.get(LoadStyle.EAGER), visitors);
+ eagerBundle.visitSubTypes(logger,
typeOracle.getType(ClientRpc.class.getName()), visitors);
- eagerBundle.visitSubTypes(
+ eagerBundle.visitSubTypes(logger,
typeOracle.getType(ServerRpc.class.getName()), visitors);
bundles.add(eagerBundle);
ConnectorBundle deferredBundle = new ConnectorBundle(
ConnectorBundleLoader.DEFERRED_BUNDLE_NAME, eagerBundle);
- deferredBundle.visitTypes(
+ deferredBundle.visitTypes(logger,
connectorsByLoadStyle.get(LoadStyle.DEFERRED), visitors);
bundles.add(deferredBundle);
@@ -254,7 +282,7 @@ public class ConnectorBundleLoaderFactory extends Generator {
for (JClassType type : lazy) {
ConnectorBundle bundle = new ConnectorBundle(type.getName(),
deferredBundle);
- bundle.visitTypes(Collections.singleton(type), visitors);
+ bundle.visitTypes(logger, Collections.singleton(type), visitors);
bundles.add(bundle);
}
@@ -264,8 +292,9 @@ public class ConnectorBundleLoaderFactory extends Generator {
private Collection<TypeVisitor> getVisitors(TypeOracle oracle)
throws NotFoundException {
- List<TypeVisitor> visitors = Arrays
- .<TypeVisitor> asList(new ConnectorInitVisitor());
+ List<TypeVisitor> visitors = Arrays.<TypeVisitor> asList(
+ new ConnectorInitVisitor(), new StateInitVisitor(),
+ new WidgetInitVisitor());
for (TypeVisitor typeVisitor : visitors) {
typeVisitor.init(oracle);
}
diff --git a/client-compiler/src/com/vaadin/terminal/gwt/widgetsetutils/ConnectorStateFactoryGenerator.java b/client-compiler/src/com/vaadin/terminal/gwt/widgetsetutils/ConnectorStateFactoryGenerator.java
deleted file mode 100644
index 136ea3360e..0000000000
--- a/client-compiler/src/com/vaadin/terminal/gwt/widgetsetutils/ConnectorStateFactoryGenerator.java
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * 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;
-
-import com.google.gwt.core.ext.typeinfo.JClassType;
-import com.vaadin.terminal.gwt.client.ServerConnector;
-
-/**
- * GWT generator that creates a SharedState class for a given Connector class,
- * based on the return type of getState()
- *
- * @since 7.0
- */
-public class ConnectorStateFactoryGenerator extends
- AbstractConnectorClassBasedFactoryGenerator {
-
- @Override
- protected JClassType getTargetType(JClassType connectorType) {
- return getGetterReturnType(connectorType, "getState");
- }
-
- @Override
- protected Class<? extends ServerConnector> getConnectorType() {
- return ServerConnector.class;
- }
-
-}
diff --git a/client-compiler/src/com/vaadin/terminal/gwt/widgetsetutils/ConnectorWidgetFactoryGenerator.java b/client-compiler/src/com/vaadin/terminal/gwt/widgetsetutils/ConnectorWidgetFactoryGenerator.java
deleted file mode 100644
index 32693369f2..0000000000
--- a/client-compiler/src/com/vaadin/terminal/gwt/widgetsetutils/ConnectorWidgetFactoryGenerator.java
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * 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;
-
-import com.google.gwt.core.ext.typeinfo.JClassType;
-import com.vaadin.terminal.gwt.client.ComponentConnector;
-import com.vaadin.terminal.gwt.client.ServerConnector;
-
-/**
- * GWT generator that creates a Widget class for a given Connector class, based
- * on the return type of getWidget()
- *
- * @since 7.0
- */
-public class ConnectorWidgetFactoryGenerator extends
- AbstractConnectorClassBasedFactoryGenerator {
- @Override
- protected JClassType getTargetType(JClassType connectorType) {
- return getGetterReturnType(connectorType, "getWidget");
- }
-
- @Override
- protected Class<? extends ServerConnector> getConnectorType() {
- return ComponentConnector.class;
- }
-
-} \ No newline at end of file
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 3155ab4474..f734b77101 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
@@ -12,7 +12,12 @@ import java.util.HashSet;
import java.util.Map;
import java.util.Set;
+import com.google.gwt.core.ext.TreeLogger;
+import com.google.gwt.core.ext.TreeLogger.Type;
+import com.google.gwt.core.ext.UnableToCompleteException;
import com.google.gwt.core.ext.typeinfo.JClassType;
+import com.google.gwt.core.ext.typeinfo.JMethod;
+import com.google.gwt.core.ext.typeinfo.NotFoundException;
public class ConnectorBundle {
private final String name;
@@ -22,6 +27,9 @@ public class ConnectorBundle {
private final Map<JClassType, Set<String>> identifiers = new HashMap<JClassType, Set<String>>();
private final Set<JClassType> visitedTypes = new HashSet<JClassType>();
private final Set<JClassType> visitQueue = new HashSet<JClassType>();
+ private final Map<JClassType, Set<JMethod>> needsReturnType = new HashMap<JClassType, Set<JMethod>>();
+
+ private boolean visiting = false;
public ConnectorBundle(String name, ConnectorBundle previousBundle) {
this.name = name;
@@ -30,6 +38,9 @@ public class ConnectorBundle {
public void setNeedsGwtConstructor(JClassType type) {
if (!needsGwtConstructor(type)) {
+ if (!isTypeVisited(type)) {
+ visitQueue.add(type);
+ }
needsGwtConstructor.add(type);
}
}
@@ -45,6 +56,9 @@ public class ConnectorBundle {
public void setIdentifier(JClassType type, String identifier) {
if (!hasIdentifier(type, identifier)) {
+ if (!isTypeVisited(type)) {
+ visitQueue.add(type);
+ }
Set<String> set = identifiers.get(type);
if (set == null) {
set = new HashSet<String>();
@@ -80,37 +94,71 @@ public class ConnectorBundle {
return Collections.unmodifiableSet(needsGwtConstructor);
}
- public void visitTypes(Collection<JClassType> types,
- Collection<TypeVisitor> visitors) {
+ public void visitTypes(TreeLogger logger, Collection<JClassType> types,
+ Collection<TypeVisitor> visitors) throws UnableToCompleteException {
for (JClassType type : types) {
if (!isTypeVisited(type)) {
visitQueue.add(type);
}
}
- visitQueue(visitors);
+ visitQueue(logger, visitors);
}
private boolean isTypeVisited(JClassType type) {
if (visitedTypes.contains(type)) {
return true;
} else {
- return previousBundle != null
- && previousBundle.isTypeVisited(type);
+ return previousBundle != null && previousBundle.isTypeVisited(type);
}
}
- private void visitQueue(Collection<TypeVisitor> visitors) {
+ private void visitQueue(TreeLogger logger, Collection<TypeVisitor> visitors)
+ throws UnableToCompleteException {
while (!visitQueue.isEmpty()) {
JClassType type = visitQueue.iterator().next();
for (TypeVisitor typeVisitor : visitors) {
- typeVisitor.visit(type, this);
+ try {
+ typeVisitor.visit(type, this);
+ } catch (NotFoundException e) {
+ logger.log(Type.ERROR, e.getMessage(), e);
+ throw new UnableToCompleteException();
+ }
}
visitQueue.remove(type);
visitedTypes.add(type);
}
}
- public void visitSubTypes(JClassType type, Collection<TypeVisitor> visitors) {
- visitTypes(Arrays.asList(type.getSubtypes()), visitors);
+ public void visitSubTypes(TreeLogger logger, JClassType type,
+ Collection<TypeVisitor> visitors) throws UnableToCompleteException {
+ visitTypes(logger, Arrays.asList(type.getSubtypes()), visitors);
+ }
+
+ public void setNeedsReturnType(JClassType type, JMethod method) {
+ if (!isNeedsReturnType(type, method)) {
+ if (!isTypeVisited(type)) {
+ visitQueue.add(type);
+ }
+ Set<JMethod> set = needsReturnType.get(type);
+ if (set == null) {
+ set = new HashSet<JMethod>();
+ needsReturnType.put(type, set);
+ }
+ set.add(method);
+ }
+ }
+
+ private boolean isNeedsReturnType(JClassType type, JMethod method) {
+ if (needsReturnType.containsKey(type)
+ && needsReturnType.get(type).contains(method)) {
+ return true;
+ } else {
+ return previousBundle != null
+ && previousBundle.isNeedsReturnType(type, method);
+ }
+ }
+
+ public Map<JClassType, Set<JMethod>> getMethodReturnTypes() {
+ return Collections.unmodifiableMap(needsReturnType);
}
} \ No newline at end of file
diff --git a/client-compiler/src/com/vaadin/terminal/gwt/widgetsetutils/metadata/ConnectorInitVisitor.java b/client-compiler/src/com/vaadin/terminal/gwt/widgetsetutils/metadata/ConnectorInitVisitor.java
index a6e71c70d9..6dd840d612 100644
--- a/client-compiler/src/com/vaadin/terminal/gwt/widgetsetutils/metadata/ConnectorInitVisitor.java
+++ b/client-compiler/src/com/vaadin/terminal/gwt/widgetsetutils/metadata/ConnectorInitVisitor.java
@@ -5,24 +5,14 @@
package com.vaadin.terminal.gwt.widgetsetutils.metadata;
import com.google.gwt.core.ext.typeinfo.JClassType;
-import com.google.gwt.core.ext.typeinfo.NotFoundException;
-import com.google.gwt.core.ext.typeinfo.TypeOracle;
import com.vaadin.shared.ui.Connect;
-import com.vaadin.terminal.gwt.client.ServerConnector;
-public class ConnectorInitVisitor implements TypeVisitor {
-
- private JClassType serverConnector;
-
- @Override
- public void init(TypeOracle oracle) throws NotFoundException {
- serverConnector = oracle.getType(ServerConnector.class.getName());
- }
+public class ConnectorInitVisitor extends TypeVisitor {
@Override
public void visit(JClassType type, ConnectorBundle bundle) {
- Connect connectAnnotation = type.getAnnotation(Connect.class);
- if (connectAnnotation != null && serverConnector.isAssignableFrom(type)) {
+ if (isConnectedConnector(type)) {
+ Connect connectAnnotation = type.getAnnotation(Connect.class);
bundle.setIdentifier(type, connectAnnotation.value()
.getCanonicalName());
bundle.setNeedsGwtConstructor(type);
diff --git a/client-compiler/src/com/vaadin/terminal/gwt/widgetsetutils/metadata/StateInitVisitor.java b/client-compiler/src/com/vaadin/terminal/gwt/widgetsetutils/metadata/StateInitVisitor.java
new file mode 100644
index 0000000000..b88afdf37a
--- /dev/null
+++ b/client-compiler/src/com/vaadin/terminal/gwt/widgetsetutils/metadata/StateInitVisitor.java
@@ -0,0 +1,25 @@
+/*
+@VaadinApache2LicenseForJavaFiles@
+ */
+
+package com.vaadin.terminal.gwt.widgetsetutils.metadata;
+
+import com.google.gwt.core.ext.typeinfo.JClassType;
+import com.google.gwt.core.ext.typeinfo.JMethod;
+import com.google.gwt.core.ext.typeinfo.JType;
+import com.google.gwt.core.ext.typeinfo.NotFoundException;
+
+public class StateInitVisitor extends TypeVisitor {
+ @Override
+ public void visit(JClassType type, ConnectorBundle bundle)
+ throws NotFoundException {
+ if (isConnectedConnector(type)) {
+ JMethod getState = getInheritedMethod(type, "getState");
+ bundle.setNeedsReturnType(type, getState);
+
+ JType stateType = getState.getReturnType();
+ bundle.setNeedsGwtConstructor(stateType.isClass());
+ }
+ }
+
+}
diff --git a/client-compiler/src/com/vaadin/terminal/gwt/widgetsetutils/metadata/TypeVisitor.java b/client-compiler/src/com/vaadin/terminal/gwt/widgetsetutils/metadata/TypeVisitor.java
index 6ed791fe86..163eda0675 100644
--- a/client-compiler/src/com/vaadin/terminal/gwt/widgetsetutils/metadata/TypeVisitor.java
+++ b/client-compiler/src/com/vaadin/terminal/gwt/widgetsetutils/metadata/TypeVisitor.java
@@ -5,11 +5,56 @@
package com.vaadin.terminal.gwt.widgetsetutils.metadata;
import com.google.gwt.core.ext.typeinfo.JClassType;
+import com.google.gwt.core.ext.typeinfo.JMethod;
+import com.google.gwt.core.ext.typeinfo.JType;
import com.google.gwt.core.ext.typeinfo.NotFoundException;
import com.google.gwt.core.ext.typeinfo.TypeOracle;
+import com.vaadin.shared.ui.Connect;
+import com.vaadin.terminal.gwt.client.ComponentConnector;
+import com.vaadin.terminal.gwt.client.ServerConnector;
-public interface TypeVisitor {
- public void init(TypeOracle oracle) throws NotFoundException;
+public abstract class TypeVisitor {
+ private JClassType serverConnector;
+ private JClassType componentConnector;
- public void visit(JClassType type, ConnectorBundle bundle);
+ public void init(TypeOracle oracle) throws NotFoundException {
+ serverConnector = oracle.getType(ServerConnector.class.getName());
+ componentConnector = oracle.getType(ComponentConnector.class.getName());
+ }
+
+ public abstract void visit(JClassType type, ConnectorBundle bundle)
+ throws NotFoundException;
+
+ protected boolean isConnectedConnector(JClassType type) {
+ return serverConnector.isAssignableFrom(type)
+ && type.isAnnotationPresent(Connect.class);
+ }
+
+ protected boolean isConnectedComponentConnector(JClassType type) {
+ return componentConnector.isAssignableFrom(type)
+ && type.isAnnotationPresent(Connect.class);
+ }
+
+ protected JMethod getInheritedMethod(JClassType type, String methodName,
+ JType... params) throws NotFoundException {
+
+ JClassType currentType = type;
+ while (currentType != null) {
+ JMethod method = currentType.findMethod(methodName, params);
+ if (method != null) {
+ return method;
+ }
+ currentType = currentType.getSuperclass();
+ }
+
+ JClassType[] interfaces = type.getImplementedInterfaces();
+ for (JClassType iface : interfaces) {
+ JMethod method = iface.findMethod(methodName, params);
+ if (method != null) {
+ return method;
+ }
+ }
+
+ throw new NotFoundException(methodName + " not found in " + type);
+ }
}
diff --git a/client-compiler/src/com/vaadin/terminal/gwt/widgetsetutils/metadata/WidgetInitVisitor.java b/client-compiler/src/com/vaadin/terminal/gwt/widgetsetutils/metadata/WidgetInitVisitor.java
new file mode 100644
index 0000000000..be6f303c5b
--- /dev/null
+++ b/client-compiler/src/com/vaadin/terminal/gwt/widgetsetutils/metadata/WidgetInitVisitor.java
@@ -0,0 +1,25 @@
+/*
+@VaadinApache2LicenseForJavaFiles@
+ */
+
+package com.vaadin.terminal.gwt.widgetsetutils.metadata;
+
+import com.google.gwt.core.ext.typeinfo.JClassType;
+import com.google.gwt.core.ext.typeinfo.JMethod;
+import com.google.gwt.core.ext.typeinfo.JType;
+import com.google.gwt.core.ext.typeinfo.NotFoundException;
+
+public class WidgetInitVisitor extends TypeVisitor {
+
+ @Override
+ public void visit(JClassType type, ConnectorBundle bundle)
+ throws NotFoundException {
+ if (isConnectedComponentConnector(type)) {
+ JMethod getWidget = getInheritedMethod(type, "getWidget");
+ bundle.setNeedsReturnType(type, getWidget);
+
+ JType widgetType = getWidget.getReturnType();
+ bundle.setNeedsGwtConstructor(widgetType.isClass());
+ }
+ }
+}