@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")); }
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())); } } }