}
TextEdit rootEdit = fileChange.getEdit();
/* loop over all renames to perform */
for (Map.Entry<IPackageFragment,RenameArguments> entry : pkgFragments.entrySet()) {
IPackageFragment pkgFragment = entry.getKey();
RenameArguments arguments = entry.getValue();
final String oldName = pkgFragment.getElementName();
final String newName = arguments.getNewName();
Pattern pattern = Pattern.compile(
/* match start boundary */"(^|" + grammarSeparator + ")" +
/* match itself / package name */"(" + Pattern.quote(oldName) + ")" +
/* match end boundary */"(" + grammarSeparator + "|" + Pattern.quote(".*") + "|" + Pattern.quote("\\") + "|$)");
/* find all matches to replace and add them to the root edit */
Matcher matcher = pattern.matcher(bndFileText);
while (matcher.find()) {
rootEdit.addChild(new ReplaceEdit(matcher.start(2), matcher.group(2).length(), newName));
}
pattern = Pattern.compile(
/* match start boundary */"(^|" + grammarSeparator + ")" +
/* match bundle activator */"(Bundle-Activator\\s*:\\s*)" +
/* match itself / package name */"(" + Pattern.quote(oldName) + ")" +
/* match class name */"(\\.[^\\.]+)" +
/* match end boundary */"(" + grammarSeparator + "|" + Pattern.quote("\\") + "|$)");
/* find all matches to replace and add them to the root edit */
matcher = pattern.matcher(bndFileText);
while (matcher.find()) {
rootEdit.addChild(new ReplaceEdit(matcher.start(3), matcher.group(3).length(), newName));
}
}
/*
* only store the changes when no changes were stored before for this file and when there are actually
* changes.
*/
if (fileChangeIsNew && rootEdit.hasChildren()) {
fileChanges.put(resource, fileChange);
}
return false;
}
};
/* determine which projects have to be visited */
Set<IProject> projectsToVisit = new HashSet<IProject>();
for (IPackageFragment pkgFragment : pkgFragments.keySet()) {
projectsToVisit.add(pkgFragment.getResource().getProject());
for (IProject projectToVisit : pkgFragment.getResource().getProject().getReferencingProjects()) {
projectsToVisit.add(projectToVisit);
}
for (IProject projectToVisit : pkgFragment.getResource().getProject().getReferencedProjects()) {
projectsToVisit.add(projectToVisit);
}
}
/* visit the projects */