Search in sources :

Example 1 with MemberInplaceRenameHandler

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

the class RenameHandlerRegistry method getRenameHandler.

@Nullable
public RenameHandler getRenameHandler(DataContext dataContext) {
    final Map<String, RenameHandler> availableHandlers = new TreeMap<>();
    for (RenameHandler renameHandler : Extensions.getExtensions(RenameHandler.EP_NAME)) {
        if (renameHandler.isRenaming(dataContext)) {
            availableHandlers.put(getHandlerTitle(renameHandler), renameHandler);
        }
    }
    for (RenameHandler renameHandler : myHandlers) {
        if (renameHandler.isRenaming(dataContext)) {
            availableHandlers.put(getHandlerTitle(renameHandler), renameHandler);
        }
    }
    if (availableHandlers.size() == 1)
        return availableHandlers.values().iterator().next();
    for (Iterator<Map.Entry<String, RenameHandler>> iterator = availableHandlers.entrySet().iterator(); iterator.hasNext(); ) {
        Map.Entry<String, RenameHandler> entry = iterator.next();
        if (entry.getValue() instanceof MemberInplaceRenameHandler) {
            iterator.remove();
            break;
        }
    }
    if (availableHandlers.size() == 1)
        return availableHandlers.values().iterator().next();
    if (availableHandlers.size() > 1) {
        if (ApplicationManager.getApplication().isUnitTestMode())
            return availableHandlers.values().iterator().next();
        final String[] strings = ArrayUtil.toStringArray(availableHandlers.keySet());
        final HandlersChooser chooser = new HandlersChooser(CommonDataKeys.PROJECT.getData(dataContext), strings);
        if (chooser.showAndGet()) {
            return availableHandlers.get(chooser.getSelection());
        }
        throw new ProcessCanceledException();
    }
    return myDefaultElementRenameHandler.isRenaming(dataContext) ? myDefaultElementRenameHandler : null;
}
Also used : MemberInplaceRenameHandler(com.intellij.refactoring.rename.inplace.MemberInplaceRenameHandler) MemberInplaceRenameHandler(com.intellij.refactoring.rename.inplace.MemberInplaceRenameHandler) TreeMap(java.util.TreeMap) TreeMap(java.util.TreeMap) Map(java.util.Map) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException) Nullable(org.jetbrains.annotations.Nullable)

Example 2 with MemberInplaceRenameHandler

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

the class RenameMembersInplaceTest method testNameSuggestion.

public void testNameSuggestion() throws Exception {
    configureByFile(BASE_PATH + "/" + getTestName(false) + ".java");
    final PsiElement element = TargetElementUtil.findTargetElement(myEditor, TargetElementUtil.getInstance().getAllAccepted());
    assertNotNull(element);
    final Set<String> result = new LinkedHashSet<>();
    new JavaNameSuggestionProvider().getSuggestedNames(element, getFile(), result);
    CodeInsightTestUtil.doInlineRename(new MemberInplaceRenameHandler(), result.iterator().next(), getEditor(), element);
    checkResultByFile(BASE_PATH + getTestName(false) + "_after.java");
}
Also used : LinkedHashSet(java.util.LinkedHashSet) MemberInplaceRenameHandler(com.intellij.refactoring.rename.inplace.MemberInplaceRenameHandler) JavaNameSuggestionProvider(com.intellij.refactoring.rename.JavaNameSuggestionProvider) PsiElement(com.intellij.psi.PsiElement)

Example 3 with MemberInplaceRenameHandler

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

the class RenameMembersInplaceTest method testSameNamedMethodsInOneFile.

