Refactoring.

This commit is contained in:
Pavel Talanov
2011-11-17 22:28:46 +04:00
parent ca57aee040
commit d1c49f80c8
21 changed files with 128 additions and 142 deletions
@@ -272,4 +272,8 @@ public class AstUtil {
public static JsPrefixOperation negated(JsExpression expression) {
return new JsPrefixOperation(JsUnaryOperator.NOT, expression);
}
public static JsStatement newAssignmentStatement(JsNameRef nameRef, JsExpression expr) {
return convertToStatement(new JsBinaryOperation(JsBinaryOperator.ASG, nameRef, expr));
}
}
@@ -61,13 +61,6 @@ public final class BindingUtils {
return getDescriptorForExpression(context, declaration, PropertyDescriptor.class);
}
@NotNull
static public String getPropertyNameForPropertyAccessor(@NotNull BindingContext context,
@NotNull JetPropertyAccessor accessor) {
PropertyAccessorDescriptor descriptor = getPropertyAccessorDescriptor(context, accessor);
return descriptor.getCorrespondingProperty().getName();
}
@NotNull
static public PropertySetterDescriptor getPropertySetterDescriptorForProperty(@NotNull BindingContext context,
@NotNull JetProperty property) {
@@ -153,22 +153,4 @@ public final class ClassBodyVisitor extends TranslatorVisitor<List<JsPropertyIni
// parsed it in initializer visitor => no additional actions are needed
return new ArrayList<JsPropertyInitializer>();
}
// @NotNull
// JsName getNameForGetter(@NotNull String propertyName, @NotNull TranslationContext context) {
// return getNameForAccessor(propertyName, true, context);
// }
//
// @NotNull
// JsName getNameForSetter(@NotNull String propertyName, @NotNull TranslationContext context) {
// return getNameForAccessor(propertyName, false, context);
// }
//
// @NotNull
// JsName getNameForAccessor(@NotNull String propertyName, boolean isGetter,
// @NotNull TranslationContext context) {
// return context.classScope().findExistingName(Namer.getNameForAccessor(propertyName, isGetter));
// }
}
@@ -50,8 +50,8 @@ public final class ClassTranslator extends AbstractTranslator {
@NotNull
private JsStatement classDeclarationStatement(@NotNull JetClass classDeclaration,
@NotNull JsInvocation jsClassDeclaration) {
return AstUtil.convertToStatement(AstUtil.newAssignment
(namespaceQualifiedClassNameReference(classDeclaration), jsClassDeclaration));
return AstUtil.newAssignmentStatement
(namespaceQualifiedClassNameReference(classDeclaration), jsClassDeclaration);
}
@NotNull
@@ -61,7 +61,7 @@ public final class ExpressionVisitor extends TranslatorVisitor<JsNode> {
@NotNull TranslationContext context) {
JetExpression returnedExpression = jetReturnExpression.getReturnedExpression();
if (returnedExpression != null) {
JsExpression jsExpression = AstUtil.convertToExpression(returnedExpression.accept(this, context));
JsExpression jsExpression = translateAsExpression(returnedExpression, context);
return new JsReturn(jsExpression);
}
return new JsReturn();
@@ -166,12 +166,11 @@ public final class ExpressionVisitor extends TranslatorVisitor<JsNode> {
@NotNull
private JsExpression translateCallee(@NotNull JetCallExpression expression, @NotNull TranslationContext context) {
JetExpression jetCallee = expression.getCalleeExpression();
if (jetCallee == null) {
JetExpression callee = expression.getCalleeExpression();
if (callee == null) {
throw new AssertionError("Call expression with no callee encountered!");
}
JsNode jsCallee = jetCallee.accept(this, context);
return AstUtil.convertToExpression(jsCallee);
return translateAsExpression(callee, context);
}
@Override
@@ -227,9 +226,9 @@ public final class ExpressionVisitor extends TranslatorVisitor<JsNode> {
@NotNull
private JsExpression translateConditionExpression(@Nullable JetExpression expression,
@NotNull TranslationContext context) {
JsNode jsCondition = translateNullableExpression(expression, context);
if (jsCondition == context.program().getEmptyStmt()) {
throw new AssertionError("Empty condition clause!");
JsExpression jsCondition = translateNullableExpression(expression, context);
if (jsCondition == null) {
throw new AssertionError("Empty condition!");
}
return AstUtil.convertToExpression(jsCondition);
}
@@ -240,6 +239,10 @@ public final class ExpressionVisitor extends TranslatorVisitor<JsNode> {
if (expression == null) {
return null;
}
return translateAsExpression(expression, context);
}
private JsExpression translateAsExpression(JetExpression expression, TranslationContext context) {
return AstUtil.convertToExpression(expression.accept(this, context));
}
@@ -286,7 +289,6 @@ public final class ExpressionVisitor extends TranslatorVisitor<JsNode> {
return null;
}
//TODO method too long
@Override
@NotNull
public JsNode visitDotQualifiedExpression(@NotNull JetDotQualifiedExpression expression,
@@ -295,8 +297,8 @@ public final class ExpressionVisitor extends TranslatorVisitor<JsNode> {
}
@NotNull
private JsNode translateQualifiedExpression(@NotNull JetQualifiedExpression expression,
@NotNull TranslationContext context) {
private JsExpression translateQualifiedExpression(@NotNull JetQualifiedExpression expression,
@NotNull TranslationContext context) {
JsInvocation getterCall = translateAsGetterCall(expression, context);
if (getterCall != null) {
return getterCall;
@@ -311,8 +313,8 @@ public final class ExpressionVisitor extends TranslatorVisitor<JsNode> {
}
@NotNull
private JsNode translateAsQualifiedAccess(@NotNull JetQualifiedExpression expression,
@NotNull TranslationContext context) {
private JsExpression translateAsQualifiedAccess(@NotNull JetQualifiedExpression expression,
@NotNull TranslationContext context) {
JsExpression receiver = translateReceiver(expression, context);
JsExpression selector = translateSelector(expression, context);
assert (selector instanceof JsNameRef || selector instanceof JsInvocation)
@@ -329,23 +331,23 @@ public final class ExpressionVisitor extends TranslatorVisitor<JsNode> {
@NotNull TranslationContext context) {
JetExpression jetSelector = expression.getSelectorExpression();
assert jetSelector != null : "Selector should not be null in dot qualified expression.";
return AstUtil.convertToExpression(jetSelector.accept(this, context));
return translateAsExpression(jetSelector, context);
}
@NotNull
private JsExpression translateReceiver(@NotNull JetQualifiedExpression expression,
@NotNull TranslationContext context) {
return AstUtil.convertToExpression(expression.getReceiverExpression().accept(this, context));
return translateAsExpression(expression.getReceiverExpression(), context);
}
@NotNull
private JsNode translateAsQualifiedNameReference(@NotNull JsExpression receiver, @NotNull JsNameRef selector) {
private JsExpression translateAsQualifiedNameReference(@NotNull JsExpression receiver, @NotNull JsNameRef selector) {
selector.setQualifier(receiver);
return selector;
}
@NotNull
private JsNode translateAsQualifiedInvocation(@NotNull JsExpression receiver, @NotNull JsInvocation selector) {
private JsExpression translateAsQualifiedInvocation(@NotNull JsExpression receiver, @NotNull JsInvocation selector) {
JsExpression qualifier = selector.getQualifier();
JsNameRef nameRef = (JsNameRef) qualifier;
nameRef.setQualifier(receiver);
@@ -382,7 +384,7 @@ public final class ExpressionVisitor extends TranslatorVisitor<JsNode> {
JsNullLiteral nullLiteral = context.program().getNullLiteral();
JsBinaryOperation nullCheck = new JsBinaryOperation
(JsBinaryOperator.NEQ, receiver, nullLiteral);
JsExpression thenExpression = AstUtil.convertToExpression(translateQualifiedExpression(expression, context));
JsExpression thenExpression = translateQualifiedExpression(expression, context);
return new JsConditional(nullCheck, thenExpression, nullLiteral);
}
@@ -28,8 +28,8 @@ public final class FunctionTranslator extends AbstractTranslator {
public JsStatement translateAsFunction(@NotNull JetNamedFunction jetFunction) {
JsName functionName = translationContext().namespaceScope().declareFreshName(jetFunction.getName());
JsFunction function = generateFunctionObject(jetFunction);
return AstUtil.convertToStatement(AstUtil.newAssignment
(translationContext().getNamespaceQualifiedReference(functionName), function));
return AstUtil.newAssignmentStatement
(translationContext().getNamespaceQualifiedReference(functionName), function);
}
@NotNull
@@ -55,12 +55,11 @@ public final class FunctionTranslator extends AbstractTranslator {
JetExpression jetBodyExpression = jetFunction.getBodyExpression();
//TODO support them ffs
assert jetBodyExpression != null : "Function without body not supported at the moment";
JsNode body = Translation.expressionTranslator
(translationContext().newFunction(jetFunction)).translate(jetBodyExpression);
JsNode body = Translation.translateExpression(jetBodyExpression, translationContext().newFunction(jetFunction));
if (jetFunction.hasBlockBody()) {
return AstUtil.convertToBlock(body);
}
return AstUtil.convertToBlock(new JsReturn(AstUtil.convertToExpression((body))));
return AstUtil.convertToBlock(new JsReturn(AstUtil.convertToExpression(body)));
}
@NotNull
@@ -121,8 +121,7 @@ public class InitializerVisitor extends TranslatorVisitor<List<JsStatement>> {
@NotNull
private JsStatement translateInitializer(@NotNull JetProperty property, @NotNull TranslationContext context,
@NotNull JetExpression initializer) {
JsExpression initExpression = AstUtil.convertToExpression(Translation.expressionTranslator(context)
.translate(initializer));
JsExpression initExpression = Translation.translateAsExpression(initializer, context);
return assignmentToBackingField(property, initExpression, context);
}
@@ -134,15 +133,14 @@ public class InitializerVisitor extends TranslatorVisitor<List<JsStatement>> {
JsName backingFieldName = getBackingFieldName(propertyName, context);
JsNameRef backingFieldRef = backingFieldName.makeRef();
backingFieldRef.setQualifier(new JsThisRef());
return AstUtil.convertToStatement(AstUtil.newAssignment(backingFieldRef, initExpression));
return AstUtil.newAssignmentStatement(backingFieldRef, initExpression);
}
@Override
@NotNull
public List<JsStatement> visitAnonymousInitializer(@NotNull JetClassInitializer initializer,
@NotNull TranslationContext context) {
return Arrays.asList(AstUtil.convertToStatement
(Translation.expressionTranslator(context).translate(initializer.getBody())));
return Arrays.asList(Translation.translateAsStatement(initializer.getBody(), context));
}
@Override
@@ -7,16 +7,16 @@ import org.jetbrains.jet.lang.psi.JetDeclaration;
/**
* @author Talanov Pavel
*/
public final class DeclarationTranslator extends AbstractTranslator {
public final class NamespaceDeclarationTranslator extends AbstractTranslator {
private DeclarationVisitor visitor = new DeclarationVisitor();
private NamespaceDeclarationVisitor visitor = new NamespaceDeclarationVisitor();
@NotNull
public static DeclarationTranslator newInstance(@NotNull TranslationContext context) {
return new DeclarationTranslator(context);
public static NamespaceDeclarationTranslator newInstance(@NotNull TranslationContext context) {
return new NamespaceDeclarationTranslator(context);
}
private DeclarationTranslator(TranslationContext context) {
private NamespaceDeclarationTranslator(TranslationContext context) {
super(context);
}
@@ -14,7 +14,7 @@ import org.jetbrains.jet.lang.psi.JetProperty;
* @author Talanov Pavel
*/
//TODO: rework the class
public class DeclarationVisitor extends TranslatorVisitor<JsStatement> {
public class NamespaceDeclarationVisitor extends TranslatorVisitor<JsStatement> {
@NotNull
@Override
@@ -39,23 +39,24 @@ public final class NamespaceTranslator extends AbstractTranslator {
JsFunction dummyFunction = JsFunction.getAnonymousFunctionWithScope
(translationContext().getScopeForElement(namespace));
JsBlock namespaceDeclarations = translateDeclarations(namespace, newContext);
block.addStatement(AstUtil.convertToStatement(newNamespace(namespaceName, namespaceDeclarations, dummyFunction)));
JsInvocation namespaceExpression = newNamespace(namespaceName, namespaceDeclarations, dummyFunction);
block.addStatement(AstUtil.convertToStatement(namespaceExpression));
return block;
}
@NotNull
private JsBlock translateDeclarations(@NotNull JetNamespace namespace, @NotNull TranslationContext newContext) {
DeclarationTranslator declarationTranslator = Translation.declarationTranslator(newContext);
NamespaceDeclarationTranslator namespaceDeclarationTranslator = Translation.declarationTranslator(newContext);
JsBlock namespaceDeclarations = new JsBlock();
for (JetDeclaration declaration : namespace.getDeclarations()) {
namespaceDeclarations.addStatement(declarationTranslator.translateDeclaration(declaration));
namespaceDeclarations.addStatement(namespaceDeclarationTranslator.translateDeclaration(declaration));
}
return namespaceDeclarations;
}
@NotNull
private JsStatement namespaceInitStatement(@NotNull JsName namespaceName) {
return AstUtil.convertToStatement(AstUtil.newAssignment(namespaceName.makeRef(), new JsObjectLiteral()));
return AstUtil.newAssignmentStatement(namespaceName.makeRef(), new JsObjectLiteral());
}
@NotNull
@@ -1,7 +1,6 @@
package org.jetbrains.k2js.translate;
import com.google.dart.compiler.backend.js.ast.*;
import com.google.dart.compiler.util.AstUtil;
import com.intellij.psi.tree.IElementType;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -42,8 +41,7 @@ public final class OperationTranslator extends AbstractTranslator {
private JsExpression translateBaseExpression(@NotNull JetUnaryExpression expression) {
JetExpression baseExpression = expression.getBaseExpression();
assert baseExpression != null : "Unary operation should have a base expression";
return AstUtil.convertToExpression
(Translation.translateExpression(baseExpression, translationContext()));
return Translation.translateAsExpression(baseExpression, translationContext());
}
@NotNull
@@ -63,6 +61,7 @@ public final class OperationTranslator extends AbstractTranslator {
return translateAsBinaryOperation(expression);
}
//TODO: think about the ways to improve logic here
@Nullable
public JsInvocation translateAsSetterCall(@NotNull JetBinaryExpression expression) {
JetToken jetOperationToken = getOperationToken(expression);
@@ -82,8 +81,7 @@ public final class OperationTranslator extends AbstractTranslator {
@NotNull
private JsExpression translateAsBinaryOperation(@NotNull JetBinaryExpression expression) {
JsExpression left = AstUtil.convertToExpression
(Translation.translateExpression(expression.getLeft(), translationContext()));
JsExpression left = Translation.translateAsExpression(expression.getLeft(), translationContext());
JsExpression right = translateRightExpression(expression);
JetToken token = getOperationToken(expression);
if (OperatorTable.hasCorrespondingBinaryOperator(token)) {
@@ -101,8 +99,7 @@ public final class OperationTranslator extends AbstractTranslator {
private JsExpression translateRightExpression(@NotNull JetBinaryExpression expression) {
JetExpression rightExpression = expression.getRight();
assert rightExpression != null : "Binary expression should have a right expression";
return AstUtil.convertToExpression
(Translation.translateExpression(rightExpression, translationContext()));
return Translation.translateAsExpression(rightExpression, translationContext());
}
@NotNull
@@ -55,38 +55,34 @@ public final class OperatorTable {
operatorToFunctionNameReference.put(JetTokens.IS_KEYWORD, Namer.isOperationReference());
}
@NotNull
public static boolean hasCorrespondingBinaryOperator(@NotNull JetToken token) {
return binaryOperatorsMap.containsKey(token);
}
@NotNull
static boolean hasCorrespondingFunctionInvocation(@NotNull JetToken token) {
return operatorToFunctionNameReference.containsKey(token);
}
@NotNull
public static JsInvocation getCorrespondingFunctionInvocation(@NotNull JetToken token) {
static public JsInvocation getCorrespondingFunctionInvocation(@NotNull JetToken token) {
JsNameRef functionReference = operatorToFunctionNameReference.get(token);
assert functionReference != null : "Token should represent a function call!";
return AstUtil.newInvocation(functionReference);
}
@NotNull
public static JsBinaryOperator getBinaryOperator(@NotNull JetToken token) {
static public JsBinaryOperator getBinaryOperator(@NotNull JetToken token) {
assert JetTokens.OPERATIONS.contains(token) : "Token should represent an operation!";
return binaryOperatorsMap.get(token);
}
@NotNull
public static JsUnaryOperator getUnaryOperator(@NotNull JetToken token) {
static public JsUnaryOperator getUnaryOperator(@NotNull JetToken token) {
assert JetTokens.OPERATIONS.contains(token) : "Token should represent an operation!";
return unaryOperatorsMap.get(token);
}
public static boolean isAssignment(JetToken token) {
static public boolean isAssignment(JetToken token) {
return (token == JetTokens.EQ);
}
}
@@ -9,7 +9,6 @@ import org.jetbrains.jet.lang.psi.*;
/**
* @author Talanov Pavel
*/
//TODO: fix members order
public final class PatternTranslator extends AbstractTranslator {
@NotNull
@@ -21,24 +20,9 @@ public final class PatternTranslator extends AbstractTranslator {
super(context);
}
// @NotNull
// public JsExpression translate(@NotNull JetBinaryExpressionWithTypeRHS expression) {
// JsExpression left = AstUtil.convertToExpression
// (Translation.translateExpression(expression.getLeft(), translationContext()));
// JsNameRef right = getClassReference(expression);
// JetToken token = getOperationToken(expression);
// if (OperatorTable.hasCorrespondingFunctionInvocation(token)) {
// JsInvocation functionInvocation = OperatorTable.getCorrespondingFunctionInvocation(token);
// functionInvocation.setArguments(Arrays.asList(left, right));
// return functionInvocation;
// }
// throw new AssertionError("Unsupported token encountered: " + token.toString());
// }
@NotNull
public JsExpression translateIsExpression(@NotNull JetIsExpression expression) {
JsExpression left = AstUtil.convertToExpression
(Translation.translateExpression(expression.getLeftHandSide(), translationContext()));
JsExpression left = Translation.translateAsExpression(expression.getLeftHandSide(), translationContext());
JetPattern pattern = getPattern(expression);
JsExpression resultingExpression = translatePattern(pattern, left);
if (expression.isNegated()) {
@@ -47,6 +31,13 @@ public final class PatternTranslator extends AbstractTranslator {
return resultingExpression;
}
@NotNull
private JetPattern getPattern(@NotNull JetIsExpression expression) {
JetPattern pattern = expression.getPattern();
assert pattern != null : "Pattern should not be null";
return pattern;
}
@NotNull
public JsExpression translatePattern(@NotNull JetPattern pattern, @NotNull JsExpression expressionToMatch) {
if (pattern instanceof JetTypePattern) {
@@ -58,23 +49,6 @@ public final class PatternTranslator extends AbstractTranslator {
throw new AssertionError("Unsupported pattern type " + pattern.getClass());
}
@NotNull
private JsExpression translateExpressionPattern(JsExpression expressionToMatch, JetExpressionPattern pattern) {
JetExpression patternExpression = pattern.getExpression();
assert patternExpression != null : "Expression patter should have an expression.";
JsExpression expressionToMatchAgainst =
Translation.translateAsExpression(patternExpression, translationContext());
//TODO: should call equals method here
return new JsBinaryOperation(JsBinaryOperator.REF_EQ, expressionToMatch, expressionToMatchAgainst);
}
@NotNull
private JetPattern getPattern(@NotNull JetIsExpression expression) {
JetPattern pattern = expression.getPattern();
assert pattern != null : "Pattern should not be null";
return pattern;
}
@NotNull
private JsExpression translateTypePattern(@NotNull JsExpression expressionToMatch,
@NotNull JetTypePattern pattern) {
@@ -88,13 +62,6 @@ public final class PatternTranslator extends AbstractTranslator {
return getClassNameReferenceForTypeReference(typeReference);
}
// @NotNull
// private JsNameRef getClassReference(@NotNull JetBinaryExpressionWithTypeRHS expression) {
// JetTypeReference typeReference = expression.getRight();
// assert typeReference != null : "Binary type expression should have a right expression";
// return getClassNameReferenceForTypeReference(typeReference);
// }
@NotNull
private JsNameRef getClassNameReferenceForTypeReference(@NotNull JetTypeReference typeReference) {
ClassDescriptor referencedClass = BindingUtils.getClassDescriptorForTypeReference
@@ -104,13 +71,13 @@ public final class PatternTranslator extends AbstractTranslator {
return translationContext().getNamespaceQualifiedReference(className);
}
// @NotNull
// private JetToken getOperationToken(@NotNull JetBinaryExpressionWithTypeRHS expression) {
// JetSimpleNameExpression operationExpression = expression.getOperationSign();
// IElementType elementType = operationExpression.getReferencedNameElementType();
// assert elementType instanceof JetToken : "Binary type operation should have IElementType of type JetToken";
// return (JetToken) elementType;
// }
@NotNull
private JsExpression translateExpressionPattern(JsExpression expressionToMatch, JetExpressionPattern pattern) {
JetExpression patternExpression = pattern.getExpression();
assert patternExpression != null : "Expression patter should have an expression.";
JsExpression expressionToMatchAgainst =
Translation.translateAsExpression(patternExpression, translationContext());
//TODO: should call equals method here
return new JsBinaryOperation(JsBinaryOperator.REF_EQ, expressionToMatch, expressionToMatchAgainst);
}
}
@@ -1,9 +1,9 @@
package org.jetbrains.k2js.translate;
import com.google.dart.compiler.backend.js.ast.JsExpression;
import com.google.dart.compiler.backend.js.ast.JsInvocation;
import com.google.dart.compiler.backend.js.ast.JsName;
import com.google.dart.compiler.backend.js.ast.JsNameRef;
import com.google.dart.compiler.backend.js.ast.JsNode;
import com.google.dart.compiler.util.AstUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -56,10 +56,10 @@ public final class PropertyAccessTranslator extends AbstractTranslator {
@NotNull
private JsInvocation translateReceiverAndReturnAccessorInvocation
(@NotNull JetQualifiedExpression qualifiedExpression, @NotNull JsName accessorName) {
JsNode node = Translation.expressionTranslator(translationContext())
.translate(qualifiedExpression.getReceiverExpression());
JsExpression qualifier = Translation.translateAsExpression
(qualifiedExpression.getReceiverExpression(), translationContext());
JsNameRef result = accessorName.makeRef();
result.setQualifier(AstUtil.convertToExpression(node));
result.setQualifier(qualifier);
return AstUtil.newInvocation(result);
}
@@ -46,8 +46,8 @@ public final class Translation {
}
@NotNull
static public DeclarationTranslator declarationTranslator(@NotNull TranslationContext context) {
return DeclarationTranslator.newInstance(context);
static public NamespaceDeclarationTranslator declarationTranslator(@NotNull TranslationContext context) {
return NamespaceDeclarationTranslator.newInstance(context);
}
@NotNull
@@ -60,7 +60,6 @@ public final class Translation {
return expressionTranslator(context).translate(expression);
}
//TODO: clean out similar code fragments
@NotNull
static public JsExpression translateAsExpression(@NotNull JetExpression expression, @NotNull TranslationContext context) {
return AstUtil.convertToExpression(translateExpression(expression, context));
@@ -2,7 +2,6 @@ package org.jetbrains.k2js.translate;
import com.google.dart.compiler.backend.js.ast.JsExpression;
import com.google.dart.compiler.backend.js.ast.JsName;
import com.google.dart.compiler.util.AstUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.lang.psi.*;
@@ -45,8 +44,7 @@ public class TranslatorVisitor<T> extends JetVisitor<T, TranslationContext> {
JsExpression jsInitExpression = null;
JetExpression initializer = declaration.getInitializer();
if (initializer != null) {
jsInitExpression = AstUtil.convertToExpression(Translation.expressionTranslator(context)
.translate(initializer));
jsInitExpression = Translation.translateAsExpression(initializer, context);
}
return jsInitExpression;
}
@@ -67,6 +65,6 @@ public class TranslatorVisitor<T> extends JetVisitor<T, TranslationContext> {
if (jetExpression == null) {
throw new AssertionError("Argument with no expression encountered!");
}
return AstUtil.convertToExpression(Translation.translateExpression(jetExpression, context));
return Translation.translateAsExpression(jetExpression, context);
}
}
@@ -24,7 +24,7 @@ public class BasicClassTest extends IncludeLibraryTest {
testFooBoxIsTrue("methodDeclarationAndCall.kt");
}
//TODO: test excluded. Wait for bugfix and implement functionality
//TODO: wait for bugfix and implement properties as consructor parameter declaration
@Test
public void constructorWithParameter() throws Exception {
testFooBoxIsTrue("constructorWithParameter.kt");
@@ -44,4 +44,9 @@ public final class PatternMatchingTest extends IncludeLibraryTest {
testFooBoxIsTrue("whenValueOrType.kt");
}
@Test
public void multipleCases() throws Exception {
testFooBoxIsTrue("multipleCases.kt");
}
}
@@ -0,0 +1,22 @@
package org.jetbrains.k2js.test;
/**
* @author Talanov Pavel
*/
public class TupleTest extends IncludeLibraryTest {
final private static String MAIN = "tuple/";
@Override
protected String mainDirectory() {
return MAIN;
}
//TODO: excluded because Tuples are not implemented
// @Test
// public void twoElements() throws Exception {
// testFooBoxIsTrue("twoElements.kt");
// }
}
@@ -0,0 +1,17 @@
namespace foo
fun box() : Boolean {
val c = 3
val d = 5
var z = 0
when(c) {
is 5, is 3 => z++;
else => z = -1000;
}
when(d) {
is 5, is 3 => z++;
else => z = -1000;
}
return c == 2
}
@@ -0,0 +1,6 @@
namespace foo
fun box() : Boolean {
val a : (Int, Int) = (1, 2)
return (a._1 == 1)
}