Search in sources :

Example 1 with AutomaticRenamerFactory

use of com.intellij.refactoring.rename.naming.AutomaticRenamerFactory 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 AutomaticRenamerFactory

use of com.intellij.refactoring.rename.naming.AutomaticRenamerFactory 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();
}
Also used : AutomaticRenamerFactory(com.intellij.refactoring.rename.naming.AutomaticRenamerFactory) RenameProcessor(com.intellij.refactoring.rename.RenameProcessor)

Example 3 with AutomaticRenamerFactory

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

the class VariableInplaceRenamer method performRefactoringRename.

protected void performRefactoringRename(final String newName, final StartMarkAction markAction) {
    final String refactoringId = getRefactoringId();
    try {
        PsiNamedElement elementToRename = getVariable();
        if (refactoringId != null) {
            final RefactoringEventData beforeData = new RefactoringEventData();
            beforeData.addElement(elementToRename);
            beforeData.addStringProperties(myOldName);
            myProject.getMessageBus().syncPublisher(RefactoringEventListener.REFACTORING_EVENT_TOPIC).refactoringStarted(refactoringId, beforeData);
        }
        if (!isIdentifier(newName, myLanguage)) {
            return;
        }
        if (elementToRename != null) {
            new WriteCommandAction(myProject, getCommandName()) {

                @Override
                protected void run(@NotNull Result result) throws Throwable {
                    renameSynthetic(newName);
                }
            }.execute();
        }
        AutomaticRenamerFactory[] factories = Extensions.getExtensions(AutomaticRenamerFactory.EP_NAME);
        for (AutomaticRenamerFactory renamerFactory : factories) {
            if (elementToRename != null && renamerFactory.isApplicable(elementToRename)) {
                final List<UsageInfo> usages = new ArrayList<>();
                final AutomaticRenamer renamer = renamerFactory.createRenamer(elementToRename, newName, new ArrayList<>());
                if (renamer.hasAnythingToRename()) {
                    if (!ApplicationManager.getApplication().isUnitTestMode()) {
                        final AutomaticRenamingDialog renamingDialog = new AutomaticRenamingDialog(myProject, renamer);
                        if (!renamingDialog.showAndGet()) {
                            continue;
                        }
                    }
                    final Runnable runnable = () -> ApplicationManager.getApplication().runReadAction(() -> renamer.findUsages(usages, false, false));
                    if (!ProgressManager.getInstance().runProcessWithProgressSynchronously(runnable, RefactoringBundle.message("searching.for.variables"), true, myProject)) {
                        return;
                    }
                    if (!CommonRefactoringUtil.checkReadOnlyStatus(myProject, PsiUtilCore.toPsiElementArray(renamer.getElements())))
                        return;
                    final Runnable performAutomaticRename = () -> {
                        CommandProcessor.getInstance().markCurrentCommandAsGlobal(myProject);
                        final UsageInfo[] usageInfos = usages.toArray(new UsageInfo[usages.size()]);
                        final MultiMap<PsiElement, UsageInfo> classified = RenameProcessor.classifyUsages(renamer.getElements(), usageInfos);
                        for (final PsiNamedElement element : renamer.getElements()) {
                            final String newElementName = renamer.getNewName(element);
                            if (newElementName != null) {
                                final Collection<UsageInfo> infos = classified.get(element);
                                RenameUtil.doRename(element, newElementName, infos.toArray(new UsageInfo[infos.size()]), myProject, RefactoringElementListener.DEAF);
                            }
                        }
                    };
                    final WriteCommandAction writeCommandAction = new WriteCommandAction(myProject, getCommandName()) {

                        @Override
                        protected void run(@NotNull Result result) throws Throwable {
                            performAutomaticRename.run();
                        }
                    };
                    if (ApplicationManager.getApplication().isUnitTestMode()) {
                        writeCommandAction.execute();
                    } else {
                        ApplicationManager.getApplication().invokeLater(() -> writeCommandAction.execute());
                    }
                }
            }
        }
    } finally {
        if (refactoringId != null) {
            final RefactoringEventData afterData = new RefactoringEventData();
            afterData.addElement(getVariable());
            afterData.addStringProperties(newName);
            myProject.getMessageBus().syncPublisher(RefactoringEventListener.REFACTORING_EVENT_TOPIC).refactoringDone(refactoringId, afterData);
        }
        try {
            ((EditorImpl) InjectedLanguageUtil.getTopLevelEditor(myEditor)).stopDumbLater();
        } finally {
            FinishMarkAction.finish(myProject, myEditor, markAction);
        }
    }
}
Also used : WriteCommandAction(com.intellij.openapi.command.WriteCommandAction) AutomaticRenamer(com.intellij.refactoring.rename.naming.AutomaticRenamer) EditorImpl(com.intellij.openapi.editor.impl.EditorImpl) ArrayList(java.util.ArrayList) NotNull(org.jetbrains.annotations.NotNull) Result(com.intellij.openapi.application.Result) MultiMap(com.intellij.util.containers.MultiMap) AutomaticRenamerFactory(com.intellij.refactoring.rename.naming.AutomaticRenamerFactory) RefactoringEventData(com.intellij.refactoring.listeners.RefactoringEventData) Collection(java.util.Collection) UsageInfo(com.intellij.usageView.UsageInfo)

