Use Gradle API to import annotations from compiler plugins instead of nasty data storage tasks
Tasks itself will be left for some time until all users migrate to the newer IDE plugin versions.
This commit is contained in:
+42
-5
@@ -918,14 +918,11 @@ compileTestKotlin {
|
||||
buildscript {
|
||||
repositories {
|
||||
mavenCentral()
|
||||
maven {
|
||||
url 'http://dl.bintray.com/kotlin/kotlin-eap-1.1'
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.1.0")
|
||||
classpath("org.jetbrains.kotlin:kotlin-allopen:1.1.0")
|
||||
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.2.10")
|
||||
classpath("org.jetbrains.kotlin:kotlin-allopen:1.2.10")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -949,6 +946,46 @@ compileTestKotlin {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testNoArgInvokeInitializers() {
|
||||
createProjectSubFile("build.gradle", """
|
||||
group 'Again'
|
||||
version '1.0-SNAPSHOT'
|
||||
|
||||
buildscript {
|
||||
repositories {
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
dependencies {
|
||||
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.2.10")
|
||||
classpath("org.jetbrains.kotlin:kotlin-noarg:1.2.10")
|
||||
}
|
||||
}
|
||||
|
||||
apply plugin: 'kotlin'
|
||||
apply plugin: "kotlin-noarg"
|
||||
|
||||
noArg {
|
||||
invokeInitializers = true
|
||||
annotation("NoArg")
|
||||
}
|
||||
""")
|
||||
importProject()
|
||||
|
||||
with (facetSettings) {
|
||||
Assert.assertEquals(
|
||||
"-version",
|
||||
compilerSettings!!.additionalArguments
|
||||
)
|
||||
Assert.assertEquals(
|
||||
listOf("plugin:org.jetbrains.kotlin.noarg:annotation=NoArg",
|
||||
"plugin:org.jetbrains.kotlin.noarg:invokeInitializers=true"),
|
||||
compilerArguments!!.pluginOptions!!.toList()
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testAndroidGradleJsDetection() {
|
||||
createProjectSubFile("android-module/build.gradle", """
|
||||
|
||||
@@ -10,6 +10,9 @@
|
||||
<pluginDescriptions implementation="org.jetbrains.kotlin.idea.configuration.KotlinGradlePluginDescription"/>
|
||||
<projectResolve implementation="org.jetbrains.kotlin.idea.configuration.KotlinGradleProjectResolverExtension" order="first"/>
|
||||
<projectResolve implementation="org.jetbrains.kotlin.kapt.idea.KaptProjectResolverExtension" order="last"/>
|
||||
<projectResolve implementation="org.jetbrains.kotlin.allopen.ide.AllOpenProjectResolverExtension" order="last"/>
|
||||
<projectResolve implementation="org.jetbrains.kotlin.noarg.ide.NoArgProjectResolverExtension" order="last"/>
|
||||
<projectResolve implementation="org.jetbrains.kotlin.samWithReceiver.ide.SamWithReceiverProjectResolverExtension" order="last"/>
|
||||
</extensions>
|
||||
|
||||
<extensionPoints>
|
||||
|
||||
@@ -20,12 +20,12 @@ import org.jetbrains.kotlin.allopen.AllOpenCommandLineProcessor
|
||||
import org.jetbrains.kotlin.annotation.plugin.ide.AbstractGradleImportHandler
|
||||
import org.jetbrains.kotlin.utils.PathUtil
|
||||
|
||||
class AllOpenGradleProjectImportHandler : AbstractGradleImportHandler() {
|
||||
class AllOpenGradleProjectImportHandler : AbstractGradleImportHandler<AllOpenModel>() {
|
||||
override val compilerPluginId = AllOpenCommandLineProcessor.PLUGIN_ID
|
||||
override val pluginName = "allopen"
|
||||
override val annotationOptionName = AllOpenCommandLineProcessor.ANNOTATION_OPTION.name
|
||||
override val dataStorageTaskName = "allOpenDataStorageTask"
|
||||
override val pluginJarFileFromIdea = PathUtil.kotlinPathsForIdeaPlugin.allOpenPluginJarPath
|
||||
override val modelKey = AllOpenProjectResolverExtension.KEY
|
||||
|
||||
override fun getAnnotationsForPreset(presetName: String): List<String> {
|
||||
for ((name, annotations) in AllOpenCommandLineProcessor.SUPPORTED_PRESETS.entries) {
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
* 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.allopen.ide
|
||||
|
||||
import com.intellij.openapi.util.Key
|
||||
import org.jetbrains.kotlin.annotation.plugin.ide.AnnotationBasedPluginModel
|
||||
import org.jetbrains.kotlin.annotation.plugin.ide.AnnotationBasedPluginModelBuilderService
|
||||
import org.jetbrains.kotlin.annotation.plugin.ide.AnnotationBasedPluginProjectResolverExtension
|
||||
|
||||
interface AllOpenModel : AnnotationBasedPluginModel
|
||||
|
||||
class AllOpenModelImpl(
|
||||
override val annotations: List<String>,
|
||||
override val presets: List<String>
|
||||
) : AllOpenModel
|
||||
|
||||
class AllOpenModelBuilderService : AnnotationBasedPluginModelBuilderService<AllOpenModel>() {
|
||||
override val gradlePluginNames get() = listOf("org.jetbrains.kotlin.plugin.allopen", "kotlin-allopen")
|
||||
override val extensionName get() = "allOpen"
|
||||
override val modelClass get() = AllOpenModel::class.java
|
||||
|
||||
override fun createModel(annotations: List<String>, presets: List<String>, extension: Any?): AllOpenModelImpl {
|
||||
return AllOpenModelImpl(annotations, presets)
|
||||
}
|
||||
}
|
||||
|
||||
class AllOpenProjectResolverExtension : AnnotationBasedPluginProjectResolverExtension<AllOpenModel>() {
|
||||
companion object {
|
||||
val KEY = Key<AllOpenModel>("AllOpenModel")
|
||||
}
|
||||
|
||||
override val modelClass get() = AllOpenModel::class.java
|
||||
override val userDataKey get() = KEY
|
||||
}
|
||||
+1
@@ -0,0 +1 @@
|
||||
org.jetbrains.kotlin.allopen.ide.AllOpenModelBuilderService
|
||||
+11
-17
@@ -19,25 +19,22 @@ package org.jetbrains.kotlin.annotation.plugin.ide
|
||||
import com.intellij.openapi.externalSystem.model.DataNode
|
||||
import com.intellij.openapi.externalSystem.model.ProjectKeys
|
||||
import com.intellij.openapi.externalSystem.model.project.ModuleData
|
||||
import com.intellij.openapi.externalSystem.model.task.TaskData
|
||||
import com.intellij.openapi.externalSystem.util.ExternalSystemApiUtil
|
||||
import com.intellij.openapi.util.Key
|
||||
import org.jetbrains.kotlin.annotation.plugin.ide.AnnotationBasedCompilerPluginSetup.PluginOption
|
||||
import org.jetbrains.kotlin.idea.configuration.GradleProjectImportHandler
|
||||
import org.jetbrains.kotlin.idea.facet.KotlinFacet
|
||||
import org.jetbrains.plugins.gradle.model.data.GradleSourceSetData
|
||||
import java.io.File
|
||||
|
||||
abstract class AbstractGradleImportHandler : GradleProjectImportHandler {
|
||||
private companion object {
|
||||
private val TASK_DESCRIPTION_REGEX = "Supported annotations: ([^; ]*); (?:Presets: (.*?); )?Compiler plugin classpath: (.*?)".toRegex()
|
||||
}
|
||||
|
||||
abstract class AbstractGradleImportHandler<T : AnnotationBasedPluginModel> : GradleProjectImportHandler {
|
||||
abstract val compilerPluginId: String
|
||||
abstract val pluginName: String
|
||||
abstract val annotationOptionName: String
|
||||
abstract val dataStorageTaskName: String
|
||||
abstract val pluginJarFileFromIdea: File
|
||||
|
||||
abstract val modelKey: Key<T>
|
||||
|
||||
override fun importBySourceSet(facet: KotlinFacet, sourceSetNode: DataNode<GradleSourceSetData>) {
|
||||
modifyCompilerArgumentsForPlugin(facet, getPluginSetupBySourceSet(sourceSetNode),
|
||||
compilerPluginId = compilerPluginId,
|
||||
@@ -52,20 +49,17 @@ abstract class AbstractGradleImportHandler : GradleProjectImportHandler {
|
||||
|
||||
protected open fun getAnnotationsForPreset(presetName: String): List<String> = emptyList()
|
||||
|
||||
protected open fun getAdditionalOptions(model: T): List<PluginOption> = emptyList()
|
||||
|
||||
private fun getPluginSetupByModule(
|
||||
moduleNode: DataNode<ModuleData>
|
||||
): AnnotationBasedCompilerPluginSetup? {
|
||||
val dataStorageTaskData = moduleNode.children.firstOrNull {
|
||||
val data = it.data as? TaskData ?: return@firstOrNull false
|
||||
data.name == dataStorageTaskName
|
||||
}?.data as? TaskData ?: return null
|
||||
val pluginModel = moduleNode.getUserData(modelKey)?.takeIf { it.isEnabled } ?: return null
|
||||
val annotations = pluginModel.annotations
|
||||
val presets = pluginModel.presets
|
||||
|
||||
val dataStorageTaskDescription = dataStorageTaskData.description ?: return null
|
||||
val matchResult = TASK_DESCRIPTION_REGEX.matchEntire(dataStorageTaskDescription)?.groupValues?.drop(1) ?: return null
|
||||
val (annotationFqNamesList, presets) = matchResult
|
||||
|
||||
val annotationFqNames = annotationFqNamesList.split(',') + presets.split(',').flatMap { getAnnotationsForPreset(it) }
|
||||
val options = annotationFqNames.map { PluginOption(annotationOptionName, it) }
|
||||
val allAnnotations = annotations + presets.flatMap { getAnnotationsForPreset(it) }
|
||||
val options = allAnnotations.map { PluginOption(annotationOptionName, it) } + getAdditionalOptions(pluginModel)
|
||||
|
||||
// For now we can't use plugins from Gradle cause they're shaded and may have an incompatible version.
|
||||
// So we use ones from the IDEA plugin.
|
||||
|
||||
+121
@@ -0,0 +1,121 @@
|
||||
/*
|
||||
* 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.annotation.plugin.ide
|
||||
|
||||
import com.intellij.openapi.diagnostic.Logger
|
||||
import com.intellij.openapi.externalSystem.model.DataNode
|
||||
import com.intellij.openapi.externalSystem.model.project.*
|
||||
import com.intellij.openapi.util.Key
|
||||
import org.gradle.api.Plugin
|
||||
import org.gradle.api.Project
|
||||
import org.gradle.tooling.model.idea.IdeaModule
|
||||
import org.jetbrains.kotlin.gradle.AbstractKotlinGradleModelBuilder
|
||||
import org.jetbrains.plugins.gradle.service.project.AbstractProjectResolverExtension
|
||||
import org.jetbrains.plugins.gradle.tooling.ErrorMessageBuilder
|
||||
import java.io.Serializable
|
||||
import java.lang.Exception
|
||||
|
||||
interface AnnotationBasedPluginModel : Serializable {
|
||||
val annotations: List<String>
|
||||
val presets: List<String>
|
||||
|
||||
val isEnabled get() = annotations.isNotEmpty() || presets.isNotEmpty()
|
||||
}
|
||||
|
||||
@Suppress("unused")
|
||||
abstract class AnnotationBasedPluginProjectResolverExtension<T : AnnotationBasedPluginModel> : AbstractProjectResolverExtension() {
|
||||
private companion object {
|
||||
private val LOG = Logger.getInstance(AnnotationBasedPluginProjectResolverExtension::class.java)
|
||||
}
|
||||
|
||||
abstract val modelClass: Class<T>
|
||||
abstract val userDataKey: Key<T>
|
||||
|
||||
override fun getExtraProjectModelClasses() = setOf(modelClass)
|
||||
|
||||
override fun getToolingExtensionsClasses() = setOf(
|
||||
modelClass,
|
||||
AnnotationBasedPluginProjectResolverExtension::class.java,
|
||||
Unit::class.java)
|
||||
|
||||
override fun populateModuleExtraModels(gradleModule: IdeaModule, ideModule: DataNode<ModuleData>) {
|
||||
val model = resolverCtx.getExtraProject(gradleModule, modelClass)
|
||||
|
||||
if (model != null) {
|
||||
ideModule.putUserData(userDataKey, model)
|
||||
}
|
||||
|
||||
super.populateModuleExtraModels(gradleModule, ideModule)
|
||||
}
|
||||
}
|
||||
|
||||
abstract class AnnotationBasedPluginModelBuilderService<T : AnnotationBasedPluginModel> : AbstractKotlinGradleModelBuilder() {
|
||||
abstract val gradlePluginNames: List<String>
|
||||
abstract val extensionName: String
|
||||
|
||||
abstract val modelClass: Class<T>
|
||||
abstract fun createModel(annotations: List<String>, presets: List<String>, extension: Any?): T
|
||||
|
||||
override fun getErrorMessageBuilder(project: Project, e: Exception): ErrorMessageBuilder {
|
||||
return ErrorMessageBuilder.create(project, e, "Gradle import errors")
|
||||
.withDescription("Unable to build $gradlePluginNames plugin configuration")
|
||||
}
|
||||
|
||||
override fun canBuild(modelName: String?): Boolean = modelName == modelClass.name
|
||||
|
||||
override fun buildAll(modelName: String?, project: Project): Any {
|
||||
val plugin: Plugin<*>? = project.findPlugin(gradlePluginNames)
|
||||
val extension: Any? = project.extensions.findByName(extensionName)
|
||||
|
||||
val annotations = mutableListOf<String>()
|
||||
val presets = mutableListOf<String>()
|
||||
|
||||
if (plugin != null && extension != null) {
|
||||
annotations += extension.getList("myAnnotations")
|
||||
presets += extension.getList("myPresets")
|
||||
return createModel(annotations, presets, extension)
|
||||
}
|
||||
|
||||
return createModel(emptyList(), emptyList(), null)
|
||||
}
|
||||
|
||||
private fun Project.findPlugin(names: List<String>): Plugin<*>? {
|
||||
for (name in names) {
|
||||
plugins.findPlugin(name)?.let { return it }
|
||||
}
|
||||
|
||||
return null
|
||||
}
|
||||
|
||||
private fun Any.getList(fieldName: String): List<String> {
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
return getFieldValue(fieldName) as? List<String> ?: emptyList()
|
||||
}
|
||||
|
||||
protected fun Any.getFieldValue(fieldName: String, clazz: Class<*> = this.javaClass): Any? {
|
||||
val field = clazz.declaredFields.firstOrNull { it.name == fieldName }
|
||||
?: return getFieldValue(fieldName, clazz.superclass ?: return null)
|
||||
|
||||
val oldIsAccessible = field.isAccessible
|
||||
try {
|
||||
field.isAccessible = true
|
||||
return field.get(this)
|
||||
} finally {
|
||||
field.isAccessible = oldIsAccessible
|
||||
}
|
||||
}
|
||||
}
|
||||
+1
@@ -0,0 +1 @@
|
||||
org.jetbrains.kotlin.noarg.ide.NoArgModelBuilderService
|
||||
@@ -17,15 +17,23 @@
|
||||
package org.jetbrains.kotlin.noarg.ide
|
||||
|
||||
import org.jetbrains.kotlin.annotation.plugin.ide.AbstractGradleImportHandler
|
||||
import org.jetbrains.kotlin.annotation.plugin.ide.AnnotationBasedCompilerPluginSetup
|
||||
import org.jetbrains.kotlin.annotation.plugin.ide.AnnotationBasedCompilerPluginSetup.PluginOption
|
||||
import org.jetbrains.kotlin.noarg.NoArgCommandLineProcessor
|
||||
import org.jetbrains.kotlin.utils.PathUtil
|
||||
|
||||
class NoArgGradleProjectImportHandler : AbstractGradleImportHandler() {
|
||||
class NoArgGradleProjectImportHandler : AbstractGradleImportHandler<NoArgModel>() {
|
||||
override val compilerPluginId = NoArgCommandLineProcessor.PLUGIN_ID
|
||||
override val pluginName = "noarg"
|
||||
override val annotationOptionName = NoArgCommandLineProcessor.ANNOTATION_OPTION.name
|
||||
override val dataStorageTaskName = "noArgDataStorageTask"
|
||||
override val pluginJarFileFromIdea = PathUtil.kotlinPathsForIdeaPlugin.noArgPluginJarPath
|
||||
override val modelKey = NoArgProjectResolverExtension.KEY
|
||||
|
||||
override fun getAdditionalOptions(model: NoArgModel): List<PluginOption> {
|
||||
return listOf(PluginOption(
|
||||
NoArgCommandLineProcessor.INVOKE_INITIALIZERS_OPTION.name,
|
||||
model.invokeInitializers.toString()))
|
||||
}
|
||||
|
||||
override fun getAnnotationsForPreset(presetName: String): List<String> {
|
||||
for ((name, annotations) in NoArgCommandLineProcessor.SUPPORTED_PRESETS.entries) {
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
* 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.noarg.ide
|
||||
|
||||
import com.intellij.openapi.util.Key
|
||||
import org.jetbrains.kotlin.annotation.plugin.ide.AnnotationBasedPluginModel
|
||||
import org.jetbrains.kotlin.annotation.plugin.ide.AnnotationBasedPluginModelBuilderService
|
||||
import org.jetbrains.kotlin.annotation.plugin.ide.AnnotationBasedPluginProjectResolverExtension
|
||||
|
||||
interface NoArgModel : AnnotationBasedPluginModel {
|
||||
val invokeInitializers: Boolean
|
||||
}
|
||||
|
||||
class NoArgModelImpl(
|
||||
override val annotations: List<String>,
|
||||
override val presets: List<String>,
|
||||
override val invokeInitializers: Boolean
|
||||
) : NoArgModel
|
||||
|
||||
class NoArgModelBuilderService : AnnotationBasedPluginModelBuilderService<NoArgModel>() {
|
||||
override val gradlePluginNames get() = listOf("org.jetbrains.kotlin.plugin.noarg", "kotlin-noarg")
|
||||
override val extensionName get() = "noArg"
|
||||
override val modelClass get() = NoArgModel::class.java
|
||||
|
||||
override fun createModel(annotations: List<String>, presets: List<String>, extension: Any?): NoArgModel {
|
||||
val invokeInitializers = extension?.getFieldValue("invokeInitializers") as? Boolean ?: false
|
||||
return NoArgModelImpl(annotations, presets, invokeInitializers)
|
||||
}
|
||||
}
|
||||
|
||||
class NoArgProjectResolverExtension : AnnotationBasedPluginProjectResolverExtension<NoArgModel>() {
|
||||
companion object {
|
||||
val KEY = Key<NoArgModel>("NoArgModel")
|
||||
}
|
||||
|
||||
override val modelClass get() = NoArgModel::class.java
|
||||
override val userDataKey get() = KEY
|
||||
}
|
||||
-39
@@ -1,39 +0,0 @@
|
||||
/*
|
||||
* 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.samWithReceiver.ide
|
||||
|
||||
import org.jetbrains.kotlin.samWithReceiver.SamWithReceiverCommandLineProcessor
|
||||
import org.jetbrains.kotlin.annotation.plugin.ide.AbstractGradleImportHandler
|
||||
import org.jetbrains.kotlin.utils.PathUtil
|
||||
|
||||
class SamWithReceiverGradleProjectImportHandler : AbstractGradleImportHandler() {
|
||||
override val compilerPluginId = SamWithReceiverCommandLineProcessor.PLUGIN_ID
|
||||
override val pluginName = "sam-with-receiver"
|
||||
override val annotationOptionName = SamWithReceiverCommandLineProcessor.ANNOTATION_OPTION.name
|
||||
override val dataStorageTaskName = "samWithReceiverDataStorageTask"
|
||||
override val pluginJarFileFromIdea = PathUtil.kotlinPathsForIdeaPlugin.samWithReceiverJarPath
|
||||
|
||||
override fun getAnnotationsForPreset(presetName: String): List<String> {
|
||||
for ((name, annotations) in SamWithReceiverCommandLineProcessor.SUPPORTED_PRESETS.entries) {
|
||||
if (presetName == name) {
|
||||
return annotations
|
||||
}
|
||||
}
|
||||
|
||||
return super.getAnnotationsForPreset(presetName)
|
||||
}
|
||||
}
|
||||
-54
@@ -1,54 +0,0 @@
|
||||
/*
|
||||
* 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.samWithReceiver.ide
|
||||
|
||||
import org.jetbrains.kotlin.samWithReceiver.SamWithReceiverCommandLineProcessor
|
||||
import org.jetbrains.kotlin.annotation.plugin.ide.AbstractMavenImportHandler
|
||||
import org.jetbrains.kotlin.annotation.plugin.ide.AnnotationBasedCompilerPluginSetup.PluginOption
|
||||
import org.jetbrains.kotlin.utils.PathUtil
|
||||
|
||||
class SamWithReceiverMavenProjectImportHandler : AbstractMavenImportHandler() {
|
||||
private companion object {
|
||||
val ANNOTATION_PARAMETER_PREFIX = "sam-with-receiver:${SamWithReceiverCommandLineProcessor.ANNOTATION_OPTION.name}="
|
||||
}
|
||||
|
||||
override val compilerPluginId = SamWithReceiverCommandLineProcessor.PLUGIN_ID
|
||||
override val pluginName = "sam-with-receiver"
|
||||
override val mavenPluginArtifactName = "kotlin-maven-sam-with-receiver"
|
||||
override val pluginJarFileFromIdea = PathUtil.kotlinPathsForIdeaPlugin.samWithReceiverJarPath
|
||||
|
||||
override fun getOptions(enabledCompilerPlugins: List<String>, compilerPluginOptions: List<String>): List<PluginOption>? {
|
||||
if ("sam-with-receiver" !in enabledCompilerPlugins) {
|
||||
return null
|
||||
}
|
||||
|
||||
val annotations = mutableListOf<String>()
|
||||
|
||||
for ((presetName, presetAnnotations) in SamWithReceiverCommandLineProcessor.SUPPORTED_PRESETS) {
|
||||
if (presetName in enabledCompilerPlugins) {
|
||||
annotations.addAll(presetAnnotations)
|
||||
}
|
||||
}
|
||||
|
||||
annotations.addAll(compilerPluginOptions.mapNotNull { text ->
|
||||
if (!text.startsWith(ANNOTATION_PARAMETER_PREFIX)) return@mapNotNull null
|
||||
text.substring(ANNOTATION_PARAMETER_PREFIX.length)
|
||||
})
|
||||
|
||||
return annotations.map { PluginOption(SamWithReceiverCommandLineProcessor.ANNOTATION_OPTION.name, it) }
|
||||
}
|
||||
}
|
||||
+1
@@ -0,0 +1 @@
|
||||
org.jetbrains.kotlin.samWithReceiver.ide.SamWithReceiverModelBuilderService
|
||||
+3
-2
@@ -17,15 +17,16 @@
|
||||
package org.jetbrains.kotlin.samWithReceiver.ide
|
||||
|
||||
import org.jetbrains.kotlin.annotation.plugin.ide.AbstractGradleImportHandler
|
||||
import org.jetbrains.kotlin.annotation.plugin.ide.AnnotationBasedCompilerPluginSetup
|
||||
import org.jetbrains.kotlin.samWithReceiver.SamWithReceiverCommandLineProcessor
|
||||
import org.jetbrains.kotlin.utils.PathUtil
|
||||
|
||||
class SamWithReceiverGradleProjectImportHandler : AbstractGradleImportHandler() {
|
||||
class SamWithReceiverGradleProjectImportHandler : AbstractGradleImportHandler<SamWithReceiverModel>() {
|
||||
override val compilerPluginId = SamWithReceiverCommandLineProcessor.PLUGIN_ID
|
||||
override val pluginName = "sam-with-receiver"
|
||||
override val annotationOptionName = SamWithReceiverCommandLineProcessor.ANNOTATION_OPTION.name
|
||||
override val dataStorageTaskName = "samWithReceiverDataStorageTask"
|
||||
override val pluginJarFileFromIdea = PathUtil.kotlinPathsForIdeaPlugin.samWithReceiverJarPath
|
||||
override val modelKey = SamWithReceiverProjectResolverExtension.KEY
|
||||
|
||||
override fun getAnnotationsForPreset(presetName: String): List<String> {
|
||||
for ((name, annotations) in SamWithReceiverCommandLineProcessor.SUPPORTED_PRESETS.entries) {
|
||||
|
||||
+48
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
* 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.samWithReceiver.ide
|
||||
|
||||
import com.intellij.openapi.util.Key
|
||||
import org.jetbrains.kotlin.annotation.plugin.ide.AnnotationBasedPluginModel
|
||||
import org.jetbrains.kotlin.annotation.plugin.ide.AnnotationBasedPluginModelBuilderService
|
||||
import org.jetbrains.kotlin.annotation.plugin.ide.AnnotationBasedPluginProjectResolverExtension
|
||||
|
||||
interface SamWithReceiverModel : AnnotationBasedPluginModel
|
||||
|
||||
class SamWithReceiverModelImpl(
|
||||
override val annotations: List<String>,
|
||||
override val presets: List<String>
|
||||
) : SamWithReceiverModel
|
||||
|
||||
class SamWithReceiverModelBuilderService : AnnotationBasedPluginModelBuilderService<SamWithReceiverModel>() {
|
||||
override val gradlePluginNames get() = listOf("org.jetbrains.kotlin.plugin.sam.with.receiver", "kotlin-sam-with-receiver")
|
||||
override val extensionName get() = "samWithReceiver"
|
||||
override val modelClass get() = SamWithReceiverModel::class.java
|
||||
|
||||
override fun createModel(annotations: List<String>, presets: List<String>, extension: Any?): SamWithReceiverModelImpl {
|
||||
return SamWithReceiverModelImpl(annotations, presets)
|
||||
}
|
||||
}
|
||||
|
||||
class SamWithReceiverProjectResolverExtension : AnnotationBasedPluginProjectResolverExtension<SamWithReceiverModel>() {
|
||||
companion object {
|
||||
val KEY = Key<SamWithReceiverModel>("SamWithReceiverModel")
|
||||
}
|
||||
|
||||
override val modelClass get() = SamWithReceiverModel::class.java
|
||||
override val userDataKey get() = KEY
|
||||
}
|
||||
Reference in New Issue
Block a user