Don't write JetValueParameter to the bytecode

The class itself can't be deleted at this point because it's used in the old
bytecode and tools (e.g. proguard) will complain if they can't find it in the
new runtime
This commit is contained in:
Alexander Udalov
2015-07-17 00:36:30 +03:00
parent 6ab1c6bfb3
commit 95be8b11f5
4 changed files with 5 additions and 167 deletions
@@ -71,7 +71,6 @@ import static org.jetbrains.kotlin.builtins.KotlinBuiltIns.isNullableAny;
import static org.jetbrains.kotlin.codegen.AsmUtil.*;
import static org.jetbrains.kotlin.codegen.JvmSerializationBindings.*;
import static org.jetbrains.kotlin.descriptors.CallableMemberDescriptor.Kind.DECLARATION;
import static org.jetbrains.kotlin.load.java.JvmAnnotationNames.OLD_JET_VALUE_PARAMETER_ANNOTATION;
import static org.jetbrains.kotlin.resolve.DescriptorToSourceUtils.getSourceFromDescriptor;
import static org.jetbrains.kotlin.resolve.DescriptorUtils.*;
import static org.jetbrains.kotlin.resolve.jvm.AsmTypes.OBJECT_TYPE;
@@ -170,10 +169,6 @@ public class FunctionCodegen {
AnnotationCodegen.forMethod(mv, typeMapper).genAnnotations(functionDescriptor, asmMethod.getReturnType());
generateParameterAnnotations(functionDescriptor, mv, typeMapper.mapSignature(functionDescriptor));
if (state.getClassBuilderMode() != ClassBuilderMode.LIGHT_CLASSES) {
generateJetValueParameterAnnotations(mv, functionDescriptor, jvmSignature);
}
generateBridges(functionDescriptor);
boolean staticInCompanionObject = AnnotationsPackage.isPlatformStaticInCompanionObject(functionDescriptor);
@@ -239,56 +234,6 @@ public class FunctionCodegen {
}
}
@SuppressWarnings("deprecation")
private static void generateJetValueParameterAnnotations(
@NotNull MethodVisitor mv,
@NotNull FunctionDescriptor functionDescriptor,
@NotNull JvmMethodSignature jvmSignature
) {
Iterator<ValueParameterDescriptor> descriptors = functionDescriptor.getValueParameters().iterator();
List<JvmMethodParameterSignature> kotlinParameterTypes = jvmSignature.getValueParameters();
for (int i = 0; i < kotlinParameterTypes.size(); i++) {
JvmMethodParameterKind kind = kotlinParameterTypes.get(i).getKind();
if (kind.isSkippedInGenericSignature()) continue;
String name;
boolean nullableType;
if (kind == JvmMethodParameterKind.VALUE) {
ValueParameterDescriptor descriptor = descriptors.next();
name = descriptor.getName().asString();
nullableType = descriptor.getType().isMarkedNullable();
}
else {
String lowercaseKind = kind.name().toLowerCase();
if (needIndexForVar(kind)) {
name = "$" + lowercaseKind + "$" + i;
}
else {
name = "$" + lowercaseKind;
}
if (kind == JvmMethodParameterKind.RECEIVER) {
ReceiverParameterDescriptor receiver = functionDescriptor.getExtensionReceiverParameter();
nullableType = receiver == null || receiver.getType().isMarkedNullable();
}
else {
nullableType = true;
}
}
AnnotationVisitor av =
mv.visitParameterAnnotation(i, asmDescByFqNameWithoutInnerClasses(OLD_JET_VALUE_PARAMETER_ANNOTATION), true);
if (av != null) {
av.visit("name", name);
if (nullableType) {
av.visit("type", "?");
}
av.visitEnd();
}
}
}
private void markEnumOrInnerConstructorParameterAsSynthetic(MethodVisitor mv, int i) {
// IDEA's ClsPsi builder fails to annotate synthetic parameters
if (state.getClassBuilderMode() == ClassBuilderMode.LIGHT_CLASSES) return;
@@ -1,106 +0,0 @@
/*
* Copyright 2010-2015 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.kotlin.codegen;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.kotlin.test.ConfigurationKind;
import java.lang.annotation.Annotation;
@SuppressWarnings("deprecation")
public class JetValueParameterAnnotationTest extends CodegenTestCase {
@Override
protected void setUp() throws Exception {
super.setUp();
createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY);
}
private static class ValueParameter {
public final String name;
public final String type;
private ValueParameter(@NotNull String name, @NotNull String type) {
this.name = name;
this.type = type;
}
}
@NotNull
private static ValueParameter valueParameter(@NotNull String name, boolean nullable) {
return new ValueParameter(name, nullable ? "?" : "");
}
public void testOneNotNullParam() {
doTest(
"fun foo(byte: Byte) {}",
valueParameter("byte", false)
);
}
public void testTwoNotNullParams() {
doTest(
"fun foo(int: Int, string: String) {}",
valueParameter("int", false),
valueParameter("string", false)
);
}
public void testTwoNullableParams() {
doTest(
"fun foo(long: Long?, unit: Unit?) {}",
valueParameter("long", true),
valueParameter("unit", true)
);
}
public void testTwoMixedParams() {
doTest(
"fun foo(short: Short?, boolean: Boolean) {}",
valueParameter("short", true),
valueParameter("boolean", false)
);
}
public void testNotNullReceiver() {
doTest(
"fun Int.foo() {}",
valueParameter("$receiver", false)
);
}
public void testNullableReceiver() {
doTest(
"fun String?.foo() {}",
valueParameter("$receiver", true)
);
}
private void doTest(@NotNull String code, @NotNull ValueParameter... expected) {
loadText(code);
Annotation[][] annotations = generateFunction().getParameterAnnotations();
assertSize(expected.length, annotations);
for (int i = 0, length = annotations.length; i < length; i++) {
assertSize(1, annotations[i]);
Annotation annotation = annotations[i][0];
assertEquals("jet.runtime.typeinfo.JetValueParameter", annotation.annotationType().getName());
assertEquals(expected[i].name, CodegenTestUtil.getAnnotationAttribute(annotation, "name"));
assertEquals(expected[i].type, CodegenTestUtil.getAnnotationAttribute(annotation, "type"));
}
}
}
@@ -101,8 +101,6 @@ public final class JvmAnnotationNames {
@Deprecated
public static final FqName OLD_JET_PACKAGE_CLASS_ANNOTATION = new FqName("jet.runtime.typeinfo.JetPackageClass");
@Deprecated
public static final FqName OLD_JET_VALUE_PARAMETER_ANNOTATION = new FqName("jet.runtime.typeinfo.JetValueParameter");
@Deprecated
public static final FqName OLD_KOTLIN_CLASS = new FqName("jet.KotlinClass");
@Deprecated
public static final FqName OLD_KOTLIN_PACKAGE = new FqName("jet.KotlinPackage");
@@ -21,15 +21,16 @@ import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* @deprecated This class is no longer used in the bytecode produced by Kotlin compiler
* and exists in the Kotlin Java Runtime only for compatibility with the older code.
* It will be deleted completely after M13.
*/
@Target(ElementType.PARAMETER)
@Retention(RetentionPolicy.RUNTIME)
@Deprecated
public @interface JetValueParameter {
String name();
/**
* This is a hack for Kara
* @return <code>"?"</code> if the type of this parameter is nullable, an empty string otherwise
*/
String type() default "";
}