private List<TypeBodyDeclaration> createMetaData() {
List<TypeBodyDeclaration> results = Lists.create();
results.add(f.newFieldDeclaration(
null,
new AttributeBuilder(f)
.Private()
.Static()
.Final()
.toAttributes(),
f.newParameterizedType(
context.resolve(Map.class),
context.resolve(String.class),
context.resolve(Integer.class)),
f.newSimpleName(NAME_PROPERTY_POSITIONS),
null));
List<Statement> statements = Lists.create();
SimpleName map = f.newSimpleName("map");
statements.add(new TypeBuilder(f, context.resolve(TreeMap.class))
.parameterize(context.resolve(String.class), context.resolve(Integer.class))
.newObject()
.toLocalVariableDeclaration(
f.newParameterizedType(
context.resolve(Map.class),
context.resolve(String.class),
context.resolve(Integer.class)),
map));
List<PropertyDeclaration> properties = getProperties();
for (int i = 0, n = properties.size(); i < n; i++) {
PropertyDeclaration property = properties.get(i);
JdbcColumnTrait trait = property.getTrait(JdbcColumnTrait.class);
assert trait != null;
statements.add(new ExpressionBuilder(f, map)
.method("put", Models.toLiteral(f, trait.getName()), Models.toLiteral(f, i))
.toStatement());
}
statements.add(new ExpressionBuilder(f, f.newSimpleName(NAME_PROPERTY_POSITIONS))
.assignFrom(map)
.toStatement());
results.add(f.newInitializerDeclaration(
null,
new AttributeBuilder(f)
.Static()
.toAttributes(),
f.newBlock(statements)));
return results;
}