Class TypeResolver


  • public class TypeResolver
    extends java.lang.Object
    Resolves declared types to dynamic Java classes (just attributes).
    Author:
    Holger Eichelberger, SSE
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.util.Map<java.lang.String,​java.lang.Class<?>> classes  
      private java.lang.ClassLoader loader  
      private static java.util.Map<java.lang.String,​java.lang.Class<?>> PRIMITIVES  
    • Constructor Summary

      Constructors 
      Constructor Description
      TypeResolver​(java.util.List<? extends Type> declarations)
      Creates a type resolver and creates internal classes for declarations.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      private boolean createClasses​(Type type)
      Creates the classes for a given descriptor-defined type.
      private java.util.List<Type> createClasses​(java.util.List<? extends Type> declarations)
      Creates classes for all given type declarations.
      static boolean isPrimitive​(java.lang.String name)
      Returns whether a given type name is considered to be pre-defined/primitive (including "String").
      java.lang.Class<?> resolve​(java.lang.String name)
      Resolve a type name to a type.
      • Methods inherited from class java.lang.Object

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

      • PRIMITIVES

        private static final java.util.Map<java.lang.String,​java.lang.Class<?>> PRIMITIVES
      • classes

        private java.util.Map<java.lang.String,​java.lang.Class<?>> classes
      • loader

        private java.lang.ClassLoader loader
    • Constructor Detail

      • TypeResolver

        public TypeResolver​(java.util.List<? extends Type> declarations)
        Creates a type resolver and creates internal classes for declarations.
        Parameters:
        declarations - the type declarations to be used as descriptor-defined types
    • Method Detail

      • createClasses

        private java.util.List<Type> createClasses​(java.util.List<? extends Type> declarations)
        Creates classes for all given type declarations.
        Parameters:
        declarations - the declarations
        Returns:
        the left-over types that cannot be resolved, e.g., due to cyclic dependencies; empty if completely successful
      • isPrimitive

        public static boolean isPrimitive​(java.lang.String name)
        Returns whether a given type name is considered to be pre-defined/primitive (including "String").
        Parameters:
        name - the name to look for
        Returns:
        true for primitive/pre-defined, false else
      • createClasses

        private boolean createClasses​(Type type)
        Creates the classes for a given descriptor-defined type.
        Parameters:
        type - the type
        Returns:
        true if the type is resolvable, the class was created and registered; false if the resolution failed, e.g., as required types are not (yet) defined.
      • resolve

        public java.lang.Class<?> resolve​(java.lang.String name)
        Resolve a type name to a type. Considers pre-defined types (PRIMITIVES) as well as descriptor-defined types used as input to this instance.
        Parameters:
        name - the type name
        Returns:
        the type, may be null