public void testSameNamedMethodsInOneFile() throws Exception {
    configureByFile(BASE_PATH + "/" + getTestName(false) + ".java");
    final PsiElement element = TargetElementUtil.findTargetElement(myEditor, TargetElementUtil.getInstance().getAllAccepted());
    assertNotNull(element);
    Editor editor = getEditor();
    Project project = editor.getProject();
    TemplateManagerImpl.setTemplateTesting(getProject(), getTestRootDisposable());
    new MemberInplaceRenameHandler().doRename(element, editor, DataManager.getInstance().getDataContext(editor.getComponent()));
    TemplateState state = TemplateManagerImpl.getTemplateState(editor);
    assert state != null;
    assertEquals(2, state.getSegmentsCount());
    final TextRange range = state.getCurrentVariableRange();
    assert range != null;
    final Editor finalEditor = editor;
    new WriteCommandAction.Simple(project) {

        @Override
        protected void run() throws Throwable {
            finalEditor.getDocument().replaceString(range.getStartOffset(), range.getEndOffset(), "newDoSomething");
        }
    }.execute().throwException();
    state = TemplateManagerImpl.getTemplateState(editor);
    assert state != null;
    state.gotoEnd(false);
    checkResultByFile(BASE_PATH + getTestName(false) + "_after.java");
}
Also used : Project(com.intellij.openapi.project.Project) MemberInplaceRenameHandler(com.intellij.refactoring.rename.inplace.MemberInplaceRenameHandler) TextRange(com.intellij.openapi.util.TextRange) Editor(com.intellij.openapi.editor.Editor) TemplateState(com.intellij.codeInsight.template.impl.TemplateState) PsiElement(com.intellij.psi.PsiElement)

Example 4 with MemberInplaceRenameHandler

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

the class RenameMembersInplaceTest method doTestInplaceRename.

private void doTestInplaceRename(final String newName) throws Exception {
    configureByFile(BASE_PATH + "/" + getTestName(false) + ".java");
    final PsiElement element = TargetElementUtil.findTargetElement(myEditor, TargetElementUtil.getInstance().getAllAccepted());
    assertNotNull(element);
    CodeInsightTestUtil.doInlineRename(new MemberInplaceRenameHandler(), newName, getEditor(), element);
    checkResultByFile(BASE_PATH + getTestName(false) + "_after.java");
}
Also used : MemberInplaceRenameHandler(com.intellij.refactoring.rename.inplace.MemberInplaceRenameHandler) PsiElement(com.intellij.psi.PsiElement)

Example 5 with MemberInplaceRenameHandler

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

the class JavaFXRenameTest method doTest.

private void doTest(final String newName, boolean inline) throws Exception {
    myFixture.configureByFiles(getTestName(true) + ".fxml", getTestName(false) + ".java");
    PsiElement element = TargetElementUtil.findTargetElement(getEditor(), TargetElementUtil.ELEMENT_NAME_ACCEPTED | TargetElementUtil.REFERENCED_ELEMENT_ACCEPTED);
    assertNotNull(element);
    if (inline) {
        CodeInsightTestUtil.doInlineRename(new MemberInplaceRenameHandler(), newName, getEditor(), element);
    } else {
        new RenameProcessor(getProject(), element, newName, true, true).run();
    }
    myFixture.checkResultByFile(getTestName(true) + "_after.fxml");
}
Also used : MemberInplaceRenameHandler(com.intellij.refactoring.rename.inplace.MemberInplaceRenameHandler) RenameProcessor(com.intellij.refactoring.rename.RenameProcessor) PsiElement(com.intellij.psi.PsiElement)

Aggregations

MemberInplaceRenameHandler (com.intellij.refactoring.rename.inplace.MemberInplaceRenameHandler)5 PsiElement (com.intellij.psi.PsiElement)4 TemplateState (com.intellij.codeInsight.template.impl.TemplateState)1 Editor (com.intellij.openapi.editor.Editor)1 ProcessCanceledException (com.intellij.openapi.progress.ProcessCanceledException)1 Project (com.intellij.openapi.project.Project)1 TextRange (com.intellij.openapi.util.TextRange)1 JavaNameSuggestionProvider (com.intellij.refactoring.rename.JavaNameSuggestionProvider)1 RenameProcessor (com.intellij.refactoring.rename.RenameProcessor)1 LinkedHashSet (java.util.LinkedHashSet)1 Map (java.util.Map)1 TreeMap (java.util.TreeMap)1 Nullable (org.jetbrains.annotations.Nullable)1