org.jboss.errai.codegen.meta.MetaClass.getParameterizedType()方法的使用及代码示例

x33g5p2x  于2022-01-25 转载在 其他  
字(10.3k)|赞(0)|评价(0)|浏览(122)

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

MetaClass.getParameterizedType介绍

暂无

代码示例

代码示例来源:origin: org.jboss.errai/errai-bus

@Override
 public Collection<MetaClass> provideTypesToExpose() {
  final Set<MetaClass> types = new HashSet<MetaClass>();
  for (final MetaClass metaClass : ClassScanner.getTypesAnnotatedWith(Remote.class)) {
   for (final MetaMethod method : metaClass.getDeclaredMethods()) {
    if (!method.getReturnType().isVoid()) {
     types.add(method.getReturnType().getErased());
    }
    for (final MetaParameter parameter : method.getParameters()) {
     final MetaClass type = parameter.getType();

     types.add(type.getErased());

     final MetaParameterizedType parameterizedType = type.getParameterizedType();
     if (parameterizedType != null) {
      for (final MetaType tp : parameterizedType.getTypeParameters()) {
        if (tp instanceof MetaClass) {
         types.add(((MetaClass) tp).getErased());
        }
      }
     }

    }
   }
  }
  return types;
 }
}

代码示例来源:origin: errai/errai

static boolean hasAssignableTypeParameters(final MetaClass fromType, final MetaClass toType) {
 final MetaParameterizedType toParamType = toType.getParameterizedType();
 final Optional<MetaParameterizedType> fromParamType = GraphUtil.getFromTypeParams(fromType, toType);
 return toParamType == null || fromParamType.map(type -> toParamType.isAssignableFrom(type)).orElse(true);
}

代码示例来源:origin: errai/errai

private MetaClass getConstraintType(final MetaClass validator, final MetaClass constraintValidatorIface) {
 final MetaType annoTypeVariable = constraintValidatorIface.getParameterizedType().getTypeParameters()[0];
 if (!(annoTypeVariable instanceof MetaClass)) {
  throw new RuntimeException("Cannot determine constraint type for " + validator.getFullyQualifiedName());
 }
 final MetaClass annoType = (MetaClass) annoTypeVariable;
 return annoType;
}

代码示例来源:origin: errai/errai

private MetaClass getValueType(final MetaClass validator, final MetaClass constraintValidatorIface) {
 final MetaType valueTypeVariable = constraintValidatorIface.getParameterizedType().getTypeParameters()[1];
 if (!(valueTypeVariable instanceof MetaClass)) {
  throw new RuntimeException("Cannot determine validated type of " + validator.getFullyQualifiedName());
 }
 final MetaClass valueType = (MetaClass) valueTypeVariable;
 return valueType;
}

代码示例来源:origin: errai/errai

protected MetaClass[] getTypeArguments(final MetaClass type) {
 final MetaParameterizedType pType = type.getParameterizedType();
 final MetaType[] typeArgs = (pType != null ? pType.getTypeParameters() : new MetaType[0]);
 final MetaClass[] typeArgsClasses = new MetaClass[typeArgs.length];
 for (int i = 0; i < typeArgs.length; i++) {
  final MetaType argType = typeArgs[i];
  if (argType instanceof MetaClass) {
   typeArgsClasses[i] = (MetaClass) argType;
  }
  else if (argType instanceof MetaParameterizedType) {
   typeArgsClasses[i] = (MetaClass) ((MetaParameterizedType) argType).getRawType();
  }
 }
 return typeArgsClasses;
}

代码示例来源:origin: errai/errai

private static void addInterfaces(final MetaClass clazz, final BuildMetaClass buildMetaClass, final MetaParameterizedType parameterizedType) {
 final MetaType[] typeParams = (clazz.getParameterizedType() != null ? clazz.getParameterizedType().getTypeParameters() : clazz.getTypeParameters());
 final MetaType[] typeArgs = parameterizedType.getTypeParameters();
 validateTypeArgumentsAgainstParameters(clazz, typeParams, typeArgs);
 final Map<String, MetaType> typeArgsByTypeParam = mapTypeArgsByTypeParamName(typeParams, typeArgs);
 final List<MetaClass> ifaces = Arrays
     .stream(clazz.getInterfaces())
     .map(iface -> getParameterizedInterface(typeArgsByTypeParam, iface))
     .collect(Collectors.toList());
 buildMetaClass.setInterfaces(ifaces);
}

