2 * Copyright 2000-2016 JetBrains s.r.o.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package org.jetbrains.plugins.groovy.codeInsight.hint
18 import com.intellij.codeInsight.daemon.impl.ParameterHintsPresentationManager
19 import com.intellij.testFramework.LightProjectDescriptor
20 import groovy.transform.CompileStatic
21 import org.jetbrains.plugins.groovy.GroovyLightProjectDescriptor
22 import org.jetbrains.plugins.groovy.LightGroovyTestCase
25 class GroovyInlayParameterHintsProviderTest extends LightGroovyTestCase {
27 final LightProjectDescriptor projectDescriptor = GroovyLightProjectDescriptor.GROOVY_LATEST
33 fixture.addFileToProject 'Foo.groovy', '''\
38 void defaultArgs(a, b = 1,c) {}
39 void mapArgs(Map m, a) {}
40 void varArgs(a, def... b) {}
41 void combo(Map m, a, b = 1, def ... c) {}
47 private void testInlays(String text, Map<Integer, String> expectedParameterHints) {
48 fixture.configureByText '_.groovy', prefix ? prefix + text : text
49 fixture.doHighlighting()
50 def manager = ParameterHintsPresentationManager.instance
51 def inlays = editor.inlayModel.getInlineElementsInRange(0, editor.document.textLength)
52 def parameterHinInlays = inlays.findAll {
53 manager.isParameterHint(it)
55 int prefixLength = prefix?.length() ?: 0
56 def actualParameterHints = parameterHinInlays.collectEntries {
57 [(it.offset - prefixLength): manager.getHintText(it)]
59 assert actualParameterHints == expectedParameterHints
62 void 'test method call expressions'() {
66 testInlays 'simple(null)', [7: 'a']
67 testInlays 'defaultArgs(1, 2)', [12: 'a', 15: 'c']
68 testInlays 'defaultArgs(1, 2, 3)', [12: 'a', 15: 'b', 18: 'c']
69 testInlays 'mapArgs(foo: 1, null, bar: 2)', [16: 'a']
70 testInlays 'varArgs(1, 2, 3, 4)', [8: 'a', 11: '...b']
71 testInlays 'combo(1, foo: 10, 2, 3, 4, bar: 20, 5)', [6: 'a', 18: 'b', 21: '...c']
74 void 'test method call applications'() {
78 testInlays 'simple null', [7: 'a']
79 testInlays 'defaultArgs 1, 2', [12: 'a', 15: 'c']
80 testInlays 'defaultArgs 1, 2, 3', [12: 'a', 15: 'b', 18: 'c']
81 testInlays 'mapArgs foo: 1, null, bar: 2 ', [16: 'a']
82 testInlays 'varArgs 1, 2, 3, 4 ', [8: 'a', 11: '...b']
83 testInlays 'combo 1, foo: 10, 2, 3, 4, bar: 20, 5', [6: 'a', 18: 'b', 21: '...c']
86 void 'test index expression'() {
87 testInlays 'new Foo()[1]', [10: 'a']
90 void 'test new expression'() {
91 testInlays 'new Foo(1, 2, 4)', [8: 'a', 11: 'b', 14: 'c']
94 void 'test constructor invocation'() {
103 ''', [31: 'a', 34: 'b', 37: 'c']
106 void 'test enum constants'() {
113 ''', [17: 'a', 20: 'b', 30: 'a', 33: 'b']
116 void 'test no DGM inlays'() {
117 testInlays '[].each {}', [:]