org.springframework.core.ResolvableType.resolveType()方法的使用及代码示例

x33g5p2x  于2022-01-28 转载在 其他  
字(11.4k)|赞(0)|评价(0)|浏览(103)

本文整理了Java中org.springframework.core.ResolvableType.resolveType方法的一些代码示例,展示了ResolvableType.resolveType的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ResolvableType.resolveType方法的具体详情如下:
包路径:org.springframework.core.ResolvableType
类名称:ResolvableType
方法名:resolveType

ResolvableType.resolveType介绍

[英]Resolve this type by a single level, returning the resolved value or #NONE.

Note: The returned ResolvableType should only be used as an intermediary as it cannot be serialized.
[中]

代码示例

代码示例来源:origin: spring-projects/spring-framework

/**
 * Return {@code true} if this type resolves to a Class that represents an array.
 * @see #getComponentType()
 */
public boolean isArray() {
  if (this == NONE) {
    return false;
  }
  return ((this.type instanceof Class && ((Class<?>) this.type).isArray()) ||
      this.type instanceof GenericArrayType || resolveType().isArray());
}

代码示例来源:origin: org.springframework/spring-core

/**
 * Return {@code true} if this type resolves to a Class that represents an array.
 * @see #getComponentType()
 */
public boolean isArray() {
  if (this == NONE) {
    return false;
  }
  return ((this.type instanceof Class && ((Class<?>) this.type).isArray()) ||
      this.type instanceof GenericArrayType || resolveType().isArray());
}

代码示例来源:origin: spring-projects/spring-framework

@Nullable
private Class<?> resolveClass() {
  if (this.type == EmptyType.INSTANCE) {
    return null;
  }
  if (this.type instanceof Class) {
    return (Class<?>) this.type;
  }
  if (this.type instanceof GenericArrayType) {
    Class<?> resolvedComponent = getComponentType().resolve();
    return (resolvedComponent != null ? Array.newInstance(resolvedComponent, 0).getClass() : null);
  }
  return resolveType().resolve();
}

代码示例来源:origin: spring-projects/spring-framework

/**
 * Get a {@link WildcardBounds} instance for the specified type, returning
 * {@code null} if the specified type cannot be resolved to a {@link WildcardType}.
 * @param type the source type
 * @return a {@link WildcardBounds} instance or {@code null}
 */
@Nullable
public static WildcardBounds get(ResolvableType type) {
  ResolvableType resolveToWildcard = type;
  while (!(resolveToWildcard.getType() instanceof WildcardType)) {
    if (resolveToWildcard == NONE) {
      return null;
    }
    resolveToWildcard = resolveToWildcard.resolveType();
  }
  WildcardType wildcardType = (WildcardType) resolveToWildcard.type;
  Kind boundsType = (wildcardType.getLowerBounds().length > 0 ? Kind.LOWER : Kind.UPPER);
  Type[] bounds = (boundsType == Kind.UPPER ? wildcardType.getUpperBounds() : wildcardType.getLowerBounds());
  ResolvableType[] resolvableBounds = new ResolvableType[bounds.length];
  for (int i = 0; i < bounds.length; i++) {
    resolvableBounds[i] = ResolvableType.forType(bounds[i], type.variableResolver);
  }
  return new WildcardBounds(boundsType, resolvableBounds);
}

代码示例来源:origin: spring-projects/spring-framework

/**
 * Return the ResolvableType representing the component type of the array or
 * {@link #NONE} if this type does not represent an array.
 * @see #isArray()
 */
public ResolvableType getComponentType() {
  if (this == NONE) {
    return NONE;
  }
  if (this.componentType != null) {
    return this.componentType;
  }
  if (this.type instanceof Class) {
    Class<?> componentType = ((Class<?>) this.type).getComponentType();
    return forType(componentType, this.variableResolver);
  }
  if (this.type instanceof GenericArrayType) {
    return forType(((GenericArrayType) this.type).getGenericComponentType(), this.variableResolver);
  }
  return resolveType().getComponentType();
}

代码示例来源:origin: org.springframework/spring-core

@Nullable
private Class<?> resolveClass() {
  if (this.type == EmptyType.INSTANCE) {
    return null;
  }
  if (this.type instanceof Class) {
    return (Class<?>) this.type;
  }
  if (this.type instanceof GenericArrayType) {
    Class<?> resolvedComponent = getComponentType().resolve();
    return (resolvedComponent != null ? Array.newInstance(resolvedComponent, 0).getClass() : null);
  }
  return resolveType().resolve();
}

代码示例来源:origin: spring-projects/spring-framework

