Implement kotlin.jvm.overloads annotation for generating all overloads of a method that has default parameter values.
#KT-2095 Fixed fix backend-side issues with kotlin.jvm.overloads: support the annotation on constructors, generate nullablity annotations on parameters, generate generic signatures, add various tests
This commit is contained in:
@@ -23,10 +23,14 @@ import com.intellij.psi.search.GlobalSearchScope;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.kotlin.checkers.KotlinMultiFileTestWithWithJava;
|
||||
import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment;
|
||||
import org.jetbrains.kotlin.config.CompilerConfiguration;
|
||||
import org.jetbrains.kotlin.test.ConfigurationKind;
|
||||
import org.jetbrains.kotlin.test.JetTestUtils;
|
||||
import org.jetbrains.kotlin.test.TestJdkKind;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.regex.Matcher;
|
||||
@@ -35,6 +39,17 @@ import java.util.regex.Pattern;
|
||||
public abstract class AbstractKotlinLightClassTest extends KotlinMultiFileTestWithWithJava<Void, Void> {
|
||||
private static final Pattern SUBJECT_FQ_NAME_PATTERN = Pattern.compile("^//\\s*(.*)$", Pattern.MULTILINE);
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
protected CompilerConfiguration createCompilerConfiguration(File javaFilesDir) {
|
||||
return JetTestUtils.compilerConfigurationForTests(
|
||||
ConfigurationKind.ALL,
|
||||
TestJdkKind.MOCK_JDK,
|
||||
Arrays.asList(JetTestUtils.getAnnotationsJar()),
|
||||
Arrays.asList(javaFilesDir)
|
||||
);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
protected File getKotlinSourceRoot() {
|
||||
|
||||
@@ -117,6 +117,12 @@ public class KotlinLightClassTestGenerated extends AbstractKotlinLightClassTest
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("JvmOverloads.kt")
|
||||
public void testJvmOverloads() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/asJava/lightClasses/nullabilityAnnotations/JvmOverloads.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("NullableUnitReturn.kt")
|
||||
public void testNullableUnitReturn() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/asJava/lightClasses/nullabilityAnnotations/NullableUnitReturn.kt");
|
||||
|
||||
+6
@@ -658,6 +658,12 @@ public class JetDiagnosticsTestWithStdLibGenerated extends AbstractJetDiagnostic
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("jvmOverloads.kt")
|
||||
public void testJvmOverloads() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/testsWithStdLib/duplicateJvmSignature/jvmOverloads.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("platformNames.kt")
|
||||
public void testPlatformNames() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/testsWithStdLib/duplicateJvmSignature/platformNames.kt");
|
||||
|
||||
@@ -66,12 +66,7 @@ public abstract class KotlinMultiFileTestWithWithJava<M, F> extends JetLiteFixtu
|
||||
@Override
|
||||
protected KotlinCoreEnvironment createEnvironment() {
|
||||
File javaFilesDir = createJavaFilesDir();
|
||||
CompilerConfiguration configuration = JetTestUtils.compilerConfigurationForTests(
|
||||
ConfigurationKind.JDK_AND_ANNOTATIONS,
|
||||
TestJdkKind.MOCK_JDK,
|
||||
Arrays.asList(JetTestUtils.getAnnotationsJar()),
|
||||
Arrays.asList(javaFilesDir)
|
||||
);
|
||||
CompilerConfiguration configuration = createCompilerConfiguration(javaFilesDir);
|
||||
File kotlinSourceRoot = getKotlinSourceRoot();
|
||||
if (kotlinSourceRoot != null) {
|
||||
addKotlinSourceRoot(configuration, kotlinSourceRoot.getPath());
|
||||
@@ -79,6 +74,16 @@ public abstract class KotlinMultiFileTestWithWithJava<M, F> extends JetLiteFixtu
|
||||
return createEnvironment(getTestRootDisposable(), configuration);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
protected CompilerConfiguration createCompilerConfiguration(File javaFilesDir) {
|
||||
return JetTestUtils.compilerConfigurationForTests(
|
||||
ConfigurationKind.JDK_AND_ANNOTATIONS,
|
||||
TestJdkKind.MOCK_JDK,
|
||||
Arrays.asList(JetTestUtils.getAnnotationsJar()),
|
||||
Arrays.asList(javaFilesDir)
|
||||
);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
protected KotlinCoreEnvironment createEnvironment(@NotNull Disposable disposable, @NotNull CompilerConfiguration configuration) {
|
||||
return KotlinCoreEnvironment.createForTests(disposable, configuration, EnvironmentConfigFiles.JVM_CONFIG_FILES);
|
||||
|
||||
+25
@@ -32,6 +32,7 @@ import java.util.regex.Pattern;
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@InnerTestClasses({
|
||||
BlackBoxWithJavaCodegenTestGenerated.BuiltinStubMethods.class,
|
||||
BlackBoxWithJavaCodegenTestGenerated.JvmOverloads.class,
|
||||
BlackBoxWithJavaCodegenTestGenerated.NotNullAssertions.class,
|
||||
BlackBoxWithJavaCodegenTestGenerated.PlatformStatic.class,
|
||||
BlackBoxWithJavaCodegenTestGenerated.Properties.class,
|
||||
@@ -98,6 +99,30 @@ public class BlackBoxWithJavaCodegenTestGenerated extends AbstractBlackBoxCodege
|
||||
|
||||
}
|
||||
|
||||
@TestMetadata("compiler/testData/codegen/boxWithJava/jvmOverloads")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@InnerTestClasses({
|
||||
})
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
public static class JvmOverloads extends AbstractBlackBoxCodegenTest {
|
||||
public void testAllFilesPresentInJvmOverloads() throws Exception {
|
||||
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/boxWithJava/jvmOverloads"), Pattern.compile("^([^\\.]+)$"), true);
|
||||
}
|
||||
|
||||
@TestMetadata("generics")
|
||||
public void testGenerics() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/boxWithJava/jvmOverloads/generics/");
|
||||
doTestWithJava(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("simple")
|
||||
public void testSimple() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/boxWithJava/jvmOverloads/simple/");
|
||||
doTestWithJava(fileName);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@TestMetadata("compiler/testData/codegen/boxWithJava/notNullAssertions")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@InnerTestClasses({
|
||||
|
||||
+18
@@ -1655,6 +1655,12 @@ public class BlackBoxWithStdlibCodegenTestGenerated extends AbstractBlackBoxCode
|
||||
doTestWithStdlib(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("defaultsNotAtEnd.kt")
|
||||
public void testDefaultsNotAtEnd() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/boxWithStdlib/jvmOverloads/defaultsNotAtEnd.kt");
|
||||
doTestWithStdlib(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("doubleParameters.kt")
|
||||
public void testDoubleParameters() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/boxWithStdlib/jvmOverloads/doubleParameters.kt");
|
||||
@@ -1679,6 +1685,18 @@ public class BlackBoxWithStdlibCodegenTestGenerated extends AbstractBlackBoxCode
|
||||
doTestWithStdlib(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("primaryConstructor.kt")
|
||||
public void testPrimaryConstructor() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/boxWithStdlib/jvmOverloads/primaryConstructor.kt");
|
||||
doTestWithStdlib(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("secondaryConstructor.kt")
|
||||
public void testSecondaryConstructor() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/boxWithStdlib/jvmOverloads/secondaryConstructor.kt");
|
||||
doTestWithStdlib(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("simple.kt")
|
||||
public void testSimple() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/boxWithStdlib/jvmOverloads/simple.kt");
|
||||
|
||||
Reference in New Issue
Block a user