Skip to content

Commit

Permalink
Replace Guava's ImmutableMap in XtextAntlrGeneratorFragment2
Browse files Browse the repository at this point in the history
  • Loading branch information
HannesWell committed Apr 14, 2024
1 parent 9e3b1b4 commit a126d43
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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».BuilderAbstractElement», «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».BuilderAbstractElement», «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».BuilderAbstractElement», «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);
Expand All @@ -426,7 +426,7 @@ class XtextAntlrGeneratorFragment2 extends AbstractAntlrGeneratorFragment2 {
«ENDIF»
}
}

Inject»
private NameMappings nameMappings;
'''
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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();
Expand All @@ -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");
Expand All @@ -934,7 +933,6 @@ protected void appendTo(StringConcatenationClient.TargetStringConcatenation _bui
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.append("\t");
_builder.newLine();
}
}
Expand All @@ -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("@");
Expand All @@ -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 ");
Expand All @@ -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");
Expand Down

0 comments on commit a126d43

Please sign in to comment.