Class JavaTypeUtil


  • public final class JavaTypeUtil
    extends java.lang.Object
    Util containing some helper methods dealing with Java types.
    Author:
    Rene Schneider - initial API and implementation
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.lang.reflect.ParameterizedType findGenericInterfaceOrSuperType​(java.lang.reflect.Type aType, java.lang.Class<?> aGenericInterfaceClass)
      Searches a class and attempts to find a generic superinterface of a certain type.
      static java.util.List<org.eclipse.xtext.common.types.JvmEnumerationLiteral> getAllEnumLiteralsFromJvmType​(org.eclipse.xtext.common.types.JvmType aType)
      Returns a list of all valid enumeration literals that are defined in the given type.
      static java.lang.String getBasicClassNameFromJvmType​(org.eclipse.xtext.common.types.JvmType aType)
      Resolves a JvmType to its basic class name (= without array indicators, even if the JvmType is an JvmArrayType).
      static org.eclipse.xtext.common.types.JvmType getBasicTypeFromJvmType​(org.eclipse.xtext.common.types.JvmType aType)
      Returns the underlying basic JvmType for the provided JvmType.
      static java.lang.String getReadableJavaTypeName​(java.lang.String aQualifiedTypeName)
      Determines the readable java type name for the provided qualified name.
      static java.lang.String getReadableJavaTypeName​(org.eclipse.xtext.common.types.JvmType aType)
      Determines the readable java type name for the provided JvmType.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • findGenericInterfaceOrSuperType

        public static java.lang.reflect.ParameterizedType findGenericInterfaceOrSuperType​(java.lang.reflect.Type aType,
                                                                                          java.lang.Class<?> aGenericInterfaceClass)
        Searches a class and attempts to find a generic superinterface of a certain type. The result can be used to acquire the generic parameters of a class.
        Parameters:
        aType - the type to inspect
        aGenericInterfaceClass - the generic interface to search for (may be null, in which case the first generic superinterface that is found is returned)
        Returns:
        the ParameterizedType, if found, otherwise null
      • getReadableJavaTypeName

        public static java.lang.String getReadableJavaTypeName​(java.lang.String aQualifiedTypeName)
        Determines the readable java type name for the provided qualified name. Returns short (non-fully-qualified) names for all the common Java types and fully qualified names for everything else.
        Parameters:
        aQualifiedTypeName - the type to investigate
        Returns:
        the name
      • getReadableJavaTypeName

        public static java.lang.String getReadableJavaTypeName​(org.eclipse.xtext.common.types.JvmType aType)
        Determines the readable java type name for the provided JvmType. Returns short (non-fully-qualified) names for all the common Java types and fully qualified names for everything else.
        Parameters:
        aType - the type to investigate
        Returns:
        the name
      • getBasicClassNameFromJvmType

        public static java.lang.String getBasicClassNameFromJvmType​(org.eclipse.xtext.common.types.JvmType aType)
        Resolves a JvmType to its basic class name (= without array indicators, even if the JvmType is an JvmArrayType).
        Parameters:
        aType - the type to resolve
        Returns:
        the fully-qualified class name of the type
      • getBasicTypeFromJvmType

        public static org.eclipse.xtext.common.types.JvmType getBasicTypeFromJvmType​(org.eclipse.xtext.common.types.JvmType aType)
        Returns the underlying basic JvmType for the provided JvmType. This strips out JvmArrayTypes and resolves them to the component type.
        Parameters:
        aType - the type to resolve
        Returns:
        the basic type
      • getAllEnumLiteralsFromJvmType

        public static java.util.List<org.eclipse.xtext.common.types.JvmEnumerationLiteral> getAllEnumLiteralsFromJvmType​(org.eclipse.xtext.common.types.JvmType aType)
        Returns a list of all valid enumeration literals that are defined in the given type.
        Parameters:
        aType - the type
        Returns:
        the enumeration literals, or none if the type reference doesn't refer to an enum type