Refactoring & fix warnings
This commit is contained in:
+7
-16
@@ -27,7 +27,6 @@ import com.intellij.psi.PsiNamedElement
|
|||||||
import com.intellij.psi.PsiReference
|
import com.intellij.psi.PsiReference
|
||||||
import com.intellij.psi.search.searches.ReferencesSearch
|
import com.intellij.psi.search.searches.ReferencesSearch
|
||||||
import com.intellij.util.containers.MultiMap
|
import com.intellij.util.containers.MultiMap
|
||||||
import org.jetbrains.kotlin.asJava.namedUnwrappedElement
|
|
||||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
||||||
import org.jetbrains.kotlin.descriptors.CallableDescriptor
|
import org.jetbrains.kotlin.descriptors.CallableDescriptor
|
||||||
import org.jetbrains.kotlin.descriptors.FunctionDescriptor
|
import org.jetbrains.kotlin.descriptors.FunctionDescriptor
|
||||||
@@ -59,7 +58,8 @@ import org.jetbrains.kotlin.types.isError
|
|||||||
import org.jetbrains.kotlin.types.typeUtil.supertypes
|
import org.jetbrains.kotlin.types.typeUtil.supertypes
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
class ConvertFunctionToPropertyIntention : SelfTargetingIntention<KtNamedFunction>(KtNamedFunction::class.java, "Convert function to property"), LowPriorityAction {
|
class ConvertFunctionToPropertyIntention :
|
||||||
|
SelfTargetingIntention<KtNamedFunction>(KtNamedFunction::class.java, "Convert function to property"), LowPriorityAction {
|
||||||
private var KtNamedFunction.typeFqNameToAdd: String? by UserDataProperty(Key.create("TYPE_FQ_NAME_TO_ADD"))
|
private var KtNamedFunction.typeFqNameToAdd: String? by UserDataProperty(Key.create("TYPE_FQ_NAME_TO_ADD"))
|
||||||
|
|
||||||
private inner class Converter(
|
private inner class Converter(
|
||||||
@@ -86,8 +86,7 @@ class ConvertFunctionToPropertyIntention : SelfTargetingIntention<KtNamedFunctio
|
|||||||
|
|
||||||
if (originalFunction.equalsToken != null) {
|
if (originalFunction.equalsToken != null) {
|
||||||
getterExpression(originalFunction.bodyExpression!!.text, breakLine = originalFunction.typeReference != null)
|
getterExpression(originalFunction.bodyExpression!!.text, breakLine = originalFunction.typeReference != null)
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
originalFunction.bodyBlockExpression?.let { body ->
|
originalFunction.bodyBlockExpression?.let { body ->
|
||||||
transform {
|
transform {
|
||||||
append("\nget() ")
|
append("\nget() ")
|
||||||
@@ -131,16 +130,10 @@ class ConvertFunctionToPropertyIntention : SelfTargetingIntention<KtNamedFunctio
|
|||||||
callableDescriptor.getContainingScope()
|
callableDescriptor.getContainingScope()
|
||||||
?.findVariable(callableDescriptor.name, NoLookupLocation.FROM_IDE)
|
?.findVariable(callableDescriptor.name, NoLookupLocation.FROM_IDE)
|
||||||
?.let { DescriptorToSourceUtilsIde.getAnyDeclaration(project, it) }
|
?.let { DescriptorToSourceUtilsIde.getAnyDeclaration(project, it) }
|
||||||
?.let { reportDeclarationConflict(conflicts, it) { "$it already exists" } }
|
?.let { reportDeclarationConflict(conflicts, it) { s -> "$s already exists" } }
|
||||||
}
|
}
|
||||||
|
|
||||||
if (callable is PsiMethod) {
|
if (callable is PsiMethod) callable.checkDeclarationConflict(getterName, conflicts, callables)
|
||||||
callable.containingClass
|
|
||||||
?.findMethodsByName(getterName, true)
|
|
||||||
// as is necessary here: see KT-10386
|
|
||||||
?.firstOrNull { it.parameterList.parametersCount == 0 && !callables.contains(it.namedUnwrappedElement as PsiElement?) }
|
|
||||||
?.let { reportDeclarationConflict(conflicts, it) { "$it already exists" } }
|
|
||||||
}
|
|
||||||
|
|
||||||
val usages = ReferencesSearch.search(callable)
|
val usages = ReferencesSearch.search(callable)
|
||||||
for (usage in usages) {
|
for (usage in usages) {
|
||||||
@@ -164,12 +157,10 @@ class ConvertFunctionToPropertyIntention : SelfTargetingIntention<KtNamedFunctio
|
|||||||
}
|
}
|
||||||
|
|
||||||
kotlinCalls.add(callElement)
|
kotlinCalls.add(callElement)
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
kotlinRefsToRename.add(usage)
|
kotlinRefsToRename.add(usage)
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
foreignRefs.add(usage)
|
foreignRefs.add(usage)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+11
-19
@@ -25,7 +25,6 @@ import com.intellij.psi.*
|
|||||||
import com.intellij.psi.search.searches.ReferencesSearch
|
import com.intellij.psi.search.searches.ReferencesSearch
|
||||||
import com.intellij.refactoring.util.RefactoringUIUtil
|
import com.intellij.refactoring.util.RefactoringUIUtil
|
||||||
import com.intellij.util.containers.MultiMap
|
import com.intellij.util.containers.MultiMap
|
||||||
import org.jetbrains.kotlin.asJava.namedUnwrappedElement
|
|
||||||
import org.jetbrains.kotlin.descriptors.CallableDescriptor
|
import org.jetbrains.kotlin.descriptors.CallableDescriptor
|
||||||
import org.jetbrains.kotlin.idea.caches.resolve.analyze
|
import org.jetbrains.kotlin.idea.caches.resolve.analyze
|
||||||
import org.jetbrains.kotlin.idea.caches.resolve.resolveToDescriptorIfAny
|
import org.jetbrains.kotlin.idea.caches.resolve.resolveToDescriptorIfAny
|
||||||
@@ -51,11 +50,12 @@ import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode
|
|||||||
import org.jetbrains.kotlin.resolve.scopes.utils.findFunction
|
import org.jetbrains.kotlin.resolve.scopes.utils.findFunction
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
class ConvertPropertyToFunctionIntention : SelfTargetingIntention<KtProperty>(KtProperty::class.java, "Convert property to function"), LowPriorityAction {
|
class ConvertPropertyToFunctionIntention : SelfTargetingIntention<KtProperty>(KtProperty::class.java, "Convert property to function"),
|
||||||
|
LowPriorityAction {
|
||||||
private inner class Converter(
|
private inner class Converter(
|
||||||
project: Project,
|
project: Project,
|
||||||
descriptor: CallableDescriptor
|
descriptor: CallableDescriptor
|
||||||
): CallableRefactoring<CallableDescriptor>(project, descriptor, text) {
|
) : CallableRefactoring<CallableDescriptor>(project, descriptor, text) {
|
||||||
private val newName: String = JvmAbi.getterName(callableDescriptor.name.asString())
|
private val newName: String = JvmAbi.getterName(callableDescriptor.name.asString())
|
||||||
|
|
||||||
private fun convertProperty(originalProperty: KtProperty, psiFactory: KtPsiFactory) {
|
private fun convertProperty(originalProperty: KtProperty, psiFactory: KtPsiFactory) {
|
||||||
@@ -97,9 +97,9 @@ class ConvertPropertyToFunctionIntention : SelfTargetingIntention<KtProperty>(Kt
|
|||||||
|
|
||||||
project.runSynchronouslyWithProgress("Looking for usages and conflicts...", true) {
|
project.runSynchronouslyWithProgress("Looking for usages and conflicts...", true) {
|
||||||
runReadAction {
|
runReadAction {
|
||||||
val progressStep = 1.0/callables.size
|
val progressStep = 1.0 / callables.size
|
||||||
for ((i, callable) in callables.withIndex()) {
|
for ((i, callable) in callables.withIndex()) {
|
||||||
ProgressManager.getInstance().progressIndicatorNullable!!.fraction = (i + 1)*progressStep
|
ProgressManager.getInstance().progressIndicatorNullable!!.fraction = (i + 1) * progressStep
|
||||||
|
|
||||||
if (callable !is PsiNamedElement) continue
|
if (callable !is PsiNamedElement) continue
|
||||||
|
|
||||||
@@ -112,15 +112,8 @@ class ConvertPropertyToFunctionIntention : SelfTargetingIntention<KtProperty>(Kt
|
|||||||
callableDescriptor.getContainingScope()
|
callableDescriptor.getContainingScope()
|
||||||
?.findFunction(callableDescriptor.name, NoLookupLocation.FROM_IDE) { it.valueParameters.isEmpty() }
|
?.findFunction(callableDescriptor.name, NoLookupLocation.FROM_IDE) { it.valueParameters.isEmpty() }
|
||||||
?.let { DescriptorToSourceUtilsIde.getAnyDeclaration(project, it) }
|
?.let { DescriptorToSourceUtilsIde.getAnyDeclaration(project, it) }
|
||||||
?.let { reportDeclarationConflict(conflicts, it) { "$it already exists" } }
|
?.let { reportDeclarationConflict(conflicts, it) { s -> "$s already exists" } }
|
||||||
}
|
} else if (callable is PsiMethod) callable.checkDeclarationConflict(propertyName, conflicts, callables)
|
||||||
else if (callable is PsiMethod) {
|
|
||||||
callable.containingClass
|
|
||||||
?.findMethodsByName(propertyName, true)
|
|
||||||
// as is necessary here: see KT-10386
|
|
||||||
?.firstOrNull { it.parameterList.parametersCount == 0 && !callables.contains(it.namedUnwrappedElement as PsiElement?) }
|
|
||||||
?.let { reportDeclarationConflict(conflicts, it) { "$it already exists" } }
|
|
||||||
}
|
|
||||||
|
|
||||||
val usages = ReferencesSearch.search(callable)
|
val usages = ReferencesSearch.search(callable)
|
||||||
for (usage in usages) {
|
for (usage in usages) {
|
||||||
@@ -128,14 +121,13 @@ class ConvertPropertyToFunctionIntention : SelfTargetingIntention<KtProperty>(Kt
|
|||||||
if (usage is KtSimpleNameReference) {
|
if (usage is KtSimpleNameReference) {
|
||||||
val expression = usage.expression
|
val expression = usage.expression
|
||||||
if (expression.getCall(expression.analyze(BodyResolveMode.PARTIAL)) != null
|
if (expression.getCall(expression.analyze(BodyResolveMode.PARTIAL)) != null
|
||||||
&& expression.getStrictParentOfType<KtCallableReferenceExpression>() == null) {
|
&& expression.getStrictParentOfType<KtCallableReferenceExpression>() == null
|
||||||
|
) {
|
||||||
kotlinRefsToReplaceWithCall.add(expression)
|
kotlinRefsToReplaceWithCall.add(expression)
|
||||||
}
|
} else if (nameChanged) {
|
||||||
else if (nameChanged) {
|
|
||||||
refsToRename.add(usage)
|
refsToRename.add(usage)
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
val refElement = usage.element
|
val refElement = usage.element
|
||||||
conflicts.putValue(
|
conflicts.putValue(
|
||||||
refElement,
|
refElement,
|
||||||
|
|||||||
@@ -28,7 +28,10 @@ import com.intellij.openapi.project.Project
|
|||||||
import com.intellij.openapi.roots.JavaProjectRootsUtil
|
import com.intellij.openapi.roots.JavaProjectRootsUtil
|
||||||
import com.intellij.openapi.ui.DialogWrapper
|
import com.intellij.openapi.ui.DialogWrapper
|
||||||
import com.intellij.openapi.ui.Messages
|
import com.intellij.openapi.ui.Messages
|
||||||
import com.intellij.openapi.ui.popup.*
|
import com.intellij.openapi.ui.popup.JBPopup
|
||||||
|
import com.intellij.openapi.ui.popup.JBPopupAdapter
|
||||||
|
import com.intellij.openapi.ui.popup.JBPopupFactory
|
||||||
|
import com.intellij.openapi.ui.popup.LightweightWindowEvent
|
||||||
import com.intellij.openapi.util.Pass
|
import com.intellij.openapi.util.Pass
|
||||||
import com.intellij.openapi.util.TextRange
|
import com.intellij.openapi.util.TextRange
|
||||||
import com.intellij.openapi.util.text.StringUtil
|
import com.intellij.openapi.util.text.StringUtil
|
||||||
@@ -82,7 +85,6 @@ import org.jetbrains.kotlin.lexer.KtTokens
|
|||||||
import org.jetbrains.kotlin.name.FqName
|
import org.jetbrains.kotlin.name.FqName
|
||||||
import org.jetbrains.kotlin.name.FqNameUnsafe
|
import org.jetbrains.kotlin.name.FqNameUnsafe
|
||||||
import org.jetbrains.kotlin.psi.*
|
import org.jetbrains.kotlin.psi.*
|
||||||
import org.jetbrains.kotlin.psi.codeFragmentUtil.suppressDiagnosticsInDebugMode
|
|
||||||
import org.jetbrains.kotlin.psi.psiUtil.*
|
import org.jetbrains.kotlin.psi.psiUtil.*
|
||||||
import org.jetbrains.kotlin.renderer.DescriptorRenderer
|
import org.jetbrains.kotlin.renderer.DescriptorRenderer
|
||||||
import org.jetbrains.kotlin.resolve.*
|
import org.jetbrains.kotlin.resolve.*
|
||||||
@@ -95,17 +97,21 @@ import java.lang.annotation.Retention
|
|||||||
import java.util.*
|
import java.util.*
|
||||||
import javax.swing.Icon
|
import javax.swing.Icon
|
||||||
|
|
||||||
val CHECK_SUPER_METHODS_YES_NO_DIALOG = "CHECK_SUPER_METHODS_YES_NO_DIALOG"
|
const val CHECK_SUPER_METHODS_YES_NO_DIALOG = "CHECK_SUPER_METHODS_YES_NO_DIALOG"
|
||||||
|
|
||||||
@JvmOverloads
|
@JvmOverloads
|
||||||
fun getOrCreateKotlinFile(fileName: String,
|
fun getOrCreateKotlinFile(
|
||||||
|
fileName: String,
|
||||||
targetDir: PsiDirectory,
|
targetDir: PsiDirectory,
|
||||||
packageName: String? = targetDir.getPackage()?.qualifiedName): KtFile? =
|
packageName: String? = targetDir.getPackage()?.qualifiedName
|
||||||
|
): KtFile? =
|
||||||
(targetDir.findFile(fileName) ?: createKotlinFile(fileName, targetDir, packageName)) as? KtFile
|
(targetDir.findFile(fileName) ?: createKotlinFile(fileName, targetDir, packageName)) as? KtFile
|
||||||
|
|
||||||
fun createKotlinFile(fileName: String,
|
fun createKotlinFile(
|
||||||
|
fileName: String,
|
||||||
targetDir: PsiDirectory,
|
targetDir: PsiDirectory,
|
||||||
packageName: String? = targetDir.getPackage()?.qualifiedName): KtFile {
|
packageName: String? = targetDir.getPackage()?.qualifiedName
|
||||||
|
): KtFile {
|
||||||
targetDir.checkCreateFile(fileName)
|
targetDir.checkCreateFile(fileName)
|
||||||
val packageFqName = packageName?.let(::FqName) ?: FqName.ROOT
|
val packageFqName = packageName?.let(::FqName) ?: FqName.ROOT
|
||||||
val file = PsiFileFactory.getInstance(targetDir.project).createFileFromText(
|
val file = PsiFileFactory.getInstance(targetDir.project).createFileFromText(
|
||||||
@@ -127,7 +133,8 @@ fun VirtualFile.toPsiFile(project: Project): PsiFile? = PsiManager.getInstance(p
|
|||||||
|
|
||||||
fun VirtualFile.toPsiDirectory(project: Project): PsiDirectory? = PsiManager.getInstance(project).findDirectory(this)
|
fun VirtualFile.toPsiDirectory(project: Project): PsiDirectory? = PsiManager.getInstance(project).findDirectory(this)
|
||||||
|
|
||||||
fun VirtualFile.toPsiFileOrDirectory(project: Project): PsiFileSystemItem? = if (isDirectory) toPsiDirectory(project) else toPsiFile(project)
|
fun VirtualFile.toPsiFileOrDirectory(project: Project): PsiFileSystemItem? =
|
||||||
|
if (isDirectory) toPsiDirectory(project) else toPsiFile(project)
|
||||||
|
|
||||||
fun PsiElement.getUsageContext(): PsiElement {
|
fun PsiElement.getUsageContext(): PsiElement {
|
||||||
return when (this) {
|
return when (this) {
|
||||||
@@ -214,7 +221,8 @@ fun PsiElement.getExtractionContainers(strict: Boolean = true, includeAll: Boole
|
|||||||
fun Project.checkConflictsInteractively(
|
fun Project.checkConflictsInteractively(
|
||||||
conflicts: MultiMap<PsiElement, String>,
|
conflicts: MultiMap<PsiElement, String>,
|
||||||
onShowConflicts: () -> Unit = {},
|
onShowConflicts: () -> Unit = {},
|
||||||
onAccept: () -> Unit) {
|
onAccept: () -> Unit
|
||||||
|
) {
|
||||||
if (!conflicts.isEmpty) {
|
if (!conflicts.isEmpty) {
|
||||||
if (ApplicationManager.getApplication()!!.isUnitTestMode) throw ConflictsInTestsException(conflicts.values())
|
if (ApplicationManager.getApplication()!!.isUnitTestMode) throw ConflictsInTestsException(conflicts.values())
|
||||||
|
|
||||||
@@ -246,7 +254,8 @@ fun <T, E : PsiElement> getPsiElementPopup(
|
|||||||
title: String?,
|
title: String?,
|
||||||
highlightSelection: Boolean,
|
highlightSelection: Boolean,
|
||||||
toPsi: (T) -> E,
|
toPsi: (T) -> E,
|
||||||
processor: (T) -> Boolean): JBPopup {
|
processor: (T) -> Boolean
|
||||||
|
): JBPopup {
|
||||||
val highlighter = if (highlightSelection) SelectionAwareScopeHighlighter(editor) else null
|
val highlighter = if (highlightSelection) SelectionAwareScopeHighlighter(editor) else null
|
||||||
|
|
||||||
val list = JBList(elements.map(toPsi))
|
val list = JBList(elements.map(toPsi))
|
||||||
@@ -364,7 +373,8 @@ fun <T> chooseContainerElement(
|
|||||||
title: String,
|
title: String,
|
||||||
highlightSelection: Boolean,
|
highlightSelection: Boolean,
|
||||||
toPsi: (T) -> PsiElement,
|
toPsi: (T) -> PsiElement,
|
||||||
onSelect: (T) -> Unit) {
|
onSelect: (T) -> Unit
|
||||||
|
) {
|
||||||
return getPsiElementPopup(
|
return getPsiElementPopup(
|
||||||
editor,
|
editor,
|
||||||
containers,
|
containers,
|
||||||
@@ -511,8 +521,7 @@ fun createJavaMethod(template: PsiMethod, targetClass: PsiClass): PsiMethod {
|
|||||||
val factory = PsiElementFactory.SERVICE.getInstance(template.project)
|
val factory = PsiElementFactory.SERVICE.getInstance(template.project)
|
||||||
val methodToAdd = if (template.isConstructor) {
|
val methodToAdd = if (template.isConstructor) {
|
||||||
factory.createConstructor(template.name)
|
factory.createConstructor(template.name)
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
factory.createMethod(template.name, template.returnType)
|
factory.createMethod(template.name, template.returnType)
|
||||||
}
|
}
|
||||||
val method = targetClass.add(methodToAdd) as PsiMethod
|
val method = targetClass.add(methodToAdd) as PsiMethod
|
||||||
@@ -541,8 +550,7 @@ fun createJavaMethod(template: PsiMethod, targetClass: PsiClass): PsiMethod {
|
|||||||
|
|
||||||
if (template.modifierList.hasModifierProperty(PsiModifier.ABSTRACT) || targetClass.isInterface) {
|
if (template.modifierList.hasModifierProperty(PsiModifier.ABSTRACT) || targetClass.isInterface) {
|
||||||
method.body!!.delete()
|
method.body!!.delete()
|
||||||
}
|
} else if (!template.isConstructor) {
|
||||||
else if (!template.isConstructor) {
|
|
||||||
CreateFromUsageUtils.setupMethodBody(method)
|
CreateFromUsageUtils.setupMethodBody(method)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -601,8 +609,7 @@ fun createJavaClass(klass: KtClass, targetClass: PsiClass?, forcePlainClass: Boo
|
|||||||
PsiReferenceList.Role.IMPLEMENTS_LIST
|
PsiReferenceList.Role.IMPLEMENTS_LIST
|
||||||
)
|
)
|
||||||
implementsList?.let { javaClass.implementsList?.replace(it) }
|
implementsList?.let { javaClass.implementsList?.replace(it) }
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
val extendsList = factory.createReferenceListWithRole(
|
val extendsList = factory.createReferenceListWithRole(
|
||||||
template.extendsList?.referenceElements ?: PsiJavaCodeReferenceElement.EMPTY_ARRAY,
|
template.extendsList?.referenceElements ?: PsiJavaCodeReferenceElement.EMPTY_ARRAY,
|
||||||
PsiReferenceList.Role.EXTENDS_LIST
|
PsiReferenceList.Role.EXTENDS_LIST
|
||||||
@@ -636,9 +643,11 @@ fun createJavaClass(klass: KtClass, targetClass: PsiClass?, forcePlainClass: Boo
|
|||||||
fun PsiElement.j2kText(): String? {
|
fun PsiElement.j2kText(): String? {
|
||||||
if (language != JavaLanguage.INSTANCE) return null
|
if (language != JavaLanguage.INSTANCE) return null
|
||||||
|
|
||||||
val j2kConverter = JavaToKotlinConverter(project,
|
val j2kConverter = JavaToKotlinConverter(
|
||||||
|
project,
|
||||||
ConverterSettings.Companion.defaultSettings,
|
ConverterSettings.Companion.defaultSettings,
|
||||||
IdeaJavaToKotlinServices)
|
IdeaJavaToKotlinServices
|
||||||
|
)
|
||||||
return j2kConverter.elementsToKotlin(listOf(this)).results.single()?.text ?: return null //TODO: insert imports
|
return j2kConverter.elementsToKotlin(listOf(this)).results.single()?.text ?: return null //TODO: insert imports
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -708,13 +717,13 @@ internal abstract class CompositeRefactoringRunner(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Throws(ConfigurationException::class) fun KtElement?.validateElement(errorMessage: String) {
|
@Throws(ConfigurationException::class)
|
||||||
|
fun KtElement?.validateElement(errorMessage: String) {
|
||||||
if (this == null) throw ConfigurationException(errorMessage)
|
if (this == null) throw ConfigurationException(errorMessage)
|
||||||
|
|
||||||
try {
|
try {
|
||||||
AnalyzingUtils.checkForSyntacticErrors(this)
|
AnalyzingUtils.checkForSyntacticErrors(this)
|
||||||
}
|
} catch (e: Exception) {
|
||||||
catch(e: Exception) {
|
|
||||||
throw ConfigurationException(errorMessage)
|
throw ConfigurationException(errorMessage)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -743,7 +752,7 @@ fun PsiNamedElement.isInterfaceClass(): Boolean = when (this) {
|
|||||||
|
|
||||||
fun KtNamedDeclaration.isAbstract(): Boolean {
|
fun KtNamedDeclaration.isAbstract(): Boolean {
|
||||||
if (hasModifier(KtTokens.ABSTRACT_KEYWORD)) return true
|
if (hasModifier(KtTokens.ABSTRACT_KEYWORD)) return true
|
||||||
if (!(containingClassOrObject?.isInterfaceClass() ?: false)) return false
|
if (containingClassOrObject?.isInterfaceClass() != true) return false
|
||||||
return when (this) {
|
return when (this) {
|
||||||
is KtProperty -> initializer == null && delegate == null && accessors.isEmpty()
|
is KtProperty -> initializer == null && delegate == null && accessors.isEmpty()
|
||||||
is KtNamedFunction -> !hasBody()
|
is KtNamedFunction -> !hasBody()
|
||||||
@@ -767,7 +776,7 @@ fun <ListType : KtElement> replaceListPsiAndKeepDelimiters(
|
|||||||
val newCount = newParameters.size
|
val newCount = newParameters.size
|
||||||
|
|
||||||
val commonCount = Math.min(oldCount, newCount)
|
val commonCount = Math.min(oldCount, newCount)
|
||||||
for (i in 0..commonCount - 1) {
|
for (i in 0 until commonCount) {
|
||||||
oldParameters[i] = oldParameters[i].replace(newParameters[i]) as KtElement
|
oldParameters[i] = oldParameters[i].replace(newParameters[i]) as KtElement
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -777,10 +786,10 @@ fun <ListType : KtElement> replaceListPsiAndKeepDelimiters(
|
|||||||
|
|
||||||
if (oldCount > commonCount) {
|
if (oldCount > commonCount) {
|
||||||
originalList.deleteChildRange(oldParameters[commonCount - 1].nextSibling, lastOriginalParameter)
|
originalList.deleteChildRange(oldParameters[commonCount - 1].nextSibling, lastOriginalParameter)
|
||||||
}
|
} else if (newCount > commonCount) {
|
||||||
else if (newCount > commonCount) {
|
|
||||||
val psiBeforeLastParameter = lastOriginalParameter.prevSibling
|
val psiBeforeLastParameter = lastOriginalParameter.prevSibling
|
||||||
val withMultiline = (psiBeforeLastParameter is PsiWhiteSpace || psiBeforeLastParameter is PsiComment) && psiBeforeLastParameter.textContains('\n')
|
val withMultiline =
|
||||||
|
(psiBeforeLastParameter is PsiWhiteSpace || psiBeforeLastParameter is PsiComment) && psiBeforeLastParameter.textContains('\n')
|
||||||
val extraSpace = if (withMultiline) KtPsiFactory(originalList).createNewLine() else null
|
val extraSpace = if (withMultiline) KtPsiFactory(originalList).createNewLine() else null
|
||||||
originalList.addRangeAfter(newParameters[commonCount - 1].nextSibling, newParameters.last(), lastOriginalParameter)
|
originalList.addRangeAfter(newParameters[commonCount - 1].nextSibling, newParameters.last(), lastOriginalParameter)
|
||||||
if (extraSpace != null) {
|
if (extraSpace != null) {
|
||||||
@@ -885,7 +894,7 @@ fun checkSuperMethods(
|
|||||||
is KtNamedFunction, is KtProperty, is KtParameter -> formatClassDescriptor(descriptor.containingDeclaration)
|
is KtNamedFunction, is KtProperty, is KtParameter -> formatClassDescriptor(descriptor.containingDeclaration)
|
||||||
is PsiMethod -> {
|
is PsiMethod -> {
|
||||||
val psiClass = element.containingClass ?: error("Invalid element: ${element.getText()}")
|
val psiClass = element.containingClass ?: error("Invalid element: ${element.getText()}")
|
||||||
formatPsiClass(psiClass, true, false)
|
formatPsiClass(psiClass, markAsJava = true, inCode = false)
|
||||||
}
|
}
|
||||||
else -> error("Unexpected element: ${element.getElementTextWithContext()}")
|
else -> error("Unexpected element: ${element.getElementTextWithContext()}")
|
||||||
}
|
}
|
||||||
@@ -908,7 +917,8 @@ fun checkSuperMethods(
|
|||||||
|
|
||||||
val exitCode = showYesNoCancelDialog(
|
val exitCode = showYesNoCancelDialog(
|
||||||
CHECK_SUPER_METHODS_YES_NO_DIALOG,
|
CHECK_SUPER_METHODS_YES_NO_DIALOG,
|
||||||
declaration.project, message, IdeBundle.message("title.warning"), Messages.getQuestionIcon(), Messages.YES)
|
declaration.project, message, IdeBundle.message("title.warning"), Messages.getQuestionIcon(), Messages.YES
|
||||||
|
)
|
||||||
return when (exitCode) {
|
return when (exitCode) {
|
||||||
Messages.YES -> overriddenElementsToDescriptor.keys.toList()
|
Messages.YES -> overriddenElementsToDescriptor.keys.toList()
|
||||||
Messages.NO -> listOf(declaration)
|
Messages.NO -> listOf(declaration)
|
||||||
@@ -974,7 +984,7 @@ fun checkSuperMethodsWithPopup(
|
|||||||
}
|
}
|
||||||
|
|
||||||
val renameBase = actionString + " base $superKind" + (if (deepestSuperMethods.size > 1) "s" else "")
|
val renameBase = actionString + " base $superKind" + (if (deepestSuperMethods.size > 1) "s" else "")
|
||||||
val renameCurrent = actionString + " only current $kind"
|
val renameCurrent = "$actionString only current $kind"
|
||||||
val title = buildString {
|
val title = buildString {
|
||||||
append(declaration.name)
|
append(declaration.name)
|
||||||
append(if (isAbstract) " implements " else " overrides ")
|
append(if (isAbstract) " implements " else " overrides ")
|
||||||
@@ -1017,3 +1027,11 @@ internal fun KtDeclaration.resolveToExpectedDescriptorIfPossible(): DeclarationD
|
|||||||
fun DialogWrapper.showWithTransaction() {
|
fun DialogWrapper.showWithTransaction() {
|
||||||
TransactionGuard.submitTransaction(disposable, Runnable { show() })
|
TransactionGuard.submitTransaction(disposable, Runnable { show() })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun PsiMethod.checkDeclarationConflict(name: String, conflicts: MultiMap<PsiElement, String>, callables: List<PsiElement>) {
|
||||||
|
containingClass
|
||||||
|
?.findMethodsByName(name, true)
|
||||||
|
// as is necessary here: see KT-10386
|
||||||
|
?.firstOrNull { it.parameterList.parametersCount == 0 && !callables.contains(it.namedUnwrappedElement as PsiElement?) }
|
||||||
|
?.let { reportDeclarationConflict(conflicts, it) { s -> "$s already exists" } }
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user