Class JPrimitiveType

  • All Implemented Interfaces:
    JGenerable, java.lang.Comparable<JType>

    public final class JPrimitiveType
    extends JType
    Java built-in primitive types. Instances of this class can be obtained as constants of JCodeModel, such as JCodeModel.BOOLEAN.
    • Field Detail

      • typeName

        private final java.lang.String typeName
      • wrapperClass

        private final JClass wrapperClass
        Corresponding wrapper class. For example, this would be "java.lang.Short" for short.
      • arrayClass

        private JClass arrayClass
    • Constructor Detail

      • JPrimitiveType

        JPrimitiveType​(JCodeModel owner,
                       java.lang.String typeName,
                       java.lang.Class<?> wrapper)
    • Method Detail

      • owner

        public JCodeModel owner()
        Description copied from class: JType
        Gets the owner code model object.
        Specified by:
        owner in class JType
      • fullName

        public java.lang.String fullName()
        Description copied from class: JType
        Gets the full name of the type. See http://java.sun.com/docs/books/jls/second_edition/html/names.doc.html#25430 for the details.
        Specified by:
        fullName in class JType
        Returns:
        Strings like "int", "java.lang.String", "java.io.File[]". Never null.
      • name

        public java.lang.String name()
        Description copied from class: JType
        Gets the name of this type.
        Specified by:
        name in class JType
        Returns:
        Names like "int", "void", "BigInteger".
      • isPrimitive

        public boolean isPrimitive()
        Description copied from class: JType
        Tell whether or not this is a built-in primitive type, such as int or void.
        Overrides:
        isPrimitive in class JType
      • 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
      • boxify

        public JClass boxify()
        Obtains the wrapper class for this primitive type. For example, this method returns a reference to java.lang.Integer if this object represents int.
        Specified by:
        boxify in class JType
      • unboxify

        public JType unboxify()
        Deprecated.
        calling this method from JPrimitiveType would be meaningless, since it's always guaranteed to return this.
        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
      • getWrapperClass

        public JClass getWrapperClass()
        Deprecated.
      • wrap

        public JExpression wrap​(JExpression exp)
        Wraps an expression of this type to the corresponding wrapper class. For example, if this class represents "float", this method will return the expression new Float(x) for the paramter x. REVISIT: it's not clear how this method works for VOID.
      • unwrap

        public JExpression unwrap​(JExpression exp)
        Do the opposite of the wrap method. REVISIT: it's not clear how this method works for VOID.
      • generate

        public void generate​(JFormatter f)