use of org.jetbrains.kotlin.js.backend.ast.JsExpression 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.JsExpression in project kotlin by JetBrains.
the class ReferenceTranslator method getLazyReferenceToObject.
@NotNull
private static JsExpression getLazyReferenceToObject(@NotNull ClassDescriptor descriptor, @NotNull TranslationContext context) {
DeclarationDescriptor container = descriptor.getContainingDeclaration();
JsExpression qualifier = context.getInnerReference(container);
return new JsNameRef(context.getNameForDescriptor(descriptor), qualifier);
}
use of org.jetbrains.kotlin.js.backend.ast.JsExpression in project kotlin by JetBrains.
the class JSTestGenerator method generateCodeForTestMethod.
private static void generateCodeForTestMethod(@NotNull TranslationContext context, @NotNull FunctionDescriptor functionDescriptor, @NotNull ClassDescriptor classDescriptor, @NotNull JSTester tester) {
JsExpression expression = ReferenceTranslator.translateAsValueReference(classDescriptor, context);
JsNew testClass = new JsNew(expression);
JsExpression functionToTestCall = CallTranslator.INSTANCE.buildCall(context, functionDescriptor, Collections.<JsExpression>emptyList(), testClass);
JsStringLiteral testName = context.program().getStringLiteral(classDescriptor.getName() + "." + functionDescriptor.getName());
tester.constructTestMethodInvocation(functionToTestCall, testName);
}
use of org.jetbrains.kotlin.js.backend.ast.JsExpression 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;
}
use of org.jetbrains.kotlin.js.backend.ast.JsExpression 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));
}
Aggregations