Search in sources :

Example 1 with RenameHandler

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

the class JavaFXRenameTest method doTestPropertyRenameHandler.

public void doTestPropertyRenameHandler(String... files) throws Exception {
    myFixture.configureByFiles(files);
    final MapDataContext dataContext = new MapDataContext();
    dataContext.put(CommonDataKeys.EDITOR, getEditor());
    final RenameHandler renameHandler = RenameHandlerRegistry.getInstance().getRenameHandler(dataContext);
    assertTrue(renameHandler instanceof JavaFxPropertyRenameHandler);
}
Also used : JavaFxPropertyRenameHandler(org.jetbrains.plugins.javaFX.refactoring.JavaFxPropertyRenameHandler) MapDataContext(com.intellij.testFramework.MapDataContext) PsiElementRenameHandler(com.intellij.refactoring.rename.PsiElementRenameHandler) JavaFxPropertyRenameHandler(org.jetbrains.plugins.javaFX.refactoring.JavaFxPropertyRenameHandler) MemberInplaceRenameHandler(com.intellij.refactoring.rename.inplace.MemberInplaceRenameHandler) RenameHandler(com.intellij.refactoring.rename.RenameHandler)

Example 2 with RenameHandler

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

the class MavenDomTestCase method assertCannotRename.

protected void assertCannotRename() throws Exception {
    MapDataContext context = createRenameDataContext(myProjectPom, "new name");
    RenameHandler handler = RenameHandlerRegistry.getInstance().getRenameHandler(context);
    if (handler == null)
        return;
    try {
        invokeRename(context, handler);
    } catch (CommonRefactoringUtil.RefactoringErrorHintException e) {
        if (!e.getMessage().startsWith("Cannot perform refactoring.")) {
            throw e;
        }
    }
}
Also used : MapDataContext(com.intellij.testFramework.MapDataContext) CommonRefactoringUtil(com.intellij.refactoring.util.CommonRefactoringUtil) RenameHandler(com.intellij.refactoring.rename.RenameHandler) PsiElementRenameHandler(com.intellij.refactoring.rename.PsiElementRenameHandler)

Example 3 with RenameHandler

use of com.intellij.refactoring.rename.RenameHandler in project android by JetBrains.

the class RenameTest method sourceRoot.

