com.sun.tools.xjc.model.nav
Class NavigatorImpl

java.lang.Object
  extended by com.sun.tools.xjc.model.nav.NavigatorImpl
All Implemented Interfaces:
Navigator<NType,NClass,java.lang.Void,java.lang.Void>

public final class NavigatorImpl
extends java.lang.Object
implements Navigator<NType,NClass,java.lang.Void,java.lang.Void>

Navigator implementation for XJC. Most of the Navigator methods are used for parsing the model, which doesn't happen in XJC. So Most of the methods aren't really implemented. Implementations should be filled in as needed.


Field Summary
static NavigatorImpl theInstance
           
 
Fields inherited from interface com.sun.xml.bind.v2.model.nav.Navigator
REFLECTION
 
Method Summary
 NClass asDecl(java.lang.Class c)
          Gets the C representation for the given class.
 NClass asDecl(NType nt)
          If the given type is an use of class declaration, returns the type casted as C.
static NClass create(java.lang.Class c)
           
static NType create(java.lang.reflect.Type t)
           
static NType createParameterizedType(java.lang.Class rawType, NType... args)
           
static NType createParameterizedType(NClass rawType, NType... args)
          Creates a NType representation for a parameterized type RawType&lt;ParamType1,ParamType2,...> .
<T> NType
erasure(NType type)
          Computes the erasure
 NClass findClass(java.lang.String className, NClass referencePoint)
          Finds the class/interface/enum/annotation of the given name.
 NType getBaseClass(NType nt, NClass base)
          Gets the parameterization of the given base type.
 Location getClassLocation(NClass c)
          Returns a location of the specified class.
 java.lang.String getClassName(NClass nClass)
          Gets the fully-qualified name of the class.
 java.lang.String getClassShortName(NClass nClass)
          Gets the short name of the class ("Object" for Object.) For nested classes, this method should just return the inner name.
 NType getComponentType(NType nType)
          Gets the component type of the array.
 java.lang.Void getDeclaredField(NClass clazz, java.lang.String fieldName)
          Gets the named field declared on the given class.
 java.util.Collection<? extends java.lang.Void> getDeclaredFields(NClass nClass)
          Gets all the declared fields of the given class.
 java.util.Collection<? extends java.lang.Void> getDeclaredMethods(NClass nClass)
          Gets all the declared methods of the given class (regardless of their access modifiers, regardless of whether they override methods of the base classes.)
 NClass getDeclaringClassForField(java.lang.Void aVoid)
          Gets the class that declares the given field.
 NClass getDeclaringClassForMethod(java.lang.Void aVoid)
          Gets the class that declares the given method.
 java.lang.Void[] getEnumConstants(NClass clazz)
          Gets the enumeration constants from an enum class.
 Location getFieldLocation(java.lang.Void _)
           
 java.lang.String getFieldName(java.lang.Void aVoid)
          Gets the name of the field.
 NType getFieldType(java.lang.Void aVoid)
          Gets the type of the field.
 Location getMethodLocation(java.lang.Void _)
           
 java.lang.String getMethodName(java.lang.Void aVoid)
          Gets the name of the method, such as "toString" or "equals".
 NType[] getMethodParameters(java.lang.Void aVoid)
          Returns the list of parameters to the method.
 java.lang.String getPackageName(NClass clazz)
          Gets the package name of the given class.
 NType getPrimitive(java.lang.Class primitiveType)
          Returns the representation for the given primitive type.
 NType getReturnType(java.lang.Void aVoid)
          Gets the return type of a method.
 NClass getSuperClass(NClass nClass)
          Gets the base class of the specified class.
 NType getTypeArgument(NType nt, int i)
          Gets the i-th type argument from a parameterized type.
 java.lang.String getTypeName(NType type)
          Gets the display name of the type object
 NType getVoidType()
          Gets the representation of the primitive "void" type.
 boolean hasDefaultConstructor(NClass nClass)
          Returns true if the given class has a no-arg default constructor.
 boolean isAbstract(NClass clazz)
          Returns true if this is an abstract class.
 boolean isArray(NType nType)
          Checks if the type is an array type.
 boolean isArrayButNotByteArray(NType t)
          Checks if the type is an array type but not byte[].
 boolean isBridgeMethod(java.lang.Void method)
          Returns true if this method is a bridge method as defined in JLS.
 boolean isEnum(NClass c)
          Returns true if this is an enum class.
 boolean isFinal(NClass clazz)
          Deprecated. no class generated by XJC is final.
 boolean isFinalMethod(java.lang.Void aVoid)
          Returns true if the method is final.
 boolean isInnerClass(NClass clazz)
          Returns true if the given class is an inner class.
 boolean isInterface(NClass clazz)
          Returns true if 'clazz' is an interface.
 boolean isOverriding(java.lang.Void method, NClass clazz)
          Returns true if the given method is overriding another one defined in the base class 'base' or its ancestors.
 boolean isParameterizedType(NType nt)
          Returns true if t is a parameterized type.
 boolean isPrimitive(NType type)
          Checks if the given type is a primitive type.
 boolean isPublicField(java.lang.Void aVoid)
          Returns true if the field is public.
 boolean isPublicMethod(java.lang.Void aVoid)
          Returns true if the method is public.
 boolean isStaticField(java.lang.Void aVoid)
          Returns true if the field is static.
 boolean isStaticMethod(java.lang.Void aVoid)
          Returns true if the method is static.
 boolean isSubClassOf(NType sub, NType sup)
          Checks if sub is a sub-type of sup.
 boolean isTransient(java.lang.Void f)
          Returns true if the field is transient.
 NClass ref(java.lang.Class c)
          Gets the representation of the given Java type in T.
 NClass ref(com.sun.codemodel.JClass c)
           
 NType use(NClass nc)
          Gets the T for the given C.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

