@@ -25,11 +25,11 @@ import com.intellij.openapi.roots.ModuleRootManager
25
25
import com.intellij.openapi.roots.ModuleRootModel
26
26
import com.intellij.openapi.roots.OrderRootType
27
27
import com.intellij.util.text.VersionComparatorUtil
28
- import org.jetbrains.kotlin.cli.common.arguments.K2JVMCompilerArguments
29
- import org.jetbrains.kotlin.cli.common.arguments.copyBean
30
- import org.jetbrains.kotlin.cli.common.arguments.parseArguments
28
+ import org.jetbrains.kotlin.cli.common.arguments.*
29
+ import org.jetbrains.kotlin.compilerRunner.ArgumentUtils
31
30
import org.jetbrains.kotlin.config.*
32
31
import org.jetbrains.kotlin.idea.compiler.configuration.Kotlin2JsCompilerArgumentsHolder
32
+ import org.jetbrains.kotlin.idea.compiler.configuration.Kotlin2JvmCompilerArgumentsHolder
33
33
import org.jetbrains.kotlin.idea.compiler.configuration.KotlinCommonCompilerArgumentsHolder
34
34
import org.jetbrains.kotlin.idea.compiler.configuration.KotlinCompilerSettings
35
35
import org.jetbrains.kotlin.idea.framework.JSLibraryStdPresentationProvider
@@ -139,6 +139,10 @@ fun KotlinFacetSettings.initializeIfNeeded(module: Module, rootModel: ModuleRoot
139
139
if (k2jsCompilerArguments == null ) {
140
140
k2jsCompilerArguments = copyBean(Kotlin2JsCompilerArgumentsHolder .getInstance(project).settings)
141
141
}
142
+
143
+ if (k2jvmCompilerArguments == null ) {
144
+ k2jvmCompilerArguments = copyBean(Kotlin2JvmCompilerArgumentsHolder .getInstance(project).settings)
145
+ }
142
146
}
143
147
}
144
148
@@ -181,38 +185,80 @@ fun KotlinFacet.configureFacet(
181
185
}
182
186
}
183
187
188
+ // Update these lists when facet/project settings UI changes
189
+ private val commonExposedFields = listOf (" languageVersion" ,
190
+ " apiVersion" ,
191
+ " suppressWarnings" ,
192
+ " coroutinesEnable" ,
193
+ " coroutinesWarn" ,
194
+ " coroutinesError" )
195
+ private val jvmExposedFields = commonExposedFields +
196
+ listOf (" jvmTarget" )
197
+ private val jsExposedFields = commonExposedFields +
198
+ listOf (" sourceMap" ,
199
+ " outputPrefix" ,
200
+ " outputPostfix" ,
201
+ " moduleKind" )
202
+
203
+ private val CommonCompilerArguments .exposedFields: List <String >
204
+ get() = when (this ) {
205
+ is K2JVMCompilerArguments -> jvmExposedFields
206
+ is K2JSCompilerArguments -> jsExposedFields
207
+ else -> commonExposedFields
208
+ }
209
+
184
210
fun parseCompilerArgumentsToFacet (arguments : List <String >, kotlinFacet : KotlinFacet ) {
185
211
val argumentArray = arguments.toTypedArray()
212
+
186
213
with (kotlinFacet.configuration.settings) {
187
214
// todo: merge common arguments with platform-specific ones in facet settings
188
- compilerInfo.commonCompilerArguments!! .let { commonCompilerArguments ->
189
- val oldCoroutineSupport = CoroutineSupport .byCompilerArguments(commonCompilerArguments)
190
- commonCompilerArguments.coroutinesEnable = false
191
- commonCompilerArguments.coroutinesWarn = false
192
- commonCompilerArguments.coroutinesError = false
193
-
194
- parseArguments(argumentArray, commonCompilerArguments, ignoreInvalidArguments = true )
195
- if (! commonCompilerArguments.coroutinesEnable && ! commonCompilerArguments.coroutinesWarn && ! commonCompilerArguments.coroutinesError) {
196
- compilerInfo.coroutineSupport = oldCoroutineSupport
197
- }
198
215
199
- versionInfo.apiLevel = LanguageVersion .fromVersionString(commonCompilerArguments.apiVersion)
200
- versionInfo.languageLevel = LanguageVersion .fromVersionString(commonCompilerArguments.languageVersion)
216
+ val commonCompilerArguments = compilerInfo.commonCompilerArguments!!
217
+ val compilerArguments = when (versionInfo.targetPlatformKind) {
218
+ is TargetPlatformKind .Jvm -> compilerInfo.k2jvmCompilerArguments
219
+ is TargetPlatformKind .JavaScript -> compilerInfo.k2jsCompilerArguments
220
+ else -> commonCompilerArguments
221
+ }!!
222
+
223
+ val oldCoroutineSupport = CoroutineSupport .byCompilerArguments(commonCompilerArguments)
224
+ commonCompilerArguments.coroutinesEnable = false
225
+ commonCompilerArguments.coroutinesWarn = false
226
+ commonCompilerArguments.coroutinesError = false
227
+
228
+ parseArguments(argumentArray, compilerArguments, true )
229
+
230
+ if (! compilerArguments.coroutinesEnable && ! compilerArguments.coroutinesWarn && ! compilerArguments.coroutinesError) {
231
+ compilerInfo.coroutineSupport = oldCoroutineSupport
201
232
}
202
233
203
- when (versionInfo.targetPlatformKind) {
204
- is TargetPlatformKind .Jvm -> {
205
- val jvmTarget = K2JVMCompilerArguments ().apply { parseArguments(argumentArray, this , ignoreInvalidArguments = true ) }.jvmTarget
206
- if (jvmTarget != null ) {
207
- versionInfo.targetPlatformKind = TargetPlatformKind .Jvm .JVM_PLATFORMS .firstOrNull {
208
- VersionComparatorUtil .compare(it.version.description, jvmTarget) >= 0
209
- } ? : TargetPlatformKind .Jvm .JVM_PLATFORMS .last()
210
- }
234
+ versionInfo.apiLevel = LanguageVersion .fromVersionString(compilerArguments.apiVersion)
235
+ versionInfo.languageLevel = LanguageVersion .fromVersionString(compilerArguments.languageVersion)
236
+
237
+ if (versionInfo.targetPlatformKind is TargetPlatformKind .Jvm ) {
238
+ val jvmTarget = compilerInfo.k2jvmCompilerArguments!! .jvmTarget
239
+ if (jvmTarget != null ) {
240
+ versionInfo.targetPlatformKind = TargetPlatformKind .Jvm .JVM_PLATFORMS .firstOrNull {
241
+ VersionComparatorUtil .compare(it.version.description, jvmTarget) >= 0
242
+ } ? : TargetPlatformKind .Jvm .JVM_PLATFORMS .last()
211
243
}
212
- is TargetPlatformKind .JavaScript -> parseArguments(argumentArray, compilerInfo.k2jsCompilerArguments!! , ignoreInvalidArguments = true )
213
- else -> {}
214
244
}
215
245
216
- compilerInfo.compilerSettings!! .additionalArguments = compilerInfo.commonCompilerArguments!! .freeArgs.joinToString(separator = " " )
246
+ // Retain only fields exposed in facet configuration editor.
247
+ // The rest is combined into string and stored in CompilerSettings.additionalArguments
248
+
249
+ val exposedFields = compilerArguments.exposedFields
250
+
251
+ val additionalArgumentsString = with (compilerArguments.javaClass.newInstance()) {
252
+ copyFieldsSatisfying(compilerArguments, this ) { it.name !in exposedFields }
253
+ ArgumentUtils .convertArgumentsToStringList(this ).joinToString(separator = " " )
254
+ }
255
+ compilerInfo.compilerSettings!! .additionalArguments =
256
+ if (additionalArgumentsString.isNotEmpty()) additionalArgumentsString else CompilerSettings .DEFAULT_ADDITIONAL_ARGUMENTS
257
+
258
+ with (compilerArguments.javaClass.newInstance()) {
259
+ copyFieldsSatisfying(this , compilerArguments) { it.name !in exposedFields }
260
+ }
261
+
262
+ copyInheritedFields(compilerArguments, commonCompilerArguments)
217
263
}
218
264
}
0 commit comments