From ea7bf6b7c1e1abecf8650878d936e047ae197fee Mon Sep 17 00:00:00 2001 From: Alexey Sedunov Date: Thu, 12 Jan 2017 18:33:09 +0300 Subject: [PATCH] Extract Interface: Red-highlight members inherited from a super-interface when that interface reference itself is not extracted #KT-15598 Fixed --- ChangeLog.md | 1 + .../ui/KotlinExtractInterfaceDialog.kt | 22 +++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/ChangeLog.md b/ChangeLog.md index 843237a0d53..18b78ceffc4 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -483,6 +483,7 @@ These artifacts include extensions for the types available in the latter JDKs, s - [`KT-15639`](https://youtrack.jetbrains.com/issue/KT-15639) Extract Superclass/Interface/Pull Up: Add spaces between 'abstract' modifier and annotations - [`KT-15606`](https://youtrack.jetbrains.com/issue/KT-15606) Extract Interface/Pull Up: Warn about private members with usages in the original class - [`KT-15635`](https://youtrack.jetbrains.com/issue/KT-15635) Extract Superclass/Interface: Fix bogus visibility warning inside a member when it's being moved as abstract +- [`KT-15598`](https://youtrack.jetbrains.com/issue/KT-15598) Extract Interface: Red-highlight members inherited from a super-interface when that interface reference itself is not extracted #### Intention actions, inspections and quickfixes diff --git a/idea/src/org/jetbrains/kotlin/idea/refactoring/introduce/extractClass/ui/KotlinExtractInterfaceDialog.kt b/idea/src/org/jetbrains/kotlin/idea/refactoring/introduce/extractClass/ui/KotlinExtractInterfaceDialog.kt index 7a19995a04f..20ef61f6b83 100644 --- a/idea/src/org/jetbrains/kotlin/idea/refactoring/introduce/extractClass/ui/KotlinExtractInterfaceDialog.kt +++ b/idea/src/org/jetbrains/kotlin/idea/refactoring/introduce/extractClass/ui/KotlinExtractInterfaceDialog.kt @@ -16,15 +16,19 @@ package org.jetbrains.kotlin.idea.refactoring.introduce.extractClass.ui +import com.intellij.psi.PsiClass import com.intellij.psi.PsiElement +import com.intellij.psi.PsiMethod import com.intellij.refactoring.HelpID import com.intellij.refactoring.JavaRefactoringSettings import com.intellij.refactoring.RefactoringBundle +import com.intellij.refactoring.classMembers.MemberInfoModel import org.jetbrains.kotlin.idea.refactoring.introduce.extractClass.ExtractSuperInfo import org.jetbrains.kotlin.idea.refactoring.introduce.extractClass.KotlinExtractInterfaceHandler import org.jetbrains.kotlin.idea.refactoring.isConstructorDeclaredProperty import org.jetbrains.kotlin.idea.refactoring.memberInfo.KotlinMemberInfo import org.jetbrains.kotlin.idea.refactoring.memberInfo.extractClassMembers +import org.jetbrains.kotlin.idea.refactoring.memberInfo.lightElementForMemberInfo import org.jetbrains.kotlin.idea.refactoring.pullUp.getInterfaceContainmentVerifier import org.jetbrains.kotlin.idea.refactoring.pullUp.isAbstractInInterface import org.jetbrains.kotlin.idea.refactoring.pullUp.mustBeAbstractInInterface @@ -79,6 +83,24 @@ class KotlinExtractInterfaceDialog( val member = memberInfo.member return member is KtProperty || member.isAbstractInInterface(originalClass) || member.isConstructorDeclaredProperty() } + + override fun checkForProblems(memberInfo: KotlinMemberInfo): Int { + val result = super.checkForProblems(memberInfo) + if (result != MemberInfoModel.OK) return result + + if (!memberInfo.isSuperClass || memberInfo.overrides != false || memberInfo.isChecked) return result + + val psiSuperInterface = lightElementForMemberInfo(memberInfo.member) as? PsiClass ?: return result + + for (info in memberInfos) { + if (!info.isChecked || info.isToAbstract) continue + val member = info.member ?: continue + val psiMethodToCheck = lightElementForMemberInfo(member) as? PsiMethod ?: continue + if (psiSuperInterface.findMethodBySignature(psiMethodToCheck, true) != null) return MemberInfoModel.ERROR + } + + return result + } } }