com.puppycrawl.tools.checkstyle.api
Class Utils

java.lang.Object
  extended bycom.puppycrawl.tools.checkstyle.api.Utils

public final class Utils
extends java.lang.Object

Contains utility methods.

Version:
1.0
Author:
Oliver Burn

Method Summary
static java.lang.String baseClassname(java.lang.String aType)
           
static RE createRE(java.lang.String aPattern)
          Helper method to create a regular expression.
static java.lang.String[] getLines(java.lang.String aFileName)
          Loads the contents of a file in a String array.
static RE getRE(java.lang.String aPattern)
          This is a factory method to return an RE object for the specified regular expression.
static int lengthExpandedTabs(java.lang.String aString, int aToIdx, int aTabWidth)
          Returns the length of a String prefix with tabs expanded.
static int lengthMinusTrailingWhitespace(java.lang.String aLine)
          Returns the length of a string ignoring all trailing whitespace.
static boolean whitespaceBefore(int aIndex, java.lang.String aLine)
          Returns whether the specified string contains only whitespace up to the specified index.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

whitespaceBefore

public static boolean whitespaceBefore(int aIndex,
                                       java.lang.String aLine)
Returns whether the specified string contains only whitespace up to the specified index.

Parameters:
aIndex - index to check up to
aLine - the line to check
Returns:
whether there is only whitespace

lengthMinusTrailingWhitespace

public static int lengthMinusTrailingWhitespace(java.lang.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.

Parameters:
aLine - the string to process
Returns:
the length of the string ignoring all trailing whitespace

lengthExpandedTabs

public static int lengthExpandedTabs(java.lang.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.

Parameters:
aString - the input String
aToIdx - index in aString (exclusive) where the calculation stops
aTabWidth - the distance betweeen tab stop position.
Returns:
the length of aString.substring(0, aToIdx) with tabs expanded.

getRE

public static RE getRE(java.lang.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.

Parameters:
aPattern - the regular expression pattern
Returns:
an RE object for the supplied pattern
Throws:
RESyntaxException - an invalid pattern was supplied

getLines

public static java.lang.String[] getLines(java.lang.String aFileName)
                                   throws java.io.IOException
Loads the contents of a file in a String array.

Parameters:
aFileName - the name of the file to load
Returns:
the lines in the file
Throws:
java.io.IOException - error occurred

createRE

public static RE createRE(java.lang.String aPattern)
                   throws ConversionException
Helper method to create a regular expression.

Parameters:
aPattern - the pattern to match
Returns:
a created regexp object
Throws:
ConversionException - if unable to create RE object.

baseClassname

public static java.lang.String baseClassname(java.lang.String aType)
Parameters:
aType - the fully qualified name. Cannot be null
Returns:
the base class name from a fully qualified name

Back to the Checkstyle Home Page