com.puppycrawl.tools.checkstyle.api
Class Utils
java.lang.Object
com.puppycrawl.tools.checkstyle.api.Utils
public final class Utils
extends java.lang.Object
Contains utility methods.
Version:
- Oliver Burn
static String | baseClassname(String aType)
|
static RE | createRE(String aPattern) - Helper method to create a regular expression.
|
static Log | getExceptionLogger() - Accessor for shared instance of logger which should be
used to log all exceptions occured during
FileSetCheck
work (debug() should be used).
|
static String[] | getLines(String aFileName) - Loads the contents of a file in a String array.
|
static String[] | getLines(String aFileName, String aCharsetName) - Loads the contents of a file in a String array using
the named charset.
|
static RE | getRE(String aPattern) - This is a factory method to return an RE object for the specified
regular expression.
|
static String | getStrippedFileName(String aBasedir, String aFileName) - Create a stripped down version of a filename.
|
static int | lengthExpandedTabs(String aString, int aToIdx, int aTabWidth) - Returns the length of a String prefix with tabs expanded.
|
static int | lengthMinusTrailingWhitespace(String aLine) - Returns the length of a string ignoring all trailing whitespace.
|
static boolean | whitespaceBefore(int aIndex, String aLine) - Returns whether the specified string contains only whitespace up to the
specified index.
|
baseClassname
public static String baseClassname(String aType)
aType
- the fully qualified name. Cannot be null
- the base class name from a fully qualified name
createRE
public static RE createRE(String aPattern)
throws ConversionException
Helper method to create a regular expression.
aPattern
- the pattern to match
- a created regexp object
getExceptionLogger
public static Log getExceptionLogger()
Accessor for shared instance of logger which should be
used to log all exceptions occured during FileSetCheck
work (debug()
should be used).
- shared exception logger.
getLines
public static String[] getLines(String aFileName)
throws IOException
Loads the contents of a file in a String array.
aFileName
- the name of the file to load
- the lines in the file
getLines
public static String[] getLines(String aFileName,
String aCharsetName)
throws IOException
Loads the contents of a file in a String array using
the named charset.
aFileName
- the name of the file to loadaCharsetName
- the name of a supported charset
- the lines in the file
getRE
public static RE getRE(String aPattern)
throws RESyntaxException
This is a factory method to return an RE object for the specified
regular expression. This method is not MT safe, but neither are the
returned RE objects.
aPattern
- the regular expression pattern
- an RE object for the supplied pattern
getStrippedFileName
public static String getStrippedFileName(String aBasedir,
String aFileName)
Create a stripped down version of a filename.
aBasedir
- the prefix to strip off the original filenameaFileName
- the original filename
- the filename where an initial prefix of basedir is stripped
lengthExpandedTabs
public static int lengthExpandedTabs(String aString,
int aToIdx,
int aTabWidth)
Returns the length of a String prefix with tabs expanded.
Each tab is counted as the number of characters is takes to
jump to the next tab stop.
aString
- the input StringaToIdx
- index in aString (exclusive) where the calculation stopsaTabWidth
- the distance betweeen tab stop position.
- the length of aString.substring(0, aToIdx) with tabs expanded.
lengthMinusTrailingWhitespace
public static int lengthMinusTrailingWhitespace(String aLine)
Returns the length of a string ignoring all trailing whitespace. It is a
pity that there is not a trim() like method that only removed the
trailing whitespace.
aLine
- the string to process
- the length of the string ignoring all trailing whitespace
whitespaceBefore
public static boolean whitespaceBefore(int aIndex,
String aLine)
Returns whether the specified string contains only whitespace up to the
specified index.
aIndex
- index to check up toaLine
- the line to check
- whether there is only whitespace