From aac68af7dbad25b29531b8544c100c497146c250 Mon Sep 17 00:00:00 2001 From: Jonas Herzig Date: Tue, 10 May 2022 11:11:27 +0200 Subject: Add support for kotlin-compiler-embeddable 1.6.20 While, unlike last time, maintaining backwards compatibility with 1.5.21 (and anything in between). --- .../kotlin/com/replaymod/gradle/remap/PsiMapper.kt | 4 ++-- .../com/replaymod/gradle/remap/Transformer.kt | 28 ++++++++-------------- 2 files changed, 12 insertions(+), 20 deletions(-) (limited to 'src/main/kotlin/com/replaymod/gradle') 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() - 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 } -- cgit