Project structure fixed
This commit is contained in:
Generated
+2
-8
@@ -14,16 +14,10 @@
|
|||||||
<element id="module-output" name="stdlib" />
|
<element id="module-output" name="stdlib" />
|
||||||
<element id="module-output" name="util" />
|
<element id="module-output" name="util" />
|
||||||
<element id="module-output" name="j2k" />
|
<element id="module-output" name="j2k" />
|
||||||
<element id="module-output" name="js.ast" />
|
<element id="module-output" name="js.libraries" />
|
||||||
<element id="library" level="project" name="js_libs" />
|
|
||||||
<element id="module-output" name="js.translator" />
|
<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="library" level="project" name="js-libs" />
|
||||||
</element>
|
</element>
|
||||||
<element id="directory" name="kotlinc">
|
<element id="directory" name="kotlinc">
|
||||||
<element id="dir-copy" path="$PROJECT_DIR$/dist/kotlinc" />
|
<element id="dir-copy" path="$PROJECT_DIR$/dist/kotlinc" />
|
||||||
|
|||||||
-4
@@ -228,10 +228,6 @@
|
|||||||
<scope name="idea openapi" level="WARNING" enabled="true" />
|
<scope name="idea openapi" level="WARNING" enabled="true" />
|
||||||
<scope name="runtime.classes" level="ERROR" enabled="true" />
|
<scope name="runtime.classes" level="ERROR" enabled="true" />
|
||||||
</inspection_tool>
|
</inspection_tool>
|
||||||
<inspection_tool class="MethodMayBeStatic" enabled="true" level="WARNING" enabled_by_default="true">
|
|
||||||
<option name="m_onlyPrivateOrFinal" value="false" />
|
|
||||||
<option name="m_ignoreEmptyMethods" value="true" />
|
|
||||||
</inspection_tool>
|
|
||||||
<inspection_tool class="MethodNamesDifferOnlyByCase" enabled="true" level="WARNING" enabled_by_default="true" />
|
<inspection_tool class="MethodNamesDifferOnlyByCase" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||||
<inspection_tool class="MethodOverloadsParentMethod" enabled="true" level="WARNING" enabled_by_default="true" />
|
<inspection_tool class="MethodOverloadsParentMethod" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||||
<inspection_tool class="MethodOverridesPrivateMethod" enabled="true" level="WARNING" enabled_by_default="true" />
|
<inspection_tool class="MethodOverridesPrivateMethod" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||||
|
|||||||
Generated
+1
-2
@@ -1,7 +1,6 @@
|
|||||||
<component name="libraryTable">
|
<component name="libraryTable">
|
||||||
<library name="js_libs">
|
<library name="js-libs">
|
||||||
<CLASSES>
|
<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/js.jar!/" />
|
||||||
<root url="jar://$PROJECT_DIR$/js/js.translator/lib/dartc.jar!/" />
|
<root url="jar://$PROJECT_DIR$/js/js.translator/lib/dartc.jar!/" />
|
||||||
</CLASSES>
|
</CLASSES>
|
||||||
|
|||||||
Generated
+1
-3
@@ -17,12 +17,10 @@
|
|||||||
<module fileurl="file://$PROJECT_DIR$/j2k/j2k.iml" filepath="$PROJECT_DIR$/j2k/j2k.iml" />
|
<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$/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$/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.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.libraries/js.libraries.iml" filepath="$PROJECT_DIR$/js/js.libraries/js.libraries.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.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/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$/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$/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" />
|
<module fileurl="file://$PROJECT_DIR$/compiler/util/util.iml" filepath="$PROJECT_DIR$/compiler/util/util.iml" />
|
||||||
|
|||||||
@@ -51,15 +51,6 @@ public class JetMainDetector {
|
|||||||
return false;
|
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
|
@Nullable
|
||||||
public static JetFile getFileWithMain(@NotNull List<JetFile> files) {
|
public static JetFile getFileWithMain(@NotNull List<JetFile> files) {
|
||||||
for (JetFile file : files) {
|
for (JetFile file : files) {
|
||||||
|
|||||||
-315
File diff suppressed because one or more lines are too long
@@ -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<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;
|
|
||||||
}
|
|
||||||
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 @@
|
|
||||||
<idea-plugin version="2">
|
|
||||||
<name>Kotlin</name>
|
|
||||||
<description>Kotlin language support</description>
|
|
||||||
- <version>@snapshot@</version>
|
|
||||||
+ <version>1.0</version>
|
|
||||||
<vendor>JetBrains</vendor>
|
|
||||||
|
|
||||||
+ <application-components>
|
|
||||||
+ </application-components>
|
|
||||||
+
|
|
||||||
<project-components>
|
|
||||||
<component>
|
|
||||||
<implementation-class>org.jetbrains.jet.plugin.compiler.JetCompilerManager</implementation-class>
|
|
||||||
@@ -28,16 +31,18 @@
|
|
||||||
<keyboard-shortcut keymap="$default" first-keystroke="control alt shift T"/>
|
|
||||||
<add-to-group group-id="CodeMenu" anchor="last"/>
|
|
||||||
</action>
|
|
||||||
- <action id="ConvertJavaToKotlin" class="org.jetbrains.jet.plugin.actions.JavaToKotlinAction"
|
|
||||||
- text="Convert Java File to Kotlin File">
|
|
||||||
- <keyboard-shortcut keymap="$default" first-keystroke="control alt shift J"/>
|
|
||||||
- <add-to-group group-id="CodeMenu" anchor="last"/>
|
|
||||||
- </action>
|
|
||||||
<action id="ToggleJetErrorReporting" class="org.jetbrains.jet.plugin.actions.ToggleErrorReportingAction"
|
|
||||||
text="Toggle Error Reporting">
|
|
||||||
<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 current namespace and create js files.">
|
|
||||||
+ <keyboard-shortcut keymap="$default" first-keystroke="control alt shift J"/>
|
|
||||||
+ <add-to-group group-id="CodeMenu" anchor="last"/>
|
|
||||||
+ </action>
|
|
||||||
+
|
|
||||||
</actions>
|
|
||||||
|
|
||||||
<extensions defaultExtensionNs="com.intellij">
|
|
||||||
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);
|
|
||||||
+ }
|
|
||||||
+}
|
|
||||||
@@ -8,9 +8,10 @@
|
|||||||
<orderEntry type="jdk" jdkName="1.6" jdkType="JavaSDK" />
|
<orderEntry type="jdk" jdkName="1.6" jdkType="JavaSDK" />
|
||||||
<orderEntry type="sourceFolder" forTests="false" />
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
<orderEntry type="module" module-name="js.translator" />
|
<orderEntry type="module" module-name="js.translator" />
|
||||||
<orderEntry type="library" name="idea-full" level="application" />
|
|
||||||
<orderEntry type="library" name="js_libs" level="project" />
|
|
||||||
<orderEntry type="module" module-name="compiler-tests" />
|
<orderEntry type="module" module-name="compiler-tests" />
|
||||||
|
<orderEntry type="library" name="idea-full" level="project" />
|
||||||
|
<orderEntry type="library" name="js-libs" level="project" />
|
||||||
|
<orderEntry type="module" module-name="frontend" />
|
||||||
<orderEntry type="module" module-name="cli" />
|
<orderEntry type="module" module-name="cli" />
|
||||||
</component>
|
</component>
|
||||||
</module>
|
</module>
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ public abstract class BaseTest extends UsefulTestCase {
|
|||||||
@Override
|
@Override
|
||||||
protected void setUp() throws Exception {
|
protected void setUp() throws Exception {
|
||||||
super.setUp();
|
super.setUp();
|
||||||
// createEnvironmentWithMockJdk();
|
createEnvironmentWithMockJdk();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -46,9 +46,9 @@ public final class Suite extends TranslationTest {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
//NOTE: just to avoid warning
|
// //NOTE: just to avoid warning
|
||||||
public void testNothing() {
|
// public void testNothing() {
|
||||||
}
|
// }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected String mainDirectory() {
|
protected String mainDirectory() {
|
||||||
|
|||||||
@@ -16,6 +16,10 @@
|
|||||||
|
|
||||||
package org.jetbrains.k2js.test;
|
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.jetbrains.k2js.facade.K2JSTranslator;
|
||||||
import org.mozilla.javascript.Context;
|
import org.mozilla.javascript.Context;
|
||||||
import org.mozilla.javascript.Scriptable;
|
import org.mozilla.javascript.Scriptable;
|
||||||
@@ -29,8 +33,11 @@ import java.nio.channels.FileChannel;
|
|||||||
import java.nio.charset.Charset;
|
import java.nio.charset.Charset;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import static org.jetbrains.k2js.utils.JetFileUtils.createPsiFileList;
|
||||||
|
|
||||||
//TODO: spread the test* methods amongst classes that actually use them
|
//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 KOTLIN_JS_LIB = TEST_FILES + "kotlin_lib.js";
|
||||||
private static final String EXPECTED = "expected/";
|
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<String> inputFiles,
|
||||||
|
@NotNull String outputFile) throws Exception {
|
||||||
|
K2JSTranslator translator = new K2JSTranslator(new TestConfig(getProject()));
|
||||||
|
List<JetFile> psiFiles = createPsiFileList(inputFiles, getProject());
|
||||||
|
JsProgram program = translator.generateProgram(psiFiles);
|
||||||
|
K2JSTranslator.saveProgramToFile(outputFile, program);
|
||||||
|
}
|
||||||
|
|
||||||
protected String kotlinLibraryPath() {
|
protected String kotlinLibraryPath() {
|
||||||
return KOTLIN_JS_LIB;
|
return KOTLIN_JS_LIB;
|
||||||
}
|
}
|
||||||
@@ -97,8 +117,8 @@ public abstract class TranslationTest extends BaseTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected void translateFile(String filename) throws Exception {
|
protected void translateFile(String filename) throws Exception {
|
||||||
K2JSTranslator.testTranslateFile(getInputFilePath(filename),
|
testTranslateFile(getInputFilePath(filename),
|
||||||
getOutputFilePath(filename));
|
getOutputFilePath(filename));
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void translateFilesInDir(String dirName) throws Exception {
|
protected void translateFilesInDir(String dirName) throws Exception {
|
||||||
@@ -109,8 +129,8 @@ public abstract class TranslationTest extends BaseTest {
|
|||||||
fullFilePaths.add(getInputFilePath(dirName) + "\\" + fileName);
|
fullFilePaths.add(getInputFilePath(dirName) + "\\" + fileName);
|
||||||
}
|
}
|
||||||
assert dir.isDirectory();
|
assert dir.isDirectory();
|
||||||
K2JSTranslator.testTranslateFiles(fullFilePaths,
|
testTranslateFiles(fullFilePaths,
|
||||||
getOutputFilePath(dirName + ".kt"));
|
getOutputFilePath(dirName + ".kt"));
|
||||||
}
|
}
|
||||||
|
|
||||||
protected List<String> generateFilenameList(String inputFile) {
|
protected List<String> generateFilenameList(String inputFile) {
|
||||||
|
|||||||
@@ -0,0 +1,16 @@
|
|||||||
|
<?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" module-name="frontend" />
|
||||||
|
<orderEntry type="module" module-name="js.libraries" />
|
||||||
|
<orderEntry type="library" name="js-libs" level="project" />
|
||||||
|
<orderEntry type="library" scope="PROVIDED" name="intellij-core" level="project" />
|
||||||
|
</component>
|
||||||
|
</module>
|
||||||
|
|
||||||
@@ -17,11 +17,14 @@
|
|||||||
package org.jetbrains.k2js.analyze;
|
package org.jetbrains.k2js.analyze;
|
||||||
|
|
||||||
import com.google.common.base.Predicate;
|
import com.google.common.base.Predicate;
|
||||||
|
import com.google.common.base.Predicates;
|
||||||
import com.intellij.openapi.project.Project;
|
import com.intellij.openapi.project.Project;
|
||||||
import com.intellij.psi.PsiFile;
|
import com.intellij.psi.PsiFile;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.jetbrains.jet.lang.Configuration;
|
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.cfg.pseudocode.JetControlFlowDataTraceFactory;
|
||||||
import org.jetbrains.jet.lang.descriptors.NamespaceDescriptor;
|
import org.jetbrains.jet.lang.descriptors.NamespaceDescriptor;
|
||||||
import org.jetbrains.jet.lang.psi.JetFile;
|
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 org.jetbrains.k2js.config.Config;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.List;
|
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.<PsiFile>alwaysTrue(),
|
||||||
|
JetControlFlowDataTraceFactory.EMPTY,
|
||||||
|
bindingTraceContext,
|
||||||
|
semanticServices);
|
||||||
|
// return AnalyzerFacade.analyzeOneFileWithJavaIntegration(file, flowDataTraceFactory);
|
||||||
|
}
|
||||||
|
|
||||||
private static final class JsConfiguration implements Configuration {
|
private static final class JsConfiguration implements Configuration {
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
|
|||||||
@@ -18,10 +18,10 @@ package org.jetbrains.k2js.config;
|
|||||||
|
|
||||||
import com.intellij.openapi.Disposable;
|
import com.intellij.openapi.Disposable;
|
||||||
import com.intellij.openapi.project.Project;
|
import com.intellij.openapi.project.Project;
|
||||||
|
import com.intellij.openapi.util.io.FileUtil;
|
||||||
import core.Dummy;
|
import core.Dummy;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.jetbrains.jet.compiler.JetCoreEnvironment;
|
|
||||||
import org.jetbrains.jet.lang.psi.JetFile;
|
import org.jetbrains.jet.lang.psi.JetFile;
|
||||||
import org.jetbrains.k2js.utils.JetFileUtils;
|
import org.jetbrains.k2js.utils.JetFileUtils;
|
||||||
|
|
||||||
@@ -56,32 +56,20 @@ public final class TestConfig extends Config {
|
|||||||
"/html5/image.kt"
|
"/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
|
@Nullable
|
||||||
private /*var*/ List<JetFile> jsLibFiles = null;
|
private /*var*/ List<JetFile> jsLibFiles = null;
|
||||||
|
|
||||||
public TestConfig() {
|
@NotNull
|
||||||
|
private final Project project;
|
||||||
|
|
||||||
|
public TestConfig(@NotNull Project project) {
|
||||||
|
this.project = project;
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public Project getProject() {
|
public Project getProject() {
|
||||||
return getTestEnvironment().getProject();
|
return project;
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@@ -92,7 +80,7 @@ public final class TestConfig extends Config {
|
|||||||
//TODO: close stream?
|
//TODO: close stream?
|
||||||
InputStream stream = Dummy.class.getResourceAsStream(libFileName);
|
InputStream stream = Dummy.class.getResourceAsStream(libFileName);
|
||||||
try {
|
try {
|
||||||
String text = readString(stream);
|
String text = FileUtil.loadTextAndClose(stream);
|
||||||
file = JetFileUtils.createPsiFile(libFileName, text, project);
|
file = JetFileUtils.createPsiFile(libFileName, text, project);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
@@ -110,17 +98,17 @@ public final class TestConfig extends Config {
|
|||||||
return jsLibFiles;
|
return jsLibFiles;
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
// @NotNull
|
||||||
private static String readString(@NotNull InputStream is) throws IOException {
|
// private static String readString(@NotNull InputStream is) throws IOException {
|
||||||
char[] buf = new char[2048];
|
// char[] buf = new char[2048];
|
||||||
Reader r = new InputStreamReader(is, "UTF-8");
|
// Reader r = new InputStreamReader(is, "UTF-8");
|
||||||
StringBuilder s = new StringBuilder();
|
// StringBuilder s = new StringBuilder();
|
||||||
while (true) {
|
// while (true) {
|
||||||
int n = r.read(buf);
|
// int n = r.read(buf);
|
||||||
if (n < 0)
|
// if (n < 0)
|
||||||
break;
|
// break;
|
||||||
s.append(buf, 0, n);
|
// s.append(buf, 0, n);
|
||||||
}
|
// }
|
||||||
return s.toString();
|
// return s.toString();
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -64,20 +64,7 @@ public final class K2JSTranslator {
|
|||||||
writer.close();
|
writer.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void testTranslateFile(@NotNull String inputFile,
|
public static void saveProgramToFile(@NotNull String outputFile, @NotNull JsProgram program) throws IOException {
|
||||||
@NotNull String outputFile) throws Exception {
|
|
||||||
testTranslateFiles(Collections.singletonList(inputFile), outputFile);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void testTranslateFiles(@NotNull List<String> inputFiles,
|
|
||||||
@NotNull String outputFile) throws Exception {
|
|
||||||
K2JSTranslator translator = new K2JSTranslator(new TestConfig());
|
|
||||||
List<JetFile> 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 {
|
|
||||||
CodeGenerator generator = new CodeGenerator();
|
CodeGenerator generator = new CodeGenerator();
|
||||||
generator.generateToFile(program, new File(outputFile));
|
generator.generateToFile(program, new File(outputFile));
|
||||||
}
|
}
|
||||||
@@ -123,7 +110,7 @@ public final class K2JSTranslator {
|
|||||||
|
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private JsProgram generateProgram(@NotNull List<JetFile> filesToTranslate) {
|
public JsProgram generateProgram(@NotNull List<JetFile> filesToTranslate) {
|
||||||
JetStandardLibrary.initialize(config.getProject());
|
JetStandardLibrary.initialize(config.getProject());
|
||||||
BindingContext bindingContext = Analyzer.analyzeFilesAndCheckErrors(filesToTranslate, config);
|
BindingContext bindingContext = Analyzer.analyzeFilesAndCheckErrors(filesToTranslate, config);
|
||||||
return Translation.generateAst(bindingContext, Analyzer.withJsLibAdded(filesToTranslate, config));
|
return Translation.generateAst(bindingContext, Analyzer.withJsLibAdded(filesToTranslate, config));
|
||||||
|
|||||||
@@ -16,6 +16,7 @@
|
|||||||
|
|
||||||
package org.jetbrains.k2js.facade;
|
package org.jetbrains.k2js.facade;
|
||||||
|
|
||||||
|
import com.intellij.openapi.project.Project;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.jetbrains.jet.lang.resolve.BindingContext;
|
import org.jetbrains.jet.lang.resolve.BindingContext;
|
||||||
@@ -33,9 +34,9 @@ public class K2JSTranslatorUtils {
|
|||||||
private static String EXCEPTION = "exception=";
|
private static String EXCEPTION = "exception=";
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public String translateToJS(@NotNull String code, @NotNull String arguments) {
|
public String translateToJS(@NotNull Project project, @NotNull String code, @NotNull String arguments) {
|
||||||
try {
|
try {
|
||||||
return generateJSCode(code, arguments);
|
return generateJSCode(project, code, arguments);
|
||||||
} catch (AssertionError e) {
|
} catch (AssertionError e) {
|
||||||
reportException(e);
|
reportException(e);
|
||||||
return EXCEPTION + "Translation error.";
|
return EXCEPTION + "Translation error.";
|
||||||
@@ -49,9 +50,9 @@ public class K2JSTranslatorUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public BindingContext getBindingContext(@NotNull String programText) {
|
public BindingContext getBindingContext(@NotNull Project project, @NotNull String programText) {
|
||||||
try {
|
try {
|
||||||
K2JSTranslator k2JSTranslator = new K2JSTranslator(new TestConfig());
|
K2JSTranslator k2JSTranslator = new K2JSTranslator(new TestConfig(project));
|
||||||
return k2JSTranslator.analyzeProgramCode(programText);
|
return k2JSTranslator.analyzeProgramCode(programText);
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
@@ -61,8 +62,8 @@ public class K2JSTranslatorUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private String generateJSCode(@NotNull String code, @NotNull String arguments) {
|
private String generateJSCode(@NotNull Project project, @NotNull String code, @NotNull String arguments) {
|
||||||
String generatedCode = (new K2JSTranslator(new TestConfig())).translateStringWithCallToMain(code, arguments);
|
String generatedCode = (new K2JSTranslator(new TestConfig(project))).translateStringWithCallToMain(code, arguments);
|
||||||
return generatedCode;
|
return generatedCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user