Resolves the arguments for the {@code genericType} using the type variable information for the
{@code targetType}. Returns {@code null} if {@code genericType} is not parameterized or if
arguments cannot be resolved.
556543
public static Class<?>[] resolveArguments(Type genericType, Class<?> targetType) {
        Class<?>[] result = null;

        if (genericType instanceof ParameterizedType) {
            ParameterizedType paramType = (ParameterizedType) genericType;
            Type[] arguments = paramType.getActualTypeArguments();
            result = new Class[arguments.length];
            for (int i = 0; i < arguments.length; i++)
                result[i] = resolveClass(arguments[i], targetType);
        } else if (genericType instanceof TypeVariable) {
            result = new Class[1];
            result[0] = resolveClass(genericType, targetType);
        }

        return result;
    }
661306
public TypeName resolve(TypeName inputType) {
		if (!hasTypeVariables())
			return inputType;
		
		if (inputType.isPrimitive() || inputType.isBoxedPrimitive() || inputType.equals(TypeName.get(String.class))) {
			return inputType;
		}
		
		if (TypeName.VOID.equals(inputType)) return inputType;
		
		TypeName resolved=null;
		if (inputType instanceof ParameterizedTypeName)
		{
			ParameterizedTypeName inputParametrizedTypeName=(ParameterizedTypeName)inputType;
			
			TypeName[] typeArguments=new TypeName[inputParametrizedTypeName.typeArguments.size()];
			int i=0;
			for (TypeName item: inputParametrizedTypeName.typeArguments)
			{
				typeArguments[i]=resolve(item);
				i++;
			}
			
			resolved=ParameterizedTypeName.get((ClassName)resolve(inputParametrizedTypeName.rawType), typeArguments);
			
			return resolved;
		} else if (inputType instanceof ArrayTypeName)
		{
			ArrayTypeName inputTypeName=(ArrayTypeName)inputType;
			
			resolved=ArrayTypeName.of(resolve(inputTypeName.componentType));
			
			return resolved;
		} else {
			// it's not a type variable
			if (inputType.toString().contains(".")) {
				return inputType;
			}
			// ASSERT: simple typeName 
			if (typeVariableMap.containsKey(inputType.toString())) {
				TypeName type = typeVariableMap.get(inputType.toString());
				return type;
			} else if (declaredTypeArgumentList.size()==1){
				resolved = declaredTypeArgumentList.get(0);
				// if we found an unique type variable, we use it.
				//typeVariableMap = new HashMap<>();
				//typeVariableMap.put(inputTypeName.toString(), resolved);

				return resolved;
			}
			
			AssertKripton.assertTrue(false, "In type hierarchy of %s '%s' there is a unresolved type variable named '%s'. Define it with @BindTypeVariables", element.getKind()==ElementKind.CLASS ? "class" :"interface", element.getQualifiedName(),
					inputType.toString());
			
			return resolved;
		}
		
	}
221165
private Map<String, TypeVariableDefinition> getEnclosingTypeVars()
  {
    ICompilableType gsClass = getGosuClass();
    if( gsClass == null )
    {
      return Collections.emptyMap();
    }
    Map<String, TypeVariableDefinition> mapTypeVarDefByName = new HashMap<>( 2 );
    while( !gsClass.isStatic() && gsClass.getEnclosingType() != null )
    {
      // Note we don't resolve type vars defined in outer for static inner classes.
      // This is because we do not maintain separate inner classes for each
      // parameterization of a generic outer class

      ICompilableType enclosingType = gsClass.getEnclosingType();
      for( IGenericTypeVariable gtv : enclosingType.getGenericTypeVariables() )
      {
        Map<String, ITypeVariableDefinition> typeVarMap = getTypeVariables();
        if( !typeVarMap.containsKey( gtv.getTypeVariableDefinition().getName() ) )
        {
          getTypeVariables().put( gtv.getName(), gtv.getTypeVariableDefinition() );
        }
      }
      gsClass = enclosingType;
    }
    return mapTypeVarDefByName;
  }
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;
    }
526579
private Type getParameterTypeOf(Type type) {
        try {
            return getLowerBoundOfSingleTypeParameter(type);
        } catch (Exception e) {
            throw new IllegalArgumentException("Unable to resolve a generic parameter type of the mapped field " + this.field + ".", e);
        }
    }
1135486
public <T extends Type> T resolve(String typeName, Class<T> clazz) {
        Type instance = resolve(typeName);
        if (instance == null) {
            return null;
        }
        if (clazz.isAssignableFrom(instance.getClass())) {
            return clazz.cast(instance);
        } else {
            throw new ParserException("Type error: %s of type %s can not be cast to %s",
                    typeName, instance.getClass(), clazz);
        }
    }
242598
public static Type resolveAt(Object o, TypeVariable<?> var) {
        Validate.notNull(var, "no variable to read");
        final GenericDeclaration genericDeclaration = var.getGenericDeclaration();
        Validate.isInstanceOf(Class.class, genericDeclaration, "%s is not declared by a Class",
            TypeUtils.toLongString(var));
        return resolveAt(o, var, TypeUtils.getTypeArguments(o.getClass(), (Class<?>) genericDeclaration));
    }
348376
static Class<?> resolveParameterName(String parameterName, Class<?> target) {
    Map<Type, Type> typeVariableMap = getTypeVariableMap(target);
    Set<Entry<Type, Type>> set = typeVariableMap.entrySet();
    Type type = Object.class;

    for (Entry<Type, Type> entry : set) {
      if (entry.getKey().toString().equals(parameterName)) {
        type = entry.getKey();
        break;
      }
    }
    return resolveType(type, typeVariableMap);
  }
