Example usage for com.google.common.reflect TypeResolver where

List of usage examples for com.google.common.reflect TypeResolver where

Introduction

In this page you can find the example usage for com.google.common.reflect TypeResolver where.

Prototype

public TypeResolver where(Type formal, Type actual) 

Source Link

Document

Returns a new TypeResolver with type variables in formal mapping to types in actual .

Usage

From source file:org.assertj.core.test.TypeCanonizer.java

/**
 * Returns a canonical form of {@code initialType} by replacing all {@link TypeVariable} by {@link Class}
 * instances./*from  w w  w.  ja v a2  s  .com*/
 * <p>
 * <p>
 * Such a canonical form allows to compare {@link ParameterizedType}s, {@link WildcardType}(s),
 * {@link GenericArrayType}(s), {@link TypeVariable}(s).
 * </p>
 */
public static Type canonize(Type initialType) {
    if (doesNotNeedCanonization(initialType)) {
        return initialType;
    }

    ReplacementClassSupplier replacementClassSupplier = new ReplacementClassSupplier();
    TypeResolver typeResolver = new TypeResolver();

    for (TypeVariable<?> typeVariable : findAllTypeVariables(initialType)) {
        // Once we have all TypeVariable we need to resolve them with actual classes so the typeResolver can resolve
        // them properly
        typeResolver = typeResolver.where(typeVariable, replacementClassSupplier.get());
    }

    return typeResolver.resolveType(initialType);
}