com.puppycrawl.tools.checkstyle.checks

Class AbstractTypeAwareCheck

public abstract class AbstractTypeAwareCheck extends Check

Abstract class that endeavours to maintain type information for the Java file being checked. It provides helper methods for performing type information functions.

Version: 1.0

Author: Oliver Burn

Nested Class Summary
protected abstract static classAbstractTypeAwareCheck.ClassInfo
Contains class's Token.
protected static classAbstractTypeAwareCheck.Token
Represents text element with location in the text.
Method Summary
voidbeginTree(DetailAST aRootAST)
{@inheritDoc}
protected AbstractTypeAwareCheck.ClassInfocreateClassInfo(AbstractTypeAwareCheck.Token aName, String aSurroundingClass)
Creates class info for given name.
protected AbstractTypeAwareCheck.ClassInfofindClassAlias(String aName)
Looking if a given name is alias.
protected StringgetCurrentClassName()
Returns current class.
int[]getRequiredTokens()
{@inheritDoc}
protected booleanisSameType(String aFirst, String aSecond)
Return if two Strings represent the same type, inspecting the import statements if necessary
protected booleanisShortName(String aShortName, String aFullName)
Calculate if one type name is a shortname for another type name.
protected booleanisSubclass(Class aChild, Class aParent)
Checks if one class is subclass of another
protected booleanisUnchecked(Class aException)
Is exception is unchecked (subclass of RuntimeException or Error
protected voidleaveAST(DetailAST aAST)
Called when exiting an AST.
voidleaveToken(DetailAST aAST)
{@inheritDoc}
protected abstract voidlogLoadError(AbstractTypeAwareCheck.Token aIdent)
Logs error if unable to load class information.
protected voidlogLoadErrorImpl(int aLineNo, int aColumnNo, String aMsgKey, Object[] aValues)
Common implementation for logLoadError() method.
protected abstract voidprocessAST(DetailAST aAST)
Called to process an AST when visiting it.
protected ClassresolveClass(String aClassName, String aCurrentClass)
Attempts to resolve the Class for a specified name.
protected ClasstryLoadClass(AbstractTypeAwareCheck.Token aIdent, String aCurrentClass)
Tries to load class.
voidvisitToken(DetailAST aAST)
{@inheritDoc}

Method Detail

beginTree

public void beginTree(DetailAST aRootAST)
{@inheritDoc}

createClassInfo

protected final AbstractTypeAwareCheck.ClassInfo createClassInfo(AbstractTypeAwareCheck.Token aName, String aSurroundingClass)
Creates class info for given name.

Parameters: aName name of type. aSurroundingClass name of surrounding class.

Returns: class infor for given name.

findClassAlias

protected final AbstractTypeAwareCheck.ClassInfo findClassAlias(String aName)
Looking if a given name is alias.

Parameters: aName given name

Returns: ClassInfo for alias if it exists, null otherwise

getCurrentClassName

protected final String getCurrentClassName()
Returns current class.

Returns: name of current class.

getRequiredTokens

public final int[] getRequiredTokens()
{@inheritDoc}

isSameType

protected boolean isSameType(String aFirst, String aSecond)
Return if two Strings represent the same type, inspecting the import statements if necessary

Parameters: aFirst first type declared in throws clause aSecond second type declared in thros tag

Returns: true iff type names represent the same type

isShortName

protected boolean isShortName(String aShortName, String aFullName)
Calculate if one type name is a shortname for another type name.

Parameters: aShortName a shorthand, such as IOException aFullName a full name, such as java.io.IOException

Returns: true iff aShortName represents the same type as aFullName

isSubclass

protected boolean isSubclass(Class aChild, Class aParent)
Checks if one class is subclass of another

Parameters: aChild Class of class which should be child aParent Class of class which should be parent

Returns: true if aChild is subclass of aParent false otherwise

isUnchecked

protected boolean isUnchecked(Class aException)
Is exception is unchecked (subclass of RuntimeException or Error

Parameters: aException Class of exception to check

Returns: true if exception is unchecked false if exception is checked

leaveAST

protected void leaveAST(DetailAST aAST)
Called when exiting an AST. A no-op by default, extending classes may choose to override this to augment their processing.

Parameters: aAST the AST we are departing. Guaranteed to not be PACKAGE_DEF, CLASS_DEF, or IMPORT

leaveToken

public final void leaveToken(DetailAST aAST)
{@inheritDoc}

logLoadError

protected abstract void logLoadError(AbstractTypeAwareCheck.Token aIdent)
Logs error if unable to load class information. Abstract, should be overrided in subclasses.

Parameters: aIdent class name for which we can no load class.

logLoadErrorImpl

protected final void logLoadErrorImpl(int aLineNo, int aColumnNo, String aMsgKey, Object[] aValues)
Common implementation for logLoadError() method.

Parameters: aLineNo line number of the problem. aColumnNo column number of the problem. aMsgKey message key to use. aValues values to fill the message out.

processAST

protected abstract void processAST(DetailAST aAST)
Called to process an AST when visiting it.

Parameters: aAST the AST to process. Guaranteed to not be PACKAGE_DEF or IMPORT tokens.

resolveClass

protected final Class resolveClass(String aClassName, String aCurrentClass)
Attempts to resolve the Class for a specified name.

Parameters: aClassName name of the class to resolve aCurrentClass name of surrounding class.

Returns: the resolved class or null if unable to resolve the class.

tryLoadClass

protected final Class tryLoadClass(AbstractTypeAwareCheck.Token aIdent, String aCurrentClass)
Tries to load class. Logs error if unable.

Parameters: aIdent name of class which we try to load. aCurrentClass name of surrounding class.

Returns: Class for a ident.

visitToken

public final void visitToken(DetailAST aAST)
{@inheritDoc}