From a126d433f25a4bf5fd3de22db142341d8afadd7b Mon Sep 17 00:00:00 2001 From: Hannes Wellmann Date: Sun, 14 Apr 2024 11:50:10 +0200 Subject: [PATCH] Replace Guava's ImmutableMap in XtextAntlrGeneratorFragment2 Part of https://github.com/eclipse/xtext/issues/2975 --- .../antlr/XtextAntlrGeneratorFragment2.xtend | 22 ++++++------- .../antlr/XtextAntlrGeneratorFragment2.java | 31 +++++++++---------- 2 files changed, 25 insertions(+), 28 deletions(-) diff --git a/org.eclipse.xtext.xtext.generator/src/org/eclipse/xtext/xtext/generator/parser/antlr/XtextAntlrGeneratorFragment2.xtend b/org.eclipse.xtext.xtext.generator/src/org/eclipse/xtext/xtext/generator/parser/antlr/XtextAntlrGeneratorFragment2.xtend index b6f76a0832e..b7650d97652 100644 --- a/org.eclipse.xtext.xtext.generator/src/org/eclipse/xtext/xtext/generator/parser/antlr/XtextAntlrGeneratorFragment2.xtend +++ b/org.eclipse.xtext.xtext.generator/src/org/eclipse/xtext/xtext/generator/parser/antlr/XtextAntlrGeneratorFragment2.xtend @@ -8,12 +8,12 @@ *******************************************************************************/ package org.eclipse.xtext.xtext.generator.parser.antlr -import com.google.common.collect.ImmutableMap import com.google.common.collect.Lists import com.google.inject.Inject import com.google.inject.Singleton import com.google.inject.name.Names import java.io.InputStream +import java.util.HashMap import java.util.List import java.util.Map import java.util.Set @@ -390,31 +390,31 @@ class XtextAntlrGeneratorFragment2 extends AbstractAntlrGeneratorFragment2 { ''' @«Singleton» public static final class NameMappings { - + «IF partitions.size > 1» «FOR partition : partitions.indexed» private static final class Init«partition.key» { - private static void doInit(«ImmutableMap».Builder<«AbstractElement», «String»> builder, «grammar.grammarAccess» grammarAccess) { + private static void doInit(«Map»<«AbstractElement», «String»> builder, «grammar.grammarAccess» grammarAccess) { «partition.value.initNameMappings» } } - + «ENDFOR» «ENDIF» private final «Map»<«AbstractElement», «String»> mappings; - + @«Inject» public NameMappings(«grammar.grammarAccess» grammarAccess) { - «ImmutableMap».Builder<«AbstractElement», «String»> builder = «ImmutableMap».builder(); + «Map»<«AbstractElement», «String»> builder = new «HashMap»<>(); init(builder, grammarAccess); - this.mappings = builder.build(); + this.mappings = «Map».copyOf(builder); } - + public «String» getRuleName(«AbstractElement» element) { return mappings.get(element); } - - private static void init(«ImmutableMap».Builder<«AbstractElement», «String»> builder, «grammar.grammarAccess» grammarAccess) { + + private static void init(«Map»<«AbstractElement», «String»> builder, «grammar.grammarAccess» grammarAccess) { «IF partitions.size > 1» «FOR partition : partitions.indexed» Init«partition.key».doInit(builder, grammarAccess); @@ -426,7 +426,7 @@ class XtextAntlrGeneratorFragment2 extends AbstractAntlrGeneratorFragment2 { «ENDIF» } } - + @«Inject» private NameMappings nameMappings; ''' diff --git a/org.eclipse.xtext.xtext.generator/xtend-gen/org/eclipse/xtext/xtext/generator/parser/antlr/XtextAntlrGeneratorFragment2.java b/org.eclipse.xtext.xtext.generator/xtend-gen/org/eclipse/xtext/xtext/generator/parser/antlr/XtextAntlrGeneratorFragment2.java index 7c4291bb1b8..f6de8740889 100644 --- a/org.eclipse.xtext.xtext.generator/xtend-gen/org/eclipse/xtext/xtext/generator/parser/antlr/XtextAntlrGeneratorFragment2.java +++ b/org.eclipse.xtext.xtext.generator/xtend-gen/org/eclipse/xtext/xtext/generator/parser/antlr/XtextAntlrGeneratorFragment2.java @@ -9,7 +9,6 @@ package org.eclipse.xtext.xtext.generator.parser.antlr; import com.google.common.base.Objects; -import com.google.common.collect.ImmutableMap; import com.google.common.collect.Iterables; import com.google.common.collect.Lists; import com.google.inject.Inject; @@ -19,6 +18,7 @@ import java.util.ArrayList; import java.util.Collection; import java.util.Collections; +import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Set; @@ -894,7 +894,6 @@ protected void appendTo(StringConcatenationClient.TargetStringConcatenation _bui _builder.newLineIfNotEmpty(); _builder.append("public static final class NameMappings {"); _builder.newLine(); - _builder.append("\t"); _builder.newLine(); { int _size = partitions.size(); @@ -912,8 +911,8 @@ protected void appendTo(StringConcatenationClient.TargetStringConcatenation _bui _builder.append("\t"); _builder.append("\t"); _builder.append("private static void doInit("); - _builder.append(ImmutableMap.class, "\t\t"); - _builder.append(".Builder<"); + _builder.append(Map.class, "\t\t"); + _builder.append("<"); _builder.append(AbstractElement.class, "\t\t"); _builder.append(", "); _builder.append(String.class, "\t\t"); @@ -934,7 +933,6 @@ protected void appendTo(StringConcatenationClient.TargetStringConcatenation _bui _builder.append("\t"); _builder.append("}"); _builder.newLine(); - _builder.append("\t"); _builder.newLine(); } } @@ -949,7 +947,6 @@ protected void appendTo(StringConcatenationClient.TargetStringConcatenation _bui _builder.append(String.class, "\t"); _builder.append("> mappings;"); _builder.newLineIfNotEmpty(); - _builder.append("\t"); _builder.newLine(); _builder.append("\t"); _builder.append("@"); @@ -962,25 +959,26 @@ protected void appendTo(StringConcatenationClient.TargetStringConcatenation _bui _builder.append(" grammarAccess) {"); _builder.newLineIfNotEmpty(); _builder.append("\t\t"); - _builder.append(ImmutableMap.class, "\t\t"); - _builder.append(".Builder<"); + _builder.append(Map.class, "\t\t"); + _builder.append("<"); _builder.append(AbstractElement.class, "\t\t"); _builder.append(", "); _builder.append(String.class, "\t\t"); - _builder.append("> builder = "); - _builder.append(ImmutableMap.class, "\t\t"); - _builder.append(".builder();"); + _builder.append("> builder = new "); + _builder.append(HashMap.class, "\t\t"); + _builder.append("<>();"); _builder.newLineIfNotEmpty(); _builder.append("\t\t"); _builder.append("init(builder, grammarAccess);"); _builder.newLine(); _builder.append("\t\t"); - _builder.append("this.mappings = builder.build();"); - _builder.newLine(); + _builder.append("this.mappings = "); + _builder.append(Map.class, "\t\t"); + _builder.append(".copyOf(builder);"); + _builder.newLineIfNotEmpty(); _builder.append("\t"); _builder.append("}"); _builder.newLine(); - _builder.append("\t"); _builder.newLine(); _builder.append("\t"); _builder.append("public "); @@ -995,12 +993,11 @@ protected void appendTo(StringConcatenationClient.TargetStringConcatenation _bui _builder.append("\t"); _builder.append("}"); _builder.newLine(); - _builder.append("\t"); _builder.newLine(); _builder.append("\t"); _builder.append("private static void init("); - _builder.append(ImmutableMap.class, "\t"); - _builder.append(".Builder<"); + _builder.append(Map.class, "\t"); + _builder.append("<"); _builder.append(AbstractElement.class, "\t"); _builder.append(", "); _builder.append(String.class, "\t");