代码示例来源:origin: org.jboss.errai/errai-codegen

private static void addInterfaces(final MetaClass clazz, final BuildMetaClass buildMetaClass, final MetaParameterizedType parameterizedType) {
 final MetaType[] typeParams = (clazz.getParameterizedType() != null ? clazz.getParameterizedType().getTypeParameters() : clazz.getTypeParameters());
 final MetaType[] typeArgs = parameterizedType.getTypeParameters();
 validateTypeArgumentsAgainstParameters(clazz, typeParams, typeArgs);
 final Map<String, MetaType> typeArgsByTypeParam = mapTypeArgsByTypeParamName(typeParams, typeArgs);
 final List<MetaClass> ifaces = Arrays
     .stream(clazz.getInterfaces())
     .map(iface -> getParameterizedInterface(typeArgsByTypeParam, iface))
     .collect(Collectors.toList());
 buildMetaClass.setInterfaces(ifaces);
}

代码示例来源:origin: errai/errai

public static void autoInitializedField(final ClassStructureBuilder<?> builder,
                    final MetaClass type,
                    final String name,
                    MetaClass implementation) {
 implementation = MetaClassFactory.parameterizedAs(implementation, type.getParameterizedType());
 builder.privateField(name, type)
     .initializesWith(Stmt.newObject(implementation)).finish();
}

代码示例来源:origin: org.jboss.errai/errai-codegen

public static void autoInitializedField(final ClassStructureBuilder<?> builder,
                    final MetaClass type,
                    final String name,
                    MetaClass implementation) {
 implementation = MetaClassFactory.parameterizedAs(implementation, type.getParameterizedType());
 builder.privateField(name, type)
     .initializesWith(Stmt.newObject(implementation)).finish();
}

代码示例来源:origin: errai/errai

@Test
public void testHashCodeErrorWithGenericHavingArrayUpperBound() throws Exception {
 final MetaClass mc = getMetaClass(ClassWithArrayGenerics.class).getField("field").getType();
 // Precondition
 assertNotNull("Failed to find field with type under test.", mc);
 assertNotNull("Type should be parameterized", mc.getParameterizedType());
 final MetaClass superClassWithProblematicBound = mc.getSuperClass();
 try {
  superClassWithProblematicBound.hashCode();
 } catch (final Throwable t) {
  throw new AssertionError("An error occurred.", t);
 }
}

代码示例来源:origin: errai/errai

@Test
public void rawClassIsAssignableToParameterizedInterface() throws Exception {
 final MetaClass parameterized = parameterizedAs(List.class, typeParametersOf(Integer.class));
 final MetaClass raw = MetaClassFactory.get(ArrayList.class);
 assertNull(raw.getParameterizedType());
 assertTrue(GraphUtil.hasAssignableTypeParameters(raw, parameterized));
}

代码示例来源:origin: errai/errai

@Test
public void rawInterfaceIsAssignableToParameterizedSuperInterfaceWithBaseParameterType() throws Exception {
 final MetaClass parameterized = parameterizedAs(ThrowableCollection.class, typeParametersOf(Throwable.class));
 final MetaClass raw = MetaClassFactory.get(ThrowableList.class);
 assertNull(raw.getParameterizedType());
 assertTrue(GraphUtil.hasAssignableTypeParameters(raw, parameterized));
}

代码示例来源:origin: errai/errai

@Test
public void rawInterfaceIsAssignableToParameterizedSameInterfaceWithBaseParameterType() throws Exception {
 final MetaClass parameterized = parameterizedAs(ThrowableList.class, typeParametersOf(Throwable.class));
 final MetaClass raw = MetaClassFactory.get(ThrowableList.class);
 assertNull(raw.getParameterizedType());
 assertTrue(GraphUtil.hasAssignableTypeParameters(raw, parameterized));
}

