Skip to content

Commit

Permalink
Light classes: test consistency for inner classes
Browse files Browse the repository at this point in the history
  • Loading branch information
PVTalanov committed Apr 9, 2017
1 parent 4f70128 commit 5e35106
Showing 1 changed file with 28 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -193,10 +193,8 @@ object LightClassLazinessChecker {
tracker.allowLevel(EXACT)
}

// 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) }
// collect api method call results on light members that should not trigger exact context evaluation
val lazinessInfo = LazinessInfo(lightClass)

tracker.allowLevel(EXACT)

Expand All @@ -207,26 +205,40 @@ object LightClassLazinessChecker {
// still running code above to catch possible exceptions
if (lazinessMode == Mode.NoConsistency) return

// check collected data against delegates which should contain correct data
for ((field, lightFieldInfo) in fieldsToInfo) {
val delegate = (field as KtLightField).clsDelegate
assertEquals(fieldInfo(delegate), lightFieldInfo)
}
for ((method, lightMethodInfo) in methodsToInfo) {
val delegate = (method as KtLightMethod).clsDelegate
assertEquals(methodInfo(delegate), lightMethodInfo)
}
lazinessInfo.checkConsistency()
}

private class LazinessInfo(val lightClass: KtLightClass) {
val classInfo = classInfo(lightClass)
val fieldsToInfo = lightClass.fields.asList().keysToMap { fieldInfo(it) }
val methodsToInfo = lightClass.methods.asList().keysToMap { methodInfo(it) }
val innerClasses = lightClass.innerClasses.map { LazinessInfo(it as KtLightClass) }

fun checkConsistency() {
// check collected data against delegates which should contain correct data
for ((field, lightFieldInfo) in fieldsToInfo) {
val delegate = (field as KtLightField).clsDelegate
assertEquals(fieldInfo(delegate), lightFieldInfo)
}
for ((method, lightMethodInfo) in methodsToInfo) {
val delegate = (method as KtLightMethod).clsDelegate
assertEquals(methodInfo(delegate), lightMethodInfo)
}

assertEquals(classInfo(lightClass.clsDelegate), classInfo)

assertEquals(classInfo(lightClass.clsDelegate), classInfo)
innerClasses.forEach(LazinessInfo::checkConsistency)
}
}

private data class ClassInfo(
val fieldNames: Collection<String>,
val methodNames: Collection<String>
val methodNames: Collection<String>,
val modifiers: List<String>
)

private fun classInfo(psiClass: PsiClass) = with(psiClass) {
ClassInfo(fields.names(), methods.names())
ClassInfo(fields.names(), methods.names(), PsiModifier.MODIFIERS.asList().filter { modifierList!!.hasModifierProperty(it) })
}

private data class FieldInfo(
Expand Down

0 comments on commit 5e35106

Please sign in to comment.