Parse type variables for generics

@param typeVariable
@return
421442
protected TypeParameter parseTypeParameter(TypeVariable typeVariable) {
		TypeParameter typeParameter = objectFactory.createTypeParameter();
		typeParameter.setName(typeVariable.typeName());

		for (Type bound : typeVariable.bounds()) {
			typeParameter.getBound().add(bound.qualifiedTypeName());
		}

		return typeParameter;
	}
252091
public static <T extends Enum<T>> EnumPath<T> enumPath(Class<? extends T> type, String variable) {
        return new EnumPath<T>(type, PathMetadataFactory.forVariable(variable));
    }
715184
public static TypeVariableResolver build(TypeElement element)
	{
		List<TypeName> typeArgs = TypeUtility.getTypeArguments(element);
		Map<String, TypeName> typeVariableMap=new HashMap<>();
		
		BindTypeVariables annotationBeanType = element.getAnnotation(BindTypeVariables.class);
		List<String> typeVariables = new ArrayList<String>();
		if (annotationBeanType != null) {
			typeVariables = Arrays.asList(annotationBeanType.value());
		}
		
		List<String> typeParameters = AnnotationUtility.extractAsClassNameArray(BindTypeSubProcessor.elementUtils, element, BindTypeVariables.class, AnnotationAttributeType.TYPE_PARAMETERS);

		AssertKripton.assertTrue(typeVariables.size() >= typeParameters.size(), "%s '%s' has incorrect definition of type variables/parameters on annotation @BindTypeVariables",
				element.getKind()==ElementKind.CLASS ? "Class" :"Interface", element.asType());

		if (typeVariables.size() > 0) {
			String[] temp;

			AssertKripton.assertTrue((typeParameters.size() == 0) || (typeVariables.size() == typeParameters.size()),
					"%s '%s' has an incorrect definition of type variables/parameters on annotation @BindTypeVariables(typeVariables, typeParameters)", element.getKind()==ElementKind.CLASS ? "Class" :"Interface", element.asType());

			if (StringUtils.hasText(typeVariables.get(0))) {
				int i = 0;
				for (String key : typeVariables) {
					if (StringUtils.hasText(key)) {
						temp = key.split(",");
						for (String alias : temp) {
							if (typeParameters.size() > 0) {
								typeVariableMap.put(alias.trim(), TypeUtility.typeName(typeParameters.get(i)));
							} else {
								typeVariableMap.put(alias.trim(), typeArgs.get(i));
							}
						}
					}
					i++;
				}

			} else {
				AssertKripton.assertTrue(typeVariableMap == null && typeArgs.size() < 2, "%s '%s' use more than one type variables in its class hierarchy. Try to use @BindTypeVariables",
						element.getKind()==ElementKind.CLASS ? "Class" :"Interface", element.asType());
			}
		}
		
		
		return new TypeVariableResolver(element, typeArgs, typeVariableMap);
	}
120223
static function typecastVariable($variable, string $type) {
        if($variable === null) {
            return null;
        }
        
        switch($type) {
            case 'array':
                $variable = (array) $variable;
            break;
            case 'bool':
                $variable = (bool) $variable;
            break;
            case 'float':
                $variable = (float) $variable;
            break;
            case 'int':
                $variable = (int) $variable;
            break;
            case 'string':
                $variable = (string) $variable;
            break;
            default:
                throw new \InvalidArgumentException('Unsupported type "'.$type.'"');
            break;
        }
        
        return $variable;
    }
1184822
private static Class<?> extractGeneric(Type type) {
        if (type instanceof ParameterizedType) {
            Type[] genericTypes = ((ParameterizedType) type).getActualTypeArguments();
            if (genericTypes.length > 0 && genericTypes[0] instanceof Class) {
                return (Class<?>) genericTypes[0];
            }
        }
        return Object.class;
    }
378100
public static <T> DslPath<T> dslPath(Class<? extends T> type, String variable) {
        return new DslPath<T>(type, PathMetadataFactory.forVariable(variable));
    }
