use of org.jetbrains.kotlin.js.backend.ast.JsStatement in project kotlin by JetBrains.
the class InitializerVisitor method visitProperty.
@Override
public final Void visitProperty(@NotNull KtProperty property, @NotNull TranslationContext context) {
PropertyDescriptor descriptor = BindingUtils.getPropertyDescriptor(context.bindingContext(), property);
JsExpression value = PropertyTranslatorKt.translateDelegateOrInitializerExpression(context, property);
JsStatement statement = null;
KtExpression initializer = property.getInitializer();
KtExpression delegate = property.getDelegateExpression();
if (initializer != null) {
assert value != null;
statement = generateInitializerForProperty(context, descriptor, value);
} else if (delegate != null) {
assert value != null;
statement = generateInitializerForDelegate(descriptor, value);
} else if (Boolean.TRUE.equals(context.bindingContext().get(BindingContext.BACKING_FIELD_REQUIRED, descriptor))) {
JsNameRef backingFieldReference = TranslationUtils.backingFieldReference(context, descriptor);
JsExpression defaultValue = generateDefaultValue(descriptor, context, backingFieldReference);
statement = TranslationUtils.assignmentToBackingField(context, descriptor, defaultValue).makeStmt();
} else if (JsDescriptorUtils.isSimpleFinalProperty(descriptor)) {
JsNameRef propRef = new JsNameRef(context.getNameForDescriptor(descriptor), JsLiteral.THIS);
JsExpression defaultValue = generateDefaultValue(descriptor, context, propRef);
statement = JsAstUtils.assignment(propRef, defaultValue).makeStmt();
}
if (statement != null && !JsAstUtils.isEmptyStatement(statement)) {
context.addStatementsToCurrentBlock(JsAstUtils.flattenStatement(statement));
}
return null;
}
Aggregations