use of com.intellij.refactoring.rename.RenamePsiPackageProcessor in project android by JetBrains.
the class AndroidApplicationPackageRenameProcessor method renameElement.
@Override
public void renameElement(PsiElement element, String newName, UsageInfo[] usages, @Nullable RefactoringElementListener listener) throws IncorrectOperationException {
if (element instanceof PsiPackage) {
final Map<GenericAttributeValue, String> newAttrValues = new HashMap<GenericAttributeValue, String>();
final Project project = element.getProject();
final String oldPackageQName = ((PsiPackage) element).getQualifiedName();
final String newPackageQName = PsiUtilCore.getQualifiedNameAfterRename(oldPackageQName, newName);
for (Module module : ModuleManager.getInstance(project).getModules()) {
final AndroidFacet facet = AndroidFacet.getInstance(module);
final Manifest manifest = facet != null ? facet.getManifest() : null;
if (manifest != null) {
final XmlElement manifestElement = manifest.getXmlElement();
final PsiFile manifestPsiFile = manifestElement != null ? manifestElement.getContainingFile() : null;
if (manifestPsiFile instanceof XmlFile) {
final String basePackage = manifest.getPackage().getValue();
if (basePackage == null) {
continue;
}
processAllAttributesToUpdate((XmlFile) manifestPsiFile, basePackage, oldPackageQName, newPackageQName, new Processor<Pair<GenericAttributeValue, String>>() {
@Override
public boolean process(Pair<GenericAttributeValue, String> pair) {
newAttrValues.put(pair.getFirst(), pair.getSecond());
return true;
}
});
}
}
}
new RenamePsiPackageProcessor().renameElement(element, newName, usages, listener);
for (Map.Entry<GenericAttributeValue, String> e : newAttrValues.entrySet()) {
//noinspection unchecked
e.getKey().setStringValue(e.getValue());
}
return;
}
final PsiFile file = element.getContainingFile();
if (!(file instanceof XmlFile)) {
return;
}
final Map<GenericAttributeValue, PsiClass> attr2class = buildAttr2ClassMap((XmlFile) file);
new RenameXmlAttributeProcessor().renameElement(element, newName, usages, listener);
for (Map.Entry<GenericAttributeValue, PsiClass> e : attr2class.entrySet()) {
//noinspection unchecked
e.getKey().setValue(e.getValue());
}
}
Aggregations