From e911c27a5ddce1050978ea191082a4065b7a228d Mon Sep 17 00:00:00 2001 From: Hannes Wellmann Date: Thu, 4 Apr 2024 20:02:13 +0200 Subject: [PATCH] Replace usage of Maps.newHashMapWithExpectedSize() with standard Java Part of https://github.com/eclipse/xtext/issues/2975 --- .../builder/clustering/CopiedResourceDescription.java | 4 ++-- .../xtext/ecore/EcoreResourceDescriptionStrategy.java | 4 +--- .../serializer/impl/EObjectDescriptionProvider.java | 4 ++-- .../ecore/EcoreResourceDescriptionStrategy.java | 4 +--- .../xtext/ui/editor/StatefulResourceDescription.java | 4 ++-- .../xtext/generator/XtextGeneratorTemplates.xtend | 6 +++--- .../xtext/xtext/generator/XtextGeneratorTemplates.java | 10 ++++------ .../xtext/generator/trace/AbstractTraceRegion.java | 4 ++-- .../src/org/eclipse/xtext/resource/SaveOptions.java | 5 ++--- 9 files changed, 19 insertions(+), 26 deletions(-) diff --git a/org.eclipse.xtext.builder/src/org/eclipse/xtext/builder/clustering/CopiedResourceDescription.java b/org.eclipse.xtext.builder/src/org/eclipse/xtext/builder/clustering/CopiedResourceDescription.java index 674149d60fb..2f8669c8be3 100644 --- a/org.eclipse.xtext.builder/src/org/eclipse/xtext/builder/clustering/CopiedResourceDescription.java +++ b/org.eclipse.xtext.builder/src/org/eclipse/xtext/builder/clustering/CopiedResourceDescription.java @@ -9,6 +9,7 @@ package org.eclipse.xtext.builder.clustering; import java.util.Collections; +import java.util.HashMap; import java.util.List; import java.util.Map; @@ -26,7 +27,6 @@ import com.google.common.base.Function; import com.google.common.collect.ImmutableList; import com.google.common.collect.Iterables; -import com.google.common.collect.Maps; /** * Makes an eager copy of the exported objects of another resource description. @@ -56,7 +56,7 @@ public IEObjectDescription apply(IEObjectDescription from) { Map userData = null; for (final String key : from.getUserDataKeys()) { if (userData == null) { - userData = Maps.newHashMapWithExpectedSize(2); + userData = new HashMap<>(3); } userData.put(key, from.getUserData(key)); } diff --git a/org.eclipse.xtext.ecore/src/org/eclipse/xtext/ecore/EcoreResourceDescriptionStrategy.java b/org.eclipse.xtext.ecore/src/org/eclipse/xtext/ecore/EcoreResourceDescriptionStrategy.java index 1b90273643d..a1271033950 100644 --- a/org.eclipse.xtext.ecore/src/org/eclipse/xtext/ecore/EcoreResourceDescriptionStrategy.java +++ b/org.eclipse.xtext.ecore/src/org/eclipse/xtext/ecore/EcoreResourceDescriptionStrategy.java @@ -19,7 +19,6 @@ import org.eclipse.xtext.resource.impl.DefaultResourceDescriptionStrategy; import org.eclipse.xtext.util.IAcceptor; -import com.google.common.collect.Maps; import com.google.inject.Inject; import com.google.inject.Singleton; @@ -48,8 +47,7 @@ protected boolean createEObjectDescriptions(IQualifiedNameProvider qualifiedName try { QualifiedName qualifiedName = qualifiedNameProvider.getFullyQualifiedName(eObject); if (qualifiedName != null) { - Map userData = Maps.newHashMapWithExpectedSize(1); - userData.put(NS_URI_INDEX_ENTRY, Boolean.toString(isNsURI)); + Map userData = Map.of(NS_URI_INDEX_ENTRY, Boolean.toString(isNsURI)); IEObjectDescription description = EObjectDescription.create(qualifiedName, eObject, userData); acceptor.accept(description); return true; diff --git a/org.eclipse.xtext.ide/src/org/eclipse/xtext/ide/serializer/impl/EObjectDescriptionProvider.java b/org.eclipse.xtext.ide/src/org/eclipse/xtext/ide/serializer/impl/EObjectDescriptionProvider.java index d55cdccbb41..6dab3dbffe0 100644 --- a/org.eclipse.xtext.ide/src/org/eclipse/xtext/ide/serializer/impl/EObjectDescriptionProvider.java +++ b/org.eclipse.xtext.ide/src/org/eclipse/xtext/ide/serializer/impl/EObjectDescriptionProvider.java @@ -9,6 +9,7 @@ package org.eclipse.xtext.ide.serializer.impl; import java.util.Collection; +import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Map.Entry; @@ -31,7 +32,6 @@ import com.google.common.base.Preconditions; import com.google.common.collect.HashMultimap; import com.google.common.collect.Lists; -import com.google.common.collect.Maps; import com.google.common.collect.Multimap; import com.google.inject.Inject; @@ -59,7 +59,7 @@ public SimpleNameDescription(QualifiedName qName, EObject resolvedObject, IEObje Map userData = null; for (final String key : source.getUserDataKeys()) { if (userData == null) { - userData = Maps.newHashMapWithExpectedSize(2); + userData = new HashMap<>(3); } userData.put(key, source.getUserData(key)); } diff --git a/org.eclipse.xtext.testlanguages/src/org/eclipse/xtext/testlanguages/ecore/EcoreResourceDescriptionStrategy.java b/org.eclipse.xtext.testlanguages/src/org/eclipse/xtext/testlanguages/ecore/EcoreResourceDescriptionStrategy.java index 2f988956c60..0043750c587 100644 --- a/org.eclipse.xtext.testlanguages/src/org/eclipse/xtext/testlanguages/ecore/EcoreResourceDescriptionStrategy.java +++ b/org.eclipse.xtext.testlanguages/src/org/eclipse/xtext/testlanguages/ecore/EcoreResourceDescriptionStrategy.java @@ -19,7 +19,6 @@ import org.eclipse.xtext.resource.impl.DefaultResourceDescriptionStrategy; import org.eclipse.xtext.util.IAcceptor; -import com.google.common.collect.Maps; import com.google.inject.Inject; import com.google.inject.Singleton; @@ -48,8 +47,7 @@ protected boolean createEObjectDescriptions(IQualifiedNameProvider qualifiedName try { QualifiedName qualifiedName = qualifiedNameProvider.getFullyQualifiedName(eObject); if (qualifiedName != null) { - Map userData = Maps.newHashMapWithExpectedSize(1); - userData.put(NS_URI_INDEX_ENTRY, Boolean.toString(isNsURI)); + Map userData = Map.of(NS_URI_INDEX_ENTRY, Boolean.toString(isNsURI)); IEObjectDescription description = EObjectDescription.create(qualifiedName, eObject, userData); acceptor.accept(description); return true; diff --git a/org.eclipse.xtext.ui/src/org/eclipse/xtext/ui/editor/StatefulResourceDescription.java b/org.eclipse.xtext.ui/src/org/eclipse/xtext/ui/editor/StatefulResourceDescription.java index ae6beed5522..8a19bedeec8 100644 --- a/org.eclipse.xtext.ui/src/org/eclipse/xtext/ui/editor/StatefulResourceDescription.java +++ b/org.eclipse.xtext.ui/src/org/eclipse/xtext/ui/editor/StatefulResourceDescription.java @@ -9,6 +9,7 @@ package org.eclipse.xtext.ui.editor; import java.util.Collections; +import java.util.HashMap; import java.util.List; import java.util.Map; @@ -27,7 +28,6 @@ import com.google.common.base.Predicates; import com.google.common.collect.ImmutableList; import com.google.common.collect.Iterables; -import com.google.common.collect.Maps; import com.google.inject.Provider; /** @@ -61,7 +61,7 @@ public IEObjectDescription apply(IEObjectDescription from) { Map userData = null; for(String key: from.getUserDataKeys()) { if (userData == null) { - userData = Maps.newHashMapWithExpectedSize(2); + userData = new HashMap<>(3); } userData.put(key, from.getUserData(key)); } diff --git a/org.eclipse.xtext.xtext.generator/src/org/eclipse/xtext/xtext/generator/XtextGeneratorTemplates.xtend b/org.eclipse.xtext.xtext.generator/src/org/eclipse/xtext/xtext/generator/XtextGeneratorTemplates.xtend index e889b9a02e6..8633f0d80da 100644 --- a/org.eclipse.xtext.xtext.generator/src/org/eclipse/xtext/xtext/generator/XtextGeneratorTemplates.xtend +++ b/org.eclipse.xtext.xtext.generator/src/org/eclipse/xtext/xtext/generator/XtextGeneratorTemplates.xtend @@ -8,7 +8,6 @@ *******************************************************************************/ package org.eclipse.xtext.xtext.generator -import com.google.common.collect.Maps import com.google.inject.Binder import com.google.inject.Guice import com.google.inject.Inject @@ -18,6 +17,7 @@ import com.google.inject.Provider import com.google.inject.Singleton import com.google.inject.name.Names import java.util.Collections +import java.util.HashMap import java.util.List import java.util.Map import java.util.Properties @@ -36,12 +36,12 @@ import org.eclipse.xtext.xtext.generator.model.FileAccessFactory import org.eclipse.xtext.xtext.generator.model.GeneratedJavaFileAccess import org.eclipse.xtext.xtext.generator.model.GuiceModuleAccess import org.eclipse.xtext.xtext.generator.model.JavaFileAccess +import org.eclipse.xtext.xtext.generator.model.TextFileAccess import org.eclipse.xtext.xtext.generator.model.TypeReference import org.eclipse.xtext.xtext.generator.model.annotations.SuppressWarningsAnnotation import org.eclipse.xtext.xtext.generator.model.project.IXtextProjectConfig import static extension org.eclipse.xtext.xtext.generator.model.TypeReference.* -import org.eclipse.xtext.xtext.generator.model.TextFileAccess /** * Templates for generating the common language infrastructure. @@ -505,7 +505,7 @@ class XtextGeneratorTemplates { private static «activator.simpleName» INSTANCE; - private «Map» injectors = «Collections».synchronizedMap(«Maps». newHashMapWithExpectedSize(1)); + private «Map» injectors = «Collections».synchronizedMap(new «HashMap»<>(2)); @Override public void start(«'org.osgi.framework.BundleContext'.typeRef» context) throws Exception { diff --git a/org.eclipse.xtext.xtext.generator/xtend-gen/org/eclipse/xtext/xtext/generator/XtextGeneratorTemplates.java b/org.eclipse.xtext.xtext.generator/xtend-gen/org/eclipse/xtext/xtext/generator/XtextGeneratorTemplates.java index f2c5b46d9e5..3d4dd49eb0c 100644 --- a/org.eclipse.xtext.xtext.generator/xtend-gen/org/eclipse/xtext/xtext/generator/XtextGeneratorTemplates.java +++ b/org.eclipse.xtext.xtext.generator/xtend-gen/org/eclipse/xtext/xtext/generator/XtextGeneratorTemplates.java @@ -8,7 +8,6 @@ */ package org.eclipse.xtext.xtext.generator; -import com.google.common.collect.Maps; import com.google.inject.Binder; import com.google.inject.Guice; import com.google.inject.Inject; @@ -17,6 +16,7 @@ import com.google.inject.Singleton; import com.google.inject.name.Names; import java.util.Collections; +import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Properties; @@ -1526,11 +1526,9 @@ protected void appendTo(StringConcatenationClient.TargetStringConcatenation _bui _builder.append(Injector.class, "\t"); _builder.append("> injectors = "); _builder.append(Collections.class, "\t"); - _builder.append(".synchronizedMap("); - _builder.append(Maps.class, "\t"); - _builder.append(". newHashMapWithExpectedSize(1));"); + _builder.append(".synchronizedMap(new "); + _builder.append(HashMap.class, "\t"); + _builder.append("<>(2));"); _builder.newLineIfNotEmpty(); _builder.append("\t"); _builder.newLine(); diff --git a/org.eclipse.xtext/src/org/eclipse/xtext/generator/trace/AbstractTraceRegion.java b/org.eclipse.xtext/src/org/eclipse/xtext/generator/trace/AbstractTraceRegion.java index fb391f1dad1..8b82a6281ec 100644 --- a/org.eclipse.xtext/src/org/eclipse/xtext/generator/trace/AbstractTraceRegion.java +++ b/org.eclipse.xtext/src/org/eclipse/xtext/generator/trace/AbstractTraceRegion.java @@ -10,6 +10,7 @@ import java.util.Collections; import java.util.Comparator; +import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Map; @@ -132,8 +133,7 @@ public Map> invertAll(SourceRelativ protected Map>> collectMatchingLocations( SourceRelativeURI expectedAssociatedPath) { - Map>> result = Maps - .newHashMapWithExpectedSize(2); + Map>> result = new HashMap<>(3); Iterator treeIterator = treeIterator(); while (treeIterator.hasNext()) { AbstractTraceRegion next = treeIterator.next(); diff --git a/org.eclipse.xtext/src/org/eclipse/xtext/resource/SaveOptions.java b/org.eclipse.xtext/src/org/eclipse/xtext/resource/SaveOptions.java index 1da8d8590b5..4eaaf962b54 100644 --- a/org.eclipse.xtext/src/org/eclipse/xtext/resource/SaveOptions.java +++ b/org.eclipse.xtext/src/org/eclipse/xtext/resource/SaveOptions.java @@ -8,10 +8,9 @@ *******************************************************************************/ package org.eclipse.xtext.resource; +import java.util.HashMap; import java.util.Map; -import com.google.common.collect.Maps; - /** * Immutable SaveOptions can be used to read and write options into the * map that is passed into {@link org.eclipse.emf.ecore.resource.Resource#save(Map)}. @@ -70,7 +69,7 @@ public void addTo(Map saveOptions) { } public Map toOptionsMap() { - Map result = Maps.newHashMapWithExpectedSize(2); + Map result = new HashMap<>(3); addTo(result); return result; }