From bee4704358a1589375b5395b0e7bf036e3603d2d Mon Sep 17 00:00:00 2001 From: pTalanov Date: Thu, 1 Mar 2012 18:06:10 +0400 Subject: [PATCH] Added patch for Web Demo. --- js/Web_demo_config_and_facade.patch | 242 ++++++++++++++++++++++++++++ 1 file changed, 242 insertions(+) create mode 100644 js/Web_demo_config_and_facade.patch diff --git a/js/Web_demo_config_and_facade.patch b/js/Web_demo_config_and_facade.patch new file mode 100644 index 00000000000..b2caae113f5 --- /dev/null +++ b/js/Web_demo_config_and_facade.patch @@ -0,0 +1,242 @@ +Index: js/js.translator/src/org/jetbrains/k2js/facade/WebDemoTranslatorFacade.java +IDEA additional info: +Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP +<+>UTF-8 +=================================================================== +--- js/js.translator/src/org/jetbrains/k2js/facade/WebDemoTranslatorFacade.java (revision ) ++++ js/js.translator/src/org/jetbrains/k2js/facade/WebDemoTranslatorFacade.java (revision ) +@@ -0,0 +1,89 @@ ++/* ++* 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.facade; ++ ++import com.intellij.openapi.project.Project; ++import org.jetbrains.annotations.NotNull; ++import org.jetbrains.annotations.Nullable; ++import org.jetbrains.jet.lang.psi.JetFile; ++import org.jetbrains.jet.lang.resolve.BindingContext; ++import org.jetbrains.k2js.analyze.AnalyzerFacade; ++import org.jetbrains.k2js.config.WebDemoConfig; ++import org.jetbrains.k2js.utils.JetFileUtils; ++ ++import java.util.Arrays; ++ ++/** ++ * @author Pavel Talanov ++ */ ++@SuppressWarnings("UnusedDeclaration") ++public final class WebDemoTranslatorFacade { ++ ++ @SuppressWarnings("FieldCanBeLocal") ++ private static String EXCEPTION = "exception="; ++ ++ private WebDemoTranslatorFacade() { ++ } ++ ++ @SuppressWarnings("UnusedDeclaration") ++ @Nullable ++ public static BindingContext analyzeProgramCode(@NotNull Project project, @NotNull String programText) { ++ try { ++ JetFile file = JetFileUtils.createPsiFile("test", programText, project); ++ return AnalyzerFacade.analyzeFiles(Arrays.asList(file), new WebDemoConfig(project)); ++ } catch (Throwable e) { ++ reportException(e); ++ return null; ++ } ++ } ++ ++ ++ @SuppressWarnings("UnusedDeclaration") ++ @NotNull ++ public static String translateStringWithCallToMain(@NotNull Project project, ++ @NotNull String programText, @NotNull String argumentsString) { ++ try { ++ return doTranslate(project, programText, argumentsString); ++ ++ } catch (AssertionError e) { ++ reportException(e); ++ return EXCEPTION + "Translation error."; ++ } catch (UnsupportedOperationException e) { ++ reportException(e); ++ return EXCEPTION + "Unsupported feature."; ++ } catch (Throwable e) { ++ reportException(e); ++ return EXCEPTION + "Unexpected exception."; ++ } ++ } ++ ++ @NotNull ++ private static String doTranslate(@NotNull Project project, @NotNull String programText, ++ @NotNull String argumentsString) { ++ K2JSTranslator translator = new K2JSTranslator(new WebDemoConfig(project)); ++ JetFile file = JetFileUtils.createPsiFile("test", programText, project); ++ String programCode = translator.generateProgramCode(file) + "\n"; ++ String flushOutput = "Kotlin.System.flush();\n"; ++ String callToMain = K2JSTranslator.generateCallToMain(file, argumentsString); ++ String programOutput = "Kotlin.System.output();\n"; ++ return programCode + flushOutput + callToMain + programOutput; ++ } ++ ++ private static void reportException(@NotNull Throwable e) { ++ //TODO: ++ } ++} +Index: js/js.libraries/src/org/jetbrains/k2js/config/Loader.java +IDEA additional info: +Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP +<+>UTF-8 +=================================================================== +--- js/js.libraries/src/org/jetbrains/k2js/config/Loader.java (revision ) ++++ js/js.libraries/src/org/jetbrains/k2js/config/Loader.java (revision ) +@@ -0,0 +1,25 @@ ++/* ++ * 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.config; ++ ++/** ++ * @author Pavel Talanov ++ */ ++//TODO: delegate loading to this class ++//NOTE: this class is for loading resources ++public final class Loader { ++} +Index: js/js.translator/src/org/jetbrains/k2js/config/WebDemoConfig.java +IDEA additional info: +Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP +<+>UTF-8 +=================================================================== +--- js/js.translator/src/org/jetbrains/k2js/config/WebDemoConfig.java (revision ) ++++ js/js.translator/src/org/jetbrains/k2js/config/WebDemoConfig.java (revision ) +@@ -0,0 +1,70 @@ ++/* ++ * 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.config; ++ ++import com.intellij.openapi.project.Project; ++import com.intellij.openapi.util.io.FileUtil; ++import org.jetbrains.annotations.NotNull; ++import org.jetbrains.annotations.Nullable; ++import org.jetbrains.jet.lang.psi.JetFile; ++import org.jetbrains.k2js.utils.JetFileUtils; ++ ++import java.io.IOException; ++import java.io.InputStream; ++import java.util.ArrayList; ++import java.util.List; ++ ++/** ++ * @author Pavel Talanov ++ */ ++//TODO: dup with TestConfig ++public final class WebDemoConfig extends Config { ++ ++ @Nullable ++ private /*var*/ List jsLibFiles = null; ++ ++ public WebDemoConfig(@NotNull Project project) { ++ super(project); ++ } ++ ++ @NotNull ++ private static List initLibFiles(@NotNull Project project) { ++ List libFiles = new ArrayList(); ++ for (String libFileName : LIB_FILE_NAMES) { ++ JetFile file = null; ++ //TODO: close stream? ++ @SuppressWarnings("IOResourceOpenedButNotSafelyClosed") ++ InputStream stream = Loader.class.getResourceAsStream(libFileName); ++ try { ++ String text = FileUtil.loadTextAndClose(stream); ++ file = JetFileUtils.createPsiFile(libFileName, text, project); ++ } catch (IOException e) { ++ e.printStackTrace(); ++ } ++ libFiles.add(file); ++ } ++ return libFiles; ++ } ++ ++ @NotNull ++ public List getLibFiles() { ++ if (jsLibFiles == null) { ++ jsLibFiles = initLibFiles(getProject()); ++ } ++ return jsLibFiles; ++ } ++} +Index: .idea/modules.xml +IDEA additional info: +Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP +<+>UTF-8 +Subsystem: com.intellij.openapi.diff.impl.patch.BaseRevisionTextPatchEP +<+>\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/modules.xml (date 1330610502000) ++++ .idea/modules.xml (revision ) +@@ -17,6 +17,7 @@ + + + ++ + + + +Index: js/js.translator/js.translator.iml +IDEA additional info: +Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP +<+>UTF-8 +Subsystem: com.intellij.openapi.diff.impl.patch.BaseRevisionTextPatchEP +<+>\n\n \n \n \n \n \n \n \n \n \n \n \n\n\n +=================================================================== +--- js/js.translator/js.translator.iml (date 1330610502000) ++++ js/js.translator/js.translator.iml (revision ) +@@ -10,6 +10,7 @@ + + + ++ + + +