theInstance

public static final NavigatorImpl theInstance
Method Detail

getSuperClass

public NClass getSuperClass(NClass nClass)
Description copied from interface: Navigator
Gets the base class of the specified class.

Specified by:
getSuperClass in interface Navigator<NType,NClass,java.lang.Void,java.lang.Void>
Returns:
null if the parameter represents Object.

getBaseClass

public NType getBaseClass(NType nt,
                          NClass base)
Description copied from interface: Navigator
Gets the parameterization of the given base type.

For example, given the following


 interface Foo<T> extends List<List<T>> {}
 interface Bar extends Foo<String> {}
 
This method works like this:

 getBaseClass( Bar, List ) = List<List<String>
 getBaseClass( Bar, Foo  ) = Foo<String>
 getBaseClass( Foo<? extends Number>, Collection ) = Collection<List<? extends Number>>
 getBaseClass( ArrayList<? extends BigInteger>, List ) = List<? extends BigInteger>
 

Specified by:
getBaseClass in interface Navigator<NType,NClass,java.lang.Void,java.lang.Void>
Parameters:
nt - The type that derives from baseType
base - The class whose parameterization we are interested in.
Returns:
The use of baseType in type. or null if the type is not assignable to the base type.

getClassName

public java.lang.String getClassName(NClass nClass)
Description copied from interface: Navigator
Gets the fully-qualified name of the class. ("java.lang.Object" for Object)

Specified by:
getClassName in interface Navigator<NType,NClass,java.lang.Void,java.lang.Void>

getTypeName

public java.lang.String getTypeName(NType type)
Description copied from interface: Navigator
Gets the display name of the type object

Specified by:
getTypeName in interface Navigator<NType,NClass,java.lang.Void,java.lang.Void>
Returns:
a human-readable name that the type represents.

getClassShortName

