diff options
-rw-r--r-- | build.gradle.kts | 32 | ||||
-rw-r--r-- | src/kotlin1521/kotlin/com/replaymod/gradle/remap/kotlin1521.kt | 18 | ||||
-rw-r--r-- | src/kotlin1620/kotlin/com/replaymod/gradle/remap/kotlin1620.kt | 18 | ||||
-rw-r--r-- | src/main/kotlin/com/replaymod/gradle/remap/PsiMapper.kt | 4 | ||||
-rw-r--r-- | src/main/kotlin/com/replaymod/gradle/remap/Transformer.kt | 28 |
5 files changed, 80 insertions, 20 deletions
diff --git a/build.gradle.kts b/build.gradle.kts index c3bba96..b6214a3 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -20,6 +20,9 @@ repositories { val testA by sourceSets.creating val testB by sourceSets.creating +kotlinVersion("1.5.21", isPrimaryVersion = true) +kotlinVersion("1.6.20") + dependencies { api("org.jetbrains.kotlin:kotlin-compiler-embeddable:1.5.21") implementation(kotlin("stdlib")) @@ -49,3 +52,32 @@ publishing { tasks.test { useJUnitPlatform() } + +fun kotlinVersion(version: String, isPrimaryVersion: Boolean = false) { + val name = version.replace(".", "") + + val sourceSet = sourceSets.create("kotlin$name") + + val testClasspath = configurations.create("kotlin${name}TestClasspath") { + extendsFrom(configurations.testRuntimeClasspath.get()) + extendsFrom(configurations[sourceSet.compileOnlyConfigurationName]) + } + + dependencies { + implementation(sourceSet.output) + sourceSet.compileOnlyConfigurationName("org.jetbrains.kotlin:kotlin-compiler-embeddable:$version") + } + + tasks.jar { + from(sourceSet.output) + } + + if (!isPrimaryVersion) { + val testTask = tasks.register("testKotlin$name", Test::class) { + useJUnitPlatform() + testClassesDirs = sourceSets.test.get().output.classesDirs + classpath = testClasspath + sourceSets.test.get().output + sourceSets.main.get().output + } + tasks.check { dependsOn(testTask) } + } +} diff --git a/src/kotlin1521/kotlin/com/replaymod/gradle/remap/kotlin1521.kt b/src/kotlin1521/kotlin/com/replaymod/gradle/remap/kotlin1521.kt new file mode 100644 index 0000000..c63cb98 --- /dev/null +++ b/src/kotlin1521/kotlin/com/replaymod/gradle/remap/kotlin1521.kt @@ -0,0 +1,18 @@ +package com.replaymod.gradle.remap + +import org.jetbrains.kotlin.analyzer.AnalysisResult +import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment +import org.jetbrains.kotlin.cli.jvm.compiler.NoScopeRecordCliBindingTrace +import org.jetbrains.kotlin.cli.jvm.compiler.TopDownAnalyzerFacadeForJVM +import org.jetbrains.kotlin.com.intellij.psi.search.GlobalSearchScope +import org.jetbrains.kotlin.psi.KtFile + +fun analyze1521(environment: KotlinCoreEnvironment, ktFiles: List<KtFile>): AnalysisResult { + return TopDownAnalyzerFacadeForJVM.analyzeFilesWithJavaIntegration( + environment.project, + ktFiles, + NoScopeRecordCliBindingTrace(), + environment.configuration, + { scope: GlobalSearchScope -> environment.createPackagePartProvider(scope) } + ) +} diff --git a/src/kotlin1620/kotlin/com/replaymod/gradle/remap/kotlin1620.kt b/src/kotlin1620/kotlin/com/replaymod/gradle/remap/kotlin1620.kt new file mode 100644 index 0000000..2574bfe --- /dev/null +++ b/src/kotlin1620/kotlin/com/replaymod/gradle/remap/kotlin1620.kt @@ -0,0 +1,18 @@ +package com.replaymod.gradle.remap + +import org.jetbrains.kotlin.analyzer.AnalysisResult +import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment +import org.jetbrains.kotlin.cli.jvm.compiler.NoScopeRecordCliBindingTrace +import org.jetbrains.kotlin.cli.jvm.compiler.TopDownAnalyzerFacadeForJVM +import org.jetbrains.kotlin.com.intellij.psi.search.GlobalSearchScope +import org.jetbrains.kotlin.psi.KtFile + +fun analyze1620(environment: KotlinCoreEnvironment, ktFiles: List<KtFile>): AnalysisResult { + return TopDownAnalyzerFacadeForJVM.analyzeFilesWithJavaIntegration( + environment.project, + ktFiles, + NoScopeRecordCliBindingTrace(), + environment.configuration, + { scope: GlobalSearchScope -> environment.createPackagePartProvider(scope) } + ) +} diff --git a/src/main/kotlin/com/replaymod/gradle/remap/PsiMapper.kt b/src/main/kotlin/com/replaymod/gradle/remap/PsiMapper.kt index dbd3f2e..1c5ac67 100644 --- a/src/main/kotlin/com/replaymod/gradle/remap/PsiMapper.kt +++ b/src/main/kotlin/com/replaymod/gradle/remap/PsiMapper.kt @@ -18,6 +18,8 @@ import org.jetbrains.kotlin.descriptors.CallableMemberDescriptor import org.jetbrains.kotlin.descriptors.FunctionDescriptor import org.jetbrains.kotlin.js.resolve.diagnostics.findPsi import org.jetbrains.kotlin.lexer.KtTokens +import org.jetbrains.kotlin.load.java.propertyNameByGetMethodName +import org.jetbrains.kotlin.load.java.propertyNameBySetMethodName import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.psi.* import org.jetbrains.kotlin.psi.psiUtil.endOffset @@ -29,8 +31,6 @@ import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameOrNull import org.jetbrains.kotlin.resolve.descriptorUtil.getAllSuperclassesWithoutAny import org.jetbrains.kotlin.resolve.descriptorUtil.overriddenTreeAsSequence import org.jetbrains.kotlin.synthetic.SyntheticJavaPropertyDescriptor -import org.jetbrains.kotlin.synthetic.SyntheticJavaPropertyDescriptor.Companion.propertyNameByGetMethodName -import org.jetbrains.kotlin.synthetic.SyntheticJavaPropertyDescriptor.Companion.propertyNameBySetMethodName import java.util.* internal class PsiMapper( diff --git a/src/main/kotlin/com/replaymod/gradle/remap/Transformer.kt b/src/main/kotlin/com/replaymod/gradle/remap/Transformer.kt index 24f41ce..67b065e 100644 --- a/src/main/kotlin/com/replaymod/gradle/remap/Transformer.kt +++ b/src/main/kotlin/com/replaymod/gradle/remap/Transformer.kt @@ -10,8 +10,6 @@ import org.jetbrains.kotlin.cli.common.messages.MessageRenderer import org.jetbrains.kotlin.cli.common.messages.PrintingMessageCollector import org.jetbrains.kotlin.cli.jvm.compiler.EnvironmentConfigFiles import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment -import org.jetbrains.kotlin.cli.jvm.compiler.NoScopeRecordCliBindingTrace -import org.jetbrains.kotlin.cli.jvm.compiler.TopDownAnalyzerFacadeForJVM import org.jetbrains.kotlin.cli.jvm.config.JavaSourceRoot import org.jetbrains.kotlin.cli.jvm.config.JvmClasspathRoot import org.jetbrains.kotlin.com.intellij.codeInsight.CustomExceptionHandler @@ -25,7 +23,6 @@ import org.jetbrains.kotlin.com.intellij.openapi.vfs.StandardFileSystems import org.jetbrains.kotlin.com.intellij.openapi.vfs.VirtualFileManager import org.jetbrains.kotlin.com.intellij.openapi.vfs.local.CoreLocalFileSystem import org.jetbrains.kotlin.com.intellij.psi.PsiManager -import org.jetbrains.kotlin.com.intellij.psi.search.GlobalSearchScope import org.jetbrains.kotlin.config.CommonConfigurationKeys import org.jetbrains.kotlin.config.CompilerConfiguration import org.jetbrains.kotlin.config.JVMConfigurationKeys @@ -90,13 +87,11 @@ class Transformer(private val map: MappingSet) { val psiFiles = virtualFiles.mapValues { psiManager.findFile(it.value)!! } val ktFiles = psiFiles.values.filterIsInstance<KtFile>() - val analysis = TopDownAnalyzerFacadeForJVM.analyzeFilesWithJavaIntegration( - project, - ktFiles, - NoScopeRecordCliBindingTrace(), - environment.configuration, - { scope: GlobalSearchScope -> environment.createPackagePartProvider(scope) } - ) + val analysis = try { + analyze1521(environment, ktFiles) + } catch (e: NoSuchMethodError) { + analyze1620(environment, ktFiles) + } val remappedProject = remappedClasspath?.let { setupRemappedProject(disposable, it) } @@ -146,14 +141,11 @@ class Transformer(private val map: MappingSet) { config, EnvironmentConfigFiles.JVM_CONFIG_FILES ) - val project = environment.project - TopDownAnalyzerFacadeForJVM.analyzeFilesWithJavaIntegration( - project, - emptyList(), - NoScopeRecordCliBindingTrace(), - environment.configuration, - { scope: GlobalSearchScope -> environment.createPackagePartProvider(scope) } - ) + try { + analyze1521(environment, emptyList()) + } catch (e: NoSuchMethodError) { + analyze1620(environment, emptyList()) + } return environment.project } |