Disable extract actions on non-JVM classes #KT-28476 Fixed
This commit is contained in:
+2
@@ -25,6 +25,8 @@ object KotlinExtractInterfaceHandler : KotlinExtractSuperHandlerBase(true) {
|
||||
val REFACTORING_NAME = "Extract Interface"
|
||||
|
||||
override fun getErrorMessage(klass: KtClassOrObject): String? {
|
||||
val superMessage = super.getErrorMessage(klass)
|
||||
if (superMessage != null) return superMessage
|
||||
if (klass is KtClass && klass.isAnnotation()) return "Interface cannot be extracted from an annotation class"
|
||||
return null
|
||||
}
|
||||
|
||||
+7
-1
@@ -30,11 +30,13 @@ import com.intellij.refactoring.RefactoringBundle
|
||||
import com.intellij.refactoring.extractSuperclass.ExtractSuperClassUtil
|
||||
import com.intellij.refactoring.lang.ElementsHandler
|
||||
import com.intellij.refactoring.util.CommonRefactoringUtil
|
||||
import org.jetbrains.kotlin.asJava.toLightClass
|
||||
import org.jetbrains.kotlin.idea.refactoring.SeparateFileWrapper
|
||||
import org.jetbrains.kotlin.idea.refactoring.chooseContainerElementIfNecessary
|
||||
import org.jetbrains.kotlin.idea.refactoring.getExtractionContainers
|
||||
import org.jetbrains.kotlin.idea.refactoring.introduce.extractClass.ui.KotlinExtractSuperDialogBase
|
||||
import org.jetbrains.kotlin.idea.refactoring.showWithTransaction
|
||||
import org.jetbrains.kotlin.idea.util.isExpectDeclaration
|
||||
import org.jetbrains.kotlin.psi.KtClassOrObject
|
||||
import org.jetbrains.kotlin.psi.KtFile
|
||||
import org.jetbrains.kotlin.psi.psiUtil.getNonStrictParentOfType
|
||||
@@ -108,7 +110,11 @@ abstract class KotlinExtractSuperHandlerBase(private val isExtractInterface: Boo
|
||||
return ExtractSuperClassUtil.showConflicts(dialog, conflicts, originalClass.project)
|
||||
}
|
||||
|
||||
internal abstract fun getErrorMessage(klass: KtClassOrObject): String?
|
||||
internal open fun getErrorMessage(klass: KtClassOrObject): String? = when {
|
||||
klass.isExpectDeclaration() -> "Extraction from expect class is not yet supported"
|
||||
klass.toLightClass() == null -> "Extraction from non-JVM class is not yet supported"
|
||||
else -> null
|
||||
}
|
||||
|
||||
protected abstract fun createDialog(klass: KtClassOrObject, targetParent: PsiElement): KotlinExtractSuperDialogBase
|
||||
}
|
||||
+2
@@ -26,6 +26,8 @@ object KotlinExtractSuperclassHandler : KotlinExtractSuperHandlerBase(false) {
|
||||
val REFACTORING_NAME = "Extract Superclass"
|
||||
|
||||
override fun getErrorMessage(klass: KtClassOrObject): String? {
|
||||
val superMessage = super.getErrorMessage(klass)
|
||||
if (superMessage != null) return superMessage
|
||||
if (klass is KtClass) {
|
||||
if (klass.isInterface()) return RefactoringBundle.message("superclass.cannot.be.extracted.from.an.interface")
|
||||
if (klass.isEnum()) return RefactoringBundle.message("superclass.cannot.be.extracted.from.an.enum")
|
||||
|
||||
Reference in New Issue
Block a user