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

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

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

MetaClass.isAssignableFrom介绍

[英]Reports if the type represented by this MetaClass is a supertype of (or the same class as) the given class. In other words, this method returns true if the following code would compile without error, where ThisType is the class represented by this MetaClass object, and GivenType is the class represented by the given "clazz" argument:

GivenType given = ...; 
ThisType a = given;

[中]报告此元类表示的类型是否是给定类的超类型(或与给定类相同的类)。换句话说,如果下面的代码编译时没有错误,那么这个方法返回true,其中ThisType是由这个元类对象表示的类,GivenType是由给定的“clazz”参数表示的类:

GivenType given = ...; 
ThisType a = given;

代码示例

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

@Override
 public boolean canBeApplied(MetaClass clazz) {
  if (constraints.length == 0) return true;
  return Arrays.stream(constraints).anyMatch(mc -> mc.asBoxed().isAssignableFrom(clazz.asBoxed()));
 }
}

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

public static boolean isNumericallyCoercible(final MetaClass target, final MetaClass parm) {
 MetaClass boxedTarget = target.isPrimitive() ? target.asBoxed() : target;
 if (boxedTarget != null && Number_MetaClass.isAssignableFrom(target)) {
  if ((boxedTarget = parm.isPrimitive() ? parm.asBoxed() : parm) != null) {
   return Number_MetaClass.isAssignableFrom(boxedTarget);
  }
 }
 return false;
}

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

/**
 * Returns true if the method signature is the same as the methods generated by BindableProxyGenerator
 */
private boolean isBindableProxyGeneratedMethod(MetaMethod method) {
 if(method.getName().equals("get") && method.getParameters().length == 1 && method.getParameters()[0].getType().isAssignableFrom(String.class)) {
   return true;
 }
 
 if(method.getName().equals("set") && method.getParameters().length == 2 && method.getParameters()[0].getType().isAssignableFrom(String.class)) {
   return true;
 }
 
 return false;  
}

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

private void checkSwitchExprType() {
  final boolean validType = supportedTypes.stream()
      .anyMatch(cls -> MetaClassFactory.get(cls).isAssignableFrom(switchExprStmt.getType().asBoxed()));

  if (!validType)
   throw new InvalidTypeException("Type not permitted in switch statements:" + 
     switchExprStmt.getType().getFullyQualifiedName());
 }
}

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

@Test
public void testChildIsAssignableFromChild() {
 // This test checks the valid case:
 // Child example = new Child();
 final MetaClass metaChild = getMetaClass(Child.class);
 assertTrue(metaChild.isAssignableFrom(metaChild));
}

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

@Test
public void testChildIsNotAssignableFromParent() {
 // This test checks the disallowed case:
 // Child child = new Parent();
 final MetaClass metaChild = getMetaClass(Child.class);
 final MetaClass metaParent = getMetaClass(Parent.class);
 assertFalse(metaChild.isAssignableFrom(metaParent));
}

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

@Test
public void testGrandParentIsAssignableFromChild() {
 // This test checks the valid case:
 // Grandparent example = new Child();
 final MetaClass metaChild = getMetaClass(Child.class);
 final MetaClass metaGrandparent = getMetaClass(Grandparent.class);
 assertTrue(metaGrandparent.isAssignableFrom(metaChild));
}

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

@Test
public void testChildIsNotAssignableFromGrandParent() {
 // This test checks the disallowed case:
 // Child child = new Grandparent();
 final MetaClass metaChild = getMetaClass(Child.class);
 final MetaClass metaGrandparent = getMetaClass(Grandparent.class);
 assertFalse(metaChild.isAssignableFrom(metaGrandparent));
}

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

/**
 * This is a regression test for ERRAI-238.
 */
@Test
public void testUncleInLawIsAssignableFromChild() {
 // This test checks the valid case:
 // ParentSuperInterface1 example = new Child();
 final MetaClass metaChild = getMetaClass(Child.class);
 final MetaClass metaUncleInLaw = getMetaClass(ParentSuperInterface1.class);
 assertTrue(metaUncleInLaw.isAssignableFrom(metaChild));
}

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

@Test
public void testChildIsNotAssignableFromUncleInLaw() {
 // This test checks the disallowed case:
 // Child child = new ParentSuperInterface1() {};
 final MetaClass metaChild = getMetaClass(Child.class);
 final MetaClass metaUncleInLaw = getMetaClass(ParentSuperInterface1.class);
 assertFalse(metaChild.isAssignableFrom(metaUncleInLaw));
}

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

