-
Notifications
You must be signed in to change notification settings - Fork 0
/
README
34 lines (29 loc) · 1.45 KB
/
README
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
The goal of this library is to provide a succinct DSL-like way to build generators for deferred binding in GWT without resorting to literal strings.
"Self explanatory" silly example:
@Override
protected void generate(GeneratedClassDefinition classDef) {
classDef.addNestedInterface(defineInterface("MyNestedInterface").thatExtends(Superinterface.class).withMethods(
defineMethod("interfaceMethod").annotatedWith(AnAnnotation.class).withParams(
defineParam(template(type(GenericType.class), TypeParameter.class), "parameter")
)
);
classDef.addNestedClass(defineClass("NestedClass").thatExtends(Superclass.class).withFields(
defineField(template(type(List.class), type("MyNestedInterface")), "listField")
).withMethods(
defineMethod(type(List.class), "getList").withBody(returnValue("listField"))
)
);
classDef.getConstructor().addToBody(
callMethod("frobnicate", classLiteral(type("MyNestedInterface")),
newAnonymousClass(type("MyNestedInterface")).withFields(
defineField(type(FieldType.class), "field").assignValue(callMethod(SomeClass.class, "staticMethod"))
).withMethods(
defineMethod("doSomething").withParams(
defineParam(ParamType.class, "param")
).withBody(
callMethod("field.someMethod", "param")
)
)
)
);
}