Package com.esotericsoftware.kryo

Examples of com.esotericsoftware.kryo.Generics


      } else
        break;
    }

    if (typeParams != null && typeParams.length > 0) {
      Generics genScope;
      trace("kryo", "Class " + clazz.getName() + " has generic type parameters");
      int typeVarNum = 0;
      Map<String, Class> typeVar2concreteClass;
      typeVar2concreteClass = new HashMap<String, Class>();
      for (TypeVariable typeVar : typeParams) {
        String typeVarName = typeVar.getName();
        if (TRACE) {
          trace("kryo", "Type parameter variable: name=" + typeVarName + " type bounds=" + Arrays.toString(typeVar.getBounds()));
        }

        final Class<?> concreteClass = getTypeVarConcreteClass(generics, typeVarNum, typeVarName);
        if (concreteClass != null) {
          typeVar2concreteClass.put(typeVarName, concreteClass);
          if (TRACE) trace("kryo", "Concrete type used for " + typeVarName + " is: " + concreteClass.getName());
        }

        typeVarNum++;
      }
      genScope = new Generics(typeVar2concreteClass);
      return genScope;
    } else
      return null;
  }
View Full Code Here


      // If passed concrete classes are known explicitly, use this information
      return generics[typeVarNum];
    } else {
      // Otherwise try to derive the information from the current GenericScope
      if (TRACE) trace("kryo", "Trying to use kryo.getGenericScope");
      Generics scope = kryo.getGenericsScope();
      if (scope != null) {
        return scope.getConcreteClass(typeVarName);
      }
    }
    return null;
  }
View Full Code Here

            else if (t instanceof GenericArrayType) {
              Type componentType = ((GenericArrayType)t).getGenericComponentType();
              if (componentType instanceof Class)
                fieldGenerics[i] = Array.newInstance((Class)componentType, 0).getClass();
              else if (componentType instanceof TypeVariable) {
                Generics scope = serializer.getGenericsScope();
                if (scope != null) {
                  Class clazz = scope.getConcreteClass(((TypeVariable)componentType).getName());
                  if (clazz != null) {
                    fieldGenerics[i] = Array.newInstance(clazz, 0).getClass();
                  }
                }
              }
View Full Code Here

    // Get list of field specific concrete classes passed as generic parameters
    Class[] cachedFieldGenerics = FieldSerializerGenericsUtil.getGenerics(fieldGenericType, kryo);

    // Build a generics scope for this field
    Generics scope = buildGenericsScope(fieldClass[0], cachedFieldGenerics);

    // Is it a field of a generic parameter type, i.e. "T field"?
    if (fieldClass[0] == Object.class && fieldGenericType instanceof TypeVariable && serializer.getGenericsScope() != null) {
      TypeVariable typeVar = (TypeVariable)fieldGenericType;
      // Obtain information about a concrete type of a given variable from the environment
      Class concreteClass = serializer.getGenericsScope().getConcreteClass(typeVar.getName());
      if (concreteClass != null) {
        scope = new Generics();
        scope.add(typeVar.getName(), concreteClass);
      }
    }

    if (TRACE) {
      trace("kryo", "Generics scope of field '" + field.getName() + "' of class " + fieldGenericType + " is " + scope);
View Full Code Here

      if (actualType instanceof Class)
        generics[i] = (Class)actualType;
      else if (actualType instanceof ParameterizedType)
        generics[i] = (Class)((ParameterizedType)actualType).getRawType();
      else if (actualType instanceof TypeVariable) {
        Generics scope = kryo.getGenericsScope();
        if (scope != null) {
          Class clazz = scope.getConcreteClass(((TypeVariable)actualType).getName());
          if (clazz != null) {
            generics[i] = clazz;
          } else
            continue;
        } else
          continue;
      } else if (actualType instanceof GenericArrayType) {
        Type componentType = ((GenericArrayType)actualType).getGenericComponentType();
        if (componentType instanceof Class)
          generics[i] = Array.newInstance((Class)componentType, 0).getClass();
        else if (componentType instanceof TypeVariable) {
          Generics scope = kryo.getGenericsScope();
          if (scope != null) {
            Class clazz = scope.getConcreteClass(((TypeVariable)componentType).getName());
            if (clazz != null) {
              generics[i] = Array.newInstance(clazz, 0).getClass();
            }
          }
        } else {
View Full Code Here

    hasObjectFields = false;

    // For generic classes, generate a mapping from type variable names to the concrete types
    // This mapping is the same for the whole class.
    Generics genScope = genericsUtil.buildGenericsScope(type, generics);
    genericsScope = genScope;

    // Push proper scopes at serializer construction time
    if (genericsScope != null) kryo.pushGenericsScope(type, genericsScope);
View Full Code Here

    hasObjectFields = false;

    // For generic classes, generate a mapping from type variable names to the concrete types
    // This mapping is the same for the whole class.
    Generics genScope = genericsUtil.buildGenericsScope(type, generics);
    genericsScope = genScope;

    // Push proper scopes at serializer construction time
    if (genericsScope != null) kryo.pushGenericsScope(type, genericsScope);
View Full Code Here

    hasObjectFields = false;

    // For generic classes, generate a mapping from type variable names to the concrete types
    // This mapping is the same for the whole class.
    Generics genScope = genericsUtil.buildGenericsScope(type, generics);
    genericsScope = genScope;

    // Push proper scopes at serializer construction time
    if (genericsScope != null) kryo.pushGenericsScope(type, genericsScope);
View Full Code Here

    hasObjectFields = false;

    // For generic classes, generate a mapping from type variable names to the concrete types
    // This mapping is the same for the whole class.
    Generics genScope = genericsUtil.buildGenericsScope(type, generics);
    genericsScope = genScope;

    // Push proper scopes at serializer construction time
    if (genericsScope != null) kryo.pushGenericsScope(type, genericsScope);
View Full Code Here

      } else
        break;
    }

    if (typeParams != null && typeParams.length > 0) {
      Generics genScope;
      trace("kryo", "Class " + clazz.getName() + " has generic type parameters");
      int typeVarNum = 0;
      Map<String, Class> typeVar2concreteClass;
      typeVar2concreteClass = new HashMap<String, Class>();
      for (TypeVariable typeVar : typeParams) {
        String typeVarName = typeVar.getName();
        if (TRACE) {
          trace("kryo", "Type parameter variable: name=" + typeVarName + " type bounds=" + Arrays.toString(typeVar.getBounds()));
        }

        final Class<?> concreteClass = getTypeVarConcreteClass(generics, typeVarNum, typeVarName);
        if (concreteClass != null) {
          typeVar2concreteClass.put(typeVarName, concreteClass);
          if (TRACE) trace("kryo", "Concrete type used for " + typeVarName + " is: " + concreteClass.getName());
        }

        typeVarNum++;
      }
      genScope = new Generics(typeVar2concreteClass);
      return genScope;
    } else
      return null;
  }
View Full Code Here

TOP

Related Classes of com.esotericsoftware.kryo.Generics

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.