Class CheckstyleApiFixer
- java.lang.Object
-
- com.thomasjensen.checkstyle.addons.util.CheckstyleApiFixer
-
public class CheckstyleApiFixer extends Object
The public API of the Checkstyle tool changes frequently, and many releases of Checkstyle are incompatible with their predecessors. This class uses reflection in order to allow the Checkstyle Addons code to work with all dependency configurations. It simply provides a stable interface with workarounds for all supported Checkstyle versions.
-
-
Constructor Summary
Constructors Constructor Description CheckstyleApiFixer(AbstractCheck pCheck)
Constructor.CheckstyleApiFixer(AbstractCheck pCheck, String pCurrentFileNameMockFile)
Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description File
getCurrentFileName()
Wrapper forFileContents.getFileName()
(Checkstyle issue #1205).String
getTokenName(int pTokenId)
Returns the name of a token for a given ID.boolean
isRootToken(int pToken)
Determine if the given token is the root token of Checkstyle's AST.
-
-
-
Constructor Detail
-
CheckstyleApiFixer
public CheckstyleApiFixer(@Nonnull AbstractCheck pCheck)
Constructor.- Parameters:
pCheck
- the check for which this instance of the API fixer shall run
-
CheckstyleApiFixer
public CheckstyleApiFixer(@Nonnull AbstractCheck pCheck, @Nullable String pCurrentFileNameMockFile)
Constructor.- Parameters:
pCheck
- the check for which this instance of the API fixer shall runpCurrentFileNameMockFile
- file to use as result ofgetCurrentFileName()
in unit tests
-
-
Method Detail
-
getCurrentFileName
@CheckForNull public File getCurrentFileName()
Wrapper forFileContents.getFileName()
(Checkstyle issue #1205).- Returns:
- the currently analyzed file as returned by Checkstyle
- Throws:
UnsupportedOperationException
- no known variant ofFileContents.getFileName()
could be found
-
getTokenName
@Nonnull public String getTokenName(int pTokenId)
Returns the name of a token for a given ID.- Parameters:
pTokenId
- the ID of the token name to get- Returns:
- a token name as returned by Checkstyle
- Throws:
UnsupportedOperationException
- no known variant ofgetTokenName()
could be found
-
isRootToken
public boolean isRootToken(int pToken)
Determine if the given token is the root token of Checkstyle's AST. This means it's either anEOF
token or aCOMPILATION_UNIT
token. This must be performed reflectively, because in Checkstyle 9.0, theEOF
token was replaced withCOMPILATION_UNIT
.- Parameters:
pToken
- the token to check- Returns:
- flag indicating root token
- Throws:
IllegalStateException
- TokenTypes class has neither anEOF
nor aCOMPILATION_UNIT
field
-
-