Fix WhenChecker after enum property type change
This commit is contained in:
@@ -17,9 +17,11 @@
|
|||||||
package org.jetbrains.jet.lang.cfg;
|
package org.jetbrains.jet.lang.cfg;
|
||||||
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.jetbrains.jet.lang.descriptors.ClassDescriptor;
|
import org.jetbrains.jet.lang.descriptors.ClassDescriptor;
|
||||||
import org.jetbrains.jet.lang.descriptors.ClassKind;
|
import org.jetbrains.jet.lang.descriptors.ClassKind;
|
||||||
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
|
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
|
||||||
|
import org.jetbrains.jet.lang.descriptors.VariableDescriptor;
|
||||||
import org.jetbrains.jet.lang.psi.*;
|
import org.jetbrains.jet.lang.psi.*;
|
||||||
import org.jetbrains.jet.lang.resolve.BindingContext;
|
import org.jetbrains.jet.lang.resolve.BindingContext;
|
||||||
import org.jetbrains.jet.lang.resolve.BindingTrace;
|
import org.jetbrains.jet.lang.resolve.BindingTrace;
|
||||||
@@ -65,15 +67,22 @@ public class WhenChecker {
|
|||||||
return isExhaust && notEmpty;
|
return isExhaust && notEmpty;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean containsEnumEntryCase(@NotNull JetWhenExpression whenExpression, @NotNull ClassDescriptor enumEntry, @NotNull BindingTrace trace) {
|
private static boolean containsEnumEntryCase(
|
||||||
|
@NotNull JetWhenExpression whenExpression,
|
||||||
|
@NotNull ClassDescriptor enumEntry,
|
||||||
|
@NotNull BindingTrace trace
|
||||||
|
) {
|
||||||
assert enumEntry.getKind() == ClassKind.ENUM_ENTRY;
|
assert enumEntry.getKind() == ClassKind.ENUM_ENTRY;
|
||||||
for (JetWhenEntry whenEntry : whenExpression.getEntries()) {
|
for (JetWhenEntry whenEntry : whenExpression.getEntries()) {
|
||||||
for (JetWhenCondition condition : whenEntry.getConditions()) {
|
for (JetWhenCondition condition : whenEntry.getConditions()) {
|
||||||
if (condition instanceof JetWhenConditionWithExpression) {
|
if (condition instanceof JetWhenConditionWithExpression) {
|
||||||
JetExpression patternExpression = ((JetWhenConditionWithExpression) condition).getExpression();
|
JetExpression patternExpression = ((JetWhenConditionWithExpression) condition).getExpression();
|
||||||
JetType type = trace.get(BindingContext.EXPRESSION_TYPE, patternExpression);
|
JetSimpleNameExpression reference = getReference(patternExpression);
|
||||||
if (type == null) continue;
|
if (reference == null) continue;
|
||||||
if (type.getConstructor().getDeclarationDescriptor() == enumEntry) {
|
DeclarationDescriptor target = trace.get(BindingContext.REFERENCE_TARGET, reference);
|
||||||
|
if (target == null) continue;
|
||||||
|
ClassDescriptor classDescriptor = trace.get(BindingContext.OBJECT_DECLARATION_CLASS, (VariableDescriptor) target);
|
||||||
|
if (classDescriptor == enumEntry) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -81,4 +90,18 @@ public class WhenChecker {
|
|||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
private static JetSimpleNameExpression getReference(@Nullable JetExpression expression) {
|
||||||
|
if (expression == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
if (expression instanceof JetSimpleNameExpression) {
|
||||||
|
return (JetSimpleNameExpression) expression;
|
||||||
|
}
|
||||||
|
if (expression instanceof JetQualifiedExpression) {
|
||||||
|
return getReference(((JetQualifiedExpression) expression).getSelectorExpression());
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user