Class JavaccTokenDocument.TokenDocumentBehavior
- java.lang.Object
-
- net.sourceforge.pmd.lang.ast.impl.javacc.JavaccTokenDocument.TokenDocumentBehavior
-
- Enclosing class:
- JavaccTokenDocument
public static class JavaccTokenDocument.TokenDocumentBehavior extends Object
Overridable configuration of a token document.
-
-
Field Summary
Fields Modifier and Type Field Description static JavaccTokenDocument.TokenDocumentBehavior
DEFAULT
-
Constructor Summary
Constructors Constructor Description TokenDocumentBehavior(List<String> tokenNames)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description JavaccToken
createToken(JavaccTokenDocument self, int kind, CharStream cs, @Nullable String image)
Creates a new token with the given kind.@NonNull String
describeKind(int kind)
Returns a string that describes the token kind.protected @Nullable String
describeKindImpl(int kind)
Describe the given kind.TextDocument
translate(TextDocument text)
Translate the escapes of the source document.boolean
useMarkSuffix()
Returns true if the lexer should accumulate the image of MORE tokens into the StringBuilder jjimage.
-
-
-
Field Detail
-
DEFAULT
public static final JavaccTokenDocument.TokenDocumentBehavior DEFAULT
-
-
Method Detail
-
useMarkSuffix
public boolean useMarkSuffix()
Returns true if the lexer should accumulate the image of MORE tokens into the StringBuilder jjimage. This is useless in our current implementations, because the image of tokens can be cut out using text coordinates, so doesn't need to be put into a separate string. The default returns false, which makesCharStream.appendSuffix(StringBuilder, int)
a noop.
-
translate
public TextDocument translate(TextDocument text) throws MalformedSourceException
Translate the escapes of the source document. The default implementation does not perform any escaping.- Parameters:
text
- Source doc- Throws:
MalformedSourceException
- See Also:
TODO move that to LanguageVersionHandler once #3919 (Merge CPD and PMD language) is implemented
-
describeKind
public final @NonNull String describeKind(int kind)
Returns a string that describes the token kind.- Parameters:
kind
- Kind of token- Returns:
- A descriptive string
-
describeKindImpl
protected @Nullable String describeKindImpl(int kind)
Describe the given kind. If this returns a non-null value, then that's whatdescribeKind(int)
will use. Otherwise a default implementation is used.An implementation typically uses the JavaCC-generated array named
<parser name>Constants.tokenImage
. Remember to check the bounds of the array.- Parameters:
kind
- Kind of token- Returns:
- A descriptive string, or null to use default
-
createToken
public JavaccToken createToken(JavaccTokenDocument self, int kind, CharStream cs, @Nullable String image)
Creates a new token with the given kind. This is called back to by JavaCC-generated token managers (jjFillToken). Note that a created token is not guaranteed to end up in the final token chain.- Parameters:
kind
- Kind of the tokencs
- Char stream of the file. This can be used to get text coordinates and the imageimage
- Shared instance of the image token. If this is non-null, then no call toCharStream.getTokenImage()
should be issued.- Returns:
- A new token
-
-