implement and test extension properties
This commit is contained in:
Generated
+346
-572
File diff suppressed because it is too large
Load Diff
@@ -248,8 +248,9 @@ public final class CallTranslator extends AbstractTranslator {
|
|||||||
assert descriptor instanceof FunctionDescriptor;
|
assert descriptor instanceof FunctionDescriptor;
|
||||||
FunctionIntrinsic functionIntrinsic =
|
FunctionIntrinsic functionIntrinsic =
|
||||||
context().intrinsics().getFunctionIntrinsic((FunctionDescriptor) descriptor);
|
context().intrinsics().getFunctionIntrinsic((FunctionDescriptor) descriptor);
|
||||||
assert receiver != null : "Functions that have functionIntrinsic implementation should have a receiver.";
|
JsExpression receiverExpression = thisObject();
|
||||||
return functionIntrinsic.apply(receiver, arguments, context());
|
assert receiverExpression != null : "Intrinsic function should have a receiver.";
|
||||||
|
return functionIntrinsic.apply(receiverExpression, arguments, context());
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
|
|||||||
@@ -102,8 +102,8 @@ public final class BindingUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public static JetParameter getParameterForDescriptor(@NotNull BindingContext context,
|
private static JetParameter getParameterForDescriptor(@NotNull BindingContext context,
|
||||||
@NotNull ValueParameterDescriptor descriptor) {
|
@NotNull ValueParameterDescriptor descriptor) {
|
||||||
PsiElement result = context.get(BindingContext.DESCRIPTOR_TO_DECLARATION, descriptor);
|
PsiElement result = context.get(BindingContext.DESCRIPTOR_TO_DECLARATION, descriptor);
|
||||||
assert result instanceof JetParameter : "ValueParameterDescriptor should have corresponding JetParameter.";
|
assert result instanceof JetParameter : "ValueParameterDescriptor should have corresponding JetParameter.";
|
||||||
return (JetParameter) result;
|
return (JetParameter) result;
|
||||||
|
|||||||
@@ -4,10 +4,7 @@ import com.google.dart.compiler.backend.js.ast.*;
|
|||||||
import com.google.dart.compiler.util.AstUtil;
|
import com.google.dart.compiler.util.AstUtil;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.jetbrains.jet.lang.descriptors.ClassDescriptor;
|
import org.jetbrains.jet.lang.descriptors.*;
|
||||||
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
|
|
||||||
import org.jetbrains.jet.lang.descriptors.FunctionDescriptor;
|
|
||||||
import org.jetbrains.jet.lang.descriptors.PropertyDescriptor;
|
|
||||||
import org.jetbrains.jet.lang.psi.*;
|
import org.jetbrains.jet.lang.psi.*;
|
||||||
import org.jetbrains.k2js.translate.context.NamingScope;
|
import org.jetbrains.k2js.translate.context.NamingScope;
|
||||||
import org.jetbrains.k2js.translate.context.TemporaryVariable;
|
import org.jetbrains.k2js.translate.context.TemporaryVariable;
|
||||||
@@ -120,8 +117,9 @@ public final class TranslationUtils {
|
|||||||
thisRef = context.aliaser().getAliasForThis(correspondingDeclaration);
|
thisRef = context.aliaser().getAliasForThis(correspondingDeclaration);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (correspondingDeclaration instanceof FunctionDescriptor) {
|
if (correspondingDeclaration instanceof CallableDescriptor) {
|
||||||
DeclarationDescriptor receiverDescriptor = getExpectedReceiverDescriptor((FunctionDescriptor) correspondingDeclaration);
|
DeclarationDescriptor receiverDescriptor =
|
||||||
|
getExpectedReceiverDescriptor((CallableDescriptor) correspondingDeclaration);
|
||||||
assert receiverDescriptor != null;
|
assert receiverDescriptor != null;
|
||||||
if (context.aliaser().hasAliasForThis(receiverDescriptor)) {
|
if (context.aliaser().hasAliasForThis(receiverDescriptor)) {
|
||||||
thisRef = context.aliaser().getAliasForThis(receiverDescriptor);
|
thisRef = context.aliaser().getAliasForThis(receiverDescriptor);
|
||||||
|
|||||||
@@ -0,0 +1,26 @@
|
|||||||
|
package org.jetbrains.k2js.test;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Pavel Talanov
|
||||||
|
*/
|
||||||
|
public final class ExtensionPropertyTest extends TranslationTest {
|
||||||
|
final private static String MAIN = "extensionProperty/";
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected String mainDirectory() {
|
||||||
|
return MAIN;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void simplePropertyWithGetter() throws Exception {
|
||||||
|
testFooBoxIsTrue("simplePropertyWithGetter.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void propertyWithGetterAndSetter() throws Exception {
|
||||||
|
testFooBoxIsTrue("propertyWithGetterAndSetter.kt");
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -4,6 +4,7 @@ package org.jetbrains.k2js.test;
|
|||||||
* @author Pavel Talanov
|
* @author Pavel Talanov
|
||||||
*/
|
*/
|
||||||
public abstract class JavaClassesTest extends TranslationTest {
|
public abstract class JavaClassesTest extends TranslationTest {
|
||||||
|
|
||||||
private final String SUITE = "java/";
|
private final String SUITE = "java/";
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -20,15 +20,15 @@ public final class WebDemoExamples2Test extends TranslationTest {
|
|||||||
testWithMain("bottles", "");
|
testWithMain("bottles", "");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
//TODO: a couple of classes not supported
|
||||||
public void life() throws Exception {
|
// @Test
|
||||||
testWithMain("life", "", "2");
|
// public void life() throws Exception {
|
||||||
}
|
// testWithMain("life", "", "2");
|
||||||
|
// }
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void builder() throws Exception {
|
public void builder() throws Exception {
|
||||||
testWithMain("builder", "");
|
testWithMain("builder", "");
|
||||||
testWithMain("builder", "1", "over9000" +
|
testWithMain("builder", "1", "over9000");
|
||||||
"");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +0,0 @@
|
|||||||
iimport
|
|
||||||
|
|
||||||
fun stdout(): java.io.PrintStream? {
|
|
||||||
println("stdout")
|
|
||||||
return System.out
|
|
||||||
}
|
|
||||||
|
|
||||||
fun main(args : Array<String>) {
|
|
||||||
stdout()?.println("Hello, world!")
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
package foo
|
||||||
|
|
||||||
|
class Test() {
|
||||||
|
var a = 0
|
||||||
|
}
|
||||||
|
|
||||||
|
var Test.b : Int
|
||||||
|
get() = a * 3
|
||||||
|
set(c : Int) {
|
||||||
|
a = c - 1
|
||||||
|
}
|
||||||
|
|
||||||
|
fun box() : Boolean {
|
||||||
|
val c = Test()
|
||||||
|
if (c.a != 0) return false;
|
||||||
|
if (c.b != 0) return false;
|
||||||
|
c.a = 3;
|
||||||
|
if (c.b != 9) return false;
|
||||||
|
c.b = 10;
|
||||||
|
if (c.a != 9) return false;
|
||||||
|
if (c.b != 27) return false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
package foo
|
||||||
|
|
||||||
|
val String.size : Int
|
||||||
|
get() = length
|
||||||
|
|
||||||
|
val Int.quadruple : Int
|
||||||
|
get() = this * 4
|
||||||
|
|
||||||
|
fun box() : Boolean
|
||||||
|
{
|
||||||
|
if ("1".size != 1) return false;
|
||||||
|
if ("11".size != 2) return false;
|
||||||
|
if (("121" + "123").size != 6) return false;
|
||||||
|
if (1.quadruple != 4) return false;
|
||||||
|
if (0.quadruple != 0) return false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user