Update synthetic parameter processing logic according to ASM 7 changes

#KT-27774 Fixed
This commit is contained in:
Mikhael Bogdanov
2018-10-29 08:48:37 +01:00
parent 23b9889ebb
commit d2a205c72d
47 changed files with 808 additions and 12 deletions
@@ -73,6 +73,9 @@ import static org.jetbrains.kotlin.types.TypeUtils.isNullableType;
import static org.jetbrains.org.objectweb.asm.Opcodes.*;
public class AsmUtil {
public static final boolean IS_BUILT_WITH_ASM6 = Opcodes.API_VERSION <= Opcodes.ASM6;
private static final Set<Type> STRING_BUILDER_OBJECT_APPEND_ARG_TYPES = Sets.newHashSet(
getType(String.class),
getType(StringBuffer.class),
@@ -517,12 +517,27 @@ public class FunctionCodegen {
Iterator<ValueParameterDescriptor> iterator = valueParameters.iterator();
List<JvmMethodParameterSignature> kotlinParameterTypes = jvmSignature.getValueParameters();
int syntheticParameterCount = 0;
for (int i = 0; i < kotlinParameterTypes.size(); i++) {
JvmMethodParameterSignature parameterSignature = kotlinParameterTypes.get(i);
JvmMethodParameterKind kind = parameterSignature.getKind();
if (kind.isSkippedInGenericSignature()) {
if (AsmUtil.IS_BUILT_WITH_ASM6) {
markEnumOrInnerConstructorParameterAsSynthetic(mv, i, state.getClassBuilderMode());
}
else {
syntheticParameterCount++;
}
}
}
if (!AsmUtil.IS_BUILT_WITH_ASM6) {
Asm7UtilKt.visitAnnotableParameterCount(mv, kotlinParameterTypes.size() - syntheticParameterCount);
}
for (int i = 0; i < kotlinParameterTypes.size(); i++) {
JvmMethodParameterSignature parameterSignature = kotlinParameterTypes.get(i);
JvmMethodParameterKind kind = parameterSignature.getKind();
if (kind.isSkippedInGenericSignature()) {
markEnumOrInnerConstructorParameterAsSynthetic(mv, i, state.getClassBuilderMode());
continue;
}
@@ -534,7 +549,9 @@ public class FunctionCodegen {
: null;
if (annotated != null) {
AnnotationCodegen.forParameter(i, mv, innerClassConsumer, state).genAnnotations(annotated, parameterSignature.getAsmType());
//noinspection ConstantConditions
AnnotationCodegen.forParameter(AsmUtil.IS_BUILT_WITH_ASM6 ? i : i - syntheticParameterCount, mv, innerClassConsumer, state)
.genAnnotations(annotated, parameterSignature.getAsmType());
}
}
}
@@ -0,0 +1,10 @@
/*
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the license/LICENSE.txt file.
*/
package org.jetbrains.kotlin.codegen
import org.jetbrains.org.objectweb.asm.MethodVisitor
internal fun visitAnnotableParameterCount(mv: MethodVisitor, paramCount: Int) {}
@@ -0,0 +1,13 @@
/*
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the license/LICENSE.txt file.
*/
package org.jetbrains.kotlin.codegen
import org.jetbrains.org.objectweb.asm.MethodVisitor
internal fun visitAnnotableParameterCount(mv: MethodVisitor, paramCount: Int) {
mv.visitAnnotableParameterCount(paramCount, true)
mv.visitAnnotableParameterCount(paramCount, false)
}