From 7efa1d6ec145aa48fc75fbdc9e403faf478e7f96 Mon Sep 17 00:00:00 2001 From: Leif Åstrand Date: Thu, 8 Jan 2015 22:21:42 +0200 Subject: 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 --- .../com/vaadin/client/metadata/TypeDataStore.java | 51 ++++++++++------------ 1 file changed, 24 insertions(+), 27 deletions(-) (limited to 'client/src') diff --git a/client/src/com/vaadin/client/metadata/TypeDataStore.java b/client/src/com/vaadin/client/metadata/TypeDataStore.java index 6d46ed1365..e3db0ccded 100644 --- a/client/src/com/vaadin/client/metadata/TypeDataStore.java +++ b/client/src/com/vaadin/client/metadata/TypeDataStore.java @@ -28,6 +28,10 @@ import com.vaadin.client.communication.JSONSerializer; import com.vaadin.shared.annotations.NoLayout; public class TypeDataStore { + public static enum MethodAttribute { + DELAYED, LAST_ONLY, NO_LAYOUT; + } + private static final String CONSTRUCTOR_NAME = "!new"; private final FastStringMap> identifiers = FastStringMap.create(); @@ -47,9 +51,8 @@ public class TypeDataStore { private final FastStringMap>> onStateChangeMethods = FastStringMap .create(); - private final FastStringSet delayedMethods = FastStringSet.create(); - private final FastStringSet lastOnlyMethods = FastStringSet.create(); - private final FastStringSet noLayoutRpcMethods = FastStringSet.create(); + private final FastStringMap methodAttributes = FastStringMap + .create(); private final FastStringMap returnTypes = FastStringMap.create(); private final FastStringMap invokers = FastStringMap.create(); @@ -213,20 +216,29 @@ public class TypeDataStore { } public static boolean isDelayed(Method method) { - return get().delayedMethods.contains(method.getLookupKey()); + return hasMethodAttribute(method, MethodAttribute.DELAYED); } - public void setDelayed(Class type, String methodName) { - delayedMethods.add(getType(type).getMethod(methodName).getLookupKey()); + private static boolean hasMethodAttribute(Method method, + MethodAttribute attribute) { + FastStringSet attributes = get().methodAttributes.get(method + .getLookupKey()); + return attributes != null && attributes.contains(attribute.name()); } - public static boolean isLastOnly(Method method) { - return get().lastOnlyMethods.contains(method.getLookupKey()); + public void setMethodAttribute(Class type, String methodName, + MethodAttribute attribute) { + String key = getType(type).getMethod(methodName).getLookupKey(); + FastStringSet attributes = methodAttributes.get(key); + if (attributes == null) { + attributes = FastStringSet.create(); + methodAttributes.put(key, attributes); + } + attributes.add(attribute.name()); } - public void setLastOnly(Class clazz, String methodName) { - lastOnlyMethods - .add(getType(clazz).getMethod(methodName).getLookupKey()); + public static boolean isLastOnly(Method method) { + return hasMethodAttribute(method, MethodAttribute.LAST_ONLY); } /** @@ -450,22 +462,7 @@ public class TypeDataStore { * otherwise false */ public static boolean isNoLayoutRpcMethod(Method method) { - return get().noLayoutRpcMethods.contains(method.getLookupKey()); - } - - /** - * Defines that a method is annotated with {@link NoLayout}. - * - * @since 7.4 - * - * @param type - * the where the method is defined - * @param methodName - * the name of the method - */ - public void setNoLayoutRpcMethod(Class type, String methodName) { - noLayoutRpcMethods.add(new Method(getType(type), methodName) - .getLookupKey()); + return hasMethodAttribute(method, MethodAttribute.NO_LAYOUT); } /** -- cgit v1.2.3