org.springframework.core.convert.TypeDescriptor.getSource()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(2.7k)|赞(0)|评价(0)|浏览(115)

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

TypeDescriptor.getSource介绍

[英]Return the underlying source of the descriptor. Will return a Field, MethodParameter or Type depending on how the TypeDescriptorwas constructed. This method is primarily to provide access to additional type information or meta-data that alternative JVM languages may provide.
[中]返回描述符的基础源。将根据TypeDescriptorW的构造方式返回字段、MethodParameter或类型。这种方法主要是提供对其他JVM语言可能提供的额外类型信息或元数据的访问。

代码示例

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

@Test
public void getSource() throws Exception {
  Field field = getClass().getField("fieldScalar");
  MethodParameter methodParameter = new MethodParameter(getClass().getMethod("testParameterPrimitive", int.class), 0);
  assertThat(new TypeDescriptor(field).getSource(), equalTo((Object) field));
  assertThat(new TypeDescriptor(methodParameter).getSource(), equalTo((Object) methodParameter));
  assertThat(TypeDescriptor.valueOf(Integer.class).getSource(), equalTo((Object) Integer.class));
}

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

/**
 * 
 * {@inheritDoc}
 */
public Object convert(Object source, TypeDescriptor sourceType, TypeDescriptor targetType) {
  Assert.isInstanceOf(HibernateProxy.class, source, "Expected an instance of HibernateProxy to convert");
  Assert.isAssignable(HibernateProxy.class, sourceType.getType(), "Expected a subclass of HibernateProxy for the source type");
  HibernateProxy proxy = (HibernateProxy) source;
  boolean isField = targetType.getSource() instanceof Field;
  boolean isProperty = targetType.getSource() instanceof MethodParameter &&
    BeanUtils.findPropertyForMethod(((MethodParameter)targetType.getSource()).getMethod()) != null;
  if (isField || isProperty) {
    if (!Hibernate.isInitialized(proxy)) {
      return null;
    }
  }
  return proxy.getHibernateLazyInitializer().getImplementation();
}

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

/**
 * 
 * {@inheritDoc}
 */
public Object convert(Object source, TypeDescriptor sourceType, TypeDescriptor targetType) {
  Assert.isInstanceOf(HibernateProxy.class, source, "Expected an instance of HibernateProxy to convert");
  Assert.isAssignable(HibernateProxy.class, sourceType.getType(), "Expected a subclass of HibernateProxy for the source type");
  HibernateProxy proxy = (HibernateProxy) source;
  boolean isField = targetType.getSource() instanceof Field;
  boolean isProperty = targetType.getSource() instanceof MethodParameter &&
    BeanUtils.findPropertyForMethod(((MethodParameter)targetType.getSource()).getMethod()) != null;
  if (isField || isProperty) {
    if (!Hibernate.isInitialized(proxy)) {
      return null;
    }
  }
  return proxy.getHibernateLazyInitializer().getImplementation();
}

相关文章

微信公众号

最新文章

更多