diff --git a/java/java-tests/testData/codeInsight/parameterInfo/HighlightCurrentParameterAfterTypingFirstArgumentOfThree.java b/java/java-tests/testData/codeInsight/parameterInfo/HighlightCurrentParameterAfterTypingFirstArgumentOfThree.java deleted file mode 100644 index c2f155128807..000000000000 --- a/java/java-tests/testData/codeInsight/parameterInfo/HighlightCurrentParameterAfterTypingFirstArgumentOfThree.java +++ /dev/null @@ -1,7 +0,0 @@ -class A { - void foo() {} - void foo(int a, int b, int c) {} - { - foo() - } -} \ No newline at end of file diff --git a/java/java-tests/testSrc/com/intellij/java/codeInsight/AbstractParameterInfoTestCase.java b/java/java-tests/testSrc/com/intellij/java/codeInsight/AbstractParameterInfoTestCase.java new file mode 100644 index 000000000000..258335fc5f62 --- /dev/null +++ b/java/java-tests/testSrc/com/intellij/java/codeInsight/AbstractParameterInfoTestCase.java @@ -0,0 +1,81 @@ +// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +package com.intellij.java.codeInsight; + +import com.intellij.codeInsight.AutoPopupController; +import com.intellij.codeInsight.CodeInsightSettings; +import com.intellij.codeInsight.completion.LightFixtureCompletionTestCase; +import com.intellij.codeInsight.daemon.impl.ParameterHintsPresentationManager; +import com.intellij.codeInsight.hint.ParameterInfoController; +import com.intellij.ide.highlighter.JavaFileType; +import com.intellij.openapi.actionSystem.IdeActions; +import com.intellij.openapi.editor.Editor; +import com.intellij.testFramework.fixtures.EditorHintFixture; +import com.intellij.util.ui.UIUtil; + +import java.util.concurrent.TimeUnit; +import java.util.concurrent.TimeoutException; +import java.util.concurrent.locks.LockSupport; + +public abstract class AbstractParameterInfoTestCase extends LightFixtureCompletionTestCase { + private EditorHintFixture myHintFixture; + private int myStoredAutoPopupDelay; + + @Override + protected void setUp() throws Exception { + super.setUp(); + myHintFixture = new EditorHintFixture(getTestRootDisposable()); + myStoredAutoPopupDelay = CodeInsightSettings.getInstance().PARAMETER_INFO_DELAY; + CodeInsightSettings.getInstance().PARAMETER_INFO_DELAY = 100; // speed up tests + } + + @Override + protected void tearDown() throws Exception { + try { + CodeInsightSettings.getInstance().PARAMETER_INFO_DELAY = myStoredAutoPopupDelay; + } + finally { + super.tearDown(); + } + } + + public void configureJava(String text) { + myFixture.configureByText(JavaFileType.INSTANCE, text); + } + + public void showParameterInfo() { + myFixture.performEditorAction(IdeActions.ACTION_EDITOR_SHOW_PARAMETER_INFO); + UIUtil.dispatchAllInvocationEvents(); + } + + public void checkHintContents(String hintText) { + assertEquals(hintText, myHintFixture.getCurrentHintText()); + } + + public void type(String text) { + myFixture.type(text); + } + + private void waitForParameterInfoUpdate() throws TimeoutException { + ParameterInfoController.waitForDelayedActions(getEditor(), 1, TimeUnit.MINUTES); + } + + public static void waitTillAnimationCompletes(Editor editor) { + long deadline = System.currentTimeMillis() + 60_000; + while (ParameterHintsPresentationManager.getInstance().isAnimationInProgress(editor)) { + if (System.currentTimeMillis() > deadline) fail("Too long waiting for animation to finish"); + LockSupport.parkNanos(10_000_000); + UIUtil.dispatchAllInvocationEvents(); + } + } + + private void waitForAutoPopup() throws TimeoutException { + AutoPopupController.getInstance(getProject()).waitForDelayedActions(1, TimeUnit.MINUTES); + } + + public void waitForAllAsyncStuff() throws TimeoutException { + waitForParameterInfoUpdate(); + myFixture.doHighlighting(); + waitTillAnimationCompletes(getEditor()); + waitForAutoPopup(); + } +} diff --git a/java/java-tests/testSrc/com/intellij/java/codeInsight/ParameterInfoTest.java b/java/java-tests/testSrc/com/intellij/java/codeInsight/ParameterInfoTest.java index 73e6a1264f4d..110227039014 100644 --- a/java/java-tests/testSrc/com/intellij/java/codeInsight/ParameterInfoTest.java +++ b/java/java-tests/testSrc/com/intellij/java/codeInsight/ParameterInfoTest.java @@ -1,4 +1,4 @@ -// Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.java.codeInsight; import com.intellij.JavaTestUtil; @@ -19,14 +19,13 @@ import com.intellij.psi.infos.MethodCandidateInfo; import com.intellij.psi.util.PsiTreeUtil; import com.intellij.testFramework.LightProjectDescriptor; import com.intellij.testFramework.fixtures.EditorHintFixture; -import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase; import com.intellij.testFramework.utils.parameterInfo.MockCreateParameterInfoContext; import com.intellij.testFramework.utils.parameterInfo.MockParameterInfoUIContext; import com.intellij.testFramework.utils.parameterInfo.MockUpdateParameterInfoContext; import com.intellij.util.ui.UIUtil; import org.jetbrains.annotations.NotNull; -public class ParameterInfoTest extends LightCodeInsightFixtureTestCase { +public class ParameterInfoTest extends AbstractParameterInfoTestCase { @Override protected String getBasePath() { return JavaTestUtil.getRelativeJavaTestDataPath() + "/codeInsight/parameterInfo/"; @@ -361,27 +360,22 @@ public class ParameterInfoTest extends LightCodeInsightFixtureTestCase { myFixture.checkResultByFile(getTestName(false) + "_after.java"); } - public void _testHighlightCurrentParameterAfterTypingFirstArgumentOfThree() { - myFixture.configureByFile(getTestName(false) + ".java"); - - MethodParameterInfoHandler handler = new MethodParameterInfoHandler(); - CreateParameterInfoContext context = new MockCreateParameterInfoContext(getEditor(), getFile()); - PsiExpressionList argList = handler.findElementForParameterInfo(context); - assertNotNull(argList); - Object[] items = context.getItemsToShow(); - assertSize(2, items); - - MockUpdateParameterInfoContext updateContext = updateParameterInfo(handler, argList, items); - assertTrue(updateContext.isUIComponentEnabled(0)); - assertTrue(updateContext.isUIComponentEnabled(1)); - assertEquals(0, updateContext.getCurrentParameter()); - - myFixture.type("1, "); - PsiDocumentManager.getInstance(getProject()).commitAllDocuments(); - handler.updateParameterInfo(argList, updateContext); - assertFalse(updateContext.isUIComponentEnabled(0)); - assertTrue(updateContext.isUIComponentEnabled(1)); - assertEquals(1, updateContext.getCurrentParameter()); + public void testHighlightCurrentParameterAfterTypingFirstArgumentOfThree() throws Exception { + configureJava("class A {\n" + + " void foo() {}\n" + + " void foo(int a, int b, int c) {}\n" + + " {\n" + + " foo()\n" + + " }\n" + + "}"); + showParameterInfo(); + checkHintContents("[<no parameters>]\n" + + "-\n" + + "int a, int b, int c"); + type("1, "); + waitForAllAsyncStuff(); + checkHintContents("[<no parameters>]\n" + + "-\n" + + "int a, int b, int c"); } - } \ No newline at end of file diff --git a/java/java-tests/testSrc/com/intellij/java/codeInsight/completion/CompletionHintsTest.java b/java/java-tests/testSrc/com/intellij/java/codeInsight/completion/CompletionHintsTest.java index f0486c579ca5..3c8b0a2c0e77 100644 --- a/java/java-tests/testSrc/com/intellij/java/codeInsight/completion/CompletionHintsTest.java +++ b/java/java-tests/testSrc/com/intellij/java/codeInsight/completion/CompletionHintsTest.java @@ -1,22 +1,15 @@ -/* - * Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. - */ +// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.java.codeInsight.completion; -import com.intellij.codeInsight.AutoPopupController; import com.intellij.codeInsight.CodeInsightSettings; import com.intellij.codeInsight.completion.CompletionType; -import com.intellij.codeInsight.completion.LightFixtureCompletionTestCase; -import com.intellij.codeInsight.daemon.impl.ParameterHintsPresentationManager; -import com.intellij.codeInsight.hint.ParameterInfoController; import com.intellij.codeInsight.hints.JavaInlayParameterHintsProvider; import com.intellij.codeInsight.hints.Option; import com.intellij.codeInsight.intention.IntentionAction; import com.intellij.codeInsight.lookup.LookupElement; import com.intellij.codeInsight.lookup.LookupElementPresentation; -import com.intellij.ide.highlighter.JavaFileType; +import com.intellij.java.codeInsight.AbstractParameterInfoTestCase; import com.intellij.openapi.actionSystem.IdeActions; -import com.intellij.openapi.editor.Editor; import com.intellij.openapi.editor.ex.EditorSettingsExternalizable; import com.intellij.openapi.util.Disposer; import com.intellij.openapi.util.registry.Registry; @@ -24,33 +17,22 @@ import com.intellij.openapi.util.registry.RegistryValue; import com.intellij.psi.JavaCodeFragmentFactory; import com.intellij.psi.PsiExpressionCodeFragment; import com.intellij.testFramework.EditorTestUtil; -import com.intellij.testFramework.fixtures.EditorHintFixture; -import com.intellij.util.ui.UIUtil; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.TimeoutException; -import java.util.concurrent.locks.LockSupport; import java.util.stream.Stream; -public class CompletionHintsTest extends LightFixtureCompletionTestCase { +public class CompletionHintsTest extends AbstractParameterInfoTestCase { private boolean myStoredSettingValue; - private EditorHintFixture myHintFixture; - private int myStoredAutoPopupDelay; @Override protected void setUp() throws Exception { super.setUp(); myStoredSettingValue = CodeInsightSettings.getInstance().SHOW_PARAMETER_NAME_HINTS_ON_COMPLETION; CodeInsightSettings.getInstance().SHOW_PARAMETER_NAME_HINTS_ON_COMPLETION = true; - myHintFixture = new EditorHintFixture(getTestRootDisposable()); - myStoredAutoPopupDelay = CodeInsightSettings.getInstance().PARAMETER_INFO_DELAY; - CodeInsightSettings.getInstance().PARAMETER_INFO_DELAY = 100; // speed up tests } @Override protected void tearDown() throws Exception { try { - CodeInsightSettings.getInstance().PARAMETER_INFO_DELAY = myStoredAutoPopupDelay; CodeInsightSettings.getInstance().SHOW_PARAMETER_NAME_HINTS_ON_COMPLETION = myStoredSettingValue; } finally { @@ -77,9 +59,9 @@ public class CompletionHintsTest extends LightFixtureCompletionTestCase { checkResultWithInlays("class C { void m() { System.setProperty(, ) } }"); // test hints remain shown while entering parameter values - myFixture.type("\"a"); + type("\"a"); next(); - myFixture.type("\"b"); + type("\"b"); waitForAllAsyncStuff(); checkResultWithInlays("class C { void m() { System.setProperty(\"a\", \"b\") } }"); @@ -112,9 +94,9 @@ public class CompletionHintsTest extends LightFixtureCompletionTestCase { checkResultWithInlays("class C { void m() { Character.forDigit(, ) } }"); // test hints remain shown while entering parameter values - myFixture.type("1"); + type("1"); next(); - myFixture.type("2"); + type("2"); waitForAllAsyncStuff(); checkResultWithInlays("class C { void m() { Character.forDigit(1, 2) } }"); @@ -214,7 +196,7 @@ public class CompletionHintsTest extends LightFixtureCompletionTestCase { complete("setProperty"); waitForAllAsyncStuff(); checkResultWithInlays("class C { void m() { System.setProperty(, ) } }"); - myFixture.type("System.getPro"); + type("System.getPro"); complete("getProperty(String key, String def)"); waitForAllAsyncStuff(); checkResultWithInlays("class C { void m() { System.setProperty(System.getProperty(, ), ) } }"); @@ -224,7 +206,7 @@ public class CompletionHintsTest extends LightFixtureCompletionTestCase { configureJava("class C { void m() { System.setPro } }"); complete("setProperty"); waitForAllAsyncStuff(); - myFixture.type("System.getPro"); + type("System.getPro"); complete("getProperty(String key, String def)"); waitForAllAsyncStuff(); checkResultWithInlays("class C { void m() { System.setProperty(System.getProperty(, ), ) } }"); @@ -506,9 +488,9 @@ public class CompletionHintsTest extends LightFixtureCompletionTestCase { checkResultWithInlays("class C { void m() { Character.forDigit(, ) } }"); // test hints remain shown while entering parameter values - myFixture.type("1"); + type("1"); next(); - myFixture.type("2"); + type("2"); waitForAllAsyncStuff(); checkResultWithInlays("class C { void m() { Character.forDigit(1, 2) } }"); @@ -541,7 +523,7 @@ public class CompletionHintsTest extends LightFixtureCompletionTestCase { configureJava("class C { void m() { System.setPro } }"); complete("setProperty"); waitForAllAsyncStuff(); - myFixture.type("System.getPro"); + type("System.getPro"); complete("getProperty(String key, String def)"); waitForAllAsyncStuff(); checkResultWithInlays("class C { void m() { System.setProperty(System.getProperty(, ), ) } }"); @@ -815,9 +797,9 @@ public class CompletionHintsTest extends LightFixtureCompletionTestCase { checkResultWithInlays("class C { C(int a, int b) {} void m() { new C(, ) } }"); // test hints remain shown while entering parameter values - myFixture.type("1"); + type("1"); next(); - myFixture.type("2"); + type("2"); waitForAllAsyncStuff(); checkResultWithInlays("class C { C(int a, int b) {} void m() { new C(1, 2) } }"); @@ -932,10 +914,6 @@ public class CompletionHintsTest extends LightFixtureCompletionTestCase { myFixture.checkResultWithInlays(text); } - private void checkHintContents(String hintText) { - assertEquals(hintText, myHintFixture.getCurrentHintText()); - } - private void prev() { myFixture.performEditorAction(IdeActions.ACTION_EDITOR_PREV_PARAMETER); } @@ -980,19 +958,6 @@ public class CompletionHintsTest extends LightFixtureCompletionTestCase { myFixture.performEditorAction(IdeActions.ACTION_EDITOR_ESCAPE); } - private void configureJava(String text) { - myFixture.configureByText(JavaFileType.INSTANCE, text); - } - - private void waitForParameterInfoUpdate() throws TimeoutException { - ParameterInfoController.waitForDelayedActions(getEditor(), 1, TimeUnit.MINUTES); - } - - private void showParameterInfo() { - myFixture.performEditorAction(IdeActions.ACTION_EDITOR_SHOW_PARAMETER_INFO); - UIUtil.dispatchAllInvocationEvents(); - } - private void complete(String partOfItemText) { LookupElement[] elements = myFixture.completeBasic(); LookupElement element = Stream.of(elements).filter(e -> { @@ -1002,24 +967,4 @@ public class CompletionHintsTest extends LightFixtureCompletionTestCase { }).findAny().get(); selectItem(element); } - - public static void waitTillAnimationCompletes(Editor editor) { - long deadline = System.currentTimeMillis() + 60_000; - while (ParameterHintsPresentationManager.getInstance().isAnimationInProgress(editor)) { - if (System.currentTimeMillis() > deadline) fail("Too long waiting for animation to finish"); - LockSupport.parkNanos(10_000_000); - UIUtil.dispatchAllInvocationEvents(); - } - } - - private void waitForAutoPopup() throws TimeoutException { - AutoPopupController.getInstance(getProject()).waitForDelayedActions(1, TimeUnit.MINUTES); - } - - private void waitForAllAsyncStuff() throws TimeoutException { - waitForParameterInfoUpdate(); - myFixture.doHighlighting(); - waitTillAnimationCompletes(getEditor()); - waitForAutoPopup(); - } } \ No newline at end of file