com.puppycrawl.tools.checkstyle.checks

Class ClassResolver

public class ClassResolver extends Object

Utility class to resolve a class name to an actual class. Note that loaded classes are not initialized.

Limitations: this does not handle inner classes very well.

Version: 1.0

Author: Oliver Burn

Constructor Summary
ClassResolver(ClassLoader aLoader, String aPkg, Set aImports)
Creates a new ClassResolver instance.
Method Summary
booleanisLoadable(String aName)
Classresolve(String aName, String aCurrentClass)
Attempts to resolve the Class for a specified name.
ClasssafeLoad(String aName)
Will load a specified class is such a way that it will NOT be initialised.

Constructor Detail

ClassResolver

public ClassResolver(ClassLoader aLoader, String aPkg, Set aImports)
Creates a new ClassResolver instance.

Parameters: aLoader the ClassLoader to load classes with. aPkg the name of the package the class may belong to aImports set of imports to check if the class belongs to

Method Detail

isLoadable

public boolean isLoadable(String aName)

Parameters: aName name of the class to check

Returns: whether a specified class is loadable with safeLoad().

resolve

public Class resolve(String aName, String aCurrentClass)
Attempts to resolve the Class for a specified name. The algorithm is to check: - fully qualified name - explicit imports - enclosing package - star imports

Parameters: aName name of the class to resolve aCurrentClass name of current class (for inner classes).

Returns: the resolved class

Throws: ClassNotFoundException if unable to resolve the class

safeLoad

public Class safeLoad(String aName)
Will load a specified class is such a way that it will NOT be initialised.

Parameters: aName name of the class to load

Returns: the Class for the specified class

Throws: ClassNotFoundException if an error occurs