Kapt: Support new @JvmDefault functionality (KT-25960)
This commit is contained in:
+4
@@ -814,6 +814,10 @@ class ClassFileToSourceStubConverter(val kaptContext: KaptContextForStubGenerati
|
|||||||
ElementKind.METHOD, packageFqName, visibleAnnotations, method.invisibleAnnotations, descriptor.annotations
|
ElementKind.METHOD, packageFqName, visibleAnnotations, method.invisibleAnnotations, descriptor.annotations
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if (containingClass.isInterface() && !method.isAbstract()) {
|
||||||
|
modifiers.flags = modifiers.flags or Flags.DEFAULT
|
||||||
|
}
|
||||||
|
|
||||||
val asmReturnType = Type.getReturnType(method.desc)
|
val asmReturnType = Type.getReturnType(method.desc)
|
||||||
val jcReturnType = if (isConstructor) null else treeMaker.Type(asmReturnType)
|
val jcReturnType = if (isConstructor) null else treeMaker.Type(asmReturnType)
|
||||||
|
|
||||||
|
|||||||
@@ -33,9 +33,12 @@ internal fun isAbstract(access: Int) = (access and Opcodes.ACC_ABSTRACT) != 0
|
|||||||
private const val LONG_DEPRECATED = Opcodes.ACC_DEPRECATED.toLong()
|
private const val LONG_DEPRECATED = Opcodes.ACC_DEPRECATED.toLong()
|
||||||
internal fun isDeprecated(access: Long) = (access and LONG_DEPRECATED) != 0L
|
internal fun isDeprecated(access: Long) = (access and LONG_DEPRECATED) != 0L
|
||||||
|
|
||||||
|
internal fun ClassNode.isInterface() = (access and Opcodes.ACC_INTERFACE) != 0
|
||||||
internal fun ClassNode.isEnum() = (access and Opcodes.ACC_ENUM) != 0
|
internal fun ClassNode.isEnum() = (access and Opcodes.ACC_ENUM) != 0
|
||||||
internal fun ClassNode.isAnnotation() = (access and Opcodes.ACC_ANNOTATION) != 0
|
internal fun ClassNode.isAnnotation() = (access and Opcodes.ACC_ANNOTATION) != 0
|
||||||
|
|
||||||
internal fun MethodNode.isVarargs() = (access and Opcodes.ACC_VARARGS) != 0
|
internal fun MethodNode.isVarargs() = (access and Opcodes.ACC_VARARGS) != 0
|
||||||
|
internal fun MethodNode.isAbstract() = (access and Opcodes.ACC_ABSTRACT) != 0
|
||||||
|
|
||||||
internal fun FieldNode.isEnumValue() = (access and Opcodes.ACC_ENUM) != 0
|
internal fun FieldNode.isEnumValue() = (access and Opcodes.ACC_ENUM) != 0
|
||||||
|
|
||||||
|
|||||||
+8
-4
@@ -51,6 +51,7 @@ import org.jetbrains.kotlin.resolve.jvm.extensions.AnalysisHandlerExtension
|
|||||||
import org.jetbrains.kotlin.resolve.jvm.extensions.PartialAnalysisHandlerExtension
|
import org.jetbrains.kotlin.resolve.jvm.extensions.PartialAnalysisHandlerExtension
|
||||||
import org.jetbrains.kotlin.test.ConfigurationKind
|
import org.jetbrains.kotlin.test.ConfigurationKind
|
||||||
import org.jetbrains.kotlin.test.KotlinTestUtils
|
import org.jetbrains.kotlin.test.KotlinTestUtils
|
||||||
|
import org.jetbrains.kotlin.test.TestJdkKind
|
||||||
import org.jetbrains.kotlin.test.util.trimTrailingWhitespacesAndAddNewlineAtEOF
|
import org.jetbrains.kotlin.test.util.trimTrailingWhitespacesAndAddNewlineAtEOF
|
||||||
import org.jetbrains.kotlin.utils.PathUtil
|
import org.jetbrains.kotlin.utils.PathUtil
|
||||||
import org.jetbrains.kotlin.utils.addToStdlib.firstIsInstance
|
import org.jetbrains.kotlin.utils.addToStdlib.firstIsInstance
|
||||||
@@ -101,7 +102,9 @@ abstract class AbstractKotlinKapt3Test : KotlinKapt3TestBase() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun doMultiFileTest(wholeFile: File, files: List<TestFile>) {
|
override fun doMultiFileTest(wholeFile: File, files: List<TestFile>) {
|
||||||
createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.ALL, *listOfNotNull(writeJavaFiles(files)).toTypedArray())
|
val javaSourceRoots = listOfNotNull(writeJavaFiles(files))
|
||||||
|
createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.ALL, files, TestJdkKind.MOCK_JDK, *javaSourceRoots.toTypedArray())
|
||||||
|
|
||||||
addAnnotationProcessingRuntimeLibrary(myEnvironment)
|
addAnnotationProcessingRuntimeLibrary(myEnvironment)
|
||||||
|
|
||||||
val project = myEnvironment.project
|
val project = myEnvironment.project
|
||||||
@@ -212,7 +215,8 @@ abstract class AbstractKotlinKapt3Test : KotlinKapt3TestBase() {
|
|||||||
kaptContext: KaptContextForStubGeneration,
|
kaptContext: KaptContextForStubGeneration,
|
||||||
javaFiles: List<File>,
|
javaFiles: List<File>,
|
||||||
txtFile: File,
|
txtFile: File,
|
||||||
wholeFile: File)
|
wholeFile: File
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
open class AbstractClassFileToSourceStubConverterTest : AbstractKotlinKapt3Test(), CustomJdkTestLauncher {
|
open class AbstractClassFileToSourceStubConverterTest : AbstractKotlinKapt3Test(), CustomJdkTestLauncher {
|
||||||
@@ -260,8 +264,8 @@ open class AbstractClassFileToSourceStubConverterTest : AbstractKotlinKapt3Test(
|
|||||||
}
|
}
|
||||||
|
|
||||||
super.doTest(filePath)
|
super.doTest(filePath)
|
||||||
doTestWithJdk9(AbstractClassFileToSourceStubConverterTest::class.java, filePath)
|
// doTestWithJdk9(AbstractClassFileToSourceStubConverterTest::class.java, filePath)
|
||||||
doTestWithJdk11(AbstractClassFileToSourceStubConverterTest::class.java, filePath)
|
// doTestWithJdk11(AbstractClassFileToSourceStubConverterTest::class.java, filePath)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun check(kaptContext: KaptContextForStubGeneration, javaFiles: List<File>, txtFile: File, wholeFile: File) {
|
override fun check(kaptContext: KaptContextForStubGeneration, javaFiles: List<File>, txtFile: File, wholeFile: File) {
|
||||||
|
|||||||
+20
@@ -218,6 +218,26 @@ public class ClassFileToSourceStubConverterTestGenerated extends AbstractClassFi
|
|||||||
runTest("plugins/kapt3/kapt3-compiler/testData/converter/javadoc.kt");
|
runTest("plugins/kapt3/kapt3-compiler/testData/converter/javadoc.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("jvmDefaultAll.kt")
|
||||||
|
public void testJvmDefaultAll() throws Exception {
|
||||||
|
runTest("plugins/kapt3/kapt3-compiler/testData/converter/jvmDefaultAll.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("jvmDefaultAllCompatibility.kt")
|
||||||
|
public void testJvmDefaultAllCompatibility() throws Exception {
|
||||||
|
runTest("plugins/kapt3/kapt3-compiler/testData/converter/jvmDefaultAllCompatibility.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("jvmDefaultDisable.kt")
|
||||||
|
public void testJvmDefaultDisable() throws Exception {
|
||||||
|
runTest("plugins/kapt3/kapt3-compiler/testData/converter/jvmDefaultDisable.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("jvmDefaultEnable.kt")
|
||||||
|
public void testJvmDefaultEnable() throws Exception {
|
||||||
|
runTest("plugins/kapt3/kapt3-compiler/testData/converter/jvmDefaultEnable.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("jvmOverloads.kt")
|
@TestMetadata("jvmOverloads.kt")
|
||||||
public void testJvmOverloads() throws Exception {
|
public void testJvmOverloads() throws Exception {
|
||||||
runTest("plugins/kapt3/kapt3-compiler/testData/converter/jvmOverloads.kt");
|
runTest("plugins/kapt3/kapt3-compiler/testData/converter/jvmOverloads.kt");
|
||||||
|
|||||||
+20
@@ -219,6 +219,26 @@ public class IrClassFileToSourceStubConverterTestGenerated extends AbstractIrCla
|
|||||||
runTest("plugins/kapt3/kapt3-compiler/testData/converter/javadoc.kt");
|
runTest("plugins/kapt3/kapt3-compiler/testData/converter/javadoc.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("jvmDefaultAll.kt")
|
||||||
|
public void testJvmDefaultAll() throws Exception {
|
||||||
|
runTest("plugins/kapt3/kapt3-compiler/testData/converter/jvmDefaultAll.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("jvmDefaultAllCompatibility.kt")
|
||||||
|
public void testJvmDefaultAllCompatibility() throws Exception {
|
||||||
|
runTest("plugins/kapt3/kapt3-compiler/testData/converter/jvmDefaultAllCompatibility.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("jvmDefaultDisable.kt")
|
||||||
|
public void testJvmDefaultDisable() throws Exception {
|
||||||
|
runTest("plugins/kapt3/kapt3-compiler/testData/converter/jvmDefaultDisable.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("jvmDefaultEnable.kt")
|
||||||
|
public void testJvmDefaultEnable() throws Exception {
|
||||||
|
runTest("plugins/kapt3/kapt3-compiler/testData/converter/jvmDefaultEnable.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("jvmOverloads.kt")
|
@TestMetadata("jvmOverloads.kt")
|
||||||
public void testJvmOverloads() throws Exception {
|
public void testJvmOverloads() throws Exception {
|
||||||
runTest("plugins/kapt3/kapt3-compiler/testData/converter/jvmOverloads.kt");
|
runTest("plugins/kapt3/kapt3-compiler/testData/converter/jvmOverloads.kt");
|
||||||
|
|||||||
@@ -0,0 +1,13 @@
|
|||||||
|
// !JVM_DEFAULT_MODE: all
|
||||||
|
|
||||||
|
interface Foo {
|
||||||
|
fun foo() {
|
||||||
|
System.out.println("foo")
|
||||||
|
}
|
||||||
|
|
||||||
|
fun foo2(a: Int) {
|
||||||
|
System.out.println("foo2")
|
||||||
|
}
|
||||||
|
|
||||||
|
fun bar()
|
||||||
|
}
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
import java.lang.System;
|
||||||
|
|
||||||
|
@kotlin.Metadata()
|
||||||
|
public abstract interface Foo {
|
||||||
|
|
||||||
|
public default void foo() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public default void foo2(int a) {
|
||||||
|
}
|
||||||
|
|
||||||
|
public abstract void bar();
|
||||||
|
}
|
||||||
+13
@@ -0,0 +1,13 @@
|
|||||||
|
// !JVM_DEFAULT_MODE: all-compatibility
|
||||||
|
|
||||||
|
interface Foo {
|
||||||
|
fun foo() {
|
||||||
|
System.out.println("foo")
|
||||||
|
}
|
||||||
|
|
||||||
|
fun foo2(a: Int) {
|
||||||
|
System.out.println("foo2")
|
||||||
|
}
|
||||||
|
|
||||||
|
fun bar()
|
||||||
|
}
|
||||||
+31
@@ -0,0 +1,31 @@
|
|||||||
|
import java.lang.System;
|
||||||
|
|
||||||
|
@kotlin.Metadata()
|
||||||
|
public abstract interface Foo {
|
||||||
|
|
||||||
|
public default void foo() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public default void foo2(int a) {
|
||||||
|
}
|
||||||
|
|
||||||
|
public abstract void bar();
|
||||||
|
|
||||||
|
@kotlin.Metadata()
|
||||||
|
public static final class DefaultImpls {
|
||||||
|
|
||||||
|
public DefaultImpls() {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
|
@java.lang.Deprecated()
|
||||||
|
public static void foo(@org.jetbrains.annotations.NotNull()
|
||||||
|
Foo $this) {
|
||||||
|
}
|
||||||
|
|
||||||
|
@java.lang.Deprecated()
|
||||||
|
public static void foo2(@org.jetbrains.annotations.NotNull()
|
||||||
|
Foo $this, int a) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
// !JVM_DEFAULT_MODE: disable
|
||||||
|
|
||||||
|
interface Foo {
|
||||||
|
fun foo() {
|
||||||
|
System.out.println("foo")
|
||||||
|
}
|
||||||
|
|
||||||
|
@JvmDefault
|
||||||
|
fun foo2(a: Int) {
|
||||||
|
System.out.println("foo2")
|
||||||
|
}
|
||||||
|
|
||||||
|
fun bar()
|
||||||
|
}
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
import java.lang.System;
|
||||||
|
|
||||||
|
@kotlin.Metadata()
|
||||||
|
public abstract interface Foo {
|
||||||
|
|
||||||
|
public abstract void foo();
|
||||||
|
|
||||||
|
public default void foo2(int a) {
|
||||||
|
}
|
||||||
|
|
||||||
|
public abstract void bar();
|
||||||
|
|
||||||
|
@kotlin.Metadata()
|
||||||
|
public static final class DefaultImpls {
|
||||||
|
|
||||||
|
public DefaultImpls() {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void foo(@org.jetbrains.annotations.NotNull()
|
||||||
|
Foo $this) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
// !JVM_DEFAULT_MODE: enable
|
||||||
|
|
||||||
|
interface Foo {
|
||||||
|
fun foo() {
|
||||||
|
System.out.println("foo")
|
||||||
|
}
|
||||||
|
|
||||||
|
@JvmDefault
|
||||||
|
fun foo2(a: Int) {
|
||||||
|
System.out.println("foo2")
|
||||||
|
}
|
||||||
|
|
||||||
|
fun bar()
|
||||||
|
}
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
import java.lang.System;
|
||||||
|
|
||||||
|
@kotlin.Metadata()
|
||||||
|
public abstract interface Foo {
|
||||||
|
|
||||||
|
public abstract void foo();
|
||||||
|
|
||||||
|
public default void foo2(int a) {
|
||||||
|
}
|
||||||
|
|
||||||
|
public abstract void bar();
|
||||||
|
|
||||||
|
@kotlin.Metadata()
|
||||||
|
public static final class DefaultImpls {
|
||||||
|
|
||||||
|
public DefaultImpls() {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void foo(@org.jetbrains.annotations.NotNull()
|
||||||
|
Foo $this) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user