@Nullable
private ResolvableType resolveVariable(TypeVariable<?> variable) {
  if (this.type instanceof TypeVariable) {
    return resolveType().resolveVariable(variable);
  }
  if (this.type instanceof ParameterizedType) {
    ParameterizedType parameterizedType = (ParameterizedType) this.type;
    Class<?> resolved = resolve();
    if (resolved == null) {
      return null;
    }
    TypeVariable<?>[] variables = resolved.getTypeParameters();
    for (int i = 0; i < variables.length; i++) {
      if (ObjectUtils.nullSafeEquals(variables[i].getName(), variable.getName())) {
        Type actualType = parameterizedType.getActualTypeArguments()[i];
        return forType(actualType, this.variableResolver);
      }
    }
    Type ownerType = parameterizedType.getOwnerType();
    if (ownerType != null) {
      return forType(ownerType, this.variableResolver).resolveVariable(variable);
    }
  }
  if (this.variableResolver != null) {
    return this.variableResolver.resolveVariable(variable);
  }
  return null;
}

代码示例来源:origin: spring-projects/spring-framework

generics = resolveType().getGenerics();

代码示例来源:origin: org.springframework/spring-core

/**
 * Get a {@link WildcardBounds} instance for the specified type, returning
 * {@code null} if the specified type cannot be resolved to a {@link WildcardType}.
 * @param type the source type
 * @return a {@link WildcardBounds} instance or {@code null}
 */
@Nullable
public static WildcardBounds get(ResolvableType type) {
  ResolvableType resolveToWildcard = type;
  while (!(resolveToWildcard.getType() instanceof WildcardType)) {
    if (resolveToWildcard == NONE) {
      return null;
    }
    resolveToWildcard = resolveToWildcard.resolveType();
  }
  WildcardType wildcardType = (WildcardType) resolveToWildcard.type;
  Kind boundsType = (wildcardType.getLowerBounds().length > 0 ? Kind.LOWER : Kind.UPPER);
  Type[] bounds = (boundsType == Kind.UPPER ? wildcardType.getUpperBounds() : wildcardType.getLowerBounds());
  ResolvableType[] resolvableBounds = new ResolvableType[bounds.length];
  for (int i = 0; i < bounds.length; i++) {
    resolvableBounds[i] = ResolvableType.forType(bounds[i], type.variableResolver);
  }
  return new WildcardBounds(boundsType, resolvableBounds);
}

代码示例来源:origin: org.springframework/spring-core

/**
 * Return the ResolvableType representing the component type of the array or
 * {@link #NONE} if this type does not represent an array.
 * @see #isArray()
 */
public ResolvableType getComponentType() {
  if (this == NONE) {
    return NONE;
  }
  if (this.componentType != null) {
    return this.componentType;
  }
  if (this.type instanceof Class) {
    Class<?> componentType = ((Class<?>) this.type).getComponentType();
    return forType(componentType, this.variableResolver);
  }
  if (this.type instanceof GenericArrayType) {
    return forType(((GenericArrayType) this.type).getGenericComponentType(), this.variableResolver);
  }
  return resolveType().getComponentType();
}

代码示例来源:origin: org.springframework/spring-core

@Nullable
private ResolvableType resolveVariable(TypeVariable<?> variable) {
  if (this.type instanceof TypeVariable) {
    return resolveType().resolveVariable(variable);
  }
  if (this.type instanceof ParameterizedType) {
    ParameterizedType parameterizedType = (ParameterizedType) this.type;
    Class<?> resolved = resolve();
    if (resolved == null) {
      return null;
    }
    TypeVariable<?>[] variables = resolved.getTypeParameters();
    for (int i = 0; i < variables.length; i++) {
      if (ObjectUtils.nullSafeEquals(variables[i].getName(), variable.getName())) {
        Type actualType = parameterizedType.getActualTypeArguments()[i];
        return forType(actualType, this.variableResolver);
      }
    }
    Type ownerType = parameterizedType.getOwnerType();
    if (ownerType != null) {
      return forType(ownerType, this.variableResolver).resolveVariable(variable);
    }
  }
  if (this.variableResolver != null) {
    return this.variableResolver.resolveVariable(variable);
  }
  return null;
}

代码示例来源:origin: org.springframework/spring-core

generics = resolveType().getGenerics();

代码示例来源:origin: spring-projects/spring-framework

