Skip to content

Commit

Permalink
Merge pull request antlr#2299 from dhalperi/streamline-java-statics
Browse files Browse the repository at this point in the history
Java.stg: use static functions instead of inline arrays
  • Loading branch information
parrt authored Jun 2, 2018
2 parents 8005cfd + 2a6a107 commit 61acb35
Showing 1 changed file with 24 additions and 12 deletions.
36 changes: 24 additions & 12 deletions tool/resources/org/antlr/v4/tool/templates/codegen/Java/Java.stg
Original file line number Diff line number Diff line change
Expand Up @@ -236,9 +236,12 @@ public class <parser.name> extends <superClass; null="Parser"> {
<endif>
public static final int
<parser.rules:{r | RULE_<r.name> = <r.index>}; separator=", ", wrap, anchor>;
public static final String[] ruleNames = {
<parser.ruleNames:{r | "<r>"}; separator=", ", wrap, anchor>
};
private static String[] makeRuleNames() {
return new String[] {
<parser.ruleNames:{r | "<r>"}; separator=", ", wrap, anchor>
};
}
public static final String[] ruleNames = makeRuleNames();

<vocabulary(parser.literalNames, parser.symbolicNames)>

Expand Down Expand Up @@ -275,12 +278,18 @@ case <f.ruleIndex>:
>>

vocabulary(literalNames, symbolicNames) ::= <<
private static final String[] _LITERAL_NAMES = {
<literalNames:{t | <t>}; null="null", separator=", ", wrap, anchor>
};
private static final String[] _SYMBOLIC_NAMES = {
<symbolicNames:{t | <t>}; null="null", separator=", ", wrap, anchor>
};
private static String[] makeLiteralNames() {
return new String[] {
<literalNames:{t | <t>}; null="null", separator=", ", wrap, anchor>
};
}
private static final String[] _LITERAL_NAMES = makeLiteralNames();
private static String[] makeSymbolicNames() {
return new String[] {
<symbolicNames:{t | <t>}; null="null", separator=", ", wrap, anchor>
};
}
private static final String[] _SYMBOLIC_NAMES = makeSymbolicNames();
public static final Vocabulary VOCABULARY = new VocabularyImpl(_LITERAL_NAMES, _SYMBOLIC_NAMES);

/**
Expand Down Expand Up @@ -914,9 +923,12 @@ public class <lexer.name> extends <superClass; null="Lexer"> {
<lexer.modes:{m| "<m>"}; separator=", ", wrap, anchor>
};

public static final String[] ruleNames = {
<lexer.ruleNames:{r | "<r>"}; separator=", ", wrap, anchor>
};
private static String[] makeRuleNames() {
return new String[] {
<lexer.ruleNames:{r | "<r>"}; separator=", ", wrap, anchor>
};
}
public static final String[] ruleNames = makeRuleNames();

<vocabulary(lexer.literalNames, lexer.symbolicNames)>

Expand Down

0 comments on commit 61acb35

Please sign in to comment.