@Test
public void testChildIsNotAssignableFromGreatUncleInLaw() {
 // This test checks the disallowed case:
 // Child child = new GrandparentSuperInterface() {};
 final MetaClass metaChild = getMetaClass(Child.class);
 final MetaClass metaGreatUncleInLaw = getMetaClass(GrandparentSuperInterface.class);
 assertFalse(metaChild.isAssignableFrom(metaGreatUncleInLaw));
}

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

@Test
public void testIsolatedInterfaceIsNotAssignableFromObject() {
 // This test checks the disallowed case:
 // IsolatedInterface ii = new Object();
 final MetaClass metaInterface = getMetaClass(IsolatedInterface.class);
 final MetaClass metaObject = getMetaClass(Object.class);
 assertFalse(metaInterface.isAssignableFrom(metaObject));
}

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

@Test
public void testParentIsAssignableFromChild() {
 // This test checks the valid case:
 // Parent example = new Child();
 final MetaClass metaChild = getMetaClass(Child.class);
 final MetaClass metaParent = getMetaClass(Parent.class);
 assertTrue(metaParent.isAssignableFrom(metaChild));
}

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

@Test
public void testChildIsNotAssignableFromUncleInLaw2() {
 // This test checks the disallowed case:
 // Child child = new ParentSuperInterface2() {};
 final MetaClass metaChild = getMetaClass(Child.class);
 final MetaClass metaUncleInLaw = getMetaClass(ParentSuperInterface2.class);
 assertFalse(metaChild.isAssignableFrom(metaUncleInLaw));
}

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

@Test
public void testObjectIsAssignableFromChild() {
 // This test checks the valid case:
 //Object example = new Child();
 final MetaClass metaChild = getMetaClass(Child.class);
 final MetaClass metaObject = getMetaClass(Object.class);
 assertTrue(metaObject.isAssignableFrom(metaChild));
}

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

@Test
public void testObjectIsAssignableFromIsolatedInterface() {
 // This test checks the valid case:
 // Object example = new IsolatedInterface() {};
 final MetaClass metaInterface = getMetaClass(IsolatedInterface.class);
 final MetaClass metaObject = getMetaClass(Object.class);
 assertTrue(metaObject.isAssignableFrom(metaInterface));
}

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

/**
 * This is a regression test for ERRAI-238.
 */
@Test
public void testUncleIsAssignableFromChild() {
 // This test checks the valid case:
 // ParentInterface example = new Child();
 final MetaClass metaChild = getMetaClass(Child.class);
 final MetaClass metaUncle = getMetaClass(ParentInterface.class);
 assertTrue(metaUncle.isAssignableFrom(metaChild));
}

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

/**
 * This is a regression test for ERRAI-238.
 */
@Test
public void testGreatUncleInLawIsAssignableFromChild() {
 // This test checks the valid case:
 //GrandparentSuperInterface example = new Child();
 final MetaClass metaChild = getMetaClass(Child.class);
 final MetaClass metaGreatUncleInLaw = getMetaClass(GrandparentSuperInterface.class);
 assertTrue(metaGreatUncleInLaw.isAssignableFrom(metaChild));
}

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

@Test
public void testChildIsNotAssignableFromObject() {
 // This test checks the disallowed case:
 // Child child = new Object();
 final MetaClass metaChild = getMetaClass(Child.class);
 final MetaClass metaObject = getMetaClass(Object.class);
 assertFalse(metaChild.isAssignableFrom(metaObject));
}

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

@Test
public void testIsAssignableFromComparisonForNested() {
 final MetaClass interfaceClass = getMetaClass(TestInterface.class);
 final MetaClass metaHolderClass = getMetaClass(ObjectWithNested.class);
 // dig out the nested interface from the holder class and ensure it's what we were looking for
 final MetaClass nestedInterface = metaHolderClass.getDeclaredClasses()[0];
 assertEquals("MyNestedInterface", nestedInterface.getName());
 assertEquals(getTypeOfMetaClassBeingTested(), nestedInterface.getClass());
 assertTrue("MyNestedInterface should be assignable from TestInterface",
     interfaceClass.isAssignableFrom(nestedInterface));
}

相关文章