package com.intellij.codeInsight.unwrap; import com.intellij.openapi.editor.markup.RangeHighlighter; public class UnwrapMethodParameterTest extends UnwrapTestCase { public void testBasic() throws Exception { assertOptions("foo(bar());", "Unwrap 'bar()'"); assertUnwrapped("foo(bar());", "bar();"); } public void testSeveralParameters() throws Exception { assertUnwrapped("foo(bar(), baz());", "baz();"); } public void testInnerCalls() throws Exception { assertOptions("foo(bar(baz()));", "Unwrap 'baz()'", "Unwrap 'bar(baz())'"); assertUnwrapped("foo(bar(baz()));", "foo(baz());", 0); assertUnwrapped("foo(bar(baz()));", "bar(baz());", 1); } public void testInstantiationParameter() throws Exception { assertOptions("foo(new String());", "Unwrap 'new String()'"); assertUnwrapped("foo(new String());", "new String();"); } public void testSimpleParameter() throws Exception { assertOptions("foo(bar);", "Unwrap 'bar'"); assertUnwrapped("foo(bar);", "bar;"); } public void testFromAssignment() throws Exception { assertOptions("int i = foo(bar());", "Unwrap 'bar()'"); assertUnwrapped("int i = foo(bar());", "int i = bar();"); } public void testFromTopLevelNew() throws Exception { assertOptions("Foo f = new Foo(bar());", "Unwrap 'Foo'"); assertUnwrapped("Foo f = new Foo(bar());", "Foo f = bar();"); } public void testFromTopLevel() throws Exception { assertOptions("int f = foo(bar());", "Unwrap 'foo'"); assertUnwrapped("int f = foo(bar());", "int f = bar();"); } public void testBeforeRightParenth() throws Exception { assertOptions("int f = foo(bar(\"path\"));", "Unwrap '\"path\"'", "Unwrap 'bar(\"path\")'"); assertUnwrapped("int f = foo(bar(\"path\"));", "int f = foo(\"path\");"); } public void testHighlightingOfTheExtractedFragment() throws Exception { assertOptions("foo(bar.str);", "Unwrap 'bar.str'"); assertUnwrapped("foo(bar.str);", "bar.str;"); final RangeHighlighter[] highlighters = myEditor.getMarkupModel().getAllHighlighters(); assertSize(1, highlighters); assertEquals(42, highlighters[0].getStartOffset()); assertEquals(49, highlighters[0].getEndOffset()); } }