Class AntlrNameDictionary
- java.lang.Object
-
- net.sourceforge.pmd.lang.ast.impl.antlr4.AntlrNameDictionary
-
public class AntlrNameDictionary extends Object
Stores the XPath name of antlr terminals. I found no simple way to give names to punctuation (we could add a lexer rule, but it may conflict with other tokens). So their names are hardcoded here.Terminal names start with
"T-"
in XPath to avoid conflicts with other stuff.
-
-
Constructor Summary
Constructors Constructor Description AntlrNameDictionary(org.antlr.v4.runtime.Vocabulary vocab, String[] ruleNames)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description @Nullable String
getConstantImageOfToken(org.antlr.v4.runtime.Token token)
Returns the constant image of the given token (a shared string), or null if the token has none.int
getMaxRuleIndex()
int
getMaxTokenType()
org.antlr.v4.runtime.Vocabulary
getVocabulary()
@NonNull String
getXPathNameOfRule(int idx)
Gets the xpath name of an inner node with a givenRuleContext.getRuleIndex()
.@NonNull String
getXPathNameOfToken(int tokenType)
Gets the xpath name of a terminal node with a givenToken.getType()
.protected @Nullable String
nonAlphaNumName(String name)
Override this to customize the XPath name of tokes with no symbolic name and with an image that is non-alphanumeric.
-
-
-
Constructor Detail
-
AntlrNameDictionary
public AntlrNameDictionary(org.antlr.v4.runtime.Vocabulary vocab, String[] ruleNames)
-
-
Method Detail
-
getVocabulary
public org.antlr.v4.runtime.Vocabulary getVocabulary()
-
nonAlphaNumName
protected @Nullable String nonAlphaNumName(String name)
Override this to customize the XPath name of tokes with no symbolic name and with an image that is non-alphanumeric. Return null to give up. The default just gives some name to common punctuation. Remember that the same token may mean several things in different contexts, so eg using"not"
as the name of"!"
is too specific.
-
getXPathNameOfToken
public @NonNull String getXPathNameOfToken(int tokenType)
Gets the xpath name of a terminal node with a givenToken.getType()
.- Throws:
IllegalArgumentException
- If the index is invalid
-
getConstantImageOfToken
public @Nullable String getConstantImageOfToken(org.antlr.v4.runtime.Token token)
Returns the constant image of the given token (a shared string), or null if the token has none. This is a memory optimization to avoid creating a new string for tokens with constant images. Antlr does not do this by itself sadly.
-
getXPathNameOfRule
public @NonNull String getXPathNameOfRule(int idx)
Gets the xpath name of an inner node with a givenRuleContext.getRuleIndex()
.- Throws:
IndexOutOfBoundsException
- If the index is invalid
-
getMaxRuleIndex
public int getMaxRuleIndex()
-
getMaxTokenType
public int getMaxTokenType()
-
-