1089558
public static IType parseTypeLiteral(String typeName) {
    try {
      IType type = GosuParserFactory.createParser(typeName).parseTypeLiteral(null).getType().getType();
      if (type instanceof IErrorType) {
        throw new RuntimeException("Type not found: " + typeName);
      }
      return type;
    } catch (ParseResultsException e) {
      throw new RuntimeException("Type not found: " + typeName, e);
    }
  }
1248882
public static Type[] getParameterTypes(Type generic) {
		Type[] types = null;
		if(isGeneric(generic)) {
			types = ((ParameterizedType)generic).getActualTypeArguments();
		}
		return types;
	}
777514
public static SymbolType typeVariableOf(final String typeVariable, List<SymbolType> upperBounds) {
        return new SymbolType(upperBounds, typeVariable);
    }
1080253
protected List<TypeNameWithArity> createTypeArityList(
      TypeName t, String extractVariableName, int maxArity) {
    TypeName u = match(t)
        .when(typeOf(TypeVariableName.class))
        .get(x -> (TypeName) TypeVariableName.get("E" + x.name, x))
        .orElse(x -> x)
        .getMatch();

    List<TypeNameWithArity> typeArityList = new ArrayList<>();
    //typeArityList.add(TypeNameWithArity.of(t, 0));
    typeArityList.add(TypeNameWithArity.of(ParameterizedTypeName.get(MATCH_EXACT, t), 0));
    typeArityList.add(TypeNameWithArity.of(ParameterizedTypeName.get(MATCH_ANY, t), 1));
    //typeArityList.add(TypeNameWithArity.of(TypeName.get(MatchesAny.class), 1));
    IntStream.rangeClosed(0, maxArity).forEach(
        extractArity -> {
          TypeName[] typeVariables = createTypeVariables(u, extractVariableName, extractArity);
          typeArityList.add(
              TypeNameWithArity.of(
                  ParameterizedTypeName
                      .get(
                          ClassName.get(getDecomposableBuilderByArity(extractArity)),
                          typeVariables), extractArity));
        });

    return typeArityList;
  }
230505
public static <T extends Comparable<?>> DatePath<T> datePath(Class<? extends T> type, String variable) {
        return new DatePath<T>(type, PathMetadataFactory.forVariable(variable));
    }
937923
public static Map<TypeVariable, Type> getTypeVariableMap(Class<?> clazz) {
		Map<TypeVariable, Type> typeVariableMap = typeVariableCache.get(clazz);

		if (typeVariableMap == null) {
			typeVariableMap = new HashMap<TypeVariable, Type>();

			// interfaces
			extractTypeVariablesFromGenericInterfaces(clazz.getGenericInterfaces(), typeVariableMap);

			try {
				// super class
				Class<?> type = clazz;
				while (type.getSuperclass() != null && !Object.class.equals(type.getSuperclass())) {
					Type genericType = type.getGenericSuperclass();
					if (genericType instanceof ParameterizedType) {
						ParameterizedType pt = (ParameterizedType) genericType;
						populateTypeMapFromParameterizedType(pt, typeVariableMap);
					}
					extractTypeVariablesFromGenericInterfaces(type.getSuperclass().getGenericInterfaces(), typeVariableMap);
					type = type.getSuperclass();
				}
			}
			catch (MalformedParameterizedTypeException ex) {
				// from getGenericSuperclass() - ignore and continue with member class check
			}

			try {
				// enclosing class
				Class<?> type = clazz;
				while (type.isMemberClass()) {
					Type genericType = type.getGenericSuperclass();
					if (genericType instanceof ParameterizedType) {
						ParameterizedType pt = (ParameterizedType) genericType;
						populateTypeMapFromParameterizedType(pt, typeVariableMap);
					}
					type = type.getEnclosingClass();
				}
			}
			catch (MalformedParameterizedTypeException ex) {
				// from getGenericSuperclass() - ignore and preserve previously accumulated type variables
			}

			typeVariableCache.put(clazz, typeVariableMap);
		}

		return typeVariableMap;
	}
