diff --git a/js/js.tests/test/org/jetbrains/k2js/test/TestWithEnvironment.java b/js/js.tests/test/org/jetbrains/k2js/test/TestWithEnvironment.java index bc39f73dccc..b3c3759a642 100644 --- a/js/js.tests/test/org/jetbrains/k2js/test/TestWithEnvironment.java +++ b/js/js.tests/test/org/jetbrains/k2js/test/TestWithEnvironment.java @@ -50,6 +50,6 @@ public abstract class TestWithEnvironment extends UsefulTestCase { } protected void createEnvironmentWithMockJdkAndIdeaAnnotations() { - myEnvironment = JetTestUtils.createEnvironmentWithMockJdkAndIdeaAnnotations(getTestRootDisposable()); + myEnvironment = JetCoreEnvironment.getCoreEnvironmentForJS(getTestRootDisposable()); } } diff --git a/js/js.tests/test/org/jetbrains/k2js/test/semantics/ClosureTest.java b/js/js.tests/test/org/jetbrains/k2js/test/semantics/ClosureTest.java index 120dca5a7e5..0beb3836ac0 100644 --- a/js/js.tests/test/org/jetbrains/k2js/test/semantics/ClosureTest.java +++ b/js/js.tests/test/org/jetbrains/k2js/test/semantics/ClosureTest.java @@ -28,6 +28,6 @@ public final class ClosureTest extends SingleFileTranslationTest { } public void testIteratingCallbacks() throws Exception { - //checkFooBoxIsTrue("iteratingCallbacks.kt"); + checkFooBoxIsTrue("iteratingCallbacks.kt"); } } diff --git a/js/js.tests/test/org/jetbrains/k2js/test/semantics/ExamplesTest.java b/js/js.tests/test/org/jetbrains/k2js/test/semantics/ExamplesTest.java index 7079c2e4c75..944ccc6f766 100644 --- a/js/js.tests/test/org/jetbrains/k2js/test/semantics/ExamplesTest.java +++ b/js/js.tests/test/org/jetbrains/k2js/test/semantics/ExamplesTest.java @@ -16,16 +16,12 @@ package org.jetbrains.k2js.test.semantics; -import closurecompiler.internal.com.google.common.collect.Sets; import junit.framework.Test; import org.jetbrains.annotations.NotNull; import org.jetbrains.k2js.test.BasicTest; import org.jetbrains.k2js.test.SingleFileTranslationTest; import org.jetbrains.k2js.translate.context.Namer; -import java.io.File; -import java.io.FilenameFilter; - @SuppressWarnings("JUnitTestCaseWithNoTests") public final class ExamplesTest extends SingleFileTranslationTest { @@ -44,13 +40,7 @@ public final class ExamplesTest extends SingleFileTranslationTest { } public static Test suite() throws Exception { - return TranslatorTestCaseBuilder.suiteForDirectory(BasicTest.pathToTestFilesRoot() + "examples/cases/", true, new FilenameFilter() { - @Override - public boolean accept(File dir, String name) { - return !Sets.newHashSet("closureWithParameter.jet", "closureWithParameterAndBoxing.jet", "doubleEnclosedLocalVariable.jet", "enclosingLocalVariable.jet", "extensionClosure.jet", - "simplestClosure.jet", "simplestClosureAndBoxing.jet").contains(name); - } - }, new TranslatorTestCaseBuilder.NamedTestFactory() { + return TranslatorTestCaseBuilder.suiteForDirectory(BasicTest.pathToTestFilesRoot() + "examples/cases/", new TranslatorTestCaseBuilder.NamedTestFactory() { @NotNull @Override public Test createTest(@NotNull String filename) { diff --git a/js/js.tests/test/org/jetbrains/k2js/test/semantics/ExtensionFunctionTest.java b/js/js.tests/test/org/jetbrains/k2js/test/semantics/ExtensionFunctionTest.java index ad32af9e460..72058f94a29 100644 --- a/js/js.tests/test/org/jetbrains/k2js/test/semantics/ExtensionFunctionTest.java +++ b/js/js.tests/test/org/jetbrains/k2js/test/semantics/ExtensionFunctionTest.java @@ -52,15 +52,15 @@ public final class ExtensionFunctionTest extends SingleFileTranslationTest { } public void testExtensionLiteralPassedToFunction() throws Exception { - //checkFooBoxIsTrue("extensionLiteralPassedToFunction.kt"); + checkFooBoxIsTrue("extensionLiteralPassedToFunction.kt"); } public void testExtensionInsideFunctionLiteral() throws Exception { - //checkFooBoxIsTrue("extensionInsideFunctionLiteral.kt"); + checkFooBoxIsTrue("extensionInsideFunctionLiteral.kt"); } public void testGenericExtension() throws Exception { - //checkFooBoxIsOk("generic.kt"); + checkFooBoxIsOk("generic.kt"); } public void testExtensionFunctionCalledFromExtensionFunction() throws Exception { diff --git a/js/js.tests/test/org/jetbrains/k2js/test/semantics/FunctionTest.java b/js/js.tests/test/org/jetbrains/k2js/test/semantics/FunctionTest.java index 85f81f95233..20eeae619cc 100644 --- a/js/js.tests/test/org/jetbrains/k2js/test/semantics/FunctionTest.java +++ b/js/js.tests/test/org/jetbrains/k2js/test/semantics/FunctionTest.java @@ -36,36 +36,36 @@ public class FunctionTest extends AbstractExpressionTest { } public void testFunctionLiteral() throws Exception { - //checkFooBoxIsTrue("functionLiteral.kt"); + checkFooBoxIsTrue("functionLiteral.kt"); } public void testAdderClosure() throws Exception { - //checkFooBoxIsTrue("adderClosure.kt"); + checkFooBoxIsTrue("adderClosure.kt"); } public void testLoopClosure() throws Exception { - //checkFooBoxIsTrue("loopClosure.kt"); + checkFooBoxIsTrue("loopClosure.kt"); } public void testFunctionLiteralAsParameter() throws Exception { - //checkFooBoxIsTrue("functionLiteralAsParameter.kt"); + checkFooBoxIsTrue("functionLiteralAsParameter.kt"); } public void testClosureWithParameter() throws Exception { - //checkFooBoxIsOk("closureWithParameter.kt"); + checkFooBoxIsOk("closureWithParameter.kt"); } public void testClosureWithParameterAndBoxing() throws Exception { - //checkFooBoxIsOk("closureWithParameterAndBoxing.jet"); + checkFooBoxIsOk("closureWithParameterAndBoxing.jet"); } public void testEnclosingThis() throws Exception { - //runFunctionOutputTest("enclosingThis.kt", Namer.getRootNamespaceName(), "box", "OK"); + runFunctionOutputTest("enclosingThis.kt", Namer.getRootNamespaceName(), "box", "OK"); } public void testImplicitItParameter() throws Exception { - //checkFooBoxIsTrue("implicitItParameter.kt"); + checkFooBoxIsTrue("implicitItParameter.kt"); } @@ -75,7 +75,7 @@ public class FunctionTest extends AbstractExpressionTest { public void testFunctionLiteralAsLastParameter() throws Exception { - //checkFooBoxIsTrue("functionLiteralAsLastParameter.kt"); + checkFooBoxIsTrue("functionLiteralAsLastParameter.kt"); } diff --git a/js/js.tests/test/org/jetbrains/k2js/test/semantics/MiscTest.java b/js/js.tests/test/org/jetbrains/k2js/test/semantics/MiscTest.java index e8870752631..e6b3a42c8d5 100644 --- a/js/js.tests/test/org/jetbrains/k2js/test/semantics/MiscTest.java +++ b/js/js.tests/test/org/jetbrains/k2js/test/semantics/MiscTest.java @@ -92,23 +92,23 @@ public final class MiscTest extends AbstractExpressionTest { } public void testFunInConstructor() throws Exception { - //checkFooBoxIsTrue("funInConstructor.kt"); + checkFooBoxIsTrue("funInConstructor.kt"); } public void testFunInConstructorBlock() throws Exception { - //checkFooBoxIsTrue("funInConstructorBlock.kt"); + checkFooBoxIsTrue("funInConstructorBlock.kt"); } public void testPropertyAsFunCalledOnConstructor() throws Exception { - //checkFooBoxIsTrue("propertyAsFunCalledOnConstructor.kt"); + checkFooBoxIsTrue("propertyAsFunCalledOnConstructor.kt"); } public void testNamespacePropertyCalledAsFun() throws Exception { - //checkFooBoxIsTrue("namespacePropertyCalledAsFun.kt"); + checkFooBoxIsTrue("namespacePropertyCalledAsFun.kt"); } public void testExtensionLiteralCreatedAtNamespaceLevel() throws Exception { - //checkFooBoxIsTrue("extensionLiteralCreatedAtNamespaceLevel.kt"); + checkFooBoxIsTrue("extensionLiteralCreatedAtNamespaceLevel.kt"); } public void testTemporaryVariableCreatedInNamespaceInitializer() throws Exception { diff --git a/js/js.tests/test/org/jetbrains/k2js/test/semantics/PropertyAccessTest.java b/js/js.tests/test/org/jetbrains/k2js/test/semantics/PropertyAccessTest.java index 0592c0acfcb..b0337104eaa 100644 --- a/js/js.tests/test/org/jetbrains/k2js/test/semantics/PropertyAccessTest.java +++ b/js/js.tests/test/org/jetbrains/k2js/test/semantics/PropertyAccessTest.java @@ -70,7 +70,7 @@ public final class PropertyAccessTest extends SingleFileTranslationTest { } public void testExtensionLiteralSafeCall() throws Exception { - //checkFooBoxIsTrue("extensionLiteralSafeCall.kt"); + checkFooBoxIsTrue("extensionLiteralSafeCall.kt"); } } diff --git a/js/js.tests/test/org/jetbrains/k2js/test/semantics/WebDemoExamples2Test.java b/js/js.tests/test/org/jetbrains/k2js/test/semantics/WebDemoExamples2Test.java index 7dd5f260174..28afb839d55 100644 --- a/js/js.tests/test/org/jetbrains/k2js/test/semantics/WebDemoExamples2Test.java +++ b/js/js.tests/test/org/jetbrains/k2js/test/semantics/WebDemoExamples2Test.java @@ -33,11 +33,11 @@ public final class WebDemoExamples2Test extends SingleFileTranslationTest { } public void testLife() throws Exception { - //performTestWithMain("life", "", "2"); + performTestWithMain("life", "", "2"); } public void testBuilder() throws Exception { - //performTestWithMain("builder", ""); - //performTestWithMain("builder", "1", "over9000"); + performTestWithMain("builder", ""); + performTestWithMain("builder", "1", "over9000"); } } diff --git a/js/js.translator/src/org/jetbrains/k2js/translate/context/StaticContext.java b/js/js.translator/src/org/jetbrains/k2js/translate/context/StaticContext.java index 36a5b0d3301..36ae40622ae 100644 --- a/js/js.translator/src/org/jetbrains/k2js/translate/context/StaticContext.java +++ b/js/js.translator/src/org/jetbrains/k2js/translate/context/StaticContext.java @@ -412,15 +412,6 @@ public final class StaticContext { return true; } }; - Rule variableAsFunctionsHaveNoQualifiers = new Rule() { - @Override - public Boolean apply(@NotNull DeclarationDescriptor descriptor) { - if (!isVariableAsFunction(descriptor)) { - return null; - } - return true; - } - }; //TODO: hack! Rule nativeObjectsHaveNoQualifiers = new Rule() { @Override @@ -445,7 +436,6 @@ public final class StaticContext { }; addRule(topLevelNamespaceHaveNoQualifier); addRule(propertiesHaveNoQualifiers); - addRule(variableAsFunctionsHaveNoQualifiers); addRule(nativeObjectsHaveNoQualifiers); } } diff --git a/js/js.translator/src/org/jetbrains/k2js/translate/reference/CallExpressionTranslator.java b/js/js.translator/src/org/jetbrains/k2js/translate/reference/CallExpressionTranslator.java index 594e0adc28e..9413827834e 100644 --- a/js/js.translator/src/org/jetbrains/k2js/translate/reference/CallExpressionTranslator.java +++ b/js/js.translator/src/org/jetbrains/k2js/translate/reference/CallExpressionTranslator.java @@ -22,14 +22,14 @@ import org.jetbrains.annotations.Nullable; import org.jetbrains.jet.lang.descriptors.CallableDescriptor; import org.jetbrains.jet.lang.descriptors.ValueParameterDescriptor; import org.jetbrains.jet.lang.psi.JetCallExpression; -import org.jetbrains.jet.lang.psi.JetExpression; -import org.jetbrains.jet.lang.psi.JetSimpleNameExpression; import org.jetbrains.jet.lang.resolve.calls.ExpressionAsFunctionDescriptor; +import org.jetbrains.jet.lang.resolve.calls.ResolvedCall; import org.jetbrains.jet.lang.resolve.calls.ResolvedValueArgument; import org.jetbrains.jet.lang.resolve.calls.VariableAsFunctionResolvedCall; import org.jetbrains.k2js.translate.context.TranslationContext; import org.jetbrains.k2js.translate.general.Translation; import org.jetbrains.k2js.translate.utils.AnnotationsUtils; +import org.jetbrains.k2js.translate.utils.PsiUtils; import java.util.ArrayList; import java.util.List; @@ -43,9 +43,9 @@ public final class CallExpressionTranslator extends AbstractCallExpressionTransl @NotNull public static JsExpression translate(@NotNull JetCallExpression expression, - @Nullable JsExpression receiver, - @NotNull CallType callType, - @NotNull TranslationContext context) { + @Nullable JsExpression receiver, + @NotNull CallType callType, + @NotNull TranslationContext context) { if (InlinedCallExpressionTranslator.shouldBeInlined(expression, context)) { return InlinedCallExpressionTranslator.translate(expression, receiver, callType, context); } @@ -55,8 +55,8 @@ public final class CallExpressionTranslator extends AbstractCallExpressionTransl private final boolean isNativeFunctionCall; private CallExpressionTranslator(@NotNull JetCallExpression expression, - @Nullable JsExpression receiver, - @NotNull CallType callType, @NotNull TranslationContext context) { + @Nullable JsExpression receiver, + @NotNull CallType callType, @NotNull TranslationContext context) { super(expression, receiver, callType, context); this.isNativeFunctionCall = AnnotationsUtils.isNativeObject(resolvedCall.getCandidateDescriptor()); } @@ -64,12 +64,28 @@ public final class CallExpressionTranslator extends AbstractCallExpressionTransl @NotNull private JsExpression translate() { return CallBuilder.build(context()) - .receiver(receiver) - .callee(getCalleeExpression()) - .args(translateArguments()) - .resolvedCall(resolvedCall) - .type(callType) - .translate(); + .receiver(getReceiver()) + .callee(getCalleeExpression()) + .args(translateArguments()) + .resolvedCall(getResolvedCall()) + .type(callType) + .translate(); + } + + @NotNull + private ResolvedCall getResolvedCall() { + if (resolvedCall instanceof VariableAsFunctionResolvedCall) { + return ((VariableAsFunctionResolvedCall) resolvedCall).getFunctionCall(); + } + return resolvedCall; + } + + @Nullable + private JsExpression getReceiver() { + if (receiver != null) { + return receiver; + } + return null; } @Nullable @@ -78,19 +94,12 @@ public final class CallExpressionTranslator extends AbstractCallExpressionTransl if (candidateDescriptor instanceof ExpressionAsFunctionDescriptor) { return translateExpressionAsFunction(); } - //if (candidateDescriptor instanceof VariableAsFunctionDescriptor) { - // return translateVariableAsFunction(); - //} + if (resolvedCall instanceof VariableAsFunctionResolvedCall) { + return Translation.translateAsExpression(PsiUtils.getCallee(expression), context()); + } return null; } - @NotNull - private JsExpression translateVariableAsFunction() { - JetExpression callee = getCallee(expression); - assert callee instanceof JetSimpleNameExpression; - return ReferenceTranslator.getAccessTranslator((JetSimpleNameExpression)callee, receiver, context()).translateAsGet(); - } - @NotNull private JsExpression translateExpressionAsFunction() { return Translation.translateAsExpression(getCallee(expression), context()); diff --git a/js/js.translator/src/org/jetbrains/k2js/translate/reference/CallParametersResolver.java b/js/js.translator/src/org/jetbrains/k2js/translate/reference/CallParametersResolver.java index 145aa54696f..e49a9d82435 100644 --- a/js/js.translator/src/org/jetbrains/k2js/translate/reference/CallParametersResolver.java +++ b/js/js.translator/src/org/jetbrains/k2js/translate/reference/CallParametersResolver.java @@ -21,6 +21,8 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jetbrains.jet.lang.descriptors.*; import org.jetbrains.jet.lang.resolve.calls.ResolvedCall; +import org.jetbrains.jet.lang.resolve.calls.ResolvedCallWithTrace; +import org.jetbrains.jet.lang.resolve.calls.VariableAsFunctionResolvedCall; import org.jetbrains.k2js.translate.context.TranslationContext; import org.jetbrains.k2js.translate.utils.TranslationUtils; @@ -78,22 +80,11 @@ public final class CallParametersResolver { if (callee != null) { return callee; } - if (!isVariableAsFunction(descriptor)) { + if (!(resolvedCall instanceof VariableAsFunctionResolvedCall)) { return ReferenceTranslator.translateAsLocalNameReference(descriptor, context); } - //VariableDescriptor variableDescriptor = - // getVariableDescriptorForVariableAsFunction((VariableAsFunctionDescriptor)descriptor); - //if (variableDescriptor instanceof PropertyDescriptor) { - // return getterCall((PropertyDescriptor)variableDescriptor); - //} - return ReferenceTranslator.translateAsLocalNameReference(descriptor, context); - } - - //TODO: inspect - @NotNull - private JsExpression getterCall(@NotNull PropertyDescriptor variableDescriptor) { - //TODO: call type? - return PropertyAccessTranslator.translateAsPropertyGetterCall(variableDescriptor, resolvedCall, context); + ResolvedCallWithTrace call = ((VariableAsFunctionResolvedCall) resolvedCall).getFunctionCall(); + return CallBuilder.build(context).resolvedCall(call).translate(); } @Nullable diff --git a/js/js.translator/src/org/jetbrains/k2js/translate/reference/CallTranslator.java b/js/js.translator/src/org/jetbrains/k2js/translate/reference/CallTranslator.java index 417e1b9eaa6..7ef0c308a48 100644 --- a/js/js.translator/src/org/jetbrains/k2js/translate/reference/CallTranslator.java +++ b/js/js.translator/src/org/jetbrains/k2js/translate/reference/CallTranslator.java @@ -16,6 +16,7 @@ package org.jetbrains.k2js.translate.reference; +import com.google.common.collect.Lists; 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.JsNameRef; @@ -28,6 +29,7 @@ import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor; import org.jetbrains.jet.lang.descriptors.FunctionDescriptor; import org.jetbrains.jet.lang.resolve.calls.ExpressionAsFunctionDescriptor; import org.jetbrains.jet.lang.resolve.calls.ResolvedCall; +import org.jetbrains.jet.lang.resolve.calls.VariableAsFunctionResolvedCall; import org.jetbrains.k2js.translate.context.TranslationContext; import org.jetbrains.k2js.translate.general.AbstractTranslator; import org.jetbrains.k2js.translate.intrinsic.Intrinsic; @@ -37,8 +39,8 @@ import java.util.ArrayList; import java.util.List; import static org.jetbrains.k2js.translate.reference.CallParametersResolver.resolveCallParameters; -import static org.jetbrains.k2js.translate.utils.JsDescriptorUtils.isConstructorDescriptor; import static org.jetbrains.k2js.translate.utils.JsAstUtils.*; +import static org.jetbrains.k2js.translate.utils.JsDescriptorUtils.isConstructorDescriptor; /** * @author Pavel Talanov @@ -57,11 +59,11 @@ public final class CallTranslator extends AbstractTranslator { private final CallParameters callParameters; /*package*/ CallTranslator(@Nullable JsExpression receiver, @Nullable JsExpression callee, - @NotNull List arguments, - @NotNull ResolvedCall resolvedCall, - @NotNull CallableDescriptor descriptorToCall, - @NotNull CallType callType, - @NotNull TranslationContext context) { + @NotNull List arguments, + @NotNull ResolvedCall resolvedCall, + @NotNull CallableDescriptor descriptorToCall, + @NotNull CallType callType, + @NotNull TranslationContext context) { super(context); this.arguments = arguments; this.resolvedCall = resolvedCall; @@ -90,12 +92,28 @@ public final class CallTranslator extends AbstractTranslator { if (isExpressionAsFunction()) { return expressionAsFunctionCall(); } + if (isInvoke()) { + return invokeCall(); + } return methodCall(getThisObjectOrQualifier()); } + //TODO: + private boolean isInvoke() { + return descriptor.getName().equals("invoke"); + } + + private JsExpression invokeCall() { + JsInvocation callMethodInvocation = generateCallMethodInvocation(); + List parameters = Lists.newArrayList(context().program().getNullLiteral()); + parameters.addAll(arguments); + setArguments(callMethodInvocation, parameters); + return callMethodInvocation; + } + private boolean isExpressionAsFunction() { - return descriptor instanceof ExpressionAsFunctionDescriptor;// || - //descriptor instanceof VariableAsFunctionDescriptor; + return descriptor instanceof ExpressionAsFunctionDescriptor || + resolvedCall instanceof VariableAsFunctionResolvedCall; } @NotNull @@ -110,7 +128,7 @@ public final class CallTranslator extends AbstractTranslator { @NotNull private JsExpression intrinsicInvocation() { assert descriptor instanceof FunctionDescriptor; - Intrinsic intrinsic = context().intrinsics().getFunctionIntrinsic((FunctionDescriptor)descriptor); + Intrinsic intrinsic = context().intrinsics().getFunctionIntrinsic((FunctionDescriptor) descriptor); return intrinsic.apply(callParameters.getThisObject(), arguments, context()); } @@ -141,8 +159,8 @@ public final class CallTranslator extends AbstractTranslator { } private boolean isExtensionFunctionLiteral() { - boolean isLiteral = //descriptor instanceof VariableAsFunctionDescriptor || - descriptor instanceof ExpressionAsFunctionDescriptor; + boolean isLiteral = isInvoke() + || descriptor instanceof ExpressionAsFunctionDescriptor; return isExtensionFunction() && isLiteral; } diff --git a/js/js.translator/src/org/jetbrains/k2js/translate/reference/PropertyAccessTranslator.java b/js/js.translator/src/org/jetbrains/k2js/translate/reference/PropertyAccessTranslator.java index 9720db68bde..992ad3e26f2 100644 --- a/js/js.translator/src/org/jetbrains/k2js/translate/reference/PropertyAccessTranslator.java +++ b/js/js.translator/src/org/jetbrains/k2js/translate/reference/PropertyAccessTranslator.java @@ -30,7 +30,7 @@ import org.jetbrains.k2js.translate.general.AbstractTranslator; import static org.jetbrains.k2js.translate.utils.AnnotationsUtils.isNativeObject; import static org.jetbrains.k2js.translate.utils.BindingUtils.getDescriptorForReferenceExpression; -import static org.jetbrains.k2js.translate.utils.BindingUtils.getResolvedCall; +import static org.jetbrains.k2js.translate.utils.BindingUtils.getResolvedCallForProperty; import static org.jetbrains.k2js.translate.utils.PsiUtils.getSelectorAsSimpleName; import static org.jetbrains.k2js.translate.utils.PsiUtils.isBackingFieldReference; @@ -42,8 +42,8 @@ public abstract class PropertyAccessTranslator extends AbstractTranslator implem //TODO: is it really called? @NotNull private static PropertyAccessTranslator newInstance(@NotNull PropertyDescriptor descriptor, - @NotNull ResolvedCall resolvedCall, - @NotNull TranslationContext context) { + @NotNull ResolvedCall resolvedCall, + @NotNull TranslationContext context) { if (isNativeObject(descriptor)) { return new NativePropertyAccessTranslator(descriptor, /*qualifier = */ null, context); } @@ -54,16 +54,16 @@ public abstract class PropertyAccessTranslator extends AbstractTranslator implem @NotNull public static PropertyAccessTranslator newInstance(@NotNull JetSimpleNameExpression expression, - @Nullable JsExpression qualifier, - @NotNull CallType callType, - @NotNull TranslationContext context) { + @Nullable JsExpression qualifier, + @NotNull CallType callType, + @NotNull TranslationContext context) { PropertyAccessTranslator result; PropertyDescriptor propertyDescriptor = getPropertyDescriptor(expression, context); if (isNativeObject(propertyDescriptor) || isBackingFieldReference(expression)) { result = new NativePropertyAccessTranslator(propertyDescriptor, qualifier, context); } else { - ResolvedCall resolvedCall = getResolvedCall(context.bindingContext(), expression); + ResolvedCall resolvedCall = getResolvedCallForProperty(context.bindingContext(), expression); result = new KotlinPropertyAccessTranslator(propertyDescriptor, qualifier, resolvedCall, context); } result.setCallType(callType); @@ -72,7 +72,7 @@ public abstract class PropertyAccessTranslator extends AbstractTranslator implem @NotNull private static PropertyDescriptor getPropertyDescriptor(@NotNull JetSimpleNameExpression expression, - @NotNull TranslationContext context) { + @NotNull TranslationContext context) { DeclarationDescriptor descriptor = getDescriptorForReferenceExpression(context.bindingContext(), expression); assert descriptor instanceof PropertyDescriptor : "Must be a property descriptor."; @@ -83,37 +83,37 @@ public abstract class PropertyAccessTranslator extends AbstractTranslator implem @NotNull /*package*/ static JsExpression translateAsPropertyGetterCall(@NotNull PropertyDescriptor descriptor, - @NotNull ResolvedCall resolvedCall, - @NotNull TranslationContext context) { + @NotNull ResolvedCall resolvedCall, + @NotNull TranslationContext context) { return (newInstance(descriptor, resolvedCall, context)) .translateAsGet(); } @NotNull public static JsExpression translateAsPropertyGetterCall(@NotNull JetSimpleNameExpression expression, - @Nullable JsExpression qualifier, - @NotNull CallType callType, - @NotNull TranslationContext context) { + @Nullable JsExpression qualifier, + @NotNull CallType callType, + @NotNull TranslationContext context) { return (newInstance(expression, qualifier, callType, context)) .translateAsGet(); } private static boolean canBePropertyGetterCall(@NotNull JetQualifiedExpression expression, - @NotNull TranslationContext context) { + @NotNull TranslationContext context) { JetSimpleNameExpression selector = getSelectorAsSimpleName(expression); assert selector != null : "Only names are allowed after the dot"; return canBePropertyGetterCall(selector, context); } public static boolean canBePropertyGetterCall(@NotNull JetSimpleNameExpression expression, - @NotNull TranslationContext context) { + @NotNull TranslationContext context) { return (getDescriptorForReferenceExpression - (context.bindingContext(), expression) instanceof PropertyDescriptor); + (context.bindingContext(), expression) instanceof PropertyDescriptor); } public static boolean canBePropertyGetterCall(@NotNull JetExpression expression, - @NotNull TranslationContext context) { + @NotNull TranslationContext context) { if (expression instanceof JetQualifiedExpression) { return canBePropertyGetterCall((JetQualifiedExpression) expression, context); } @@ -124,7 +124,7 @@ public abstract class PropertyAccessTranslator extends AbstractTranslator implem } public static boolean canBePropertyAccess(@NotNull JetExpression expression, - @NotNull TranslationContext context) { + @NotNull TranslationContext context) { return canBePropertyGetterCall(expression, context); } diff --git a/js/js.translator/src/org/jetbrains/k2js/translate/utils/BindingUtils.java b/js/js.translator/src/org/jetbrains/k2js/translate/utils/BindingUtils.java index 5e5c760e11f..a6fcbf75dbb 100644 --- a/js/js.translator/src/org/jetbrains/k2js/translate/utils/BindingUtils.java +++ b/js/js.translator/src/org/jetbrains/k2js/translate/utils/BindingUtils.java @@ -25,6 +25,7 @@ import org.jetbrains.jet.lang.psi.*; import org.jetbrains.jet.lang.resolve.BindingContext; import org.jetbrains.jet.lang.resolve.BindingContextUtils; import org.jetbrains.jet.lang.resolve.calls.ResolvedCall; +import org.jetbrains.jet.lang.resolve.calls.VariableAsFunctionResolvedCall; import org.jetbrains.jet.lang.resolve.constants.CompileTimeConstant; import org.jetbrains.jet.lang.types.JetType; import org.jetbrains.jet.lang.types.lang.JetStandardClasses; @@ -190,15 +191,11 @@ public final class BindingUtils { return referencedDescriptor; } + //TODO: remove? @Nullable public static DeclarationDescriptor getNullableDescriptorForReferenceExpression(@NotNull BindingContext context, @NotNull JetReferenceExpression reference) { - DeclarationDescriptor referencedDescriptor = context.get(BindingContext.REFERENCE_TARGET, reference); - //if (isVariableAsFunction(referencedDescriptor)) { - // assert referencedDescriptor != null; - // return getVariableDescriptorForVariableAsFunction((VariableAsFunctionDescriptor)referencedDescriptor); - //} - return referencedDescriptor; + return context.get(BindingContext.REFERENCE_TARGET, reference); } public static boolean isNotAny(@NotNull DeclarationDescriptor superClassDescriptor) { @@ -213,6 +210,17 @@ public final class BindingUtils { return resolvedCall; } + @NotNull + public static ResolvedCall getResolvedCallForProperty(@NotNull BindingContext context, + @NotNull JetExpression expression) { + ResolvedCall resolvedCall = context.get(BindingContext.RESOLVED_CALL, expression); + assert resolvedCall != null : "Must resolve to a call."; + if (resolvedCall instanceof VariableAsFunctionResolvedCall) { + return ((VariableAsFunctionResolvedCall)resolvedCall).getVariableCall(); + } + return resolvedCall; + } + @NotNull public static ResolvedCall getResolvedCallForCallExpression(@NotNull BindingContext context, @NotNull JetCallExpression expression) { diff --git a/js/js.translator/src/org/jetbrains/k2js/translate/utils/JsDescriptorUtils.java b/js/js.translator/src/org/jetbrains/k2js/translate/utils/JsDescriptorUtils.java index 445b5ed4c6d..43cafa94718 100644 --- a/js/js.translator/src/org/jetbrains/k2js/translate/utils/JsDescriptorUtils.java +++ b/js/js.translator/src/org/jetbrains/k2js/translate/utils/JsDescriptorUtils.java @@ -126,18 +126,6 @@ public final class JsDescriptorUtils { return (ClassDescriptor)superClassDescriptor; } - //@NotNull - //public static VariableDescriptor getVariableDescriptorForVariableAsFunction - // (@NotNull VariableAsFunctionDescriptor descriptor) { - // VariableDescriptor functionVariable = descriptor.getVariableDescriptor(); - // assert functionVariable != null; - // return functionVariable; - //} - - - public static boolean isVariableAsFunction(@Nullable DeclarationDescriptor referencedDescriptor) { - return false;//referencedDescriptor instanceof VariableAsFunctionDescriptor; - } @NotNull public static DeclarationDescriptor getContainingDeclaration(@NotNull DeclarationDescriptor descriptor) {