return status;
}
@Override
public Change createChange(IProgressMonitor pm) throws CoreException, OperationCanceledException {
CompositeChange changes = null;
String content;
changes = new CompositeChange("Fix " + currentName + " field on DRL files");
IFile file = getSourceFieldIFile();
String typeName = sourceField.getParent().getElementName();
Pattern fieldPattern = Pattern.compile(FIELD_NAME.replaceAll("FIELD_NAME", currentName));
Pattern typePattern = Pattern.compile(VARIABLE_ASSIGNED.replace("TYPE", typeName));
if (file!=null) {
RenameFieldProcessor renameFieldProcessor = (RenameFieldProcessor)processor;
for (IFile drlFile : drlFiles) {
if ((content = FileUtil.readFile(drlFile))==null)
return null;
TextFileChange change = new TextFileChange(drlFile.getName(), drlFile);
MultiTextEdit mte = new MultiTextEdit();
change.setEdit(mte);
// rename the field name
Matcher matcher = fieldPattern.matcher(content);
while (matcher.find()) {
if (isFieldInRightType(content, typeName, matcher.start())) {
ReplaceEdit replace = new ReplaceEdit(matcher.start(), currentName.length(), newName);
mte.addChild(replace);
}
}
// search all the variables of the type to replace the getters/setters
matcher = typePattern.matcher(content);
while (matcher.find()) {
if (matcher.group().length() > 0) {
String variableNameAssigned = matcher.group();
if (renameFieldProcessor.getRenameGetter()) {
String newGetterName = renameFieldProcessor.getNewGetterName();
String currentGetterName = renameFieldProcessor.getGetter().getElementName();
String regexp = GETTER_NAME.replace("VARIABLE_NAME", variableNameAssigned).replace("CURRENT_GETTER_NAME", currentGetterName);
createFieldRenameChanges(mte, content, regexp, currentGetterName, newGetterName);
}
if (renameFieldProcessor.getRenameSetter()) {
String newSetterName = renameFieldProcessor.getNewSetterName();
String currentSetterName = renameFieldProcessor.getSetter().getElementName();
String regexp = SETTER_NAME.replace("VARIABLE_NAME", variableNameAssigned).replace("CURRENT_SETTER_NAME", currentSetterName);
createFieldRenameChanges(mte, content, regexp, currentSetterName, newSetterName);
}
}
}
if (change.getEdit().getChildrenSize() > 0)
changes.add(change);
}
}
return (changes.getChildren().length > 0)?changes:null;
}