String oldMethodAnnotations = "";
String oldMethodSourceCode = "";
String targetBean = Utils.getTargetBean(compilationUnit,method.getElementName());
AttributesSelectionDialog attributesSelectionDialog = new AttributesSelectionDialog(Utils.getCompilationUnit(compilationUnit,targetBean),true,false);
attributesSelectionDialog.pack();
attributesSelectionDialog.setLocationRelativeTo(null);
attributesSelectionDialog.setVisible(true);
if(!attributesSelectionDialog.selectedAttributes())
return;
// Dal codice esistente rimuove l'annotazione se presente
StringTokenizer st = new StringTokenizer(method.getSource(),"\t\n\r\f");
while (st.hasMoreTokens())
{
String token = st.nextToken();
if(!token.contains("@ShowRelationshipAttributesInForm"))
{
if (token.startsWith("@"))
oldMethodAnnotations += token + "\r\n";
else
oldMethodSourceCode += token + "\r\n";
}
}
IType type = compilationUnit.getTypes()[0];
//Rimuove il metodo esistente
type.getMethod(method.getElementName(),null).delete(true, null);
newMethodSourceCode += "\r\n@ShowRelationshipAttributesInForm(names="+attributesSelectionDialog.getSelectedAttributes()+", orders="+attributesSelectionDialog.getSelectedAttributesOrders()+")\r\n";
newMethodSourceCode = oldMethodAnnotations + newMethodSourceCode + oldMethodSourceCode + "\r\n";
type.createMethod(newMethodSourceCode, null, true, null);