Override/Implement Members: Support all nullability annotations respected by the Kotlin compiler
#KT-12704 Fixed #KT-15583 Fixed
This commit is contained in:
@@ -473,6 +473,7 @@ These artifacts include extensions for the types available in the latter JDKs, s
|
|||||||
- Pull Up: Fix pull-up from object to superclass
|
- Pull Up: Fix pull-up from object to superclass
|
||||||
- [`KT-15602`](https://youtrack.jetbrains.com/issue/KT-15602) Extract Interface/Superclass: Disable "Make abstract" for inline/external/lateinit members
|
- [`KT-15602`](https://youtrack.jetbrains.com/issue/KT-15602) Extract Interface/Superclass: Disable "Make abstract" for inline/external/lateinit members
|
||||||
- Extract Interface: Disable inline/external/lateinit members
|
- Extract Interface: Disable inline/external/lateinit members
|
||||||
|
- [`KT-12704`](https://youtrack.jetbrains.com/issue/KT-12704), [`KT-15583`](https://youtrack.jetbrains.com/issue/KT-15583) Override/Implement Members: Support all nullability annotations respected by the Kotlin compiler
|
||||||
|
|
||||||
#### Intention actions, inspections and quickfixes
|
#### Intention actions, inspections and quickfixes
|
||||||
|
|
||||||
|
|||||||
@@ -31,10 +31,7 @@ import org.jetbrains.kotlin.resolve.descriptorUtil.builtIns
|
|||||||
import org.jetbrains.kotlin.resolve.scopes.LexicalScope
|
import org.jetbrains.kotlin.resolve.scopes.LexicalScope
|
||||||
import org.jetbrains.kotlin.resolve.scopes.utils.findClassifier
|
import org.jetbrains.kotlin.resolve.scopes.utils.findClassifier
|
||||||
import org.jetbrains.kotlin.types.*
|
import org.jetbrains.kotlin.types.*
|
||||||
import org.jetbrains.kotlin.types.typeUtil.builtIns
|
import org.jetbrains.kotlin.types.typeUtil.*
|
||||||
import org.jetbrains.kotlin.types.typeUtil.immediateSupertypes
|
|
||||||
import org.jetbrains.kotlin.types.typeUtil.substitute
|
|
||||||
import org.jetbrains.kotlin.types.typeUtil.supertypes
|
|
||||||
import org.jetbrains.kotlin.utils.SmartSet
|
import org.jetbrains.kotlin.utils.SmartSet
|
||||||
import org.jetbrains.kotlin.utils.addToStdlib.singletonList
|
import org.jetbrains.kotlin.utils.addToStdlib.singletonList
|
||||||
|
|
||||||
@@ -68,7 +65,7 @@ private fun KotlinType.approximateNonDynamicFlexibleTypes(
|
|||||||
|
|
||||||
approximation = approximation.approximateNonDynamicFlexibleTypes()
|
approximation = approximation.approximateNonDynamicFlexibleTypes()
|
||||||
|
|
||||||
approximation = if (isAnnotatedNotNull()) approximation.makeNullableAsSpecified(false) else approximation
|
approximation = if (nullability() == TypeNullability.NOT_NULL) approximation.makeNullableAsSpecified(false) else approximation
|
||||||
|
|
||||||
if (approximation.isMarkedNullable && !flexible.lowerBound.isMarkedNullable && TypeUtils.isTypeParameter(approximation) && TypeUtils.hasNullableSuperType(approximation)) {
|
if (approximation.isMarkedNullable && !flexible.lowerBound.isMarkedNullable && TypeUtils.isTypeParameter(approximation) && TypeUtils.hasNullableSuperType(approximation)) {
|
||||||
approximation = approximation.makeNullableAsSpecified(false)
|
approximation = approximation.makeNullableAsSpecified(false)
|
||||||
|
|||||||
+3
-1
@@ -47,8 +47,10 @@ import org.jetbrains.kotlin.resolve.BindingContext
|
|||||||
import org.jetbrains.kotlin.resolve.DescriptorUtils
|
import org.jetbrains.kotlin.resolve.DescriptorUtils
|
||||||
import org.jetbrains.kotlin.resolve.descriptorUtil.resolveTopLevelClass
|
import org.jetbrains.kotlin.resolve.descriptorUtil.resolveTopLevelClass
|
||||||
import org.jetbrains.kotlin.types.*
|
import org.jetbrains.kotlin.types.*
|
||||||
|
import org.jetbrains.kotlin.types.typeUtil.TypeNullability
|
||||||
import org.jetbrains.kotlin.types.typeUtil.builtIns
|
import org.jetbrains.kotlin.types.typeUtil.builtIns
|
||||||
import org.jetbrains.kotlin.types.typeUtil.isUnit
|
import org.jetbrains.kotlin.types.typeUtil.isUnit
|
||||||
|
import org.jetbrains.kotlin.types.typeUtil.nullability
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
interface Parameter {
|
interface Parameter {
|
||||||
@@ -331,7 +333,7 @@ val ControlFlow.possibleReturnTypes: List<KotlinType>
|
|||||||
return when {
|
return when {
|
||||||
!returnType.isNullabilityFlexible() ->
|
!returnType.isNullabilityFlexible() ->
|
||||||
listOf(returnType)
|
listOf(returnType)
|
||||||
returnType.isAnnotatedNotNull() || returnType.isAnnotatedNullable() ->
|
returnType.nullability() != TypeNullability.FLEXIBLE ->
|
||||||
listOf(returnType.approximateFlexibleTypes())
|
listOf(returnType.approximateFlexibleTypes())
|
||||||
else ->
|
else ->
|
||||||
(returnType.unwrap() as FlexibleType).let { listOf(it.upperBound, it.lowerBound) }
|
(returnType.unwrap() as FlexibleType).let { listOf(it.upperBound, it.lowerBound) }
|
||||||
|
|||||||
@@ -0,0 +1,9 @@
|
|||||||
|
package foo;
|
||||||
|
|
||||||
|
import javax.annotation.Nonnull;
|
||||||
|
|
||||||
|
public class A {
|
||||||
|
public @Nonnull String foo(@Nonnull String s) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
import foo.A
|
||||||
|
|
||||||
|
class B : A() {
|
||||||
|
<caret>
|
||||||
|
}
|
||||||
+7
@@ -0,0 +1,7 @@
|
|||||||
|
import foo.A
|
||||||
|
|
||||||
|
class B : A() {
|
||||||
|
override fun foo(s: String): String {
|
||||||
|
<selection><caret>return super.foo(s)</selection>
|
||||||
|
}
|
||||||
|
}
|
||||||
Vendored
+26
@@ -0,0 +1,26 @@
|
|||||||
|
package javax.annotation;
|
||||||
|
|
||||||
|
import java.lang.annotation.Documented;
|
||||||
|
import java.lang.annotation.Retention;
|
||||||
|
import java.lang.annotation.RetentionPolicy;
|
||||||
|
|
||||||
|
import javax.annotation.meta.TypeQualifier;
|
||||||
|
import javax.annotation.meta.TypeQualifierValidator;
|
||||||
|
import javax.annotation.meta.When;
|
||||||
|
|
||||||
|
@Documented
|
||||||
|
@TypeQualifier
|
||||||
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
|
public @interface Nonnull {
|
||||||
|
When when() default When.ALWAYS;
|
||||||
|
|
||||||
|
static class Checker implements TypeQualifierValidator<Nonnull> {
|
||||||
|
|
||||||
|
public When forConstantValue(Nonnull qualifierqualifierArgument,
|
||||||
|
Object value) {
|
||||||
|
if (value == null)
|
||||||
|
return When.NEVER;
|
||||||
|
return When.ALWAYS;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -256,6 +256,10 @@ class OverrideImplementTest : AbstractOverrideImplementTest() {
|
|||||||
doOverrideDirectoryTest("foo")
|
doOverrideDirectoryTest("foo")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun testJavaxNonnullJavaType() {
|
||||||
|
doOverrideDirectoryTest("foo")
|
||||||
|
}
|
||||||
|
|
||||||
fun testNullableKotlinType() {
|
fun testNullableKotlinType() {
|
||||||
doOverrideDirectoryTest("foo")
|
doOverrideDirectoryTest("foo")
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user