diff options
author | Jonas Herzig <jonas@spark-squared.com> | 2021-11-12 10:58:10 +0100 |
---|---|---|
committer | Jonas Herzig <jonas@spark-squared.com> | 2021-11-12 15:23:25 +0100 |
commit | 5723e6481d2f4e07b6820201e74924643b5687bc (patch) | |
tree | 8e91c4b8a1e2e59cac1fad71209670309b2f5153 /src/main/kotlin/com/replaymod/gradle/remap/Transformer.kt | |
parent | 0e7f8ea1d9ebd42bcd88506e771a8b5a1e9ba0b9 (diff) | |
download | Remap-5723e6481d2f4e07b6820201e74924643b5687bc.tar.gz Remap-5723e6481d2f4e07b6820201e74924643b5687bc.tar.bz2 Remap-5723e6481d2f4e07b6820201e74924643b5687bc.zip |
Fix synthetic property becoming shadowed by field of same name
Diffstat (limited to 'src/main/kotlin/com/replaymod/gradle/remap/Transformer.kt')
-rw-r--r-- | src/main/kotlin/com/replaymod/gradle/remap/Transformer.kt | 29 |
1 files changed, 28 insertions, 1 deletions
diff --git a/src/main/kotlin/com/replaymod/gradle/remap/Transformer.kt b/src/main/kotlin/com/replaymod/gradle/remap/Transformer.kt index dd4215f..0fd8093 100644 --- a/src/main/kotlin/com/replaymod/gradle/remap/Transformer.kt +++ b/src/main/kotlin/com/replaymod/gradle/remap/Transformer.kt @@ -16,8 +16,10 @@ import org.jetbrains.kotlin.cli.jvm.config.JavaSourceRoot import org.jetbrains.kotlin.cli.jvm.config.JvmClasspathRoot import org.jetbrains.kotlin.com.intellij.codeInsight.CustomExceptionHandler import org.jetbrains.kotlin.com.intellij.mock.MockProject +import org.jetbrains.kotlin.com.intellij.openapi.Disposable import org.jetbrains.kotlin.com.intellij.openapi.extensions.ExtensionPoint import org.jetbrains.kotlin.com.intellij.openapi.extensions.Extensions +import org.jetbrains.kotlin.com.intellij.openapi.project.Project import org.jetbrains.kotlin.com.intellij.openapi.util.Disposer import org.jetbrains.kotlin.com.intellij.openapi.vfs.StandardFileSystems import org.jetbrains.kotlin.com.intellij.openapi.vfs.VirtualFileManager @@ -41,6 +43,7 @@ import kotlin.system.exitProcess class Transformer(private val map: MappingSet) { var classpath: Array<String>? = null + var remappedClasspath: Array<String>? = null var patternAnnotation: String? = null @Throws(IOException::class) @@ -95,6 +98,8 @@ class Transformer(private val map: MappingSet) { { scope: GlobalSearchScope -> environment.createPackagePartProvider(scope) } ) + val remappedProject = remappedClasspath?.let { setupRemappedProject(disposable, it) } + val patterns = patternAnnotation?.let { annotationFQN -> val patterns = PsiPatterns(annotationFQN) val annotationName = annotationFQN.substring(annotationFQN.lastIndexOf('.') + 1) @@ -117,7 +122,7 @@ class Transformer(private val map: MappingSet) { val psiFile = psiManager.findFile(file)!! val mapped = try { - PsiMapper(map, psiFile, patterns).remapFile(analysis.bindingContext) + PsiMapper(map, remappedProject, psiFile, patterns).remapFile(analysis.bindingContext) } catch (e: Exception) { throw RuntimeException("Failed to map file \"$name\".", e) } @@ -130,6 +135,28 @@ class Transformer(private val map: MappingSet) { } } + private fun setupRemappedProject(disposable: Disposable, classpath: Array<String>): Project { + val config = CompilerConfiguration() + config.put(CommonConfigurationKeys.MODULE_NAME, "main") + config.addAll(CLIConfigurationKeys.CONTENT_ROOTS, classpath.map { JvmClasspathRoot(File(it)) }) + config.put(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY, PrintingMessageCollector(System.err, MessageRenderer.GRADLE_STYLE, true)) + + val environment = KotlinCoreEnvironment.createForProduction( + disposable, + config, + EnvironmentConfigFiles.JVM_CONFIG_FILES + ) + val project = environment.project + TopDownAnalyzerFacadeForJVM.analyzeFilesWithJavaIntegration( + project, + emptyList(), + NoScopeRecordCliBindingTrace(), + environment.configuration, + { scope: GlobalSearchScope -> environment.createPackagePartProvider(scope) } + ) + return environment.project + } + companion object { @Throws(IOException::class) |