use of com.intellij.refactoring.rename.RenameProcessor in project android by JetBrains.
the class NlIdPropertyItem method setValue.
@Override
public void setValue(Object value) {
String newId = value != null ? stripIdPrefix(value.toString()) : "";
String oldId = getValue();
XmlTag tag = getTag();
if (ourRefactoringChoice != REFACTOR_NO && oldId != null && !oldId.isEmpty() && !newId.isEmpty() && !oldId.equals(newId) && tag != null && tag.isValid()) {
// Offer rename refactoring?
XmlAttribute attribute = tag.getAttribute(SdkConstants.ATTR_ID, SdkConstants.ANDROID_URI);
if (attribute != null) {
Module module = getModel().getModule();
Project project = module.getProject();
XmlAttributeValue valueElement = attribute.getValueElement();
if (valueElement != null && valueElement.isValid()) {
// Exact replace only, no comment/text occurrence changes since it is non-interactive
ValueResourceElementWrapper wrapper = new ValueResourceElementWrapper(valueElement);
RenameProcessor processor = new RenameProcessor(project, wrapper, NEW_ID_PREFIX + newId, false, /*comments*/
false);
processor.setPreviewUsages(false);
// Do a quick usage search to see if we need to ask about renaming
UsageInfo[] usages = processor.findUsages();
if (usages.length > 0) {
int choice = ourRefactoringChoice;
if (choice == REFACTOR_ASK) {
DialogBuilder builder = createDialogBuilder(project);
builder.setTitle("Update Usages?");
// UGH!
JPanel panel = new JPanel(new BorderLayout());
JLabel label = new JLabel("<html>" + "Update usages as well?<br>" + "This will update all XML references and Java R field references.<br>" + "<br>" + "</html>");
panel.add(label, BorderLayout.CENTER);
JBCheckBox checkBox = new JBCheckBox("Don't ask again during this session");
panel.add(checkBox, BorderLayout.SOUTH);
builder.setCenterPanel(panel);
builder.setDimensionServiceKey("idPropertyDimension");
builder.removeAllActions();
DialogBuilder.CustomizableAction yesAction = builder.addOkAction();
yesAction.setText(Messages.YES_BUTTON);
builder.addActionDescriptor(dialogWrapper -> new AbstractAction(Messages.NO_BUTTON) {
@Override
public void actionPerformed(ActionEvent actionEvent) {
dialogWrapper.close(DialogWrapper.NEXT_USER_EXIT_CODE);
}
});
builder.addCancelAction();
int exitCode = builder.show();
choice = exitCode == DialogWrapper.OK_EXIT_CODE ? REFACTOR_YES : exitCode == DialogWrapper.NEXT_USER_EXIT_CODE ? REFACTOR_NO : ourRefactoringChoice;
//noinspection AssignmentToStaticFieldFromInstanceMethod
ourRefactoringChoice = checkBox.isSelected() ? choice : REFACTOR_ASK;
if (exitCode == DialogWrapper.CANCEL_EXIT_CODE) {
return;
}
}
if (choice == REFACTOR_YES) {
processor.run();
return;
}
}
}
}
}
super.setValue(!StringUtil.isEmpty(newId) ? NEW_ID_PREFIX + newId : null);
}
use of com.intellij.refactoring.rename.RenameProcessor in project intellij-community by JetBrains.
the class MemberInplaceRenamer method performRenameInner.
protected void performRenameInner(PsiElement element, String newName) {
final RenameProcessor renameProcessor = createRenameProcessor(element, newName);
for (AutomaticRenamerFactory factory : Extensions.getExtensions(AutomaticRenamerFactory.EP_NAME)) {
if (factory.getOptionName() != null && factory.isEnabled() && factory.isApplicable(element)) {
renameProcessor.addRenamerFactory(factory);
}
}
renameProcessor.run();
}
use of com.intellij.refactoring.rename.RenameProcessor in project intellij-community by JetBrains.
the class RenameChangeInfo method perform.
public void perform() {
final PsiNameIdentifierOwner element = getNamedElement();
if (element != null) {
final String name = element.getName();
ApplicationManager.getApplication().runWriteAction(() -> {
element.setName(myOldName);
});
new RenameProcessor(element.getProject(), element, name, false, false).run();
}
}
use of com.intellij.refactoring.rename.RenameProcessor in project intellij-community by JetBrains.
the class RenameElementFix method invoke.
@Override
public void invoke(@NotNull Project project, @NotNull PsiFile file, @Nullable("is null when called from inspection") Editor editor, @NotNull PsiElement startElement, @NotNull PsiElement endElement) {
if (isAvailable(project, null, file)) {
LOG.assertTrue(file == startElement.getContainingFile());
if (!FileModificationService.getInstance().prepareFileForWrite(file))
return;
RenameProcessor processor = new RenameProcessor(project, startElement, myNewName, false, false);
processor.run();
}
}
use of com.intellij.refactoring.rename.RenameProcessor in project intellij-community by JetBrains.
the class RenameClassTest method doRenameClass.
private void doRenameClass(final String className, final String newName) throws Exception {
doTest((rootDir, rootAfter) -> {
PsiClass aClass = myJavaFacade.findClass(className, GlobalSearchScope.allScope(getProject()));
assertNotNull("Class XX not found", aClass);
final RenameProcessor processor = new RenameProcessor(myProject, aClass, newName, true, true);
for (AutomaticRenamerFactory factory : Extensions.getExtensions(AutomaticRenamerFactory.EP_NAME)) {
processor.addRenamerFactory(factory);
}
processor.run();
PsiDocumentManager.getInstance(myProject).commitAllDocuments();
FileDocumentManager.getInstance().saveAllDocuments();
});
}
Aggregations