idea: cleanup code

Original commit: 8dbbd64beb
This commit is contained in:
Dmitry Gridin
2019-12-13 22:11:25 +07:00
parent 3a4e06af13
commit e0de867600
5 changed files with 35 additions and 58 deletions
@@ -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<out Version : TargetPlatformVersion>(
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
@@ -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<Element> { 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)
}
}
@@ -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<JavaSourceRootProperties>(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<JavaResourceRootProperties>(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
@@ -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")
}
}
@@ -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<JvmIdePlatformKind>() {
return K2JVMCompilerArguments()
}
val platforms: List<TargetPlatform> = JvmTarget.values().map { ver -> JvmPlatforms.jvmPlatformByTargetVersion(ver) } + listOf(JvmPlatforms.unspecifiedJvmPlatform)
val platforms: List<TargetPlatform> = JvmTarget.values()
.map { ver -> JvmPlatforms.jvmPlatformByTargetVersion(ver) } + listOf(JvmPlatforms.unspecifiedJvmPlatform)
override val defaultPlatform get() = JvmPlatforms.defaultJvmPlatform
override val argumentsClass get() = K2JVMCompilerArguments::class.java