Search in sources :

Example 1 with RenameProcessor

use of com.intellij.refactoring.rename.RenameProcessor in project intellij-community by JetBrains.

the class ResourceBundleTest method doTestRenameResourceBundleEntryFile.

private void doTestRenameResourceBundleEntryFile(String fileNameToRenameBefore, String fileNameToCheckBefore, String fileNameToRenameAfter, String fileNameToCheckAfter) {
    final PsiFile toRenameFile = myFixture.addFileToProject(fileNameToRenameBefore, "");
    final PsiFile toCheck = myFixture.addFileToProject(fileNameToCheckBefore, "");
    final RenameProcessor processor = new RenameProcessor(getProject(), toRenameFile, fileNameToRenameAfter, true, true);
    for (AutomaticRenamerFactory factory : Extensions.getExtensions(AutomaticRenamerFactory.EP_NAME)) {
        if (factory instanceof ResourceBundleRenamerFactory) {
            processor.addRenamerFactory(factory);
        }
    }
    processor.run();
    assertEquals(fileNameToCheckAfter, toCheck.getName());
}
Also used : AutomaticRenamerFactory(com.intellij.refactoring.rename.naming.AutomaticRenamerFactory) RenameProcessor(com.intellij.refactoring.rename.RenameProcessor) ResourceBundleRenamerFactory(com.intellij.lang.properties.refactoring.rename.ResourceBundleRenamerFactory) PsiFile(com.intellij.psi.PsiFile)

Example 2 with RenameProcessor

use of com.intellij.refactoring.rename.RenameProcessor in project intellij-community by JetBrains.

the class BindingProperty method updateBoundFieldName.

public static void updateBoundFieldName(final RadRootContainer root, final String oldName, final String newName, final String fieldClassName) {
    final String classToBind = root.getClassToBind();
    if (classToBind == null)
        return;
    final Project project = root.getProject();
    if (newName.length() == 0) {
        checkRemoveUnusedField(root, oldName, FormEditingUtil.getNextSaveUndoGroupId(project));
        return;
    }
    final PsiClass aClass = JavaPsiFacade.getInstance(project).findClass(classToBind, GlobalSearchScope.allScope(project));
    if (aClass == null) {
        return;
    }
    if (oldName == null) {
        if (aClass.findFieldByName(newName, true) == null) {
            CreateFieldFix.runImpl(project, root, aClass, fieldClassName, newName, false, FormEditingUtil.getNextSaveUndoGroupId(project));
        }
        return;
    }
    final PsiField oldField = aClass.findFieldByName(oldName, true);
    if (oldField == null) {
        return;
    }
    if (aClass.findFieldByName(newName, true) != null) {
        checkRemoveUnusedField(root, oldName, FormEditingUtil.getNextSaveUndoGroupId(project));
        return;
    }
    if (!isFieldUnreferenced(oldField)) {
        final int option = Messages.showYesNoDialog(project, MessageFormat.format(UIDesignerBundle.message("message.rename.field"), oldName, newName), UIDesignerBundle.message("title.rename"), Messages.getQuestionIcon());
        if (option != Messages.YES) /*Yes*/
        {
            return;
        }
    }
    // Commit document before refactoring starts
    GuiEditor editor = DesignerToolWindowManager.getInstance(project).getActiveFormEditor();
    if (editor != null) {
        editor.refreshAndSave(false);
    }
    PsiDocumentManager.getInstance(project).commitAllDocuments();
    if (!CommonRefactoringUtil.checkReadOnlyStatus(project, aClass)) {
        return;
    }
    final RenameProcessor processor = new RenameProcessor(project, oldField, newName, true, true);
    processor.run();
}
Also used : Project(com.intellij.openapi.project.Project) RenameProcessor(com.intellij.refactoring.rename.RenameProcessor) GuiEditor(com.intellij.uiDesigner.designSurface.GuiEditor)

Example 3 with RenameProcessor

use of com.intellij.refactoring.rename.RenameProcessor in project intellij-community by JetBrains.

the class PyMakePublicQuickFix method applyFix.

