Class Types

java.lang.Object
org.apache.calcite.linq4j.tree.Types

public abstract class Types extends Object
Utilities for converting between Expression, Type and Class.
See Also:
  • Method Details

    • of

      public static Type of(Type type, Type... typeArguments)
      Creates a type with generic parameters.
    • getElementType

      public static @Nullable Type getElementType(Type type)
      Returns the element type of a Collection, Iterable (including Queryable and Enumerable), Iterator, Enumerator, or an array.

      Returns null if the type is not one of these.

    • toClass

      public static Class toClass(Type type)
    • toClassArray

      public static Class[] toClassArray(Iterable<? extends Expression> arguments)
    • getComponentType

      public static @Nullable Type getComponentType(Type type)
      Returns the component type of an array.
    • box

      public static Type box(Type type)
    • unbox

      public static Type unbox(Type type)
    • isAssignableFrom

      public static boolean isAssignableFrom(Type type0, Type type)
    • isArray

      public static boolean isArray(Type type)
    • nthField

      public static Field nthField(int ordinal, Class clazz)
    • nthField

      public static PseudoField nthField(int ordinal, Type clazz)
    • allAssignable

      public static boolean allAssignable(boolean varArgs, Class[] parameterTypes, Class[] argumentTypes)
    • lookupMethod

      public static Method lookupMethod(Class clazz, String methodName, Class... argumentTypes)
      Finds a method of a given name that accepts a given set of arguments. Includes in its search inherited methods and methods with wider argument types.
      Parameters:
      clazz - Class against which method is invoked
      methodName - Name of method
      argumentTypes - Types of arguments
      Returns:
      A method with the given name that matches the arguments given
      Throws:
      RuntimeException - if method not found
    • lookupConstructor

      public static Constructor lookupConstructor(Type type, Class... argumentTypes)
      Finds a constructor of a given class that accepts a given set of arguments. Includes in its search methods with wider argument types.
      Parameters:
      type - Class against which method is invoked
      argumentTypes - Types of arguments
      Returns:
      A method with the given name that matches the arguments given
      Throws:
      RuntimeException - if method not found
    • lookupField

      public static Field lookupField(Type type, String name)
    • discard

      public static void discard(Object o)
    • castIfNecessary

      public static Expression castIfNecessary(Type returnType, Expression expression)
      Wraps an expression in a cast if it is not already of the desired type, or cannot be implicitly converted to it.
      Parameters:
      returnType - Desired type
      expression - Expression
      Returns:
      Expression of desired type
    • needTypeCast

      public static boolean needTypeCast(Type fromType, Type toType)
      When trying to cast/convert a Type to another Type, it is necessary to pre-check whether the cast operation is needed. We summarize general exceptions, including:
      1. target Type toType equals with original Type fromType
      2. target Type can be assignable from original Type
      3. target Type is an instance of RecordType, since the mapping Java Class might not generated yet
      Parameters:
      fromType - original type
      toType - target type
      Returns:
      Whether a cast operation is needed
    • field

      public static PseudoField field(Field field)
    • stripGenerics

      public static Type stripGenerics(Type type)