Rollback commented out code.
Implement a hacky solution for the new "invoke" concept. Fix most of the tests. (apart from 3)
This commit is contained in:
@@ -50,6 +50,6 @@ public abstract class TestWithEnvironment extends UsefulTestCase {
|
||||
}
|
||||
|
||||
protected void createEnvironmentWithMockJdkAndIdeaAnnotations() {
|
||||
myEnvironment = JetTestUtils.createEnvironmentWithMockJdkAndIdeaAnnotations(getTestRootDisposable());
|
||||
myEnvironment = JetCoreEnvironment.getCoreEnvironmentForJS(getTestRootDisposable());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,6 +28,6 @@ public final class ClosureTest extends SingleFileTranslationTest {
|
||||
}
|
||||
|
||||
public void testIteratingCallbacks() throws Exception {
|
||||
//checkFooBoxIsTrue("iteratingCallbacks.kt");
|
||||
checkFooBoxIsTrue("iteratingCallbacks.kt");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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");
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -70,7 +70,7 @@ public final class PropertyAccessTest extends SingleFileTranslationTest {
|
||||
}
|
||||
|
||||
public void testExtensionLiteralSafeCall() throws Exception {
|
||||
//checkFooBoxIsTrue("extensionLiteralSafeCall.kt");
|
||||
checkFooBoxIsTrue("extensionLiteralSafeCall.kt");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -412,15 +412,6 @@ public final class StaticContext {
|
||||
return true;
|
||||
}
|
||||
};
|
||||
Rule<Boolean> variableAsFunctionsHaveNoQualifiers = new Rule<Boolean>() {
|
||||
@Override
|
||||
public Boolean apply(@NotNull DeclarationDescriptor descriptor) {
|
||||
if (!isVariableAsFunction(descriptor)) {
|
||||
return null;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
};
|
||||
//TODO: hack!
|
||||
Rule<Boolean> nativeObjectsHaveNoQualifiers = new Rule<Boolean>() {
|
||||
@Override
|
||||
@@ -445,7 +436,6 @@ public final class StaticContext {
|
||||
};
|
||||
addRule(topLevelNamespaceHaveNoQualifier);
|
||||
addRule(propertiesHaveNoQualifiers);
|
||||
addRule(variableAsFunctionsHaveNoQualifiers);
|
||||
addRule(nativeObjectsHaveNoQualifiers);
|
||||
}
|
||||
}
|
||||
|
||||
+32
-23
@@ -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());
|
||||
|
||||
+5
-14
@@ -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<FunctionDescriptor> call = ((VariableAsFunctionResolvedCall) resolvedCall).getFunctionCall();
|
||||
return CallBuilder.build(context).resolvedCall(call).translate();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
|
||||
@@ -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<JsExpression> arguments,
|
||||
@NotNull ResolvedCall<? extends CallableDescriptor> resolvedCall,
|
||||
@NotNull CallableDescriptor descriptorToCall,
|
||||
@NotNull CallType callType,
|
||||
@NotNull TranslationContext context) {
|
||||
@NotNull List<JsExpression> arguments,
|
||||
@NotNull ResolvedCall<? extends CallableDescriptor> 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<JsExpression> parameters = Lists.<JsExpression>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;
|
||||
}
|
||||
|
||||
|
||||
+18
-18
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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<? extends CallableDescriptor> 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) {
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user