initial changes
This commit is contained in:
Generated
+9
@@ -14,6 +14,15 @@
|
||||
<element id="module-output" name="stdlib" />
|
||||
<element id="module-output" name="util" />
|
||||
<element id="module-output" name="j2k" />
|
||||
<element id="module-output" name="js.ast" />
|
||||
<element id="library" level="project" name="js_libs" />
|
||||
<element id="module-output" name="js.translator" />
|
||||
<element id="file-copy" path="$APPLICATION_HOME_DIR$/lib/annotations.jar" />
|
||||
<element id="library" level="application" name="idea-full" />
|
||||
<element id="library" level="project" name="idea-full" />
|
||||
<element id="module-output" name="cli" />
|
||||
<element id="library" level="project" name="intellij-core" />
|
||||
<element id="module-output" name="js.lib" />
|
||||
</element>
|
||||
</element>
|
||||
<element id="directory" name="kotlinc">
|
||||
|
||||
Generated
+1
@@ -16,6 +16,7 @@
|
||||
<entry name="?*.ftl" />
|
||||
<entry name="?*.jet" />
|
||||
<entry name="?*.ft" />
|
||||
<entry name="?*.kt" />
|
||||
</wildcardResourcePatterns>
|
||||
<annotationProcessing enabled="false" useClasspath="true" />
|
||||
</component>
|
||||
|
||||
Generated
+14
@@ -0,0 +1,14 @@
|
||||
<component name="libraryTable">
|
||||
<library name="js_libs">
|
||||
<CLASSES>
|
||||
<root url="jar://$PROJECT_DIR$/js/js.translator/lib/guava-10.0.1.jar!/" />
|
||||
<root url="jar://$PROJECT_DIR$/js/js.translator/lib/js.jar!/" />
|
||||
<root url="jar://$PROJECT_DIR$/js/js.translator/lib/dartc.jar!/" />
|
||||
</CLASSES>
|
||||
<JAVADOC />
|
||||
<SOURCES>
|
||||
<root url="file://$PROJECT_DIR$/js/js.translator/lib" />
|
||||
</SOURCES>
|
||||
<jarDirectory url="file://$PROJECT_DIR$/js/js.translator/lib" recursive="false" type="SOURCES" />
|
||||
</library>
|
||||
</component>
|
||||
Generated
+6
@@ -17,6 +17,12 @@
|
||||
<module fileurl="file://$PROJECT_DIR$/j2k/j2k.iml" filepath="$PROJECT_DIR$/j2k/j2k.iml" />
|
||||
<module fileurl="file://$PROJECT_DIR$/j2k/tests/j2k-tests.iml" filepath="$PROJECT_DIR$/j2k/tests/j2k-tests.iml" />
|
||||
<module fileurl="file://$PROJECT_DIR$/compiler/jet.as.java.psi/jet.as.java.psi.iml" filepath="$PROJECT_DIR$/compiler/jet.as.java.psi/jet.as.java.psi.iml" />
|
||||
<module fileurl="file://$PROJECT_DIR$/js/js.ast/js.ast.iml" filepath="$PROJECT_DIR$/js/js.ast/js.ast.iml" />
|
||||
<module fileurl="file://$PROJECT_DIR$/js/js.examples/js.examples.iml" filepath="$PROJECT_DIR$/js/js.examples/js.examples.iml" />
|
||||
<module fileurl="file://$PROJECT_DIR$/js/js.lib/js.lib.iml" filepath="$PROJECT_DIR$/js/js.lib/js.lib.iml" />
|
||||
<module fileurl="file://$PROJECT_DIR$/js/js.tests/js.tests.iml" filepath="$PROJECT_DIR$/js/js.tests/js.tests.iml" />
|
||||
<module fileurl="file://$PROJECT_DIR$/js/js.translator/js.translator.iml" filepath="$PROJECT_DIR$/js/js.translator/js.translator.iml" />
|
||||
<module fileurl="file://$PROJECT_DIR$/js/k2js.iml" filepath="$PROJECT_DIR$/js/k2js.iml" />
|
||||
<module fileurl="file://$PROJECT_DIR$/stdlib/stdlib.iml" filepath="$PROJECT_DIR$/stdlib/stdlib.iml" />
|
||||
<module fileurl="file://$PROJECT_DIR$/testlib/testlib.iml" filepath="$PROJECT_DIR$/testlib/testlib.iml" />
|
||||
<module fileurl="file://$PROJECT_DIR$/compiler/util/util.iml" filepath="$PROJECT_DIR$/compiler/util/util.iml" />
|
||||
|
||||
@@ -52,7 +52,7 @@ class String() : Comparable<String>, CharSequence {
|
||||
fun equals(other : Any?) : Boolean
|
||||
}
|
||||
|
||||
class Throwable(message : String? = null, cause: Throwable? = null) {
|
||||
open class Throwable(message : String? = null, cause: Throwable? = null) {
|
||||
fun getMessage() : String?
|
||||
fun getCause() : Throwable?
|
||||
fun printStackTrace() : Unit
|
||||
|
||||
@@ -173,8 +173,8 @@ public class AnnotationResolver {
|
||||
List<AnnotationDescriptor> result = Lists.newArrayList();
|
||||
for (JetAnnotationEntry annotation : annotations) {
|
||||
AnnotationDescriptor annotationDescriptor = new AnnotationDescriptor();
|
||||
result.add(annotationDescriptor);
|
||||
trace.record(BindingContext.ANNOTATION, annotation, annotationDescriptor);
|
||||
// result.add(annotationDescriptor);
|
||||
// trace.record(BindingContext.ANNOTATION, annotation, annotationDescriptor);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -462,6 +462,11 @@ public class JetStandardLibrary {
|
||||
return volatileType;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Collection<ClassDescriptor> getArrayClasses() {
|
||||
return primitiveTypeToArrayClass.values();
|
||||
}
|
||||
|
||||
public final boolean isVolatile(PropertyDescriptor descriptor) {
|
||||
List<AnnotationDescriptor> annotations = descriptor.getOriginal().getAnnotations();
|
||||
if(annotations != null) {
|
||||
|
||||
@@ -16,10 +16,9 @@
|
||||
|
||||
package org.jetbrains.jet.plugin;
|
||||
|
||||
import org.jetbrains.jet.lang.psi.JetDeclaration;
|
||||
import org.jetbrains.jet.lang.psi.JetNamedFunction;
|
||||
import org.jetbrains.jet.lang.psi.JetParameter;
|
||||
import org.jetbrains.jet.lang.psi.JetTypeReference;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.psi.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -51,4 +50,23 @@ public class JetMainDetector {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static String getMainClassFQName(@NotNull List<JetFile> files) {
|
||||
JetFile file = getFileWithMain(files);
|
||||
if (file == null) {
|
||||
return null;
|
||||
}
|
||||
return JetPsiUtil.getFQName(file);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static JetFile getFileWithMain(@NotNull List<JetFile> files) {
|
||||
for (JetFile file : files) {
|
||||
if (hasMain(file.getDeclarations())) {
|
||||
return file;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,6 +26,7 @@
|
||||
<orderEntry type="library" name="idea-full" level="project" />
|
||||
<orderEntry type="library" scope="PROVIDED" name="junit-plugin" level="project" />
|
||||
<orderEntry type="module" module-name="j2k" />
|
||||
<orderEntry type="module" module-name="js.translator" />
|
||||
</component>
|
||||
</module>
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<idea-plugin version="2">
|
||||
<name>Kotlin</name>
|
||||
<description>Kotlin language support</description>
|
||||
<version>@snapshot@</version>
|
||||
<version>1.0</version>
|
||||
<vendor>JetBrains</vendor>
|
||||
|
||||
<depends optional="true">JUnit</depends>
|
||||
@@ -43,6 +43,14 @@
|
||||
<keyboard-shortcut keymap="$default" first-keystroke="control alt shift E"/>
|
||||
<add-to-group group-id="CodeMenu" anchor="last"/>
|
||||
</action>
|
||||
|
||||
<action id="Kotlin.TranslateToJs" class="org.jetbrains.jet.plugin.actions.TranslateToJsAction"
|
||||
text="Translate Kotlin to JavaScript.">
|
||||
<keyboard-shortcut keymap="$default" first-keystroke="control alt shift W"/>
|
||||
<add-to-group group-id="CodeMenu" anchor="last"/>
|
||||
</action>
|
||||
|
||||
|
||||
</actions>
|
||||
|
||||
<extensions defaultExtensionNs="com.intellij">
|
||||
|
||||
@@ -56,13 +56,9 @@ public class JavaToKotlinActionUtil {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
static List<PsiFile> getAllJavaFiles(@NotNull VirtualFile[] vFiles, Project project) {
|
||||
/*package*/ static List<PsiFile> getAllJavaFiles(@NotNull VirtualFile[] vFiles, Project project) {
|
||||
Set<VirtualFile> filesSet = allVirtualFiles(vFiles);
|
||||
final PsiManager manager = PsiManager.getInstance(project);
|
||||
Set<VirtualFile> filesSet = new HashSet<VirtualFile>();
|
||||
for (VirtualFile f : vFiles) {
|
||||
filesSet.add(f);
|
||||
filesSet.addAll(getChildrenRecursive(f));
|
||||
}
|
||||
final List<PsiFile> res = new ArrayList<PsiFile>();
|
||||
for (final VirtualFile file : filesSet) {
|
||||
final PsiFile psiFile = manager.findFile(file);
|
||||
@@ -73,6 +69,16 @@ public class JavaToKotlinActionUtil {
|
||||
return res;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static Set<VirtualFile> allVirtualFiles(@NotNull VirtualFile[] vFiles) {
|
||||
Set<VirtualFile> filesSet = new HashSet<VirtualFile>();
|
||||
for (VirtualFile f : vFiles) {
|
||||
filesSet.add(f);
|
||||
filesSet.addAll(getChildrenRecursive(f));
|
||||
}
|
||||
return filesSet;
|
||||
}
|
||||
|
||||
static void reformatFiles(List<VirtualFile> allJetFiles, final Project project) {
|
||||
for (final VirtualFile vf : allJetFiles)
|
||||
ApplicationManager.getApplication().runWriteAction(new Runnable() {
|
||||
|
||||
@@ -0,0 +1,140 @@
|
||||
/*
|
||||
* Copyright 2000-2012 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.jet.plugin.actions;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.intellij.notification.Notification;
|
||||
import com.intellij.notification.NotificationType;
|
||||
import com.intellij.notification.Notifications;
|
||||
import com.intellij.openapi.actionSystem.AnAction;
|
||||
import com.intellij.openapi.actionSystem.AnActionEvent;
|
||||
import com.intellij.openapi.actionSystem.PlatformDataKeys;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.module.Module;
|
||||
import com.intellij.openapi.module.ModuleManager;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.roots.ModuleRootManager;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.psi.PsiManager;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.psi.JetFile;
|
||||
import org.jetbrains.jet.plugin.JetMainDetector;
|
||||
import org.jetbrains.k2js.facade.K2JSTranslator;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import static org.jetbrains.jet.plugin.actions.JavaToKotlinActionUtil.allVirtualFiles;
|
||||
|
||||
//TODO: clean up
|
||||
|
||||
/**
|
||||
* @author Pavel Talanov
|
||||
*/
|
||||
public final class TranslateToJsAction extends AnAction {
|
||||
|
||||
private static void notifyFailure(@NotNull Throwable exception) {
|
||||
Notifications.Bus.notify(new Notification("JsTranslator", "Translation failed.",
|
||||
"Exception: " + exception.getMessage(),
|
||||
NotificationType.ERROR));
|
||||
}
|
||||
|
||||
private static void notifySuccess(@NotNull String outputPath) {
|
||||
Notifications.Bus.notify(new Notification("JsTranslator", "Translation successful.",
|
||||
"Generated file: " + outputPath,
|
||||
NotificationType.INFORMATION));
|
||||
}
|
||||
|
||||
public void actionPerformed(final AnActionEvent event) {
|
||||
Runnable task = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
performAction(event);
|
||||
} catch (Throwable e) {
|
||||
e.printStackTrace();
|
||||
notifyFailure(e);
|
||||
}
|
||||
}
|
||||
};
|
||||
ApplicationManager.getApplication().runWriteAction(task);
|
||||
}
|
||||
|
||||
private static void performAction(@NotNull AnActionEvent event) throws Exception {
|
||||
final Project project = PlatformDataKeys.PROJECT.getData(event.getDataContext());
|
||||
assert project != null;
|
||||
Set<VirtualFile> allVirtualFiles = getAllProjectVirtualFiles(project);
|
||||
List<JetFile> kotlinFiles = getJetFiles(allVirtualFiles, project);
|
||||
String outputPath = getOutputPath(JetMainDetector.getFileWithMain(kotlinFiles));
|
||||
K2JSTranslator.translateWithCallToMainAndSaveToFile(kotlinFiles,
|
||||
outputPath,
|
||||
project);
|
||||
notifySuccess(outputPath);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static Set<VirtualFile> getAllProjectVirtualFiles(@NotNull Project project) {
|
||||
Module[] modules = ModuleManager.getInstance(project).getModules();
|
||||
Set<VirtualFile> allVirtualFiles = allVirtualFiles(new VirtualFile[]{project.getBaseDir()});
|
||||
for (Module module : modules) {
|
||||
VirtualFile[] roots = ModuleRootManager.getInstance(module).getContentRoots();
|
||||
allVirtualFiles.addAll(allVirtualFiles(roots));
|
||||
}
|
||||
return allVirtualFiles;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static List<JetFile> getJetFiles(@NotNull Collection<VirtualFile> virtualFiles,
|
||||
@NotNull Project project) {
|
||||
List<JetFile> kotlinFiles = Lists.newArrayList();
|
||||
|
||||
PsiManager psiManager = PsiManager.getInstance(project);
|
||||
for (VirtualFile virtualFile : virtualFiles) {
|
||||
PsiFile psiFile = psiManager.findFile(virtualFile);
|
||||
if (psiFile instanceof JetFile) {
|
||||
kotlinFiles.add((JetFile) psiFile);
|
||||
}
|
||||
}
|
||||
return kotlinFiles;
|
||||
}
|
||||
|
||||
|
||||
@NotNull
|
||||
private static String getOutputPath(@Nullable PsiFile psiFile) {
|
||||
if (psiFile == null) {
|
||||
throw new AssertionError("Main was not detected.");
|
||||
}
|
||||
VirtualFile virtualFile = psiFile.getVirtualFile();
|
||||
assert virtualFile != null : "Internal error: Psi file should correspond to actual virtual file";
|
||||
String originalFilePath = virtualFile.getPath();
|
||||
|
||||
//TODO: make platform independent
|
||||
String pathToDir = originalFilePath.substring(0, originalFilePath.lastIndexOf("/") + 1);
|
||||
String generatedFileName = ((JetFile) psiFile).getNamespaceHeader().getName() + ".js";
|
||||
return pathToDir + generatedFileName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(AnActionEvent e) {
|
||||
Editor editor = e.getData(PlatformDataKeys.EDITOR);
|
||||
e.getPresentation().setEnabled(editor != null);
|
||||
}
|
||||
}
|
||||
Generated
-1
@@ -1 +0,0 @@
|
||||
k2js
|
||||
Generated
-7
@@ -1,7 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="AntConfiguration">
|
||||
<defaultAnt bundledAnt="true" />
|
||||
</component>
|
||||
</project>
|
||||
|
||||
Generated
-23
@@ -1,23 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="CompilerConfiguration">
|
||||
<option name="DEFAULT_COMPILER" value="Javac" />
|
||||
<resourceExtensions />
|
||||
<wildcardResourcePatterns>
|
||||
<entry name="?*.properties" />
|
||||
<entry name="?*.xml" />
|
||||
<entry name="?*.gif" />
|
||||
<entry name="?*.png" />
|
||||
<entry name="?*.jpeg" />
|
||||
<entry name="?*.jpg" />
|
||||
<entry name="?*.html" />
|
||||
<entry name="?*.dtd" />
|
||||
<entry name="?*.tld" />
|
||||
<entry name="?*.ftl" />
|
||||
<entry name="?*.jet" />
|
||||
<entry name="?*.kt" />
|
||||
</wildcardResourcePatterns>
|
||||
<annotationProcessing enabled="false" useClasspath="true" />
|
||||
</component>
|
||||
</project>
|
||||
|
||||
Generated
-9
@@ -1,9 +0,0 @@
|
||||
<component name="CopyrightManager">
|
||||
<copyright>
|
||||
<option name="notice" value="Copyright 2000-&#36;today.year JetBrains s.r.o. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License." />
|
||||
<option name="keyword" value="Copyright" />
|
||||
<option name="allowReplaceKeyword" value="JetBrains" />
|
||||
<option name="myName" value="apache" />
|
||||
<option name="myLocal" value="true" />
|
||||
</copyright>
|
||||
</component>
|
||||
Generated
-7
@@ -1,7 +0,0 @@
|
||||
<component name="CopyrightManager">
|
||||
<settings default="apache">
|
||||
<module2copyright>
|
||||
<element module="All" copyright="apache" />
|
||||
</module2copyright>
|
||||
</settings>
|
||||
</component>
|
||||
Generated
-3
@@ -1,3 +0,0 @@
|
||||
<component name="ProjectDictionaryState">
|
||||
<dictionary name="Pavel.Talanov" />
|
||||
</component>
|
||||
Generated
-5
@@ -1,5 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="Encoding" useUTFGuessing="true" native2AsciiForPropertiesFiles="false" />
|
||||
</project>
|
||||
|
||||
-8
@@ -1,8 +0,0 @@
|
||||
<component name="InspectionProjectProfileManager">
|
||||
<profile version="1.0" is_locked="false">
|
||||
<option name="myName" value="Project Default" />
|
||||
<option name="myLocal" value="false" />
|
||||
<inspection_tool class="SimplifiableIfStatement" enabled="false" level="WARNING" enabled_by_default="false" />
|
||||
<inspection_tool class="TrivialIf" enabled="false" level="WARNING" enabled_by_default="false" />
|
||||
</profile>
|
||||
</component>
|
||||
@@ -1,7 +0,0 @@
|
||||
<component name="InspectionProjectProfileManager">
|
||||
<settings>
|
||||
<option name="PROJECT_PROFILE" value="Project Default" />
|
||||
<option name="USE_PROJECT_PROFILE" value="true" />
|
||||
<version value="1.0" />
|
||||
</settings>
|
||||
</component>
|
||||
Generated
-9
@@ -1,9 +0,0 @@
|
||||
<component name="libraryTable">
|
||||
<library name="guava-10.0.1">
|
||||
<CLASSES>
|
||||
<root url="jar://$PROJECT_DIR$/translator/lib/guava-10.0.1.jar!/" />
|
||||
</CLASSES>
|
||||
<JAVADOC />
|
||||
<SOURCES />
|
||||
</library>
|
||||
</component>
|
||||
Generated
-36
@@ -1,36 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="EntryPointsManager">
|
||||
<entry_points version="2.0" />
|
||||
</component>
|
||||
<component name="IdProvider" IDEtalkID="C5E9A8C8EEE7359144ADEDA64003CE1D" />
|
||||
<component name="JavadocGenerationManager">
|
||||
<option name="OUTPUT_DIRECTORY" />
|
||||
<option name="OPTION_SCOPE" value="protected" />
|
||||
<option name="OPTION_HIERARCHY" value="true" />
|
||||
<option name="OPTION_NAVIGATOR" value="true" />
|
||||
<option name="OPTION_INDEX" value="true" />
|
||||
<option name="OPTION_SEPARATE_INDEX" value="true" />
|
||||
<option name="OPTION_DOCUMENT_TAG_USE" value="false" />
|
||||
<option name="OPTION_DOCUMENT_TAG_AUTHOR" value="false" />
|
||||
<option name="OPTION_DOCUMENT_TAG_VERSION" value="false" />
|
||||
<option name="OPTION_DOCUMENT_TAG_DEPRECATED" value="true" />
|
||||
<option name="OPTION_DEPRECATED_LIST" value="true" />
|
||||
<option name="OTHER_OPTIONS" value="" />
|
||||
<option name="HEAP_SIZE" />
|
||||
<option name="LOCALE" />
|
||||
<option name="OPEN_IN_BROWSER" value="true" />
|
||||
</component>
|
||||
<component name="ProjectResources">
|
||||
<default-html-doctype>http://www.w3.org/1999/xhtml</default-html-doctype>
|
||||
</component>
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_6" assert-keyword="true" jdk-15="true" project-jdk-name="1.6" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/out" />
|
||||
</component>
|
||||
<component name="com.sixrr.metrics.MetricsReloaded">
|
||||
<option name="selectedProfile" value="Lines of code metrics" />
|
||||
<option name="autoscroll" value="false" />
|
||||
<option name="showOnlyWarnings" value="false" />
|
||||
</component>
|
||||
</project>
|
||||
|
||||
Generated
-20
@@ -1,20 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/../../Kotlin/jet/compiler/backend/backend.iml" filepath="$PROJECT_DIR$/../../Kotlin/jet/compiler/backend/backend.iml" />
|
||||
<module fileurl="file://$PROJECT_DIR$/../../Kotlin/jet/compiler/cli/cli.iml" filepath="$PROJECT_DIR$/../../Kotlin/jet/compiler/cli/cli.iml" />
|
||||
<module fileurl="file://$PROJECT_DIR$/../../Kotlin/jet/compiler/tests/compiler-tests.iml" filepath="$PROJECT_DIR$/../../Kotlin/jet/compiler/tests/compiler-tests.iml" />
|
||||
<module fileurl="file://$PROJECT_DIR$/../../Kotlin/jet/compiler/frontend/frontend.iml" filepath="$PROJECT_DIR$/../../Kotlin/jet/compiler/frontend/frontend.iml" />
|
||||
<module fileurl="file://$PROJECT_DIR$/../../Kotlin/jet/compiler/frontend.java/frontend.java.iml" filepath="$PROJECT_DIR$/../../Kotlin/jet/compiler/frontend.java/frontend.java.iml" />
|
||||
<module fileurl="file://$PROJECT_DIR$/js.ast/js.ast.iml" filepath="$PROJECT_DIR$/js.ast/js.ast.iml" />
|
||||
<module fileurl="file://$PROJECT_DIR$/js.backend/js.backend.iml" filepath="$PROJECT_DIR$/js.backend/js.backend.iml" />
|
||||
<module fileurl="file://$PROJECT_DIR$/js.examples/js.examples.iml" filepath="$PROJECT_DIR$/js.examples/js.examples.iml" />
|
||||
<module fileurl="file://$PROJECT_DIR$/js.tests/js.tests.iml" filepath="$PROJECT_DIR$/js.tests/js.tests.iml" />
|
||||
<module fileurl="file://$PROJECT_DIR$/js.lib/jslib.iml" filepath="$PROJECT_DIR$/js.lib/jslib.iml" />
|
||||
<module fileurl="file://$PROJECT_DIR$/../../Kotlin/jet/stdlib/stdlib.iml" filepath="$PROJECT_DIR$/../../Kotlin/jet/stdlib/stdlib.iml" />
|
||||
<module fileurl="file://$PROJECT_DIR$/../../Kotlin/jet/compiler/util/util.iml" filepath="$PROJECT_DIR$/../../Kotlin/jet/compiler/util/util.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
||||
|
||||
Generated
-5
@@ -1,5 +0,0 @@
|
||||
<component name="DependencyValidationManager">
|
||||
<state>
|
||||
<option name="SKIP_IMPORT_STATEMENTS" value="false" />
|
||||
</state>
|
||||
</component>
|
||||
Generated
-125
@@ -1,125 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="Palette2">
|
||||
<group name="Swing">
|
||||
<item class="com.intellij.uiDesigner.HSpacer" tooltip-text="Horizontal Spacer" icon="/com/intellij/uiDesigner/icons/hspacer.png" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="1" hsize-policy="6" anchor="0" fill="1" />
|
||||
</item>
|
||||
<item class="com.intellij.uiDesigner.VSpacer" tooltip-text="Vertical Spacer" icon="/com/intellij/uiDesigner/icons/vspacer.png" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="6" hsize-policy="1" anchor="0" fill="2" />
|
||||
</item>
|
||||
<item class="javax.swing.JPanel" icon="/com/intellij/uiDesigner/icons/panel.png" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3" />
|
||||
</item>
|
||||
<item class="javax.swing.JScrollPane" icon="/com/intellij/uiDesigner/icons/scrollPane.png" removable="false" auto-create-binding="false" can-attach-label="true">
|
||||
<default-constraints vsize-policy="7" hsize-policy="7" anchor="0" fill="3" />
|
||||
</item>
|
||||
<item class="javax.swing.JButton" icon="/com/intellij/uiDesigner/icons/button.png" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="3" anchor="0" fill="1" />
|
||||
<initial-values>
|
||||
<property name="text" value="Button" />
|
||||
</initial-values>
|
||||
</item>
|
||||
<item class="javax.swing.JRadioButton" icon="/com/intellij/uiDesigner/icons/radioButton.png" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
|
||||
<initial-values>
|
||||
<property name="text" value="RadioButton" />
|
||||
</initial-values>
|
||||
</item>
|
||||
<item class="javax.swing.JCheckBox" icon="/com/intellij/uiDesigner/icons/checkBox.png" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
|
||||
<initial-values>
|
||||
<property name="text" value="CheckBox" />
|
||||
</initial-values>
|
||||
</item>
|
||||
<item class="javax.swing.JLabel" icon="/com/intellij/uiDesigner/icons/label.png" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="0" anchor="8" fill="0" />
|
||||
<initial-values>
|
||||
<property name="text" value="Label" />
|
||||
</initial-values>
|
||||
</item>
|
||||
<item class="javax.swing.JTextField" icon="/com/intellij/uiDesigner/icons/textField.png" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
|
||||
<preferred-size width="150" height="-1" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JPasswordField" icon="/com/intellij/uiDesigner/icons/passwordField.png" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
|
||||
<preferred-size width="150" height="-1" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JFormattedTextField" icon="/com/intellij/uiDesigner/icons/formattedTextField.png" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
|
||||
<preferred-size width="150" height="-1" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JTextArea" icon="/com/intellij/uiDesigner/icons/textArea.png" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||
<preferred-size width="150" height="50" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JTextPane" icon="/com/intellij/uiDesigner/icons/textPane.png" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||
<preferred-size width="150" height="50" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JEditorPane" icon="/com/intellij/uiDesigner/icons/editorPane.png" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||
<preferred-size width="150" height="50" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JComboBox" icon="/com/intellij/uiDesigner/icons/comboBox.png" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="0" hsize-policy="2" anchor="8" fill="1" />
|
||||
</item>
|
||||
<item class="javax.swing.JTable" icon="/com/intellij/uiDesigner/icons/table.png" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||
<preferred-size width="150" height="50" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JList" icon="/com/intellij/uiDesigner/icons/list.png" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="6" hsize-policy="2" anchor="0" fill="3">
|
||||
<preferred-size width="150" height="50" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JTree" icon="/com/intellij/uiDesigner/icons/tree.png" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||
<preferred-size width="150" height="50" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JTabbedPane" icon="/com/intellij/uiDesigner/icons/tabbedPane.png" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
|
||||
<preferred-size width="200" height="200" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JSplitPane" icon="/com/intellij/uiDesigner/icons/splitPane.png" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
|
||||
<preferred-size width="200" height="200" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JSpinner" icon="/com/intellij/uiDesigner/icons/spinner.png" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
|
||||
</item>
|
||||
<item class="javax.swing.JSlider" icon="/com/intellij/uiDesigner/icons/slider.png" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
|
||||
</item>
|
||||
<item class="javax.swing.JSeparator" icon="/com/intellij/uiDesigner/icons/separator.png" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3" />
|
||||
</item>
|
||||
<item class="javax.swing.JProgressBar" icon="/com/intellij/uiDesigner/icons/progressbar.png" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1" />
|
||||
</item>
|
||||
<item class="javax.swing.JToolBar" icon="/com/intellij/uiDesigner/icons/toolbar.png" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1">
|
||||
<preferred-size width="-1" height="20" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JToolBar$Separator" icon="/com/intellij/uiDesigner/icons/toolbarSeparator.png" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="0" anchor="0" fill="1" />
|
||||
</item>
|
||||
<item class="javax.swing.JScrollBar" icon="/com/intellij/uiDesigner/icons/scrollbar.png" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="6" hsize-policy="0" anchor="0" fill="2" />
|
||||
</item>
|
||||
</group>
|
||||
</component>
|
||||
</project>
|
||||
|
||||
Generated
-7
@@ -1,7 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="" vcs="Git" />
|
||||
</component>
|
||||
</project>
|
||||
|
||||
Generated
-1097
File diff suppressed because it is too large
Load Diff
+315
File diff suppressed because one or more lines are too long
@@ -8,6 +8,7 @@
|
||||
<orderEntry type="jdk" jdkName="1.6" jdkType="JavaSDK" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
<orderEntry type="library" name="guava-10.0.1" level="application" />
|
||||
<orderEntry type="library" name="js_libs" level="project" />
|
||||
</component>
|
||||
</module>
|
||||
|
||||
|
||||
@@ -1,26 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="JAVA_MODULE" version="4">
|
||||
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||
<exclude-output />
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
<orderEntry type="module-library">
|
||||
<library>
|
||||
<CLASSES>
|
||||
<root url="jar://$APPLICATION_HOME_DIR$/lib/annotations.jar!/" />
|
||||
</CLASSES>
|
||||
<JAVADOC />
|
||||
<SOURCES />
|
||||
</library>
|
||||
</orderEntry>
|
||||
<orderEntry type="library" name="guava-10.0.1" level="application" />
|
||||
<orderEntry type="library" name="js" level="application" />
|
||||
<orderEntry type="library" name="idea-full" level="application" />
|
||||
<orderEntry type="module" module-name="js.ast" />
|
||||
<orderEntry type="module" module-name="jslib" />
|
||||
</component>
|
||||
</module>
|
||||
|
||||
Binary file not shown.
@@ -1,163 +0,0 @@
|
||||
/*
|
||||
* Copyright 2000-2012 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.k2js.translate.utils;
|
||||
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.tree.IElementType;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.psi.*;
|
||||
import org.jetbrains.jet.lexer.JetToken;
|
||||
import org.jetbrains.jet.lexer.JetTokens;
|
||||
import org.jetbrains.k2js.translate.context.Namer;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Pavel Talanov
|
||||
*/
|
||||
public final class PsiUtils {
|
||||
|
||||
private PsiUtils() {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static JetSimpleNameExpression getSelectorAsSimpleName(@NotNull JetQualifiedExpression expression) {
|
||||
JetExpression selectorExpression = getSelector(expression);
|
||||
if (!(selectorExpression instanceof JetSimpleNameExpression)) {
|
||||
return null;
|
||||
}
|
||||
return (JetSimpleNameExpression) selectorExpression;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static JetExpression getSelector(@NotNull JetQualifiedExpression expression) {
|
||||
JetExpression selectorExpression = expression.getSelectorExpression();
|
||||
assert selectorExpression != null : "Selector should not be null.";
|
||||
return selectorExpression;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static JetSimpleNameExpression getNotNullSimpleNameSelector(@NotNull JetQualifiedExpression expression) {
|
||||
JetSimpleNameExpression selectorAsSimpleName = getSelectorAsSimpleName(expression);
|
||||
assert selectorAsSimpleName != null;
|
||||
return selectorAsSimpleName;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static JetToken getOperationToken(@NotNull JetOperationExpression expression) {
|
||||
JetSimpleNameExpression operationExpression = expression.getOperationReference();
|
||||
IElementType elementType = operationExpression.getReferencedNameElementType();
|
||||
assert elementType instanceof JetToken : "Unary expression should have operation token of type JetToken";
|
||||
return (JetToken) elementType;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static JetExpression getBaseExpression(@NotNull JetUnaryExpression expression) {
|
||||
JetExpression baseExpression = expression.getBaseExpression();
|
||||
assert baseExpression != null;
|
||||
return baseExpression;
|
||||
}
|
||||
|
||||
public static boolean isPrefix(@NotNull JetUnaryExpression expression) {
|
||||
return (expression instanceof JetPrefixExpression);
|
||||
}
|
||||
|
||||
public static boolean isAssignment(JetToken token) {
|
||||
return (token == JetTokens.EQ);
|
||||
}
|
||||
|
||||
public static boolean isBackingFieldReference(@NotNull JetSimpleNameExpression expression) {
|
||||
return expression.getReferencedNameElementType() == JetTokens.FIELD_IDENTIFIER;
|
||||
}
|
||||
|
||||
public static boolean isInOrNotInOperation(@NotNull JetBinaryExpression binaryExpression) {
|
||||
return isInOperation(binaryExpression) || isNotInOperation(binaryExpression);
|
||||
}
|
||||
|
||||
public static boolean isNotInOperation(@NotNull JetBinaryExpression binaryExpression) {
|
||||
return (binaryExpression.getOperationToken() == JetTokens.NOT_IN);
|
||||
}
|
||||
|
||||
private static boolean isInOperation(@NotNull JetBinaryExpression binaryExpression) {
|
||||
return (binaryExpression.getOperationToken() == JetTokens.IN_KEYWORD);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static JetExpression getCallee(@NotNull JetCallExpression expression) {
|
||||
JetExpression calleeExpression = expression.getCalleeExpression();
|
||||
assert calleeExpression != null;
|
||||
return calleeExpression;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static JetExpression getLoopBody(@NotNull JetLoopExpression expression) {
|
||||
JetExpression body = expression.getBody();
|
||||
assert body != null : "Loops cannot have null bodies.";
|
||||
return body;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static JetParameter getLoopParameter(@NotNull JetForExpression expression) {
|
||||
JetParameter loopParameter = expression.getLoopParameter();
|
||||
assert loopParameter != null;
|
||||
return loopParameter;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static List<JetParameter> getPrimaryConstructorParameters(@NotNull JetClassOrObject classDeclaration) {
|
||||
if (classDeclaration instanceof JetClass) {
|
||||
return ((JetClass) classDeclaration).getPrimaryConstructorParameters();
|
||||
}
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static JetObjectDeclaration getObjectDeclarationForName(@NotNull JetObjectDeclarationName name) {
|
||||
PsiElement parent = name.getParent();
|
||||
assert parent instanceof JetObjectDeclaration :
|
||||
"ObjectDeclarationName should have a parent of type ObjectDeclaration.";
|
||||
return (JetObjectDeclaration) parent;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static JetObjectDeclarationName getObjectDeclarationName(@NotNull JetObjectDeclaration objectDeclaration) {
|
||||
//TODO: util
|
||||
JetObjectDeclarationName nameAsDeclaration = objectDeclaration.getNameAsDeclaration();
|
||||
assert nameAsDeclaration != null;
|
||||
return nameAsDeclaration;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static String getNamespaceName(@NotNull JetFile psiFile) {
|
||||
JetNamespaceHeader namespaceHeader = psiFile.getNamespaceHeader();
|
||||
String name = namespaceHeader.getName();
|
||||
assert name != null : "NamespaceHeader must have a name";
|
||||
if (name.equals("")) {
|
||||
return Namer.getAnonymousNamespaceName();
|
||||
}
|
||||
return name;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static JetExpression getLoopRange(@NotNull JetForExpression expression) {
|
||||
JetExpression rangeExpression = expression.getLoopRange();
|
||||
assert rangeExpression != null;
|
||||
return rangeExpression;
|
||||
}
|
||||
}
|
||||
@@ -1,233 +0,0 @@
|
||||
/*
|
||||
* Copyright 2000-2012 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.k2js.translate.utils;
|
||||
|
||||
import com.google.dart.compiler.backend.js.ast.*;
|
||||
import com.google.dart.compiler.util.AstUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.descriptors.*;
|
||||
import org.jetbrains.jet.lang.psi.*;
|
||||
import org.jetbrains.k2js.translate.context.NamingScope;
|
||||
import org.jetbrains.k2js.translate.context.TemporaryVariable;
|
||||
import org.jetbrains.k2js.translate.context.TranslationContext;
|
||||
import org.jetbrains.k2js.translate.general.Translation;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static org.jetbrains.k2js.translate.utils.BindingUtils.*;
|
||||
import static org.jetbrains.k2js.translate.utils.DescriptorUtils.getExpectedReceiverDescriptor;
|
||||
|
||||
/**
|
||||
* @author Pavel Talanov
|
||||
*/
|
||||
public final class TranslationUtils {
|
||||
|
||||
@NotNull
|
||||
public static JsBinaryOperation notNullCheck(@NotNull TranslationContext context,
|
||||
@NotNull JsExpression expressionToCheck) {
|
||||
JsNullLiteral nullLiteral = context.program().getNullLiteral();
|
||||
return AstUtil.notEqual(expressionToCheck, nullLiteral);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static JsBinaryOperation isNullCheck(@NotNull TranslationContext context,
|
||||
@NotNull JsExpression expressionToCheck) {
|
||||
JsNullLiteral nullLiteral = context.program().getNullLiteral();
|
||||
return AstUtil.equals(expressionToCheck, nullLiteral);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static List<JsExpression> translateArgumentList(@NotNull TranslationContext context,
|
||||
@NotNull List<? extends ValueArgument> jetArguments) {
|
||||
List<JsExpression> jsArguments = new ArrayList<JsExpression>();
|
||||
for (ValueArgument argument : jetArguments) {
|
||||
jsArguments.add(translateArgument(context, argument));
|
||||
}
|
||||
return jsArguments;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static JsExpression translateArgument(@NotNull TranslationContext context, @NotNull ValueArgument argument) {
|
||||
JetExpression jetExpression = argument.getArgumentExpression();
|
||||
assert jetExpression != null : "Argument with no expression";
|
||||
return Translation.translateAsExpression(jetExpression, context);
|
||||
}
|
||||
|
||||
//TODO: refactor backing field reference generation to use the generic way
|
||||
@NotNull
|
||||
public static JsNameRef backingFieldReference(@NotNull TranslationContext context,
|
||||
@NotNull JetProperty expression) {
|
||||
PropertyDescriptor propertyDescriptor = getPropertyDescriptor(context.bindingContext(), expression);
|
||||
return backingFieldReference(context, propertyDescriptor);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static JsNameRef backingFieldReference(@NotNull TranslationContext context,
|
||||
@NotNull PropertyDescriptor descriptor) {
|
||||
JsName backingFieldName = context.getNameForDescriptor(descriptor);
|
||||
if (isOwnedByClass(descriptor)) {
|
||||
return AstUtil.qualified(backingFieldName, new JsThisRef());
|
||||
}
|
||||
assert isOwnedByNamespace(descriptor)
|
||||
: "Only classes and namespaces may own backing fields.";
|
||||
JsNameRef qualifier = context.getQualifierForDescriptor(descriptor);
|
||||
return AstUtil.qualified(backingFieldName, qualifier);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static JsStatement assignmentToBackingField(@NotNull TranslationContext context,
|
||||
@NotNull PropertyDescriptor descriptor,
|
||||
@NotNull JsExpression assignTo) {
|
||||
JsNameRef backingFieldReference = backingFieldReference(context, descriptor);
|
||||
return AstUtil.newAssignmentStatement(backingFieldReference, assignTo);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static JsExpression translateInitializerForProperty(@NotNull JetProperty declaration,
|
||||
@NotNull TranslationContext context) {
|
||||
JsExpression jsInitExpression = null;
|
||||
JetExpression initializer = declaration.getInitializer();
|
||||
if (initializer != null) {
|
||||
jsInitExpression = Translation.translateAsExpression(initializer, context);
|
||||
}
|
||||
return jsInitExpression;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static JsNameRef getQualifiedReference(@NotNull TranslationContext context,
|
||||
@NotNull DeclarationDescriptor descriptor) {
|
||||
JsName name = context.getNameForDescriptor(descriptor);
|
||||
JsNameRef reference = name.makeRef();
|
||||
JsNameRef qualifier = context.getQualifierForDescriptor(descriptor);
|
||||
if (qualifier != null) {
|
||||
AstUtil.setQualifier(reference, qualifier);
|
||||
}
|
||||
return reference;
|
||||
}
|
||||
|
||||
//TODO: refactor
|
||||
@NotNull
|
||||
public static JsExpression getThisObject(@NotNull TranslationContext context,
|
||||
@NotNull DeclarationDescriptor correspondingDeclaration) {
|
||||
JsExpression thisRef = null;
|
||||
if (correspondingDeclaration instanceof ClassDescriptor) {
|
||||
if (context.aliaser().hasAliasForThis(correspondingDeclaration)) {
|
||||
thisRef = context.aliaser().getAliasForThis(correspondingDeclaration);
|
||||
}
|
||||
}
|
||||
if (correspondingDeclaration instanceof CallableDescriptor) {
|
||||
DeclarationDescriptor receiverDescriptor =
|
||||
getExpectedReceiverDescriptor((CallableDescriptor) correspondingDeclaration);
|
||||
assert receiverDescriptor != null;
|
||||
if (context.aliaser().hasAliasForThis(receiverDescriptor)) {
|
||||
thisRef = context.aliaser().getAliasForThis(receiverDescriptor);
|
||||
}
|
||||
}
|
||||
if (thisRef != null) {
|
||||
return thisRef;
|
||||
}
|
||||
return new JsThisRef();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static List<JsExpression> translateExpressionList(@NotNull TranslationContext context,
|
||||
@NotNull List<JetExpression> expressions) {
|
||||
List<JsExpression> result = new ArrayList<JsExpression>();
|
||||
for (JetExpression expression : expressions) {
|
||||
result.add(Translation.translateAsExpression(expression, context));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static JsExpression translateBaseExpression(@NotNull TranslationContext context,
|
||||
@NotNull JetUnaryExpression expression) {
|
||||
JetExpression baseExpression = PsiUtils.getBaseExpression(expression);
|
||||
return Translation.translateAsExpression(baseExpression, context);
|
||||
}
|
||||
|
||||
//TODO:
|
||||
@NotNull
|
||||
public static JsExpression translateReceiver(@NotNull TranslationContext context,
|
||||
@NotNull JetDotQualifiedExpression expression) {
|
||||
return Translation.translateAsExpression(expression.getReceiverExpression(), context);
|
||||
}
|
||||
|
||||
|
||||
@NotNull
|
||||
public static JsExpression translateLeftExpression(@NotNull TranslationContext context,
|
||||
@NotNull JetBinaryExpression expression) {
|
||||
return Translation.translateAsExpression(expression.getLeft(), context);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static JsExpression translateRightExpression(@NotNull TranslationContext context,
|
||||
@NotNull JetBinaryExpression expression) {
|
||||
JetExpression rightExpression = expression.getRight();
|
||||
assert rightExpression != null : "Binary expression should have a right expression";
|
||||
return Translation.translateAsExpression(rightExpression, context);
|
||||
}
|
||||
|
||||
public static boolean isIntrinsicOperation(@NotNull TranslationContext context,
|
||||
@NotNull JetOperationExpression expression) {
|
||||
FunctionDescriptor operationDescriptor =
|
||||
BindingUtils.getFunctionDescriptorForOperationExpression(context.bindingContext(), expression);
|
||||
|
||||
if (operationDescriptor == null) return true;
|
||||
if (context.intrinsics().isIntrinsic(operationDescriptor)) return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static JsNameRef getMethodReferenceForOverloadedOperation(@NotNull TranslationContext context,
|
||||
@NotNull JetOperationExpression expression) {
|
||||
FunctionDescriptor overloadedOperationDescriptor = getFunctionDescriptorForOperationExpression
|
||||
(context.bindingContext(), expression);
|
||||
assert overloadedOperationDescriptor != null;
|
||||
JsNameRef overloadedOperationReference = context.getNameForDescriptor(overloadedOperationDescriptor).makeRef();
|
||||
assert overloadedOperationReference != null;
|
||||
return overloadedOperationReference;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static JsFunction functionWithScope(@NotNull NamingScope scope) {
|
||||
return JsFunction.getAnonymousFunctionWithScope(scope.jsScope());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static JsNumberLiteral zeroLiteral(@NotNull TranslationContext context) {
|
||||
return context.program().getNumberLiteral(0);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static TemporaryVariable newAliasForThis(@NotNull TranslationContext context,
|
||||
@NotNull DeclarationDescriptor descriptor) {
|
||||
JsExpression thisQualifier = getThisObject(context, descriptor);
|
||||
TemporaryVariable aliasForThis = context.declareTemporary(thisQualifier);
|
||||
context.aliaser().setAliasForThis(descriptor, aliasForThis.name());
|
||||
return aliasForThis;
|
||||
}
|
||||
|
||||
public static void removeAliasForThis(@NotNull TranslationContext context,
|
||||
@NotNull DeclarationDescriptor descriptor) {
|
||||
context.aliaser().removeAliasForThis(descriptor);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,43 +0,0 @@
|
||||
/*
|
||||
* Copyright 2000-2012 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.k2js.utils;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
//TODO: very thin class
|
||||
|
||||
/**
|
||||
* @author Pavel Talanov
|
||||
*/
|
||||
public final class GenerationUtils {
|
||||
|
||||
@NotNull
|
||||
public static String generateCallToMain(@NotNull String namespaceName, @NotNull List<String> arguments) {
|
||||
String constructArguments = "var args = [];\n";
|
||||
int index = 0;
|
||||
for (String argument : arguments) {
|
||||
constructArguments = constructArguments + "args[" + index + "]= \"" + argument + "\";\n";
|
||||
index++;
|
||||
}
|
||||
String callMain = namespaceName + ".main(args);\n";
|
||||
return constructArguments + callMain;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -1,89 +0,0 @@
|
||||
/*
|
||||
* Copyright 2000-2012 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.k2js.utils;
|
||||
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.openapi.vfs.CharsetToolkit;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.psi.PsiFileFactory;
|
||||
import com.intellij.psi.impl.PsiFileFactoryImpl;
|
||||
import com.intellij.testFramework.LightVirtualFile;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.psi.JetFile;
|
||||
import org.jetbrains.jet.plugin.JetLanguage;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Pavel Talanov
|
||||
*/
|
||||
public final class JetFileUtils {
|
||||
|
||||
@NotNull
|
||||
public static String loadFile(@NotNull String path) throws IOException {
|
||||
return doLoadFile(path);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static String doLoadFile(@NotNull String path) throws IOException {
|
||||
String text = FileUtil.loadFile(new File(path), CharsetToolkit.UTF8).trim();
|
||||
text = StringUtil.convertLineSeparators(text);
|
||||
return text;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static JetFile createPsiFile(@NotNull String name,
|
||||
@NotNull String text,
|
||||
@NotNull Project project) {
|
||||
return (JetFile) createFile(name + ".jet", text, project);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static JetFile loadPsiFile(@NotNull String name, @NotNull Project project) {
|
||||
try {
|
||||
return createPsiFile(name, loadFile(name), project);
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static PsiFile createFile(@NotNull String name, @NotNull String text, @NotNull Project project) {
|
||||
LightVirtualFile virtualFile = new LightVirtualFile(name, JetLanguage.INSTANCE, text);
|
||||
virtualFile.setCharset(CharsetToolkit.UTF8_CHARSET);
|
||||
PsiFile result = ((PsiFileFactoryImpl) PsiFileFactory.getInstance(project))
|
||||
.trySetupPsiForFile(virtualFile, JetLanguage.INSTANCE, true, false);
|
||||
assert result != null;
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@NotNull
|
||||
public static List<JetFile> createPsiFileList(@NotNull List<String> inputFiles,
|
||||
@NotNull Project project) {
|
||||
List<JetFile> psiFiles = new ArrayList<JetFile>();
|
||||
for (String inputFile : inputFiles) {
|
||||
psiFiles.add(JetFileUtils.loadPsiFile(inputFile, project));
|
||||
}
|
||||
return psiFiles;
|
||||
}
|
||||
}
|
||||
@@ -1,178 +0,0 @@
|
||||
/*
|
||||
* Copyright 2000-2012 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.k2js.utils;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.cfg.pseudocode.JetControlFlowDataTraceFactory;
|
||||
import org.jetbrains.jet.lang.diagnostics.Diagnostic;
|
||||
import org.jetbrains.jet.lang.diagnostics.Severity;
|
||||
import org.jetbrains.jet.lang.diagnostics.UnresolvedReferenceDiagnostic;
|
||||
import org.jetbrains.jet.lang.psi.JetFile;
|
||||
import org.jetbrains.jet.lang.resolve.BindingContext;
|
||||
import org.jetbrains.jet.lang.resolve.BindingTrace;
|
||||
import org.jetbrains.jet.lang.resolve.java.AnalyzerFacade;
|
||||
import org.jetbrains.jet.util.slicedmap.ReadOnlySlice;
|
||||
import org.jetbrains.jet.util.slicedmap.SlicedMap;
|
||||
import org.jetbrains.jet.util.slicedmap.WritableSlice;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
|
||||
/**
|
||||
* @author abreslav
|
||||
*/
|
||||
public class JetTestUtils {
|
||||
public static final BindingTrace DUMMY_TRACE = new BindingTrace() {
|
||||
|
||||
|
||||
@Override
|
||||
public BindingContext getBindingContext() {
|
||||
return new BindingContext() {
|
||||
|
||||
@Override
|
||||
public Collection<Diagnostic> getDiagnostics() {
|
||||
throw new UnsupportedOperationException(); // TODO
|
||||
}
|
||||
|
||||
@Override
|
||||
public <K, V> V get(ReadOnlySlice<K, V> slice, K key) {
|
||||
return DUMMY_TRACE.get(slice, key);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public <K, V> Collection<K> getKeys(WritableSlice<K, V> slice) {
|
||||
return DUMMY_TRACE.getKeys(slice);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public <K, V> void record(WritableSlice<K, V> slice, K key, V value) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public <K> void record(WritableSlice<K, Boolean> slice, K key) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public <K, V> V get(ReadOnlySlice<K, V> slice, K key) {
|
||||
if (slice == BindingContext.PROCESSED) return (V) Boolean.FALSE;
|
||||
return SlicedMap.DO_NOTHING.get(slice, key);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public <K, V> Collection<K> getKeys(WritableSlice<K, V> slice) {
|
||||
assert slice.isCollective();
|
||||
return Collections.emptySet();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void report(@NotNull Diagnostic diagnostic) {
|
||||
if (diagnostic instanceof UnresolvedReferenceDiagnostic) {
|
||||
UnresolvedReferenceDiagnostic unresolvedReferenceDiagnostic = (UnresolvedReferenceDiagnostic) diagnostic;
|
||||
throw new IllegalStateException("Unresolved: " + unresolvedReferenceDiagnostic.getPsiElement().getText());
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
public static BindingTrace DUMMY_EXCEPTION_ON_ERROR_TRACE = new BindingTrace() {
|
||||
@Override
|
||||
public BindingContext getBindingContext() {
|
||||
return new BindingContext() {
|
||||
@Override
|
||||
public Collection<Diagnostic> getDiagnostics() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public <K, V> V get(ReadOnlySlice<K, V> slice, K key) {
|
||||
return DUMMY_EXCEPTION_ON_ERROR_TRACE.get(slice, key);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public <K, V> Collection<K> getKeys(WritableSlice<K, V> slice) {
|
||||
return DUMMY_EXCEPTION_ON_ERROR_TRACE.getKeys(slice);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public <K, V> void record(WritableSlice<K, V> slice, K key, V value) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public <K> void record(WritableSlice<K, Boolean> slice, K key) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public <K, V> V get(ReadOnlySlice<K, V> slice, K key) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public <K, V> Collection<K> getKeys(WritableSlice<K, V> slice) {
|
||||
assert slice.isCollective();
|
||||
return Collections.emptySet();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void report(@NotNull Diagnostic diagnostic) {
|
||||
if (diagnostic.getSeverity() == Severity.ERROR) {
|
||||
throw new IllegalStateException(diagnostic.getMessage());
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
public static BindingContext analyzeNamespace(@NotNull JetFile file, @NotNull JetControlFlowDataTraceFactory flowDataTraceFactory) {
|
||||
return AnalyzerFacade.analyzeOneFileWithJavaIntegration(file, flowDataTraceFactory);
|
||||
}
|
||||
|
||||
|
||||
public static void mkdirs(File file) throws IOException {
|
||||
if (file.isDirectory()) {
|
||||
return;
|
||||
}
|
||||
if (!file.mkdirs()) {
|
||||
throw new IOException();
|
||||
}
|
||||
}
|
||||
|
||||
public static void rmrf(File file) {
|
||||
if (file != null) {
|
||||
File[] children = file.listFiles();
|
||||
if (children != null) {
|
||||
for (File child : children) {
|
||||
rmrf(child);
|
||||
}
|
||||
}
|
||||
file.delete();
|
||||
}
|
||||
}
|
||||
|
||||
public static void recreateDirectory(File file) throws IOException {
|
||||
rmrf(file);
|
||||
mkdirs(file);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -1,27 +0,0 @@
|
||||
/*
|
||||
* Copyright 2000-2012 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
function getContext() {
|
||||
return getCanvas().getContext('2d');
|
||||
}
|
||||
|
||||
function getCanvas() {
|
||||
return document.getElementsByTagName('canvas')[0];
|
||||
}
|
||||
|
||||
function getKotlinLogo() {
|
||||
return document.getElementsByTagName('img')[0];
|
||||
}
|
||||
@@ -1,7 +0,0 @@
|
||||
class A(var a : Int) {
|
||||
{
|
||||
$a=3
|
||||
}
|
||||
}
|
||||
|
||||
fun box() = (A(1).a == 3)
|
||||
@@ -1,4 +0,0 @@
|
||||
# Ignore everything in this directory
|
||||
*
|
||||
# Except this file
|
||||
!.gitignore
|
||||
@@ -1,7 +0,0 @@
|
||||
fun box() : String {
|
||||
return apply( "OK", {(arg: String) -> arg } )
|
||||
}
|
||||
|
||||
fun apply(arg : String, f : (p:String) -> String) : String {
|
||||
return f(arg)
|
||||
}
|
||||
@@ -1,7 +0,0 @@
|
||||
fun box() : String {
|
||||
return if (apply( 5, {(arg: Int) -> arg + 13 } ) == 18) "OK" else "fail"
|
||||
}
|
||||
|
||||
fun apply(arg : Int, f : (p:Int) -> Int) : Int {
|
||||
return f(arg)
|
||||
}
|
||||
@@ -1,24 +0,0 @@
|
||||
// Changed when traits were introduced. May not make sense any more
|
||||
|
||||
open class Base() {
|
||||
public var v : Int = 0
|
||||
}
|
||||
|
||||
open class Left() : Base() {}
|
||||
trait Right : Base {}
|
||||
|
||||
class D() : Left(), Right
|
||||
|
||||
fun vl(l : Left) : Int = l.v
|
||||
fun vr(r : Right) : Int = r.v
|
||||
|
||||
fun box() : String {
|
||||
val d = D()
|
||||
d.v = 42
|
||||
|
||||
if (d.v != 42) return "Fail #1"
|
||||
if (vl(d) != 42) return "Fail #2"
|
||||
if (vr(d) != 42) return "Fail #3"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
fun box() : String {
|
||||
val cl = 39
|
||||
return if (sum(200, { val ff = {cl}; ff() }) == 239) "OK" else "FAIL"
|
||||
}
|
||||
|
||||
fun sum(arg:Int, f : () -> Int) : Int {
|
||||
return arg + f()
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
fun box() : String {
|
||||
val cl = 39
|
||||
return if (sum(200, { val m = { val r = { cl }; r() }; m() }) == 239) "OK" else "FAIL"
|
||||
}
|
||||
|
||||
fun sum(arg:Int, f : () -> Int) : Int {
|
||||
return arg + f()
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
class Point(val x : Int, val y : Int)
|
||||
|
||||
fun box() : String {
|
||||
val answer = apply(Point(3, 5), { Point.(scalar : Int) : Point ->
|
||||
Point(x * scalar, y * scalar)
|
||||
})
|
||||
|
||||
return if (answer.x == 6 && answer.y == 10) "OK" else "FAIL"
|
||||
}
|
||||
|
||||
fun apply(arg:Point, f : Point.(scalar : Int) -> Point) : Point {
|
||||
return arg.f(2)
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
open class Base() {
|
||||
fun n(n : Int) : Int = n + 1
|
||||
}
|
||||
|
||||
trait Abstract {}
|
||||
|
||||
class Derived1() : Base(), Abstract {}
|
||||
class Derived2() : Abstract, Base() {}
|
||||
|
||||
fun test(s : Base) : Boolean = s.n(238) == 239
|
||||
|
||||
fun box() : String {
|
||||
if (!test(Base())) return "Fail #1"
|
||||
if (!test(Derived1())) return "Fail #2"
|
||||
if (!test(Derived2())) return "Fail #3"
|
||||
return "OK"
|
||||
}
|
||||
@@ -1,14 +0,0 @@
|
||||
class Slot() {
|
||||
var vitality: Int = 10000
|
||||
|
||||
fun increaseVitality(delta: Int) {
|
||||
vitality = vitality + delta
|
||||
if (vitality > 65535) vitality = 65535;
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val s = Slot()
|
||||
s.increaseVitality(1000)
|
||||
if (s.vitality == 11000) return "OK" else return "fail"
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
open class Foo() {
|
||||
fun xyzzy(): String = "xyzzy"
|
||||
}
|
||||
|
||||
class Bar(): Foo() {
|
||||
fun test(): String = xyzzy()
|
||||
}
|
||||
|
||||
fun box() : String {
|
||||
val bar = Bar()
|
||||
val f = bar.test()
|
||||
return if (f == "xyzzy") "OK" else "fail"
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
class C() {
|
||||
public var f: Int
|
||||
|
||||
{
|
||||
$f = 610
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val c = C()
|
||||
if (c.f != 610) return "fail"
|
||||
return "OK"
|
||||
}
|
||||
@@ -1,19 +0,0 @@
|
||||
fun box() : String {
|
||||
val i: Int? = 7
|
||||
val j: Int? = null
|
||||
val k = 7
|
||||
|
||||
//verify errors
|
||||
if (i == 7) {}
|
||||
if (7 == i) {}
|
||||
|
||||
if (j == 7) {}
|
||||
if (7 == j) {}
|
||||
|
||||
if (i == k) {}
|
||||
if (k == i) {}
|
||||
|
||||
if (j == k) {}
|
||||
if (k == j) {}
|
||||
return "OK"
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
class SimpleClass() {
|
||||
fun foo() = 610
|
||||
}
|
||||
|
||||
fun box() : String {
|
||||
val c = SimpleClass()
|
||||
if (c.foo() == 610) {
|
||||
return "OK"
|
||||
}
|
||||
return "FAIL"
|
||||
}
|
||||
@@ -1,25 +0,0 @@
|
||||
import java.util.*
|
||||
|
||||
class ArrayWrapper<T>() {
|
||||
val contents = ArrayList<T>()
|
||||
|
||||
fun add(item: T) {
|
||||
contents.add(item)
|
||||
}
|
||||
|
||||
fun plus(b: ArrayWrapper<T>): ArrayWrapper<T> {
|
||||
val result = ArrayWrapper<T>()
|
||||
result.contents.addAll(contents)
|
||||
result.contents.addAll(b.contents)
|
||||
return result
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val v1 = ArrayWrapper<String>()
|
||||
val v2 = ArrayWrapper<String>()
|
||||
v1.add("foo")
|
||||
v2.add("bar")
|
||||
val v3 = v1 + v2
|
||||
return if (v3.contents.size() == 2) "OK" else "fail"
|
||||
}
|
||||
@@ -1,27 +0,0 @@
|
||||
import java.util.*
|
||||
|
||||
class ArrayWrapper<T>() {
|
||||
val contents = ArrayList<T>()
|
||||
|
||||
fun add(item: T) {
|
||||
contents.add(item)
|
||||
}
|
||||
|
||||
fun plusAssign(rhs: ArrayWrapper<T>) {
|
||||
contents.addAll(rhs.contents)
|
||||
}
|
||||
|
||||
fun get(index: Int): T {
|
||||
return contents.get(index)
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
var v1 = ArrayWrapper<String>()
|
||||
val v2 = ArrayWrapper<String>()
|
||||
v1.add("foo")
|
||||
val v3 = v1
|
||||
v2.add("bar")
|
||||
v1 += v2
|
||||
return if (v1.contents.size() == 2 && v3.contents.size() == 2) "OK" else "fail"
|
||||
}
|
||||
@@ -1,30 +0,0 @@
|
||||
import java.util.*
|
||||
|
||||
class ArrayWrapper<T>() {
|
||||
val contents = ArrayList<T>()
|
||||
|
||||
fun add(item: T) {
|
||||
contents.add(item)
|
||||
}
|
||||
|
||||
fun plus(rhs: ArrayWrapper<T>): ArrayWrapper<T> {
|
||||
val result = ArrayWrapper<T>()
|
||||
result.contents.addAll(contents)
|
||||
result.contents.addAll(rhs.contents)
|
||||
return result
|
||||
}
|
||||
|
||||
fun get(index: Int): T {
|
||||
return contents.get(index)
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
var v1 = ArrayWrapper<String>()
|
||||
val v2 = ArrayWrapper<String>()
|
||||
v1.add("foo")
|
||||
val v3 = v1
|
||||
v2.add("bar")
|
||||
v1 += v2
|
||||
return if (v1.contents.size() == 2 && v3.contents.size() == 1) "OK" else "fail"
|
||||
}
|
||||
@@ -1,31 +0,0 @@
|
||||
import java.util.*
|
||||
|
||||
class ArrayWrapper<T>() {
|
||||
val contents = ArrayList<T>()
|
||||
|
||||
fun add(item: T) {
|
||||
contents.add(item)
|
||||
}
|
||||
|
||||
fun minus(): ArrayWrapper<T> {
|
||||
val result = ArrayWrapper<T>()
|
||||
result.contents.addAll(contents)
|
||||
var i = contents.size();
|
||||
for (a in contents) {
|
||||
result.contents[--i] = a;
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
fun get(index: Int): T {
|
||||
return contents.get(index)
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val v1 = ArrayWrapper<String>()
|
||||
v1.add("foo")
|
||||
v1.add("bar")
|
||||
val v2 = -v1
|
||||
return if (v2[0] == "bar" && v2[1] == "foo") "OK" else "fail"
|
||||
}
|
||||
@@ -1,33 +0,0 @@
|
||||
open class Base() {
|
||||
val plain = 239
|
||||
public val read : Int
|
||||
get() = 239
|
||||
|
||||
public var readwrite : Int = 0
|
||||
get() = $readwrite + 1
|
||||
set(n : Int) {
|
||||
$readwrite = n
|
||||
}
|
||||
}
|
||||
|
||||
trait Abstract {}
|
||||
|
||||
class Derived1() : Base(), Abstract {}
|
||||
class Derived2() : Abstract, Base() {}
|
||||
|
||||
fun code(s : Base) : Int {
|
||||
if (s.plain != 239) return 1
|
||||
if (s.read != 239) return 2
|
||||
s.readwrite = 238
|
||||
if (s.readwrite != 239) return 3
|
||||
return 0
|
||||
}
|
||||
|
||||
fun test(s : Base) : Boolean = code(s) == 0
|
||||
|
||||
fun box() : String {
|
||||
if (!test(Base())) return "Fail #1"
|
||||
if (!test(Derived1())) return "Fail #2"
|
||||
if (!test(Derived2())) return "Fail #3"
|
||||
return "OK"
|
||||
}
|
||||
@@ -1,20 +0,0 @@
|
||||
// Changed when traits were introduced. May not make sense any more
|
||||
|
||||
trait Left {}
|
||||
open class Right() {
|
||||
open fun f() = 42
|
||||
}
|
||||
|
||||
class D() : Left, Right() {
|
||||
override fun f() = 239
|
||||
}
|
||||
|
||||
fun box() : String {
|
||||
val r : Right = Right()
|
||||
val d : D = D()
|
||||
|
||||
if (r.f() != 42) return "Fail #1"
|
||||
if (d.f() != 239) return "Fail #2"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -1,7 +0,0 @@
|
||||
fun box() : String {
|
||||
return invoker( {"OK"} )
|
||||
}
|
||||
|
||||
fun invoker(gen : () -> String) : String {
|
||||
return gen()
|
||||
}
|
||||
@@ -1,7 +0,0 @@
|
||||
fun box() : String {
|
||||
return if (int_invoker( { 7 } ) == 7) "OK" else "fail"
|
||||
}
|
||||
|
||||
fun int_invoker(gen : () -> Int) : Int {
|
||||
return gen()
|
||||
}
|
||||
@@ -1,4 +0,0 @@
|
||||
# Ignore everything in this directory
|
||||
*
|
||||
# Except this file
|
||||
!.gitignore
|
||||
@@ -1,21 +0,0 @@
|
||||
import java.util.ArrayList
|
||||
|
||||
trait Tr {
|
||||
fun extra() : String = "_"
|
||||
}
|
||||
|
||||
class N() : ArrayList<Any>(), Tr {
|
||||
override fun add(el: Any) : Boolean {
|
||||
super<ArrayList>.add(el)
|
||||
return super<ArrayList>.add(el.toString() + super<Tr>.extra() + el + extra())
|
||||
}
|
||||
|
||||
override fun extra() : String = super<Tr>.extra() + super<Tr>.extra()
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val n = N()
|
||||
n.add("239")
|
||||
if (n.get(0) == "239" && n.get(1) == "239_239__") return "OK";
|
||||
return "fail";
|
||||
}
|
||||
@@ -1,22 +0,0 @@
|
||||
open class M() {
|
||||
open var b: Int = 0
|
||||
}
|
||||
|
||||
class N() : M() {
|
||||
val a : Int
|
||||
get() {
|
||||
super.b = super.b + 1
|
||||
return super.b + 1
|
||||
}
|
||||
override var b: Int = a + 1
|
||||
|
||||
val superb : Int
|
||||
get() = super.b
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val n = N()
|
||||
println("a: " + n.a + " b: " + n.b + " superb: " + n.superb)
|
||||
if (n.b == 3 && n.a == 4 && n.superb == 3) return "OK";
|
||||
return "fail";
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
class C() {
|
||||
class object {
|
||||
fun create() = C()
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val c = C.create()
|
||||
return if (c is C) "OK" else "fail"
|
||||
}
|
||||
|
||||
@@ -1,9 +0,0 @@
|
||||
class C() {
|
||||
fun getInstance(): Runnable = C
|
||||
|
||||
class object: Runnable {
|
||||
override fun run(): Unit { }
|
||||
}
|
||||
}
|
||||
|
||||
fun foo() = C().getInstance()
|
||||
@@ -1,13 +0,0 @@
|
||||
abstract open class Default {
|
||||
abstract fun defaultValue(): Int
|
||||
}
|
||||
|
||||
class MyInt() {
|
||||
class object : Default {
|
||||
override fun defaultValue(): Int = 610
|
||||
}
|
||||
}
|
||||
|
||||
fun toDefault<T: Any>(t: T) where class object T: Default = T.defaultValue()
|
||||
|
||||
fun box(): String = if (toDefault<MyInt>(MyInt()) == 610) "OK" else "fail"
|
||||
@@ -1,42 +0,0 @@
|
||||
trait BK {
|
||||
fun x() : Int = 50
|
||||
}
|
||||
|
||||
trait K : BK {
|
||||
override fun x() : Int = super.x() * 2
|
||||
}
|
||||
|
||||
open class M() {
|
||||
open fun x() : Int = 10
|
||||
|
||||
open var y = 500
|
||||
}
|
||||
|
||||
open class N() : M(), K {
|
||||
|
||||
override fun x() : Int = 20
|
||||
|
||||
override var y = 200
|
||||
|
||||
open class C() : K {
|
||||
fun test1() = x()
|
||||
fun test2() = super<M>@N.x()
|
||||
fun test3() = super<K>@N.x()
|
||||
fun test4() = super<K>.x()
|
||||
fun test5() = y
|
||||
fun test6() : Int {
|
||||
super<M>@N.y += 200
|
||||
return super<M>@N.y
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
if (N().C().test1() != 100) return "test1 fail";
|
||||
if (N().C().test2() != 10) return "test2 fail";
|
||||
if (N().C().test3() != 100) return "test3 fail";
|
||||
if (N().C().test4() != 100) return "test4 fail";
|
||||
if (N().C().test5() != 200) return "test5 fail";
|
||||
if (N().C().test6() != 700) return "test6 fail";
|
||||
return "OK";
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
class Foo() { }
|
||||
class Bar() { }
|
||||
|
||||
fun isInstance<T>(obj: Any?) = obj is T
|
||||
|
||||
fun isInstance2<T>(obj: Any?) = isInstance<T>(obj)
|
||||
|
||||
fun box(): String {
|
||||
if (! isInstance2<Foo>(Foo())) return "fail 1"
|
||||
if (isInstance2<Bar>(Foo())) return "fail 2"
|
||||
return "OK"
|
||||
}
|
||||
@@ -1,41 +0,0 @@
|
||||
// Changed when traits were introduced. May not make sense any more
|
||||
|
||||
open class X(val x : Int) {}
|
||||
trait Y {
|
||||
abstract val y : Int
|
||||
}
|
||||
|
||||
class YImpl(override val y : Int) : Y {}
|
||||
|
||||
class Point(x : Int, yy : Int) : X(x) , Y {
|
||||
override val y : Int = yy
|
||||
}
|
||||
|
||||
trait Abstract {}
|
||||
|
||||
class P1(x : Int, yy : Y) : Abstract, X(x), Y by yy {}
|
||||
class P2(x : Int, yy : Y) : X(x), Abstract, Y by yy {}
|
||||
class P3(x : Int, yy : Y) : X(x), Y by yy, Abstract {}
|
||||
class P4(x : Int, yy : Y) : Y by yy, Abstract, X(x) {}
|
||||
|
||||
fun box() : String {
|
||||
if (X(239).x != 239) return "FAIL #1"
|
||||
if (YImpl(239).y != 239) return "FAIL #2"
|
||||
|
||||
val p = Point(240, -1)
|
||||
if (p.x + p.y != 239) return "FAIL #3"
|
||||
|
||||
val y = YImpl(-1)
|
||||
val p1 = P1(240, y)
|
||||
if (p1.x + p1.y != 239) return "FAIL #4"
|
||||
val p2 = P2(240, y)
|
||||
if (p2.x + p2.y != 239) return "FAIL #5"
|
||||
|
||||
val p3 = P3(240, y)
|
||||
if (p3.x + p3.y != 239) return "FAIL #6"
|
||||
|
||||
val p4 = P4(240, y)
|
||||
if (p4.x + p4.y != 239) return "FAIL #7"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -1,14 +0,0 @@
|
||||
class Outer() {
|
||||
open class InnerBase() {
|
||||
}
|
||||
|
||||
class InnerDerived(): InnerBase() {
|
||||
}
|
||||
|
||||
public val foo: InnerBase? = InnerDerived()
|
||||
}
|
||||
|
||||
fun box() : String {
|
||||
val o = Outer()
|
||||
return if (o.foo === null) "fail" else "OK"
|
||||
}
|
||||
@@ -1,20 +0,0 @@
|
||||
import java.util.*
|
||||
import java.io.*
|
||||
|
||||
class World() {
|
||||
public val items: ArrayList<Item> = ArrayList<Item>
|
||||
|
||||
class Item() {
|
||||
{
|
||||
items.add(this)
|
||||
}
|
||||
}
|
||||
|
||||
val foo = Item()
|
||||
}
|
||||
|
||||
fun box() : String {
|
||||
val w = World()
|
||||
if (w.items.size() != 1) return "fail"
|
||||
return "OK"
|
||||
}
|
||||
@@ -1,19 +0,0 @@
|
||||
class Outer(val foo: StringBuilder) {
|
||||
class Inner() {
|
||||
fun len() : Int {
|
||||
return foo.length()
|
||||
}
|
||||
}
|
||||
|
||||
fun test() : Inner {
|
||||
return Inner()
|
||||
}
|
||||
}
|
||||
|
||||
fun box() : String {
|
||||
val sb = StringBuilder("xyzzy")
|
||||
val o = Outer(sb)
|
||||
val i = o.test()
|
||||
val l = i.len()
|
||||
return if (l != 5) "fail" else "OK"
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
class Outer() {
|
||||
val s = "xyzzy"
|
||||
|
||||
open class InnerBase(public val name: String) {
|
||||
}
|
||||
|
||||
class InnerDerived(): InnerBase(s) {
|
||||
}
|
||||
|
||||
val x = InnerDerived()
|
||||
}
|
||||
|
||||
fun box() : String {
|
||||
val o = Outer()
|
||||
return if (o.x.name != "xyzzy") "fail" else "OK"
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
class Box<T>(t: T) {
|
||||
var value = t
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val box: Box<Int> = Box<Int>(1)
|
||||
return if (box.value == 1) "OK" else "fail"
|
||||
}
|
||||
@@ -1,29 +0,0 @@
|
||||
trait M {
|
||||
var backingB : Int
|
||||
var b : Int
|
||||
get() = backingB
|
||||
set(value: Int) {
|
||||
backingB = value
|
||||
}
|
||||
}
|
||||
|
||||
class N() : M {
|
||||
override var backingB : Int = 0
|
||||
|
||||
val a : Int
|
||||
get() {
|
||||
super.b = super.b + 1
|
||||
return super.b + 1
|
||||
}
|
||||
override var b: Int = a + 1
|
||||
|
||||
val superb : Int
|
||||
get() = super.b
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val n = N()
|
||||
println("a: " + n.a + " b: " + n.b + " superb: " + n.superb)
|
||||
if (n.b == 3 && n.a == 4 && n.superb == 3) return "OK";
|
||||
return "fail";
|
||||
}
|
||||
@@ -1,7 +0,0 @@
|
||||
class GameError(msg: String): Exception(msg) {
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val e = GameError("foo")
|
||||
return if (e.getMessage() == "foo") "OK" else "fail"
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
package foo
|
||||
|
||||
fun box() = if (true) throw Exception() else false
|
||||
@@ -1,4 +0,0 @@
|
||||
# Ignore everything in this directory
|
||||
*
|
||||
# Except this file
|
||||
!.gitignore
|
||||
@@ -1,19 +0,0 @@
|
||||
package foo
|
||||
|
||||
val a1 = Array<Int>(10)
|
||||
|
||||
fun box() : Boolean {
|
||||
var c = 0
|
||||
var d = 0
|
||||
a1[3] = 3
|
||||
a1[5] = 5
|
||||
|
||||
for (var a : Int? in a1) {
|
||||
if (a != null) {
|
||||
c += 1;
|
||||
} else {
|
||||
d += 1
|
||||
}
|
||||
}
|
||||
return (c == 2) && (d == 8)
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
package foo
|
||||
|
||||
val a1 = Array<Int>(0)
|
||||
|
||||
fun box() : Boolean {
|
||||
for (a in a1) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -1,4 +0,0 @@
|
||||
# Ignore everything in this directory
|
||||
*
|
||||
# Except this file
|
||||
!.gitignore
|
||||
@@ -1,67 +0,0 @@
|
||||
import java.util.*
|
||||
|
||||
class Lifetime() {
|
||||
val attached = ArrayList< Function0<Unit> >()
|
||||
|
||||
public fun attach(action : ()->Unit)
|
||||
{
|
||||
attached.add(action)
|
||||
}
|
||||
|
||||
fun close()
|
||||
{
|
||||
for(x in attached) x()
|
||||
attached.clear()
|
||||
}
|
||||
}
|
||||
|
||||
public class Viewable<T>()
|
||||
{
|
||||
val items = ArrayList<T>()
|
||||
|
||||
fun add(item:T)
|
||||
{
|
||||
items.add(item)
|
||||
}
|
||||
|
||||
fun remove(item:T)
|
||||
{
|
||||
items.remove(item)
|
||||
}
|
||||
|
||||
fun view(lifetime: Lifetime, viewer: (itemLifetime:Lifetime, item:T) -> Unit)
|
||||
{
|
||||
for(item in items)
|
||||
viewer(lifetime, item)
|
||||
}
|
||||
}
|
||||
|
||||
fun lifetime(body: (Lifetime)->Unit)
|
||||
{
|
||||
val l = Lifetime()
|
||||
body(l)
|
||||
l.close()
|
||||
}
|
||||
|
||||
fun<T> Dump(items:ArrayList<T>)
|
||||
{
|
||||
for(item in items)
|
||||
print(item.toString() + ", ")
|
||||
println()
|
||||
}
|
||||
|
||||
fun main(args:Array<String>)
|
||||
{
|
||||
val v = Viewable<Int>()
|
||||
val x = ArrayList<Int>()
|
||||
v.add(1)
|
||||
v.add(2)
|
||||
lifetime(
|
||||
{
|
||||
v.view(it, {(itemLifetime, item)->
|
||||
x.add(item)
|
||||
Dump(x)
|
||||
itemLifetime.attach { x.remove(item as Any); Dump(x) }
|
||||
})
|
||||
})
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
package foo
|
||||
|
||||
fun box() : Boolean {
|
||||
var sum = 0
|
||||
val adder = {(a: Int) -> sum += a }
|
||||
adder(3)
|
||||
adder(2)
|
||||
return sum == 5
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
package foo
|
||||
|
||||
fun box() : String {
|
||||
return apply( "OK", {(arg: String) -> arg } )
|
||||
}
|
||||
|
||||
fun apply(arg : String, f : (p:String) -> String) : String {
|
||||
return f(arg)
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
package foo
|
||||
|
||||
fun box() : String {
|
||||
return if (apply( 5, {(arg: Int) -> arg + 13 } ) == 18) "OK" else "fail"
|
||||
}
|
||||
|
||||
fun apply(arg : Int, f : (p:Int) -> Int) : Int {
|
||||
return f(arg)
|
||||
}
|
||||
@@ -1,15 +0,0 @@
|
||||
package foo
|
||||
|
||||
|
||||
fun f(a : Int = 2, b : Int = 3) = a + b
|
||||
|
||||
fun box() : Boolean
|
||||
{
|
||||
if (f(1,2) != 3) return false;
|
||||
if (f(1,3) != 4) return false;
|
||||
if (f(3) != 6) return false;
|
||||
if (f() != 5) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -1,12 +0,0 @@
|
||||
class Point(val x:Int, val y:Int) {
|
||||
fun mul() : (scalar:Int)->Point {
|
||||
return { (scalar:Int):Point -> Point(x * scalar, y * scalar) }
|
||||
}
|
||||
}
|
||||
|
||||
val m = Point(2, 3).mul() : (scalar:Int)->Point
|
||||
|
||||
fun box() : String {
|
||||
val answer = m(5)
|
||||
return if (answer.x == 10 && answer.y == 15) "OK" else "FAIL"
|
||||
}
|
||||
@@ -1,42 +0,0 @@
|
||||
package foo
|
||||
|
||||
import java.util.*;
|
||||
|
||||
val d = {(a : Int) -> a + 1}
|
||||
val p = {(a : Int) -> a * 3}
|
||||
|
||||
val list = ArrayList<Function1<Int, Int>>();
|
||||
|
||||
fun chain(start : Int) : Int {
|
||||
var res = start;
|
||||
for (func in list) {
|
||||
res = (func)(res);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
fun box() : Boolean {
|
||||
if (chain(0) != 0) {
|
||||
return false;
|
||||
}
|
||||
list.add(d);
|
||||
if (list.get(0)(0) != 1) {
|
||||
return false;
|
||||
}
|
||||
list.add(p);
|
||||
if (list.get(1)(10) != 30) {
|
||||
return false;
|
||||
}
|
||||
if (chain(0) != 3) {
|
||||
return false;
|
||||
}
|
||||
list.add({it * it});
|
||||
list.add({it - 100});
|
||||
if (chain(2) != -19) {
|
||||
return false;
|
||||
}
|
||||
if (({(a : Int) -> a * a}(3)) != 9) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -1,19 +0,0 @@
|
||||
package foo
|
||||
|
||||
|
||||
fun box() : Boolean{
|
||||
fun f() = 3
|
||||
|
||||
return (((f() + f()) == 6) && (b() == 24))
|
||||
}
|
||||
|
||||
|
||||
fun b() : Int {
|
||||
|
||||
fun a() : Int {
|
||||
fun c() = 4
|
||||
return c() * 3
|
||||
}
|
||||
val a = 2
|
||||
return a() * a
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
package foo
|
||||
|
||||
fun box() : Boolean {
|
||||
var sum = 0
|
||||
val addFive = {(a: Int) -> a + 5 }
|
||||
sum = addFive(sum)
|
||||
return sum == 5
|
||||
}
|
||||
@@ -1,14 +0,0 @@
|
||||
package foo
|
||||
|
||||
fun f(a: (Int) -> Int) = a(1)
|
||||
|
||||
fun box() : Boolean {
|
||||
|
||||
if (f() {
|
||||
it + 2
|
||||
} != 3) return false
|
||||
|
||||
if (f() {(a : Int) -> a * 300} != 300) return false;
|
||||
|
||||
return true
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
package foo
|
||||
|
||||
fun apply(f : (Int) -> Int, t : Int) : Int {
|
||||
return f(t)
|
||||
}
|
||||
|
||||
|
||||
fun box() : Boolean {
|
||||
return apply({(a: Int) -> a + 5 }, 3) == 8
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
package foo
|
||||
|
||||
|
||||
fun box() : Boolean
|
||||
{
|
||||
return f()
|
||||
}
|
||||
|
||||
fun f() : Boolean {
|
||||
return true
|
||||
}
|
||||
|
||||
|
||||
@@ -1,9 +0,0 @@
|
||||
package foo
|
||||
|
||||
fun sum(param1 : Int, param2 : Int) : Int {
|
||||
return param1 + param2;
|
||||
}
|
||||
|
||||
fun box() : Boolean {
|
||||
return (sum(1, 5) == 6)
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
package foo
|
||||
|
||||
fun test(f : (Int) -> Boolean, p : Int) = f(p)
|
||||
|
||||
fun box() : Boolean {
|
||||
if (!test({it + 1 == 2}, 1)) return false;
|
||||
|
||||
if (!test({it > 1}, 3)) return false;
|
||||
|
||||
return (test({((it < 1) == false)}, 1))
|
||||
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
package foo
|
||||
|
||||
var b = 0
|
||||
|
||||
fun loop(var times : Int) {
|
||||
while(times > 0) {
|
||||
val u = {(value : Int) ->
|
||||
b = b + 1
|
||||
}
|
||||
u(times--)
|
||||
}
|
||||
}
|
||||
|
||||
fun box() : Boolean {
|
||||
loop(5)
|
||||
return b == 5
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
package foo
|
||||
|
||||
fun test(x: Int, y: Int) = y - x
|
||||
|
||||
fun box() : Boolean {
|
||||
if (test(1,2) != 1) {
|
||||
return false;
|
||||
}
|
||||
if (test(x=1, y=2) != 1) {
|
||||
return false;
|
||||
}
|
||||
if (test(y=2, x=1) != 1) {
|
||||
return false;
|
||||
}
|
||||
return true
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
package foo
|
||||
|
||||
fun testSize(expectedSize : Int, vararg i : Int) : Boolean {
|
||||
return (i.size == expectedSize)
|
||||
}
|
||||
|
||||
fun testSum(expectedSum : Int, vararg i : Int) : Boolean {
|
||||
var sum = 0
|
||||
for (j in i) {
|
||||
sum += j
|
||||
}
|
||||
|
||||
return (expectedSum == sum)
|
||||
}
|
||||
|
||||
fun box() = testSize(0) && testSum(0) && testSize(3, 1, 1, 1) && testSum(3, 1, 1, 1) && testSize(6, 1, 1, 1, 2, 3, 4) &&
|
||||
testSum(30, 10, 20, 0)
|
||||
@@ -1,4 +0,0 @@
|
||||
# Ignore everything in this directory
|
||||
*
|
||||
# Except this file
|
||||
!.gitignore
|
||||
@@ -1,112 +0,0 @@
|
||||
package foo
|
||||
|
||||
import js.*
|
||||
|
||||
class RangeIterator(val start : Int, var count : Int, val reversed : Boolean) {
|
||||
|
||||
var i = start
|
||||
|
||||
fun next() : Int {
|
||||
--count
|
||||
if (reversed) {
|
||||
i--
|
||||
return i + 1
|
||||
} else {
|
||||
i++
|
||||
return i - 1
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
fun hasNext() = (count > 0);
|
||||
}
|
||||
|
||||
class NumberRange(val start : Int, val size : Int, val reversed : Boolean) {
|
||||
|
||||
val end : Int
|
||||
get() = if (reversed) start - size + 1 else start + size - 1
|
||||
|
||||
fun contains(number : Int) : Boolean {
|
||||
if (reversed) {
|
||||
return (number <= start) && (number > start - size);
|
||||
} else {
|
||||
return (number >= start) && (number < start + size);
|
||||
}
|
||||
}
|
||||
|
||||
fun iterator() = RangeIterator(start, size, reversed);
|
||||
}
|
||||
|
||||
|
||||
|
||||
fun box() = testRange() && testReversedRange();
|
||||
|
||||
fun testRange() : Boolean {
|
||||
|
||||
val oneToFive = NumberRange(1, 4, false);
|
||||
if (oneToFive.contains(5)) return false;
|
||||
if (oneToFive.contains(0)) return false;
|
||||
if (oneToFive.contains(-100)) return false;
|
||||
if (oneToFive.contains(10)) return false;
|
||||
if (!oneToFive.contains(1)) return false;
|
||||
if (!oneToFive.contains(2)) return false;
|
||||
if (!oneToFive.contains(3)) return false;
|
||||
if (!oneToFive.contains(4)) return false;
|
||||
if (!(oneToFive.start == 1)) return false;
|
||||
if (!(oneToFive.size == 4)) return false;
|
||||
if (!(oneToFive.end == 4)) return false;
|
||||
|
||||
var sum = 0;
|
||||
for (i in oneToFive) {
|
||||
sum += i;
|
||||
}
|
||||
for (i in oneToFive) {
|
||||
print(i)
|
||||
}
|
||||
|
||||
if (sum != 10) return false;
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
fun testReversedRange() : Boolean {
|
||||
|
||||
println("Testing reversed range.");
|
||||
|
||||
val tenToFive = NumberRange(10, 5, true);
|
||||
|
||||
if (tenToFive.contains(5)) return false;
|
||||
if (tenToFive.contains(11)) return false;
|
||||
if (tenToFive.contains(-100)) return false;
|
||||
if (tenToFive.contains(1000)) return false;
|
||||
if (!tenToFive.contains(6)) return false;
|
||||
if (!tenToFive.contains(7)) return false;
|
||||
if (!tenToFive.contains(8)) return false;
|
||||
if (!tenToFive.contains(9)) return false;
|
||||
if (!tenToFive.contains(10)) return false;
|
||||
|
||||
if (!(tenToFive.start == 10)) return false;
|
||||
if (!(tenToFive.size == 5)) return false;
|
||||
if (!(tenToFive.end == 6)) return false;
|
||||
|
||||
for (i in tenToFive) {
|
||||
println(i)
|
||||
}
|
||||
|
||||
|
||||
var sum = 0;
|
||||
for (i in tenToFive) {
|
||||
sum += i;
|
||||
}
|
||||
|
||||
if (sum != 40) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
fun main(args : Array<String>) {
|
||||
println(box())
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user