CLI: drop CompilerArguments and unnecessary methods from *CompilerArguments classes

This commit is contained in:
Zalim Bashorov
2013-10-15 17:56:06 +04:00
parent 5e0ef68d64
commit 31a4d91122
22 changed files with 67 additions and 229 deletions
@@ -16,13 +16,13 @@
package org.jetbrains.jet.cli.common.arguments;
import com.intellij.util.SmartList;
import com.sampullara.cli.Argument;
import java.util.List;
import static org.jetbrains.jet.cli.common.arguments.CommonArgumentConstants.SUPPRESS_WARNINGS;
public abstract class CommonCompilerArguments extends CompilerArguments {
public static final CommonCompilerArguments DUMMY = new DummyImpl();
public abstract class CommonCompilerArguments {
@Argument(value = "tags", description = "Demarcate each compilation message (error, warning, etc) with an open and close tag")
public boolean tags;
@Argument(value = "verbose", description = "Enable verbose logging output")
@@ -31,54 +31,17 @@ public abstract class CommonCompilerArguments extends CompilerArguments {
public boolean version;
@Argument(value = "help", alias = "h", description = "Show help")
public boolean help;
@Argument(value = "suppress", description = "Suppress compiler messages by severity (warnings)")
@Argument(value = "suppress", description = "Suppress compiler messages by severity (" + SUPPRESS_WARNINGS + ")")
public String suppress;
@Argument(value = "printArgs", description = "Print commandline arguments")
public boolean printArgs;
@Override
public boolean isHelp() {
return help;
}
public List<String> freeArgs = new SmartList<String>();
public void setHelp(boolean help) {
this.help = help;
}
@Override
public boolean isTags() {
return tags;
}
@Override
public boolean isVersion() {
return version;
}
@Override
public boolean isVerbose() {
return verbose;
}
@Override
public boolean isPrintArgs() {
return printArgs;
}
public void setTags(boolean tags) {
this.tags = tags;
}
@Override
public boolean suppressAllWarnings() {
return SUPPRESS_WARNINGS.equalsIgnoreCase(suppress);
}
// Used only for serialize and deserialize settings. Don't use in other places!
public static final class DummyImpl extends CommonCompilerArguments {
@Override
public String getSrc() {
return null;
}
}
public static final class DummyImpl extends CommonCompilerArguments {}
}
@@ -1,35 +0,0 @@
/*
* Copyright 2010-2013 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.cli.common.arguments;
import com.intellij.util.SmartList;
import java.util.List;
public abstract class CompilerArguments {
public List<String> freeArgs = new SmartList<String>();
public abstract boolean isHelp();
public abstract boolean isTags();
public abstract boolean isVersion();
public abstract boolean isVerbose();
public abstract boolean isPrintArgs();
public abstract String getSrc();
public abstract boolean suppressAllWarnings();
}
@@ -45,9 +45,4 @@ public class K2JSCompilerArguments extends CommonCompilerArguments {
@Argument(value = "main", description = "Whether a main function should be called; either '" + CALL +
"' or '" + NO_CALL + "', default '" + CALL + "' (main function will be auto detected)")
public String main;
@Override
public String getSrc() {
throw new IllegalStateException();
}
}
@@ -19,24 +19,11 @@ package org.jetbrains.jet.cli.common.arguments;
import com.sampullara.cli.Argument;
import java.util.List;
/**
* Command line arguments for the {@link K2JVMCompiler}
*/
@SuppressWarnings("UnusedDeclaration")
public class K2JVMCompilerArguments extends CommonCompilerArguments {
// TODO ideally we'd unify this with 'src' to just having a single field that supports multiple files/dirs
private List<String> sourceDirs;
public List<String> getSourceDirs() {
return sourceDirs;
}
public void setSourceDirs(List<String> sourceDirs) {
this.sourceDirs = sourceDirs;
}
@Argument(value = "jar", description = "jar file name")
public String jar;
@@ -78,65 +65,4 @@ public class K2JVMCompilerArguments extends CommonCompilerArguments {
@Argument(value = "kotlinHome", description = "Path to Kotlin compiler home directory, used for annotations and runtime libraries discovery")
public String kotlinHome;
public String getKotlinHome() {
return kotlinHome;
}
public void setKotlinHome(String kotlinHome) {
this.kotlinHome = kotlinHome;
}
public String getClasspath() {
return classpath;
}
public void setClasspath(String classpath) {
this.classpath = classpath;
}
public boolean isIncludeRuntime() {
return includeRuntime;
}
public void setIncludeRuntime(boolean includeRuntime) {
this.includeRuntime = includeRuntime;
}
public String getJar() {
return jar;
}
public void setJar(String jar) {
this.jar = jar;
}
public String getModule() {
return module;
}
public void setModule(String module) {
this.module = module;
}
public String getOutputDir() {
return outputDir;
}
public void setOutputDir(String outputDir) {
this.outputDir = outputDir;
}
@Override
public String getSrc() {
return src;
}
public void setSrc(String src) {
this.src = src;
}
public void setNoStdlib(boolean noStdlib) {
this.noStdlib = noStdlib;
}
}
@@ -24,7 +24,7 @@ import com.intellij.openapi.util.text.StringUtil;
import com.sampullara.cli.Args;
import com.sampullara.cli.ArgumentUtils;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.cli.common.arguments.CompilerArguments;
import org.jetbrains.jet.cli.common.arguments.CommonCompilerArguments;
import org.jetbrains.jet.cli.common.messages.*;
import org.jetbrains.jet.cli.jvm.compiler.CompileEnvironmentException;
import org.jetbrains.jet.config.CompilerConfiguration;
@@ -34,7 +34,7 @@ import java.util.List;
import static org.jetbrains.jet.cli.common.ExitCode.*;
public abstract class CLICompiler<A extends CompilerArguments> {
public abstract class CLICompiler<A extends CommonCompilerArguments> {
@NotNull
private List<CompilerPlugin> compilerPlugins = Lists.newArrayList();
@@ -112,7 +112,7 @@ public abstract class CLICompiler<A extends CompilerArguments> {
*/
@NotNull
public ExitCode exec(@NotNull PrintStream errStream, @NotNull A arguments) {
if (arguments.isHelp()) {
if (arguments.help) {
usage(errStream);
return OK;
}
@@ -123,7 +123,7 @@ public abstract class CLICompiler<A extends CompilerArguments> {
printArgumentsIfNeeded(errStream, arguments, messageRenderer);
printVersionIfNeeded(errStream, arguments, messageRenderer);
MessageCollector collector = new PrintingMessageCollector(errStream, messageRenderer, arguments.isVerbose());
MessageCollector collector = new PrintingMessageCollector(errStream, messageRenderer, arguments.verbose);
if (arguments.suppressAllWarnings()) {
collector = new FilteringMessageCollector(collector, Predicates.equalTo(CompilerMessageSeverity.WARNING));
@@ -167,7 +167,7 @@ public abstract class CLICompiler<A extends CompilerArguments> {
//TODO: can we make it private?
@NotNull
protected MessageRenderer getMessageRenderer(@NotNull A arguments) {
return arguments.isTags() ? MessageRenderer.TAGS : MessageRenderer.PLAIN;
return arguments.tags ? MessageRenderer.TAGS : MessageRenderer.PLAIN;
}
protected void printVersionIfNeeded(
@@ -175,7 +175,7 @@ public abstract class CLICompiler<A extends CompilerArguments> {
@NotNull A arguments,
@NotNull MessageRenderer messageRenderer
) {
if (arguments.isVersion()) {
if (arguments.version) {
String versionMessage = messageRenderer.render(CompilerMessageSeverity.INFO,
"Kotlin Compiler version " + KotlinVersion.VERSION,
CompilerMessageLocation.NO_LOCATION);
@@ -188,7 +188,7 @@ public abstract class CLICompiler<A extends CompilerArguments> {
@NotNull A arguments,
@NotNull MessageRenderer messageRenderer
) {
if (arguments.isPrintArgs()) {
if (arguments.printArgs) {
String freeArgs = StringUtil.join(arguments.freeArgs, "");
String argumentsAsString = ArgumentUtils.convertArgumentsToString(arguments, createArguments());
String printArgsMessage = messageRenderer.render(CompilerMessageSeverity.INFO,
@@ -89,7 +89,7 @@ public class K2JSCompiler extends CLICompiler<K2JSCompilerArguments> {
List<JetFile> sourceFiles = sourceLoader.findSourceFiles();
environmentForJS.getSourceFiles().addAll(sourceFiles);
if (arguments.isVerbose()) {
if (arguments.verbose) {
reportCompiledSourcesList(messageCollector, environmentForJS);
}
@@ -77,13 +77,11 @@ public class K2JVMCompiler extends CLICompiler<K2JVMCompilerArguments> {
return INTERNAL_ERROR;
}
List<String> argumentsSourceDirs = arguments.getSourceDirs();
if (!arguments.script &&
arguments.module == null &&
arguments.src == null &&
arguments.freeArgs.isEmpty() &&
(argumentsSourceDirs == null || argumentsSourceDirs.size() == 0)) {
arguments.freeArgs.isEmpty()
) {
ReplFromTerminal.run(rootDisposable, configuration);
return ExitCode.OK;
}
@@ -93,21 +91,13 @@ public class K2JVMCompiler extends CLICompiler<K2JVMCompilerArguments> {
configuration.add(CommonConfigurationKeys.SOURCE_ROOTS_KEY, arguments.freeArgs.get(0));
}
else {
// TODO ideally we'd unify to just having a single field that supports multiple files/dirs
if (arguments.getSourceDirs() != null) {
for (String source : arguments.getSourceDirs()) {
configuration.add(CommonConfigurationKeys.SOURCE_ROOTS_KEY, source);
}
if (arguments.src != null) {
List<String> sourcePathsSplitByPathSeparator
= Arrays.asList(arguments.src.split(StringUtil.escapeToRegexp(File.pathSeparator)));
configuration.addAll(CommonConfigurationKeys.SOURCE_ROOTS_KEY, sourcePathsSplitByPathSeparator);
}
else {
if (arguments.src != null) {
List<String> sourcePathsSplitByPathSeparator
= Arrays.asList(arguments.src.split(StringUtil.escapeToRegexp(File.pathSeparator)));
configuration.addAll(CommonConfigurationKeys.SOURCE_ROOTS_KEY, sourcePathsSplitByPathSeparator);
}
for (String freeArg : arguments.freeArgs) {
configuration.add(CommonConfigurationKeys.SOURCE_ROOTS_KEY, freeArg);
}
for (String freeArg : arguments.freeArgs) {
configuration.add(CommonConfigurationKeys.SOURCE_ROOTS_KEY, freeArg);
}
}