Search in sources :

Example 1 with JavaRenameRefactoringImpl

use of com.intellij.refactoring.openapi.impl.JavaRenameRefactoringImpl in project intellij-community by JetBrains.

the class JavaFXRenameTest method testStaticPropertyMethod.

public void testStaticPropertyMethod() throws Exception {
    final String className = "container.MyCustomContainer";
    final String methodName = "setStaticProp";
    final String newName = "setNewMethodName";
    myFixture.configureByFiles(getTestName(true) + ".fxml", className.replace('.', '/') + ".java");
    final PsiClass psiClass = myFixture.findClass(className);
    assertNotNull(psiClass);
    final PsiMethod[] methods = psiClass.findMethodsByName(methodName, false);
    assertEquals(1, methods.length);
    final PsiMethod method = methods[0];
    final RenameRefactoring rename = new JavaRenameRefactoringImpl(getProject(), method, newName, false, false);
    rename.run();
    myFixture.checkResultByFile(getTestName(true) + "_after.fxml");
    assertMethodExists(psiClass, newName);
}
Also used : JavaRenameRefactoringImpl(com.intellij.refactoring.openapi.impl.JavaRenameRefactoringImpl) PsiMethod(com.intellij.psi.PsiMethod) RenameRefactoring(com.intellij.refactoring.RenameRefactoring) PsiClass(com.intellij.psi.PsiClass)

Example 2 with JavaRenameRefactoringImpl

use of com.intellij.refactoring.openapi.impl.JavaRenameRefactoringImpl in project intellij-community by JetBrains.

the class JavaFxPropertyRenameHandler method doRename.

private static void doRename(JavaFxPropertyReference reference, String newName, final boolean searchInComments, boolean isPreview) {
    final PsiElement psiElement = JavaFxPropertyElement.fromReference(reference);
    if (psiElement == null)
        return;
    final RenameRefactoring rename = new JavaRenameRefactoringImpl(psiElement.getProject(), psiElement, newName, searchInComments, false);
    rename.setPreviewUsages(isPreview);
    final Map<PsiElement, String> elementsToRename = getElementsToRename(reference, newName);
    elementsToRename.forEach(rename::addElement);
    rename.run();
}
Also used : JavaRenameRefactoringImpl(com.intellij.refactoring.openapi.impl.JavaRenameRefactoringImpl) RenameRefactoring(com.intellij.refactoring.RenameRefactoring)

Example 3 with JavaRenameRefactoringImpl

use of com.intellij.refactoring.openapi.impl.JavaRenameRefactoringImpl 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 4 with JavaRenameRefactoringImpl

use of com.intellij.refactoring.openapi.impl.JavaRenameRefactoringImpl 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)4 JavaRenameRefactoringImpl (com.intellij.refactoring.openapi.impl.JavaRenameRefactoringImpl)4 PsiClass (com.intellij.psi.PsiClass)1 PsiMethod (com.intellij.psi.PsiMethod)1 JavaCodeStyleManager (com.intellij.psi.codeStyle.JavaCodeStyleManager)1