New J2K: Add file range support for nullability analysis
This commit is contained in:
@@ -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) {
|
||||
|
||||
+6
-4
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user