@SuppressWarnings("rawtypes")
private static void buildTypeVariableMap(ResolvableType type, Map<TypeVariable, Type> typeVariableMap) {
  if (type != ResolvableType.NONE) {
    Class<?> resolved = type.resolve();
    if (resolved != null && type.getType() instanceof ParameterizedType) {
      TypeVariable<?>[] variables = resolved.getTypeParameters();
      for (int i = 0; i < variables.length; i++) {
        ResolvableType generic = type.getGeneric(i);
        while (generic.getType() instanceof TypeVariable<?>) {
          generic = generic.resolveType();
        }
        if (generic != ResolvableType.NONE) {
          typeVariableMap.put(variables[i], generic.getType());
        }
      }
    }
    buildTypeVariableMap(type.getSuperType(), typeVariableMap);
    for (ResolvableType interfaceType : type.getInterfaces()) {
      buildTypeVariableMap(interfaceType, typeVariableMap);
    }
    if (resolved != null && resolved.isMemberClass()) {
      buildTypeVariableMap(ResolvableType.forClass(resolved.getEnclosingClass()), typeVariableMap);
    }
  }
}

代码示例来源:origin: org.springframework/spring-core

@SuppressWarnings("rawtypes")
private static void buildTypeVariableMap(ResolvableType type, Map<TypeVariable, Type> typeVariableMap) {
  if (type != ResolvableType.NONE) {
    Class<?> resolved = type.resolve();
    if (resolved != null && type.getType() instanceof ParameterizedType) {
      TypeVariable<?>[] variables = resolved.getTypeParameters();
      for (int i = 0; i < variables.length; i++) {
        ResolvableType generic = type.getGeneric(i);
        while (generic.getType() instanceof TypeVariable<?>) {
          generic = generic.resolveType();
        }
        if (generic != ResolvableType.NONE) {
          typeVariableMap.put(variables[i], generic.getType());
        }
      }
    }
    buildTypeVariableMap(type.getSuperType(), typeVariableMap);
    for (ResolvableType interfaceType : type.getInterfaces()) {
      buildTypeVariableMap(interfaceType, typeVariableMap);
    }
    if (resolved != null && resolved.isMemberClass()) {
      buildTypeVariableMap(ResolvableType.forClass(resolved.getEnclosingClass()), typeVariableMap);
    }
  }
}

代码示例来源:origin: apache/servicemix-bundles

/**
 * Return {@code true} if this type resolves to a Class that represents an array.
 * @see #getComponentType()
 */
public boolean isArray() {
  if (this == NONE) {
    return false;
  }
  return ((this.type instanceof Class && ((Class<?>) this.type).isArray()) ||
      this.type instanceof GenericArrayType || resolveType().isArray());
}

代码示例来源:origin: com.github.XDean/spring-annotation

/**
 * Return {@code true} if this type resolves to a Class that represents an array.
 *
 * @see #getComponentType()
 */
public boolean isArray() {
 if (this == NONE) {
  return false;
 }
 return ((this.type instanceof Class && ((Class<?>) this.type).isArray()) ||
   this.type instanceof GenericArrayType || resolveType().isArray());
}

代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.spring-core

/**
 * Return {@code true} if this type resolves to a Class that represents an array.
 * @see #getComponentType()
 */
public boolean isArray() {
  if (this == NONE) {
    return false;
  }
  return ((this.type instanceof Class && ((Class<?>) this.type).isArray()) ||
      this.type instanceof GenericArrayType || resolveType().isArray());
}

代码示例来源:origin: apache/servicemix-bundles

@Nullable
private Class<?> resolveClass() {
  if (this.type == EmptyType.INSTANCE) {
    return null;
  }
  if (this.type instanceof Class) {
    return (Class<?>) this.type;
  }
  if (this.type instanceof GenericArrayType) {
    Class<?> resolvedComponent = getComponentType().resolve();
    return (resolvedComponent != null ? Array.newInstance(resolvedComponent, 0).getClass() : null);
  }
  return resolveType().resolve();
}

代码示例来源:origin: com.github.XDean/spring-annotation

@Nullable
private Class<?> resolveClass() {
 if (this.type == EmptyType.INSTANCE) {
  return null;
 }
 if (this.type instanceof Class) {
  return (Class<?>) this.type;
 }
 if (this.type instanceof GenericArrayType) {
  Class<?> resolvedComponent = getComponentType().resolve();
  return (resolvedComponent != null ? Array.newInstance(resolvedComponent, 0).getClass() : null);
 }
 return resolveType().resolve();
}

代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.spring-core

@Nullable
private Class<?> resolveClass() {
  if (this.type == EmptyType.INSTANCE) {
    return null;
  }
  if (this.type instanceof Class) {
    return (Class<?>) this.type;
  }
  if (this.type instanceof GenericArrayType) {
    Class<?> resolvedComponent = getComponentType().resolve();
    return (resolvedComponent != null ? Array.newInstance(resolvedComponent, 0).getClass() : null);
  }
  return resolveType().resolve();
}

相关文章

微信公众号

最新文章

更多