1167
@NonNull
  public final <X> GenericType<T> where(
      @NonNull GenericTypeParameter<X> freeVariable, @NonNull GenericType<X> actualType) {
    TypeResolver resolver =
        new TypeResolver().where(freeVariable.getTypeVariable(), actualType.__getToken().getType());
    Type resolvedType = resolver.resolveType(this.token.getType());
    @SuppressWarnings("unchecked")
    TypeToken<T> resolvedToken = (TypeToken<T>) TypeToken.of(resolvedType);
    return new GenericType<>(resolvedToken);
  }
1038767
public Type resolveType(Type type) {
        if (type instanceof Class) {
            Type resolvedType = types.get(type);
            if (resolvedType != null) {
                return resolvedType;
            }
        }
        return resolver.resolveType(type);
    }
534097
public ResolvableType resolveType() {
        if (this.type instanceof ParameterizedType) {
            return forType(((ParameterizedType) this.type).getRawType(), this.variableResolver);
        }
        if (this.type instanceof WildcardType) {
            Type resolved = resolveBounds(((WildcardType) this.type).getUpperBounds());
            if (resolved == null) {
                resolved = resolveBounds(((WildcardType) this.type).getLowerBounds());
            }
            return forType(resolved, this.variableResolver);
        }
        if (this.type instanceof TypeVariable) {
            TypeVariable<?> variable = (TypeVariable<?>) this.type;
            // Try default variable resolution
            if (this.variableResolver != null) {
                ResolvableType resolved = this.variableResolver.resolveVariable(variable);
                if (resolved != null) {
                    return resolved;
                }
            }
            // Fallback to bounds
            return forType(resolveBounds(variable.getBounds()), this.variableResolver);
        }
        return NONE;
    }
319270
public static Optional<Class> resolveInterfaceTypeArgument(Class type, Class interfaceType) {
        Type[] genericInterfaces = type.getGenericInterfaces();
        for (Type genericInterface : genericInterfaces) {
            if (genericInterface instanceof ParameterizedType) {
                ParameterizedType pt = (ParameterizedType) genericInterface;
                if (pt.getRawType() == interfaceType) {
                    return resolveSingleTypeArgument(genericInterface);
                }
            }
        }
        Class superClass = type.getSuperclass();
        if (superClass != null && superClass != Object.class) {
            return resolveInterfaceTypeArgument(superClass, interfaceType);
        }
        return Optional.empty();
    }
1171213
public static Type resolveGenericType(Type initialType, Class<?> targetType) {
        Class<?> rawType;
        if (initialType instanceof ParameterizedType)
            rawType = (Class<?>) ((ParameterizedType) initialType).getRawType();
        else
            rawType = (Class<?>) initialType;

        if (targetType.equals(rawType))
            return initialType;

        Type result;
        if (targetType.isInterface()) {
            for (Type superInterface : rawType.getGenericInterfaces())
                if (superInterface != null && !superInterface.equals(Object.class))
                    if ((result = resolveGenericType(superInterface, targetType)) != null)
                        return result;
        }

        Type superType = rawType.getGenericSuperclass();
        if (superType != null && !superType.equals(Object.class))
            if ((result = resolveGenericType(superType, targetType)) != null)
                return result;

        return null;
    }
179008
public int applicability(final Class<?>[] paramTypes, boolean varArgs) {
        if (argTypes == null) {
            return MATCH_WILDCARD;
        }
        int level = MATCH;
        final int fixArgs = paramTypes.length - (varArgs ? 1 : 0);
        if (fixArgs > argTypes.length 
                || (!varArgs && fixArgs != argTypes.length)) {
            return NO_MATCH;
        }
        // match fix args
        for (int i = 0; i < fixArgs; i++) {
            int m = applicable(argTypes[i], paramTypes[i]);
            if (m == NO_MATCH) return NO_MATCH;
            if (m < level) level = m;
        }
        if (varArgs) {
            // try if last arg matches varargs parameter directly
            Class<?> varArgType = paramTypes[fixArgs];
            if (paramTypes.length == argTypes.length) {
                int m = applicable(argTypes[fixArgs], varArgType);
                if (m != NO_MATCH) {
                    return Math.min(m, level);
                }
            }
            // match remaining args against vararg component type
            level = MATCH_VARARGS;
            Class<?> comp = varArgType.getComponentType();
            for (int i = fixArgs; i < argTypes.length; i++) {
                int m = applicable(argTypes[i], comp);
                if (m == NO_MATCH) return NO_MATCH;
            }
        }
        return level;
    }
1082889
public static Class[] resolveTypeParameters(Class invocationClass, Type targetType) {
        if (targetType instanceof ParameterizedType) {

            Type[] actualTypes = ((ParameterizedType) targetType).getActualTypeArguments();
            Class[] actualClasses = new Class[actualTypes.length];
            for (int i = 0; i < actualTypes.length; i++) {
                actualClasses[i] = resolveTypeVariable(invocationClass, actualTypes[i]);
            }
            return actualClasses;
        }

        return EMPTY_CLASSES;
    }
806136
@SuppressWarnings("PMD.AvoidProtectedMethodInFinalClassNotExtending")
    protected static Type[] resolveTypeVariables(final Type[] types,
                                                 final Map<String, Type> generics,
                                                 final boolean countPreservedVariables) {
        if (types.length == 0) {
            return NO_TYPES;
        }
        final Type[] resolved = new Type[types.length];
        for (int i = 0; i < types.length; i++) {
            resolved[i] = resolveTypeVariables(types[i], generics, countPreservedVariables);
        }
        return resolved;
    }
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));
            }
        }
    }