KT-15176 Remove "Create type alias" intention when called on java class
This commit is contained in:
committed by
asedunov
parent
44920f42d8
commit
2a10d8e837
+3
@@ -16,6 +16,8 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.idea.quickfix.createFromUsage.createTypeAlias
|
package org.jetbrains.kotlin.idea.quickfix.createFromUsage.createTypeAlias
|
||||||
|
|
||||||
|
import com.intellij.lang.java.JavaLanguage
|
||||||
|
import com.intellij.psi.PsiClass
|
||||||
import com.intellij.psi.PsiPackage
|
import com.intellij.psi.PsiPackage
|
||||||
import org.jetbrains.kotlin.config.LanguageFeature
|
import org.jetbrains.kotlin.config.LanguageFeature
|
||||||
import org.jetbrains.kotlin.diagnostics.Diagnostic
|
import org.jetbrains.kotlin.diagnostics.Diagnostic
|
||||||
@@ -41,6 +43,7 @@ object CreateTypeAliasFromTypeReferenceActionFactory : KotlinSingleIntentionActi
|
|||||||
|
|
||||||
val classInfo = CreateClassFromTypeReferenceActionFactory.extractFixData(element, diagnostic) ?: return null
|
val classInfo = CreateClassFromTypeReferenceActionFactory.extractFixData(element, diagnostic) ?: return null
|
||||||
val targetParent = classInfo.applicableParents.singleOrNull { it !is KtDeclaration && it !is PsiPackage } ?: return null
|
val targetParent = classInfo.applicableParents.singleOrNull { it !is KtDeclaration && it !is PsiPackage } ?: return null
|
||||||
|
if ((targetParent as? PsiClass)?.language == JavaLanguage.INSTANCE) return null
|
||||||
|
|
||||||
val expectedType = getTypeConstraintInfo(element)?.upperBound
|
val expectedType = getTypeConstraintInfo(element)?.upperBound
|
||||||
if (expectedType != null && expectedType.containsError()) return null
|
if (expectedType != null && expectedType.containsError()) return null
|
||||||
|
|||||||
Vendored
+19
@@ -0,0 +1,19 @@
|
|||||||
|
// FILE: foo/test.before.kt
|
||||||
|
// "Create type alias 'A'" "false"
|
||||||
|
// ACTION: Convert to block body
|
||||||
|
// ACTION: Create annotation 'A'
|
||||||
|
// ACTION: Create class 'A'
|
||||||
|
// ACTION: Create enum 'A'
|
||||||
|
// ACTION: Create interface 'A'
|
||||||
|
// ACTION: Remove explicit type specification
|
||||||
|
// ERROR: Unresolved reference: A
|
||||||
|
package foo
|
||||||
|
|
||||||
|
fun foo(): JavaClass.<caret>A = throw Throwable("")
|
||||||
|
|
||||||
|
|
||||||
|
// FILE: foo/JavaClass.java
|
||||||
|
package foo;
|
||||||
|
|
||||||
|
public class JavaClass {
|
||||||
|
}
|
||||||
+15
@@ -1408,6 +1408,21 @@ public class QuickFixMultiFileTestGenerated extends AbstractQuickFixMultiFileTes
|
|||||||
public void testAllFilesPresentInCreateTypeAlias() throws Exception {
|
public void testAllFilesPresentInCreateTypeAlias() throws Exception {
|
||||||
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/quickfix/createFromUsage/createTypeAlias"), Pattern.compile("^(\\w+)\\.((before\\.Main\\.\\w+)|(test))$"), TargetBackend.ANY, true);
|
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/quickfix/createFromUsage/createTypeAlias"), Pattern.compile("^(\\w+)\\.((before\\.Main\\.\\w+)|(test))$"), TargetBackend.ANY, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("idea/testData/quickfix/createFromUsage/createTypeAlias/typeReference")
|
||||||
|
@TestDataPath("$PROJECT_ROOT")
|
||||||
|
@RunWith(JUnit3RunnerWithInners.class)
|
||||||
|
public static class TypeReference extends AbstractQuickFixMultiFileTest {
|
||||||
|
public void testAllFilesPresentInTypeReference() throws Exception {
|
||||||
|
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/quickfix/createFromUsage/createTypeAlias/typeReference"), Pattern.compile("^(\\w+)\\.((before\\.Main\\.\\w+)|(test))$"), TargetBackend.ANY, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("javaUserTypeReceiver.test")
|
||||||
|
public void testJavaUserTypeReceiver() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/quickfix/createFromUsage/createTypeAlias/typeReference/javaUserTypeReceiver.test");
|
||||||
|
doTestWithExtraFile(fileName);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@TestMetadata("idea/testData/quickfix/createFromUsage/createTypeParameter")
|
@TestMetadata("idea/testData/quickfix/createFromUsage/createTypeParameter")
|
||||||
|
|||||||
Reference in New Issue
Block a user