diff options
author | Leif Åstrand <leif@vaadin.com> | 2015-01-08 22:21:42 +0200 |
---|---|---|
committer | Henri Sara <hesara@vaadin.com> | 2015-01-12 10:36:59 +0000 |
commit | 7efa1d6ec145aa48fc75fbdc9e403faf478e7f96 (patch) | |
tree | aa02e97fe9c0e63e24eb6c1c5ef6a45d4a170a18 /client-compiler/src | |
parent | 2286f9871f7f77dea6139d0cd1dfc6754b1946d5 (diff) | |
download | vaadin-framework-7efa1d6ec145aa48fc75fbdc9e403faf478e7f96.tar.gz vaadin-framework-7efa1d6ec145aa48fc75fbdc9e403faf478e7f96.zip |
Handle generated method flags in a unified way (#15373)
Refactor existing functionality without functional changes to make it
easier to add support for the @BackgroundMessage annotation added in a
separate commit.
Change-Id: I27454ba44af4b7b3b7beccf29b12e22bf9f75a86
Diffstat (limited to 'client-compiler/src')
4 files changed, 55 insertions, 76 deletions
diff --git a/client-compiler/src/com/vaadin/server/widgetsetutils/ConnectorBundleLoaderFactory.java b/client-compiler/src/com/vaadin/server/widgetsetutils/ConnectorBundleLoaderFactory.java index f946d87638..884852f7c8 100644 --- a/client-compiler/src/com/vaadin/server/widgetsetutils/ConnectorBundleLoaderFactory.java +++ b/client-compiler/src/com/vaadin/server/widgetsetutils/ConnectorBundleLoaderFactory.java @@ -55,6 +55,7 @@ import com.vaadin.client.metadata.OnStateChangeMethod; import com.vaadin.client.metadata.ProxyHandler; import com.vaadin.client.metadata.TypeData; import com.vaadin.client.metadata.TypeDataStore; +import com.vaadin.client.metadata.TypeDataStore.MethodAttribute; import com.vaadin.client.ui.UnknownComponentConnector; import com.vaadin.server.widgetsetutils.metadata.ClientRpcVisitor; import com.vaadin.server.widgetsetutils.metadata.ConnectorBundle; @@ -67,7 +68,6 @@ import com.vaadin.server.widgetsetutils.metadata.ServerRpcVisitor; import com.vaadin.server.widgetsetutils.metadata.StateInitVisitor; import com.vaadin.server.widgetsetutils.metadata.TypeVisitor; import com.vaadin.server.widgetsetutils.metadata.WidgetInitVisitor; -import com.vaadin.shared.annotations.Delayed; import com.vaadin.shared.annotations.DelegateToWidget; import com.vaadin.shared.annotations.NoLayout; import com.vaadin.shared.communication.ClientRpc; @@ -502,8 +502,7 @@ public class ConnectorBundleLoaderFactory extends Generator { writeInvokers(logger, w, bundle); writeParamTypes(w, bundle); writeProxys(w, bundle); - writeDelayedInfo(w, bundle); - writeNoLayoutRpcMethods(w, bundle); + writeMethodAttributes(logger, w, bundle); w.println("%s(store);", loadNativeJsMethodName); @@ -516,22 +515,6 @@ public class ConnectorBundleLoaderFactory extends Generator { writeOnStateChangeHandlers(logger, w, bundle); } - private void writeNoLayoutRpcMethods(SplittingSourceWriter w, - ConnectorBundle bundle) { - Map<JClassType, Set<JMethod>> needsNoLayout = bundle - .getNeedsNoLayoutRpcMethods(); - for (Entry<JClassType, Set<JMethod>> entry : needsNoLayout.entrySet()) { - JClassType type = entry.getKey(); - - for (JMethod method : entry.getValue()) { - w.println("store.setNoLayoutRpcMethod(%s, \"%s\");", - getClassLiteralString(type), method.getName()); - } - - w.splitIfNeeded(); - } - } - private void writeOnStateChangeHandlers(TreeLogger logger, SplittingSourceWriter w, ConnectorBundle bundle) throws UnableToCompleteException { @@ -740,32 +723,20 @@ public class ConnectorBundleLoaderFactory extends Generator { } } - private void writeDelayedInfo(SplittingSourceWriter w, - ConnectorBundle bundle) { - Map<JClassType, Set<JMethod>> needsDelayedInfo = bundle - .getNeedsDelayedInfo(); - Set<Entry<JClassType, Set<JMethod>>> entrySet = needsDelayedInfo - .entrySet(); - for (Entry<JClassType, Set<JMethod>> entry : entrySet) { - JClassType type = entry.getKey(); - Set<JMethod> methods = entry.getValue(); - for (JMethod method : methods) { - Delayed annotation = method.getAnnotation(Delayed.class); - if (annotation != null) { - w.print("store.setDelayed("); - writeClassLiteral(w, type); - w.print(", \""); - w.print(escape(method.getName())); - w.println("\");"); - - if (annotation.lastOnly()) { - w.print("store.setLastOnly("); - writeClassLiteral(w, type); - w.print(", \""); - w.print(escape(method.getName())); - w.println("\");"); - } - + private void writeMethodAttributes(TreeLogger logger, + SplittingSourceWriter w, ConnectorBundle bundle) { + for (Entry<JClassType, Map<JMethod, Set<MethodAttribute>>> typeEntry : bundle + .getMethodAttributes().entrySet()) { + JClassType type = typeEntry.getKey(); + for (Entry<JMethod, Set<MethodAttribute>> methodEntry : typeEntry + .getValue().entrySet()) { + JMethod method = methodEntry.getKey(); + Set<MethodAttribute> attributes = methodEntry.getValue(); + for (MethodAttribute attribute : attributes) { + w.println("store.setMethodAttribute(%s, \"%s\", %s.%s);", + getClassLiteralString(type), method.getName(), + MethodAttribute.class.getCanonicalName(), + attribute.name()); w.splitIfNeeded(); } } diff --git a/client-compiler/src/com/vaadin/server/widgetsetutils/metadata/ClientRpcVisitor.java b/client-compiler/src/com/vaadin/server/widgetsetutils/metadata/ClientRpcVisitor.java index 1df3d78588..992a012005 100644 --- a/client-compiler/src/com/vaadin/server/widgetsetutils/metadata/ClientRpcVisitor.java +++ b/client-compiler/src/com/vaadin/server/widgetsetutils/metadata/ClientRpcVisitor.java @@ -24,6 +24,7 @@ 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.vaadin.client.metadata.TypeDataStore.MethodAttribute; import com.vaadin.shared.annotations.NoLayout; public class ClientRpcVisitor extends TypeVisitor { @@ -41,7 +42,8 @@ public class ClientRpcVisitor extends TypeVisitor { bundle.setNeedsInvoker(type, method); bundle.setNeedsParamTypes(type, method); if (method.getAnnotation(NoLayout.class) != null) { - bundle.setNeedsNoLayoutRpcMethod(type, method); + bundle.setMethodAttribute(type, method, + MethodAttribute.NO_LAYOUT); } JType[] parameterTypes = method.getParameterTypes(); 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 31f59ddee4..405925a920 100644 --- a/client-compiler/src/com/vaadin/server/widgetsetutils/metadata/ConnectorBundle.java +++ b/client-compiler/src/com/vaadin/server/widgetsetutils/metadata/ConnectorBundle.java @@ -43,6 +43,7 @@ import com.vaadin.client.ComponentConnector; import com.vaadin.client.ServerConnector; import com.vaadin.client.communication.JSONSerializer; import com.vaadin.client.connectors.AbstractRendererConnector; +import com.vaadin.client.metadata.TypeDataStore.MethodAttribute; import com.vaadin.client.ui.UnknownComponentConnector; import com.vaadin.shared.communication.ClientRpc; import com.vaadin.shared.communication.ServerRpc; @@ -71,9 +72,9 @@ public class ConnectorBundle { private final Map<JClassType, Set<JMethod>> needsReturnType = new HashMap<JClassType, Set<JMethod>>(); private final Map<JClassType, Set<JMethod>> needsInvoker = new HashMap<JClassType, Set<JMethod>>(); 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 Map<JClassType, Set<JMethod>> needsOnStateChange = new HashMap<JClassType, Set<JMethod>>(); - private final Map<JClassType, Set<JMethod>> needsNoLayoutRpcMethods = new HashMap<JClassType, Set<JMethod>>(); + + private final Map<JClassType, Map<JMethod, Set<MethodAttribute>>> methodAttributes = new HashMap<JClassType, Map<JMethod, Set<MethodAttribute>>>(); private final Set<Property> needsProperty = new HashSet<Property>(); private final Map<JClassType, Set<Property>> needsDelegateToWidget = new HashMap<JClassType, Set<Property>>(); @@ -525,23 +526,35 @@ public class ConnectorBundle { return Collections.unmodifiableSet(needsProxySupport); } - public void setNeedsDelayedInfo(JClassType type, JMethod method) { - if (!isNeedsDelayedInfo(type, method)) { - addMapping(needsDelayedInfo, type, method); + public void setMethodAttribute(JClassType type, JMethod method, + MethodAttribute methodAttribute) { + if (!hasMethodAttribute(type, method, methodAttribute)) { + Map<JMethod, Set<MethodAttribute>> typeData = methodAttributes + .get(type); + if (typeData == null) { + typeData = new HashMap<JMethod, Set<MethodAttribute>>(); + methodAttributes.put(type, typeData); + } + + addMapping(typeData, method, methodAttribute); } } - private boolean isNeedsDelayedInfo(JClassType type, JMethod method) { - if (hasMapping(needsDelayedInfo, type, method)) { + private boolean hasMethodAttribute(JClassType type, JMethod method, + MethodAttribute methodAttribute) { + Map<JMethod, Set<MethodAttribute>> typeData = methodAttributes + .get(type); + if (typeData != null && hasMapping(typeData, method, methodAttribute)) { return true; } else { return previousBundle != null - && previousBundle.isNeedsDelayedInfo(type, method); + && previousBundle.hasMethodAttribute(type, method, + methodAttribute); } } - public Map<JClassType, Set<JMethod>> getNeedsDelayedInfo() { - return Collections.unmodifiableMap(needsDelayedInfo); + public Map<JClassType, Map<JMethod, Set<MethodAttribute>>> getMethodAttributes() { + return Collections.unmodifiableMap(methodAttributes); } public void setNeedsSerialize(JType type) { @@ -635,25 +648,6 @@ public class ConnectorBundle { return Collections.unmodifiableMap(needsOnStateChange); } - public void setNeedsNoLayoutRpcMethod(JClassType type, JMethod method) { - if (!isNeedsNoLayoutRpcMethod(type, method)) { - addMapping(needsNoLayoutRpcMethods, type, method); - } - } - - private boolean isNeedsNoLayoutRpcMethod(JClassType type, JMethod method) { - if (hasMapping(needsNoLayoutRpcMethods, type, method)) { - return true; - } else { - return previousBundle != null - && previousBundle.isNeedsNoLayoutRpcMethod(type, method); - } - } - - public Map<JClassType, Set<JMethod>> getNeedsNoLayoutRpcMethods() { - return Collections.unmodifiableMap(needsNoLayoutRpcMethods); - } - public static JMethod findInheritedMethod(JClassType type, String methodName, JType... params) { diff --git a/client-compiler/src/com/vaadin/server/widgetsetutils/metadata/ServerRpcVisitor.java b/client-compiler/src/com/vaadin/server/widgetsetutils/metadata/ServerRpcVisitor.java index 6ad0d2fd98..a1852d5b32 100644 --- a/client-compiler/src/com/vaadin/server/widgetsetutils/metadata/ServerRpcVisitor.java +++ b/client-compiler/src/com/vaadin/server/widgetsetutils/metadata/ServerRpcVisitor.java @@ -23,6 +23,8 @@ 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.vaadin.client.metadata.TypeDataStore.MethodAttribute; +import com.vaadin.shared.annotations.Delayed; public class ServerRpcVisitor extends TypeVisitor { @Override @@ -38,7 +40,17 @@ public class ServerRpcVisitor extends TypeVisitor { JMethod[] methods = subType.getMethods(); for (JMethod method : methods) { ClientRpcVisitor.checkReturnType(logger, method); - bundle.setNeedsDelayedInfo(type, method); + + Delayed delayed = method.getAnnotation(Delayed.class); + if (delayed != null) { + bundle.setMethodAttribute(type, method, + MethodAttribute.DELAYED); + if (delayed.lastOnly()) { + bundle.setMethodAttribute(type, method, + MethodAttribute.LAST_ONLY); + } + } + bundle.setNeedsParamTypes(type, method); JType[] parameterTypes = method.getParameterTypes(); |