diff --git a/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/highlighting/GrClosureParamsTest.java b/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/highlighting/GrClosureParamsTest.java index 2cb689148144..b55bb837ffab 100644 --- a/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/highlighting/GrClosureParamsTest.java +++ b/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/highlighting/GrClosureParamsTest.java @@ -1,148 +1,154 @@ -// Copyright 2000-2019 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.highlighting +// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. +package org.jetbrains.plugins.groovy.lang.highlighting; -import com.intellij.testFramework.LightProjectDescriptor -import groovy.transform.CompileStatic -import org.jetbrains.plugins.groovy.GroovyProjectDescriptors -import org.jetbrains.plugins.groovy.codeInspection.assignment.GroovyAssignabilityCheckInspection -import org.jetbrains.plugins.groovy.codeInspection.untypedUnresolvedAccess.GrUnresolvedAccessInspection +import com.intellij.openapi.vfs.VirtualFile; +import com.intellij.testFramework.LightProjectDescriptor; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.plugins.groovy.GroovyProjectDescriptors; +import org.jetbrains.plugins.groovy.codeInspection.assignment.GroovyAssignabilityCheckInspection; +import org.jetbrains.plugins.groovy.codeInspection.untypedUnresolvedAccess.GrUnresolvedAccessInspection; -@CompileStatic -class GrClosureParamsTest extends GrHighlightingTestBase { - final String basePath = super.basePath + 'closureParams/' - final LightProjectDescriptor projectDescriptor = GroovyProjectDescriptors.GROOVY_LATEST - - - void 'test from string with non-fqn options no error'() { - addBigInteger() - doTest('fromString/nonFqnOptions') +public class GrClosureParamsTest extends GrHighlightingTestBase { + public void testFromStringWithNonFqnOptionsNoError() { + addBigInteger(); + doTest("fromString/nonFqnOptions"); } - void 'test from string do not resolve usage context'() { - doTest('fromString/doNotResolveUsageContext', 'com/foo/bar/test.groovy') + public void testFromStringDoNotResolveUsageContext() { + doTest("fromString/doNotResolveUsageContext", "com/foo/bar/test.groovy"); } - void 'test from string do not resolve usage import context'() { - doTest('fromString/doNotResolveUsageImportContext', 'com/foo/bar/test.groovy') + public void testFromStringDoNotResolveUsageImportContext() { + doTest("fromString/doNotResolveUsageImportContext", "com/foo/bar/test.groovy"); } - void 'test from string do not resolve method context'() { - doTest('fromString/doNotResolveMethodContext') + public void testFromStringDoNotResolveMethodContext() { + doTest("fromString/doNotResolveMethodContext"); } - void 'test from string resolve default package' () { - doTest('fromString/resolveDefaultPackage') + public void testFromStringResolveDefaultPackage() { + doTest("fromString/resolveDefaultPackage"); } - void 'test from string resolve default package generic'() { - myFixture.addClass ''' -package com.foo.baz; + public void testFromStringResolveDefaultPackageGeneric() { + myFixture.addClass(""" + package com.foo.baz; -import groovy.lang.Closure; -import groovy.transform.stc.ClosureParams; -import groovy.transform.stc.FromString; + import groovy.lang.Closure; + import groovy.transform.stc.ClosureParams; + import groovy.transform.stc.FromString; -public class A { - public void bar(@ClosureParams(value = FromString.class, options = "MyClass") Closure c) {} -} -''' - myFixture.addClass ''' -public class MyClass {} -''' - myFixture.configureByText 'a.groovy', ''' -import com.foo.baz.A -import groovy.transform.CompileStatic + public class A { + public void bar(@ClosureParams(value = FromString.class, options = "MyClass") Closure c) {} + } + """); + myFixture.addClass("public class MyClass {}"); + myFixture.configureByText("a.groovy", """ + import com.foo.baz.A + import groovy.transform.CompileStatic -@CompileStatic -class Usage { - def foo() { new A().bar { MyClass a -> } } -} -''' - myFixture.checkHighlighting() + @CompileStatic + class Usage { + def foo() { new A().bar { MyClass a -> } } + } + """); + myFixture.checkHighlighting(); } + public void testCastArgument() { + myFixture.configureByText("a.groovy", """ + import groovy.transform.CompileStatic - void 'test cast argument'() { - myFixture.configureByText 'a.groovy', ''' -import groovy.transform.CompileStatic - -@CompileStatic -def m() { - List l = [] - l.findAll { - Object o -> false - } -} -''' - myFixture.checkHighlighting() + @CompileStatic + def m() { + List l = [] + l.findAll { + Object o -> false + } + } + """); + myFixture.checkHighlighting(); } + public void testCastArgumentError() { + myFixture.configureByText("a.groovy", """ + import groovy.transform.CompileStatic - void 'test cast argument error'() { - myFixture.configureByText 'a.groovy', ''' -import groovy.transform.CompileStatic - -@CompileStatic -def m() { - List l = [] - l.findAll { - Integer o -> false - } -} -''' - myFixture.checkHighlighting() + @CompileStatic + def m() { + List l = [] + l.findAll { + Integer o -> false + } + } + """); + myFixture.checkHighlighting(); } - void 'test several signatures'() { - myFixture.enableInspections(GroovyAssignabilityCheckInspection) - myFixture.configureByText 'a.groovy', ''' -import groovy.transform.CompileStatic -import groovy.transform.stc.ClosureParams -import groovy.transform.stc.SimpleType + public void testSeveralSignatures() { + myFixture.enableInspections(GroovyAssignabilityCheckInspection.class); + myFixture.configureByText("a.groovy", """ + import groovy.transform.CompileStatic + import groovy.transform.stc.ClosureParams + import groovy.transform.stc.SimpleType -def m1(String o, @ClosureParams(value=SimpleType.class, options="java.lang.String") Closure c) {} -def m1(Double o, @ClosureParams(value=SimpleType.class, options="java.lang.Double") Closure c) {} + def m1(String o, @ClosureParams(value=SimpleType.class, options="java.lang.String") Closure c) {} + def m1(Double o, @ClosureParams(value=SimpleType.class, options="java.lang.Double") Closure c) {} -@CompileStatic -def m() { - def a; - m1(a) { - long l -> println(l) - } -} -''' - myFixture.checkHighlighting() + @CompileStatic + def m() { + def a; + m1(a) { + long l -> println(l) + } + } + """); + myFixture.checkHighlighting(); } - void 'test cast several arguments'() { - myFixture.configureByText 'a.groovy', ''' -import groovy.transform.CompileStatic -import groovy.transform.stc.ClosureParams -import groovy.transform.stc.SimpleType + public void testCastSeveralArguments() { + myFixture.configureByText("a.groovy", """ + import groovy.transform.CompileStatic + import groovy.transform.stc.ClosureParams + import groovy.transform.stc.SimpleType -void forEachTyped(Map self, @ClosureParams(value=SimpleType.class, options=["java.lang.String", "java.lang.Integer"]) Closure closure) { - self.each { - k, v -> closure(k, v) - }; -} + void forEachTyped(Map self, @ClosureParams(value=SimpleType.class, options=["java.lang.String", "java.lang.Integer"]) Closure closure) { + self.each { + k, v -> closure(k, v) + }; + } -@CompileStatic -def m() { - Map m = [:] - forEachTyped(m) { - String key, String value -> println( key + ' ' + value) - } -} -''' - myFixture.checkHighlighting() + @CompileStatic + def m() { + Map m = [:] + forEachTyped(m) { + String key, String value -> println( key + ' ' + value) + } + } + """); + myFixture.checkHighlighting(); } - private void doTest(String dir = getTestName(true), String path = 'test.groovy') { - myFixture.enableInspections(new GroovyAssignabilityCheckInspection(), new GrUnresolvedAccessInspection()) - myFixture.copyDirectoryToProject(dir, '.') - def file = myFixture.findFileInTempDir(path) - myFixture.allowTreeAccessForAllFiles() - myFixture.configureFromExistingVirtualFile(file) - myFixture.checkHighlighting() + private void doTest(String dir, String path) { + myFixture.enableInspections(new GroovyAssignabilityCheckInspection(), new GrUnresolvedAccessInspection()); + myFixture.copyDirectoryToProject(dir, "."); + VirtualFile file = myFixture.findFileInTempDir(path); + myFixture.allowTreeAccessForAllFiles(); + myFixture.configureFromExistingVirtualFile(file); + myFixture.checkHighlighting(); + } + + private void doTest(String dir) { + doTest(dir, "test.groovy"); + } + + @Override + public final String getBasePath() { + return super.getBasePath() + "closureParams/"; + } + + @Override + public final @NotNull LightProjectDescriptor getProjectDescriptor() { + return GroovyProjectDescriptors.GROOVY_LATEST; } }