generate local variables table for @JvmOverloads-generated methods

#KT-7319 Fixed
This commit is contained in:
Dmitry Jemerov
2016-02-01 18:45:41 +01:00
parent da7acd5e73
commit 970d6f6834
5 changed files with 43 additions and 5 deletions
@@ -26,6 +26,7 @@ import org.jetbrains.kotlin.resolve.descriptorUtil.hasDefaultValue
import org.jetbrains.kotlin.resolve.jvm.AsmTypes
import org.jetbrains.kotlin.resolve.jvm.annotations.hasJvmOverloadsAnnotation
import org.jetbrains.kotlin.resolve.jvm.diagnostics.OtherOrigin
import org.jetbrains.org.objectweb.asm.Label
import org.jetbrains.org.objectweb.asm.Opcodes
import org.jetbrains.org.objectweb.asm.commons.InstructionAdapter
@@ -134,6 +135,7 @@ class DefaultParameterValueSubstitutor(val state: GenerationState) {
}
if (state.classBuilderMode == ClassBuilderMode.LIGHT_CLASSES) {
FunctionCodegen.generateLocalVariablesForParameters(mv, signature, null, Label(), Label(), remainingParameters, isStatic)
mv.visitEnd()
return
}
@@ -142,6 +144,9 @@ class DefaultParameterValueSubstitutor(val state: GenerationState) {
val v = InstructionAdapter(mv)
mv.visitCode()
val methodBegin = Label()
mv.visitLabel(methodBegin)
val methodOwner = typeMapper.mapToCallableMethod(delegateFunctionDescriptor, false).owner
if (!isStatic) {
val thisIndex = frameMap.enterTemp(AsmTypes.OBJECT_TYPE)
@@ -201,6 +206,13 @@ class DefaultParameterValueSubstitutor(val state: GenerationState) {
v.invokestatic(methodOwner.internalName, defaultMethod.name, defaultMethod.descriptor, false)
}
v.areturn(signature.returnType)
val methodEnd = Label()
mv.visitLabel(methodEnd)
FunctionCodegen.generateLocalVariablesForParameters(mv, signature, null, methodBegin, methodEnd,
remainingParameters, isStatic)
FunctionCodegen.endVisit(mv, null, methodElement)
}
@@ -400,11 +400,24 @@ public class FunctionCodegen {
@NotNull Label methodEnd,
@NotNull OwnerKind ownerKind
) {
Iterator<ValueParameterDescriptor> valueParameters = functionDescriptor.getValueParameters().iterator();
generateLocalVariablesForParameters(mv, jvmMethodSignature, thisType, methodBegin, methodEnd,
functionDescriptor.getValueParameters(),
AsmUtil.isStaticMethod(ownerKind, functionDescriptor));
}
public static void generateLocalVariablesForParameters(
@NotNull MethodVisitor mv,
@NotNull JvmMethodSignature jvmMethodSignature,
@Nullable Type thisType,
@NotNull Label methodBegin,
@NotNull Label methodEnd,
Collection<ValueParameterDescriptor> valueParameters,
boolean isStatic
) {
Iterator<ValueParameterDescriptor> valueParameterIterator = valueParameters.iterator();
List<JvmMethodParameterSignature> params = jvmMethodSignature.getValueParameters();
int shift = 0;
boolean isStatic = AsmUtil.isStaticMethod(ownerKind, functionDescriptor);
if (!isStatic) {
//add this
if (thisType != null) {
@@ -422,7 +435,7 @@ public class FunctionCodegen {
String parameterName;
if (kind == JvmMethodParameterKind.VALUE) {
ValueParameterDescriptor parameter = valueParameters.next();
ValueParameterDescriptor parameter = valueParameterIterator.next();
parameterName = parameter.getName().asString();
}
else {
@@ -5,11 +5,11 @@ public final class C {
@kotlin.jvm.JvmOverloads
@org.jetbrains.annotations.NotNull
public java.lang.String foo(@org.jetbrains.annotations.NotNull java.lang.String p, @org.jetbrains.annotations.NotNull java.lang.String p1, @org.jetbrains.annotations.Nullable java.lang.String p2) { /* compiled code */ }
public java.lang.String foo(@org.jetbrains.annotations.NotNull java.lang.String o, @org.jetbrains.annotations.NotNull java.lang.String o1, @org.jetbrains.annotations.Nullable java.lang.String o4) { /* compiled code */ }
@kotlin.jvm.JvmOverloads
@org.jetbrains.annotations.NotNull
public java.lang.String foo(@org.jetbrains.annotations.NotNull java.lang.String p, @org.jetbrains.annotations.Nullable java.lang.String p1) { /* compiled code */ }
public java.lang.String foo(@org.jetbrains.annotations.NotNull java.lang.String o1, @org.jetbrains.annotations.Nullable java.lang.String o4) { /* compiled code */ }
public C() { /* compiled code */ }
}
@@ -0,0 +1,7 @@
class C {
@kotlin.jvm.JvmOverloads fun foo(firstParam: Int, secondParam: String = "") {
}
}
// METHOD : C.foo(I)V
// VARIABLE : NAME=firstParam TYPE=I INDEX=1
@@ -83,6 +83,12 @@ public class CheckLocalVariablesTableTestGenerated extends AbstractCheckLocalVar
doTest(fileName);
}
@TestMetadata("jvmOverloads.kt")
public void testJvmOverloads() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/checkLocalVariablesTable/jvmOverloads.kt");
doTest(fileName);
}
@TestMetadata("lambdaAsVar.kt")
public void testLambdaAsVar() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/checkLocalVariablesTable/lambdaAsVar.kt");