@Test
 public void testGenerateHashCode() throws ClassNotFoundException {
   plugin.generateHashCodeMethod(aModel, aClass);
   final JMethod generatedMethod = aClass.getMethod("hashCode", new JType[] {});
   assertThat(generatedMethod, not(nullValue()));
   assertThat(generatedMethod.type().fullName(), equalTo("int"));
 }
 @Test
 public void testGenerateToString() {
   plugin.generateToStringMethod(aModel, aClass);
   final JMethod generatedMethod = aClass.getMethod("toString", new JType[0]);
   assertThat(generatedMethod, not(nullValue()));
   assertThat(generatedMethod.type().fullName(), equalTo(String.class.getName()));
 }
 @Test
 public void testGenerateEquals() throws ClassNotFoundException {
   plugin.generateEqualsMethod(aModel, aClass);
   final JMethod generatedMethod =
       aClass.getMethod("equals", new JType[] {aModel.parseType("java.lang.Object")});
   assertThat(generatedMethod, not(nullValue()));
   assertThat(generatedMethod.type().fullName(), equalTo("boolean"));
 }
Esempio n. 4
0
  /**
   * Returns the <code>setProperty(...)</code> method for the given field outline or <code>null
   * </code> if no such method exists.
   *
   * @param fieldOutline field outline.
   * @return The <code>setProperty(...)</code> method for the given field outline or <code>null
   *     </code> if no such method exists.
   */
  public static JMethod setter(FieldOutline fieldOutline) {

    final JMethod getter = getter(fieldOutline);
    final JType type = getter != null ? getter.type() : fieldOutline.getRawType();
    final JDefinedClass theClass = fieldOutline.parent().implClass;
    final String publicName = fieldOutline.getPropertyInfo().getName(true);
    final String name = "set" + publicName;
    return theClass.getMethod(name, new JType[] {type});
  }
Esempio n. 5
0
 private void addVarArgsWither(
     Filter filter, JMethod wither, JDefinedClass bldrCls, JClass paramType)
     throws JClassAlreadyExistsException {
   JMethod method = bldrCls.method(wither.mods().getValue(), wither.type(), wither.name());
   if (filter.getTitle() != null) {
     method.javadoc().add(String.format("<p>%s</p>", filter.getTitle()));
   }
   JVar param = method.varParam(paramType, wither.listParams()[0].name());
   method
       .body()
       ._return(JExpr.invoke(wither).arg(immutableList.staticInvoke("copyOf").arg(param)));
 }
 public void run(Set<ClassOutline> sorted, JDefinedClass transformer) {
   for (ClassOutline classOutline : sorted) {
     // skip over abstract classes
     if (!classOutline.target.isAbstract()) {
       // add the accept method to the bean
       JDefinedClass beanImpl = classOutline.implClass;
       JMethod acceptMethod = beanImpl.method(JMod.PUBLIC, Object.class, "accept");
       JTypeVar genericType = acceptMethod.generify("T");
       acceptMethod.type(genericType);
       JVar vizParam = acceptMethod.param(transformer.narrow(genericType), "aTransformer");
       JBlock block = acceptMethod.body();
       block._return(vizParam.invoke("transform").arg(JExpr._this()));
     }
   }
 }