Fix WhenChecker after enum property type change
This commit is contained in:
@@ -17,9 +17,11 @@
|
||||
package org.jetbrains.jet.lang.cfg;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.descriptors.ClassDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.ClassKind;
|
||||
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.resolve.BindingContext;
|
||||
import org.jetbrains.jet.lang.resolve.BindingTrace;
|
||||
@@ -65,15 +67,22 @@ public class WhenChecker {
|
||||
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;
|
||||
for (JetWhenEntry whenEntry : whenExpression.getEntries()) {
|
||||
for (JetWhenCondition condition : whenEntry.getConditions()) {
|
||||
if (condition instanceof JetWhenConditionWithExpression) {
|
||||
JetExpression patternExpression = ((JetWhenConditionWithExpression) condition).getExpression();
|
||||
JetType type = trace.get(BindingContext.EXPRESSION_TYPE, patternExpression);
|
||||
if (type == null) continue;
|
||||
if (type.getConstructor().getDeclarationDescriptor() == enumEntry) {
|
||||
JetSimpleNameExpression reference = getReference(patternExpression);
|
||||
if (reference == null) continue;
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -81,4 +90,18 @@ public class WhenChecker {
|
||||
}
|
||||
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