"Wrap element with arrayOf() call": don't suggest for annotation parameters
#KT-28969 Fixed
This commit is contained in:
committed by
Mikhail Glukhikh
parent
41b6bcf8c3
commit
53b0aa5813
@@ -9,11 +9,9 @@ import com.intellij.openapi.editor.Editor
|
||||
import com.intellij.openapi.project.Project
|
||||
import org.jetbrains.kotlin.idea.core.replaced
|
||||
import org.jetbrains.kotlin.idea.intentions.branchedTransformations.isNullExpression
|
||||
import org.jetbrains.kotlin.psi.KtExpression
|
||||
import org.jetbrains.kotlin.psi.KtFile
|
||||
import org.jetbrains.kotlin.psi.KtPsiFactory
|
||||
import org.jetbrains.kotlin.psi.createExpressionByPattern
|
||||
import org.jetbrains.kotlin.psi.*
|
||||
import org.jetbrains.kotlin.psi.psiUtil.endOffset
|
||||
import org.jetbrains.kotlin.psi.psiUtil.getStrictParentOfType
|
||||
import org.jetbrains.kotlin.types.KotlinType
|
||||
import org.jetbrains.kotlin.types.Variance
|
||||
import org.jetbrains.kotlin.types.typeUtil.isSubtypeOf
|
||||
@@ -46,6 +44,8 @@ class WrapWithCollectionLiteralCallFix private constructor(
|
||||
|
||||
companion object {
|
||||
fun create(expectedType: KotlinType, expressionType: KotlinType, element: KtExpression): List<WrapWithCollectionLiteralCallFix> {
|
||||
if (element.getStrictParentOfType<KtAnnotationEntry>() != null) return emptyList()
|
||||
|
||||
val collectionType =
|
||||
with(ConvertCollectionFix) {
|
||||
expectedType.getCollectionType(acceptNullableTypes = true)
|
||||
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
// "Wrap element with 'arrayOf' call" "false"
|
||||
// ERROR: Type mismatch: inferred type is String but Array<String> was expected
|
||||
// ACTION: Add arrayOf wrapper
|
||||
// ACTION: Change parameter 'value' type of primary constructor of class 'Foo' to 'String'
|
||||
// ACTION: Create test
|
||||
// ACTION: Make internal
|
||||
// ACTION: Make private
|
||||
// ACTION: To raw string literal
|
||||
// ACTION: Wrap with []
|
||||
|
||||
annotation class Foo(val value: Array<String>)
|
||||
|
||||
@Foo(value = "abc"<caret>)
|
||||
class Bar
|
||||
@@ -12810,6 +12810,11 @@ public class QuickFixTestGenerated extends AbstractQuickFixTest {
|
||||
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/quickfix/typeMismatch/wrapWithCollectionLiteral"), Pattern.compile("^([\\w\\-_]+)\\.kt$"), TargetBackend.ANY, true);
|
||||
}
|
||||
|
||||
@TestMetadata("inAnnotation.kt")
|
||||
public void testInAnnotation() throws Exception {
|
||||
runTest("idea/testData/quickfix/typeMismatch/wrapWithCollectionLiteral/inAnnotation.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("noMutableList.kt")
|
||||
public void testNoMutableList() throws Exception {
|
||||
runTest("idea/testData/quickfix/typeMismatch/wrapWithCollectionLiteral/noMutableList.kt");
|
||||
|
||||
Reference in New Issue
Block a user