Move JvmTarget to frontend.java, introduce TargetPlatformVersion

Previously JvmTarget was declared in module 'util' which is accessible
for example from 'frontend', which is not very good.

Also add a superinterface named TargetPlatformVersion which is going to
be used in platform-independent injectors in 'frontend' in the following
commits. Use it in one place (LanguageVersionSettingsProviderImpl.kt)
instead of DescriptionAware because TargetPlatformVersion sounds like a
better abstraction than DescriptionAware here
This commit is contained in:
Alexander Udalov
2017-03-01 19:23:14 +03:00
parent d2cd5d46fa
commit 573c6ab5d4
8 changed files with 42 additions and 21 deletions
+1 -1
View File
@@ -10,6 +10,6 @@
<orderEntry type="module" module-name="util" />
<orderEntry type="library" scope="PROVIDED" name="intellij-core" level="project" />
<orderEntry type="library" name="jps" level="project" />
<orderEntry type="module" module-name="descriptor.loader.java" />
<orderEntry type="module" module-name="frontend.java" />
</component>
</module>
@@ -1,5 +1,5 @@
/*
* Copyright 2010-2016 JetBrains s.r.o.
* 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.
@@ -16,10 +16,9 @@
package org.jetbrains.kotlin.config
import org.jetbrains.kotlin.utils.DescriptionAware
import org.jetbrains.org.objectweb.asm.Opcodes
enum class JvmTarget(override val description: String) : DescriptionAware {
enum class JvmTarget(override val description: String) : TargetPlatformVersion {
JVM_1_6("1.6"),
JVM_1_8("1.8"),
;
@@ -23,6 +23,7 @@ import org.jetbrains.kotlin.builtins.DefaultBuiltIns
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
import org.jetbrains.kotlin.config.LanguageVersionSettings
import org.jetbrains.kotlin.config.LanguageVersionSettingsImpl
import org.jetbrains.kotlin.config.TargetPlatformVersion
import org.jetbrains.kotlin.container.ComponentProvider
import org.jetbrains.kotlin.context.ModuleContext
import org.jetbrains.kotlin.context.ProjectContext
@@ -37,7 +38,6 @@ import org.jetbrains.kotlin.resolve.CompilerEnvironment
import org.jetbrains.kotlin.resolve.MultiTargetPlatform
import org.jetbrains.kotlin.resolve.TargetEnvironment
import org.jetbrains.kotlin.resolve.TargetPlatform
import org.jetbrains.kotlin.utils.DescriptionAware
import org.jetbrains.kotlin.utils.singletonOrEmptyList
import java.util.*
@@ -261,15 +261,15 @@ private class DelegatingPackageFragmentProvider(
interface LanguageSettingsProvider {
fun getLanguageVersionSettings(moduleInfo: ModuleInfo, project: Project): LanguageVersionSettings
fun getTargetPlatform(moduleInfo: ModuleInfo): DescriptionAware
fun getTargetPlatform(moduleInfo: ModuleInfo): TargetPlatformVersion
object Default : LanguageSettingsProvider {
override fun getLanguageVersionSettings(moduleInfo: ModuleInfo, project: Project) = LanguageVersionSettingsImpl.DEFAULT
override fun getTargetPlatform(moduleInfo: ModuleInfo): DescriptionAware = DescriptionAware.NoVersion
override fun getTargetPlatform(moduleInfo: ModuleInfo): TargetPlatformVersion = TargetPlatformVersion.NoVersion
}
companion object {
fun getInstance(project: Project) = ServiceManager.getService(project, LanguageSettingsProvider::class.java) ?: Default
}
}
}
@@ -0,0 +1,25 @@
/*
* 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.
*/
package org.jetbrains.kotlin.config
import org.jetbrains.kotlin.utils.DescriptionAware
interface TargetPlatformVersion : DescriptionAware {
object NoVersion : TargetPlatformVersion {
override val description = ""
}
}
@@ -14,12 +14,8 @@
* limitations under the License.
*/
package org.jetbrains.kotlin.utils;
package org.jetbrains.kotlin.utils
interface DescriptionAware {
val description: String
object NoVersion : DescriptionAware {
override val description = ""
}
}
}
+1
View File
@@ -12,5 +12,6 @@
<orderEntry type="library" name="intellij-core" level="project" />
<orderEntry type="module" module-name="cli-common" />
<orderEntry type="module" module-name="util" />
<orderEntry type="module" module-name="frontend.java" />
</component>
</module>
@@ -25,7 +25,7 @@ import org.jetbrains.kotlin.cli.common.arguments.K2JVMCompilerArguments
import org.jetbrains.kotlin.cli.common.arguments.K2MetadataCompilerArguments
import org.jetbrains.kotlin.utils.DescriptionAware
sealed class TargetPlatformKind<out Version : DescriptionAware>(
sealed class TargetPlatformKind<out Version : TargetPlatformVersion>(
val version: Version,
val name: String
) : DescriptionAware {
@@ -39,9 +39,9 @@ sealed class TargetPlatformKind<out Version : DescriptionAware>(
}
}
object JavaScript : TargetPlatformKind<DescriptionAware.NoVersion>(DescriptionAware.NoVersion, "JavaScript")
object JavaScript : TargetPlatformKind<TargetPlatformVersion.NoVersion>(TargetPlatformVersion.NoVersion, "JavaScript")
object Common : TargetPlatformKind<DescriptionAware.NoVersion>(DescriptionAware.NoVersion, "Common (experimental)")
object Common : TargetPlatformKind<TargetPlatformVersion.NoVersion>(TargetPlatformVersion.NoVersion, "Common (experimental)")
companion object {
val ALL_PLATFORMS: List<TargetPlatformKind<*>> by lazy { Jvm.JVM_PLATFORMS + JavaScript + Common }
@@ -141,4 +141,4 @@ interface KotlinFacetSettingsProvider {
companion object {
fun getInstance(project: Project) = ServiceManager.getService(project, KotlinFacetSettingsProvider::class.java)!!
}
}
}
@@ -20,18 +20,18 @@ import com.intellij.openapi.project.Project
import org.jetbrains.kotlin.analyzer.LanguageSettingsProvider
import org.jetbrains.kotlin.analyzer.ModuleInfo
import org.jetbrains.kotlin.config.LanguageVersionSettings
import org.jetbrains.kotlin.config.TargetPlatformVersion
import org.jetbrains.kotlin.idea.caches.resolve.ModuleSourceInfo
import org.jetbrains.kotlin.idea.project.getLanguageVersionSettings
import org.jetbrains.kotlin.idea.project.languageVersionSettings
import org.jetbrains.kotlin.idea.project.targetPlatform
import org.jetbrains.kotlin.utils.DescriptionAware
class LanguageVersionSettingsProviderImpl : LanguageSettingsProvider {
override fun getLanguageVersionSettings(moduleInfo: ModuleInfo, project: Project): LanguageVersionSettings {
return (moduleInfo as? ModuleSourceInfo)?.module?.languageVersionSettings ?: project.getLanguageVersionSettings()
}
override fun getTargetPlatform(moduleInfo: ModuleInfo): DescriptionAware {
return (moduleInfo as? ModuleSourceInfo)?.module?.targetPlatform?.version ?: DescriptionAware.NoVersion
override fun getTargetPlatform(moduleInfo: ModuleInfo): TargetPlatformVersion {
return (moduleInfo as? ModuleSourceInfo)?.module?.targetPlatform?.version ?: TargetPlatformVersion.NoVersion
}
}