pull https://github.com/develar/kotlin ecma5-iter3 Make most of the tests work.

Thanks to develar.
This commit is contained in:
Pavel V. Talanov
2012-07-03 15:27:37 +04:00
75 changed files with 7964 additions and 1165 deletions
@@ -22,6 +22,7 @@ import com.google.common.base.Predicates;
import com.google.common.collect.Iterables;
import com.intellij.openapi.Disposable;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.io.FileUtil;
import com.intellij.psi.PsiFile;
import jet.Function0;
import org.jetbrains.annotations.NotNull;
@@ -40,6 +41,7 @@ import org.jetbrains.k2js.config.*;
import org.jetbrains.k2js.facade.K2JSTranslator;
import org.jetbrains.k2js.facade.MainCallParameters;
import java.io.File;
import java.util.List;
import static org.jetbrains.jet.cli.common.messages.CompilerMessageLocation.NO_LOCATION;
@@ -63,21 +65,15 @@ public class K2JSCompiler extends CLICompiler<K2JSCompilerArguments, K2JSCompile
@NotNull
@Override
protected ExitCode doExecute(K2JSCompilerArguments arguments, PrintingMessageCollector messageCollector, Disposable rootDisposable) {
if (arguments.srcdir == null && arguments.sourceFiles == null) {
messageCollector.report(CompilerMessageSeverity.ERROR, "Specify sources location via -srcdir", NO_LOCATION);
if (arguments.sourceFiles == null) {
messageCollector.report(CompilerMessageSeverity.ERROR, "Specify sources location via -sourceFiles", NO_LOCATION);
return ExitCode.INTERNAL_ERROR;
}
JetCoreEnvironment environmentForJS = JetCoreEnvironment.getCoreEnvironmentForJS(rootDisposable);
if (arguments.srcdir != null) {
environmentForJS.addSources(arguments.srcdir);
}
if (arguments.sourceFiles != null) {
for (String sourceFile : arguments.sourceFiles) {
environmentForJS.addSources(sourceFile);
}
for (String sourceFile : arguments.sourceFiles) {
environmentForJS.addSources(sourceFile);
}
Project project = environmentForJS.getProject();
@@ -101,7 +97,6 @@ public class K2JSCompiler extends CLICompiler<K2JSCompilerArguments, K2JSCompile
return ExitCode.INTERNAL_ERROR;
}
MainCallParameters mainCallParameters = arguments.createMainCallParameters();
return translateAndGenerateOutputFile(mainCallParameters, messageCollector, environmentForJS, config, outputFile);
}
@@ -151,10 +146,11 @@ public class K2JSCompiler extends CLICompiler<K2JSCompilerArguments, K2JSCompile
@NotNull
private static Config getConfig(@NotNull K2JSCompilerArguments arguments, @NotNull Project project) {
EcmaVersion ecmaVersion = EcmaVersion.fromString(arguments.target);
if (arguments.libzip == null) {
String moduleId = FileUtil.getNameWithoutExtension(new File(arguments.outputFile));
if (arguments.libraryFiles == null) {
// lets discover the JS library definitions on the classpath
return new ClassPathLibraryDefintionsConfig(project, ecmaVersion);
return new ClassPathLibraryDefintionsConfig(project, moduleId, ecmaVersion);
}
return new ZippedLibrarySourcesConfig(project, arguments.libzip, ecmaVersion);
return new LibrarySourcesConfig(project, moduleId, arguments.libraryFiles, ecmaVersion);
}
}
@@ -17,30 +17,28 @@
package org.jetbrains.jet.cli.js;
import com.sampullara.cli.Argument;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.cli.common.CompilerArguments;
import org.jetbrains.k2js.facade.MainCallParameters;
import java.util.ArrayList;
import java.util.List;
/**
* @author Pavel Talanov
*/
/**
* NOTE: for now K2JSCompiler supports only minimal amount of parameters required to launch it from the plugin.
* You can specify only one source folder, path to the file where generated file will be stored, path to zipped library sources.
* You can specify path to the file where generated file will be stored, path to zipped library sources.
*/
public class K2JSCompilerArguments extends CompilerArguments {
@Argument(value = "output", description = "Output file path")
public String outputFile;
//NOTE: may well be a subject to change soon
@Argument(value = "libzip", description = "Path to zipped lib sources")
public String libzip;
@Argument(value = "libraryFiles", description = "Path to zipped lib sources or kotlin files")
public String[] libraryFiles;
@Argument(value = "srcdir", description = "Sources directory")
public String srcdir;
@Argument(value = "sourceFiles", description = "Source files (dir or file)")
public String[] sourceFiles;
@Argument(value = "target", description = "Generate js files for specific ECMA version (3 or 5, default ECMA 3)")
public String target;
@@ -54,14 +52,13 @@ public class K2JSCompilerArguments extends CompilerArguments {
@Argument(value = "version", description = "Display compiler version")
public boolean version;
@Argument(value = "mainCall", description = "Whether a main function should be invoked; either 'main' or 'mainWithArgs'")
public String mainCall;
@Nullable
@Argument(value = "main", description = "Whether a main function should be called; either 'call' or 'noCall', default 'call' (main function will be auto detected)")
public String main;
@Argument(value = "help", alias = "h", description = "Show help")
public boolean help;
public List<String> sourceFiles;
@Override
public boolean isHelp() {
return help;
@@ -84,22 +81,16 @@ public class K2JSCompilerArguments extends CompilerArguments {
@Override
public String getSrc() {
if (sourceFiles != null) {
return sourceFiles.toString();
}
return srcdir;
throw new IllegalStateException();
}
public MainCallParameters createMainCallParameters() {
if (mainCall != null) {
if (mainCall.equals("main")) {
return MainCallParameters.mainWithoutArguments();
}
if (mainCall.equals("mainWithArgs")) {
// TODO should we pass the arguments to the compiler?
return MainCallParameters.mainWithArguments(new ArrayList<String>());
}
if ("noCall".equals(main)) {
return MainCallParameters.noCall();
}
else {
// TODO should we pass the arguments to the compiler?
return MainCallParameters.mainWithoutArguments();
}
return MainCallParameters.noCall();
}
}