Get template of map class from generic type

@param actualTypeArguments
@return
180363
String getTemplateOfMap(Type[] actualTypeArguments, IJsonMarshaller jsonMarshaller) {
		StringBuilder res = new StringBuilder("{");
		boolean first = true;
		for (Type actualTypeArgument : actualTypeArguments) {
			if (!first) {
				res.append(":");
			}
			res.append(_getTemplateOfType(actualTypeArgument, jsonMarshaller));
			first = false;
		}
		res.append("}");
		return res.toString();
	}
701720
public static Class<?> getTypeParameter(Class<?> genericType, Class<?> type) {
        Type[] genericInterfaces = type.getGenericInterfaces();
        for (Type genericInterface : genericInterfaces) {
            if (genericInterface instanceof ParameterizedType) {
                ParameterizedType parameterizedType = (ParameterizedType) genericInterface;
                if (genericType.equals(parameterizedType.getRawType())) {
                    Type typeParameter = ((ParameterizedType) genericInterface).getActualTypeArguments()[0];
                    if (typeParameter instanceof Class<?>) {
                        return (Class<?>) typeParameter;
                    }
                }
            }
        }
        return null;
    }
1371544
@SuppressWarnings("unchecked")
    public <T> FieldFormatter<T> getFormatter(final Class<T> requiredType) {
        return (FieldFormatter<T>)typeMap.get(requiredType);
    }
709121
private static Optional<Class> resolveSingleTypeArgument(Type genericType) {
        if (genericType instanceof ParameterizedType) {
            ParameterizedType pt = (ParameterizedType) genericType;
            Type[] actualTypeArguments = pt.getActualTypeArguments();
            if (actualTypeArguments.length == 1) {
                Type actualTypeArgument = actualTypeArguments[0];
                return resolveParameterizedTypeArgument(actualTypeArgument);
            }
        }
        return Optional.empty();
    }
411511
public static <T> TemplateExpression<T> template(Class<? extends T> cl, String template, Object... args) {
        return template(cl, TemplateFactory.DEFAULT.create(template), ImmutableList.copyOf(args));
    }
1025402
private Map<String, JSType> buildTypeVariables(
      Map<TemplateType, JSType> inferredTypes) {
    Map<String, JSType> typeVars = new LinkedHashMap<>();
    for (Entry<TemplateType, JSType> e : inferredTypes.entrySet()) {
      // Only add the template type that do not have a type transformation
      if (!e.getKey().isTypeTransformation()) {
        typeVars.put(e.getKey().getReferenceName(), e.getValue());
      }
    }
    return typeVars;
  }
1059929
public static Class<?> getRawType(Type type) {
		if (type instanceof Class) {
			return (Class<?>) type;
		} else if (type instanceof ParameterizedType) {
			ParameterizedType actualType = (ParameterizedType) type;
			return getRawType(actualType.getRawType());
		} else if (type instanceof GenericArrayType) {
			GenericArrayType genericArrayType = (GenericArrayType) type;
			Object rawArrayType = Array.newInstance(getRawType(genericArrayType
					.getGenericComponentType()), 0);
			return rawArrayType.getClass();
		} else if (type instanceof WildcardType) {
			WildcardType castedType = (WildcardType) type;
			return getRawType(castedType.getUpperBounds()[0]);
		} else {
			throw new IllegalArgumentException(
					"Type \'"
							+ type
							+ "\' is not a Class, "
							+ "ParameterizedType, or GenericArrayType. Can't extract class.");
		}
	}
441212
@SuppressWarnings("unchecked")
	public static <K, V> Map<K, V> createMap(Class<?> mapType) {
		if (mapType.isAssignableFrom(AbstractMap.class)) {
			return new HashMap<>();
		} else {
			return (Map<K, V>) ReflectUtil.newInstance(mapType);
		}
	}
300499
public static Type getTypeArgument(Type type) {
        if (!(type instanceof ParameterizedType)) {
            return null;
        }
        return ((ParameterizedType) type).getActualTypeArguments()[0];
    }
