Take nullability annotations into account in QF correcting override
So Java NotNull annotated is converted to `Type` and Java Nullable annotated to `Type?` accordingly So #KT-19299 Fixed
This commit is contained in:
committed by
Mikhail Glukhikh
parent
1264ed7c86
commit
64eeb479aa
@@ -35,6 +35,9 @@ import org.jetbrains.kotlin.idea.util.IdeDescriptorRenderers
|
|||||||
import org.jetbrains.kotlin.idea.core.ShortenReferences
|
import org.jetbrains.kotlin.idea.core.ShortenReferences
|
||||||
import org.jetbrains.kotlin.idea.util.application.executeWriteCommand
|
import org.jetbrains.kotlin.idea.util.application.executeWriteCommand
|
||||||
import org.jetbrains.kotlin.incremental.components.NoLookupLocation
|
import org.jetbrains.kotlin.incremental.components.NoLookupLocation
|
||||||
|
import org.jetbrains.kotlin.load.java.NOT_NULL_ANNOTATIONS
|
||||||
|
import org.jetbrains.kotlin.load.java.NULLABLE_ANNOTATIONS
|
||||||
|
import org.jetbrains.kotlin.name.FqName
|
||||||
import org.jetbrains.kotlin.psi.KtFile
|
import org.jetbrains.kotlin.psi.KtFile
|
||||||
import org.jetbrains.kotlin.psi.KtNamedFunction
|
import org.jetbrains.kotlin.psi.KtNamedFunction
|
||||||
import org.jetbrains.kotlin.psi.KtParameterList
|
import org.jetbrains.kotlin.psi.KtParameterList
|
||||||
@@ -202,8 +205,7 @@ class ChangeMemberFunctionSignatureFix private constructor(
|
|||||||
SourceElement.NO_SOURCE
|
SourceElement.NO_SOURCE
|
||||||
)
|
)
|
||||||
|
|
||||||
val parameters = newParameters.withIndex().map {
|
val parameters = newParameters.withIndex().map { (index, parameter) ->
|
||||||
val (index, parameter) = it
|
|
||||||
ValueParameterDescriptorImpl(
|
ValueParameterDescriptorImpl(
|
||||||
descriptor, null, index,
|
descriptor, null, index,
|
||||||
parameter.annotations, parameter.name, parameter.returnType!!, parameter.declaresDefaultValue(),
|
parameter.annotations, parameter.name, parameter.returnType!!, parameter.declaresDefaultValue(),
|
||||||
@@ -319,6 +321,15 @@ class ChangeMemberFunctionSignatureFix private constructor(
|
|||||||
ShortenReferences.DEFAULT.process(newTypeRef)
|
ShortenReferences.DEFAULT.process(newTypeRef)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
patternFunction.valueParameters.forEach { param ->
|
||||||
|
param.annotationEntries.forEach { a ->
|
||||||
|
a.typeReference?.run {
|
||||||
|
val fqName = FqName(this.text)
|
||||||
|
if (fqName in (NULLABLE_ANNOTATIONS + NOT_NULL_ANNOTATIONS)) a.delete()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
val newParameterList = function.valueParameterList!!.replace(patternFunction.valueParameterList!!) as KtParameterList
|
val newParameterList = function.valueParameterList!!.replace(patternFunction.valueParameterList!!) as KtParameterList
|
||||||
ShortenReferences.DEFAULT.process(newParameterList)
|
ShortenReferences.DEFAULT.process(newParameterList)
|
||||||
}
|
}
|
||||||
|
|||||||
+38
@@ -0,0 +1,38 @@
|
|||||||
|
// FILE: test.before.kt
|
||||||
|
// "Change function signature to 'fun foo(a: String, b: String?, c: String?)'" "true"
|
||||||
|
// ERROR: 'foo' overrides nothing
|
||||||
|
package foo
|
||||||
|
|
||||||
|
class KotlinClass : JavaClass() {
|
||||||
|
<caret>override fun foo() {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// FILE: foo/JavaClass.java
|
||||||
|
package foo;
|
||||||
|
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
public class JavaClass {
|
||||||
|
void foo(@NotNull String a,
|
||||||
|
@Nullable String b,
|
||||||
|
@JavaAnnotation String c) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// FILE: foo/JavaAnnotation.java
|
||||||
|
package foo;
|
||||||
|
|
||||||
|
public @interface JavaAnnotation {
|
||||||
|
}
|
||||||
|
|
||||||
|
// FILE: test.after.kt
|
||||||
|
// "Change function signature to 'fun foo(a: String, b: String?, c: String?)'" "true"
|
||||||
|
// ERROR: 'foo' overrides nothing
|
||||||
|
package foo
|
||||||
|
|
||||||
|
class KotlinClass : JavaClass() {
|
||||||
|
<caret>override fun foo(a: String, b: String?, @JavaAnnotation c: String?) {
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1855,6 +1855,12 @@ public class QuickFixMultiFileTestGenerated extends AbstractQuickFixMultiFileTes
|
|||||||
doTestWithExtraFile(fileName);
|
doTestWithExtraFile(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("overrideJavaMethodWithAnnotation.test")
|
||||||
|
public void testOverrideJavaMethodWithAnnotation() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/quickfix/override/nothingToOverride/overrideJavaMethodWithAnnotation.test");
|
||||||
|
doTestWithExtraFile(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("twoPackages.before.Main.kt")
|
@TestMetadata("twoPackages.before.Main.kt")
|
||||||
public void testTwoPackages() throws Exception {
|
public void testTwoPackages() throws Exception {
|
||||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/quickfix/override/nothingToOverride/twoPackages.before.Main.kt");
|
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/quickfix/override/nothingToOverride/twoPackages.before.Main.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user