From a33772e3f5932cf913ac2c67ce0bcda991dd8fc2 Mon Sep 17 00:00:00 2001 From: Taras Hupalo Date: Sun, 25 Jan 2015 05:46:41 +0200 Subject: Replaced HashMaps with TreeMaps to keep the same order (#14736) Change-Id: Ia2d8b6a2189e0bb7673f28b3606120d77628afb4 --- .../AcceptCriteriaFactoryGenerator.java | 6 +- .../ConnectorBundleLoaderFactory.java | 6 +- .../widgetsetutils/metadata/ConnectorBundle.java | 111 ++++++++++++++++----- .../server/widgetsetutils/metadata/Property.java | 16 ++- 4 files changed, 111 insertions(+), 28 deletions(-) (limited to 'client-compiler') diff --git a/client-compiler/src/com/vaadin/server/widgetsetutils/AcceptCriteriaFactoryGenerator.java b/client-compiler/src/com/vaadin/server/widgetsetutils/AcceptCriteriaFactoryGenerator.java index b7850e6370..2d08329e9a 100644 --- a/client-compiler/src/com/vaadin/server/widgetsetutils/AcceptCriteriaFactoryGenerator.java +++ b/client-compiler/src/com/vaadin/server/widgetsetutils/AcceptCriteriaFactoryGenerator.java @@ -16,6 +16,7 @@ package com.vaadin.server.widgetsetutils; import java.io.PrintWriter; +import java.util.Arrays; import java.util.Date; import com.google.gwt.core.ext.Generator; @@ -29,6 +30,7 @@ import com.google.gwt.user.rebind.ClassSourceFileComposerFactory; import com.google.gwt.user.rebind.SourceWriter; import com.vaadin.client.ui.dd.VAcceptCriterion; import com.vaadin.client.ui.dd.VAcceptCriterionFactory; +import com.vaadin.server.widgetsetutils.metadata.ConnectorBundle; import com.vaadin.shared.ui.dd.AcceptCriterion; /** @@ -114,7 +116,9 @@ public class AcceptCriteriaFactoryGenerator extends Generator { JClassType criteriaType = context.getTypeOracle().findType( VAcceptCriterion.class.getName()); - for (JClassType clientClass : criteriaType.getSubtypes()) { + JClassType[] subtypes = criteriaType.getSubtypes(); + Arrays.sort(subtypes, ConnectorBundle.jClassComparator); + for (JClassType clientClass : subtypes) { AcceptCriterion annotation = clientClass .getAnnotation(AcceptCriterion.class); if (annotation != null) { diff --git a/client-compiler/src/com/vaadin/server/widgetsetutils/ConnectorBundleLoaderFactory.java b/client-compiler/src/com/vaadin/server/widgetsetutils/ConnectorBundleLoaderFactory.java index 884852f7c8..2b8ccc87d0 100644 --- a/client-compiler/src/com/vaadin/server/widgetsetutils/ConnectorBundleLoaderFactory.java +++ b/client-compiler/src/com/vaadin/server/widgetsetutils/ConnectorBundleLoaderFactory.java @@ -27,6 +27,7 @@ import java.util.List; import java.util.Map; import java.util.Map.Entry; import java.util.Set; +import java.util.TreeMap; import com.google.gwt.core.client.GWT; import com.google.gwt.core.client.RunAsyncCallback; @@ -1185,10 +1186,11 @@ public class ConnectorBundleLoaderFactory extends Generator { JClassType[] types = serverConnectorType.getSubtypes(); - Map mappings = new HashMap(); + Map mappings = new TreeMap(); // Keep track of what has happened to avoid logging intermediate state - Map> replaced = new HashMap>(); + Map> replaced = new TreeMap>( + ConnectorBundle.jClassComparator); for (JClassType type : types) { Connect connectAnnotation = type.getAnnotation(Connect.class); 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 fedc86fbf6..b4531eb08e 100644 --- a/client-compiler/src/com/vaadin/server/widgetsetutils/metadata/ConnectorBundle.java +++ b/client-compiler/src/com/vaadin/server/widgetsetutils/metadata/ConnectorBundle.java @@ -19,12 +19,16 @@ import java.io.Serializable; 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.Iterator; +import java.util.LinkedHashSet; import java.util.List; import java.util.Map; import java.util.Set; +import java.util.TreeMap; +import java.util.TreeSet; import com.google.gwt.core.ext.TreeLogger; import com.google.gwt.core.ext.TreeLogger.Type; @@ -37,7 +41,6 @@ import com.google.gwt.core.ext.typeinfo.JParameterizedType; 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.thirdparty.guava.common.collect.Sets; import com.vaadin.client.ApplicationConnection; import com.vaadin.client.ComponentConnector; import com.vaadin.client.ServerConnector; @@ -54,6 +57,22 @@ import elemental.json.JsonValue; public class ConnectorBundle { private static final String FAIL_IF_NOT_SERIALIZABLE = "vFailIfNotSerializable"; + public static final Comparator jClassComparator = new Comparator() { + @Override + public int compare(JClassType o1, JClassType o2) { + return o1.getQualifiedSourceName().compareTo( + o2.getQualifiedSourceName()); + } + }; + + public static final Comparator jMethodComparator = new Comparator() { + @Override + public int compare(JMethod o1, JMethod o2) { + return o1.getReadableDeclaration().compareTo( + o2.getReadableDeclaration()); + } + }; + private final String name; private final ConnectorBundle previousBundle; private final Collection visitors; @@ -61,24 +80,42 @@ public class ConnectorBundle { private final Set hasSerializeSupport = new HashSet(); private final Set needsSerializeSupport = new HashSet(); - private final Map serializers = new HashMap(); - private final Map presentationTypes = new HashMap(); - private final Set needsSuperClass = new HashSet(); - private final Set needsGwtConstructor = new HashSet(); + private final Map serializers = new TreeMap( + new Comparator() { + @Override + public int compare(JType o1, JType o2) { + return o1.toString().compareTo(o2.toString()); + } + }); + + private final Map>> methodAttributes = new TreeMap>>( + jClassComparator); + private final Set needsSuperClass = new TreeSet( + jClassComparator); + private final Set needsGwtConstructor = new TreeSet( + jClassComparator); private final Set visitedTypes = new HashSet(); - private final Set needsProxySupport = new HashSet(); - private final Map> identifiers = new HashMap>(); - private final Map> needsReturnType = new HashMap>(); - private final Map> needsInvoker = new HashMap>(); - private final Map> needsParamTypes = new HashMap>(); - private final Map> needsOnStateChange = new HashMap>(); - - private final Map>> methodAttributes = new HashMap>>(); - - private final Set needsProperty = new HashSet(); - private final Map> needsDelegateToWidget = new HashMap>(); + private final Set needsProxySupport = new TreeSet( + jClassComparator); + + private final Map presentationTypes = new TreeMap( + jClassComparator); + private final Map> identifiers = new TreeMap>( + jClassComparator); + private final Map> needsReturnType = new TreeMap>( + jClassComparator); + private final Map> needsInvoker = new TreeMap>( + jClassComparator); + private final Map> needsParamTypes = new TreeMap>( + jClassComparator); + private final Map> needsOnStateChange = new TreeMap>( + jClassComparator); + + private final Set needsProperty = new TreeSet(); + private final Map> needsDelegateToWidget = new TreeMap>( + jClassComparator); private ConnectorBundle(String name, ConnectorBundle previousBundle, Collection visitors, @@ -369,7 +406,7 @@ public class ConnectorBundle { } public Collection getProperties(JClassType type) { - HashSet properties = new HashSet(); + Set properties = new TreeSet(); properties.addAll(MethodProperty.findProperties(type)); properties.addAll(FieldProperty.findProperties(type)); @@ -463,10 +500,19 @@ public class ConnectorBundle { } } - private void addMapping(Map> map, K key, V value) { - Set set = map.get(key); + private void addMapping(Map> map, K key, String value) { + Set set = map.get(key); + if (set == null) { + set = new TreeSet(); + map.put(key, set); + } + set.add(value); + } + + private void addMapping(Map> map, K key, JMethod value) { + Set set = map.get(key); if (set == null) { - set = new HashSet(); + set = new TreeSet(jMethodComparator); map.put(key, set); } set.add(value); @@ -533,11 +579,26 @@ public class ConnectorBundle { Map> typeData = methodAttributes .get(type); if (typeData == null) { - typeData = new HashMap>(); + typeData = new TreeMap>( + jMethodComparator); methodAttributes.put(type, typeData); } - addMapping(typeData, method, methodAttribute); + Map> methods = methodAttributes + .get(type); + if (methods == null) { + methods = new TreeMap>( + jMethodComparator); + methodAttributes.put(type, methods); + } + + Set attributes = methods.get(method); + if (attributes == null) { + attributes = new TreeSet(); + methods.put(method, attributes); + } + + attributes.add(methodAttribute); } } @@ -564,7 +625,7 @@ public class ConnectorBundle { } } - private static Set> frameworkHandledTypes = new HashSet>(); + private static Set> frameworkHandledTypes = new LinkedHashSet>(); { frameworkHandledTypes.add(String.class); frameworkHandledTypes.add(Boolean.class); @@ -611,7 +672,9 @@ public class ConnectorBundle { public void setNeedsDelegateToWidget(Property property, JClassType type) { if (!isNeedsDelegateToWidget(type)) { - needsDelegateToWidget.put(type, Sets.newHashSet(property)); + TreeSet set = new TreeSet(); + set.add(property); + needsDelegateToWidget.put(type, set); } else if (!needsDelegateToWidget.get(type).contains(property)) { needsDelegateToWidget.get(type).add(property); } 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 f07b1c29fd..0c849bead5 100644 --- a/client-compiler/src/com/vaadin/server/widgetsetutils/metadata/Property.java +++ b/client-compiler/src/com/vaadin/server/widgetsetutils/metadata/Property.java @@ -24,7 +24,7 @@ import com.google.gwt.core.ext.typeinfo.JPrimitiveType; import com.google.gwt.core.ext.typeinfo.JType; import com.google.gwt.user.rebind.SourceWriter; -public abstract class Property { +public abstract class Property implements Comparable { private final String name; private final JClassType beanType; private final JType propertyType; @@ -107,6 +107,20 @@ public abstract class Property { + getName().hashCode(); } + @Override + public int compareTo(Property o) { + int comp = getName().compareTo(o.getName()); + if (comp == 0) { + comp = getBeanType().getQualifiedSourceName().compareTo( + o.getBeanType().getQualifiedSourceName()); + } + if (comp == 0) { + comp = getClass().getCanonicalName().compareTo( + o.getClass().getCanonicalName()); + } + return comp; + } + public abstract T getAnnotation( Class annotationClass); -- cgit v1.2.3