Fix exception from data class codegen for light classes

EA-66827
This commit is contained in:
Alexander Udalov
2015-09-09 18:10:51 +03:00
parent 47b8853051
commit a946f787bc
7 changed files with 74 additions and 112 deletions
@@ -18,7 +18,6 @@ package org.jetbrains.kotlin.js.translate.declaration;
import com.google.dart.compiler.backend.js.ast.*;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.kotlin.backend.common.CodegenUtil;
import org.jetbrains.kotlin.backend.common.DataClassMethodGenerator;
import org.jetbrains.kotlin.descriptors.*;
import org.jetbrains.kotlin.js.translate.context.Namer;
@@ -31,9 +30,6 @@ import org.jetbrains.kotlin.resolve.descriptorUtil.DescriptorUtilPackage;
import java.util.ArrayList;
import java.util.List;
import static kotlin.KotlinPackage.first;
import static org.jetbrains.kotlin.resolve.descriptorUtil.DescriptorUtilPackage.getBuiltIns;
class JsDataClassGenerator extends DataClassMethodGenerator {
private final TranslationContext context;
private final List<? super JsPropertyInitializer> output;
@@ -91,11 +87,10 @@ class JsDataClassGenerator extends DataClassMethodGenerator {
}
@Override
public void generateToStringMethod(@NotNull List<PropertyDescriptor> classProperties) {
public void generateToStringMethod(@NotNull FunctionDescriptor function, @NotNull List<PropertyDescriptor> classProperties) {
// TODO: relax this limitation, with the data generation logic fixed.
assert !classProperties.isEmpty();
FunctionDescriptor prototypeFun = CodegenUtil.getAnyToStringMethod(getBuiltIns(first(classProperties)));
JsFunction functionObj = generateJsMethod(prototypeFun);
JsFunction functionObj = generateJsMethod(function);
JsProgram jsProgram = context.program();
JsExpression result = null;
@@ -118,9 +113,8 @@ class JsDataClassGenerator extends DataClassMethodGenerator {
}
@Override
public void generateHashCodeMethod(@NotNull List<PropertyDescriptor> classProperties) {
FunctionDescriptor prototypeFun = CodegenUtil.getAnyHashCodeMethod(getBuiltIns(first(classProperties)));
JsFunction functionObj = generateJsMethod(prototypeFun);
public void generateHashCodeMethod(@NotNull FunctionDescriptor function, @NotNull List<PropertyDescriptor> classProperties) {
JsFunction functionObj = generateJsMethod(function);
JsProgram jsProgram = context.program();
List<JsStatement> statements = functionObj.getBody().getStatements();
@@ -144,10 +138,9 @@ class JsDataClassGenerator extends DataClassMethodGenerator {
}
@Override
public void generateEqualsMethod(@NotNull List<PropertyDescriptor> classProperties) {
public void generateEqualsMethod(@NotNull FunctionDescriptor function, @NotNull List<PropertyDescriptor> classProperties) {
assert !classProperties.isEmpty();
FunctionDescriptor prototypeFun = CodegenUtil.getAnyEqualsMethod(getBuiltIns(first(classProperties)));
JsFunction functionObj = generateJsMethod(prototypeFun);
JsFunction functionObj = generateJsMethod(function);
JsFunctionScope funScope = functionObj.getScope();
JsName paramName = funScope.declareName("other");