Search in sources :

Example 6 with RenameRefactoring

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();
    }
}
Also used : RenameRefactoring(com.intellij.refactoring.RenameRefactoring) PsiNamedElement(com.intellij.psi.PsiNamedElement)

Example 7 with RenameRefactoring

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();
    }
}
Also used : RenameRefactoring(com.intellij.refactoring.RenameRefactoring) RefactoringFactory(com.intellij.refactoring.RefactoringFactory) PsiElement(com.intellij.psi.PsiElement)

Example 8 with RenameRefactoring

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();
}
Also used : JavaRenameRefactoringImpl(com.intellij.refactoring.openapi.impl.JavaRenameRefactoringImpl) JavaCodeStyleManager(com.intellij.psi.codeStyle.JavaCodeStyleManager) RenameRefactoring(com.intellij.refactoring.RenameRefactoring)

Example 9 with RenameRefactoring

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");
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) RenameRefactoring(com.intellij.refactoring.RenameRefactoring) PsiNamedElement(com.intellij.psi.PsiNamedElement) PsiElement(com.intellij.psi.PsiElement)

Example 10 with RenameRefactoring

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();
}
Also used : JavaRenameRefactoringImpl(com.intellij.refactoring.openapi.impl.JavaRenameRefactoringImpl) RenameRefactoring(com.intellij.refactoring.RenameRefactoring)

Aggregations

RenameRefactoring (com.intellij.refactoring.RenameRefactoring)10 JavaRenameRefactoringImpl (com.intellij.refactoring.openapi.impl.JavaRenameRefactoringImpl)4 Project (com.intellij.openapi.project.Project)3 PsiClass (com.intellij.psi.PsiClass)3 PsiMethod (com.intellij.psi.PsiMethod)3 Result (com.intellij.openapi.application.Result)2 WriteCommandAction (com.intellij.openapi.command.WriteCommandAction)2 VirtualFile (com.intellij.openapi.vfs.VirtualFile)2 PsiElement (com.intellij.psi.PsiElement)2 PsiNamedElement (com.intellij.psi.PsiNamedElement)2 RefactoringFactory (com.intellij.refactoring.RefactoringFactory)2 Test (org.testng.annotations.Test)2 PsiFile (com.intellij.psi.PsiFile)1 JavaCodeStyleManager (com.intellij.psi.codeStyle.JavaCodeStyleManager)1