704282
public static PredicateTemplate predicateTemplate(Template template, List<?> args) {
        return new PredicateTemplate(template, ImmutableList.copyOf(args));
    }
296889
@NotNull
    protected  Map<String, Map<String, Object>>  toTypeArguments(ParameterElement... parameters) {
        final LinkedHashMap<String, Map<String, Object>>  map = new LinkedHashMap<>(parameters.length);
        for (ParameterElement ce : parameters) {
            final ClassElement type = ce.getType();
            if (type == null) {
                continue;
            }
            final Map<String, ClassElement> subArgs = type.getTypeArguments();
            if (CollectionUtils.isNotEmpty(subArgs)) {
                map.put(ce.getName(), toTypeArguments(subArgs));
            }
        }
        return map;
    }
320321
private String genericTypeAsString(GenericsType genericsType, boolean showRedirect) {
        String ret = genericsType.getName();
        if (genericsType.getUpperBounds() != null) {
            ret += " extends ";
            for (int i = 0; i < genericsType.getUpperBounds().length; i++) {
                ClassNode classNode = genericsType.getUpperBounds()[i];
                if (classNode.equals(this)) {
                    ret += classNode.getName();
                } else {
                    ret += classNode.toString(showRedirect);
                }
                if (i + 1 < genericsType.getUpperBounds().length) ret += " & ";
            }
        } else if (genericsType.getLowerBound() !=null) {
            ClassNode classNode = genericsType.getLowerBound();
            if (classNode.equals(this)) {
                ret += " super " + classNode.getName();
            } else {
                ret += " super " + classNode;
            }
        }
        return ret;
    }
1019458
public static <T> DslTemplate<T> dslTemplate(Class<? extends T> cl, String template, List<?> args) {
        return dslTemplate(cl, createTemplate(template), args);
    }
528927
@SuppressWarnings("unchecked")
  public static <T extends Map<?, ?>> T newMap(Type type)
  {
    Class<?> implementation = MAPS.get(type);
    if(implementation == null) {
      throw new BugError("No registered implementation for map |%s|.", type);
    }
    return (T)newInstance(implementation);
  }
1074357
static Type getRawType(Type genericType, Map<TypeVariable, Type> typeVariableMap) {
		Type resolvedType = genericType;
		if (genericType instanceof TypeVariable) {
			TypeVariable tv = (TypeVariable) genericType;
			resolvedType = typeVariableMap.get(tv);
			if (resolvedType == null) {
				resolvedType = extractBoundForTypeVariable(tv);
			}
		}
		if (resolvedType instanceof ParameterizedType) {
			return ((ParameterizedType) resolvedType).getRawType();
		}
		else {
			return resolvedType;
		}
	}
161978
@SuppressWarnings("PMD.LooseCoupling")
    public static LinkedHashMap<String, Type> createGenericsMap(final Class<?> type,
                                                                final List<? extends Type> generics) {
        final TypeVariable<? extends Class<?>>[] params = type.getTypeParameters();
        if (params.length != generics.size()) {
            throw new IllegalArgumentException(String.format(
                    "Can't build generics map for %s with %s because of incorrect generics count",
                    type.getSimpleName(), Arrays.toString(generics.toArray())));
        }
        final LinkedHashMap<String, Type> res = new LinkedHashMap<String, Type>();
        int i = 0;
        for (TypeVariable var : params) {
            res.put(var.getName(), generics.get(i++));
        }
        // add possible outer class generics to avoid unknown generics
        return GenericsResolutionUtils.fillOuterGenerics(type, res, null);
    }
1371969
@Override
	protected Map<JvmTypeParameter, LightweightMergedBoundTypeArgument> getTypeParameterMapping() {
		if (typeParameterMapping == null) {
			typeParameterMapping = initializeTypeParameterMapping();
		}
		return typeParameterMapping;
	}