TODO fixes
This commit is contained in:
@@ -51,11 +51,11 @@ public abstract class TranslationTest extends BaseTest {
|
||||
|
||||
public void translateFile(@NotNull String inputFile,
|
||||
@NotNull String outputFile) throws Exception {
|
||||
traslateFiles(Collections.singletonList(inputFile), outputFile);
|
||||
translateFiles(Collections.singletonList(inputFile), outputFile);
|
||||
}
|
||||
|
||||
public void traslateFiles(@NotNull List<String> inputFiles,
|
||||
@NotNull String outputFile) throws Exception {
|
||||
public void translateFiles(@NotNull List<String> inputFiles,
|
||||
@NotNull String outputFile) throws Exception {
|
||||
K2JSTranslator translator = new K2JSTranslator(new TestConfig(getProject()));
|
||||
List<JetFile> psiFiles = createPsiFileList(inputFiles, getProject());
|
||||
JsProgram program = translator.generateProgram(psiFiles);
|
||||
@@ -158,8 +158,8 @@ public abstract class TranslationTest extends BaseTest {
|
||||
fullFilePaths.add(getInputFilePath(dirName) + "/" + fileName);
|
||||
}
|
||||
assert dir.isDirectory();
|
||||
traslateFiles(fullFilePaths,
|
||||
getOutputFilePath(dirName + ".kt"));
|
||||
translateFiles(fullFilePaths,
|
||||
getOutputFilePath(dirName + ".kt"));
|
||||
}
|
||||
|
||||
protected List<String> generateFilenameList(String inputFile) {
|
||||
|
||||
-1
@@ -38,7 +38,6 @@ import static org.jetbrains.k2js.translate.utils.PsiUtils.getLoopRange;
|
||||
*/
|
||||
public final class RangeForTranslator extends ForTranslator {
|
||||
|
||||
//TODO: inspection
|
||||
@NotNull
|
||||
public static JsStatement doTranslate(@NotNull JetForExpression expression,
|
||||
@NotNull TranslationContext context) {
|
||||
|
||||
+16
-9
@@ -19,6 +19,7 @@ package org.jetbrains.k2js.translate.initializer;
|
||||
import com.google.dart.compiler.backend.js.ast.*;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.descriptors.ConstructorDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.PropertyDescriptor;
|
||||
import org.jetbrains.jet.lang.psi.JetClassOrObject;
|
||||
@@ -27,15 +28,15 @@ import org.jetbrains.jet.lang.psi.JetDelegatorToSuperCall;
|
||||
import org.jetbrains.jet.lang.psi.JetParameter;
|
||||
import org.jetbrains.k2js.translate.context.Namer;
|
||||
import org.jetbrains.k2js.translate.context.TranslationContext;
|
||||
import org.jetbrains.k2js.translate.utils.PsiUtils;
|
||||
import org.jetbrains.k2js.translate.utils.TranslationUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static org.jetbrains.k2js.translate.utils.BindingUtils.*;
|
||||
import static org.jetbrains.k2js.translate.utils.JsAstUtils.*;
|
||||
import static org.jetbrains.k2js.translate.utils.PsiUtils.getPrimaryConstructorParameters;
|
||||
import static org.jetbrains.k2js.translate.utils.TranslationUtils.assignmentToBackingField;
|
||||
import static org.jetbrains.k2js.translate.utils.TranslationUtils.translateArgumentList;
|
||||
|
||||
/**
|
||||
* @author Pavel Talanov
|
||||
@@ -57,9 +58,10 @@ public final class ClassInitializerTranslator extends AbstractInitializerTransla
|
||||
@Override
|
||||
@NotNull
|
||||
protected JsFunction generateInitializerFunction() {
|
||||
//TODO: look for duplication of this code
|
||||
JsFunction result = new JsFunction(initializerMethodScope.jsScope());
|
||||
//NOTE: that while we translateAsLocalNameReference constructor parameters we also add property initializer statements
|
||||
//TODO: it's inconsistent that we scope for class and function for constructor, currently have problems implementing better way
|
||||
ConstructorDescriptor primaryConstructor = getConstructor();
|
||||
JsFunction result = context().getFunctionObject(primaryConstructor);
|
||||
//NOTE: while we translate constructor parameters we also add property initializer statements
|
||||
// for properties declared as constructor parameters
|
||||
setParameters(result, translatePrimaryConstructorParameters());
|
||||
mayBeAddCallToSuperMethod();
|
||||
@@ -67,6 +69,13 @@ public final class ClassInitializerTranslator extends AbstractInitializerTransla
|
||||
return result;
|
||||
}
|
||||
|
||||
private ConstructorDescriptor getConstructor() {
|
||||
ConstructorDescriptor primaryConstructor =
|
||||
getClassDescriptor(context().bindingContext(), classDeclaration).getUnsubstitutedPrimaryConstructor();
|
||||
assert primaryConstructor != null : "Traits do not have initialize methods.";
|
||||
return primaryConstructor;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private JsBlock generateInitializerMethodBody() {
|
||||
initializerStatements.addAll(translateClassInitializers(classDeclaration));
|
||||
@@ -91,8 +100,7 @@ public final class ClassInitializerTranslator extends AbstractInitializerTransla
|
||||
|
||||
@NotNull
|
||||
private List<JsExpression> translateArguments(@NotNull JetDelegatorToSuperCall superCall) {
|
||||
//TODO: use the same mechanism as in call translator
|
||||
return TranslationUtils.translateArgumentList(context(), superCall.getValueArguments());
|
||||
return translateArgumentList(context(), superCall.getValueArguments());
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@@ -103,13 +111,12 @@ public final class ClassInitializerTranslator extends AbstractInitializerTransla
|
||||
result = (JetDelegatorToSuperCall) specifier;
|
||||
}
|
||||
}
|
||||
//assert result != null : "Class must call ancestor's constructor.";
|
||||
return result;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
List<JsParameter> translatePrimaryConstructorParameters() {
|
||||
List<JetParameter> parameterList = PsiUtils.getPrimaryConstructorParameters(classDeclaration);
|
||||
List<JetParameter> parameterList = getPrimaryConstructorParameters(classDeclaration);
|
||||
List<JsParameter> result = new ArrayList<JsParameter>();
|
||||
for (JetParameter jetParameter : parameterList) {
|
||||
result.add(translateParameter(jetParameter));
|
||||
|
||||
+1
@@ -40,6 +40,7 @@ public final class NamespaceInitializerTranslator extends AbstractInitializerTra
|
||||
@Override
|
||||
@NotNull
|
||||
protected JsFunction generateInitializerFunction() {
|
||||
//NOTE: namespace has no constructor
|
||||
JsFunction result = new JsFunction(initializerMethodScope.jsScope());
|
||||
result.setBody(newBlock(translateNamespaceInitializers(namespace)));
|
||||
return result;
|
||||
|
||||
-1
@@ -30,7 +30,6 @@ public final class BuiltInPropertyIntrinsic implements Intrinsic {
|
||||
@NotNull TranslationContext context) {
|
||||
assert receiver != null;
|
||||
assert arguments.isEmpty() : "Length expression must have zero arguments.";
|
||||
//TODO: provide better way
|
||||
JsNameRef lengthProperty = AstUtil.newQualifiedNameRef(propertyName);
|
||||
setQualifier(lengthProperty, receiver);
|
||||
return lengthProperty;
|
||||
|
||||
+1
-2
@@ -52,8 +52,7 @@ public final class PrimitiveRangeToIntrinsic implements Intrinsic {
|
||||
JsBinaryOperation rangeSize = sum(subtract(rangeEnd, rangeStart),
|
||||
context.program().getNumberLiteral(1));
|
||||
//TODO: provide a way not to hard code this value
|
||||
JsNew numberRangeConstructorInvocation
|
||||
= new JsNew(AstUtil.newQualifiedNameRef("Kotlin.NumberRange"));
|
||||
JsNew numberRangeConstructorInvocation = new JsNew(AstUtil.newQualifiedNameRef("Kotlin.NumberRange"));
|
||||
//TODO: add tests and correct expression for reversed ranges.
|
||||
JsBooleanLiteral isRangeReversed = context.program().getFalseLiteral();
|
||||
setArguments(numberRangeConstructorInvocation, rangeStart, rangeSize, isRangeReversed);
|
||||
|
||||
@@ -77,13 +77,6 @@ public final class BindingUtils {
|
||||
return getDescriptorForExpression(context, declaration, FunctionDescriptor.class);
|
||||
}
|
||||
|
||||
//TODO:
|
||||
@NotNull
|
||||
public static PropertyAccessorDescriptor getPropertyAccessorDescriptor(@NotNull BindingContext context,
|
||||
@NotNull JetPropertyAccessor declaration) {
|
||||
return getDescriptorForExpression(context, declaration, PropertyAccessorDescriptor.class);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static PropertyDescriptor getPropertyDescriptor(@NotNull BindingContext context,
|
||||
@NotNull JetProperty declaration) {
|
||||
|
||||
Reference in New Issue
Block a user