com.ideanest.attributes.dev
Class TypeResolver

java.lang.Object
  extended bycom.ideanest.attributes.dev.TypeResolver

public class TypeResolver
extends java.lang.Object

Resolves type names found in Java source files, according to Java type resolution rules. Normally this algorithm is implemented by a Java compiler, but sometimes we want to know what fully qualified typename a typename mentioned locally corresponds to.

Instances of this class are not thread-safe.

Version:
$Revision: 1.4 $ ($Date: 2003/08/01 04:52:04 $)
Author:
Piotr Kaminski

Constructor Summary
TypeResolver()
           
 
Method Summary
 void addImport(java.lang.String importName)
          Register an import declaration, either fully qualified or wildcard.
 void addPackage(java.lang.String packageName)
          Set the package name for the source file being parsed.
 java.lang.String beginClass(com.thoughtworks.qdox.parser.structs.ClassDef def)
          Mark the beginning of a class definition.
 java.lang.String endClass()
          Mark the end of a class definition.
 java.lang.String getCurrentClassName()
          Get the fully qualified name of the class currently being defined.
 boolean isTopContext()
          Check whether we are currently defining a class.
 void reset()
          Reset this type resolver to a virgin state, as if though newly instantiated.
 java.lang.Class resolve(java.lang.String typeName)
          Resolve a local type name to a type.
 java.lang.Class resolve(java.lang.String typeName, int dimensions)
          Resolve an array type, with the given base type name and number of dimensions.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TypeResolver

public TypeResolver()
Method Detail

addImport

public void addImport(java.lang.String importName)
Register an import declaration, either fully qualified or wildcard.

Parameters:
importName - the name of the imported type or package (including ".*" if wildcard)

addPackage

public void addPackage(java.lang.String packageName)
Set the package name for the source file being parsed. Can only be called once between resets.

Parameters:
packageName - the package name of the current source file
Throws:
java.lang.IllegalStateException - if the package name was already set

beginClass

public java.lang.String beginClass(com.thoughtworks.qdox.parser.structs.ClassDef def)
Mark the beginning of a class definition.

Parameters:
def - the class header, giving its name and other details
Returns:
the fully qualified name of the class whose definition was just begun

endClass

public java.lang.String endClass()
Mark the end of a class definition.

Returns:
the fully qualified name of the class who definition was just ended
Throws:
java.lang.IllegalStateException - if no class is currently being defined

getCurrentClassName

public java.lang.String getCurrentClassName()
Get the fully qualified name of the class currently being defined.

Returns:
the fully qualified name of the class currently being defined
Throws:
java.lang.IllegalStateException - if there is no class currently being defined

isTopContext

public boolean isTopContext()
Check whether we are currently defining a class.

Returns:
true if there is no class definition currently under way, false otherwise

reset

public void reset()
Reset this type resolver to a virgin state, as if though newly instantiated.


resolve

public java.lang.Class resolve(java.lang.String typeName)
                        throws java.lang.ClassNotFoundException
Resolve a local type name to a type. This takes into consideration the local context with appropriate scoping rules, the package of which the current source code is a member, and any import declarations that have been made. If the target type is a class, it must be present on the thread's classloader's classpath. This method does not work for array types.

Parameters:
typeName - a type name, qualified or not, primitive or not
Returns:
the type to which the given type name resolves in this context
Throws:
java.lang.ClassNotFoundException - if the type name could not be resolved
See Also:
resolve(String,int)

resolve

public java.lang.Class resolve(java.lang.String typeName,
                               int dimensions)
                        throws java.lang.ClassNotFoundException
Resolve an array type, with the given base type name and number of dimensions. If the number of dimensions is 0, the resolved type is not an array and the method works exactly like resolve(String).

Parameters:
typeName - a type name, qualified or not, nested or not
dimensions - the number of dimensions for the array type
Returns:
the resolved array type
Throws:
java.lang.ClassNotFoundException - if the base type cannot be resolved