Introduced BindingContext.DATA_FLOW_INFO_BEFORE
This commit is contained in:
+3
-2
@@ -28,8 +28,8 @@ import org.jetbrains.annotations.TestOnly
|
||||
import org.jetbrains.kotlin.asJava.LightClassGenerationSupport
|
||||
import org.jetbrains.kotlin.asJava.builder.LightClassConstructionContext
|
||||
import org.jetbrains.kotlin.asJava.classes.KtLightClass
|
||||
import org.jetbrains.kotlin.asJava.classes.KtLightClassForSourceDeclaration
|
||||
import org.jetbrains.kotlin.asJava.classes.KtLightClassForFacade
|
||||
import org.jetbrains.kotlin.asJava.classes.KtLightClassForSourceDeclaration
|
||||
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.ModuleDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.PackageViewDescriptor
|
||||
@@ -172,9 +172,10 @@ class CliLightClassGenerationSupport(project: Project) : LightClassGenerationSup
|
||||
return NoScopeRecordCliBindingTrace()
|
||||
}
|
||||
|
||||
// TODO: needs better name + list of keys to skip somewhere
|
||||
class NoScopeRecordCliBindingTrace : CliBindingTrace() {
|
||||
override fun <K, V> record(slice: WritableSlice<K, V>, key: K, value: V) {
|
||||
if (slice === BindingContext.LEXICAL_SCOPE) {
|
||||
if (slice === BindingContext.LEXICAL_SCOPE || slice == BindingContext.DATA_FLOW_INFO_BEFORE) {
|
||||
// In the compiler there's no need to keep scopes
|
||||
return
|
||||
}
|
||||
|
||||
@@ -98,6 +98,7 @@ public interface BindingContext {
|
||||
WritableSlice<KtTypeReference, KotlinType> TYPE = Slices.createSimpleSlice();
|
||||
WritableSlice<KtTypeReference, KotlinType> ABBREVIATED_TYPE = Slices.createSimpleSlice();
|
||||
WritableSlice<KtExpression, KotlinTypeInfo> EXPRESSION_TYPE_INFO = new BasicWritableSlice<KtExpression, KotlinTypeInfo>(DO_NOTHING);
|
||||
WritableSlice<KtExpression, DataFlowInfo> DATA_FLOW_INFO_BEFORE = new BasicWritableSlice<KtExpression, DataFlowInfo>(DO_NOTHING);
|
||||
WritableSlice<KtExpression, KotlinType> EXPECTED_EXPRESSION_TYPE = new BasicWritableSlice<KtExpression, KotlinType>(DO_NOTHING);
|
||||
WritableSlice<KtFunction, KotlinType> EXPECTED_RETURN_TYPE = new BasicWritableSlice<KtFunction, KotlinType>(DO_NOTHING);
|
||||
WritableSlice<KtExpression, DataFlowInfo> DATAFLOW_INFO_AFTER_CONDITION = Slices.createSimpleSlice();
|
||||
|
||||
@@ -80,7 +80,7 @@ fun BindingTrace.recordScope(scope: LexicalScope, element: KtElement?) {
|
||||
}
|
||||
}
|
||||
|
||||
fun BindingContext.getDataFlowInfo(position: PsiElement): DataFlowInfo {
|
||||
fun BindingContext.getDataFlowInfoAfter(position: PsiElement): DataFlowInfo {
|
||||
for (element in position.parentsWithSelf) {
|
||||
(element as? KtExpression)?.let {
|
||||
val parent = it.parent
|
||||
@@ -92,6 +92,15 @@ fun BindingContext.getDataFlowInfo(position: PsiElement): DataFlowInfo {
|
||||
return DataFlowInfo.EMPTY
|
||||
}
|
||||
|
||||
fun BindingContext.getDataFlowInfoBefore(position: PsiElement): DataFlowInfo {
|
||||
for (element in position.parentsWithSelf) {
|
||||
(element as? KtExpression)
|
||||
?.let { this[BindingContext.DATA_FLOW_INFO_BEFORE, it] }
|
||||
?.let { return it }
|
||||
}
|
||||
return DataFlowInfo.EMPTY
|
||||
}
|
||||
|
||||
fun KtExpression.isUnreachableCode(context: BindingContext): Boolean = context[BindingContext.UNREACHABLE_CODE, this]!!
|
||||
|
||||
fun KtExpression.getReferenceTargets(context: BindingContext): Collection<DeclarationDescriptor> {
|
||||
|
||||
+3
@@ -177,6 +177,9 @@ public abstract class ExpressionTypingVisitorDispatcher extends KtVisitor<Kotlin
|
||||
if (recordedTypeInfo != null) {
|
||||
return recordedTypeInfo;
|
||||
}
|
||||
|
||||
context.trace.record(BindingContext.DATA_FLOW_INFO_BEFORE, expression, context.dataFlowInfo);
|
||||
|
||||
KotlinTypeInfo result;
|
||||
try {
|
||||
result = expression.accept(visitor, context);
|
||||
|
||||
Reference in New Issue
Block a user