GMethod { public GMethod typeParameters(String typeParameters) { this.typeParameters = typeParameters; return this; } GMethod(GClass gclass, String methodName); GMethod returnType(Class<?> type); GMethod returnType(String returnClassName, Object... args); GMethod argument(String typeClassName, String name); GMethod arguments(String... typeAndNames); GMethod arguments(List<Argument> args); GMethod constructorFor(String shortClassName); void setBody(String body); String toCode(); String getName(); GMethod setPrivate(); GMethod setProtected(); GMethod setAccess(Access access); GMethod setStatic(); GMethod setAbstract(); boolean hasArguments(); boolean hasSameArguments(String... typeAndNames); boolean hasSameArguments(List<Argument> other); GMethod addAnnotation(String annotation, Object... args); GMethod addOverride(); GMethod addThrows(String exception); GMethod typeParameters(String typeParameters); GMethod assignFields(); final StringBuilderr body; }
@Test public void testTypeParameters() { GClass gc = new GClass("foo.bar.Foo"); gc.getMethod("hello").arguments("T foo").typeParameters("T"); gc.getMethod("goodbye").arguments("T foo").typeParameters("T").setStatic(); Assert.assertEquals( Join.lines(new Object[] { "package foo.bar;", "", "public class Foo {", "", " public <T> void hello(T foo) {", " }", "", " public static <T> void goodbye(T foo) {", " }", "", "}", "" }), gc.toCode()); }