org.mule.devkit.model.code
Class TypeReference

java.lang.Object
  extended by org.mule.devkit.model.code.Type
      extended by org.mule.devkit.model.code.TypeReference
All Implemented Interfaces:
Comparable<Type>, Generable
Direct Known Subclasses:
GeneratedClass, NullType, TypeVariable

public abstract class TypeReference
extends Type

Represents a Java reference type, such as a class, an interface, an enum, an array type, a parameterized type.

To be exact, this object represents an "use" of a reference type, not necessarily a declaration of it, which is modeled as GeneratedClass.


Field Summary
protected static TypeVariable[] EMPTY_ARRAY
          Sometimes useful reusable empty array.
 
Constructor Summary
protected TypeReference(CodeModel _owner)
           
 
Method Summary
abstract  TypeReference _extends()
          Gets the super class of this class.
abstract  Iterator<TypeReference> _implements()
          Iterates all super interfaces directly implemented by this class/interface.
abstract  GeneratedPackage _package()
          Gets the package to which this class belongs.
 TypeReference array()
          Create an array type of this type.
 TypeReference array(GeneratedExpression size)
           
 TypeReference boxify()
          Deprecated. calling this method from TypeReference would be meaningless, since it's always guaranteed to return this.
 TypeReference erasure()
          Returns the erasure of this type.
 void generate(Formatter f)
           
 TypeReference getBaseClass(Class<?> baseType)
           
 TypeReference getBaseClass(TypeReference baseType)
          Gets the parameterization of the given base type.
 PrimitiveType getPrimitiveType()
          If this class represents one of the wrapper classes defined in the java.lang package, return the corresponding primitive type.
 List<TypeReference> getTypeParameters()
          If this class is parameterized, return the type parameter of the given index.
abstract  boolean isAbstract()
          Checks if this class is an abstract class.
 boolean isAssignableFrom(TypeReference derived)
          Checks the relationship between two classes.
abstract  boolean isInterface()
          Checks if this object represents an interface.
 boolean isParameterized()
          Returns true if this class is a parameterized class.
abstract  String name()
          Gets the name of this class.
 TypeReference narrow(Class<?>... clazz)
           
 TypeReference narrow(Class<?> clazz)
          "Narrows" a generic class to a concrete class by specifying a type argument.
 TypeReference narrow(List<? extends TypeReference> clazz)
           
 TypeReference narrow(Type type)
           
 TypeReference narrow(TypeReference... clazz)
           
 TypeReference narrow(TypeReference clazz)
          "Narrows" a generic class to a concrete class by specifying a type argument.
 TypeReference outer()
          Returns the class in which this class is nested, or null if this is a top-level class.
 CodeModel owner()
          Gets the CodeModel object to which this object belongs.
 GeneratedInvocation staticInvoke(GeneratedMethod method)
          Generates a static method invocation.
 GeneratedInvocation staticInvoke(String method)
          Generates a static method invocation.
 GeneratedFieldReference staticRef(GeneratedVariable field)
          Static field reference.
 GeneratedFieldReference staticRef(String field)
          Static field reference.
protected abstract  TypeReference substituteParams(TypeVariable[] variables, List<TypeReference> bindings)
          Substitutes the type variables with their actual arguments.
 String toString()
           
 TypeVariable[] typeParams()
          Iterates all the type parameters of this class/interface.
 Type unboxify()
          If this class is a wrapper type for a primitive, return the primitive type.
 TypeReference wildcard()
          Create "? extends T" from T.
 
Methods inherited from class org.mule.devkit.model.code.Type
binaryName, compareTo, dotclass, elementType, equals, fullName, hashCode, isArray, isPrimitive, isReference, parse
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

EMPTY_ARRAY

protected static final TypeVariable[] EMPTY_ARRAY
Sometimes useful reusable empty array.

Constructor Detail

TypeReference

protected TypeReference(CodeModel _owner)
Method Detail

name

public abstract String name()
Gets the name of this class.

Specified by:
name in class Type
Returns:
name of this class, without any qualification. For example, this method returns "String" for java.lang.String.

_package

public abstract GeneratedPackage _package()
Gets the package to which this class belongs. TODO: shall we move move this down?


outer

public TypeReference outer()
Returns the class in which this class is nested, or null if this is a top-level class.


owner

public final CodeModel owner()
Gets the CodeModel object to which this object belongs.

Specified by:
owner in class Type

_extends

