diff --git a/.idea/artifacts/KotlinPlugin.xml b/.idea/artifacts/KotlinPlugin.xml
index bf13e346538..aa2dc6c2da4 100644
--- a/.idea/artifacts/KotlinPlugin.xml
+++ b/.idea/artifacts/KotlinPlugin.xml
@@ -14,16 +14,10 @@
-
-
+
-
-
-
-
-
-
+
diff --git a/.idea/inspectionProfiles/idea_default.xml b/.idea/inspectionProfiles/idea_default.xml
index 1dfe9e84ad8..e5f3ca2c256 100644
--- a/.idea/inspectionProfiles/idea_default.xml
+++ b/.idea/inspectionProfiles/idea_default.xml
@@ -228,10 +228,6 @@
-
-
-
-
diff --git a/.idea/libraries/js_libs.xml b/.idea/libraries/js_libs.xml
index 5dafbf5773d..e42ca339692 100644
--- a/.idea/libraries/js_libs.xml
+++ b/.idea/libraries/js_libs.xml
@@ -1,7 +1,6 @@
-
+
-
diff --git a/.idea/modules.xml b/.idea/modules.xml
index d4b860b6f00..745a36b3cec 100644
--- a/.idea/modules.xml
+++ b/.idea/modules.xml
@@ -17,12 +17,10 @@
-
-
+
-
diff --git a/compiler/frontend/src/org/jetbrains/jet/plugin/JetMainDetector.java b/compiler/frontend/src/org/jetbrains/jet/plugin/JetMainDetector.java
index 1545365c86e..0e72ffe5bd1 100644
--- a/compiler/frontend/src/org/jetbrains/jet/plugin/JetMainDetector.java
+++ b/compiler/frontend/src/org/jetbrains/jet/plugin/JetMainDetector.java
@@ -51,15 +51,6 @@ public class JetMainDetector {
return false;
}
- @Nullable
- public static String getMainClassFQName(@NotNull List files) {
- JetFile file = getFileWithMain(files);
- if (file == null) {
- return null;
- }
- return JetPsiUtil.getFQName(file);
- }
-
@Nullable
public static JetFile getFileWithMain(@NotNull List files) {
for (JetFile file : files) {
diff --git a/js/action.patch b/js/action.patch
deleted file mode 100644
index 287b4364c9c..00000000000
--- a/js/action.patch
+++ /dev/null
@@ -1,315 +0,0 @@
-Index: idea/src/META-INF/plugin.xml
-IDEA additional info:
-Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
-<+>UTF-8
-Subsystem: com.intellij.openapi.diff.impl.patch.BaseRevisionTextPatchEP
-<+>\n Kotlin\n Kotlin language support\n @snapshot@\n JetBrains\n\n JUnit\n\n \n \n org.jetbrains.jet.plugin.JetStandardLibraryInitializer\n \n \n org.jetbrains.jet.plugin.compiler.JetCompilerManager\n \n \n org.jetbrains.jet.plugin.caches.JetCacheManager\n \n \n\n \n \n \n \n\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n\n \n \n\n \n\n \n \n \n \n\n \n\n \n \n \n \n \n \n \n \n \n \n\n \n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n \n\n \n\n \n\n \n\n \n \n \n \n \n \n \n \n \n \n \n\n \n \n \n \n\n \n \n \n \n \n \n \n \n \n \n\n \n \n\n \n \n \n \n \n\n \n\n \n\n \n \n\n
-===================================================================
---- idea/src/META-INF/plugin.xml (date 1330080250000)
-+++ idea/src/META-INF/plugin.xml (revision )
-@@ -45,8 +45,8 @@
-
-
-
--
-+ text="Translate Kotlin to JavaScript.">
-+
-
-
-
-Index: compiler/frontend/src/jet/Library.jet
-IDEA additional info:
-Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
-<+>UTF-8
-Subsystem: com.intellij.openapi.diff.impl.patch.BaseRevisionTextPatchEP
-<+>package jet\n\nannotation class volatile\nannotation class atomic\n\nfun synchronized(lock: Any, block : () -> R) : R\n\nfun Any?.identityEquals(other : Any?) : Boolean // = this === other\n\n// Can't write a body due to a bootstrapping problem (see JET-74)\nfun Any?.equals(other : Any?) : Boolean// = this === other\n\n// Returns \"null\" for null\nfun Any?.toString() : String// = this === other\n\nfun T?.sure() : T\n\nfun String?.plus(other: Any?) : String\n\ntrait Comparable {\n fun compareTo(other : T) : Int\n}\n\ntrait Hashable {\n fun hashCode() : Int\n fun equals(other : Any?) : Boolean\n}\n\nclass Boolean : Comparable {\n fun not() : Boolean\n\n fun and(other : Boolean) : Boolean\n\n fun or(other : Boolean) : Boolean\n\n fun xor(other : Boolean) : Boolean\n\n fun equals(other : Any?) : Boolean\n}\n\ntrait CharSequence {\n fun get(index : Int) : Char\n\n val length : Int\n\n fun toString() : String\n}\n\nclass String() : Comparable, CharSequence {\n fun plus(other : Any?) : String\n\n fun equals(other : Any?) : Boolean\n}\n\nclass Throwable(message : String? = null, cause: Throwable? = null) {\n fun getMessage() : String?\n fun getCause() : Throwable?\n fun printStackTrace() : Unit\n}
-===================================================================
---- compiler/frontend/src/jet/Library.jet (date 1330080250000)
-+++ compiler/frontend/src/jet/Library.jet (revision )
-@@ -52,7 +52,7 @@
- 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
-\ No newline at end of file
-Index: compiler/frontend/src/org/jetbrains/jet/plugin/JetMainDetector.java
-IDEA additional info:
-Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
-<+>UTF-8
-Subsystem: com.intellij.openapi.diff.impl.patch.BaseRevisionTextPatchEP
-<+>/*\n * Copyright 2010-2012 JetBrains s.r.o.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\npackage org.jetbrains.jet.plugin;\n\nimport org.jetbrains.jet.lang.psi.JetDeclaration;\nimport org.jetbrains.jet.lang.psi.JetNamedFunction;\nimport org.jetbrains.jet.lang.psi.JetParameter;\nimport org.jetbrains.jet.lang.psi.JetTypeReference;\n\nimport java.util.List;\n\n/**\n * @author yole\n */\npublic class JetMainDetector {\n private JetMainDetector() {\n }\n\n public static boolean hasMain(List declarations) {\n for (JetDeclaration declaration : declarations) {\n if (declaration instanceof JetNamedFunction) {\n if (isMain((JetNamedFunction) declaration)) return true;\n }\n }\n return false;\n }\n\n public static boolean isMain(JetNamedFunction function) {\n if (\"main\".equals(function.getName())) {\n List parameters = function.getValueParameters();\n if (parameters.size() == 1) {\n JetTypeReference reference = parameters.get(0).getTypeReference();\n if (reference != null && reference.getText().equals(\"Array\")) { // TODO correct check\n return true;\n }\n }\n }\n return false;\n }\n}\n
-===================================================================
---- compiler/frontend/src/org/jetbrains/jet/plugin/JetMainDetector.java (date 1330080250000)
-+++ compiler/frontend/src/org/jetbrains/jet/plugin/JetMainDetector.java (revision )
-@@ -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;
-
-@@ -50,5 +49,24 @@
- }
- }
- return false;
-+ }
-+
-+ @Nullable
-+ public static String getMainClassFQName(@NotNull List files) {
-+ JetFile file = getFileWithMain(files);
-+ if (file == null) {
-+ return null;
-+ }
-+ return JetPsiUtil.getFQName(file);
-+ }
-+
-+ @Nullable
-+ public static JetFile getFileWithMain(@NotNull List files) {
-+ for (JetFile file : files) {
-+ if (hasMain(file.getDeclarations())) {
-+ return file;
-+ }
-+ }
-+ return null;
- }
- }
-Index: idea/src/org/jetbrains/jet/plugin/actions/TranslateToJsAction.java
-IDEA additional info:
-Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
-<+>UTF-8
-Subsystem: com.intellij.openapi.diff.impl.patch.BaseRevisionTextPatchEP
-<+>package org.jetbrains.jet.plugin.actions;\n\nimport com.intellij.notification.Notification;\nimport com.intellij.notification.NotificationType;\nimport com.intellij.notification.Notifications;\nimport com.intellij.openapi.actionSystem.AnAction;\nimport com.intellij.openapi.actionSystem.AnActionEvent;\nimport com.intellij.openapi.actionSystem.LangDataKeys;\nimport com.intellij.openapi.actionSystem.PlatformDataKeys;\nimport com.intellij.openapi.application.ApplicationManager;\nimport com.intellij.openapi.editor.Editor;\nimport com.intellij.openapi.project.Project;\nimport com.intellij.openapi.vfs.VirtualFile;\nimport com.intellij.psi.PsiFile;\nimport org.jetbrains.jet.lang.psi.JetFile;\nimport org.jetbrains.k2js.facade.K2JSTranslator;\n\n/**\n * @author Pavel Talanov\n */\npublic final class TranslateToJsAction extends AnAction {\n\n private static void notifyFailure(Throwable exception) {\n Notifications.Bus.notify(new Notification(\"JsTranslator\", \"Translation failed.\",\n \"Exception: \" + exception.getMessage(),\n NotificationType.ERROR));\n }\n\n private static void notifySuccess(String outputPath) {\n Notifications.Bus.notify(new Notification(\"JsTranslator\", \"Translation successful.\",\n \"Generated file: \" + outputPath,\n NotificationType.INFORMATION));\n }\n\n public void actionPerformed(AnActionEvent event) {\n\n final PsiFile psiFile = event.getData(LangDataKeys.PSI_FILE);\n if (!(psiFile instanceof JetFile)) {\n return;\n }\n\n Runnable task = new Runnable() {\n @Override\n public void run() {\n try {\n Project project = psiFile.getProject();\n String outputPath = getOutputPath(psiFile);\n K2JSTranslator.translateWithCallToMainAndSaveToFile((JetFile) psiFile,\n outputPath,\n project);\n notifySuccess(outputPath);\n } catch (Throwable e) {\n e.printStackTrace();\n notifyFailure(e);\n }\n }\n };\n ApplicationManager.getApplication().runWriteAction(task);\n }\n\n private static String getOutputPath(PsiFile psiFile) {\n VirtualFile virtualFile = psiFile.getVirtualFile();\n assert virtualFile != null : \"Internal error: Psi file should correspond to actual virtual file\";\n String originalFilePath = virtualFile.getPath();\n\n //TODO: make platform independent\n String pathToDir = originalFilePath.substring(0, originalFilePath.lastIndexOf(\"/\") + 1);\n String generatedFileName = ((JetFile) psiFile).getNamespaceHeader().getName() + \".js\";\n return pathToDir + generatedFileName;\n }\n\n\n @Override\n public void update(AnActionEvent e) {\n Editor editor = e.getData(PlatformDataKeys.EDITOR);\n PsiFile psiFile = e.getData(LangDataKeys.PSI_FILE);\n e.getPresentation().setEnabled(editor != null && psiFile instanceof JetFile);\n }\n}\n
-===================================================================
---- idea/src/org/jetbrains/jet/plugin/actions/TranslateToJsAction.java (date 1330080250000)
-+++ idea/src/org/jetbrains/jet/plugin/actions/TranslateToJsAction.java (revision )
-@@ -1,54 +1,74 @@
-+/*
-+ * 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.LangDataKeys;
- 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(Throwable exception) {
-+ private static void notifyFailure(@NotNull Throwable exception) {
- Notifications.Bus.notify(new Notification("JsTranslator", "Translation failed.",
- "Exception: " + exception.getMessage(),
- NotificationType.ERROR));
- }
-
-- private static void notifySuccess(String outputPath) {
-+ private static void notifySuccess(@NotNull String outputPath) {
- Notifications.Bus.notify(new Notification("JsTranslator", "Translation successful.",
- "Generated file: " + outputPath,
- NotificationType.INFORMATION));
- }
-
-- public void actionPerformed(AnActionEvent event) {
--
-- final PsiFile psiFile = event.getData(LangDataKeys.PSI_FILE);
-- if (!(psiFile instanceof JetFile)) {
-- return;
-- }
--
-+ public void actionPerformed(final AnActionEvent event) {
- Runnable task = new Runnable() {
- @Override
- public void run() {
- try {
-- Project project = psiFile.getProject();
-- String outputPath = getOutputPath(psiFile);
-- K2JSTranslator.translateWithCallToMainAndSaveToFile((JetFile) psiFile,
-- outputPath,
-- project);
-- notifySuccess(outputPath);
-+ performAction(event);
- } catch (Throwable e) {
- e.printStackTrace();
- notifyFailure(e);
-@@ -58,7 +78,50 @@
- ApplicationManager.getApplication().runWriteAction(task);
- }
-
-- private static String getOutputPath(PsiFile psiFile) {
-+ private static void performAction(@NotNull AnActionEvent event) throws Exception {
-+ final Project project = PlatformDataKeys.PROJECT.getData(event.getDataContext());
-+ assert project != null;
-+ Set allVirtualFiles = getAllProjectVirtualFiles(project);
-+ List kotlinFiles = getJetFiles(allVirtualFiles, project);
-+ String outputPath = getOutputPath(JetMainDetector.getFileWithMain(kotlinFiles));
-+ K2JSTranslator.translateWithCallToMainAndSaveToFile(kotlinFiles,
-+ outputPath,
-+ project);
-+ notifySuccess(outputPath);
-+ }
-+
-+ @NotNull
-+ private static Set getAllProjectVirtualFiles(@NotNull Project project) {
-+ Module[] modules = ModuleManager.getInstance(project).getModules();
-+ Set 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 getJetFiles(@NotNull Collection virtualFiles,
-+ @NotNull Project project) {
-+ List 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();
-@@ -69,11 +132,9 @@
- return pathToDir + generatedFileName;
- }
-
--
- @Override
- public void update(AnActionEvent e) {
- Editor editor = e.getData(PlatformDataKeys.EDITOR);
-- PsiFile psiFile = e.getData(LangDataKeys.PSI_FILE);
-- e.getPresentation().setEnabled(editor != null && psiFile instanceof JetFile);
-+ e.getPresentation().setEnabled(editor != null);
- }
- }
-Index: idea/src/org/jetbrains/jet/plugin/actions/JavaToKotlinActionUtil.java
-IDEA additional info:
-Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
-<+>UTF-8
-Subsystem: com.intellij.openapi.diff.impl.patch.BaseRevisionTextPatchEP
-<+>/*\n * Copyright 2010-2012 JetBrains s.r.o.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\npackage org.jetbrains.jet.plugin.actions;\n\nimport com.intellij.ide.highlighter.JavaFileType;\nimport com.intellij.openapi.application.ApplicationManager;\nimport com.intellij.openapi.project.Project;\nimport com.intellij.openapi.ui.ex.MessagesEx;\nimport com.intellij.openapi.vfs.CharsetToolkit;\nimport com.intellij.openapi.vfs.VirtualFile;\nimport com.intellij.psi.PsiFile;\nimport com.intellij.psi.PsiJavaFile;\nimport com.intellij.psi.PsiManager;\nimport com.intellij.psi.codeStyle.CodeStyleManager;\nimport org.jetbrains.annotations.NotNull;\nimport org.jetbrains.annotations.Nullable;\nimport org.jetbrains.jet.j2k.Converter;\nimport org.jetbrains.jet.j2k.visitors.ClassVisitor;\n\nimport java.io.IOException;\nimport java.util.*;\n\n/**\n * @author ignatov\n */\npublic class JavaToKotlinActionUtil {\n\n static void setClassIdentifiers(@NotNull Converter converter, @NotNull PsiFile psiFile) {\n ClassVisitor c = new ClassVisitor();\n psiFile.accept(c);\n converter.setClassIdentifiers(c.getClassIdentifiers());\n }\n\n @NotNull\n private static List getChildrenRecursive(@Nullable VirtualFile baseDir) {\n List result = new LinkedList();\n VirtualFile[] children = baseDir != null ? baseDir.getChildren() : VirtualFile.EMPTY_ARRAY;\n result.addAll(Arrays.asList(children));\n for (VirtualFile f : children)\n result.addAll(getChildrenRecursive(f));\n return result;\n }\n\n @NotNull\n static List getAllJavaFiles(@NotNull VirtualFile[] vFiles, Project project) {\n final PsiManager manager = PsiManager.getInstance(project);\n Set filesSet = new HashSet();\n for (VirtualFile f : vFiles) {\n filesSet.add(f);\n filesSet.addAll(getChildrenRecursive(f));\n }\n final List res = new ArrayList();\n for (final VirtualFile file : filesSet) {\n final PsiFile psiFile = manager.findFile(file);\n if (psiFile != null && psiFile.getFileType() instanceof JavaFileType) {\n res.add(psiFile);\n }\n }\n return res;\n }\n\n static void reformatFiles(List allJetFiles, final Project project) {\n for (final VirtualFile vf : allJetFiles)\n ApplicationManager.getApplication().runWriteAction(new Runnable() {\n @Override\n public void run() {\n if (vf != null) {\n PsiFile psiFile = PsiManager.getInstance(project).findFile(vf);\n if (psiFile != null) {\n CodeStyleManager.getInstance(project).reformat(psiFile);\n }\n }\n }\n });\n }\n\n @NotNull\n static List convertFiles(final Converter converter, List allJavaFilesNear) {\n final List result = new LinkedList();\n for (final PsiFile f : allJavaFilesNear) {\n ApplicationManager.getApplication().runWriteAction(new Runnable() {\n @Override\n public void run() {\n VirtualFile vf = convertOneFile(converter, f);\n if (vf != null) {\n result.add(vf);\n }\n }\n });\n }\n return result;\n }\n\n static void deleteFiles(List allJavaFilesNear) {\n for (final PsiFile f : allJavaFilesNear) {\n ApplicationManager.getApplication().runWriteAction(new Runnable() {\n @Override\n public void run() {\n try {\n PsiManager manager = f.getManager();\n VirtualFile vFile = f.getVirtualFile();\n if (vFile != null) {\n vFile.delete(manager);\n }\n } catch (IOException ignored) {\n }\n }\n });\n }\n }\n\n @Nullable\n private static VirtualFile convertOneFile(Converter converter, PsiFile psiFile) {\n try {\n VirtualFile virtualFile = psiFile.getVirtualFile();\n if (psiFile instanceof PsiJavaFile && virtualFile != null) {\n String result = \"\";\n try {\n result = converter.fileToFile((PsiJavaFile) psiFile).toKotlin();\n } catch (Exception e) {\n //noinspection CallToPrintStackTrace\n e.printStackTrace();\n }\n final PsiManager manager = psiFile.getManager();\n assert manager != null;\n VirtualFile copy = virtualFile.copy(manager, virtualFile.getParent(), virtualFile.getNameWithoutExtension() + \".kt\");\n copy.setBinaryContent(CharsetToolkit.getUtf8Bytes(result));\n return copy;\n }\n } catch (Exception ex) {\n MessagesEx.error(psiFile.getProject(), ex.getMessage()).showLater();\n }\n return null;\n }\n\n static void renameFiles(@NotNull List psiFiles) {\n for (final PsiFile f : psiFiles) {\n ApplicationManager.getApplication().runWriteAction(new Runnable() {\n @Override\n public void run() {\n try {\n PsiManager manager = f.getManager();\n VirtualFile vFile = f.getVirtualFile();\n if (vFile != null) {\n vFile.copy(manager, vFile.getParent(), vFile.getNameWithoutExtension() + \".java.old\");\n vFile.delete(manager);\n }\n } catch (IOException ignored) {\n }\n }\n });\n }\n }\n}\n
-===================================================================
---- idea/src/org/jetbrains/jet/plugin/actions/JavaToKotlinActionUtil.java (date 1330080250000)
-+++ idea/src/org/jetbrains/jet/plugin/actions/JavaToKotlinActionUtil.java (revision )
-@@ -56,13 +56,9 @@
- }
-
- @NotNull
-- static List getAllJavaFiles(@NotNull VirtualFile[] vFiles, Project project) {
-+ /*package*/ static List getAllJavaFiles(@NotNull VirtualFile[] vFiles, Project project) {
-+ Set filesSet = allVirtualFiles(vFiles);
- final PsiManager manager = PsiManager.getInstance(project);
-- Set filesSet = new HashSet();
-- for (VirtualFile f : vFiles) {
-- filesSet.add(f);
-- filesSet.addAll(getChildrenRecursive(f));
-- }
- final List res = new ArrayList();
- for (final VirtualFile file : filesSet) {
- final PsiFile psiFile = manager.findFile(file);
-@@ -71,6 +67,16 @@
- }
- }
- return res;
-+ }
-+
-+ @NotNull
-+ public static Set allVirtualFiles(@NotNull VirtualFile[] vFiles) {
-+ Set filesSet = new HashSet();
-+ for (VirtualFile f : vFiles) {
-+ filesSet.add(f);
-+ filesSet.addAll(getChildrenRecursive(f));
-+ }
-+ return filesSet;
- }
-
- static void reformatFiles(List allJetFiles, final Project project) {
-Index: compiler/frontend/src/org/jetbrains/jet/lang/types/JetStandardLibrary.java
-IDEA additional info:
-Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
-<+>UTF-8
-Subsystem: com.intellij.openapi.diff.impl.patch.BaseRevisionTextPatchEP
-<+>/*\n * Copyright 2010-2012 JetBrains s.r.o.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\npackage org.jetbrains.jet.lang.types;\n\nimport com.intellij.openapi.progress.ProcessCanceledException;\nimport com.intellij.openapi.project.Project;\nimport com.intellij.openapi.util.io.FileUtil;\nimport com.intellij.psi.PsiFileFactory;\nimport org.jetbrains.annotations.NotNull;\nimport org.jetbrains.annotations.Nullable;\nimport org.jetbrains.jet.lang.JetSemanticServices;\nimport org.jetbrains.jet.lang.descriptors.ClassDescriptor;\nimport org.jetbrains.jet.lang.descriptors.FunctionDescriptor;\nimport org.jetbrains.jet.lang.descriptors.PropertyDescriptor;\nimport org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;\nimport org.jetbrains.jet.lang.psi.JetFile;\nimport org.jetbrains.jet.lang.resolve.AnalyzingUtils;\nimport org.jetbrains.jet.lang.resolve.BindingTraceContext;\nimport org.jetbrains.jet.lang.resolve.TopDownAnalyzer;\nimport org.jetbrains.jet.lang.resolve.scopes.JetScope;\nimport org.jetbrains.jet.lang.resolve.scopes.RedeclarationHandler;\nimport org.jetbrains.jet.lang.resolve.scopes.WritableScope;\nimport org.jetbrains.jet.lang.resolve.scopes.WritableScopeImpl;\nimport org.jetbrains.jet.plugin.JetFileType;\n\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.util.*;\n\n/**\n * @author abreslav\n */\npublic class JetStandardLibrary {\n\n private static JetStandardLibrary instance = null;\n\n // This method must be called at least once per application run, on any project\n // before any type checking is run\n public static synchronized void initialize(@NotNull Project project) {\n if (instance == null) {\n instance = new JetStandardLibrary(project);\n }\n }\n\n @NotNull // This asserts that initialize() is called before any resolution happens\n public static JetStandardLibrary getInstance() {\n return instance;\n }\n\n private JetScope libraryScope;\n\n private ClassDescriptor numberClass;\n\n private ClassDescriptor charSequenceClass;\n private ClassDescriptor stringClass;\n private ClassDescriptor arrayClass;\n private ClassDescriptor iterableClass;\n private ClassDescriptor comparableClass;\n private ClassDescriptor volatileClass;\n private ClassDescriptor throwableClass;\n\n private JetType stringType;\n private JetType volatileType;\n private JetType nullableStringType;\n private JetType charSequenceType;\n private JetType nullableCharSequenceType;\n private JetType nullableTuple0Type;\n private JetType throwableType;\n private JetType nullableThrowableType;\n\n private JetType tuple0Type;\n\n private Set typeInfoFunction;\n\n private EnumMap primitiveTypeToClass;\n private EnumMap primitiveTypeToArrayClass;\n private EnumMap primitiveTypeToJetType;\n private EnumMap primitiveTypeToNullableJetType;\n private EnumMap primitiveTypeToArrayJetType;\n private EnumMap primitiveTypeToNullableArrayJetType;\n private Map primitiveJetTypeToJetArrayType;\n private Map jetArrayTypeToPrimitiveJetType;\n\n private JetStandardLibrary(@NotNull Project project) {\n // TODO : review\n List libraryFiles = Arrays.asList(\n \"Library.jet\",\n \"Numbers.jet\",\n \"Ranges.jet\",\n \"Iterables.jet\",\n \"Iterators.jet\",\n \"Arrays.jet\"\n );\n try {\n List files = new LinkedList();\n for(String fileName : libraryFiles) {\n InputStream stream = JetStandardClasses.class.getClassLoader().getResourceAsStream(\"jet/\" + fileName);\n\n //noinspection IOResourceOpenedButNotSafelyClosed\n JetFile file = (JetFile) PsiFileFactory.getInstance(project).createFileFromText(fileName,\n JetFileType.INSTANCE, FileUtil.loadTextAndClose(new InputStreamReader(stream)));\n files.add(file);\n }\n\n JetSemanticServices bootstrappingSemanticServices = JetSemanticServices.createSemanticServices(this);\n BindingTraceContext bindingTraceContext = new BindingTraceContext();\n WritableScopeImpl writableScope = new WritableScopeImpl(JetStandardClasses.STANDARD_CLASSES, JetStandardClasses.STANDARD_CLASSES_NAMESPACE, RedeclarationHandler.THROW_EXCEPTION).setDebugName(\"Root bootstrap scope\");\n writableScope.changeLockLevel(WritableScope.LockLevel.BOTH);\n TopDownAnalyzer.processStandardLibraryNamespace(bootstrappingSemanticServices, bindingTraceContext, writableScope, JetStandardClasses.STANDARD_CLASSES_NAMESPACE, files);\n\n AnalyzingUtils.throwExceptionOnErrors(bindingTraceContext.getBindingContext());\n initStdClasses();\n } catch (IOException e) {\n throw new IllegalStateException(e);\n } catch (ProcessCanceledException e) {\n throw e;\n }\n }\n\n public JetScope getLibraryScope() {\n initStdClasses();\n return libraryScope;\n }\n\n private void initStdClasses() {\n if(libraryScope == null) {\n this.libraryScope = JetStandardClasses.STANDARD_CLASSES_NAMESPACE.getMemberScope();\n this.numberClass = (ClassDescriptor) libraryScope.getClassifier(\"Number\");\n this.stringClass = (ClassDescriptor) libraryScope.getClassifier(\"String\");\n this.charSequenceClass = (ClassDescriptor) libraryScope.getClassifier(\"CharSequence\");\n this.arrayClass = (ClassDescriptor) libraryScope.getClassifier(\"Array\");\n this.volatileClass = (ClassDescriptor) libraryScope.getClassifier(\"volatile\");\n this.throwableClass = (ClassDescriptor) libraryScope.getClassifier(\"Throwable\"); \n\n this.iterableClass = (ClassDescriptor) libraryScope.getClassifier(\"Iterable\");\n this.comparableClass = (ClassDescriptor) libraryScope.getClassifier(\"Comparable\");\n this.typeInfoFunction = libraryScope.getFunctions(\"typeinfo\");\n\n this.stringType = new JetTypeImpl(getString());\n this.charSequenceType = new JetTypeImpl(getCharSequence());\n this.nullableCharSequenceType = TypeUtils.makeNullable(charSequenceType);\n this.nullableStringType = TypeUtils.makeNullable(stringType);\n this.volatileType = new JetTypeImpl(getVolatile());\n this.throwableType = new JetTypeImpl(getThrowable());\n this.nullableThrowableType = TypeUtils.makeNullable(throwableType);\n\n this.tuple0Type = new JetTypeImpl(JetStandardClasses.getTuple(0));\n this.nullableTuple0Type = TypeUtils.makeNullable(tuple0Type);\n \n primitiveTypeToClass = new EnumMap(PrimitiveType.class);\n primitiveTypeToJetType = new EnumMap(PrimitiveType.class);\n primitiveTypeToNullableJetType = new EnumMap(PrimitiveType.class);\n primitiveTypeToArrayClass = new EnumMap(PrimitiveType.class);\n primitiveTypeToArrayJetType = new EnumMap(PrimitiveType.class);\n primitiveTypeToNullableArrayJetType = new EnumMap(PrimitiveType.class);\n primitiveJetTypeToJetArrayType = new HashMap();\n jetArrayTypeToPrimitiveJetType = new HashMap();\n\n for (PrimitiveType primitive : PrimitiveType.values()) {\n makePrimitive(primitive);\n }\n }\n }\n\n private void makePrimitive(PrimitiveType primitiveType) {\n ClassDescriptor clazz = (ClassDescriptor) libraryScope.getClassifier(primitiveType.getTypeName());\n ClassDescriptor arrayClazz = (ClassDescriptor) libraryScope.getClassifier(primitiveType.getTypeName() + \"Array\");\n JetTypeImpl type = new JetTypeImpl(clazz);\n JetTypeImpl arrayType = new JetTypeImpl(arrayClazz);\n\n primitiveTypeToClass.put(primitiveType, clazz);\n primitiveTypeToJetType.put(primitiveType, type);\n primitiveTypeToNullableJetType.put(primitiveType, TypeUtils.makeNullable(type));\n primitiveTypeToArrayClass.put(primitiveType, arrayClazz);\n primitiveTypeToArrayJetType.put(primitiveType, arrayType);\n primitiveTypeToNullableArrayJetType.put(primitiveType, TypeUtils.makeNullable(arrayType));\n primitiveJetTypeToJetArrayType.put(type, arrayType);\n jetArrayTypeToPrimitiveJetType.put(arrayType, type);\n }\n\n @NotNull\n public ClassDescriptor getNumber() {\n initStdClasses();\n return numberClass;\n }\n\n @NotNull\n public ClassDescriptor getPrimitiveClassDescriptor(PrimitiveType primitiveType) {\n initStdClasses();\n return primitiveTypeToClass.get(primitiveType);\n }\n\n @NotNull\n public ClassDescriptor getByte() {\n return getPrimitiveClassDescriptor(PrimitiveType.BYTE);\n }\n\n @NotNull\n public ClassDescriptor getChar() {\n return getPrimitiveClassDescriptor(PrimitiveType.CHAR);\n }\n\n @NotNull\n public ClassDescriptor getShort() {\n return getPrimitiveClassDescriptor(PrimitiveType.SHORT);\n }\n\n @NotNull\n public ClassDescriptor getInt() {\n return getPrimitiveClassDescriptor(PrimitiveType.INT);\n }\n\n @NotNull\n public ClassDescriptor getLong() {\n return getPrimitiveClassDescriptor(PrimitiveType.LONG);\n }\n\n @NotNull\n public ClassDescriptor getFloat() {\n return getPrimitiveClassDescriptor(PrimitiveType.FLOAT);\n }\n\n @NotNull\n public ClassDescriptor getDouble() {\n return getPrimitiveClassDescriptor(PrimitiveType.DOUBLE);\n }\n\n @NotNull\n public ClassDescriptor getBoolean() {\n return getPrimitiveClassDescriptor(PrimitiveType.BOOLEAN);\n }\n\n @NotNull\n public ClassDescriptor getString() {\n initStdClasses();\n return stringClass;\n }\n\n @NotNull\n public ClassDescriptor getCharSequence() {\n initStdClasses();\n return charSequenceClass;\n }\n\n @NotNull\n public ClassDescriptor getArray() {\n initStdClasses();\n return arrayClass;\n }\n\n @NotNull\n public ClassDescriptor getIterable() {\n initStdClasses();\n return iterableClass;\n }\n\n @NotNull\n public ClassDescriptor getComparable() {\n initStdClasses();\n return comparableClass;\n }\n\n @NotNull\n public ClassDescriptor getThrowable() {\n initStdClasses();\n return throwableClass;\n }\n \n public Set getTypeInfoFunctions() {\n initStdClasses();\n return typeInfoFunction;\n }\n\n @NotNull\n public JetType getPrimitiveJetType(PrimitiveType primitiveType) {\n return primitiveTypeToJetType.get(primitiveType);\n }\n\n @NotNull\n public JetType getIntType() {\n return getPrimitiveJetType(PrimitiveType.INT);\n }\n\n @NotNull\n public JetType getLongType() {\n return getPrimitiveJetType(PrimitiveType.LONG);\n }\n\n @NotNull\n public JetType getDoubleType() {\n return getPrimitiveJetType(PrimitiveType.DOUBLE);\n }\n\n @NotNull\n public JetType getFloatType() {\n return getPrimitiveJetType(PrimitiveType.FLOAT);\n }\n\n @NotNull\n public JetType getCharType() {\n return getPrimitiveJetType(PrimitiveType.CHAR);\n }\n\n @NotNull\n public JetType getBooleanType() {\n return getPrimitiveJetType(PrimitiveType.BOOLEAN);\n }\n\n @NotNull\n public JetType getStringType() {\n initStdClasses();\n return stringType;\n }\n\n @NotNull\n public JetType getCharSequenceType() {\n initStdClasses();\n return charSequenceType;\n }\n\n @NotNull\n public JetType getByteType() {\n return getPrimitiveJetType(PrimitiveType.BYTE);\n }\n\n @NotNull\n public JetType getShortType() {\n return getPrimitiveJetType(PrimitiveType.SHORT);\n }\n\n @NotNull\n public JetType getArrayType(@NotNull JetType argument) {\n return getArrayType(Variance.INVARIANT, argument);\n }\n\n @NotNull\n public JetType getArrayType(@NotNull Variance projectionType, @NotNull JetType argument) {\n List types = Collections.singletonList(new TypeProjection(projectionType, argument));\n return new JetTypeImpl(\n Collections.emptyList(),\n getArray().getTypeConstructor(),\n false,\n types,\n getArray().getMemberScope(types)\n );\n }\n \n @NotNull\n public JetType getArrayElementType(@NotNull JetType arrayType) {\n // make non-null?\n if (arrayType.getConstructor().getDeclarationDescriptor() == getArray()) {\n if (arrayType.getArguments().size() != 1) {\n throw new IllegalStateException();\n }\n return arrayType.getArguments().get(0).getType();\n }\n JetType primitiveType = jetArrayTypeToPrimitiveJetType.get(arrayType);\n if (primitiveType == null) {\n throw new IllegalStateException(\"not array: \" + arrayType);\n }\n return primitiveType;\n }\n\n @NotNull\n public JetType getIterableType(@NotNull JetType argument) {\n return getIterableType(Variance.INVARIANT, argument);\n }\n\n @NotNull\n public JetType getIterableType(@NotNull Variance projectionType, @NotNull JetType argument) {\n List types = Collections.singletonList(new TypeProjection(projectionType, argument));\n return new JetTypeImpl(\n Collections.emptyList(),\n getIterable().getTypeConstructor(),\n false,\n types,\n getIterable().getMemberScope(types)\n );\n }\n\n @NotNull\n public JetType getNullableStringType() {\n initStdClasses();\n return nullableStringType;\n }\n\n @NotNull\n public JetType getNullableCharSequenceType() {\n initStdClasses();\n return nullableCharSequenceType;\n }\n \n @NotNull\n public JetType getThrowableType() {\n initStdClasses();\n return throwableType;\n }\n\n public JetType getNullableThrowableType() {\n initStdClasses();\n return nullableThrowableType;\n }\n\n @NotNull\n public JetType getNullablePrimitiveJetType(PrimitiveType primitiveType) {\n initStdClasses();\n return primitiveTypeToNullableJetType.get(primitiveType);\n }\n\n public JetType getNullableTuple0Type() {\n initStdClasses();\n return nullableTuple0Type;\n }\n \n @NotNull\n public JetType getPrimitiveArrayJetType(PrimitiveType primitiveType) {\n initStdClasses();\n return primitiveTypeToArrayJetType.get(primitiveType);\n }\n\n /**\n * @return null if not primitive\n */\n @Nullable\n public JetType getPrimitiveArrayJetTypeByPrimitiveJetType(JetType jetType) {\n return primitiveJetTypeToJetArrayType.get(jetType);\n }\n\n @NotNull\n public ClassDescriptor getPrimitiveArrayClassDescriptor(PrimitiveType primitiveType) {\n initStdClasses();\n return primitiveTypeToArrayClass.get(primitiveType);\n }\n\n\n @NotNull\n public JetType getNullablePrimitiveArrayJetType(PrimitiveType primitiveType) {\n initStdClasses();\n return primitiveTypeToNullableArrayJetType.get(primitiveType);\n }\n\n public ClassDescriptor getVolatile() {\n return volatileClass;\n }\n\n public JetType getVolatileType() {\n return volatileType;\n }\n\n public final boolean isVolatile(PropertyDescriptor descriptor) {\n List annotations = descriptor.getOriginal().getAnnotations();\n if(annotations != null) {\n for(AnnotationDescriptor d: annotations) {\n if(d.getType().equals(getVolatileType()))\n return true;\n }\n }\n return false;\n }\n\n public JetType getTuple0Type() {\n return tuple0Type;\n }\n}\n
-===================================================================
---- compiler/frontend/src/org/jetbrains/jet/lang/types/JetStandardLibrary.java (date 1330080250000)
-+++ compiler/frontend/src/org/jetbrains/jet/lang/types/JetStandardLibrary.java (revision )
-@@ -462,6 +462,11 @@
- return volatileType;
- }
-
-+ @NotNull
-+ public Collection getArrayClasses() {
-+ return primitiveTypeToArrayClass.values();
-+ }
-+
- public final boolean isVolatile(PropertyDescriptor descriptor) {
- List annotations = descriptor.getOriginal().getAnnotations();
- if(annotations != null) {
diff --git a/js/ideaAction.patch b/js/ideaAction.patch
deleted file mode 100644
index 4f2eaa8fa34..00000000000
--- a/js/ideaAction.patch
+++ /dev/null
@@ -1,150 +0,0 @@
-Index: compiler/frontend/src/org/jetbrains/jet/lang/resolve/AnnotationResolver.java
-IDEA additional info:
-Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
-<+>UTF-8
-===================================================================
---- compiler/frontend/src/org/jetbrains/jet/lang/resolve/AnnotationResolver.java (revision 24a2ec5)
-+++ compiler/frontend/src/org/jetbrains/jet/lang/resolve/AnnotationResolver.java (revision 4229e867af6d744d3b384dfc515cbf89caf363ae)
-@@ -173,8 +173,8 @@
- List 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;
- }
-Index: idea/src/META-INF/plugin.xml
-IDEA additional info:
-Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
-<+>UTF-8
-===================================================================
---- idea/src/META-INF/plugin.xml (revision 24a2ec5)
-+++ idea/src/META-INF/plugin.xml (revision 4229e867af6d744d3b384dfc515cbf89caf363ae)
-@@ -1,9 +1,12 @@
-
- Kotlin
- Kotlin language support
-- @snapshot@
-+ 1.0
- JetBrains
-
-+
-+
-+
-
-
- org.jetbrains.jet.plugin.compiler.JetCompilerManager
-@@ -28,16 +31,18 @@
-
-
-
--
--
--
--
-
-
-
-
-+
-+
-+
-+
-+
-+
-
-
-
-Index: idea/src/org/jetbrains/jet/plugin/actions/TranslateToJsAction.java
-IDEA additional info:
-Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
-<+>UTF-8
-===================================================================
---- idea/src/org/jetbrains/jet/plugin/actions/TranslateToJsAction.java (revision 4229e867af6d744d3b384dfc515cbf89caf363ae)
-+++ idea/src/org/jetbrains/jet/plugin/actions/TranslateToJsAction.java (revision 4229e867af6d744d3b384dfc515cbf89caf363ae)
-@@ -0,0 +1,79 @@
-+package org.jetbrains.jet.plugin.actions;
-+
-+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.LangDataKeys;
-+import com.intellij.openapi.actionSystem.PlatformDataKeys;
-+import com.intellij.openapi.application.ApplicationManager;
-+import com.intellij.openapi.editor.Editor;
-+import com.intellij.openapi.project.Project;
-+import com.intellij.openapi.vfs.VirtualFile;
-+import com.intellij.psi.PsiFile;
-+import org.jetbrains.jet.lang.psi.JetFile;
-+import org.jetbrains.k2js.facade.K2JSTranslator;
-+
-+/**
-+ * @author Pavel Talanov
-+ */
-+public final class TranslateToJsAction extends AnAction {
-+
-+ private static void notifyFailure(Throwable exception) {
-+ Notifications.Bus.notify(new Notification("JsTranslator", "Translation failed.",
-+ "Exception: " + exception.getMessage(),
-+ NotificationType.ERROR));
-+ }
-+
-+ private static void notifySuccess(String outputPath) {
-+ Notifications.Bus.notify(new Notification("JsTranslator", "Translation successful.",
-+ "Generated file: " + outputPath,
-+ NotificationType.INFORMATION));
-+ }
-+
-+ public void actionPerformed(AnActionEvent event) {
-+
-+ final PsiFile psiFile = event.getData(LangDataKeys.PSI_FILE);
-+ if (!(psiFile instanceof JetFile)) {
-+ return;
-+ }
-+
-+ Runnable task = new Runnable() {
-+ @Override
-+ public void run() {
-+ try {
-+ Project project = psiFile.getProject();
-+ String outputPath = getOutputPath(psiFile);
-+ K2JSTranslator.translateWithCallToMainAndSaveToFile((JetFile) psiFile,
-+ outputPath,
-+ project);
-+ notifySuccess(outputPath);
-+ } catch (Throwable e) {
-+ e.printStackTrace();
-+ notifyFailure(e);
-+ }
-+ }
-+ };
-+ ApplicationManager.getApplication().runWriteAction(task);
-+ }
-+
-+ private static String getOutputPath(PsiFile psiFile) {
-+ 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);
-+ PsiFile psiFile = e.getData(LangDataKeys.PSI_FILE);
-+ e.getPresentation().setEnabled(editor != null && psiFile instanceof JetFile);
-+ }
-+}
diff --git a/js/js.lib/jslib.iml b/js/js.libraries/js.libraries.iml
similarity index 100%
rename from js/js.lib/jslib.iml
rename to js/js.libraries/js.libraries.iml
diff --git a/js/js.lib/src/core/Dummy.java b/js/js.libraries/src/core/Dummy.java
similarity index 100%
rename from js/js.lib/src/core/Dummy.java
rename to js/js.libraries/src/core/Dummy.java
diff --git a/js/js.lib/src/core/annotations.kt b/js/js.libraries/src/core/annotations.kt
similarity index 100%
rename from js/js.lib/src/core/annotations.kt
rename to js/js.libraries/src/core/annotations.kt
diff --git a/js/js.lib/src/core/core.kt b/js/js.libraries/src/core/core.kt
similarity index 100%
rename from js/js.lib/src/core/core.kt
rename to js/js.libraries/src/core/core.kt
diff --git a/js/js.lib/src/core/date.kt b/js/js.libraries/src/core/date.kt
similarity index 100%
rename from js/js.lib/src/core/date.kt
rename to js/js.libraries/src/core/date.kt
diff --git a/js/js.lib/src/core/javalang.kt b/js/js.libraries/src/core/javalang.kt
similarity index 100%
rename from js/js.lib/src/core/javalang.kt
rename to js/js.libraries/src/core/javalang.kt
diff --git a/js/js.lib/src/core/javautil.kt b/js/js.libraries/src/core/javautil.kt
similarity index 100%
rename from js/js.lib/src/core/javautil.kt
rename to js/js.libraries/src/core/javautil.kt
diff --git a/js/js.lib/src/core/json.kt b/js/js.libraries/src/core/json.kt
similarity index 100%
rename from js/js.lib/src/core/json.kt
rename to js/js.libraries/src/core/json.kt
diff --git a/js/js.lib/src/core/math.kt b/js/js.libraries/src/core/math.kt
similarity index 100%
rename from js/js.lib/src/core/math.kt
rename to js/js.libraries/src/core/math.kt
diff --git a/js/js.lib/src/html5/canvas.kt b/js/js.libraries/src/html5/canvas.kt
similarity index 100%
rename from js/js.lib/src/html5/canvas.kt
rename to js/js.libraries/src/html5/canvas.kt
diff --git a/js/js.lib/src/html5/files.kt b/js/js.libraries/src/html5/files.kt
similarity index 100%
rename from js/js.lib/src/html5/files.kt
rename to js/js.libraries/src/html5/files.kt
diff --git a/js/js.lib/src/html5/image.kt b/js/js.libraries/src/html5/image.kt
similarity index 100%
rename from js/js.lib/src/html5/image.kt
rename to js/js.libraries/src/html5/image.kt
diff --git a/js/js.lib/src/jquery/common.kt b/js/js.libraries/src/jquery/common.kt
similarity index 100%
rename from js/js.lib/src/jquery/common.kt
rename to js/js.libraries/src/jquery/common.kt
diff --git a/js/js.lib/src/jquery/ui.kt b/js/js.libraries/src/jquery/ui.kt
similarity index 100%
rename from js/js.lib/src/jquery/ui.kt
rename to js/js.libraries/src/jquery/ui.kt
diff --git a/js/js.lib/src/raphael/raphael.kt b/js/js.libraries/src/raphael/raphael.kt
similarity index 100%
rename from js/js.lib/src/raphael/raphael.kt
rename to js/js.libraries/src/raphael/raphael.kt
diff --git a/js/js.tests/js.tests.iml b/js/js.tests/js.tests.iml
index 79bcf12bc71..72acf26a5cc 100644
--- a/js/js.tests/js.tests.iml
+++ b/js/js.tests/js.tests.iml
@@ -8,9 +8,10 @@
-
-
+
+
+
diff --git a/js/js.tests/test/org/jetbrains/k2js/test/BaseTest.java b/js/js.tests/test/org/jetbrains/k2js/test/BaseTest.java
index 71875def517..1862a52d6e4 100644
--- a/js/js.tests/test/org/jetbrains/k2js/test/BaseTest.java
+++ b/js/js.tests/test/org/jetbrains/k2js/test/BaseTest.java
@@ -36,7 +36,7 @@ public abstract class BaseTest extends UsefulTestCase {
@Override
protected void setUp() throws Exception {
super.setUp();
- // createEnvironmentWithMockJdk();
+ createEnvironmentWithMockJdk();
}
@Override
diff --git a/js/js.tests/test/org/jetbrains/k2js/test/Suite.java b/js/js.tests/test/org/jetbrains/k2js/test/Suite.java
index fc00d540acd..334e7634216 100644
--- a/js/js.tests/test/org/jetbrains/k2js/test/Suite.java
+++ b/js/js.tests/test/org/jetbrains/k2js/test/Suite.java
@@ -46,9 +46,9 @@ public final class Suite extends TranslationTest {
});
}
- //NOTE: just to avoid warning
- public void testNothing() {
- }
+// //NOTE: just to avoid warning
+// public void testNothing() {
+// }
@Override
protected String mainDirectory() {
diff --git a/js/js.tests/test/org/jetbrains/k2js/test/TranslationTest.java b/js/js.tests/test/org/jetbrains/k2js/test/TranslationTest.java
index 15ca18a2058..5e4e3029b05 100644
--- a/js/js.tests/test/org/jetbrains/k2js/test/TranslationTest.java
+++ b/js/js.tests/test/org/jetbrains/k2js/test/TranslationTest.java
@@ -16,6 +16,10 @@
package org.jetbrains.k2js.test;
+import com.google.dart.compiler.backend.js.ast.JsProgram;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.jet.lang.psi.JetFile;
+import org.jetbrains.k2js.config.TestConfig;
import org.jetbrains.k2js.facade.K2JSTranslator;
import org.mozilla.javascript.Context;
import org.mozilla.javascript.Scriptable;
@@ -29,8 +33,11 @@ import java.nio.channels.FileChannel;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.Arrays;
+import java.util.Collections;
import java.util.List;
+import static org.jetbrains.k2js.utils.JetFileUtils.createPsiFileList;
+
//TODO: spread the test* methods amongst classes that actually use them
/**
@@ -44,6 +51,19 @@ public abstract class TranslationTest extends BaseTest {
private static final String KOTLIN_JS_LIB = TEST_FILES + "kotlin_lib.js";
private static final String EXPECTED = "expected/";
+ public void testTranslateFile(@NotNull String inputFile,
+ @NotNull String outputFile) throws Exception {
+ testTranslateFiles(Collections.singletonList(inputFile), outputFile);
+ }
+
+ public void testTranslateFiles(@NotNull List inputFiles,
+ @NotNull String outputFile) throws Exception {
+ K2JSTranslator translator = new K2JSTranslator(new TestConfig(getProject()));
+ List psiFiles = createPsiFileList(inputFiles, getProject());
+ JsProgram program = translator.generateProgram(psiFiles);
+ K2JSTranslator.saveProgramToFile(outputFile, program);
+ }
+
protected String kotlinLibraryPath() {
return KOTLIN_JS_LIB;
}
@@ -97,8 +117,8 @@ public abstract class TranslationTest extends BaseTest {
}
protected void translateFile(String filename) throws Exception {
- K2JSTranslator.testTranslateFile(getInputFilePath(filename),
- getOutputFilePath(filename));
+ testTranslateFile(getInputFilePath(filename),
+ getOutputFilePath(filename));
}
protected void translateFilesInDir(String dirName) throws Exception {
@@ -109,8 +129,8 @@ public abstract class TranslationTest extends BaseTest {
fullFilePaths.add(getInputFilePath(dirName) + "\\" + fileName);
}
assert dir.isDirectory();
- K2JSTranslator.testTranslateFiles(fullFilePaths,
- getOutputFilePath(dirName + ".kt"));
+ testTranslateFiles(fullFilePaths,
+ getOutputFilePath(dirName + ".kt"));
}
protected List generateFilenameList(String inputFile) {
diff --git a/js/js.translator/js.translator.iml b/js/js.translator/js.translator.iml
new file mode 100644
index 00000000000..f8641655212
--- /dev/null
+++ b/js/js.translator/js.translator.iml
@@ -0,0 +1,16 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/js/js.translator/src/org/jetbrains/k2js/analyze/Analyzer.java b/js/js.translator/src/org/jetbrains/k2js/analyze/Analyzer.java
index d0aba16b5a6..9337a34131a 100644
--- a/js/js.translator/src/org/jetbrains/k2js/analyze/Analyzer.java
+++ b/js/js.translator/src/org/jetbrains/k2js/analyze/Analyzer.java
@@ -17,11 +17,14 @@
package org.jetbrains.k2js.analyze;
import com.google.common.base.Predicate;
+import com.google.common.base.Predicates;
import com.intellij.openapi.project.Project;
import com.intellij.psi.PsiFile;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.lang.Configuration;
+import org.jetbrains.jet.lang.JetSemanticServices;
+import org.jetbrains.jet.lang.StandardConfiguration;
import org.jetbrains.jet.lang.cfg.pseudocode.JetControlFlowDataTraceFactory;
import org.jetbrains.jet.lang.descriptors.NamespaceDescriptor;
import org.jetbrains.jet.lang.psi.JetFile;
@@ -31,6 +34,7 @@ import org.jetbrains.jet.lang.resolve.scopes.WritableScope;
import org.jetbrains.k2js.config.Config;
import java.util.ArrayList;
+import java.util.Collections;
import java.util.List;
/**
@@ -89,6 +93,21 @@ public final class Analyzer {
};
}
+ public static BindingContext analyzeNamespace(@NotNull JetFile file) {
+ BindingTraceContext bindingTraceContext = new BindingTraceContext();
+ Project project = file.getProject();
+ JetSemanticServices semanticServices = JetSemanticServices.createSemanticServices(project);
+ return AnalyzingUtils.analyzeFilesWithGivenTrace(
+ project,
+ JsConfiguration.jsLibConfiguration(project),
+ Collections.singletonList(file),
+ Predicates.alwaysTrue(),
+ JetControlFlowDataTraceFactory.EMPTY,
+ bindingTraceContext,
+ semanticServices);
+// return AnalyzerFacade.analyzeOneFileWithJavaIntegration(file, flowDataTraceFactory);
+ }
+
private static final class JsConfiguration implements Configuration {
@NotNull
diff --git a/js/js.translator/src/org/jetbrains/k2js/config/TestConfig.java b/js/js.translator/src/org/jetbrains/k2js/config/TestConfig.java
index 68a91518455..0740353e7c3 100644
--- a/js/js.translator/src/org/jetbrains/k2js/config/TestConfig.java
+++ b/js/js.translator/src/org/jetbrains/k2js/config/TestConfig.java
@@ -18,10 +18,10 @@ package org.jetbrains.k2js.config;
import com.intellij.openapi.Disposable;
import com.intellij.openapi.project.Project;
+import com.intellij.openapi.util.io.FileUtil;
import core.Dummy;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
-import org.jetbrains.jet.compiler.JetCoreEnvironment;
import org.jetbrains.jet.lang.psi.JetFile;
import org.jetbrains.k2js.utils.JetFileUtils;
@@ -56,32 +56,20 @@ public final class TestConfig extends Config {
"/html5/image.kt"
);
- @NotNull
- private static JetCoreEnvironment getTestEnvironment() {
- if (testOnlyEnvironment == null) {
- testOnlyEnvironment = new JetCoreEnvironment(new Disposable() {
- @Override
- public void dispose() {
- }
- });
- }
- return testOnlyEnvironment;
- }
-
- @Nullable
- private static /*var*/ JetCoreEnvironment testOnlyEnvironment = null;
-
-
@Nullable
private /*var*/ List jsLibFiles = null;
- public TestConfig() {
+ @NotNull
+ private final Project project;
+
+ public TestConfig(@NotNull Project project) {
+ this.project = project;
}
@NotNull
@Override
public Project getProject() {
- return getTestEnvironment().getProject();
+ return project;
}
@NotNull
@@ -92,7 +80,7 @@ public final class TestConfig extends Config {
//TODO: close stream?
InputStream stream = Dummy.class.getResourceAsStream(libFileName);
try {
- String text = readString(stream);
+ String text = FileUtil.loadTextAndClose(stream);
file = JetFileUtils.createPsiFile(libFileName, text, project);
} catch (IOException e) {
e.printStackTrace();
@@ -110,17 +98,17 @@ public final class TestConfig extends Config {
return jsLibFiles;
}
- @NotNull
- private static String readString(@NotNull InputStream is) throws IOException {
- char[] buf = new char[2048];
- Reader r = new InputStreamReader(is, "UTF-8");
- StringBuilder s = new StringBuilder();
- while (true) {
- int n = r.read(buf);
- if (n < 0)
- break;
- s.append(buf, 0, n);
- }
- return s.toString();
- }
+// @NotNull
+// private static String readString(@NotNull InputStream is) throws IOException {
+// char[] buf = new char[2048];
+// Reader r = new InputStreamReader(is, "UTF-8");
+// StringBuilder s = new StringBuilder();
+// while (true) {
+// int n = r.read(buf);
+// if (n < 0)
+// break;
+// s.append(buf, 0, n);
+// }
+// return s.toString();
+// }
}
diff --git a/js/js.translator/src/org/jetbrains/k2js/facade/K2JSTranslator.java b/js/js.translator/src/org/jetbrains/k2js/facade/K2JSTranslator.java
index 86b330ea218..b5983e53caa 100644
--- a/js/js.translator/src/org/jetbrains/k2js/facade/K2JSTranslator.java
+++ b/js/js.translator/src/org/jetbrains/k2js/facade/K2JSTranslator.java
@@ -64,20 +64,7 @@ public final class K2JSTranslator {
writer.close();
}
- public static void testTranslateFile(@NotNull String inputFile,
- @NotNull String outputFile) throws Exception {
- testTranslateFiles(Collections.singletonList(inputFile), outputFile);
- }
-
- public static void testTranslateFiles(@NotNull List inputFiles,
- @NotNull String outputFile) throws Exception {
- K2JSTranslator translator = new K2JSTranslator(new TestConfig());
- List psiFiles = createPsiFileList(inputFiles, translator.getProject());
- JsProgram program = translator.generateProgram(psiFiles);
- saveProgramToFile(outputFile, program);
- }
-
- private static void saveProgramToFile(@NotNull String outputFile, @NotNull JsProgram program) throws IOException {
+ public static void saveProgramToFile(@NotNull String outputFile, @NotNull JsProgram program) throws IOException {
CodeGenerator generator = new CodeGenerator();
generator.generateToFile(program, new File(outputFile));
}
@@ -123,7 +110,7 @@ public final class K2JSTranslator {
@NotNull
- private JsProgram generateProgram(@NotNull List filesToTranslate) {
+ public JsProgram generateProgram(@NotNull List filesToTranslate) {
JetStandardLibrary.initialize(config.getProject());
BindingContext bindingContext = Analyzer.analyzeFilesAndCheckErrors(filesToTranslate, config);
return Translation.generateAst(bindingContext, Analyzer.withJsLibAdded(filesToTranslate, config));
diff --git a/js/js.translator/src/org/jetbrains/k2js/facade/K2JSTranslatorUtils.java b/js/js.translator/src/org/jetbrains/k2js/facade/K2JSTranslatorUtils.java
index 8fafffc52ff..df69c35ca1b 100644
--- a/js/js.translator/src/org/jetbrains/k2js/facade/K2JSTranslatorUtils.java
+++ b/js/js.translator/src/org/jetbrains/k2js/facade/K2JSTranslatorUtils.java
@@ -16,6 +16,7 @@
package org.jetbrains.k2js.facade;
+import com.intellij.openapi.project.Project;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.lang.resolve.BindingContext;
@@ -33,9 +34,9 @@ public class K2JSTranslatorUtils {
private static String EXCEPTION = "exception=";
@Nullable
- public String translateToJS(@NotNull String code, @NotNull String arguments) {
+ public String translateToJS(@NotNull Project project, @NotNull String code, @NotNull String arguments) {
try {
- return generateJSCode(code, arguments);
+ return generateJSCode(project, code, arguments);
} catch (AssertionError e) {
reportException(e);
return EXCEPTION + "Translation error.";
@@ -49,9 +50,9 @@ public class K2JSTranslatorUtils {
}
@Nullable
- public BindingContext getBindingContext(@NotNull String programText) {
+ public BindingContext getBindingContext(@NotNull Project project, @NotNull String programText) {
try {
- K2JSTranslator k2JSTranslator = new K2JSTranslator(new TestConfig());
+ K2JSTranslator k2JSTranslator = new K2JSTranslator(new TestConfig(project));
return k2JSTranslator.analyzeProgramCode(programText);
} catch (Throwable e) {
e.printStackTrace();
@@ -61,8 +62,8 @@ public class K2JSTranslatorUtils {
}
@NotNull
- private String generateJSCode(@NotNull String code, @NotNull String arguments) {
- String generatedCode = (new K2JSTranslator(new TestConfig())).translateStringWithCallToMain(code, arguments);
+ private String generateJSCode(@NotNull Project project, @NotNull String code, @NotNull String arguments) {
+ String generatedCode = (new K2JSTranslator(new TestConfig(project))).translateStringWithCallToMain(code, arguments);
return generatedCode;
}