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;
}
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");
}
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");
}
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");
}
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");
}
Aggregations