TypeUtil.modifyType(unit, monitor, new TypeUtil.ModifyTypeHandler() {
public void modify(final ASTNode node, final ASTRewrite rewrite,
final ImportsStructure imports) {
node.accept(new ASTVisitor() {
@Override
public void endVisit(TypeDeclaration node) {
ListRewrite lr = rewrite.getListRewrite(node,TypeDeclaration.MODIFIERS2_PROPERTY);
for (Iterator i = node.modifiers().iterator(); i.hasNext();) {
IExtendedModifier em = (IExtendedModifier) i.next();
if (em.isModifier()) {
ASTNode entity = rewrite
.createStringPlaceholder(
'@' + imports.addImport("javax.persistence.Entity"),ASTNode.MARKER_ANNOTATION);
lr.insertBefore(entity, (Modifier) em, null);
String metaName = currentSelection.getMetaData().getName();
if (getPrimaryName(unit).equalsIgnoreCase(metaName) == false) {
StringBuffer stb = new StringBuffer();
stb.append('@');
stb.append(imports.addImport("javax.persistence.Table"));
stb.append("(name=\"");
stb.append(metaName);
stb.append("\")");
ASTNode table = rewrite.createStringPlaceholder(stb.toString(),
ASTNode.NORMAL_ANNOTATION);
lr.insertBefore(table, (Modifier) em, null);
}
break;
}
}
}
});
}
});