Skip to content

Commit

Permalink
Replace Guava's ImmutableMap in XtextAntlrGeneratorFragment2
Browse files Browse the repository at this point in the history
Part of eclipse#2975
  • Loading branch information
HannesWell committed Apr 26, 2024
1 parent 8d53e99 commit 96f9df6
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 25 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 @@ -372,7 +372,7 @@ class XtextAntlrGeneratorFragment2 extends AbstractAntlrGeneratorFragment2 {
*/
protected def StringConcatenationClient initNameMappings(List<AbstractElement> partition) '''
«FOR element : partition»
builder.put(grammarAccesselement.originalElement.grammarElementAccess», "«element.originalElement.containingRule.contentAssistRuleName»__«element.originalElement.gaElementIdentifier»«IF element instanceof Group»__0«ENDIF»");
mappings.put(grammarAccesselement.originalElement.grammarElementAccess», "«element.originalElement.containingRule.contentAssistRuleName»__«element.originalElement.gaElementIdentifier»«IF element instanceof Group»__0«ENDIF»");
«ENDFOR»
'''
Expand All @@ -394,7 +394,7 @@ class XtextAntlrGeneratorFragment2 extends AbstractAntlrGeneratorFragment2 {
«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»> mappings, «grammar.grammarAccess» grammarAccess) {
«partition.value.initNameMappings»
}
}
Expand All @@ -405,19 +405,19 @@ class XtextAntlrGeneratorFragment2 extends AbstractAntlrGeneratorFragment2 {

Inject»
public NameMappings(«grammar.grammarAccess» grammarAccess) {
«ImmutableMap».BuilderAbstractElement», «String»> builder = «ImmutableMap».builder();
init(builder, grammarAccess);
this.mappings = builder.build();
«Map»<«AbstractElement», «String»> mappings = new «HashMap»<>();
init(mappings, grammarAccess);
this.mappings = «Map».copyOf(mappings);
}

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»> mappings, «grammar.grammarAccess» grammarAccess) {
«IF partitions.size > 1»
«FOR partition : partitions.indexed»
Init«partition.key».doInit(builder, grammarAccess);
Init«partition.key».doInit(mappings, grammarAccess);
«ENDFOR»
«ELSE»
«FOR partition : partitions»
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 @@ -841,7 +841,7 @@ protected StringConcatenationClient initNameMappings(final List<AbstractElement>
protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
{
for(final AbstractElement element : partition) {
_builder.append("builder.put(grammarAccess.");
_builder.append("mappings.put(grammarAccess.");
String _grammarElementAccess = XtextAntlrGeneratorFragment2.this.grammarUtil.grammarElementAccess(AntlrGrammarGenUtil.<AbstractElement>getOriginalElement(element));
_builder.append(_grammarElementAccess);
_builder.append(", \"");
Expand Down Expand Up @@ -912,12 +912,12 @@ 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");
_builder.append("> builder, ");
_builder.append("> mappings, ");
TypeReference _grammarAccess = XtextAntlrGeneratorFragment2.this.grammarUtil.getGrammarAccess(XtextAntlrGeneratorFragment2.this.getGrammar());
_builder.append(_grammarAccess, "\t\t");
_builder.append(" grammarAccess) {");
Expand Down Expand Up @@ -962,21 +962,23 @@ 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("> mappings = new ");
_builder.append(HashMap.class, "\t\t");
_builder.append("<>();");
_builder.newLineIfNotEmpty();
_builder.append("\t\t");
_builder.append("init(builder, grammarAccess);");
_builder.append("init(mappings, 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(mappings);");
_builder.newLineIfNotEmpty();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
Expand All @@ -999,12 +1001,12 @@ protected void appendTo(StringConcatenationClient.TargetStringConcatenation _bui
_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");
_builder.append("> builder, ");
_builder.append("> mappings, ");
TypeReference _grammarAccess_2 = XtextAntlrGeneratorFragment2.this.grammarUtil.getGrammarAccess(XtextAntlrGeneratorFragment2.this.getGrammar());
_builder.append(_grammarAccess_2, "\t");
_builder.append(" grammarAccess) {");
Expand All @@ -1020,7 +1022,7 @@ protected void appendTo(StringConcatenationClient.TargetStringConcatenation _bui
_builder.append("Init");
Integer _key_1 = partition_1.getKey();
_builder.append(_key_1, "\t\t");
_builder.append(".doInit(builder, grammarAccess);");
_builder.append(".doInit(mappings, grammarAccess);");
_builder.newLineIfNotEmpty();
}
}
Expand Down

0 comments on commit 96f9df6

Please sign in to comment.