diff --git a/platform/lang-impl/src/com/intellij/codeInsight/unwrap/UnwrapAction.java b/platform/lang-impl/src/com/intellij/codeInsight/unwrap/UnwrapAction.java index f06e46664384..0ca3ec755404 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/unwrap/UnwrapAction.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/unwrap/UnwrapAction.java @@ -24,6 +24,7 @@ import com.intellij.psi.*; public class UnwrapAction extends BaseCodeInsightAction{ public UnwrapAction() { + super(true); setEnabledInModalContext(true); } diff --git a/platform/testFramework/testSrc/com/intellij/codeInsight/unwrap/UnwrapTestCase.java b/platform/testFramework/testSrc/com/intellij/codeInsight/unwrap/UnwrapTestCase.java new file mode 100644 index 000000000000..554506348a56 --- /dev/null +++ b/platform/testFramework/testSrc/com/intellij/codeInsight/unwrap/UnwrapTestCase.java @@ -0,0 +1,77 @@ +package com.intellij.codeInsight.unwrap; + +import com.intellij.openapi.actionSystem.AnAction; +import com.intellij.openapi.editor.Editor; +import com.intellij.openapi.util.text.StringUtil; +import com.intellij.psi.PsiFile; +import com.intellij.testFramework.LightPlatformCodeInsightTestCase; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +public abstract class UnwrapTestCase extends LightPlatformCodeInsightTestCase { + protected void assertUnwrapped(String codeBefore, String expectedCodeAfter) throws Exception { + assertUnwrapped(codeBefore, expectedCodeAfter, 0); + } + + protected void assertUnwrapped(String codeBefore, String expectedCodeAfter, final int option) throws Exception { + configureCode(codeBefore); + + UnwrapHandler h = new UnwrapHandler() { + @Override + protected void selectOption(List options, Editor editor, PsiFile file) { + if (options.isEmpty()) return; + options.get(option).actionPerformed(null); + } + }; + + h.invoke(getProject(), getEditor(), getFile()); + + checkResultByText(createCode(expectedCodeAfter)); + } + + protected void assertOptions(String code, String... expectedOptions) throws IOException { + configureCode(code); + + final List actualOptions = new ArrayList(); + + UnwrapHandler h = new UnwrapHandler() { + @Override + protected void selectOption(List options, Editor editor, PsiFile file) { + for (AnAction each : options) { + actualOptions.add(each.getTemplatePresentation().getText()); + } + } + }; + + h.invoke(getProject(), getEditor(), getFile()); + + assertEquals(Arrays.asList(expectedOptions), actualOptions); + } + + protected void configureCode(final String codeBefore) throws IOException { + configureFromFileText(getFileNameToCreate(), createCode(codeBefore)); + } + + protected String getFileNameToCreate() { + return "A.java"; + } + + protected String createCode(String codeBefore) { + return "public class A {\n" + + " void foo() {\n" + + indentTwice(codeBefore) + + " }\n" + + "}"; + } + + protected String indentTwice(String code) { + String result = ""; + for (String line : StringUtil.tokenize(code, "\n")) { + result += " " + line + "\n"; + } + return result; + } +} \ No newline at end of file