Create from Usage: Do not suggest creating annotations/enum classes for unresolved type parameter bounds

#KT-13364 Fixed
This commit is contained in:
Alexey Sedunov
2016-08-08 14:54:25 +03:00
parent 1b546d18ff
commit 6e3d1d726e
9 changed files with 81 additions and 6 deletions
+1
View File
@@ -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-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-13364`](https://youtrack.jetbrains.com/issue/KT-13364) Do not suggest creating annotations/enum classes for unresolved type parameter bounds
##### New features
@@ -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
}
}
@@ -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>
@@ -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
@@ -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>
@@ -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
@@ -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>
@@ -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");