@Override
public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) {
    PsiElement element = descriptor.getPsiElement();
    if (element instanceof PyReferenceExpression) {
        final PsiReference reference = element.getReference();
        if (reference == null)
            return;
        element = reference.resolve();
    }
    if (element instanceof PyTargetExpression) {
        final String name = ((PyTargetExpression) element).getName();
        if (name == null)
            return;
        final VirtualFile virtualFile = element.getContainingFile().getVirtualFile();
        if (virtualFile != null) {
            final String publicName = StringUtil.trimLeading(name, '_');
            new RenameProcessor(project, element, publicName, false, false).run();
        }
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) PyTargetExpression(com.jetbrains.python.psi.PyTargetExpression) RenameProcessor(com.intellij.refactoring.rename.RenameProcessor) PsiReference(com.intellij.psi.PsiReference) PsiElement(com.intellij.psi.PsiElement) PyReferenceExpression(com.jetbrains.python.psi.PyReferenceExpression)

Example 4 with RenameProcessor

use of com.intellij.refactoring.rename.RenameProcessor in project smali by JesusFreke.

the class ClassRenameTest method doRename.

private void doRename(String oldQualifiedName, String newName) throws Exception {
    PsiClass testClass = myJavaFacade.findClass(oldQualifiedName, GlobalSearchScope.allScope(getProject()));
    RenameProcessor processor = new RenameProcessor(getProject(), testClass, newName, false, false);
    processor.run();
    PsiDocumentManager.getInstance(getProject()).commitAllDocuments();
    FileDocumentManager.getInstance().saveAllDocuments();
}
Also used : RenameProcessor(com.intellij.refactoring.rename.RenameProcessor) PsiClass(com.intellij.psi.PsiClass)

Example 5 with RenameProcessor

use of com.intellij.refactoring.rename.RenameProcessor in project smali by JesusFreke.

the class FieldRenameTest method doRename.

private void doRename(String containingClass, String oldFieldName, String newFieldName) throws Exception {
    PsiClass testClass = myJavaFacade.findClass(containingClass, GlobalSearchScope.allScope(getProject()));
    PsiField field = testClass.findFieldByName(oldFieldName, false);
    RenameProcessor processor = new RenameProcessor(getProject(), field, newFieldName, false, false);
    processor.run();
    PsiDocumentManager.getInstance(getProject()).commitAllDocuments();
    FileDocumentManager.getInstance().saveAllDocuments();
}
Also used : RenameProcessor(com.intellij.refactoring.rename.RenameProcessor) PsiField(com.intellij.psi.PsiField) PsiClass(com.intellij.psi.PsiClass)

Aggregations

RenameProcessor (com.intellij.refactoring.rename.RenameProcessor)32 PsiElement (com.intellij.psi.PsiElement)10 PsiClass (com.intellij.psi.PsiClass)7 AutomaticRenamerFactory (com.intellij.refactoring.rename.naming.AutomaticRenamerFactory)5 PsiMethod (com.intellij.psi.PsiMethod)3 Project (com.intellij.openapi.project.Project)2 VirtualFile (com.intellij.openapi.vfs.VirtualFile)2 JavaPsiFacade (com.intellij.psi.JavaPsiFacade)2 BuildFile (com.google.idea.blaze.base.lang.buildfile.psi.BuildFile)1 WorkspacePath (com.google.idea.blaze.base.model.primitives.WorkspacePath)1 AbstractProjectViewPSIPane (com.intellij.ide.projectView.impl.AbstractProjectViewPSIPane)1 ClassesTreeStructureProvider (com.intellij.ide.projectView.impl.ClassesTreeStructureProvider)1 FlexMxmlNSDescriptor (com.intellij.javascript.flex.mxml.schema.FlexMxmlNSDescriptor)1 ResourceBundleRenamerFactory (com.intellij.lang.properties.refactoring.rename.ResourceBundleRenamerFactory)1 Editor (com.intellij.openapi.editor.Editor)1 Module (com.intellij.openapi.module.Module)1 DialogBuilder (com.intellij.openapi.ui.DialogBuilder)1 ProperTextRange (com.intellij.openapi.util.ProperTextRange)1 TextRange (com.intellij.openapi.util.TextRange)1 PsiField (com.intellij.psi.PsiField)1