use of org.jetbrains.kotlin.psi.KtDestructuringDeclarationEntry in project kotlin by JetBrains.
the class DestructuringDeclarationTranslator method translate.
private JsVars translate() {
if (initializer != null) {
context().getCurrentBlock().getStatements().add(JsAstUtils.newVar(multiObjectName, initializer));
}
List<JsVars.JsVar> jsVars = new ArrayList<JsVars.JsVar>();
JsNameRef multiObjNameRef = multiObjectName.makeRef();
for (KtDestructuringDeclarationEntry entry : multiDeclaration.getEntries()) {
VariableDescriptor descriptor = BindingContextUtils.getNotNull(context().bindingContext(), BindingContext.VARIABLE, entry);
// Do not call `componentX` for destructuring entry called _
if (descriptor.getName().isSpecial())
continue;
ResolvedCall<FunctionDescriptor> entryInitCall = context().bindingContext().get(BindingContext.COMPONENT_RESOLVED_CALL, entry);
assert entryInitCall != null : "Entry init call must be not null";
JsExpression entryInitializer = CallTranslator.translate(context(), entryInitCall, multiObjNameRef);
FunctionDescriptor candidateDescriptor = entryInitCall.getCandidateDescriptor();
if (CallExpressionTranslator.shouldBeInlined(candidateDescriptor, context())) {
setInlineCallMetadata(entryInitializer, entry, entryInitCall, context());
}
KotlinType returnType = candidateDescriptor.getReturnType();
if (returnType != null && KotlinBuiltIns.isCharOrNullableChar(returnType) && !KotlinBuiltIns.isCharOrNullableChar(descriptor.getType())) {
entryInitializer = JsAstUtils.charToBoxedChar(entryInitializer);
}
JsName name = context().getNameForDescriptor(descriptor);
if (isVarCapturedInClosure(context().bindingContext(), descriptor)) {
JsNameRef alias = getCapturedVarAccessor(name.makeRef());
entryInitializer = JsAstUtils.wrapValue(alias, entryInitializer);
}
jsVars.add(new JsVars.JsVar(name, entryInitializer));
}
return new JsVars(jsVars, true);
}
Aggregations