JS Backend: fix tests after object refactoring

This commit is contained in:
Alexander Udalov
2013-11-19 23:16:01 +04:00
parent ba693d3e38
commit 97ad75a9f9
3 changed files with 12 additions and 15 deletions
@@ -51,7 +51,6 @@ import static org.jetbrains.k2js.translate.reference.ReferenceTranslator.transla
import static org.jetbrains.k2js.translate.utils.BindingUtils.*;
import static org.jetbrains.k2js.translate.utils.ErrorReportingUtils.message;
import static org.jetbrains.k2js.translate.utils.JsAstUtils.*;
import static org.jetbrains.k2js.translate.utils.PsiUtils.getObjectDeclarationName;
import static org.jetbrains.k2js.translate.utils.TranslationUtils.translateInitializerForProperty;
import static org.jetbrains.k2js.translate.utils.mutator.LastExpressionMutator.mutateLastExpression;
@@ -473,10 +472,9 @@ public final class ExpressionVisitor extends TranslatorVisitor<JsNode> {
@NotNull
public JsNode visitObjectDeclaration(@NotNull JetObjectDeclaration expression,
@NotNull TranslationContext context) {
JetObjectDeclarationName objectDeclarationName = getObjectDeclarationName(expression);
DeclarationDescriptor descriptor = getDescriptorForElement(context.bindingContext(), objectDeclarationName);
JsName propertyName = context.getNameForDescriptor(descriptor);
DeclarationDescriptor descriptor = getDescriptorForElement(context.bindingContext(), expression);
JsName name = context.getNameForDescriptor(descriptor);
JsExpression value = ClassTranslator.generateClassCreation(expression, context);
return newVar(propertyName, value).source(expression);
return newVar(name, value).source(expression);
}
}
@@ -31,6 +31,8 @@ import org.jetbrains.k2js.translate.utils.AnnotationsUtils;
import java.util.Collections;
import java.util.List;
import static org.jetbrains.jet.lang.resolve.DescriptorUtils.isEnumEntry;
import static org.jetbrains.jet.lang.resolve.DescriptorUtils.isObject;
import static org.jetbrains.k2js.translate.reference.ReferenceTranslator.translateAsFQReference;
import static org.jetbrains.k2js.translate.utils.BindingUtils.getDescriptorForReferenceExpression;
@@ -54,7 +56,13 @@ public class ClassObjectAccessTranslator extends AbstractTranslator implements C
private ClassObjectAccessTranslator(@NotNull DeclarationDescriptor descriptor, @NotNull TranslationContext context) {
super(context);
this.referenceToClassObject = Namer.getClassObjectAccessor(translateAsFQReference(descriptor, context()));
JsExpression fqReference = translateAsFQReference(descriptor, context());
if (isObject(descriptor) || isEnumEntry(descriptor)) {
this.referenceToClassObject = fqReference;
}
else {
this.referenceToClassObject = Namer.getClassObjectAccessor(fqReference);
}
}
@Override
@@ -120,19 +120,10 @@ public final class PsiUtils {
return Collections.emptyList();
}
@NotNull
public static JetObjectDeclarationName getObjectDeclarationName(@NotNull JetObjectDeclaration objectDeclaration) {
//TODO: util
JetObjectDeclarationName nameAsDeclaration = objectDeclaration.getNameAsDeclaration();
assert nameAsDeclaration != null;
return nameAsDeclaration;
}
@NotNull
public static JetExpression getLoopRange(@NotNull JetForExpression expression) {
JetExpression rangeExpression = expression.getLoopRange();
assert rangeExpression != null;
return rangeExpression;
}
}