JS backend: fix translation for extension property

This commit is contained in:
Michael Nedzelsky
2014-12-03 16:12:53 +03:00
parent 5bf1d73199
commit 7c9ea16d8e
3 changed files with 21 additions and 10 deletions
@@ -45,6 +45,8 @@ import org.jetbrains.jet.lang.resolve.calls.tasks.ExplicitReceiverKind.*
import com.google.dart.compiler.backend.js.ast.JsLiteral
import org.jetbrains.k2js.translate.utils.TranslationUtils
import org.jetbrains.k2js.translate.context.TranslationContext
import org.jetbrains.jet.lang.descriptors.PropertyDescriptor
import org.jetbrains.jet.lang.resolve.descriptorUtil.isExtension
val CallInfo.callableDescriptor: CallableDescriptor
@@ -58,7 +60,7 @@ fun CallInfo.isNative(): Boolean = AnnotationsUtils.isNativeObject(callableDescr
fun CallInfo.isSuperInvocation(): Boolean {
val dispatchReceiver = resolvedCall.getDispatchReceiver()
return dispatchReceiver is ExpressionReceiver && ((dispatchReceiver as ExpressionReceiver)).getExpression() is JetSuperExpression
return dispatchReceiver is ExpressionReceiver && dispatchReceiver.getExpression() is JetSuperExpression
}
val VariableAccessInfo.variableDescriptor: VariableDescriptor
@@ -69,7 +71,16 @@ val VariableAccessInfo.variableName: JsName
fun VariableAccessInfo.isGetAccess(): Boolean = value == null
fun VariableAccessInfo.getAccessFunctionName(): String = Namer.getNameForAccessor(variableName.getIdent()!!, isGetAccess(), false)
fun VariableAccessInfo.getAccessFunctionName(): String {
val descriptor = variableDescriptor
if (descriptor is PropertyDescriptor && descriptor.isExtension) {
val propertyAccessorDescriptor = if (isGetAccess()) descriptor.getGetter() else descriptor.getSetter()
return context.getNameForDescriptor(propertyAccessorDescriptor).getIdent()
}
else {
return Namer.getNameForAccessor(variableName.getIdent()!!, isGetAccess(), false)
}
}
fun VariableAccessInfo.constructAccessExpression(ref: JsExpression): JsExpression {
if (isGetAccess()) {
@@ -290,14 +290,11 @@ public final class StaticContext {
}
return declarePropertyOrPropertyAccessorName(descriptor, propertyName, false);
} else {
if (descriptor instanceof PropertyDescriptor) {
return declarePropertyOrPropertyAccessorName(descriptor, propertyName, false);
} else {
String propertyJsName = getNameForDescriptor(propertyDescriptor).getIdent();
boolean isGetter = descriptor instanceof PropertyGetterDescriptor;
String accessorName = Namer.getNameForAccessor(propertyJsName, isGetter, false);
return declarePropertyOrPropertyAccessorName(descriptor, accessorName, false);
}
assert !(descriptor instanceof PropertyDescriptor) : "descriptor should not be instance of PropertyDescriptor: " + descriptor;
boolean isGetter = descriptor instanceof PropertyGetterDescriptor;
String accessorName = Namer.getNameForAccessor(propertyName, isGetter, false);
return declarePropertyOrPropertyAccessorName(descriptor, accessorName, false);
}
}
};
@@ -33,6 +33,7 @@ import org.jetbrains.k2js.translate.utils.ast.*
import org.jetbrains.k2js.translate.utils.TranslationUtils.*
import org.jetbrains.jet.lang.resolve.DescriptorUtils.isExtension
import org.jetbrains.jet.lang.resolve.calls.model.ResolvedCall
import org.jetbrains.jet.lang.resolve.descriptorUtil.isExtension
/**
* Translates single property /w accessors.
@@ -120,6 +121,7 @@ private class PropertyTranslator(
return generateDelegatedGetterFunction(getterDescriptor, delegatedCall)
}
assert(!descriptor.isExtension, "Unexpected extension property $descriptor}")
val scope = context().getScopeForDescriptor(getterDescriptor.getContainingDeclaration())
val result = backingFieldReference(context(), descriptor)
val body = JsBlock(JsReturn(result))
@@ -172,6 +174,7 @@ private class PropertyTranslator(
(delegatedJsCall as JsInvocation).getArguments().set(0, receiver.makeRef())
}
} else {
assert(!descriptor.isExtension, "Unexpected extension property $descriptor}")
val assignment = assignmentToBackingField(withAliased, descriptor, valueParameter.makeRef())
function.addStatement(assignment.makeStmt())
}