Example 4 with AutomaticRenamerFactory

use of com.intellij.refactoring.rename.naming.AutomaticRenamerFactory 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();
    });
}
Also used : AutomaticRenamerFactory(com.intellij.refactoring.rename.naming.AutomaticRenamerFactory) RenameProcessor(com.intellij.refactoring.rename.RenameProcessor) PsiClass(com.intellij.psi.PsiClass)

Example 5 with AutomaticRenamerFactory

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

the class RenameMethodMultiTest method doAutomaticRenameMethod.

private void doAutomaticRenameMethod(final String className, final String methodSignature, final String newName) throws Exception {
    doTest((rootDir, rootAfter) -> {
        final JavaPsiFacade manager = getJavaFacade();
        final PsiClass aClass = manager.findClass(className, GlobalSearchScope.moduleScope(myModule));
        assertNotNull(aClass);
        final PsiMethod methodBySignature = aClass.findMethodBySignature(manager.getElementFactory().createMethodFromText(methodSignature + "{}", null), false);
        assertNotNull(methodBySignature);
        final RenameProcessor processor = new RenameProcessor(myProject, methodBySignature, newName, false, false);
        for (AutomaticRenamerFactory factory : Extensions.getExtensions(AutomaticRenamerFactory.EP_NAME)) {
            processor.addRenamerFactory(factory);
        }
        processor.run();
        PsiDocumentManager.getInstance(myProject).commitAllDocuments();
        FileDocumentManager.getInstance().saveAllDocuments();
    });
}
Also used : JavaPsiFacade(com.intellij.psi.JavaPsiFacade) AutomaticRenamerFactory(com.intellij.refactoring.rename.naming.AutomaticRenamerFactory) RenameProcessor(com.intellij.refactoring.rename.RenameProcessor) PsiMethod(com.intellij.psi.PsiMethod) PsiClass(com.intellij.psi.PsiClass)

Aggregations

AutomaticRenamerFactory (com.intellij.refactoring.rename.naming.AutomaticRenamerFactory)8 RenameProcessor (com.intellij.refactoring.rename.RenameProcessor)5 PsiClass (com.intellij.psi.PsiClass)2 UsageInfo (com.intellij.usageView.UsageInfo)2 NotNull (org.jetbrains.annotations.NotNull)2 ResourceBundleRenamerFactory (com.intellij.lang.properties.refactoring.rename.ResourceBundleRenamerFactory)1 Result (com.intellij.openapi.application.Result)1 WriteCommandAction (com.intellij.openapi.command.WriteCommandAction)1 EditorImpl (com.intellij.openapi.editor.impl.EditorImpl)1 JavaPsiFacade (com.intellij.psi.JavaPsiFacade)1 PsiFile (com.intellij.psi.PsiFile)1 PsiMethod (com.intellij.psi.PsiMethod)1 RefactoringEventData (com.intellij.refactoring.listeners.RefactoringEventData)1 AutomaticRenamer (com.intellij.refactoring.rename.naming.AutomaticRenamer)1 MoveRenameUsageInfo (com.intellij.refactoring.util.MoveRenameUsageInfo)1 NonCodeUsageInfo (com.intellij.refactoring.util.NonCodeUsageInfo)1 RelatedUsageInfo (com.intellij.refactoring.util.RelatedUsageInfo)1 NonFocusableCheckBox (com.intellij.ui.NonFocusableCheckBox)1 MultiMap (com.intellij.util.containers.MultiMap)1 ArrayList (java.util.ArrayList)1