code: @SuppressWarnings({"PMD.AvoidProtectedMethodInFinalClassNotExtending",
              "PMD.CyclomaticComplexity",
              "checkstyle:CyclomaticComplexity"})
      protected static Type resolveTypeVariables(final Type type,
                                                 final Map<String, Type> generics,
                                                 final boolean countPreservedVariables) {
          Type resolvedGenericType = null;
          if (type instanceof TypeVariable) {
              // simple named generics resolved to target types
              resolvedGenericType = declaredGeneric((TypeVariable) type, generics);
          } else if (type instanceof ExplicitTypeVariable) {
              // special type used to preserve named generic (and differentiate from type variable)
              resolvedGenericType = declaredGeneric((ExplicitTypeVariable) type, generics, countPreservedVariables);
          } else if (type instanceof Class) {
              resolvedGenericType = type;
          } else if (type instanceof ParameterizedType) {
              // here parameterized type could shrink to class (if it has no arguments and owner class)
              resolvedGenericType = resolveParameterizedTypeVariables(
                      (ParameterizedType) type, generics, countPreservedVariables);
          } else if (type instanceof GenericArrayType) {
              // here generic array could shrink to array class (if component type shrink to simple class)
              resolvedGenericType = resolveGenericArrayTypeVariables(
                      (GenericArrayType) type, generics, countPreservedVariables);
          } else if (type instanceof WildcardType) {
              // here wildcard could shrink to upper type (if it has only one upper type)
              resolvedGenericType = resolveWildcardTypeVariables(
                      (WildcardType) type, generics, countPreservedVariables);
          }
          return resolvedGenericType;
      }
docs: for TypeVariableUtils access