Remove obsolete logic to IS_BUILT_WITH_ASM6

This commit is contained in:
Mikhael Bogdanov
2019-12-11 11:20:56 +01:00
parent a92f58b1ac
commit 8225c5a9ce
4 changed files with 9 additions and 50 deletions
@@ -76,8 +76,6 @@ 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),
@@ -520,22 +520,9 @@ 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);
}
int syntheticParameterCount = CollectionsKt.count(kotlinParameterTypes, signature -> signature.getKind().isSkippedInGenericSignature());
Asm7UtilKt.visitAnnotableParameterCount(mv, kotlinParameterTypes.size() - syntheticParameterCount);
for (int i = 0; i < kotlinParameterTypes.size(); i++) {
JvmMethodParameterSignature parameterSignature = kotlinParameterTypes.get(i);
@@ -553,25 +540,12 @@ public class FunctionCodegen {
if (annotated != null) {
//noinspection ConstantConditions
AnnotationCodegen.forParameter(AsmUtil.IS_BUILT_WITH_ASM6 ? i : i - syntheticParameterCount, mv, innerClassConsumer, state)
AnnotationCodegen.forParameter(i - syntheticParameterCount, mv, innerClassConsumer, state)
.genAnnotations(annotated, parameterSignature.getAsmType());
}
}
}
private static void markEnumOrInnerConstructorParameterAsSynthetic(MethodVisitor mv, int i, ClassBuilderMode mode) {
// IDEA's ClsPsi builder fails to annotate synthetic parameters
if (mode == ClassBuilderMode.LIGHT_CLASSES) return;
// This is needed to avoid RuntimeInvisibleParameterAnnotations error in javac:
// see MethodWriter.visitParameterAnnotation()
AnnotationVisitor av = mv.visitParameterAnnotation(i, "Ljava/lang/Synthetic;", true);
if (av != null) {
av.visitEnd();
}
}
@Nullable
private static Type getThisTypeForFunction(
@NotNull FunctionDescriptor functionDescriptor,
@@ -221,22 +221,9 @@ private fun generateParameterAnnotations(
) {
val iterator = irFunction.valueParameters.iterator()
val kotlinParameterTypes = jvmSignature.valueParameters
var syntheticParameterCount = 0
kotlinParameterTypes.forEachIndexed { i, parameterSignature ->
val kind = parameterSignature.kind
if (kind.isSkippedInGenericSignature) {
if (AsmUtil.IS_BUILT_WITH_ASM6) {
// This is needed to avoid RuntimeInvisibleParameterAnnotations error in javac:
// see MethodWriter.visitParameterAnnotation()
mv.visitParameterAnnotation(i, "Ljava/lang/Synthetic;", true)?.visitEnd()
} else {
syntheticParameterCount++
}
}
}
if (!AsmUtil.IS_BUILT_WITH_ASM6) {
visitAnnotableParameterCount(mv, kotlinParameterTypes.size - syntheticParameterCount)
}
val syntheticParameterCount = kotlinParameterTypes.count { it.kind.isSkippedInGenericSignature }
visitAnnotableParameterCount(mv, kotlinParameterTypes.size - syntheticParameterCount)
kotlinParameterTypes.forEachIndexed { i, parameterSignature ->
val kind = parameterSignature.kind
@@ -248,7 +235,7 @@ private fun generateParameterAnnotations(
if (!kind.isSkippedInGenericSignature) {
AnnotationCodegen(innerClassConsumer, context) { descriptor, visible ->
mv.visitParameterAnnotation(
if (AsmUtil.IS_BUILT_WITH_ASM6) i else i - syntheticParameterCount,
i - syntheticParameterCount,
descriptor,
visible
)
@@ -74,7 +74,7 @@ internal fun MethodNode.getParametersInfo(containingClass: ClassNode, isInnerCla
name = "p${index - startParameterIndex}"
}
val indexForAnnotation = if (AsmUtil.IS_BUILT_WITH_ASM6) index else index - startParameterIndex
val indexForAnnotation = index - startParameterIndex
val visibleAnnotations = visibleParameterAnnotations?.get(indexForAnnotation)
val invisibleAnnotations = invisibleParameterAnnotations?.get(indexForAnnotation)
parameterInfos += ParameterInfo(0, name, type, visibleAnnotations, invisibleAnnotations)