示例#1
0
  @Override
  public String getName() {
    List<String> parameterTypes = new ArrayList<>();
    for (Parameter<?> p : method.getParameters()) {
      parameterTypes.add(p.getType().getQualifiedName());
    }

    Type<?> methodReturnType = method.getReturnType();
    String returnType =
        (method.isReturnTypeVoid() || methodReturnType == null)
            ? "void"
            : methodReturnType.getQualifiedName();
    return String.format(
        "%s(%s)::%s", method.getName(), Strings.join(parameterTypes, ","), returnType);
  }
  @Test
  public void testCreateNewObserverMethodWithQualifiers() throws Exception {
    try (CommandController controller =
        uiTestHarness.createCommandController(CDINewBeanCommand.class, project.getRoot())) {
      controller.initialize();
      controller.setValueFor("named", "MyBean");
      controller.setValueFor("targetPackage", "org.jboss.forge.test.bean");
      assertTrue(controller.isValid());
      assertTrue(controller.canExecute());
      Result result = controller.execute();
      Assert.assertThat(result, is(not(instanceOf(Failed.class))));
    }

    try (CommandController controller =
        uiTestHarness.createCommandController(
            CDIAddObserverMethodCommand.class, project.getRoot())) {
      controller.initialize();
      controller.setValueFor("named", "observe");
      controller.setValueFor("targetClass", "org.jboss.forge.test.bean.MyBean");
      controller.setValueFor("eventType", "java.lang.String");
      controller.setValueFor(
          "qualifiers",
          Arrays.asList("javax.enterprise.inject.Default", "javax.enterprise.inject.Any"));
      assertTrue(controller.isValid());
      assertTrue(controller.canExecute());
      Result result = controller.execute();
      Assert.assertThat(result, is(not(instanceOf(Failed.class))));
    }

    JavaSourceFacet facet = project.getFacet(JavaSourceFacet.class);
    JavaResource javaResource = facet.getJavaResource("org.jboss.forge.test.bean.MyBean");
    Assert.assertNotNull(javaResource);
    Assert.assertThat(javaResource.getJavaType(), is(instanceOf(JavaClass.class)));
    JavaClass<?> myBean = javaResource.getJavaType();
    Assert.assertEquals(1, myBean.getMethods().size());
    Assert.assertEquals(0, myBean.getInterfaces().size());
    Method<?, ?> method = myBean.getMethods().get(0);
    Assert.assertEquals("observe", method.getName());
    Assert.assertEquals(1, method.getParameters().size());
    Parameter<?> parameter = method.getParameters().get(0);
    Assert.assertTrue(parameter.hasAnnotation(Observes.class));
    Assert.assertEquals("java.lang.String", parameter.getType().getQualifiedName());
    Assert.assertEquals("event", parameter.getName());
    Assert.assertEquals(3, parameter.getAnnotations().size());
    Assert.assertTrue(parameter.hasAnnotation(Observes.class));
    Assert.assertTrue(parameter.hasAnnotation(Default.class));
    Assert.assertTrue(parameter.hasAnnotation(Any.class));
  }
示例#3
0
 @Override
 @SuppressWarnings({"unchecked"})
 public boolean delete() throws UnsupportedOperationException {
   Object origin = method.getOrigin();
   if (origin instanceof MethodHolderSource) {
     ((MethodHolderSource) origin).removeMethod(method);
     if (!((MethodHolderSource) origin).hasMethodSignature(method)) {
       ((JavaResource) this.getParent()).setContents(origin.toString());
       return true;
     }
   }
   return false;
 }
示例#4
0
 @Override
 public String toString() {
   return method.toString();
 }