428557
private static <T> void mapTypeVariablesToArguments(final Class<T> cls,
            final ParameterizedType parameterizedType, final Map<TypeVariable<?>, Type> typeVarAssigns) {
        // capture the type variables from the owner type that have assignments
        final Type ownerType = parameterizedType.getOwnerType();

        if (ownerType instanceof ParameterizedType) {
            // recursion to make sure the owner's owner type gets processed
            mapTypeVariablesToArguments(cls, (ParameterizedType) ownerType, typeVarAssigns);
        }

        // parameterizedType is a generic interface/class (or it's in the owner
        // hierarchy of said interface/class) implemented/extended by the class
        // cls. Find out which type variables of cls are type arguments of
        // parameterizedType:
        final Type[] typeArgs = parameterizedType.getActualTypeArguments();

        // of the cls's type variables that are arguments of parameterizedType,
        // find out which ones can be determined from the super type's arguments
        final TypeVariable<?>[] typeVars = getRawType(parameterizedType).getTypeParameters();

        // use List view of type parameters of cls so the contains() method can be used:
        final List<TypeVariable<Class<T>>> typeVarList = Arrays.asList(cls
                .getTypeParameters());

        for (int i = 0; i < typeArgs.length; i++) {
            final TypeVariable<?> typeVar = typeVars[i];
            final Type typeArg = typeArgs[i];

            // argument of parameterizedType is a type variable of cls
            if (typeVarList.contains(typeArg)
            // type variable of parameterizedType has an assignment in
                    // the super type.
                    && typeVarAssigns.containsKey(typeVar)) {
                // map the assignment to the cls's type variable
                typeVarAssigns.put((TypeVariable<?>) typeArg, typeVarAssigns.get(typeVar));
            }
        }
    }
61849
def infer_typing_typevar_or_newtype(node, context=None):
    """"""
    try:
        func = next(node.func.infer(context=context))
    except InferenceError as exc:
        raise UseInferenceDefault from exc

    if func.qname() not in TYPING_TYPEVARS_QUALIFIED:
        raise UseInferenceDefault
    if not node.args:
        raise UseInferenceDefault

    typename = node.args[0].as_string().strip("'")
    node = extract_node(TYPING_TYPE_TEMPLATE.format(typename))
    return node.infer(context=context)
207952
public static <T> Path<T> path(Class<? extends T> type, String variable) {
        return new PathImpl<T>(type, variable);
    }
1091076
protected void enterTypevars(Type t) {
        if (t.getEnclosingType() != null && t.getEnclosingType().hasTag(CLASS))
            enterTypevars(t.getEnclosingType());
        for (List<Type> xs = t.getTypeArguments(); xs.nonEmpty(); xs = xs.tail)
            typevars.enter(xs.head.tsym);
    }
788842
private static void buildTypeVariableMap(ParameterizedType type,
                                             Map<TypeVariable<?>, Type> typeVariableMap) {
        if (type.getRawType() instanceof Class) {
            TypeVariable<?>[] typeVariables = ((Class<?>) type.getRawType()).getTypeParameters();
            Type[] typeArguments = type.getActualTypeArguments();

            for (int i = 0; i < typeArguments.length; i++) {
                TypeVariable<?> variable = typeVariables[i];
                Type typeArgument = typeArguments[i];

                if (typeArgument instanceof Class) {
                    typeVariableMap.put(variable, typeArgument);
                } else if (typeArgument instanceof GenericArrayType) {
                    typeVariableMap.put(variable, typeArgument);
                } else if (typeArgument instanceof ParameterizedType) {
                    typeVariableMap.put(variable, typeArgument);
                } else if (typeArgument instanceof TypeVariable) {
                    TypeVariable<?> typeVariableArgument = (TypeVariable<?>) typeArgument;
                    Type resolvedType = typeVariableMap.get(typeVariableArgument);
                    if (resolvedType == null)
                        resolvedType = resolveBound(typeVariableArgument);
                    typeVariableMap.put(variable, resolvedType);
                }
            }
        }
    }