From 845de7aa4d1c18cdcafe858c58af6f9c346f8afc Mon Sep 17 00:00:00 2001 From: Alexander Udalov Date: Tue, 25 Jul 2017 15:40:30 +0300 Subject: [PATCH] Minor, change parameter type of parseCommandLineArguments --- .../cli/common/arguments/parseCommandLineArguments.kt | 3 +-- .../cli/src/org/jetbrains/kotlin/cli/common/CLITool.kt | 4 ++-- .../org/jetbrains/kotlin/daemon/CompileServiceImpl.kt | 2 +- .../jetbrains/kotlin/idea/maven/KotlinMavenImporter.kt | 4 ++-- .../kotlin/idea/facet/KotlinFacetEditorGeneralTab.kt | 9 +++++---- idea/src/org/jetbrains/kotlin/idea/facet/facetUtils.kt | 6 ++---- 6 files changed, 13 insertions(+), 15 deletions(-) diff --git a/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/parseCommandLineArguments.kt b/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/parseCommandLineArguments.kt index 374c9dedc1b..b7a65526bce 100644 --- a/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/parseCommandLineArguments.kt +++ b/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/parseCommandLineArguments.kt @@ -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 parseCommandLineArguments(args: Array, result: A) { +fun parseCommandLineArguments(args: List, result: A) { data class ArgumentField(val field: Field, val argument: Argument) val fields = result::class.java.fields.mapNotNull { field -> diff --git a/compiler/cli/src/org/jetbrains/kotlin/cli/common/CLITool.kt b/compiler/cli/src/org/jetbrains/kotlin/cli/common/CLITool.kt index aa7139260d7..d307775d9f9 100644 --- a/compiler/cli/src/org/jetbrains/kotlin/cli/common/CLITool.kt +++ b/compiler/cli/src/org/jetbrains/kotlin/cli/common/CLITool.kt @@ -45,7 +45,7 @@ abstract class CLITool { 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 { // Used in kotlin-maven-plugin (KotlinCompileMojoBase) and in kotlin-gradle-plugin (KotlinJvmOptionsImpl, KotlinJsOptionsImpl) fun parseArguments(args: Array, arguments: A) { - parseCommandLineArguments(args, arguments) + parseCommandLineArguments(args.asList(), arguments) val message = validateArguments(arguments.errors) if (message != null) { throw IllegalArgumentException(message) diff --git a/compiler/daemon/src/org/jetbrains/kotlin/daemon/CompileServiceImpl.kt b/compiler/daemon/src/org/jetbrains/kotlin/daemon/CompileServiceImpl.kt index b30d8d0ef01..f0b3c83871e 100644 --- a/compiler/daemon/src/org/jetbrains/kotlin/daemon/CompileServiceImpl.kt +++ b/compiler/daemon/src/org/jetbrains/kotlin/daemon/CompileServiceImpl.kt @@ -366,7 +366,7 @@ class CompileServiceImpl( } as CLICompiler val k2PlatformArgs = compiler.createArguments() - parseCommandLineArguments(compilerArguments, k2PlatformArgs) + parseCommandLineArguments(compilerArguments.asList(), k2PlatformArgs) val argumentParseError = validateArguments(k2PlatformArgs.errors) if (argumentParseError != null) { messageCollector.report(CompilerMessageSeverity.ERROR, argumentParseError) diff --git a/idea/idea-maven/src/org/jetbrains/kotlin/idea/maven/KotlinMavenImporter.kt b/idea/idea-maven/src/org/jetbrains/kotlin/idea/maven/KotlinMavenImporter.kt index 38763467ced..0e8d175adba 100644 --- a/idea/idea-maven/src/org/jetbrains/kotlin/idea/maven/KotlinMavenImporter.kt +++ b/idea/idea-maven/src/org/jetbrains/kotlin/idea/maven/KotlinMavenImporter.kt @@ -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) } diff --git a/idea/src/org/jetbrains/kotlin/idea/facet/KotlinFacetEditorGeneralTab.kt b/idea/src/org/jetbrains/kotlin/idea/facet/KotlinFacetEditorGeneralTab.kt index c31e48f1131..111a04865f4 100644 --- a/idea/src/org/jetbrains/kotlin/idea/facet/KotlinFacetEditorGeneralTab.kt +++ b/idea/src/org/jetbrains/kotlin/idea/facet/KotlinFacetEditorGeneralTab.kt @@ -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() diff --git a/idea/src/org/jetbrains/kotlin/idea/facet/facetUtils.kt b/idea/src/org/jetbrains/kotlin/idea/facet/facetUtils.kt index 4071a4674a5..099ff4bd454 100644 --- a/idea/src/org/jetbrains/kotlin/idea/facet/facetUtils.kt +++ b/idea/src/org/jetbrains/kotlin/idea/facet/facetUtils.kt @@ -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()