CreateExpect: fix case with parameters in constructor without var/val

This commit is contained in:
Dmitry Gridin
2019-08-19 19:37:17 +07:00
parent 1b718761b2
commit bddf768d59
8 changed files with 14 additions and 10 deletions
@@ -130,7 +130,10 @@ class CreateExpectedClassFix(
if (!showUnknownTypesDialog(project, declarationsWithNonExistentClasses)) return@block null
val membersForSelection = members.filterNot(KtNamedDeclaration::isAlwaysActual)
val membersForSelection = members.filter {
!it.isAlwaysActual() && if (it is KtParameter) it.hasValOrVar() else true
}
val selectedElements = when {
membersForSelection.all(KtDeclaration::hasActualModifier) -> membersForSelection
ApplicationManager.getApplication().isUnitTestMode -> membersForSelection.filter(KtDeclaration::hasActualModifier)
@@ -138,9 +141,9 @@ class CreateExpectedClassFix(
val prefix = klass.fqName?.asString()?.plus(".") ?: ""
chooseMembers(project, membersForSelection, prefix) ?: return@block null
}
}.asSequence().plus(members.filter(KtNamedDeclaration::isAlwaysActual)).flatMap(KtNamedDeclaration::selected).toSet()
}.asSequence().plus(klass).plus(members.filter(KtNamedDeclaration::isAlwaysActual)).flatMap(KtNamedDeclaration::selected).toSet()
val selectedClasses = findClasses(selectedElements + klass, commonModule)
val selectedClasses = findClasses(selectedElements, commonModule)
val resultDeclarations = if (selectedClasses != existingClasses) {
if (!element.checkTypeAccessibilityInModule(commonModule, selectedClasses)) {
showUnknownTypesError(element)
@@ -258,7 +261,7 @@ private fun repairActualModifiers(
originalElements: Collection<KtNamedDeclaration>,
selectedElements: Collection<KtNamedDeclaration>
) {
if (originalElements.size == selectedElements.size)
if (originalElements == selectedElements)
for (original in originalElements) {
original.makeActualWithParents()
}
@@ -1,5 +1,5 @@
// "Create expected function in common module testModule_Common" "true"
// SHOULD_FAIL_WITH: Cannot generate expected function: Type Some is not accessible from common code
// SHOULD_FAIL_WITH: You cannot create the expect declaration from:,fun foo(some: Some){...}
// DISABLE-ERRORS
class Some
@@ -1,5 +1,5 @@
// "Create expected function in common module testModule_Common" "true"
// SHOULD_FAIL_WITH: Cannot generate expected function: Type Some is not accessible from common code
// SHOULD_FAIL_WITH: You cannot create the expect declaration from:,fun foo(some: Some){...}
// DISABLE-ERRORS
class Some
@@ -1,5 +1,5 @@
// "Create expected function in common module testModule_Common" "true"
// SHOULD_FAIL_WITH: Cannot generate expected function: Type Some is not accessible from common code
// SHOULD_FAIL_WITH: You cannot create the expect declaration from:,fun foo(some: List<Some>){...}
// DISABLE-ERRORS
class Some
@@ -1,5 +1,5 @@
// "Create expected function in common module testModule_Common" "true"
// SHOULD_FAIL_WITH: Cannot generate expected function: Type Some is not accessible from common code
// SHOULD_FAIL_WITH: You cannot create the expect declaration from:,fun foo(some: List<Some>){...}
// DISABLE-ERRORS
class Some
@@ -1,5 +1,5 @@
// "Create expected function in common module proj_Common" "true"
// SHOULD_FAIL_WITH: Cannot generate expected function: Type java.util.ArrayList<kotlin.Any> is not accessible from common code
// SHOULD_FAIL_WITH: You cannot create the expect declaration from:,fun createList() = ArrayList()
// DISABLE-ERRORS
import java.util.ArrayList
@@ -1,5 +1,5 @@
// "Create expected function in common module proj_Common" "true"
// SHOULD_FAIL_WITH: Cannot generate expected function: Type java.util.ArrayList<kotlin.Any> is not accessible from common code
// SHOULD_FAIL_WITH: You cannot create the expect declaration from:,fun createList() = ArrayList()
// DISABLE-ERRORS
import java.util.ArrayList
@@ -5,6 +5,7 @@ annotation class CommonAnnotation
expect class My {
tailrec fun foo(arg: Int): Int
var some: Boolean
@CommonAnnotation
fun initialize()
}