代码示例来源:origin: errai/errai

@Test
public void rawClassIsAssignableToParameterizedSameClassWithBaseParameterType() throws Exception {
 final MetaClass parameterized = parameterizedAs(ThrowableArrayList.class, typeParametersOf(Throwable.class));
 final MetaClass raw = MetaClassFactory.get(ThrowableArrayList.class);
 assertNull(raw.getParameterizedType());
 assertTrue(GraphUtil.hasAssignableTypeParameters(raw, parameterized));
}

代码示例来源:origin: errai/errai

@Test
public void rawInterfaceIsAssignableToParameterizedSameInterface() throws Exception {
 final MetaClass parameterized = parameterizedAs(Collection.class, typeParametersOf(Integer.class));
 final MetaClass raw = MetaClassFactory.get(Collection.class);
 assertNull(raw.getParameterizedType());
 assertTrue(GraphUtil.hasAssignableTypeParameters(raw, parameterized));
}

代码示例来源:origin: errai/errai

@Test
public void rawClassIsAssignableToParameterizedSameClass() throws Exception {
 final MetaClass parameterized = parameterizedAs(ArrayList.class, typeParametersOf(Integer.class));
 final MetaClass raw = MetaClassFactory.get(ArrayList.class);
 assertNull(raw.getParameterizedType());
 assertTrue(GraphUtil.hasAssignableTypeParameters(raw, parameterized));
}

代码示例来源:origin: errai/errai

@Test
public void rawClassIsAssignableToParameterizedInterfaceWithBaseParameterType() throws Exception {
 final MetaClass parameterized = parameterizedAs(ThrowableList.class, typeParametersOf(Throwable.class));
 final MetaClass raw = MetaClassFactory.get(ThrowableArrayList.class);
 assertNull(raw.getParameterizedType());
 assertTrue(GraphUtil.hasAssignableTypeParameters(raw, parameterized));
}

代码示例来源:origin: errai/errai

@Test
public void rawInterfaceIsAssignableToParameterizedSuperInterface() throws Exception {
 final MetaClass parameterized = parameterizedAs(Collection.class, typeParametersOf(Integer.class));
 final MetaClass raw = MetaClassFactory.get(List.class);
 assertNull(raw.getParameterizedType());
 assertTrue(GraphUtil.hasAssignableTypeParameters(raw, parameterized));
}

代码示例来源:origin: errai/errai

@Test
public void testFieldWithStringTypeParam() throws Exception {
 final MetaClass metaClass = getMetaClass(ClassWithGenericCollections.class);
 final MetaField field = metaClass.getDeclaredField("hasStringParam");
 assertNotNull(field);
 assertEquals("Collection", field.getType().getName());
 assertEquals("java.util.Collection", field.getType().getFullyQualifiedName());
 assertEquals("<java.lang.String>", field.getType().getParameterizedType().toString());
 assertEquals("java.util.Collection<java.lang.String>", field.getType().getFullyQualifiedNameWithTypeParms());
 assertEquals("java.util.Collection", field.getType().getErased().getFullyQualifiedNameWithTypeParms());
 assertEquals(
     Arrays.asList(getMetaClass(String.class)),
     Arrays.asList(field.getType().getParameterizedType().getTypeParameters()));
}

代码示例来源:origin: errai/errai

@Test
public void testEraseParameterizedTopLevelType() throws Exception {
 final MetaClass parameterized = getMetaClass(ParameterizedClass.class);
 assertEquals("ParameterizedClass", parameterized.getName());
 assertEquals("org.jboss.errai.codegen.test.model.ParameterizedClass", parameterized.getFullyQualifiedName());
 assertNull(parameterized.getParameterizedType());
 // I think this would be correct, but right now we get the raw type name
 //assertEquals("org.jboss.errai.codegen.test.model.ParameterizedClass<T>", parameterized.getFullyQualifiedNameWithTypeParms());
 assertEquals("org.jboss.errai.codegen.test.model.ParameterizedClass", parameterized.getErased().getFullyQualifiedNameWithTypeParms());
}

相关文章