Class AntlrNameDictionary
java.lang.Object
net.sourceforge.pmd.lang.ast.impl.antlr4.AntlrNameDictionary
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
ConstructorsConstructorDescriptionAntlrNameDictionary(org.antlr.v4.runtime.Vocabulary vocab, String[] ruleNames) -
Method Summary
Modifier and TypeMethodDescription@Nullable StringgetConstantImageOfToken(org.antlr.v4.runtime.Token token) Returns the constant image of the given token (a shared string), or null if the token has none.intintorg.antlr.v4.runtime.Vocabulary@NonNull StringgetXPathNameOfRule(int idx) Gets the xpath name of an inner node with a givenRuleContext.getRuleIndex().@NonNull StringgetXPathNameOfToken(int tokenType) Gets the xpath name of a terminal node with a givenToken.getType().protected @Nullable StringnonAlphaNumName(String name) Override this to customize the XPath name of tokes with no symbolic name and with an image that is non-alphanumeric.
-
Constructor Details
-
AntlrNameDictionary
-
-
Method Details
-
getVocabulary
public org.antlr.v4.runtime.Vocabulary getVocabulary() -
nonAlphaNumName
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
Gets the xpath name of a terminal node with a givenToken.getType().- Throws:
IllegalArgumentException- If the index is invalid
-
getConstantImageOfToken
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
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()
-