Class JClass

    • Field Detail

      • EMPTY_ARRAY

        protected static final JTypeVar[] EMPTY_ARRAY
        Sometimes useful reusable empty array.
      • arrayClass

        private JClass arrayClass
    • Constructor Detail

    • Method Detail

      • name

        public abstract java.lang.String name()
        Gets the name of this class.
        Specified by:
        name in class JType
        Returns:
        name of this class, without any qualification. For example, this method returns "String" for java.lang.String.
      • _package

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

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

        public final JCodeModel owner()
        Gets the JCodeModel object to which this object belongs.
        Specified by:
        owner in class JType
      • _extends

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

        public abstract java.util.Iterator<JClass> _implements()
        Iterates all super interfaces directly implemented by this class/interface.
        Returns:
        A non-null valid iterator that iterates all JClass objects that represents those interfaces implemented by this object.
      • typeParams

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

        For example, if this JClass represents Set<T>, this method returns an array that contains single JTypeVar 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 JPrimitiveType 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 JClass boxify()
        Deprecated.
        calling this method from JClass would be meaningless, since it's always guaranteed to return this.
        Description copied from class: JType
        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 JType
      • unboxify

        public JType unboxify()
        Description copied from class: JType
        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 JType
      • erasure

        public JClass erasure()
        Description copied from class: JType
        Returns the erasure of this type.
        Overrides:
        erasure in class JType
      • isAssignableFrom

        public final boolean isAssignableFrom​(JClass 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 JClass getBaseClass​(JClass 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 JClass getBaseClass​(java.lang.Class<?> baseType)
      • array

        public JClass array()
        Description copied from class: JType
        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 JType
        Returns:
        A JClass representing the array type whose element type is this type
      • narrow

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

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

      • narrow

        public JClass narrow​(java.lang.Class<?>... clazz)
      • narrow

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

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

      • narrow

        public JClass narrow​(java.util.List<? extends JClass> clazz)
      • getTypeParameters

        public java.util.List<JClass> 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 JClass wildcard()
        Create "? extends T" from T.
        Returns:
        never null
      • substituteParams

        protected abstract JClass substituteParams​(JTypeVar[] variables,
                                                   java.util.List<JClass> 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 JClass for Map<String,Map<Integer>>.

        This method needs to work recursively.

      • toString

        public java.lang.String toString()
        Overrides:
        toString in class JType
      • staticInvoke

        public final JInvocation staticInvoke​(JMethod method)
        Generates a static method invocation.
      • staticInvoke

        public final JInvocation staticInvoke​(java.lang.String method)
        Generates a static method invocation.
      • staticRef

        public final JFieldRef staticRef​(java.lang.String field)
        Static field reference.
      • staticRef

        public final JFieldRef staticRef​(JVar field)
        Static field reference.
      • generate

        public void generate​(JFormatter f)
      • printLink

        void printLink​(JFormatter f)
        Prints the class name in javadoc @link format.