reimplemented extension literal definition and calls to comply with jquery conventions
This commit is contained in:
@@ -103,8 +103,9 @@ public final class StandardClasses {
|
|||||||
|
|
||||||
private static void declareJQuery(@NotNull StandardClasses standardClasses) {
|
private static void declareJQuery(@NotNull StandardClasses standardClasses) {
|
||||||
standardClasses.declare().forFQ("jquery.JQuery").externalClass("jQuery")
|
standardClasses.declare().forFQ("jquery.JQuery").externalClass("jQuery")
|
||||||
.methods("addClass", "attr", "hasClass", "append");
|
.methods("addClass", "attr", "hasClass", "append", "text", "ready");
|
||||||
standardClasses.declare().forFQ("jquery.jq").externalFunction("jQuery");
|
standardClasses.declare().forFQ("jquery.jq").externalFunction("jQuery");
|
||||||
|
standardClasses.declare().forFQ("jquery.get-document").externalObject("document");
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO: test all the methods
|
//TODO: test all the methods
|
||||||
@@ -142,6 +143,8 @@ public final class StandardClasses {
|
|||||||
|
|
||||||
standardClasses.declare().forFQ("jet.String").kotlinClass("String").
|
standardClasses.declare().forFQ("jet.String").kotlinClass("String").
|
||||||
properties("length");
|
properties("length");
|
||||||
|
|
||||||
|
standardClasses.declare().forFQ("jet.Any.toString").kotlinFunction("toString");
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void declareTopLevelFunctions(@NotNull StandardClasses standardClasses) {
|
private static void declareTopLevelFunctions(@NotNull StandardClasses standardClasses) {
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package org.jetbrains.k2js.translate.expression;
|
package org.jetbrains.k2js.translate.expression;
|
||||||
|
|
||||||
|
|
||||||
import com.google.dart.compiler.backend.js.ast.*;
|
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;
|
||||||
@@ -195,7 +196,7 @@ public final class FunctionTranslator extends AbstractTranslator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private boolean isExtensionFunction() {
|
private boolean isExtensionFunction() {
|
||||||
return DescriptorUtils.isExtensionFunction(descriptor);
|
return DescriptorUtils.isExtensionFunction(descriptor) && !isLiteral();
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isLiteral() {
|
private boolean isLiteral() {
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package org.jetbrains.k2js.translate.reference;
|
|||||||
|
|
||||||
import com.google.dart.compiler.backend.js.ast.JsExpression;
|
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.JsInvocation;
|
||||||
|
import com.google.dart.compiler.backend.js.ast.JsNameRef;
|
||||||
import com.google.dart.compiler.backend.js.ast.JsNew;
|
import com.google.dart.compiler.backend.js.ast.JsNew;
|
||||||
import com.google.dart.compiler.util.AstUtil;
|
import com.google.dart.compiler.util.AstUtil;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
@@ -129,7 +130,6 @@ public final class CallTranslator extends AbstractTranslator {
|
|||||||
public static JsExpression translate(@Nullable JsExpression receiver,
|
public static JsExpression translate(@Nullable JsExpression receiver,
|
||||||
@NotNull CallableDescriptor descriptor,
|
@NotNull CallableDescriptor descriptor,
|
||||||
@NotNull TranslationContext context) {
|
@NotNull TranslationContext context) {
|
||||||
//TODO: HACK!
|
|
||||||
return translate(receiver, Collections.<JsExpression>emptyList(),
|
return translate(receiver, Collections.<JsExpression>emptyList(),
|
||||||
ResolvedCallImpl.create(descriptor), null, context);
|
ResolvedCallImpl.create(descriptor), null, context);
|
||||||
}
|
}
|
||||||
@@ -224,12 +224,37 @@ public final class CallTranslator extends AbstractTranslator {
|
|||||||
if (isConstructor()) {
|
if (isConstructor()) {
|
||||||
return constructorCall();
|
return constructorCall();
|
||||||
}
|
}
|
||||||
|
if (isExtensionFunctionLiteral()) {
|
||||||
|
return extensionFunctionLiteralCall();
|
||||||
|
}
|
||||||
if (isExtensionFunction()) {
|
if (isExtensionFunction()) {
|
||||||
return extensionFunctionCall();
|
return extensionFunctionCall();
|
||||||
}
|
}
|
||||||
return methodCall();
|
return methodCall();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
private JsExpression extensionFunctionLiteralCall() {
|
||||||
|
|
||||||
|
List<JsExpression> callArguments = new ArrayList<JsExpression>();
|
||||||
|
assert receiver != null;
|
||||||
|
callArguments.add(thisObject());
|
||||||
|
callArguments.addAll(arguments);
|
||||||
|
receiver = null;
|
||||||
|
JsNameRef callMethodNameRef = AstUtil.newQualifiedNameRef("call");
|
||||||
|
JsInvocation callMethodInvocation = new JsInvocation();
|
||||||
|
callMethodInvocation.setQualifier(callMethodNameRef);
|
||||||
|
AstUtil.setQualifier(callMethodInvocation, calleeReference());
|
||||||
|
callMethodInvocation.setArguments(callArguments);
|
||||||
|
return callMethodInvocation;
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean isExtensionFunctionLiteral() {
|
||||||
|
boolean isLiteral = descriptor instanceof VariableAsFunctionDescriptor
|
||||||
|
|| descriptor instanceof ExpressionAsFunctionDescriptor;
|
||||||
|
return isExtensionFunction() && isLiteral;
|
||||||
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private JsExpression extensionFunctionCall() {
|
private JsExpression extensionFunctionCall() {
|
||||||
receiver = getExtensionFunctionCallReceiver();
|
receiver = getExtensionFunctionCallReceiver();
|
||||||
@@ -257,8 +282,10 @@ public final class CallTranslator extends AbstractTranslator {
|
|||||||
return getThisObject(context(), expectedReceiverDescriptor);
|
return getThisObject(context(), expectedReceiverDescriptor);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("UnnecessaryLocalVariable")
|
||||||
private boolean isExtensionFunction() {
|
private boolean isExtensionFunction() {
|
||||||
return resolvedCall.getReceiverArgument().exists();
|
boolean hasReceiver = resolvedCall.getReceiverArgument().exists();
|
||||||
|
return hasReceiver;
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package org.jetbrains.k2js.utils;
|
package org.jetbrains.k2js.utils;
|
||||||
|
|
||||||
|
import com.intellij.openapi.Disposable;
|
||||||
import com.intellij.openapi.project.Project;
|
import com.intellij.openapi.project.Project;
|
||||||
import com.intellij.openapi.util.io.FileUtil;
|
import com.intellij.openapi.util.io.FileUtil;
|
||||||
import com.intellij.openapi.util.text.StringUtil;
|
import com.intellij.openapi.util.text.StringUtil;
|
||||||
@@ -10,6 +11,7 @@ import com.intellij.psi.impl.PsiFileFactoryImpl;
|
|||||||
import com.intellij.testFramework.LightVirtualFile;
|
import com.intellij.testFramework.LightVirtualFile;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
import org.jetbrains.jet.compiler.JetCoreEnvironment;
|
||||||
import org.jetbrains.jet.lang.psi.JetFile;
|
import org.jetbrains.jet.lang.psi.JetFile;
|
||||||
import org.jetbrains.jet.plugin.JetLanguage;
|
import org.jetbrains.jet.plugin.JetLanguage;
|
||||||
|
|
||||||
@@ -21,13 +23,13 @@ import java.io.IOException;
|
|||||||
*/
|
*/
|
||||||
public final class JetFileUtils {
|
public final class JetFileUtils {
|
||||||
|
|
||||||
// @NotNull
|
@NotNull
|
||||||
// private static JetCoreEnvironment testOnlyEnvironment = new JetCoreEnvironment(new Disposable() {
|
private static JetCoreEnvironment testOnlyEnvironment = new JetCoreEnvironment(new Disposable() {
|
||||||
//
|
|
||||||
// @Override
|
@Override
|
||||||
// public void dispose() {
|
public void dispose() {
|
||||||
// }
|
}
|
||||||
// });
|
});
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public static String loadFile(@NotNull String path) throws IOException {
|
public static String loadFile(@NotNull String path) throws IOException {
|
||||||
@@ -63,7 +65,8 @@ public final class JetFileUtils {
|
|||||||
virtualFile.setCharset(CharsetToolkit.UTF8_CHARSET);
|
virtualFile.setCharset(CharsetToolkit.UTF8_CHARSET);
|
||||||
Project realProject = project;
|
Project realProject = project;
|
||||||
if (realProject == null) {
|
if (realProject == null) {
|
||||||
throw new RuntimeException();
|
realProject = testOnlyEnvironment.getProject();
|
||||||
|
//throw new RuntimeException();
|
||||||
}
|
}
|
||||||
PsiFile result = ((PsiFileFactoryImpl) PsiFileFactory.getInstance(realProject))
|
PsiFile result = ((PsiFileFactoryImpl) PsiFileFactory.getInstance(realProject))
|
||||||
.trySetupPsiForFile(virtualFile, JetLanguage.INSTANCE, true, false);
|
.trySetupPsiForFile(virtualFile, JetLanguage.INSTANCE, true, false);
|
||||||
|
|||||||
@@ -902,6 +902,9 @@ Kotlin.StringBuilder = Kotlin.Class.create(
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
Kotlin.toString = function(obj) {
|
||||||
|
return obj.toString();
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Copyright 2010 Tim Down.
|
* Copyright 2010 Tim Down.
|
||||||
|
|||||||
Reference in New Issue
Block a user