public abstract TypeReference _extends()
Gets the super class of this class.

Returns:
Returns the TypeReference representing the superclass of the entity (class or interface) represented by this TypeReference. Even if no super class is given explicitly or this TypeReference is not a class, this method still returns TypeReference for Object. If this TypeReference represents Object, return null.

_implements

public abstract Iterator<TypeReference> _implements()
Iterates all super interfaces directly implemented by this class/interface.

Returns:
A non-null valid iterator that iterates all TypeReference objects that represents those interfaces implemented by this object.

typeParams

public TypeVariable[] typeParams()
Iterates all the type parameters of this class/interface.

For example, if this TypeReference represents Set<T>, this method returns an array that contains single TypeVariable for 'T'.


isInterface

public abstract boolean isInterface()
Checks if this object represents an interface.


isAbstract

public abstract boolean isAbstract()
Checks if this class is an abstract class.


getPrimitiveType

public PrimitiveType getPrimitiveType()
If this class represents one of the wrapper classes defined in the java.lang package, return the corresponding primitive type. Otherwise null.


boxify

public TypeReference boxify()
Deprecated. calling this method from TypeReference would be meaningless, since it's always guaranteed to return this.

Description copied from class: Type
If this class is a primitive type, return the boxed class. Otherwise return this.

For example, for "int", this method returns "java.lang.Integer".

Specified by:
boxify in class Type

unboxify

public Type unboxify()
Description copied from class: Type
If this class is a wrapper type for a primitive, return the primitive type. Otherwise return this.

For example, for "java.lang.Integer", this method returns "int".

Specified by:
unboxify in class Type

erasure

public TypeReference erasure()
Description copied from class: Type
Returns the erasure of this type.

Overrides:
erasure in class Type

isAssignableFrom

public final boolean isAssignableFrom(TypeReference derived)
Checks the relationship between two classes.

This method works in the same way as Class.isAssignableFrom(Class) works. For example, baseClass.isAssignableFrom(derivedClass)==true.


getBaseClass

public final TypeReference getBaseClass(TypeReference baseType)
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>
 

Parameters:
baseType - The class whose parameterization we are interested in.
Returns:
The use of baseType in this type. or null if the type is not assignable to the base type.

getBaseClass

public final TypeReference getBaseClass(Class<?> baseType)

array

public TypeReference array()
Description copied from class: Type
Create an array type of this type.

This method is undefined for primitive void type, which doesn't have any corresponding array representation.

Specified by:
array in class Type
Returns:
A TypeReference representing the array type whose element type is this type

array

public TypeReference array(GeneratedExpression size)

narrow

public TypeReference narrow(Class<?> clazz)
"Narrows" a generic class to a concrete class by specifying a type argument.

.narrow(X) builds Set<X> from Set.


narrow

public TypeReference narrow(Class<?>... clazz)

narrow

public TypeReference narrow(TypeReference clazz)
"Narrows" a generic class to a concrete class by specifying a type argument.

.narrow(X) builds Set<X> from Set.


narrow

public TypeReference narrow(Type type)

narrow

public TypeReference narrow(TypeReference... clazz)

narrow

public TypeReference narrow(List<? extends TypeReference> clazz)

getTypeParameters

public List<TypeReference> getTypeParameters()
If this class is parameterized, return the type parameter of the given index.


isParameterized

public final boolean isParameterized()
Returns true if this class is a parameterized class.


wildcard

public final TypeReference wildcard()
Create "? extends T" from T.

Returns:
never null

substituteParams

protected abstract TypeReference substituteParams(TypeVariable[] variables,
                                                  List<TypeReference> bindings)
Substitutes the type variables with their actual arguments.

For example, when this class is Map<String,Map<V>>, (where V then doing substituteParams( V, Integer ) returns a TypeReference for Map<String,Map<Integer>>.

This method needs to work recursively.


toString

public String toString()
Overrides:
toString in class Type

staticInvoke

public final GeneratedInvocation staticInvoke(GeneratedMethod method)
Generates a static method invocation.


staticInvoke

public final GeneratedInvocation staticInvoke(String method)
Generates a static method invocation.


staticRef

public final GeneratedFieldReference staticRef(String field)
Static field reference.


staticRef

public final GeneratedFieldReference staticRef(GeneratedVariable field)
Static field reference.


generate

public void generate(Formatter f)


Copyright © 2010–2014 MuleSoft, Inc.. All rights reserved.