From e0de8676001b4847cc178428cfefae50af0755ff Mon Sep 17 00:00:00 2001 From: Dmitry Gridin Date: Fri, 13 Dec 2019 22:11:25 +0700 Subject: [PATCH] idea: cleanup code Original commit: 8dbbd64beb05f8da6d99b3fd7e51e59a0672a5d7 --- .../kotlin/config/KotlinFacetSettings.kt | 22 +++-------- .../kotlin/config/facetSerialization.kt | 38 ++++++------------- .../moduleSourceRootPropertiesSerializers.kt | 19 +++++----- .../kotlin/platform/IdePlatformKind.kt | 8 ++-- .../platform/impl/JvmIdePlatformKind.kt | 6 ++- 5 files changed, 35 insertions(+), 58 deletions(-) diff --git a/jps/jps-common/src/org/jetbrains/kotlin/config/KotlinFacetSettings.kt b/jps/jps-common/src/org/jetbrains/kotlin/config/KotlinFacetSettings.kt index a6264e0c63a..24f6f2eb465 100644 --- a/jps/jps-common/src/org/jetbrains/kotlin/config/KotlinFacetSettings.kt +++ b/jps/jps-common/src/org/jetbrains/kotlin/config/KotlinFacetSettings.kt @@ -1,17 +1,6 @@ /* - * Copyright 2010-2016 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. + * Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ package org.jetbrains.kotlin.config @@ -58,7 +47,7 @@ sealed class TargetPlatformKind( object CoroutineSupport { @JvmStatic fun byCompilerArguments(arguments: CommonCompilerArguments?): LanguageFeature.State = - byCompilerArgumentsOrNull(arguments) ?: LanguageFeature.Coroutines.defaultState + byCompilerArgumentsOrNull(arguments) ?: LanguageFeature.Coroutines.defaultState fun byCompilerArgumentsOrNull(arguments: CommonCompilerArguments?): LanguageFeature.State? = when (arguments?.coroutinesState) { CommonCompilerArguments.ENABLE -> LanguageFeature.State.ENABLED @@ -68,7 +57,7 @@ object CoroutineSupport { } fun byCompilerArgument(argument: String): LanguageFeature.State = - LanguageFeature.State.values().find { getCompilerArgument(it).equals(argument, ignoreCase = true) } + LanguageFeature.State.values().find { getCompilerArgument(it).equals(argument, ignoreCase = true) } ?: LanguageFeature.Coroutines.defaultState fun getCompilerArgument(state: LanguageFeature.State): String = when (state) { @@ -191,8 +180,7 @@ class KotlinFacetSettings { parseCommandLineArguments(compilerSettings.additionalArgumentsAsList, this) } } - } - else null + } else null } var compilerArguments: CommonCompilerArguments? = null diff --git a/jps/jps-common/src/org/jetbrains/kotlin/config/facetSerialization.kt b/jps/jps-common/src/org/jetbrains/kotlin/config/facetSerialization.kt index 668eb3bace5..64cb27329ed 100644 --- a/jps/jps-common/src/org/jetbrains/kotlin/config/facetSerialization.kt +++ b/jps/jps-common/src/org/jetbrains/kotlin/config/facetSerialization.kt @@ -1,17 +1,6 @@ /* - * Copyright 2010-2017 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. + * Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ package org.jetbrains.kotlin.config @@ -100,8 +89,7 @@ private fun readV1Config(element: Element): KotlinFacetSettings { if (useProjectSettings != null) { this.useProjectSettings = useProjectSettings - } - else { + } else { // Migration problem workaround for pre-1.1-beta releases (mainly 1.0.6) -> 1.1-rc+ // Problematic cases: 1.1-beta/1.1-beta2 -> 1.1-rc+ (useProjectSettings gets reset to false) // This heuristic detects old enough configurations: @@ -214,13 +202,11 @@ private fun readLatestConfig(element: Element): KotlinFacetSettings { } fun deserializeFacetSettings(element: Element): KotlinFacetSettings { - val version = - try { - element.getAttribute("version")?.intValue - } - catch(e: DataConversionException) { - null - } ?: KotlinFacetSettings.DEFAULT_VERSION + val version = try { + element.getAttribute("version")?.intValue + } catch (e: DataConversionException) { + null + } ?: KotlinFacetSettings.DEFAULT_VERSION return when (version) { 1 -> readV1Config(element) 2 -> readV2Config(element) @@ -290,9 +276,8 @@ private val Class<*>.normalOrdering private fun Element.restoreNormalOrdering(bean: Any) { val normalOrdering = bean.javaClass.normalOrdering val elementsToReorder = this.getContent { it is Element && it.getAttribute("name")?.value in normalOrdering } - elementsToReorder - .sortedBy { normalOrdering[it.getAttribute("name")?.value!!] } - .forEachIndexed { index, element -> elementsToReorder[index] = element.clone() } + elementsToReorder.sortedBy { normalOrdering[it.getAttribute("name")?.value!!] } + .forEachIndexed { index, element -> elementsToReorder[index] = element.clone() } } private fun buildChildElement(element: Element, tag: String, bean: Any, filter: SerializationFilter): Element { @@ -422,8 +407,7 @@ fun KotlinFacetSettings.serializeFacetSettings(element: Element) { element.setAttribute("version", versionToWrite.toString()) if (versionToWrite == 2) { writeV2Config(element) - } - else { + } else { writeLatestConfig(element) } } diff --git a/jps/jps-common/src/org/jetbrains/kotlin/config/moduleSourceRootPropertiesSerializers.kt b/jps/jps-common/src/org/jetbrains/kotlin/config/moduleSourceRootPropertiesSerializers.kt index e9635a4bd5a..9ae08088253 100644 --- a/jps/jps-common/src/org/jetbrains/kotlin/config/moduleSourceRootPropertiesSerializers.kt +++ b/jps/jps-common/src/org/jetbrains/kotlin/config/moduleSourceRootPropertiesSerializers.kt @@ -1,5 +1,5 @@ /* - * Copyright 2010-2018 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ @@ -13,8 +13,8 @@ import org.jetbrains.jps.model.module.JpsModuleSourceRootType import org.jetbrains.jps.model.serialization.module.JpsModuleRootModelSerializer import org.jetbrains.jps.model.serialization.module.JpsModuleSourceRootPropertiesSerializer -private val IS_GENERATED_ATTRIBUTE = "generated" -private val RELATIVE_OUTPUT_PATH_ATTRIBUTE = "relativeOutputPath" +private const val IS_GENERATED_ATTRIBUTE = "generated" +private const val RELATIVE_OUTPUT_PATH_ATTRIBUTE = "relativeOutputPath" val KOTLIN_SOURCE_ROOT_TYPE_ID = "kotlin-source" val KOTLIN_TEST_ROOT_TYPE_ID = "kotlin-test" @@ -27,13 +27,13 @@ sealed class KotlinSourceRootPropertiesSerializer( typeId: String ) : JpsModuleSourceRootPropertiesSerializer(type, typeId) { object Source : KotlinSourceRootPropertiesSerializer( - SourceKotlinRootType, - KOTLIN_SOURCE_ROOT_TYPE_ID + SourceKotlinRootType, + KOTLIN_SOURCE_ROOT_TYPE_ID ) object TestSource : KotlinSourceRootPropertiesSerializer( - TestSourceKotlinRootType, - KOTLIN_TEST_ROOT_TYPE_ID + TestSourceKotlinRootType, + KOTLIN_TEST_ROOT_TYPE_ID ) override fun loadProperties(sourceRootTag: Element): JavaSourceRootProperties { @@ -59,9 +59,10 @@ sealed class KotlinResourceRootPropertiesSerializer( typeId: String ) : JpsModuleSourceRootPropertiesSerializer(type, typeId) { object Resource : KotlinResourceRootPropertiesSerializer( - ResourceKotlinRootType, - KOTLIN_RESOURCE_ROOT_TYPE_ID + ResourceKotlinRootType, + KOTLIN_RESOURCE_ROOT_TYPE_ID ) + object TestResource : KotlinResourceRootPropertiesSerializer( TestResourceKotlinRootType, KOTLIN_TEST_RESOURCE_ROOT_TYPE_ID diff --git a/jps/jps-common/src/org/jetbrains/kotlin/platform/IdePlatformKind.kt b/jps/jps-common/src/org/jetbrains/kotlin/platform/IdePlatformKind.kt index 72c06542638..fe75bbad037 100644 --- a/jps/jps-common/src/org/jetbrains/kotlin/platform/IdePlatformKind.kt +++ b/jps/jps-common/src/org/jetbrains/kotlin/platform/IdePlatformKind.kt @@ -1,5 +1,5 @@ /* - * Copyright 2010-2018 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ @@ -8,9 +8,9 @@ package org.jetbrains.kotlin.platform import com.intellij.openapi.diagnostic.Logger -import org.jetbrains.kotlin.extensions.ApplicationExtensionDescriptor import org.jetbrains.kotlin.cli.common.arguments.CommonCompilerArguments import org.jetbrains.kotlin.config.isJps +import org.jetbrains.kotlin.extensions.ApplicationExtensionDescriptor import org.jetbrains.kotlin.platform.impl.CommonIdePlatformKind import org.jetbrains.kotlin.platform.impl.JsIdePlatformKind import org.jetbrains.kotlin.platform.impl.JvmIdePlatformKind @@ -75,7 +75,9 @@ val TargetPlatform.idePlatformKind: IdePlatformKind<*> get() = IdePlatformKind.ALL_KINDS.filter { it.supportsTargetPlatform(this) }.let { list -> when { list.size == 1 -> list.first() - list.size > 1 -> list.first().also { Logger.getInstance(IdePlatformKind.javaClass).warn("Found more than one IdePlatformKind [$list] for target [$this].") } + list.size > 1 -> list.first().also { + Logger.getInstance(IdePlatformKind.javaClass).warn("Found more than one IdePlatformKind [$list] for target [$this].") + } else -> error("Unknown platform $this") } } \ No newline at end of file diff --git a/jps/jps-common/src/org/jetbrains/kotlin/platform/impl/JvmIdePlatformKind.kt b/jps/jps-common/src/org/jetbrains/kotlin/platform/impl/JvmIdePlatformKind.kt index 8ad48e32821..a0ab9b1af92 100644 --- a/jps/jps-common/src/org/jetbrains/kotlin/platform/impl/JvmIdePlatformKind.kt +++ b/jps/jps-common/src/org/jetbrains/kotlin/platform/impl/JvmIdePlatformKind.kt @@ -1,5 +1,5 @@ /* - * Copyright 2010-2018 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ @@ -43,7 +43,9 @@ object JvmIdePlatformKind : IdePlatformKind() { return K2JVMCompilerArguments() } - val platforms: List = JvmTarget.values().map { ver -> JvmPlatforms.jvmPlatformByTargetVersion(ver) } + listOf(JvmPlatforms.unspecifiedJvmPlatform) + val platforms: List = JvmTarget.values() + .map { ver -> JvmPlatforms.jvmPlatformByTargetVersion(ver) } + listOf(JvmPlatforms.unspecifiedJvmPlatform) + override val defaultPlatform get() = JvmPlatforms.defaultJvmPlatform override val argumentsClass get() = K2JVMCompilerArguments::class.java