Create from Usage: Do not suggest creating annotations/enum classes for unresolved type parameter bounds
#KT-13364 Fixed
This commit is contained in:
+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.core.quickfix.QuickFixUtil
|
||||
import org.jetbrains.kotlin.idea.quickfix.createFromUsage.callableBuilder.TypeInfo
|
||||
import org.jetbrains.kotlin.psi.KtConstructorCalleeExpression
|
||||
import org.jetbrains.kotlin.psi.KtFile
|
||||
import org.jetbrains.kotlin.psi.KtSuperTypeEntry
|
||||
import org.jetbrains.kotlin.psi.KtUserType
|
||||
import org.jetbrains.kotlin.psi.*
|
||||
import org.jetbrains.kotlin.psi.psiUtil.getParentOfTypeAndBranch
|
||||
import org.jetbrains.kotlin.resolve.BindingContext
|
||||
import org.jetbrains.kotlin.types.Variance
|
||||
import java.util.*
|
||||
@@ -41,15 +39,19 @@ object CreateClassFromTypeReferenceActionFactory : CreateClassFromUsageFactory<K
|
||||
|
||||
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 {
|
||||
interfaceExpected -> Collections.singletonList(ClassKind.INTERFACE)
|
||||
else -> ClassKind.values().filter {
|
||||
val noTypeArguments = element.typeArgumentsAsTypes.isEmpty()
|
||||
when (it) {
|
||||
ClassKind.OBJECT -> noTypeArguments && isQualifier
|
||||
ClassKind.ANNOTATION_CLASS -> noTypeArguments && !isQualifier
|
||||
ClassKind.ANNOTATION_CLASS -> noTypeArguments && !isQualifier && !isUpperBound
|
||||
ClassKind.ENUM_ENTRY -> false
|
||||
ClassKind.ENUM_CLASS -> noTypeArguments
|
||||
ClassKind.ENUM_CLASS -> noTypeArguments && !isUpperBound
|
||||
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);
|
||||
}
|
||||
|
||||
@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")
|
||||
public void testObjectNotQualifierNoTypeArgs() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/quickfix/createFromUsage/createClass/typeReference/objectNotQualifierNoTypeArgs.kt");
|
||||
|
||||
Reference in New Issue
Block a user