Kapt: Preserve parameter names for abstract methods
This commit is contained in:
committed by
Yan Zhulanow
parent
18e17a4400
commit
5ec16167bc
@@ -70,7 +70,7 @@ public abstract class TransformationMethodVisitor extends MethodVisitor {
|
||||
// So we just do it here
|
||||
if (methodNode.instructions.size() == 0
|
||||
// MethodNode does not create a list of variables for abstract methods, so we would get NPE in accept() instead
|
||||
&& (!(delegate instanceof MethodNode) || (methodNode.access & Opcodes.ACC_ABSTRACT) == 0)
|
||||
&& (!(delegate instanceof MethodNode) || methodNode.localVariables != null)
|
||||
) {
|
||||
List<LocalVariableNode> localVariables = methodNode.localVariables;
|
||||
// visits local variables
|
||||
|
||||
@@ -21,12 +21,8 @@ import org.jetbrains.kotlin.codegen.ClassBuilder
|
||||
import org.jetbrains.kotlin.codegen.ClassBuilderFactory
|
||||
import org.jetbrains.kotlin.codegen.ClassBuilderMode
|
||||
import org.jetbrains.kotlin.resolve.jvm.diagnostics.JvmDeclarationOrigin
|
||||
import org.jetbrains.org.objectweb.asm.ClassWriter
|
||||
import org.jetbrains.org.objectweb.asm.FieldVisitor
|
||||
import org.jetbrains.org.objectweb.asm.MethodVisitor
|
||||
import org.jetbrains.org.objectweb.asm.tree.ClassNode
|
||||
import org.jetbrains.org.objectweb.asm.tree.FieldNode
|
||||
import org.jetbrains.org.objectweb.asm.tree.MethodNode
|
||||
import org.jetbrains.org.objectweb.asm.*
|
||||
import org.jetbrains.org.objectweb.asm.tree.*
|
||||
|
||||
internal class Kapt3BuilderFactory : ClassBuilderFactory {
|
||||
internal val compiledClasses = mutableListOf<ClassNode>()
|
||||
@@ -65,6 +61,12 @@ internal class Kapt3BuilderFactory : ClassBuilderFactory {
|
||||
): MethodVisitor {
|
||||
val methodNode = super.newMethod(origin, access, name, desc, signature, exceptions) as MethodNode
|
||||
origins.put(methodNode, origin)
|
||||
|
||||
// ASM doesn't read information about local variables for the `abstract` methods so we need to get it manually
|
||||
if ((access and Opcodes.ACC_ABSTRACT) != 0 && methodNode.localVariables == null) {
|
||||
methodNode.localVariables = mutableListOf<LocalVariableNode>()
|
||||
}
|
||||
|
||||
return methodNode
|
||||
}
|
||||
}
|
||||
|
||||
+6
@@ -186,6 +186,12 @@ public class ClassFileToSourceStubConverterTestGenerated extends AbstractClassFi
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("methodParameterNames.kt")
|
||||
public void testMethodParameterNames() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("plugins/kapt3/testData/converter/methodParameterNames.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("methodPropertySignatureClash.kt")
|
||||
public void testMethodPropertySignatureClash() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("plugins/kapt3/testData/converter/methodPropertySignatureClash.kt");
|
||||
|
||||
+2
-2
@@ -1,10 +1,10 @@
|
||||
public abstract class Base {
|
||||
|
||||
protected abstract void doJob(@org.jetbrains.annotations.NotNull()
|
||||
java.lang.String p0, int p1);
|
||||
java.lang.String job, int delay);
|
||||
|
||||
protected abstract <T extends java.lang.CharSequence>void doJobGeneric(@org.jetbrains.annotations.NotNull()
|
||||
T p0, int p1);
|
||||
T job, int delay);
|
||||
|
||||
public Base() {
|
||||
super();
|
||||
|
||||
+1
-1
@@ -2,7 +2,7 @@ public abstract interface EntryHolder {
|
||||
|
||||
@org.jetbrains.annotations.NotNull()
|
||||
public abstract java.util.Map.Entry<java.lang.String, java.lang.Object> entry(@org.jetbrains.annotations.NotNull()
|
||||
java.util.Map.Entry<? extends java.lang.CharSequence, ? extends java.util.Map.Entry<java.lang.String, java.lang.Integer>> p0);
|
||||
java.util.Map.Entry<? extends java.lang.CharSequence, ? extends java.util.Map.Entry<java.lang.String, java.lang.Integer>> p);
|
||||
|
||||
@org.jetbrains.annotations.NotNull()
|
||||
public abstract java.util.Map.Entry<java.lang.String, java.lang.Object> getEntryProperty();
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
interface Intf {
|
||||
fun foo(abc: String)
|
||||
|
||||
fun bar(bcd: Int): String {
|
||||
return ""
|
||||
}
|
||||
}
|
||||
|
||||
abstract class Cls {
|
||||
abstract fun foo(abc: String)
|
||||
|
||||
fun bar(bcd: Int): String {
|
||||
return ""
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
public abstract class Cls {
|
||||
|
||||
public abstract void foo(@org.jetbrains.annotations.NotNull()
|
||||
java.lang.String abc);
|
||||
|
||||
@org.jetbrains.annotations.NotNull()
|
||||
public final java.lang.String bar(int bcd) {
|
||||
return null;
|
||||
}
|
||||
|
||||
public Cls() {
|
||||
super();
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////
|
||||
|
||||
|
||||
public abstract interface Intf {
|
||||
|
||||
public abstract void foo(@org.jetbrains.annotations.NotNull()
|
||||
java.lang.String abc);
|
||||
|
||||
@org.jetbrains.annotations.NotNull()
|
||||
public abstract java.lang.String bar(int bcd);
|
||||
|
||||
public static final class DefaultImpls {
|
||||
|
||||
public DefaultImpls() {
|
||||
super();
|
||||
}
|
||||
|
||||
@org.jetbrains.annotations.NotNull()
|
||||
public static java.lang.String bar(Intf $this, int bcd) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user