From 5912e046c7bb46b7a873ad84ae91de4ac5198bf1 Mon Sep 17 00:00:00 2001 From: Dmitry Jemerov Date: Fri, 25 Dec 2009 17:59:43 +0300 Subject: [PATCH] tests for forthcoming functionality, cleanup and refactoring --- .../testFramework/fixtures/CodeInsightTestFixture.java | 2 ++ .../fixtures/impl/CodeInsightTestFixtureImpl.java | 10 ++++++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/platform/testFramework/src/com/intellij/testFramework/fixtures/CodeInsightTestFixture.java b/platform/testFramework/src/com/intellij/testFramework/fixtures/CodeInsightTestFixture.java index 3e68bd591d..68aab06593 100644 --- a/platform/testFramework/src/com/intellij/testFramework/fixtures/CodeInsightTestFixture.java +++ b/platform/testFramework/src/com/intellij/testFramework/fixtures/CodeInsightTestFixture.java @@ -320,5 +320,7 @@ public interface CodeInsightTestFixture extends IdeaProjectTestFixture { void renameElementAtCaret(String newName) throws Exception; + void renameElement(PsiElement element, String newName) throws Exception; + void allowTreeAccessForFile(VirtualFile file); } diff --git a/platform/testFramework/src/com/intellij/testFramework/fixtures/impl/CodeInsightTestFixtureImpl.java b/platform/testFramework/src/com/intellij/testFramework/fixtures/impl/CodeInsightTestFixtureImpl.java index 3205bf938f..f427e38eff 100644 --- a/platform/testFramework/src/com/intellij/testFramework/fixtures/impl/CodeInsightTestFixtureImpl.java +++ b/platform/testFramework/src/com/intellij/testFramework/fixtures/impl/CodeInsightTestFixtureImpl.java @@ -501,10 +501,16 @@ public class CodeInsightTestFixtureImpl extends BaseFixture implements CodeInsig public void renameElementAtCaret(final String newName) throws Exception { assertInitialized(); + final PsiElement element = TargetElementUtilBase.findTargetElement(getCompletionEditor(), TargetElementUtilBase.REFERENCED_ELEMENT_ACCEPTED | + TargetElementUtilBase.ELEMENT_NAME_ACCEPTED); + assert element != null : "element not found in file " + myFile.getName() + " at caret position, offset " + + myEditor.getCaretModel().getOffset(); + renameElement(element, newName); + } + + public void renameElement(final PsiElement element, final String newName) throws Exception { new WriteCommandAction.Simple(myProjectFixture.getProject()) { protected void run() throws Exception { - PsiElement element = TargetElementUtilBase.findTargetElement(getCompletionEditor(), TargetElementUtilBase.REFERENCED_ELEMENT_ACCEPTED | TargetElementUtilBase.ELEMENT_NAME_ACCEPTED); - assert element != null: "element not found in file " + myFile.getName() + " at caret position, offset " + myEditor.getCaretModel().getOffset(); final PsiElement substitution = RenamePsiElementProcessor.forElement(element).substituteElementToRename(element, myEditor); new RenameProcessor(myProjectFixture.getProject(), substitution, newName, false, false).run(); } -- 2.11.4.GIT