@Test
public void sourceRoot() throws Exception {
    guiTest.importSimpleApplication();
    final Project project = guiTest.ideFrame().getProject();
    Module[] modules = ModuleManager.getInstance(project).getModules();
    for (Module module : modules) {
        final VirtualFile[] sourceRoots = ModuleRootManager.getInstance(module).getSourceRoots();
        for (final VirtualFile sourceRoot : sourceRoots) {
            PsiDirectory directory = GuiQuery.getNonNull(() -> PsiManager.getInstance(project).findDirectory(sourceRoot));
            for (final RenameHandler handler : Extensions.getExtensions(RenameHandler.EP_NAME)) {
                if (handler instanceof DirectoryAsPackageRenameHandler) {
                    final RenameDialogFixture renameDialog = RenameDialogFixture.startFor(directory, handler, guiTest.robot());
                    assertFalse(renameDialog.warningExists(null));
                    renameDialog.setNewName(renameDialog.getNewName() + 1);
                    // 'Rename dialog' show a warning asynchronously to the text change, that's why we wait here for the
                    // warning to appear
                    Wait.seconds(1).expecting("error text to appear").until(() -> renameDialog.warningExists(AndroidBundle.message("android.refactoring.gradle.warning.rename.source.root")));
                    renameDialog.clickCancel();
                    return;
                }
            }
        }
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) DirectoryAsPackageRenameHandler(com.intellij.refactoring.rename.DirectoryAsPackageRenameHandler) RenameDialogFixture(com.android.tools.idea.tests.gui.framework.fixture.RenameDialogFixture) PsiDirectory(com.intellij.psi.PsiDirectory) DirectoryAsPackageRenameHandler(com.intellij.refactoring.rename.DirectoryAsPackageRenameHandler) RenameHandler(com.intellij.refactoring.rename.RenameHandler) Module(com.intellij.openapi.module.Module) Test(org.junit.Test)

Example 4 with RenameHandler

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

the class RenameModuleTest method testRename.

public void testRename() throws Exception {
    String moduleName = "module";
    String newModuleName = "moduleA";
    Module module = createModule(moduleName);
    assertEquals(moduleName, module.getName());
    MapDataContext context = new MapDataContext();
    context.put(LangDataKeys.MODULE_CONTEXT, module);
    final RenameHandler renameHandler = RenameHandlerRegistry.getInstance().getRenameHandler(context);
    assertNotNull(renameHandler);
    Messages.setTestInputDialog(new TestInputDialog() {

        @Override
        public String show(String message) {
            return null;
        }

        @Override
        public String show(String message, @Nullable InputValidator validator) {
            assertNotNull(validator);
            boolean canClose = validator.canClose(newModuleName);
            assertTrue(canClose);
            return newModuleName;
        }
    });
    renameHandler.invoke(myProject, PsiElement.EMPTY_ARRAY, context);
    assertEquals(newModuleName, module.getName());
}
Also used : MapDataContext(com.intellij.testFramework.MapDataContext) InputValidator(com.intellij.openapi.ui.InputValidator) RenameHandler(com.intellij.refactoring.rename.RenameHandler) TestInputDialog(com.intellij.openapi.ui.TestInputDialog) Module(com.intellij.openapi.module.Module)

Example 5 with RenameHandler

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

the class JarRootsRefreshTest method rename.

private static void rename(PsiNamedElement file, String newName) {
    DataContext psiDataContext = SimpleDataContext.getSimpleContext(CommonDataKeys.PSI_ELEMENT.getName(), file);
    RenameHandler renameHandler = RenameHandlerRegistry.getInstance().getRenameHandler(psiDataContext);
    assertNotNull(renameHandler);
    PsiElementRenameHandler.rename(file, file.getProject(), file, null, newName);
}
Also used : DataContext(com.intellij.openapi.actionSystem.DataContext) SimpleDataContext(com.intellij.openapi.actionSystem.impl.SimpleDataContext) PsiElementRenameHandler(com.intellij.refactoring.rename.PsiElementRenameHandler) RenameHandler(com.intellij.refactoring.rename.RenameHandler)

Aggregations

RenameHandler (com.intellij.refactoring.rename.RenameHandler)8 PsiElementRenameHandler (com.intellij.refactoring.rename.PsiElementRenameHandler)5 MapDataContext (com.intellij.testFramework.MapDataContext)4 DataContext (com.intellij.openapi.actionSystem.DataContext)2 Module (com.intellij.openapi.module.Module)2 RenameDialogFixture (com.android.tools.idea.tests.gui.framework.fixture.RenameDialogFixture)1 SimpleDataContext (com.intellij.openapi.actionSystem.impl.SimpleDataContext)1 Project (com.intellij.openapi.project.Project)1 InputValidator (com.intellij.openapi.ui.InputValidator)1 TestInputDialog (com.intellij.openapi.ui.TestInputDialog)1 AsyncResult (com.intellij.openapi.util.AsyncResult)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 PsiDirectory (com.intellij.psi.PsiDirectory)1 RefactoringActionHandler (com.intellij.refactoring.RefactoringActionHandler)1 DirectoryAsPackageRenameHandler (com.intellij.refactoring.rename.DirectoryAsPackageRenameHandler)1 MemberInplaceRenameHandler (com.intellij.refactoring.rename.inplace.MemberInplaceRenameHandler)1 CommonRefactoringUtil (com.intellij.refactoring.util.CommonRefactoringUtil)1 Consumer (com.intellij.util.Consumer)1 JavaFxPropertyRenameHandler (org.jetbrains.plugins.javaFX.refactoring.JavaFxPropertyRenameHandler)1 Test (org.junit.Test)1