New J2K: suggest user to configure Kotlin in a project before nj2k conversion
This commit is contained in:
@@ -31,6 +31,7 @@ dependencies {
|
||||
compile(project(":idea:fir-view"))
|
||||
compile(project(":idea:idea-core"))
|
||||
compile(project(":idea:ide-common"))
|
||||
compile(project(":idea:idea-jvm"))
|
||||
compile(project(":idea:idea-jps-common"))
|
||||
compile(project(":idea:kotlin-gradle-tooling"))
|
||||
compile(project(":plugins:uast-kotlin"))
|
||||
|
||||
@@ -1,8 +1,15 @@
|
||||
package org.jetbrains.kotlin.nj2k
|
||||
|
||||
import com.intellij.openapi.module.Module
|
||||
import com.intellij.openapi.project.Project
|
||||
import com.intellij.openapi.ui.Messages
|
||||
import org.jetbrains.kotlin.idea.configuration.getAbleToRunConfigurators
|
||||
import org.jetbrains.kotlin.idea.configuration.hasAnyKotlinRuntimeInScope
|
||||
import org.jetbrains.kotlin.idea.configuration.isModuleConfigured
|
||||
import org.jetbrains.kotlin.idea.configuration.toModuleGroup
|
||||
import org.jetbrains.kotlin.j2k.*
|
||||
import org.jetbrains.kotlin.nj2k.postProcessing.NewJ2kPostProcessor
|
||||
import org.jetbrains.kotlin.platform.jvm.isJvm
|
||||
|
||||
class NewJ2kConverterExtension : J2kConverterExtension() {
|
||||
override val isNewJ2k = true
|
||||
@@ -16,4 +23,43 @@ class NewJ2kConverterExtension : J2kConverterExtension() {
|
||||
|
||||
override fun createPostProcessor(formatCode: Boolean): PostProcessor =
|
||||
NewJ2kPostProcessor()
|
||||
|
||||
override fun doCheckBeforeConversion(project: Project, module: Module): Boolean =
|
||||
checkKotlinIsConfigured(project, module)
|
||||
|
||||
private fun checkKotlinIsConfigured(project: Project, module: Module): Boolean {
|
||||
val kotlinIsConfigured =
|
||||
hasAnyKotlinRuntimeInScope(module) || isModuleConfigured(module.toModuleGroup())
|
||||
if (kotlinIsConfigured) return true
|
||||
|
||||
val title = "Kotlin is not configured in the project"
|
||||
if (Messages.showOkCancelDialog(
|
||||
project,
|
||||
"You will have to configure Kotlin in project before performing a conversion.",
|
||||
title,
|
||||
"OK, configure Kotlin in the project",
|
||||
"No, cancel conversion",
|
||||
Messages.getWarningIcon()
|
||||
) == Messages.OK
|
||||
) {
|
||||
val configurators = getAbleToRunConfigurators(module).filter { it.targetPlatform.isJvm() }
|
||||
when {
|
||||
configurators.isEmpty() -> Messages.showErrorDialog("There aren't configurators available", title)
|
||||
configurators.size == 1 -> configurators.single().configure(project, emptyList())
|
||||
else -> {
|
||||
val resultIndex = Messages.showChooseDialog(//TODO a better dialog?
|
||||
project,
|
||||
"Choose Configurator",
|
||||
title,
|
||||
null,
|
||||
configurators.map { it.presentableText }.toTypedArray(),
|
||||
configurators.first().presentableText
|
||||
)
|
||||
configurators.getOrNull(resultIndex)?.configure(project, emptyList())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user