[groovy] 2.5 support tap method (IDEA-200196)

This commit is contained in:
Daniil Ovchinnikov
2018-10-11 21:08:52 +03:00
parent e5b54eb524
commit d529d38f32
4 changed files with 61 additions and 1 deletions
@@ -117,7 +117,7 @@ public class GdkMethodUtil {
}
public static boolean isWithName(String name) {
return WITH.equals(name) || IDENTITY.equals(name);
return WITH.equals(name) || IDENTITY.equals(name) || "tap".equals(name);
}
@Nullable
@@ -0,0 +1,25 @@
// 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 org.jetbrains.plugins.groovy.lang.resolve
import groovy.transform.CompileStatic
import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrReferenceExpression
import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrAccessorMethod
import org.jetbrains.plugins.groovy.util.Groovy25Test
import org.jetbrains.plugins.groovy.util.ResolveTest
import org.junit.Test
@CompileStatic
class Groovy25ResolveTest extends Groovy25Test implements ResolveTest {
@Test
void 'tap'() {
def expression = elementUnderCaret '''\
class A { def prop }
new A().tap { <caret>prop = 1 }
''', GrReferenceExpression
def reference = expression.LValueReference
assert reference != null
def resolved = reference.resolve()
assert resolved instanceof GrAccessorMethod
}
}
@@ -1,11 +1,17 @@
// 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 org.jetbrains.plugins.groovy.util;
import com.intellij.psi.PsiElement;
import com.intellij.testFramework.fixtures.CodeInsightTestFixture;
import com.intellij.util.ArrayUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.plugins.groovy.lang.psi.GroovyFile;
import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression;
import java.util.Objects;
import static com.intellij.psi.util.PsiTreeUtil.getParentOfType;
public interface BaseTest {
@NotNull
@@ -18,4 +24,11 @@ public interface BaseTest {
default GrExpression configureByExpression(@NotNull String text) {
return (GrExpression)ArrayUtil.getLastElement(configureByText(text).getStatements());
}
@NotNull
default <T extends PsiElement> T elementUnderCaret(@NotNull String text, @NotNull Class<T> clazz) {
GroovyFile file = configureByText(text);
T element = getParentOfType(file.findElementAt(getFixture().getCaretOffset()), clazz);
return Objects.requireNonNull(element);
}
}
@@ -0,0 +1,22 @@
// 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 org.jetbrains.plugins.groovy.util
import com.intellij.testFramework.fixtures.CodeInsightTestFixture
import groovy.transform.CompileStatic
import org.jetbrains.annotations.NotNull
import org.jetbrains.plugins.groovy.GroovyProjectDescriptors
import org.junit.Rule
import org.junit.rules.RuleChain
import org.junit.rules.TestRule
@CompileStatic
abstract class Groovy25Test {
private final FixtureRule myFixtureRule = new FixtureRule(GroovyProjectDescriptors.GROOVY_2_5, '')
public final @Rule TestRule myRules = RuleChain.outerRule(myFixtureRule).around(new EdtRule())
@NotNull
CodeInsightTestFixture getFixture() {
myFixtureRule.fixture
}
}