public java.lang.String getClassShortName(NClass nClass)
Description copied from interface: Navigator
Gets the short name of the class ("Object" for Object.) For nested classes, this method should just return the inner name. (for example "Inner" for "com.acme.Outer$Inner".

Specified by:
getClassShortName in interface Navigator<NType,NClass,java.lang.Void,java.lang.Void>

getDeclaredFields

public java.util.Collection<? extends java.lang.Void> getDeclaredFields(NClass nClass)
Description copied from interface: Navigator
Gets all the declared fields of the given class.

Specified by:
getDeclaredFields in interface Navigator<NType,NClass,java.lang.Void,java.lang.Void>

getDeclaredField

public java.lang.Void getDeclaredField(NClass clazz,
                                       java.lang.String fieldName)
Description copied from interface: Navigator
Gets the named field declared on the given class. This method doesn't visit ancestors, but does recognize non-public fields.

Specified by:
getDeclaredField in interface Navigator<NType,NClass,java.lang.Void,java.lang.Void>
Returns:
null if not found

getDeclaredMethods

public java.util.Collection<? extends java.lang.Void> getDeclaredMethods(NClass nClass)
Description copied from interface: Navigator
Gets all the declared methods of the given class (regardless of their access modifiers, regardless of whether they override methods of the base classes.)

Note that this method does not list methods declared on base classes.

Specified by:
getDeclaredMethods in interface Navigator<NType,NClass,java.lang.Void,java.lang.Void>
Returns:
can be empty but always non-null.

getDeclaringClassForField

public NClass getDeclaringClassForField(java.lang.Void aVoid)
Description copied from interface: Navigator
Gets the class that declares the given field.

Specified by:
getDeclaringClassForField in interface Navigator<NType,NClass,java.lang.Void,java.lang.Void>

getDeclaringClassForMethod

public NClass getDeclaringClassForMethod(java.lang.Void aVoid)
Description copied from interface: Navigator
Gets the class that declares the given method.

Specified by:
getDeclaringClassForMethod in interface Navigator<NType,NClass,java.lang.Void,java.lang.Void>

getFieldType

public NType getFieldType(java.lang.Void aVoid)
Description copied from interface: Navigator
Gets the type of the field.

Specified by:
getFieldType in interface Navigator<NType,NClass,java.lang.Void,java.lang.Void>

getFieldName

public java.lang.String getFieldName(java.lang.Void aVoid)
Description copied from interface: Navigator
Gets the name of the field.

Specified by:
getFieldName in interface Navigator<NType,NClass,java.lang.Void,java.lang.Void>

getMethodName

public java.lang.String getMethodName(java.lang.Void aVoid)
Description copied from interface: Navigator
Gets the name of the method, such as "toString" or "equals".

Specified by:
getMethodName in interface Navigator<NType,NClass,java.lang.Void,java.lang.Void>

getReturnType

public NType getReturnType(java.lang.Void aVoid)
Description copied from interface: Navigator
Gets the return type of a method.

Specified by:
getReturnType in interface Navigator<NType,NClass,java.lang.Void,java.lang.Void>

getMethodParameters

public NType[] getMethodParameters(java.lang.Void aVoid)
Description copied from interface: Navigator
Returns the list of parameters to the method.

Specified by:
getMethodParameters in interface Navigator<NType,NClass,java.lang.Void,java.lang.Void>

isStaticMethod

public boolean isStaticMethod(java.lang.Void aVoid)
Description copied from interface: Navigator
Returns true if the method is static.

Specified by:
isStaticMethod in interface Navigator<NType,NClass,java.lang.Void,java.lang.Void>

isFinalMethod

public boolean isFinalMethod(java.lang.Void aVoid)
Description copied from interface: Navigator
Returns true if the method is final.

Specified by:
isFinalMethod in interface Navigator<NType,NClass,java.lang.Void,java.lang.Void>

isSubClassOf

public boolean isSubClassOf(NType sub,
                            NType sup)
Description copied from interface: Navigator
Checks if sub is a sub-type of sup. TODO: should this method take T or C?

Specified by:
isSubClassOf in interface Navigator<NType,NClass,java.lang.Void,java.lang.Void>

ref

public NClass ref(java.lang.Class c)
Description copied from interface: Navigator
Gets the representation of the given Java type in T.

Specified by:
ref in interface Navigator<NType,NClass,java.lang.Void,java.lang.Void>
Parameters:
c - can be a primitive, array, class, or anything. (therefore the return type has to be T, not C)

ref

public NClass ref(com.sun.codemodel.JClass c)

use

public NType use(NClass nc)
Description copied from interface: Navigator
Gets the T for the given C.

Specified by:
use in interface Navigator<NType,NClass,java.lang.Void,java.lang.Void>

asDecl

public NClass asDecl(NType nt)
Description copied from interface: Navigator
If the given type is an use of class declaration, returns the type casted as C. Otherwise null.

TODO: define the exact semantics.

Specified by:
asDecl in interface Navigator<NType,NClass,java.lang.Void,java.lang.Void>

asDecl

public NClass asDecl(java.lang.Class c)
Description copied from interface: Navigator
Gets the C representation for the given class. The behavior is undefined if the class object represents primitives, arrays, and other types that are not class declaration.

Specified by:
asDecl in interface Navigator<NType,NClass,java.lang.Void,java.lang.Void>

isArray

public boolean isArray(NType nType)
Description copied from interface: Navigator
Checks if the type is an array type.

Specified by:
isArray in interface Navigator<NType,NClass,java.lang.Void,java.lang.Void>

isArrayButNotByteArray

public boolean isArrayButNotByteArray(NType t)
Description copied from interface: Navigator
Checks if the type is an array type but not byte[].

Specified by:
isArrayButNotByteArray in interface Navigator<NType,NClass,java.lang.Void,java.lang.Void>

getComponentType

public NType getComponentType(NType nType)
Description copied from interface: Navigator
Gets the component type of the array.

Specified by:
getComponentType in interface Navigator<NType,NClass,java.lang.Void,java.lang.Void>
Parameters:
nType - must be an array.

getTypeArgument

public NType getTypeArgument(NType nt,
                             int i)
Description copied from interface: Navigator
Gets the i-th type argument from a parameterized type. For example, getTypeArgument([Map<Integer,String>],0)=Integer

Specified by:
getTypeArgument in interface Navigator<NType,NClass,java.lang.Void,java.lang.Void>
See Also:
Navigator.isParameterizedType(Object)

isParameterizedType

public boolean isParameterizedType(NType nt)
Description copied from interface: Navigator
Returns true if t is a parameterized type.

Specified by:
isParameterizedType in interface Navigator<NType,NClass,java.lang.Void,java.lang.Void>

isPrimitive

public boolean isPrimitive(NType type)
Description copied from interface: Navigator
Checks if the given type is a primitive type.

Specified by:
isPrimitive in interface Navigator<NType,NClass,java.lang.Void,java.lang.Void>

getPrimitive

public NType getPrimitive(java.lang.Class primitiveType)
Description copied from interface: Navigator
Returns the representation for the given primitive type.

Specified by:
getPrimitive in interface Navigator<NType,NClass,java.lang.Void,java.lang.Void>
Parameters:
primitiveType - must be Class objects like Integer.TYPE.

create

public static final NType create(java.lang.reflect.Type t)

create

public static NClass create(java.lang.Class c)

createParameterizedType

public static NType createParameterizedType(NClass rawType,
                                            NType... args)
Creates a NType representation for a parameterized type RawType&lt;ParamType1,ParamType2,...> .


createParameterizedType

public static NType createParameterizedType(java.lang.Class rawType,
                                            NType... args)

getClassLocation

public Location getClassLocation(NClass c)
Description copied from interface: Navigator
Returns a location of the specified class.

Specified by:
getClassLocation in interface Navigator<NType,NClass,java.lang.Void,java.lang.Void>

getFieldLocation

public Location getFieldLocation(java.lang.Void _)
Specified by:
getFieldLocation in interface Navigator<NType,NClass,java.lang.Void,java.lang.Void>

getMethodLocation

public Location getMethodLocation(java.lang.Void _)
Specified by:
getMethodLocation in interface Navigator<NType,NClass,java.lang.Void,java.lang.Void>

hasDefaultConstructor

public boolean hasDefaultConstructor(NClass nClass)
Description copied from interface: Navigator
Returns true if the given class has a no-arg default constructor. The constructor does not need to be public.

Specified by:
hasDefaultConstructor in interface Navigator<NType,NClass,java.lang.Void,java.lang.Void>

isStaticField

public boolean isStaticField(java.lang.Void aVoid)
Description copied from interface: Navigator
Returns true if the field is static.

Specified by:
isStaticField in interface Navigator<NType,NClass,java.lang.Void,java.lang.Void>

isPublicMethod

public boolean isPublicMethod(java.lang.Void aVoid)
Description copied from interface: Navigator
Returns true if the method is public.

Specified by:
isPublicMethod in interface Navigator<NType,NClass,java.lang.Void,java.lang.Void>

isPublicField

public boolean isPublicField(java.lang.Void aVoid)
Description copied from interface: Navigator
Returns true if the field is public.

Specified by:
isPublicField in interface Navigator<NType,NClass,java.lang.Void,java.lang.Void>

isEnum

public boolean isEnum(NClass c)
Description copied from interface: Navigator
Returns true if this is an enum class.

Specified by:
isEnum in interface Navigator<NType,NClass,java.lang.Void,java.lang.Void>

erasure

public <T> NType erasure(NType type)
Description copied from interface: Navigator
Computes the erasure

Specified by:
erasure in interface Navigator<NType,NClass,java.lang.Void,java.lang.Void>

isAbstract

public boolean isAbstract(NClass clazz)
Description copied from interface: Navigator
Returns true if this is an abstract class.

Specified by:
isAbstract in interface Navigator<NType,NClass,java.lang.Void,java.lang.Void>

isFinal

public boolean isFinal(NClass clazz)
Deprecated. no class generated by XJC is final.

Description copied from interface: Navigator
Returns true if this is a final class.

Specified by:
isFinal in interface Navigator<NType,NClass,java.lang.Void,java.lang.Void>

getEnumConstants

public java.lang.Void[] getEnumConstants(NClass clazz)
Description copied from interface: Navigator
Gets the enumeration constants from an enum class.

Specified by:
getEnumConstants in interface Navigator<NType,NClass,java.lang.Void,java.lang.Void>
Parameters:
clazz - must derive from Enum.
Returns:
can be empty but never null.

getVoidType

public NType getVoidType()
Description copied from interface: Navigator
Gets the representation of the primitive "void" type.

Specified by:
getVoidType in interface Navigator<NType,NClass,java.lang.Void,java.lang.Void>

getPackageName

public java.lang.String getPackageName(NClass clazz)
Description copied from interface: Navigator
Gets the package name of the given class.

Specified by:
getPackageName in interface Navigator<NType,NClass,java.lang.Void,java.lang.Void>
Returns:
i.e. "", "java.lang" but not null.

findClass

public NClass findClass(java.lang.String className,
                        NClass referencePoint)
Description copied from interface: Navigator
Finds the class/interface/enum/annotation of the given name.

Specified by:
findClass in interface Navigator<NType,NClass,java.lang.Void,java.lang.Void>
referencePoint - The class that refers to the specified class.
Returns:
null if not found.

isBridgeMethod

public boolean isBridgeMethod(java.lang.Void method)
Description copied from interface: Navigator
Returns true if this method is a bridge method as defined in JLS.

Specified by:
isBridgeMethod in interface Navigator<NType,NClass,java.lang.Void,java.lang.Void>

isOverriding

public boolean isOverriding(java.lang.Void method,
                            NClass clazz)
Description copied from interface: Navigator
Returns true if the given method is overriding another one defined in the base class 'base' or its ancestors.

Specified by:
isOverriding in interface Navigator<NType,NClass,java.lang.Void,java.lang.Void>

isInterface

public boolean isInterface(NClass clazz)
Description copied from interface: Navigator
Returns true if 'clazz' is an interface.

Specified by:
isInterface in interface Navigator<NType,NClass,java.lang.Void,java.lang.Void>

isTransient

public boolean isTransient(java.lang.Void f)
Description copied from interface: Navigator
Returns true if the field is transient.

Specified by:
isTransient in interface Navigator<NType,NClass,java.lang.Void,java.lang.Void>

isInnerClass

public boolean isInnerClass(NClass clazz)
Description copied from interface: Navigator
Returns true if the given class is an inner class. This is only used to improve the error diagnostics, so it's OK to fail to detect some inner classes as such. Note that this method should return false for nested classes (static classes.)

Specified by:
isInnerClass in interface Navigator<NType,NClass,java.lang.Void,java.lang.Void>