Exemplo n.º 1
0
  private void processTypeAnnotations(
      AbstractClassTypeDeclarationDescr typeDescr, TypeDeclaration type) {
    try {
      Role role = typeDescr.getTypedAnnotation(Role.class);
      if (role != null) {
        type.setRole(role.value());
      }

      TypeSafe typeSafe = typeDescr.getTypedAnnotation(TypeSafe.class);
      if (typeSafe != null) {
        type.setTypesafe(typeSafe.value());
      }

      if (typeDescr instanceof EnumDeclarationDescr) {
        type.setKind(TypeDeclaration.Kind.ENUM);
      } else if (typeDescr instanceof TypeDeclarationDescr
          && ((TypeDeclarationDescr) typeDescr).isTrait()) {
        type.setKind(TypeDeclaration.Kind.TRAIT);
      }

      type.setDynamic(typeDescr.hasAnnotation(PropertyChangeSupport.class));
    } catch (Exception e) {
      kbuilder.addBuilderResult(new TypeDeclarationError(typeDescr, e.getMessage()));
    }
  }
  private void testKieModuleMetaDataInMemory(boolean useTypeDeclaration) throws Exception {
    KieServices ks = KieServices.Factory.get();
    ReleaseId dependency = ks.newReleaseId("org.drools", "drools-core", "5.5.0.Final");
    ReleaseId releaseId = ks.newReleaseId("org.kie", "metadata-test", "1.0-SNAPSHOT");

    InternalKieModule kieModule =
        createKieJarWithClass(ks, releaseId, useTypeDeclaration, 2, 7, dependency);
    KieModuleMetaData kieModuleMetaData = KieModuleMetaData.Factory.newKieModuleMetaData(kieModule);
    checkDroolsCoreDep(kieModuleMetaData);

    Collection<String> testClasses = kieModuleMetaData.getClasses("org.kie.test");
    assertEquals(1, testClasses.size());
    assertEquals("Bean", testClasses.iterator().next());
    Class<?> beanClass = kieModuleMetaData.getClass("org.kie.test", "Bean");
    assertNotNull(beanClass.getMethod("getValue"));

    TypeMetaInfo beanTypeInfo = kieModuleMetaData.getTypeMetaInfo(beanClass);
    assertNotNull(beanTypeInfo);

    assertTrue(beanTypeInfo.isEvent());

    Role role = beanClass.getAnnotation(Role.class);
    assertNotNull(role);
    assertEquals(Role.Type.EVENT, role.value());

    assertEquals(useTypeDeclaration, beanTypeInfo.isDeclaredType());
  }
Exemplo n.º 3
0
 /**
  * Returns true if clazz is imported as an Event class in this package
  *
  * @param clazz
  * @return true if clazz is imported as an Event class in this package
  */
 public boolean isEvent(Class clazz) {
   TypeDeclaration typeDeclaration = getTypeDeclaration(clazz);
   if (typeDeclaration != null) {
     return typeDeclaration.getRole() == Role.Type.EVENT;
   }
   Role role = (Role) clazz.getAnnotation(Role.class);
   return role != null && role.value() == Role.Type.EVENT;
 }