use of org.jetbrains.kotlin.codegen.when.WhenByEnumsMapping in project kotlin by JetBrains.
the class CodegenAnnotatingVisitor method visitWhenExpression.
@Override
public void visitWhenExpression(@NotNull KtWhenExpression expression) {
super.visitWhenExpression(expression);
if (!isWhenWithEnums(expression))
return;
String currentClassName = getCurrentTopLevelClassOrPackagePartInternalName(expression.getContainingKtFile());
if (bindingContext.get(MAPPINGS_FOR_WHENS_BY_ENUM_IN_CLASS_FILE, currentClassName) == null) {
bindingTrace.record(MAPPINGS_FOR_WHENS_BY_ENUM_IN_CLASS_FILE, currentClassName, new ArrayList<WhenByEnumsMapping>(1));
}
List<WhenByEnumsMapping> mappings = bindingContext.get(MAPPINGS_FOR_WHENS_BY_ENUM_IN_CLASS_FILE, currentClassName);
assert mappings != null : "guaranteed by contract";
int fieldNumber = mappings.size();
assert expression.getSubjectExpression() != null : "subject expression should be not null in a valid when by enums";
KotlinType type = WhenChecker.whenSubjectType(expression, bindingContext);
assert type != null : "should not be null in a valid when by enums";
ClassDescriptor classDescriptor = (ClassDescriptor) type.getConstructor().getDeclarationDescriptor();
assert classDescriptor != null : "because it's enum";
WhenByEnumsMapping mapping = new WhenByEnumsMapping(classDescriptor, currentClassName, fieldNumber);
for (ConstantValue<?> constant : SwitchCodegenUtil.getAllConstants(expression, bindingContext, shouldInlineConstVals)) {
if (constant instanceof NullValue)
continue;
assert constant instanceof EnumValue : "expression in when should be EnumValue";
mapping.putFirstTime((EnumValue) constant, mapping.size() + 1);
}
mappings.add(mapping);
bindingTrace.record(MAPPING_FOR_WHEN_BY_ENUM, expression, mapping);
}
Aggregations