use of com.intellij.refactoring.RenameRefactoring in project intellij-community by JetBrains.
the class AliasingPsiTargetUtil method renameTargets.
public static void renameTargets(AliasingPsiTarget target, @NotNull String newDelegateName) {
final PsiNamedElement namedElement = (PsiNamedElement) target.getNavigationElement();
if (!newDelegateName.equals(namedElement.getName())) {
final RenameRefactoring refactoring = RefactoringFactory.getInstance(namedElement.getProject()).createRename(namedElement, newDelegateName);
refactoring.run();
}
}
use of com.intellij.refactoring.RenameRefactoring in project intellij-community by JetBrains.
the class RenameFix method doFix.
@Override
public void doFix(Project project, ProblemDescriptor descriptor) {
if (m_targetName == null) {
super.doFix(project, descriptor);
} else {
final PsiElement nameIdentifier = descriptor.getPsiElement();
final PsiElement elementToRename = nameIdentifier.getParent();
final RefactoringFactory factory = RefactoringFactory.getInstance(project);
final RenameRefactoring renameRefactoring = factory.createRename(elementToRename, m_targetName, m_searchInStrings, m_searchInNonJavaFiles);
renameRefactoring.run();
}
}
use of com.intellij.refactoring.RenameRefactoring in project intellij-community by JetBrains.
the class BeanPropertyRenameHandler method doRename.
public static void doRename(@NotNull final BeanProperty property, final String newName, final boolean searchInComments, boolean isPreview) {
final PsiElement psiElement = property.getPsiElement();
final RenameRefactoring rename = new JavaRenameRefactoringImpl(psiElement.getProject(), psiElement, newName, searchInComments, false);
rename.setPreviewUsages(isPreview);
final PsiMethod setter = property.getSetter();
if (setter != null) {
final String setterName = PropertyUtil.suggestSetterName(newName);
rename.addElement(setter, setterName);
final PsiParameter[] setterParameters = setter.getParameterList().getParameters();
if (setterParameters.length == 1) {
final JavaCodeStyleManager manager = JavaCodeStyleManager.getInstance(psiElement.getProject());
final String suggestedParameterName = manager.propertyNameToVariableName(property.getName(), VariableKind.PARAMETER);
if (suggestedParameterName.equals(setterParameters[0].getName())) {
rename.addElement(setterParameters[0], manager.propertyNameToVariableName(newName, VariableKind.PARAMETER));
}
}
}
final PsiMethod getter = property.getGetter();
if (getter != null) {
final String getterName = PropertyUtil.suggestGetterName(newName, getter.getReturnType());
rename.addElement(getter, getterName);
}
rename.run();
}
use of com.intellij.refactoring.RenameRefactoring in project intellij-community by JetBrains.
the class AntRenameTest method doTest.
private void doTest() throws Exception {
final String filename = getTestName(true) + ".xml";
VirtualFile vfile = VirtualFileManager.getInstance().findFileByUrl("file://" + getTestDataPath() + filename);
String text = FileDocumentManager.getInstance().getDocument(vfile).getText();
final int off = text.indexOf("<ren>");
text = text.replace("<ren>", "");
configureFromFileText(filename, text);
assertNotNull(myFile);
PsiElement element = TargetElementUtil.getInstance().findTargetElement(getEditor(), TargetElementUtil.REFERENCED_ELEMENT_ACCEPTED | TargetElementUtil.ELEMENT_NAME_ACCEPTED, off);
assertNotNull(element);
assertTrue(element instanceof PsiNamedElement);
final RenameRefactoring rename = RefactoringFactory.getInstance(getProject()).createRename(element, ((PsiNamedElement) element).getName() + "-after");
rename.setSearchInComments(false);
rename.setSearchInNonJavaFiles(false);
rename.run();
checkResultByFile(filename + "-after");
}
use of com.intellij.refactoring.RenameRefactoring in project intellij-community by JetBrains.
the class JavaFxPropertyRenameHandler method doRenameFxId.
public static void doRenameFxId(XmlAttributeValue fxIdValueElement, String newName, boolean searchInComments, boolean previewUsages) {
final RenameRefactoring rename = new JavaRenameRefactoringImpl(fxIdValueElement.getProject(), fxIdValueElement, newName, searchInComments, false);
rename.setPreviewUsages(previewUsages);
final PsiField nestedControllerField = getNestedControllerField(fxIdValueElement);
if (nestedControllerField != null) {
rename.addElement(nestedControllerField, newName + FxmlConstants.CONTROLLER_SUFFIX);
}
rename.run();
}
Aggregations