Create from Usage: Do not suggest creating annotations/enum classes for unresolved type parameter bounds
#KT-13364 Fixed
This commit is contained in:
@@ -210,6 +210,7 @@ These artifacts include extensions for the types available in the latter JDKs, s
|
|||||||
- [`KT-13151`](https://youtrack.jetbrains.com/issue/KT-13151) Incorrect warning "Make variable immutable"
|
- [`KT-13151`](https://youtrack.jetbrains.com/issue/KT-13151) Incorrect warning "Make variable immutable"
|
||||||
- [`KT-13170`](https://youtrack.jetbrains.com/issue/KT-13170) "Declaration has platform type" inspection: by default should not be reported for platform type arguments
|
- [`KT-13170`](https://youtrack.jetbrains.com/issue/KT-13170) "Declaration has platform type" inspection: by default should not be reported for platform type arguments
|
||||||
- [`KT-13262`](https://youtrack.jetbrains.com/issue/KT-13262) "Wrap with safe let call" quickfix produces wrong result for qualified function
|
- [`KT-13262`](https://youtrack.jetbrains.com/issue/KT-13262) "Wrap with safe let call" quickfix produces wrong result for qualified function
|
||||||
|
- [`KT-13364`](https://youtrack.jetbrains.com/issue/KT-13364) Do not suggest creating annotations/enum classes for unresolved type parameter bounds
|
||||||
|
|
||||||
##### New features
|
##### New features
|
||||||
|
|
||||||
|
|||||||
+8
-6
@@ -20,10 +20,8 @@ import org.jetbrains.kotlin.diagnostics.Diagnostic
|
|||||||
import org.jetbrains.kotlin.idea.caches.resolve.analyzeAndGetResult
|
import org.jetbrains.kotlin.idea.caches.resolve.analyzeAndGetResult
|
||||||
import org.jetbrains.kotlin.idea.core.quickfix.QuickFixUtil
|
import org.jetbrains.kotlin.idea.core.quickfix.QuickFixUtil
|
||||||
import org.jetbrains.kotlin.idea.quickfix.createFromUsage.callableBuilder.TypeInfo
|
import org.jetbrains.kotlin.idea.quickfix.createFromUsage.callableBuilder.TypeInfo
|
||||||
import org.jetbrains.kotlin.psi.KtConstructorCalleeExpression
|
import org.jetbrains.kotlin.psi.*
|
||||||
import org.jetbrains.kotlin.psi.KtFile
|
import org.jetbrains.kotlin.psi.psiUtil.getParentOfTypeAndBranch
|
||||||
import org.jetbrains.kotlin.psi.KtSuperTypeEntry
|
|
||||||
import org.jetbrains.kotlin.psi.KtUserType
|
|
||||||
import org.jetbrains.kotlin.resolve.BindingContext
|
import org.jetbrains.kotlin.resolve.BindingContext
|
||||||
import org.jetbrains.kotlin.types.Variance
|
import org.jetbrains.kotlin.types.Variance
|
||||||
import java.util.*
|
import java.util.*
|
||||||
@@ -41,15 +39,19 @@ object CreateClassFromTypeReferenceActionFactory : CreateClassFromUsageFactory<K
|
|||||||
|
|
||||||
val isQualifier = (element.parent as? KtUserType)?.let { it.qualifier == element } ?: false
|
val isQualifier = (element.parent as? KtUserType)?.let { it.qualifier == element } ?: false
|
||||||
|
|
||||||
|
val typeReference = element.parent as? KtTypeReference
|
||||||
|
val isUpperBound = typeReference?.getParentOfTypeAndBranch<KtTypeParameter> { extendsBound } != null
|
||||||
|
|| typeReference?.getParentOfTypeAndBranch<KtTypeConstraint> { boundTypeReference } != null
|
||||||
|
|
||||||
return when {
|
return when {
|
||||||
interfaceExpected -> Collections.singletonList(ClassKind.INTERFACE)
|
interfaceExpected -> Collections.singletonList(ClassKind.INTERFACE)
|
||||||
else -> ClassKind.values().filter {
|
else -> ClassKind.values().filter {
|
||||||
val noTypeArguments = element.typeArgumentsAsTypes.isEmpty()
|
val noTypeArguments = element.typeArgumentsAsTypes.isEmpty()
|
||||||
when (it) {
|
when (it) {
|
||||||
ClassKind.OBJECT -> noTypeArguments && isQualifier
|
ClassKind.OBJECT -> noTypeArguments && isQualifier
|
||||||
ClassKind.ANNOTATION_CLASS -> noTypeArguments && !isQualifier
|
ClassKind.ANNOTATION_CLASS -> noTypeArguments && !isQualifier && !isUpperBound
|
||||||
ClassKind.ENUM_ENTRY -> false
|
ClassKind.ENUM_ENTRY -> false
|
||||||
ClassKind.ENUM_CLASS -> noTypeArguments
|
ClassKind.ENUM_CLASS -> noTypeArguments && !isUpperBound
|
||||||
else -> true
|
else -> true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Vendored
+6
@@ -0,0 +1,6 @@
|
|||||||
|
// "Create annotation 'NotExistent'" "false"
|
||||||
|
// ACTION: Create class 'NotExistent'
|
||||||
|
// ACTION: Create interface 'NotExistent'
|
||||||
|
// ACTION: Create test
|
||||||
|
// ERROR: Unresolved reference: NotExistent
|
||||||
|
class TPB<X : <caret>NotExistent>
|
||||||
Vendored
+6
@@ -0,0 +1,6 @@
|
|||||||
|
// "Create annotation 'NotExistent'" "false"
|
||||||
|
// ACTION: Create class 'NotExistent'
|
||||||
|
// ACTION: Create interface 'NotExistent'
|
||||||
|
// ACTION: Create test
|
||||||
|
// ERROR: Unresolved reference: NotExistent
|
||||||
|
class TPB<X> where X : <caret>NotExistent
|
||||||
+6
@@ -0,0 +1,6 @@
|
|||||||
|
// "Create enum 'NotExistent'" "false"
|
||||||
|
// ACTION: Create class 'NotExistent'
|
||||||
|
// ACTION: Create interface 'NotExistent'
|
||||||
|
// ACTION: Create test
|
||||||
|
// ERROR: Unresolved reference: NotExistent
|
||||||
|
class TPB<X : <caret>NotExistent>
|
||||||
Vendored
+6
@@ -0,0 +1,6 @@
|
|||||||
|
// "Create enum 'NotExistent'" "false"
|
||||||
|
// ACTION: Create class 'NotExistent'
|
||||||
|
// ACTION: Create interface 'NotExistent'
|
||||||
|
// ACTION: Create test
|
||||||
|
// ERROR: Unresolved reference: NotExistent
|
||||||
|
class TPB<X> where X : <caret>NotExistent
|
||||||
+6
@@ -0,0 +1,6 @@
|
|||||||
|
// "Create object 'NotExistent'" "false"
|
||||||
|
// ACTION: Create class 'NotExistent'
|
||||||
|
// ACTION: Create interface 'NotExistent'
|
||||||
|
// ACTION: Create test
|
||||||
|
// ERROR: Unresolved reference: NotExistent
|
||||||
|
class TPB<X : <caret>NotExistent>
|
||||||
Vendored
+6
@@ -0,0 +1,6 @@
|
|||||||
|
// "Create object 'NotExistent'" "false"
|
||||||
|
// ACTION: Create class 'NotExistent'
|
||||||
|
// ACTION: Create interface 'NotExistent'
|
||||||
|
// ACTION: Create test
|
||||||
|
// ERROR: Unresolved reference: NotExistent
|
||||||
|
class TPB<X> where X : <caret>NotExistent
|
||||||
@@ -1815,6 +1815,42 @@ public class QuickFixTestGenerated extends AbstractQuickFixTest {
|
|||||||
doTest(fileName);
|
doTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("noAnnotationForTypeBound.kt")
|
||||||
|
public void testNoAnnotationForTypeBound() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/quickfix/createFromUsage/createClass/typeReference/noAnnotationForTypeBound.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("noAnnotationForTypeConstraint.kt")
|
||||||
|
public void testNoAnnotationForTypeConstraint() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/quickfix/createFromUsage/createClass/typeReference/noAnnotationForTypeConstraint.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("noEnumForTypeBound.kt")
|
||||||
|
public void testNoEnumForTypeBound() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/quickfix/createFromUsage/createClass/typeReference/noEnumForTypeBound.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("noEnumForTypeConstraint.kt")
|
||||||
|
public void testNoEnumForTypeConstraint() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/quickfix/createFromUsage/createClass/typeReference/noEnumForTypeConstraint.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("noObjectForTypeBound.kt")
|
||||||
|
public void testNoObjectForTypeBound() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/quickfix/createFromUsage/createClass/typeReference/noObjectForTypeBound.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("noObjectForTypeConstraint.kt")
|
||||||
|
public void testNoObjectForTypeConstraint() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/quickfix/createFromUsage/createClass/typeReference/noObjectForTypeConstraint.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("objectNotQualifierNoTypeArgs.kt")
|
@TestMetadata("objectNotQualifierNoTypeArgs.kt")
|
||||||
public void testObjectNotQualifierNoTypeArgs() throws Exception {
|
public void testObjectNotQualifierNoTypeArgs() throws Exception {
|
||||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/quickfix/createFromUsage/createClass/typeReference/objectNotQualifierNoTypeArgs.kt");
|
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/quickfix/createFromUsage/createClass/typeReference/objectNotQualifierNoTypeArgs.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user