Do not annotate Kotlin members returning platform types as @Nullable

This leads to pointless warning in Java code
This commit is contained in:
Andrey Breslav
2014-11-04 10:36:29 +02:00
parent 19afb2fcb8
commit f16dcdd8a9
4 changed files with 36 additions and 0 deletions
@@ -34,8 +34,10 @@ import org.jetbrains.jet.lang.resolve.calls.model.ResolvedCall;
import org.jetbrains.jet.lang.resolve.constants.*;
import org.jetbrains.jet.lang.resolve.constants.StringValue;
import org.jetbrains.jet.lang.resolve.name.FqName;
import org.jetbrains.jet.lang.types.Flexibility;
import org.jetbrains.jet.lang.types.JetType;
import org.jetbrains.jet.lang.types.TypeUtils;
import org.jetbrains.jet.lang.types.TypesPackage;
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns;
import org.jetbrains.org.objectweb.asm.*;
@@ -184,6 +186,14 @@ public abstract class AnnotationCodegen {
return;
}
if (TypesPackage.isFlexible(type)) {
// A flexible type whose lower bound in not-null and upper bound is nullable, should not be annotated
Flexibility flexibility = TypesPackage.flexibility(type);
if (!TypeUtils.isNullableType(flexibility.getLowerBound()) && TypeUtils.isNullableType(flexibility.getUpperBound())) {
return;
}
}
boolean isNullableType = TypeUtils.isNullableType(type);
Class<?> annotationClass = isNullableType ? Nullable.class : NotNull.class;
@@ -0,0 +1,11 @@
public final class PlatformTypes implements kotlin.jvm.internal.KObject {
public final java.lang.String simplyPlatform() { /* compiled code */ }
@org.jetbrains.annotations.Nullable
public final java.util.List<java.lang.String> bothNullable() { /* compiled code */ }
@org.jetbrains.annotations.NotNull
public final java.util.List<java.lang.String> bothNotNull() { /* compiled code */ }
public PlatformTypes() { /* compiled code */ }
}
@@ -0,0 +1,9 @@
// PlatformTypes
import java.util.Collections
class PlatformTypes {
fun simplyPlatform() = Collections.singletonList("")[0]
fun bothNullable() = Collections.emptyList<String>() ?: null
fun bothNotNull() = Collections.emptyList<String>()!!
}
@@ -114,6 +114,12 @@ public class KotlinLightClassTestGenerated extends AbstractKotlinLightClassTest
doTest(fileName);
}
@TestMetadata("PlatformTypes.kt")
public void testPlatformTypes() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/asJava/lightClasses/nullabilityAnnotations/PlatformTypes.kt");
doTest(fileName);
}
@TestMetadata("Primitives.kt")
public void testPrimitives() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/asJava/lightClasses/nullabilityAnnotations/Primitives.kt");