Skip to content

Commit

Permalink
AbstractIdeLightClassTest: minor, refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
PVTalanov committed Apr 9, 2017
1 parent 0a42a1c commit 8fbd75c
Showing 1 changed file with 13 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ object LightClassLazinessChecker {
}

// collect method class results on light members that should not trigger exact context evaluation
val classInfo = classInfo(lightClass)
val fieldsToInfo = lightClass.fields.asList().keysToMap { fieldInfo(it) }
val methodsToInfo = lightClass.methods.asList().keysToMap { methodInfo(it) }

Expand All @@ -199,9 +200,6 @@ object LightClassLazinessChecker {
// still running code above to catch possible exceptions
if (lazinessMode == Mode.NoConsistency) return

assertEquals(lightClass.clsDelegate.methods.names(), lightClass.methods.names())
assertEquals(lightClass.clsDelegate.fields.names(), lightClass.fields.names())

// check collected data against delegates which should contain correct data
for ((field, lightFieldInfo) in fieldsToInfo) {
val delegate = (field as KtLightField).clsDelegate
Expand All @@ -211,9 +209,18 @@ object LightClassLazinessChecker {
val delegate = (method as KtLightMethod).clsDelegate
assertEquals(methodInfo(delegate), lightMethodInfo)
}

assertEquals(classInfo(lightClass.clsDelegate), classInfo)
}

private fun Array<out PsiMember>.names() = mapTo(LinkedHashSet()) { it.name }
private data class ClassInfo(
val fieldNames: Collection<String>,
val methodNames: Collection<String>
)

private fun classInfo(psiClass: PsiClass) = with(psiClass) {
ClassInfo(fields.names(), methods.names())
}

private data class FieldInfo(
val name: String,
Expand All @@ -240,6 +247,8 @@ object LightClassLazinessChecker {
isConstructor, method.parameterList.parametersCount, isVarArgs
)
}

private fun Array<out PsiMember>.names() = mapTo(LinkedHashSet()) { it.name!! }
}

private fun String.removeLinesStartingWith(prefix: String): String {
Expand Down

0 comments on commit 8fbd75c

Please sign in to comment.