[param hints] refactored + preserve existing hints in some cases [IDEA-169381]

This commit is contained in:
Yaroslav Lepenkin
2017-03-28 10:57:00 +03:00
parent 1c8ee7eb03
commit 90407ca29f
2 changed files with 152 additions and 69 deletions
@@ -15,10 +15,14 @@
*/
package com.intellij.codeInsight.daemon.inlays
import com.intellij.codeInsight.daemon.impl.ParameterHintsPresentationManager
import com.intellij.codeInsight.hints.JavaInlayParameterHintsProvider
import com.intellij.codeInsight.hints.settings.ParameterNameHintsSettings
import com.intellij.ide.highlighter.JavaFileType
import com.intellij.lang.java.JavaLanguage
import com.intellij.openapi.editor.Inlay
import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase
import org.assertj.core.api.Assertions.assertThat
class JavaInlayParameterHintsTest : LightCodeInsightFixtureTestCase() {
@@ -762,4 +766,51 @@ class X {
""")
}
fun `test preserved inlays`() {
myFixture.configureByText(JavaFileType.INSTANCE,
"""
class Test {
void main() {
test(<caret>);
}
void test(int fooo) {}
}
""")
myFixture.type("100")
myFixture.doHighlighting()
assertSingleInlayWithText("fooo:")
myFixture.type("\b\b\b")
myFixture.doHighlighting()
assertSingleInlayWithText("fooo:")
myFixture.type("yyy")
myFixture.doHighlighting()
assertSingleInlayWithText("fooo:")
myFixture.checkResult(
"""
class Test {
void main() {
test(yyy);
}
void test(int fooo) {}
}
""")
}
fun assertSingleInlayWithText(expectedText: String) {
val inlays = myFixture.editor.inlayModel.getInlineElementsInRange(0, editor.document.textLength)
assertThat(inlays).hasSize(1)
val realText = getHintText(inlays[0])
assertThat(realText).isEqualTo(expectedText)
}
fun getHintText(inlay: Inlay): String {
return ParameterHintsPresentationManager.getInstance().getHintText(inlay)
}
}