Minor, change parameter type of parseCommandLineArguments

This commit is contained in:
Alexander Udalov
2017-07-25 15:40:30 +03:00
parent 593f98190d
commit 845de7aa4d
6 changed files with 13 additions and 15 deletions
@@ -18,7 +18,6 @@ package org.jetbrains.kotlin.cli.common.arguments
import com.intellij.util.SmartList
import java.lang.reflect.Field
import java.util.*
annotation class Argument(
val value: String,
@@ -54,7 +53,7 @@ data class ArgumentParseErrors(
)
// Parses arguments into the passed [result] object. Errors related to the parsing will be collected into [CommonToolArguments.errors].
fun <A : CommonToolArguments> parseCommandLineArguments(args: Array<out String>, result: A) {
fun <A : CommonToolArguments> parseCommandLineArguments(args: List<String>, result: A) {
data class ArgumentField(val field: Field, val argument: Argument)
val fields = result::class.java.fields.mapNotNull { field ->
@@ -45,7 +45,7 @@ abstract class CLITool<A : CommonToolArguments> {
K2JVMCompiler.resetInitStartTime()
val arguments = createArguments()
parseCommandLineArguments(args, arguments)
parseCommandLineArguments(args.asList(), arguments)
val collector = PrintingMessageCollector(errStream, messageRenderer, arguments.verbose)
try {
@@ -99,7 +99,7 @@ abstract class CLITool<A : CommonToolArguments> {
// Used in kotlin-maven-plugin (KotlinCompileMojoBase) and in kotlin-gradle-plugin (KotlinJvmOptionsImpl, KotlinJsOptionsImpl)
fun parseArguments(args: Array<out String>, arguments: A) {
parseCommandLineArguments(args, arguments)
parseCommandLineArguments(args.asList(), arguments)
val message = validateArguments(arguments.errors)
if (message != null) {
throw IllegalArgumentException(message)
@@ -366,7 +366,7 @@ class CompileServiceImpl(
} as CLICompiler<CommonCompilerArguments>
val k2PlatformArgs = compiler.createArguments()
parseCommandLineArguments(compilerArguments, k2PlatformArgs)
parseCommandLineArguments(compilerArguments.asList(), k2PlatformArgs)
val argumentParseError = validateArguments(k2PlatformArgs.errors)
if (argumentParseError != null) {
messageCollector.report(CompilerMessageSeverity.ERROR, argumentParseError)
@@ -159,8 +159,8 @@ class KotlinMavenImporter : MavenImporter(KOTLIN_PLUGIN_GROUP_ID, KOTLIN_PLUGIN_
}
}
val additionalArgs = configuration?.getChild("args")?.getChildren("arg")?.mapNotNull { it.text } ?: emptyList()
parseCommandLineArguments(additionalArgs.toTypedArray(), arguments)
val additionalArgs = configuration?.getChild("args")?.getChildren("arg")?.mapNotNull { it.text }.orEmpty()
parseCommandLineArguments(additionalArgs, arguments)
return ArgumentUtils.convertArgumentsToStringList(arguments)
}
@@ -26,7 +26,10 @@ import com.intellij.ui.HoverHyperlinkLabel
import com.intellij.util.ui.FormBuilder
import com.intellij.util.ui.ThreeStateCheckBox
import org.jetbrains.kotlin.cli.common.arguments.*
import org.jetbrains.kotlin.config.*
import org.jetbrains.kotlin.config.CompilerSettings
import org.jetbrains.kotlin.config.TargetPlatformKind
import org.jetbrains.kotlin.config.createCompilerArguments
import org.jetbrains.kotlin.config.splitArgumentString
import org.jetbrains.kotlin.idea.compiler.configuration.*
import org.jetbrains.kotlin.utils.addToStdlib.firstIsInstanceOrNull
import java.awt.BorderLayout
@@ -160,9 +163,7 @@ class KotlinFacetEditorGeneralTab(
}
val argumentClass = primaryArguments.javaClass
val additionalArguments = argumentClass.newInstance().apply {
parseCommandLineArguments(
splitArgumentString(editor.compilerConfigurable.additionalArgsOptionsField.text).toTypedArray(), this
)
parseCommandLineArguments(splitArgumentString(editor.compilerConfigurable.additionalArgsOptionsField.text), this)
validateArguments(errors)?.let { message -> return ValidationResult(message) }
}
val emptyArguments = argumentClass.newInstance()
@@ -200,16 +200,14 @@ fun parseCompilerArgumentsToFacet(
kotlinFacet: KotlinFacet,
modelsProvider: IdeModifiableModelsProvider
) {
val argumentArray = arguments.toTypedArray()
with(kotlinFacet.configuration.settings) {
val compilerArguments = this.compilerArguments ?: return
val defaultCompilerArguments = compilerArguments::class.java.newInstance()
parseCommandLineArguments(defaultArguments.toTypedArray(), defaultCompilerArguments)
parseCommandLineArguments(defaultArguments, defaultCompilerArguments)
defaultCompilerArguments.convertPathsToSystemIndependent()
parseCommandLineArguments(argumentArray, compilerArguments)
parseCommandLineArguments(arguments, compilerArguments)
compilerArguments.convertPathsToSystemIndependent()