diff --git a/idea/src/org/jetbrains/kotlin/idea/quickfix/AddTypeAnnotationToValueParameterFix.kt b/idea/src/org/jetbrains/kotlin/idea/quickfix/AddTypeAnnotationToValueParameterFix.kt index bd13c839118..df1a5a14562 100644 --- a/idea/src/org/jetbrains/kotlin/idea/quickfix/AddTypeAnnotationToValueParameterFix.kt +++ b/idea/src/org/jetbrains/kotlin/idea/quickfix/AddTypeAnnotationToValueParameterFix.kt @@ -41,9 +41,12 @@ class AddTypeAnnotationToValueParameterFix(element: KtParameter) : KotlinQuickFi init { val defaultValue = element.defaultValue var type = defaultValue?.getType(defaultValue.analyze(BodyResolveMode.PARTIAL)) - if (type != null && KotlinBuiltIns.isArray(type)) { + if (type != null && KotlinBuiltIns.isArrayOrPrimitiveArray(type)) { if (element.hasModifier(KtTokens.VARARG_KEYWORD)) { - type = type.arguments.singleOrNull()?.type + type = if (KotlinBuiltIns.isPrimitiveArray(type)) + element.builtIns.getArrayElementType(type) + else + type.arguments.singleOrNull()?.type } else if (defaultValue is KtCollectionLiteralExpression) { val builtIns = element.builtIns diff --git a/idea/testData/quickfix/addTypeAnnotationToValueParameter/annotationWithVarargDoubleArray.kt b/idea/testData/quickfix/addTypeAnnotationToValueParameter/annotationWithVarargDoubleArray.kt new file mode 100644 index 00000000000..d2274c2dcde --- /dev/null +++ b/idea/testData/quickfix/addTypeAnnotationToValueParameter/annotationWithVarargDoubleArray.kt @@ -0,0 +1,3 @@ +// "Add type 'Double' to parameter 'value'" "true" + +class CollectionDefault(vararg val value = doubleArrayOf(1.0, 2.2)) \ No newline at end of file diff --git a/idea/testData/quickfix/addTypeAnnotationToValueParameter/annotationWithVarargDoubleArray.kt.after b/idea/testData/quickfix/addTypeAnnotationToValueParameter/annotationWithVarargDoubleArray.kt.after new file mode 100644 index 00000000000..13c7ecfe564 --- /dev/null +++ b/idea/testData/quickfix/addTypeAnnotationToValueParameter/annotationWithVarargDoubleArray.kt.after @@ -0,0 +1,3 @@ +// "Add type 'Double' to parameter 'value'" "true" + +class CollectionDefault(vararg val value: Double = doubleArrayOf(1.0, 2.2)) \ No newline at end of file diff --git a/idea/testData/quickfix/addTypeAnnotationToValueParameter/annotationWithVarargIntArray.kt b/idea/testData/quickfix/addTypeAnnotationToValueParameter/annotationWithVarargIntArray.kt new file mode 100644 index 00000000000..53a9fd09f0c --- /dev/null +++ b/idea/testData/quickfix/addTypeAnnotationToValueParameter/annotationWithVarargIntArray.kt @@ -0,0 +1,3 @@ +// "Add type 'Int' to parameter 'value'" "true" + +class CollectionDefault(vararg val value = intArrayOf(1, 2)) \ No newline at end of file diff --git a/idea/testData/quickfix/addTypeAnnotationToValueParameter/annotationWithVarargIntArray.kt.after b/idea/testData/quickfix/addTypeAnnotationToValueParameter/annotationWithVarargIntArray.kt.after new file mode 100644 index 00000000000..68729f77bea --- /dev/null +++ b/idea/testData/quickfix/addTypeAnnotationToValueParameter/annotationWithVarargIntArray.kt.after @@ -0,0 +1,3 @@ +// "Add type 'Int' to parameter 'value'" "true" + +class CollectionDefault(vararg val value: Int = intArrayOf(1, 2)) \ No newline at end of file diff --git a/idea/tests/org/jetbrains/kotlin/idea/quickfix/QuickFixTestGenerated.java b/idea/tests/org/jetbrains/kotlin/idea/quickfix/QuickFixTestGenerated.java index bb6ecafe0c7..db35ea22383 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/quickfix/QuickFixTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/idea/quickfix/QuickFixTestGenerated.java @@ -1043,6 +1043,18 @@ public class QuickFixTestGenerated extends AbstractQuickFixTest { doTest(fileName); } + @TestMetadata("annotationWithVarargDoubleArray.kt") + public void testAnnotationWithVarargDoubleArray() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("idea/testData/quickfix/addTypeAnnotationToValueParameter/annotationWithVarargDoubleArray.kt"); + doTest(fileName); + } + + @TestMetadata("annotationWithVarargIntArray.kt") + public void testAnnotationWithVarargIntArray() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("idea/testData/quickfix/addTypeAnnotationToValueParameter/annotationWithVarargIntArray.kt"); + doTest(fileName); + } + @TestMetadata("noDefaultValue.kt") public void testNoDefaultValue() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("idea/testData/quickfix/addTypeAnnotationToValueParameter/noDefaultValue.kt");