diff --git a/idea/src/org/jetbrains/jet/plugin/actions/TranslateToJsAction.java b/idea/src/org/jetbrains/jet/plugin/actions/TranslateToJsAction.java index f8d226707fc..3d2dbb1a609 100644 --- a/idea/src/org/jetbrains/jet/plugin/actions/TranslateToJsAction.java +++ b/idea/src/org/jetbrains/jet/plugin/actions/TranslateToJsAction.java @@ -25,7 +25,6 @@ import com.intellij.openapi.actionSystem.AnAction; import com.intellij.openapi.actionSystem.AnActionEvent; import com.intellij.openapi.actionSystem.PlatformDataKeys; import com.intellij.openapi.application.ApplicationManager; -import com.intellij.openapi.editor.Editor; import com.intellij.openapi.module.Module; import com.intellij.openapi.module.ModuleManager; import com.intellij.openapi.project.Project; @@ -52,7 +51,7 @@ import static org.jetbrains.jet.plugin.actions.JavaToKotlinActionUtil.allVirtual */ public final class TranslateToJsAction extends AnAction { - private static void notifyFailure(@NotNull Throwable exception) { + public static void notifyFailure(@NotNull Throwable exception) { Notifications.Bus.notify(new Notification("JsTranslator", "Translation failed.", "Exception: " + exception.getMessage(), NotificationType.ERROR)); @@ -70,7 +69,8 @@ public final class TranslateToJsAction extends AnAction { public void run() { try { performAction(event); - } catch (Throwable e) { + } + catch (Throwable e) { e.printStackTrace(); notifyFailure(e); } @@ -82,6 +82,10 @@ public final class TranslateToJsAction extends AnAction { private static void performAction(@NotNull AnActionEvent event) throws Exception { final Project project = PlatformDataKeys.PROJECT.getData(event.getDataContext()); assert project != null; + doPerform(project); + } + + public static void doPerform(@NotNull Project project) throws Exception { Set allVirtualFiles = getAllProjectVirtualFiles(project); List kotlinFiles = getJetFiles(allVirtualFiles, project); String outputPath = getOutputPath(JetMainDetector.getFileWithMain(kotlinFiles)); @@ -111,7 +115,7 @@ public final class TranslateToJsAction extends AnAction { for (VirtualFile virtualFile : virtualFiles) { PsiFile psiFile = psiManager.findFile(virtualFile); if (psiFile instanceof JetFile) { - kotlinFiles.add((JetFile) psiFile); + kotlinFiles.add((JetFile)psiFile); } } return kotlinFiles; @@ -129,13 +133,13 @@ public final class TranslateToJsAction extends AnAction { //TODO: make platform independent String pathToDir = originalFilePath.substring(0, originalFilePath.lastIndexOf("/") + 1); - String generatedFileName = ((JetFile) psiFile).getNamespaceHeader().getName() + ".js"; + String generatedFileName = ((JetFile)psiFile).getNamespaceHeader().getName() + ".js"; return pathToDir + generatedFileName; } @Override public void update(AnActionEvent e) { - Editor editor = e.getData(PlatformDataKeys.EDITOR); - e.getPresentation().setEnabled(editor != null); + // Editor editor = e.getData(PlatformDataKeys.EDITOR); + // e.getPresentation().setEnabled(editor != null); } } diff --git a/idea/src/org/jetbrains/jet/plugin/k2jsrun/K2JSBrowserProgramRunner.java b/idea/src/org/jetbrains/jet/plugin/k2jsrun/K2JSBrowserProgramRunner.java new file mode 100644 index 00000000000..71eb3b2344a --- /dev/null +++ b/idea/src/org/jetbrains/jet/plugin/k2jsrun/K2JSBrowserProgramRunner.java @@ -0,0 +1,86 @@ +/* + * Copyright 2010-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.k2jsrun; + +import com.intellij.execution.ExecutionException; +import com.intellij.execution.Executor; +import com.intellij.execution.configurations.RunProfile; +import com.intellij.execution.configurations.RunProfileState; +import com.intellij.execution.runners.ExecutionEnvironment; +import com.intellij.execution.runners.GenericProgramRunner; +import com.intellij.execution.ui.RunContentDescriptor; +import com.intellij.ide.browsers.BrowsersConfiguration; +import com.intellij.openapi.project.Project; +import com.intellij.openapi.vfs.LocalFileSystem; +import com.intellij.openapi.vfs.VirtualFileManager; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.jet.plugin.actions.TranslateToJsAction; + +/** + * @author Pavel Talanov + */ +public final class K2JSBrowserProgramRunner extends GenericProgramRunner { + @Override + protected RunContentDescriptor doExecute(Project project, + Executor executor, + RunProfileState state, + RunContentDescriptor contentToReuse, + ExecutionEnvironment env) throws ExecutionException { + if (project == null) { + return null; + } + try { + K2JSConfigurationSettings configurationSettings = getSettings(state); + try { + TranslateToJsAction.doPerform(project); + } + catch (Throwable e) { + TranslateToJsAction.notifyFailure(e); + return null; + } + openBrowser(configurationSettings); + } + catch (Exception e) { + throw new ExecutionException(e); + } + return null; + } + + private static void openBrowser(@NotNull K2JSConfigurationSettings configurationSettings) { + String filePath = configurationSettings.getFilePath(); + String url = VirtualFileManager.constructUrl(LocalFileSystem.PROTOCOL, filePath); + BrowsersConfiguration.launchBrowser(BrowsersConfiguration.BrowserFamily.FIREFOX, url); + } + + @NotNull + private static K2JSConfigurationSettings getSettings(@NotNull RunProfileState state) { + RunProfile profile = state.getRunnerSettings().getRunProfile(); + assert profile instanceof K2JSRunConfiguration; + return ((K2JSRunConfiguration)profile).settings(); + } + + @NotNull + @Override + public String getRunnerId() { + return "K2JSBrowserRunner"; + } + + @Override + public boolean canRun(@NotNull String executorId, @NotNull RunProfile profile) { + return (profile instanceof K2JSRunConfiguration); + } +} diff --git a/idea/src/org/jetbrains/jet/plugin/k2jsrun/K2JSConfigurationSettings.java b/idea/src/org/jetbrains/jet/plugin/k2jsrun/K2JSConfigurationSettings.java new file mode 100644 index 00000000000..be6d3563326 --- /dev/null +++ b/idea/src/org/jetbrains/jet/plugin/k2jsrun/K2JSConfigurationSettings.java @@ -0,0 +1,37 @@ +/* + * Copyright 2010-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.k2jsrun; + +import org.jetbrains.annotations.NotNull; + +/** + * @author Pavel Talanov + */ +public class K2JSConfigurationSettings { + + @NotNull + private String filePath = ""; + + @NotNull + public String getFilePath() { + return filePath; + } + + public void setFilePath(@NotNull String filePath) { + this.filePath = filePath; + } +} diff --git a/idea/src/org/jetbrains/jet/plugin/k2jsrun/K2JSRunConfigurationEditor.form b/idea/src/org/jetbrains/jet/plugin/k2jsrun/K2JSRunConfigurationEditor.form new file mode 100644 index 00000000000..b28f0ab4ae9 --- /dev/null +++ b/idea/src/org/jetbrains/jet/plugin/k2jsrun/K2JSRunConfigurationEditor.form @@ -0,0 +1,63 @@ + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
diff --git a/idea/src/org/jetbrains/jet/plugin/k2jsrun/K2JSRunConfigurationEditor.java b/idea/src/org/jetbrains/jet/plugin/k2jsrun/K2JSRunConfigurationEditor.java new file mode 100644 index 00000000000..829746cd84f --- /dev/null +++ b/idea/src/org/jetbrains/jet/plugin/k2jsrun/K2JSRunConfigurationEditor.java @@ -0,0 +1,69 @@ +/* + * Copyright 2010-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.k2jsrun; + +import com.intellij.openapi.fileChooser.FileChooserDescriptor; +import com.intellij.openapi.fileChooser.FileChooserDescriptorFactory; +import com.intellij.openapi.fileTypes.StdFileTypes; +import com.intellij.openapi.options.ConfigurationException; +import com.intellij.openapi.options.SettingsEditor; +import com.intellij.openapi.project.Project; +import com.intellij.openapi.roots.ProjectRootManager; +import com.intellij.openapi.ui.TextFieldWithBrowseButton; +import com.intellij.openapi.util.io.FileUtil; +import org.jetbrains.annotations.NotNull; + +import javax.swing.*; + +/** + * @author Pavel Talanov + */ +public final class K2JSRunConfigurationEditor extends SettingsEditor { + + private JPanel mainPanel; + private TextFieldWithBrowseButton chooseFile; + @NotNull + private final Project project; + + public K2JSRunConfigurationEditor(@NotNull Project project) { + this.project = project; + } + + @Override + protected void resetEditorFrom(K2JSRunConfiguration configuration) { + chooseFile.setText(configuration.settings().getFilePath()); + } + + @Override + protected void applyEditorTo(@NotNull K2JSRunConfiguration configuration) throws ConfigurationException { + configuration.settings().setFilePath(FileUtil.toSystemIndependentName(chooseFile.getText())); + } + + @NotNull + @Override + protected JComponent createEditor() { + FileChooserDescriptor fileChooserDescriptor = FileChooserDescriptorFactory.createSingleFileDescriptor(StdFileTypes.HTML); + fileChooserDescriptor.setRoots(ProjectRootManager.getInstance(project).getContentRootUrls()); + chooseFile.addBrowseFolderListener("Choose file", "Yeah!", project, fileChooserDescriptor); + return mainPanel; + } + + @Override + protected void disposeEditor() { + // do nothing + } +} diff --git a/idea/src/org/jetbrains/jet/plugin/k2jsrun/K2JsRunConfigurationType.java b/idea/src/org/jetbrains/jet/plugin/k2jsrun/K2JsRunConfigurationType.java new file mode 100644 index 00000000000..c882aa85220 --- /dev/null +++ b/idea/src/org/jetbrains/jet/plugin/k2jsrun/K2JsRunConfigurationType.java @@ -0,0 +1,46 @@ +/* + * Copyright 2010-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.k2jsrun; + +import com.intellij.execution.configurations.*; +import com.intellij.openapi.project.Project; +import org.jetbrains.jet.plugin.JetFileType; + +/** + * @author Pavel Talanov + */ +public final class K2JSRunConfigurationType extends ConfigurationTypeBase { + public static K2JSRunConfigurationType getInstance() { + return ConfigurationTypeUtil.findConfigurationType(K2JSRunConfigurationType.class); + } + + public K2JSRunConfigurationType() { + super("K2JSConfigurationType", "K2JS", "Kotlin to Javascript", JetFileType.INSTANCE.getIcon()); + addFactory(new K2JSConfigurationFactory()); + } + + private class K2JSConfigurationFactory extends ConfigurationFactory { + protected K2JSConfigurationFactory() { + super(K2JSRunConfigurationType.this); + } + + @Override + public RunConfiguration createTemplateConfiguration(Project project) { + return new K2JSRunConfiguration("", new RunConfigurationModule(project), this); + } + } +} \ No newline at end of file diff --git a/js/js.translator/src/org/jetbrains/k2js/translate/reference/QualifiedExpressionTranslator.java b/js/js.translator/src/org/jetbrains/k2js/translate/reference/QualifiedExpressionTranslator.java index a4d4e4972b5..7ac80ccb0a3 100644 --- a/js/js.translator/src/org/jetbrains/k2js/translate/reference/QualifiedExpressionTranslator.java +++ b/js/js.translator/src/org/jetbrains/k2js/translate/reference/QualifiedExpressionTranslator.java @@ -40,7 +40,6 @@ public final class QualifiedExpressionTranslator { @NotNull public static AccessTranslator getAccessTranslator(@NotNull JetQualifiedExpression expression, @NotNull TranslationContext context) { - JsExpression receiver = translateReceiver(expression, context); PropertyAccessTranslator result = PropertyAccessTranslator.newInstance(getNotNullSimpleNameSelector(expression), receiver,