use of org.jetbrains.kotlin.js.backend.ast.JsInvocation in project kotlin by JetBrains.
the class ReferenceTranslator method translateAsValueReference.
@NotNull
public static JsExpression translateAsValueReference(@NotNull DeclarationDescriptor descriptor, @NotNull TranslationContext context) {
JsExpression alias = context.getAliasForDescriptor(descriptor);
if (alias != null)
return alias;
if (shouldTranslateAsFQN(descriptor, context)) {
return context.getQualifiedReference(descriptor);
}
if (descriptor instanceof PropertyDescriptor) {
PropertyDescriptor property = (PropertyDescriptor) descriptor;
if (context.isFromCurrentModule(property)) {
return context.getInnerReference(property);
} else {
JsExpression qualifier = context.getInnerReference(property.getContainingDeclaration());
JsName name = context.getNameForDescriptor(property);
return new JsNameRef(name, qualifier);
}
}
if (DescriptorUtils.isObject(descriptor) || DescriptorUtils.isEnumEntry(descriptor)) {
if (!context.isFromCurrentModule(descriptor)) {
return getLazyReferenceToObject((ClassDescriptor) descriptor, context);
} else {
JsExpression functionRef = JsAstUtils.pureFqn(context.getNameForObjectInstance((ClassDescriptor) descriptor), null);
return new JsInvocation(functionRef);
}
}
return context.getInnerReference(descriptor);
}
use of org.jetbrains.kotlin.js.backend.ast.JsInvocation in project kotlin by JetBrains.
the class KotlinFunctionIntrinsic method apply.
@NotNull
@Override
public JsExpression apply(@Nullable JsExpression receiver, @NotNull List<? extends JsExpression> arguments, @NotNull TranslationContext context) {
JsExpression function = JsAstUtils.pureFqn(functionName, Namer.kotlinObject());
if (additionalArguments.length > 0) {
List<JsExpression> newArguments = new ArrayList<JsExpression>(arguments);
for (JsExpression e : additionalArguments) {
newArguments.add(e.deepCopy());
}
arguments = newArguments;
}
return new JsInvocation(function, receiver == null ? arguments : TranslationUtils.generateInvocationArguments(receiver, arguments));
}
use of org.jetbrains.kotlin.js.backend.ast.JsInvocation in project kotlin by JetBrains.
the class ReferenceTranslator method getPrototypeIfNecessary.
@NotNull
private static JsExpression getPrototypeIfNecessary(@NotNull ClassDescriptor descriptor, @NotNull JsExpression reference) {
if (DescriptorUtils.isObject(descriptor) || DescriptorUtils.isEnumEntry(descriptor)) {
JsNameRef getPrototypeRef = JsAstUtils.pureFqn("getPrototypeOf", JsAstUtils.pureFqn("Object", null));
JsInvocation getPrototypeInvocation = new JsInvocation(getPrototypeRef, reference);
MetadataProperties.setSideEffects(getPrototypeInvocation, SideEffectKind.PURE);
reference = JsAstUtils.pureFqn("constructor", getPrototypeInvocation);
}
return reference;
}
use of org.jetbrains.kotlin.js.backend.ast.JsInvocation in project kotlin by JetBrains.
the class PatternTranslator method translateCastExpression.
@NotNull
public JsExpression translateCastExpression(@NotNull KtBinaryExpressionWithTypeRHS expression) {
assert isCastExpression(expression) : "Expected cast expression, got " + expression;
KtExpression left = expression.getLeft();
JsExpression expressionToCast = Translation.translateAsExpression(left, context());
KtTypeReference typeReference = expression.getRight();
assert typeReference != null : "Cast expression must have type reference";
KotlinType leftType = context().bindingContext().getType(left);
if (leftType != null && KotlinBuiltIns.isChar(leftType)) {
expressionToCast = JsAstUtils.charToBoxedChar(expressionToCast);
}
TemporaryVariable temporary = context().declareTemporary(expressionToCast);
JsExpression isCheck = translateIsCheck(temporary.assignmentExpression(), typeReference);
if (isCheck == null)
return expressionToCast;
JsExpression onFail;
if (isSafeCast(expression)) {
onFail = JsLiteral.NULL;
} else {
JsExpression throwCCEFunRef = Namer.throwClassCastExceptionFunRef();
onFail = new JsInvocation(throwCCEFunRef);
}
JsExpression result = new JsConditional(isCheck, temporary.reference(), onFail);
KotlinType expressionType = context().bindingContext().getType(expression);
if (expressionType != null && KotlinBuiltIns.isCharOrNullableChar(expressionType)) {
result = JsAstUtils.boxedCharToChar(result);
}
return result;
}
use of org.jetbrains.kotlin.js.backend.ast.JsInvocation in project kotlin by JetBrains.
the class PatternTranslator method translateIsCheck.
@Nullable
public JsExpression translateIsCheck(@NotNull JsExpression subject, @NotNull KtTypeReference targetTypeReference) {
KotlinType targetType = getTypeByReference(bindingContext(), targetTypeReference);
JsExpression checkFunReference = doGetIsTypeCheckCallable(targetType);
if (checkFunReference == null) {
return null;
}
boolean isReifiedType = isReifiedTypeParameter(targetType);
if (!isReifiedType && isNullableType(targetType) || isReifiedType && findChildByType(targetTypeReference, KtNodeTypes.NULLABLE_TYPE) != null) {
checkFunReference = namer().orNull(checkFunReference);
}
return new JsInvocation(checkFunReference, subject);
}
Aggregations