New J2K: Add file range support for nullability analysis

This commit is contained in:
Ilya Kirillov
2019-04-08 19:31:34 +03:00
parent 33a42733f5
commit 54d6fc846b
2 changed files with 10 additions and 4 deletions
@@ -5,9 +5,13 @@
package org.jetbrains.kotlin.nj2k.nullabilityAnalysis
import com.intellij.openapi.editor.RangeMarker
import com.intellij.openapi.util.TextRange
import com.intellij.psi.PsiComment
import com.intellij.psi.PsiElement
import org.jetbrains.kotlin.psi.*
import org.jetbrains.kotlin.psi.psiUtil.collectDescendantsOfType
import org.jetbrains.kotlin.psi.psiUtil.elementsInRange
import org.jetbrains.kotlin.utils.addToStdlib.safeAs
internal class ContextCreator(private val getNullability: (KtTypeElement) -> Nullability) {
@@ -82,10 +82,11 @@ class NullabilityAnalysisFacade(
runWriteAction {
analysisScope.prepareTypeElements(prepareTypeElement)
val context = ContextCreator(getTypeElementNullability).createContext(analysisScope)
if (debugPrint)
if (debugPrint) {
with(Printer(context)) {
analysisScope.single().addTypeVariablesNames()
analysisScope.forEach { it.addTypeVariablesNames() }
}
}
val constraints = ConstraintsCollector(context, debugPrint).collectConstraints(analysisScope)
Solver(context, debugPrint).solveConstraints(constraints)
@@ -97,8 +98,9 @@ class NullabilityAnalysisFacade(
}
private fun AnalysisScope.prepareTypeElements(prepareTypeElement: (KtTypeElement) -> Unit) {
val typeElements = flatMap { it.collectDescendantsOfType<KtTypeElement>() }
typeElements.forEach { typeElement ->
val typeElements = flatMap { it.collectDescendantsOfType<KtTypeReference>() }
typeElements.forEach { typeReference ->
val typeElement = typeReference.typeElement ?: return@forEach
if (typeElement.parentOfType<KtSuperTypeCallEntry>() == null) {
prepareTypeElement(typeElement)
}