mirror of
https://github.com/architectury/architectury-loom.git
synced 2026-03-28 04:07:01 -05:00
Rewrite Kotlin metadata remapping to support the latest kotlin metadata library. (#866)
This commit is contained in:
26
build.gradle
26
build.gradle
@@ -9,8 +9,8 @@ plugins {
|
||||
id 'jacoco'
|
||||
id 'codenarc'
|
||||
id "org.jetbrains.kotlin.jvm" version "1.8.0" // Must match the version included with gradle.
|
||||
id "com.diffplug.spotless" version "6.13.0"
|
||||
id "org.gradle.test-retry" version "1.5.1"
|
||||
id "com.diffplug.spotless" version "6.18.0"
|
||||
id "org.gradle.test-retry" version "1.5.2"
|
||||
}
|
||||
|
||||
tasks.withType(JavaCompile).configureEach {
|
||||
@@ -65,13 +65,13 @@ dependencies {
|
||||
// libraries
|
||||
implementation ('commons-io:commons-io:2.11.0')
|
||||
implementation ('com.google.code.gson:gson:2.10.1')
|
||||
implementation ('com.fasterxml.jackson.core:jackson-databind:2.14.1')
|
||||
implementation ('com.fasterxml.jackson.core:jackson-databind:2.14.2')
|
||||
implementation ('com.google.guava:guava:31.1-jre')
|
||||
implementation ('org.ow2.asm:asm:9.4')
|
||||
implementation ('org.ow2.asm:asm-analysis:9.4')
|
||||
implementation ('org.ow2.asm:asm-commons:9.4')
|
||||
implementation ('org.ow2.asm:asm-tree:9.4')
|
||||
implementation ('org.ow2.asm:asm-util:9.4')
|
||||
implementation ('org.ow2.asm:asm:9.5')
|
||||
implementation ('org.ow2.asm:asm-analysis:9.5')
|
||||
implementation ('org.ow2.asm:asm-commons:9.5')
|
||||
implementation ('org.ow2.asm:asm-tree:9.5')
|
||||
implementation ('org.ow2.asm:asm-util:9.5')
|
||||
|
||||
// game handling utils
|
||||
implementation ('net.fabricmc:stitch:0.6.2') {
|
||||
@@ -95,7 +95,7 @@ dependencies {
|
||||
implementation ('net.fabricmc:mercury:0.3.0')
|
||||
|
||||
// Kotlin
|
||||
implementation('org.jetbrains.kotlinx:kotlinx-metadata-jvm:0.5.0') {
|
||||
implementation('org.jetbrains.kotlinx:kotlinx-metadata-jvm:0.6.0') {
|
||||
transitive = false
|
||||
}
|
||||
|
||||
@@ -108,13 +108,13 @@ dependencies {
|
||||
exclude module: 'groovy-all'
|
||||
}
|
||||
testImplementation 'org.junit.jupiter:junit-jupiter-engine:5.9.2'
|
||||
testImplementation ('io.javalin:javalin:5.3.1') {
|
||||
testImplementation ('io.javalin:javalin:5.4.2') {
|
||||
exclude group: 'org.jetbrains.kotlin'
|
||||
}
|
||||
testImplementation 'org.mockito:mockito-core:5.0.0'
|
||||
testImplementation 'org.mockito:mockito-core:5.2.0'
|
||||
|
||||
compileOnly 'org.jetbrains:annotations:24.0.0'
|
||||
testCompileOnly 'org.jetbrains:annotations:24.0.0'
|
||||
compileOnly 'org.jetbrains:annotations:24.0.1'
|
||||
testCompileOnly 'org.jetbrains:annotations:24.0.1'
|
||||
|
||||
testCompileOnly ('net.fabricmc:sponge-mixin:0.11.4+mixin.0.8.5') {
|
||||
transitive = false
|
||||
|
||||
@@ -0,0 +1,271 @@
|
||||
/*
|
||||
* This file is part of fabric-loom, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) 2023 FabricMC
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package net.fabricmc.loom.kotlin.remapping;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import kotlinx.metadata.KmAnnotation;
|
||||
import kotlinx.metadata.KmProperty;
|
||||
import kotlinx.metadata.internal.extensions.KmClassExtension;
|
||||
import kotlinx.metadata.internal.extensions.KmConstructorExtension;
|
||||
import kotlinx.metadata.internal.extensions.KmFunctionExtension;
|
||||
import kotlinx.metadata.internal.extensions.KmPackageExtension;
|
||||
import kotlinx.metadata.internal.extensions.KmPropertyExtension;
|
||||
import kotlinx.metadata.internal.extensions.KmTypeExtension;
|
||||
import kotlinx.metadata.internal.extensions.KmTypeParameterExtension;
|
||||
import kotlinx.metadata.jvm.JvmFieldSignature;
|
||||
import kotlinx.metadata.jvm.JvmMethodSignature;
|
||||
import kotlinx.metadata.jvm.internal.JvmClassExtension;
|
||||
import kotlinx.metadata.jvm.internal.JvmConstructorExtension;
|
||||
import kotlinx.metadata.jvm.internal.JvmFunctionExtension;
|
||||
import kotlinx.metadata.jvm.internal.JvmPackageExtension;
|
||||
import kotlinx.metadata.jvm.internal.JvmPropertyExtension;
|
||||
import kotlinx.metadata.jvm.internal.JvmTypeExtension;
|
||||
import kotlinx.metadata.jvm.internal.JvmTypeParameterExtension;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/*
|
||||
* This is a fun meme. All of these kotlin classes are marked as "internal" so Kotlin code cannot compile against them.
|
||||
* However, luckily for us the Java compiler has no idea about this, so they can compile against it :D
|
||||
*
|
||||
* This file contains Java wrappers around Kotlin classes, to used by Kotlin.
|
||||
*/
|
||||
public interface JvmExtensionWrapper {
|
||||
record Class(JvmClassExtension extension) implements JvmExtensionWrapper {
|
||||
@Nullable
|
||||
public static Class get(KmClassExtension classExtension) {
|
||||
if (classExtension instanceof JvmClassExtension jvmClassExtension) {
|
||||
return new Class(jvmClassExtension);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public List<KmProperty> getLocalDelegatedProperties() {
|
||||
return extension.getLocalDelegatedProperties();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public String getModuleName() {
|
||||
return extension.getModuleName();
|
||||
}
|
||||
|
||||
public void setModuleName(@Nullable String name) {
|
||||
extension.setModuleName(name);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public String getAnonymousObjectOriginName() {
|
||||
return extension.getAnonymousObjectOriginName();
|
||||
}
|
||||
|
||||
public void setAnonymousObjectOriginName(@Nullable String name) {
|
||||
extension.setAnonymousObjectOriginName(name);
|
||||
}
|
||||
|
||||
public int getJvmFlags() {
|
||||
return extension.getJvmFlags();
|
||||
}
|
||||
|
||||
public void setJvmFlags(int flags) {
|
||||
extension.setJvmFlags(flags);
|
||||
}
|
||||
}
|
||||
|
||||
record Package(JvmPackageExtension extension) {
|
||||
@Nullable
|
||||
public static Package get(KmPackageExtension packageExtension) {
|
||||
if (packageExtension instanceof JvmPackageExtension jvmPackageExtension) {
|
||||
return new Package(jvmPackageExtension);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public List<KmProperty> getLocalDelegatedProperties() {
|
||||
return extension.getLocalDelegatedProperties();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public String getModuleName() {
|
||||
return extension.getModuleName();
|
||||
}
|
||||
|
||||
public void setModuleName(@Nullable String name) {
|
||||
extension.setModuleName(name);
|
||||
}
|
||||
}
|
||||
|
||||
record Function(JvmFunctionExtension extension) {
|
||||
@Nullable
|
||||
public static Function get(KmFunctionExtension functionExtension) {
|
||||
if (functionExtension instanceof JvmFunctionExtension jvmFunctionExtension) {
|
||||
return new Function(jvmFunctionExtension);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public JvmMethodSignature getSignature() {
|
||||
return extension.getSignature();
|
||||
}
|
||||
|
||||
public void setSignature(@Nullable JvmMethodSignature signature) {
|
||||
extension.setSignature(signature);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public String getLambdaClassOriginName() {
|
||||
return extension.getLambdaClassOriginName();
|
||||
}
|
||||
|
||||
public void setLambdaClassOriginName(@Nullable String name) {
|
||||
extension.setLambdaClassOriginName(name);
|
||||
}
|
||||
}
|
||||
|
||||
record Property(JvmPropertyExtension extension) {
|
||||
@Nullable
|
||||
public static Property get(KmPropertyExtension propertyExtension) {
|
||||
if (propertyExtension instanceof JvmPropertyExtension jvmPropertyExtension) {
|
||||
return new Property(jvmPropertyExtension);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public int getJvmFlags() {
|
||||
return extension.getJvmFlags();
|
||||
}
|
||||
|
||||
public void setJvmFlags(int flags) {
|
||||
extension.setJvmFlags(flags);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public JvmFieldSignature getFieldSignature() {
|
||||
return extension.getFieldSignature();
|
||||
}
|
||||
|
||||
public void setFieldSignature(@Nullable JvmFieldSignature signature) {
|
||||
extension.setFieldSignature(signature);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public JvmMethodSignature getGetterSignature() {
|
||||
return extension.getGetterSignature();
|
||||
}
|
||||
|
||||
public void setGetterSignature(@Nullable JvmMethodSignature signature) {
|
||||
extension.setGetterSignature(signature);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public JvmMethodSignature getSetterSignature() {
|
||||
return extension.getSetterSignature();
|
||||
}
|
||||
|
||||
public void setSetterSignature(@Nullable JvmMethodSignature signature) {
|
||||
extension.setSetterSignature(signature);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public JvmMethodSignature getSyntheticMethodForAnnotations() {
|
||||
return extension.getSyntheticMethodForAnnotations();
|
||||
}
|
||||
|
||||
public void setSyntheticMethodForAnnotations(@Nullable JvmMethodSignature signature) {
|
||||
extension.setSyntheticMethodForAnnotations(signature);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public JvmMethodSignature getSyntheticMethodForDelegate() {
|
||||
return extension.getSyntheticMethodForDelegate();
|
||||
}
|
||||
|
||||
public void setSyntheticMethodForDelegate(@Nullable JvmMethodSignature signature) {
|
||||
extension.setSyntheticMethodForDelegate(signature);
|
||||
}
|
||||
}
|
||||
|
||||
record Constructor(JvmConstructorExtension extension) {
|
||||
@Nullable
|
||||
public static Constructor get(KmConstructorExtension constructorExtension) {
|
||||
if (constructorExtension instanceof JvmConstructorExtension jvmConstructorExtension) {
|
||||
return new Constructor(jvmConstructorExtension);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public JvmMethodSignature getSignature() {
|
||||
return extension.getSignature();
|
||||
}
|
||||
|
||||
public void setSignature(@Nullable JvmMethodSignature signature) {
|
||||
extension.setSignature(signature);
|
||||
}
|
||||
}
|
||||
|
||||
record TypeParameter(JvmTypeParameterExtension extension) {
|
||||
@Nullable
|
||||
public static TypeParameter get(KmTypeParameterExtension typeParameterExtension) {
|
||||
if (typeParameterExtension instanceof JvmTypeParameterExtension jvmTypeParameterExtension) {
|
||||
return new TypeParameter(jvmTypeParameterExtension);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public List<KmAnnotation> getAnnotations() {
|
||||
return extension.getAnnotations();
|
||||
}
|
||||
}
|
||||
|
||||
record Type(JvmTypeExtension extension) {
|
||||
@Nullable
|
||||
public static Type get(KmTypeExtension typeExtension) {
|
||||
if (typeExtension instanceof JvmTypeExtension jvmTypeExtension) {
|
||||
return new Type(jvmTypeExtension);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean isRaw() {
|
||||
return extension.isRaw();
|
||||
}
|
||||
|
||||
public void setRaw(boolean raw) {
|
||||
extension.setRaw(raw);
|
||||
}
|
||||
|
||||
public List<KmAnnotation> getAnnotations() {
|
||||
return extension.getAnnotations();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -104,7 +104,7 @@ public class Constants {
|
||||
public static final String MIXIN_COMPILE_EXTENSIONS = "0.6.0";
|
||||
public static final String DEV_LAUNCH_INJECTOR = "0.2.1+build.8";
|
||||
public static final String TERMINAL_CONSOLE_APPENDER = "1.2.0";
|
||||
public static final String JETBRAINS_ANNOTATIONS = "24.0.0";
|
||||
public static final String JETBRAINS_ANNOTATIONS = "24.0.1";
|
||||
public static final String NATIVE_SUPPORT_VERSION = "1.0.1";
|
||||
|
||||
private Versions() {
|
||||
|
||||
@@ -55,6 +55,6 @@ public class KotlinPluginUtils {
|
||||
}
|
||||
|
||||
public static String getKotlinMetadataVersion() {
|
||||
return KotlinClassMetadata.class.getPackage().getImplementationVersion();
|
||||
return KotlinClassMetadata.class.getPackage().getImplementationVersion().split("-")[0];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,6 +31,7 @@ import java.util.List;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import net.fabricmc.loom.LoomGradlePlugin;
|
||||
import net.fabricmc.loom.kotlin.remapping.JvmExtensionWrapper;
|
||||
import net.fabricmc.loom.kotlin.remapping.KotlinMetadataTinyRemapperExtensionImpl;
|
||||
|
||||
/**
|
||||
@@ -61,7 +62,8 @@ public class KotlinRemapperClassloader extends URLClassLoader {
|
||||
public static KotlinRemapperClassloader create(KotlinClasspath classpathProvider) {
|
||||
// Include the libraries that are not on the kotlin classpath.
|
||||
final Stream<URL> loomUrls = getClassUrls(
|
||||
KotlinMetadataTinyRemapperExtensionImpl.class // Loom
|
||||
KotlinMetadataTinyRemapperExtensionImpl.class, // Loom (Kotlin)
|
||||
JvmExtensionWrapper.class // Loom (Java)
|
||||
);
|
||||
|
||||
final URL[] urls = Stream.concat(
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* This file is part of fabric-loom, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) 2022 FabricMC
|
||||
* Copyright (c) 2022-2023 FabricMC
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
@@ -24,8 +24,8 @@
|
||||
|
||||
package net.fabricmc.loom.kotlin.remapping
|
||||
|
||||
import kotlinx.metadata.jvm.KotlinClassHeader
|
||||
import kotlinx.metadata.jvm.KotlinClassMetadata
|
||||
import kotlinx.metadata.jvm.Metadata
|
||||
import org.objectweb.asm.AnnotationVisitor
|
||||
import org.objectweb.asm.Opcodes
|
||||
import org.objectweb.asm.commons.Remapper
|
||||
@@ -58,20 +58,18 @@ class KotlinClassMetadataRemappingAnnotationVisitor(private val remapper: Remapp
|
||||
|
||||
when (val metadata = KotlinClassMetadata.read(header)) {
|
||||
is KotlinClassMetadata.Class -> {
|
||||
val klass = metadata.toKmClass()
|
||||
val writer = KotlinClassMetadata.Class.Writer()
|
||||
klass.accept(RemappingKmVisitors(remapper).RemappingKmClassVisitor(writer))
|
||||
val remapped = writer.write(header.metadataVersion, header.extraInt).header
|
||||
var klass = metadata.toKmClass()
|
||||
klass = KotlinClassRemapper(remapper).remap(klass)
|
||||
val remapped = KotlinClassMetadata.writeClass(klass, header.metadataVersion, header.extraInt).annotationData
|
||||
writeClassHeader(remapped)
|
||||
validateKotlinClassHeader(remapped, header)
|
||||
}
|
||||
is KotlinClassMetadata.SyntheticClass -> {
|
||||
val klambda = metadata.toKmLambda()
|
||||
var klambda = metadata.toKmLambda()
|
||||
|
||||
if (klambda != null) {
|
||||
val writer = KotlinClassMetadata.SyntheticClass.Writer()
|
||||
klambda.accept(RemappingKmVisitors(remapper).RemappingKmLambdaVisitor(writer))
|
||||
val remapped = writer.write(header.metadataVersion, header.extraInt).header
|
||||
klambda = KotlinClassRemapper(remapper).remap(klambda)
|
||||
val remapped = KotlinClassMetadata.writeLambda(klambda, header.metadataVersion, header.extraInt).annotationData
|
||||
writeClassHeader(remapped)
|
||||
validateKotlinClassHeader(remapped, header)
|
||||
} else {
|
||||
@@ -79,18 +77,16 @@ class KotlinClassMetadataRemappingAnnotationVisitor(private val remapper: Remapp
|
||||
}
|
||||
}
|
||||
is KotlinClassMetadata.FileFacade -> {
|
||||
val kpackage = metadata.toKmPackage()
|
||||
val writer = KotlinClassMetadata.FileFacade.Writer()
|
||||
kpackage.accept(RemappingKmVisitors(remapper).RemappingKmPackageVisitor(writer))
|
||||
val remapped = writer.write(header.metadataVersion, header.extraInt).header
|
||||
var kpackage = metadata.toKmPackage()
|
||||
kpackage = KotlinClassRemapper(remapper).remap(kpackage)
|
||||
val remapped = KotlinClassMetadata.writeFileFacade(kpackage, header.metadataVersion, header.extraInt).annotationData
|
||||
writeClassHeader(remapped)
|
||||
validateKotlinClassHeader(remapped, header)
|
||||
}
|
||||
is KotlinClassMetadata.MultiFileClassPart -> {
|
||||
val kpackage = metadata.toKmPackage()
|
||||
val writer = KotlinClassMetadata.MultiFileClassPart.Writer()
|
||||
kpackage.accept(RemappingKmVisitors(remapper).RemappingKmPackageVisitor(writer))
|
||||
val remapped = writer.write(metadata.facadeClassName, metadata.header.metadataVersion, metadata.header.extraInt).header
|
||||
var kpackage = metadata.toKmPackage()
|
||||
kpackage = KotlinClassRemapper(remapper).remap(kpackage)
|
||||
val remapped = KotlinClassMetadata.writeMultiFileClassPart(kpackage, metadata.facadeClassName, metadata.annotationData.metadataVersion, metadata.annotationData.extraInt).annotationData
|
||||
writeClassHeader(remapped)
|
||||
validateKotlinClassHeader(remapped, header)
|
||||
}
|
||||
@@ -102,7 +98,7 @@ class KotlinClassMetadataRemappingAnnotationVisitor(private val remapper: Remapp
|
||||
}
|
||||
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
private fun readHeader(): KotlinClassHeader? {
|
||||
private fun readHeader(): Metadata? {
|
||||
var kind: Int? = null
|
||||
var metadataVersion: IntArray? = null
|
||||
var data1: Array<String>? = null
|
||||
@@ -127,10 +123,10 @@ class KotlinClassMetadataRemappingAnnotationVisitor(private val remapper: Remapp
|
||||
}
|
||||
}
|
||||
|
||||
return KotlinClassHeader(kind, metadataVersion, data1, data2, extraString, packageName, extraInt)
|
||||
return Metadata(kind, metadataVersion, data1, data2, extraString, packageName, extraInt)
|
||||
}
|
||||
|
||||
private fun writeClassHeader(header: KotlinClassHeader) {
|
||||
private fun writeClassHeader(header: Metadata) {
|
||||
val newNode = AnnotationNode(api, desc)
|
||||
newNode.values = this.values.toMutableList()
|
||||
|
||||
@@ -151,7 +147,7 @@ class KotlinClassMetadataRemappingAnnotationVisitor(private val remapper: Remapp
|
||||
newNode.accept(next)
|
||||
}
|
||||
|
||||
private fun validateKotlinClassHeader(remapped: KotlinClassHeader, original: KotlinClassHeader) {
|
||||
private fun validateKotlinClassHeader(remapped: Metadata, original: Metadata) {
|
||||
// This can happen when the remapper is ran on a kotlin version that does not match the version the class was compiled with.
|
||||
if (remapped.data2.size != original.data2.size) {
|
||||
logger.info("Kotlin class metadata size mismatch: data2 size does not match original in class $className. New: ${remapped.data2.size} Old: ${original.data2.size}")
|
||||
|
||||
@@ -0,0 +1,250 @@
|
||||
/*
|
||||
* This file is part of fabric-loom, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) 2023 FabricMC
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package net.fabricmc.loom.kotlin.remapping
|
||||
|
||||
import kotlinx.metadata.ClassName
|
||||
import kotlinx.metadata.ExperimentalContextReceivers
|
||||
import kotlinx.metadata.KmAnnotation
|
||||
import kotlinx.metadata.KmClass
|
||||
import kotlinx.metadata.KmClassifier
|
||||
import kotlinx.metadata.KmConstructor
|
||||
import kotlinx.metadata.KmFlexibleTypeUpperBound
|
||||
import kotlinx.metadata.KmFunction
|
||||
import kotlinx.metadata.KmLambda
|
||||
import kotlinx.metadata.KmPackage
|
||||
import kotlinx.metadata.KmProperty
|
||||
import kotlinx.metadata.KmType
|
||||
import kotlinx.metadata.KmTypeAlias
|
||||
import kotlinx.metadata.KmTypeParameter
|
||||
import kotlinx.metadata.KmTypeProjection
|
||||
import kotlinx.metadata.KmValueParameter
|
||||
import kotlinx.metadata.internal.extensions.KmClassExtension
|
||||
import kotlinx.metadata.internal.extensions.KmConstructorExtension
|
||||
import kotlinx.metadata.internal.extensions.KmFunctionExtension
|
||||
import kotlinx.metadata.internal.extensions.KmPackageExtension
|
||||
import kotlinx.metadata.internal.extensions.KmPropertyExtension
|
||||
import kotlinx.metadata.internal.extensions.KmTypeAliasExtension
|
||||
import kotlinx.metadata.internal.extensions.KmTypeExtension
|
||||
import kotlinx.metadata.internal.extensions.KmTypeParameterExtension
|
||||
import kotlinx.metadata.internal.extensions.KmValueParameterExtension
|
||||
import kotlinx.metadata.isLocal
|
||||
import kotlinx.metadata.jvm.JvmFieldSignature
|
||||
import kotlinx.metadata.jvm.JvmMethodSignature
|
||||
import kotlinx.metadata.jvm.jvmInternalName
|
||||
import org.objectweb.asm.commons.Remapper
|
||||
|
||||
@OptIn(ExperimentalContextReceivers::class)
|
||||
class KotlinClassRemapper(private val remapper: Remapper) {
|
||||
fun remap(clazz: KmClass): KmClass {
|
||||
clazz.name = remap(clazz.name)
|
||||
clazz.typeParameters.replaceAll(this::remap)
|
||||
clazz.supertypes.replaceAll(this::remap)
|
||||
clazz.functions.replaceAll(this::remap)
|
||||
clazz.properties.replaceAll(this::remap)
|
||||
clazz.typeAliases.replaceAll(this::remap)
|
||||
clazz.constructors.replaceAll(this::remap)
|
||||
clazz.nestedClasses.replaceAll(this::remap)
|
||||
clazz.sealedSubclasses.replaceAll(this::remap)
|
||||
clazz.contextReceiverTypes.replaceAll(this::remap)
|
||||
clazz.getExtensions().replaceAll(this::remap)
|
||||
return clazz
|
||||
}
|
||||
|
||||
fun remap(lambda: KmLambda): KmLambda {
|
||||
lambda.function = remap(lambda.function)
|
||||
return lambda
|
||||
}
|
||||
|
||||
fun remap(pkg: KmPackage): KmPackage {
|
||||
pkg.functions.replaceAll(this::remap)
|
||||
pkg.properties.replaceAll(this::remap)
|
||||
pkg.typeAliases.replaceAll(this::remap)
|
||||
pkg.getExtensions().replaceAll(this::remap)
|
||||
return pkg
|
||||
}
|
||||
|
||||
private fun remap(name: ClassName): ClassName {
|
||||
val local = name.isLocal
|
||||
val remapped = remapper.map(name.jvmInternalName).replace('$', '.')
|
||||
|
||||
if (local) {
|
||||
return ".$remapped"
|
||||
}
|
||||
|
||||
return remapped
|
||||
}
|
||||
|
||||
private fun remap(type: KmType): KmType {
|
||||
type.classifier = when (val classifier = type.classifier) {
|
||||
is KmClassifier.Class -> KmClassifier.Class(remap(classifier.name))
|
||||
is KmClassifier.TypeParameter -> KmClassifier.TypeParameter(classifier.id)
|
||||
is KmClassifier.TypeAlias -> KmClassifier.TypeAlias(remap(classifier.name))
|
||||
}
|
||||
type.arguments.replaceAll(this::remap)
|
||||
type.abbreviatedType = type.abbreviatedType?.let { remap(it) }
|
||||
type.outerType = type.outerType?.let { remap(it) }
|
||||
type.flexibleTypeUpperBound = type.flexibleTypeUpperBound?.let { remap(it) }
|
||||
type.getExtensions().replaceAll(this::remap)
|
||||
return type
|
||||
}
|
||||
|
||||
private fun remap(function: KmFunction): KmFunction {
|
||||
function.typeParameters.replaceAll(this::remap)
|
||||
function.receiverParameterType = function.receiverParameterType?.let { remap(it) }
|
||||
function.contextReceiverTypes.replaceAll(this::remap)
|
||||
function.valueParameters.replaceAll(this::remap)
|
||||
function.returnType = remap(function.returnType)
|
||||
function.getExtensions().replaceAll(this::remap)
|
||||
return function
|
||||
}
|
||||
|
||||
private fun remap(property: KmProperty): KmProperty {
|
||||
property.typeParameters.replaceAll(this::remap)
|
||||
property.receiverParameterType = property.receiverParameterType?.let { remap(it) }
|
||||
property.contextReceiverTypes.replaceAll(this::remap)
|
||||
property.setterParameter = property.setterParameter?.let { remap(it) }
|
||||
property.returnType = remap(property.returnType)
|
||||
property.getExtensions().replaceAll(this::remap)
|
||||
return property
|
||||
}
|
||||
|
||||
private fun remap(typeAlias: KmTypeAlias): KmTypeAlias {
|
||||
typeAlias.typeParameters.replaceAll(this::remap)
|
||||
typeAlias.underlyingType = remap(typeAlias.underlyingType)
|
||||
typeAlias.expandedType = remap(typeAlias.expandedType)
|
||||
typeAlias.annotations.replaceAll(this::remap)
|
||||
typeAlias.getExtensions().replaceAll(this::remap)
|
||||
return typeAlias
|
||||
}
|
||||
|
||||
private fun remap(constructor: KmConstructor): KmConstructor {
|
||||
constructor.valueParameters.replaceAll(this::remap)
|
||||
constructor.getExtensions().replaceAll(this::remap)
|
||||
return constructor
|
||||
}
|
||||
|
||||
private fun remap(typeParameter: KmTypeParameter): KmTypeParameter {
|
||||
typeParameter.upperBounds.replaceAll(this::remap)
|
||||
typeParameter.getExtensions().replaceAll(this::remap)
|
||||
return typeParameter
|
||||
}
|
||||
|
||||
private fun remap(typeProjection: KmTypeProjection): KmTypeProjection {
|
||||
return KmTypeProjection(typeProjection.variance, typeProjection.type?.let { remap(it) })
|
||||
}
|
||||
|
||||
private fun remap(flexibleTypeUpperBound: KmFlexibleTypeUpperBound): KmFlexibleTypeUpperBound {
|
||||
return KmFlexibleTypeUpperBound(remap(flexibleTypeUpperBound.type), flexibleTypeUpperBound.typeFlexibilityId)
|
||||
}
|
||||
|
||||
private fun remap(valueParameter: KmValueParameter): KmValueParameter {
|
||||
valueParameter.type = remap(valueParameter.type)
|
||||
valueParameter.varargElementType = valueParameter.varargElementType?.let { remap(it) }
|
||||
valueParameter.getExtensions().replaceAll(this::remap)
|
||||
return valueParameter
|
||||
}
|
||||
|
||||
private fun remap(annotation: KmAnnotation): KmAnnotation {
|
||||
return KmAnnotation(remap(annotation.className), annotation.arguments)
|
||||
}
|
||||
|
||||
private fun remap(classExtension: KmClassExtension): KmClassExtension {
|
||||
JvmExtensionWrapper.Class.get(classExtension)?.let {
|
||||
it.localDelegatedProperties.replaceAll(this::remap)
|
||||
return it.extension
|
||||
}
|
||||
|
||||
return classExtension
|
||||
}
|
||||
|
||||
private fun remap(packageExtension: KmPackageExtension): KmPackageExtension {
|
||||
JvmExtensionWrapper.Package.get(packageExtension)?.let {
|
||||
it.localDelegatedProperties.replaceAll(this::remap)
|
||||
return it.extension
|
||||
}
|
||||
|
||||
return packageExtension
|
||||
}
|
||||
|
||||
private fun remap(typeExtension: KmTypeExtension): KmTypeExtension {
|
||||
JvmExtensionWrapper.Type.get(typeExtension)?.let {
|
||||
it.annotations.replaceAll(this::remap)
|
||||
return it.extension
|
||||
}
|
||||
|
||||
return typeExtension
|
||||
}
|
||||
|
||||
private fun remap(functionExtension: KmFunctionExtension): KmFunctionExtension {
|
||||
JvmExtensionWrapper.Function.get(functionExtension)?.let {
|
||||
it.signature = it.signature?.let { sig -> remap(sig) }
|
||||
return it.extension
|
||||
}
|
||||
|
||||
return functionExtension
|
||||
}
|
||||
|
||||
private fun remap(propertyExtension: KmPropertyExtension): KmPropertyExtension {
|
||||
JvmExtensionWrapper.Property.get(propertyExtension)?.let {
|
||||
it.fieldSignature = it.fieldSignature?.let { sig -> remap(sig) }
|
||||
it.getterSignature = it.getterSignature?.let { sig -> remap(sig) }
|
||||
it.setterSignature = it.setterSignature?.let { sig -> remap(sig) }
|
||||
it.syntheticMethodForAnnotations = it.syntheticMethodForAnnotations?.let { sig -> remap(sig) }
|
||||
it.syntheticMethodForDelegate = it.syntheticMethodForDelegate?.let { sig -> remap(sig) }
|
||||
return it.extension
|
||||
}
|
||||
|
||||
return propertyExtension
|
||||
}
|
||||
|
||||
private fun remap(typeAliasExtension: KmTypeAliasExtension): KmTypeAliasExtension {
|
||||
return typeAliasExtension
|
||||
}
|
||||
|
||||
private fun remap(typeParameterExtension: KmTypeParameterExtension): KmTypeParameterExtension {
|
||||
return typeParameterExtension
|
||||
}
|
||||
|
||||
private fun remap(valueParameterExtension: KmValueParameterExtension): KmValueParameterExtension {
|
||||
return valueParameterExtension
|
||||
}
|
||||
|
||||
private fun remap(constructorExtension: KmConstructorExtension): KmConstructorExtension {
|
||||
JvmExtensionWrapper.Constructor.get(constructorExtension)?.let {
|
||||
it.signature = it.signature?.let { sig -> remap(sig) }
|
||||
return it.extension
|
||||
}
|
||||
|
||||
return constructorExtension
|
||||
}
|
||||
|
||||
private fun remap(signature: JvmMethodSignature): JvmMethodSignature {
|
||||
return JvmMethodSignature(signature.name, remapper.mapMethodDesc(signature.desc))
|
||||
}
|
||||
|
||||
private fun remap(signature: JvmFieldSignature): JvmFieldSignature {
|
||||
return JvmFieldSignature(signature.name, remapper.mapDesc(signature.desc))
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,100 @@
|
||||
/*
|
||||
* This file is part of fabric-loom, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) 2023 FabricMC
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
@file:Suppress("UNCHECKED_CAST")
|
||||
|
||||
package net.fabricmc.loom.kotlin.remapping
|
||||
|
||||
import kotlinx.metadata.KmClass
|
||||
import kotlinx.metadata.KmConstructor
|
||||
import kotlinx.metadata.KmFunction
|
||||
import kotlinx.metadata.KmPackage
|
||||
import kotlinx.metadata.KmProperty
|
||||
import kotlinx.metadata.KmType
|
||||
import kotlinx.metadata.KmTypeAlias
|
||||
import kotlinx.metadata.KmTypeParameter
|
||||
import kotlinx.metadata.KmValueParameter
|
||||
import kotlinx.metadata.internal.extensions.KmClassExtension
|
||||
import kotlinx.metadata.internal.extensions.KmConstructorExtension
|
||||
import kotlinx.metadata.internal.extensions.KmFunctionExtension
|
||||
import kotlinx.metadata.internal.extensions.KmPackageExtension
|
||||
import kotlinx.metadata.internal.extensions.KmPropertyExtension
|
||||
import kotlinx.metadata.internal.extensions.KmTypeAliasExtension
|
||||
import kotlinx.metadata.internal.extensions.KmTypeExtension
|
||||
import kotlinx.metadata.internal.extensions.KmTypeParameterExtension
|
||||
import kotlinx.metadata.internal.extensions.KmValueParameterExtension
|
||||
import java.lang.reflect.Field
|
||||
import kotlin.reflect.KClass
|
||||
|
||||
val KM_CLASS_EXTENSIONS = getField(KmClass::class)
|
||||
val KM_PACKAGE_EXTENSIONS = getField(KmPackage::class)
|
||||
val KM_TYPE_EXTENSIONS = getField(KmType::class)
|
||||
val KM_FUNCTION_EXTENSIONS = getField(KmFunction::class)
|
||||
val KM_PROPERTY_EXTENSIONS = getField(KmProperty::class)
|
||||
val KM_TYPE_ALIAS_EXTENSIONS = getField(KmTypeAlias::class)
|
||||
val KM_TYPE_PARAMETER_EXTENSIONS = getField(KmTypeParameter::class)
|
||||
val KM_VALUE_PARAMETER_EXTENSIONS = getField(KmValueParameter::class)
|
||||
val KM_CONSTRUCTOR_EXTENSIONS = getField(KmConstructor::class)
|
||||
|
||||
fun KmClass.getExtensions(): MutableList<KmClassExtension> {
|
||||
return KM_CLASS_EXTENSIONS.get(this) as MutableList<KmClassExtension>
|
||||
}
|
||||
|
||||
fun KmPackage.getExtensions(): MutableList<KmPackageExtension> {
|
||||
return KM_PACKAGE_EXTENSIONS.get(this) as MutableList<KmPackageExtension>
|
||||
}
|
||||
|
||||
fun KmType.getExtensions(): MutableList<KmTypeExtension> {
|
||||
return KM_TYPE_EXTENSIONS.get(this) as MutableList<KmTypeExtension>
|
||||
}
|
||||
|
||||
fun KmFunction.getExtensions(): MutableList<KmFunctionExtension> {
|
||||
return KM_FUNCTION_EXTENSIONS.get(this) as MutableList<KmFunctionExtension>
|
||||
}
|
||||
|
||||
fun KmProperty.getExtensions(): MutableList<KmPropertyExtension> {
|
||||
return KM_PROPERTY_EXTENSIONS.get(this) as MutableList<KmPropertyExtension>
|
||||
}
|
||||
|
||||
fun KmTypeAlias.getExtensions(): MutableList<KmTypeAliasExtension> {
|
||||
return KM_TYPE_ALIAS_EXTENSIONS.get(this) as MutableList<KmTypeAliasExtension>
|
||||
}
|
||||
|
||||
fun KmTypeParameter.getExtensions(): MutableList<KmTypeParameterExtension> {
|
||||
return KM_TYPE_PARAMETER_EXTENSIONS.get(this) as MutableList<KmTypeParameterExtension>
|
||||
}
|
||||
|
||||
fun KmValueParameter.getExtensions(): MutableList<KmValueParameterExtension> {
|
||||
return KM_VALUE_PARAMETER_EXTENSIONS.get(this) as MutableList<KmValueParameterExtension>
|
||||
}
|
||||
|
||||
fun KmConstructor.getExtensions(): MutableList<KmConstructorExtension> {
|
||||
return KM_CONSTRUCTOR_EXTENSIONS.get(this) as MutableList<KmConstructorExtension>
|
||||
}
|
||||
|
||||
private fun getField(clazz: KClass<*>): Field {
|
||||
val field = clazz.java.getDeclaredField("extensions")
|
||||
field.isAccessible = true
|
||||
return field
|
||||
}
|
||||
@@ -1,405 +0,0 @@
|
||||
/*
|
||||
* This file is part of fabric-loom, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) 2022 FabricMC
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package net.fabricmc.loom.kotlin.remapping
|
||||
|
||||
import kotlinx.metadata.ClassName
|
||||
import kotlinx.metadata.Flags
|
||||
import kotlinx.metadata.KmAnnotation
|
||||
import kotlinx.metadata.KmClassExtensionVisitor
|
||||
import kotlinx.metadata.KmClassVisitor
|
||||
import kotlinx.metadata.KmConstructorExtensionVisitor
|
||||
import kotlinx.metadata.KmConstructorVisitor
|
||||
import kotlinx.metadata.KmContractVisitor
|
||||
import kotlinx.metadata.KmEffectExpressionVisitor
|
||||
import kotlinx.metadata.KmEffectInvocationKind
|
||||
import kotlinx.metadata.KmEffectType
|
||||
import kotlinx.metadata.KmEffectVisitor
|
||||
import kotlinx.metadata.KmExtensionType
|
||||
import kotlinx.metadata.KmFunctionExtensionVisitor
|
||||
import kotlinx.metadata.KmFunctionVisitor
|
||||
import kotlinx.metadata.KmLambdaVisitor
|
||||
import kotlinx.metadata.KmPackageExtensionVisitor
|
||||
import kotlinx.metadata.KmPackageVisitor
|
||||
import kotlinx.metadata.KmPropertyExtensionVisitor
|
||||
import kotlinx.metadata.KmPropertyVisitor
|
||||
import kotlinx.metadata.KmTypeAliasVisitor
|
||||
import kotlinx.metadata.KmTypeExtensionVisitor
|
||||
import kotlinx.metadata.KmTypeParameterExtensionVisitor
|
||||
import kotlinx.metadata.KmTypeParameterVisitor
|
||||
import kotlinx.metadata.KmTypeVisitor
|
||||
import kotlinx.metadata.KmValueParameterVisitor
|
||||
import kotlinx.metadata.KmVariance
|
||||
import kotlinx.metadata.jvm.JvmClassExtensionVisitor
|
||||
import kotlinx.metadata.jvm.JvmConstructorExtensionVisitor
|
||||
import kotlinx.metadata.jvm.JvmFieldSignature
|
||||
import kotlinx.metadata.jvm.JvmFunctionExtensionVisitor
|
||||
import kotlinx.metadata.jvm.JvmMethodSignature
|
||||
import kotlinx.metadata.jvm.JvmPackageExtensionVisitor
|
||||
import kotlinx.metadata.jvm.JvmPropertyExtensionVisitor
|
||||
import kotlinx.metadata.jvm.JvmTypeExtensionVisitor
|
||||
import kotlinx.metadata.jvm.JvmTypeParameterExtensionVisitor
|
||||
import org.objectweb.asm.commons.Remapper
|
||||
|
||||
class RemappingKmVisitors(private val remapper: Remapper) {
|
||||
private fun remapJvmMethodSignature(signature: JvmMethodSignature?): JvmMethodSignature? {
|
||||
if (signature != null) {
|
||||
return JvmMethodSignature(signature.name, remapper.mapMethodDesc(signature.desc))
|
||||
}
|
||||
|
||||
return null
|
||||
}
|
||||
|
||||
private fun remapJvmFieldSignature(signature: JvmFieldSignature?): JvmFieldSignature? {
|
||||
if (signature != null) {
|
||||
return JvmFieldSignature(signature.name, remapper.mapDesc(signature.desc))
|
||||
}
|
||||
|
||||
return null
|
||||
}
|
||||
|
||||
inner class RemappingKmClassVisitor(delegate: KmClassVisitor?) : KmClassVisitor(delegate) {
|
||||
override fun visit(flags: Flags, name: ClassName) {
|
||||
super.visit(flags, remapper.map(name))
|
||||
}
|
||||
|
||||
override fun visitNestedClass(name: String) {
|
||||
super.visitNestedClass(remapper.map(name))
|
||||
}
|
||||
|
||||
override fun visitSealedSubclass(name: ClassName) {
|
||||
super.visitSealedSubclass(remapper.map(name))
|
||||
}
|
||||
|
||||
override fun visitSupertype(flags: Flags): KmTypeVisitor {
|
||||
return RemappingKmTypeVisitor(super.visitSupertype(flags))
|
||||
}
|
||||
|
||||
override fun visitFunction(flags: Flags, name: String): KmFunctionVisitor {
|
||||
return RemappingKmFunctionVisitor(super.visitFunction(flags, name))
|
||||
}
|
||||
|
||||
override fun visitInlineClassUnderlyingType(flags: Flags): KmTypeVisitor {
|
||||
return RemappingKmTypeVisitor(super.visitInlineClassUnderlyingType(flags))
|
||||
}
|
||||
|
||||
override fun visitProperty(flags: Flags, name: String, getterFlags: Flags, setterFlags: Flags): KmPropertyVisitor {
|
||||
return RemappingKmPropertyVisitor(super.visitProperty(flags, name, getterFlags, setterFlags))
|
||||
}
|
||||
|
||||
override fun visitTypeAlias(flags: Flags, name: String): KmTypeAliasVisitor {
|
||||
return RemappingKmTypeAliasVisitor(super.visitTypeAlias(flags, name))
|
||||
}
|
||||
|
||||
override fun visitConstructor(flags: Flags): KmConstructorVisitor {
|
||||
return RemappingKmConstructorVisitor(super.visitConstructor(flags))
|
||||
}
|
||||
|
||||
override fun visitExtensions(type: KmExtensionType): KmClassExtensionVisitor {
|
||||
return RemappingJvmClassExtensionVisitor(super.visitExtensions(type) as JvmClassExtensionVisitor?)
|
||||
}
|
||||
|
||||
override fun visitTypeParameter(
|
||||
flags: Flags,
|
||||
name: String,
|
||||
id: Int,
|
||||
variance: KmVariance,
|
||||
): KmTypeParameterVisitor {
|
||||
return RemappingKmTypeParameterVisitor(super.visitTypeParameter(flags, name, id, variance))
|
||||
}
|
||||
}
|
||||
|
||||
inner class RemappingKmLambdaVisitor(delegate: KmLambdaVisitor?) : KmLambdaVisitor(delegate) {
|
||||
override fun visitFunction(flags: Flags, name: String): KmFunctionVisitor {
|
||||
return RemappingKmFunctionVisitor(super.visitFunction(flags, name))
|
||||
}
|
||||
}
|
||||
|
||||
inner class RemappingKmTypeVisitor(delegate: KmTypeVisitor?) : KmTypeVisitor(delegate) {
|
||||
override fun visitClass(name: ClassName) {
|
||||
super.visitClass(remapper.map(name))
|
||||
}
|
||||
|
||||
override fun visitTypeAlias(name: ClassName) {
|
||||
super.visitTypeAlias(remapper.map(name))
|
||||
}
|
||||
|
||||
override fun visitAbbreviatedType(flags: Flags): KmTypeVisitor {
|
||||
return RemappingKmTypeVisitor(super.visitAbbreviatedType(flags))
|
||||
}
|
||||
|
||||
override fun visitArgument(flags: Flags, variance: KmVariance): KmTypeVisitor {
|
||||
return RemappingKmTypeVisitor(super.visitArgument(flags, variance))
|
||||
}
|
||||
|
||||
override fun visitOuterType(flags: Flags): KmTypeVisitor {
|
||||
return RemappingKmTypeVisitor(super.visitOuterType(flags))
|
||||
}
|
||||
|
||||
override fun visitFlexibleTypeUpperBound(flags: Flags, typeFlexibilityId: String?): KmTypeVisitor {
|
||||
return RemappingKmTypeVisitor(super.visitFlexibleTypeUpperBound(flags, typeFlexibilityId))
|
||||
}
|
||||
|
||||
override fun visitExtensions(type: KmExtensionType): KmTypeExtensionVisitor {
|
||||
return RemappingJvmTypeExtensionVisitor(super.visitExtensions(type) as JvmTypeExtensionVisitor?)
|
||||
}
|
||||
}
|
||||
|
||||
inner class RemappingJvmTypeExtensionVisitor(delegate: JvmTypeExtensionVisitor?) : JvmTypeExtensionVisitor(delegate) {
|
||||
override fun visitAnnotation(annotation: KmAnnotation) {
|
||||
super.visitAnnotation(KmAnnotation(remapper.map(annotation.className), annotation.arguments))
|
||||
}
|
||||
}
|
||||
|
||||
inner class RemappingKmFunctionVisitor(delegate: KmFunctionVisitor?) : KmFunctionVisitor(delegate) {
|
||||
override fun visitReceiverParameterType(flags: Flags): KmTypeVisitor {
|
||||
return RemappingKmTypeVisitor(super.visitReceiverParameterType(flags))
|
||||
}
|
||||
|
||||
override fun visitReturnType(flags: Flags): KmTypeVisitor {
|
||||
return RemappingKmTypeVisitor(super.visitReturnType(flags))
|
||||
}
|
||||
|
||||
override fun visitValueParameter(flags: Flags, name: String): KmValueParameterVisitor {
|
||||
return RemappingKmValueParameterVisitor(super.visitValueParameter(flags, name))
|
||||
}
|
||||
|
||||
override fun visitExtensions(type: KmExtensionType): KmFunctionExtensionVisitor {
|
||||
return RemappingJvmFunctionExtensionVisitor(super.visitExtensions(type) as JvmFunctionExtensionVisitor)
|
||||
}
|
||||
|
||||
override fun visitContract(): KmContractVisitor {
|
||||
return RemappingKmContractVisitor(super.visitContract())
|
||||
}
|
||||
|
||||
override fun visitTypeParameter(
|
||||
flags: Flags,
|
||||
name: String,
|
||||
id: Int,
|
||||
variance: KmVariance,
|
||||
): KmTypeParameterVisitor {
|
||||
return RemappingKmTypeParameterVisitor(super.visitTypeParameter(flags, name, id, variance))
|
||||
}
|
||||
}
|
||||
|
||||
inner class RemappingKmContractVisitor(delegate: KmContractVisitor?) : KmContractVisitor(delegate) {
|
||||
override fun visitEffect(type: KmEffectType, invocationKind: KmEffectInvocationKind?): KmEffectVisitor {
|
||||
return RemappingKmEffectVisitor(super.visitEffect(type, invocationKind))
|
||||
}
|
||||
}
|
||||
|
||||
inner class RemappingKmEffectVisitor(delegate: KmEffectVisitor?) : KmEffectVisitor(delegate) {
|
||||
override fun visitConclusionOfConditionalEffect(): KmEffectExpressionVisitor {
|
||||
return RemappingKmEffectExpressionVisitor(super.visitConclusionOfConditionalEffect())
|
||||
}
|
||||
|
||||
override fun visitConstructorArgument(): KmEffectExpressionVisitor {
|
||||
return RemappingKmEffectExpressionVisitor(super.visitConclusionOfConditionalEffect())
|
||||
}
|
||||
}
|
||||
|
||||
inner class RemappingKmEffectExpressionVisitor(delegate: KmEffectExpressionVisitor?) : KmEffectExpressionVisitor(delegate) {
|
||||
override fun visitAndArgument(): KmEffectExpressionVisitor {
|
||||
return RemappingKmEffectExpressionVisitor(super.visitAndArgument())
|
||||
}
|
||||
|
||||
override fun visitIsInstanceType(flags: Flags): KmTypeVisitor {
|
||||
return RemappingKmTypeVisitor(super.visitIsInstanceType(flags))
|
||||
}
|
||||
|
||||
override fun visitOrArgument(): KmEffectExpressionVisitor {
|
||||
return RemappingKmEffectExpressionVisitor(super.visitOrArgument())
|
||||
}
|
||||
}
|
||||
|
||||
inner class RemappingKmPropertyVisitor(delegate: KmPropertyVisitor?) : KmPropertyVisitor(delegate) {
|
||||
override fun visitReceiverParameterType(flags: Flags): KmTypeVisitor {
|
||||
return RemappingKmTypeVisitor(super.visitReceiverParameterType(flags))
|
||||
}
|
||||
|
||||
override fun visitReturnType(flags: Flags): KmTypeVisitor {
|
||||
return RemappingKmTypeVisitor(super.visitReturnType(flags))
|
||||
}
|
||||
|
||||
override fun visitSetterParameter(flags: Flags, name: String): KmValueParameterVisitor {
|
||||
return RemappingKmValueParameterVisitor(super.visitSetterParameter(flags, name))
|
||||
}
|
||||
|
||||
override fun visitExtensions(type: KmExtensionType): KmPropertyExtensionVisitor {
|
||||
return RemappingJvmPropertyExtensionVisitor(super.visitExtensions(type) as JvmPropertyExtensionVisitor?)
|
||||
}
|
||||
|
||||
override fun visitTypeParameter(
|
||||
flags: Flags,
|
||||
name: String,
|
||||
id: Int,
|
||||
variance: KmVariance,
|
||||
): KmTypeParameterVisitor {
|
||||
return RemappingKmTypeParameterVisitor(super.visitTypeParameter(flags, name, id, variance))
|
||||
}
|
||||
}
|
||||
|
||||
inner class RemappingJvmPropertyExtensionVisitor(delegate: JvmPropertyExtensionVisitor?) : JvmPropertyExtensionVisitor(delegate) {
|
||||
override fun visit(
|
||||
jvmFlags: Flags,
|
||||
fieldSignature: JvmFieldSignature?,
|
||||
getterSignature: JvmMethodSignature?,
|
||||
setterSignature: JvmMethodSignature?,
|
||||
) {
|
||||
super.visit(jvmFlags, remapJvmFieldSignature(fieldSignature), remapJvmMethodSignature(getterSignature), remapJvmMethodSignature(setterSignature))
|
||||
}
|
||||
|
||||
override fun visitSyntheticMethodForAnnotations(signature: JvmMethodSignature?) {
|
||||
super.visitSyntheticMethodForAnnotations(remapJvmMethodSignature(signature))
|
||||
}
|
||||
|
||||
override fun visitSyntheticMethodForDelegate(signature: JvmMethodSignature?) {
|
||||
super.visitSyntheticMethodForDelegate(remapJvmMethodSignature(signature))
|
||||
}
|
||||
}
|
||||
|
||||
inner class RemappingKmTypeParameterVisitor(delegate: KmTypeParameterVisitor?) : KmTypeParameterVisitor(delegate) {
|
||||
override fun visitExtensions(type: KmExtensionType): KmTypeParameterExtensionVisitor {
|
||||
return RemappingJvmTypeParameterExtensionVisitor(super.visitExtensions(type) as JvmTypeParameterExtensionVisitor?)
|
||||
}
|
||||
|
||||
override fun visitUpperBound(flags: Flags): KmTypeVisitor {
|
||||
return RemappingKmTypeVisitor(super.visitUpperBound(flags))
|
||||
}
|
||||
}
|
||||
|
||||
inner class RemappingJvmTypeParameterExtensionVisitor(delegate: JvmTypeParameterExtensionVisitor?) : JvmTypeParameterExtensionVisitor(delegate) {
|
||||
override fun visitAnnotation(annotation: KmAnnotation) {
|
||||
super.visitAnnotation(KmAnnotation(remapper.map(annotation.className), annotation.arguments))
|
||||
}
|
||||
}
|
||||
|
||||
inner class RemappingKmValueParameterVisitor(delegate: KmValueParameterVisitor?) : KmValueParameterVisitor(delegate) {
|
||||
override fun visitType(flags: Flags): KmTypeVisitor {
|
||||
return RemappingKmTypeVisitor(super.visitType(flags))
|
||||
}
|
||||
|
||||
override fun visitVarargElementType(flags: Flags): KmTypeVisitor {
|
||||
return RemappingKmTypeVisitor(super.visitVarargElementType(flags))
|
||||
}
|
||||
}
|
||||
|
||||
inner class RemappingKmTypeAliasVisitor(delegate: KmTypeAliasVisitor?) : KmTypeAliasVisitor(delegate) {
|
||||
override fun visitExpandedType(flags: Flags): KmTypeVisitor {
|
||||
return RemappingKmTypeVisitor(super.visitExpandedType(flags))
|
||||
}
|
||||
|
||||
override fun visitTypeParameter(
|
||||
flags: Flags,
|
||||
name: String,
|
||||
id: Int,
|
||||
variance: KmVariance,
|
||||
): KmTypeParameterVisitor {
|
||||
return RemappingKmTypeParameterVisitor(super.visitTypeParameter(flags, name, id, variance))
|
||||
}
|
||||
|
||||
override fun visitUnderlyingType(flags: Flags): KmTypeVisitor {
|
||||
return RemappingKmTypeVisitor(super.visitUnderlyingType(flags))
|
||||
}
|
||||
|
||||
override fun visitAnnotation(annotation: KmAnnotation) {
|
||||
super.visitAnnotation(KmAnnotation(remapper.map(annotation.className), annotation.arguments))
|
||||
}
|
||||
}
|
||||
|
||||
inner class RemappingJvmFunctionExtensionVisitor(delegate: JvmFunctionExtensionVisitor?) : JvmFunctionExtensionVisitor(delegate) {
|
||||
override fun visit(signature: JvmMethodSignature?) {
|
||||
super.visit(remapJvmMethodSignature(signature))
|
||||
}
|
||||
|
||||
override fun visitLambdaClassOriginName(internalName: String) {
|
||||
super.visitLambdaClassOriginName(remapper.map(internalName))
|
||||
}
|
||||
}
|
||||
|
||||
inner class RemappingJvmClassExtensionVisitor(delegate: JvmClassExtensionVisitor?) : JvmClassExtensionVisitor(delegate) {
|
||||
override fun visitAnonymousObjectOriginName(internalName: String) {
|
||||
super.visitAnonymousObjectOriginName(remapper.map(internalName))
|
||||
}
|
||||
|
||||
override fun visitLocalDelegatedProperty(
|
||||
flags: Flags,
|
||||
name: String,
|
||||
getterFlags: Flags,
|
||||
setterFlags: Flags,
|
||||
): KmPropertyVisitor {
|
||||
return RemappingKmPropertyVisitor(super.visitLocalDelegatedProperty(flags, name, getterFlags, setterFlags))
|
||||
}
|
||||
}
|
||||
|
||||
inner class RemappingKmConstructorVisitor(delegate: KmConstructorVisitor?) : KmConstructorVisitor(delegate) {
|
||||
override fun visitExtensions(type: KmExtensionType): KmConstructorExtensionVisitor {
|
||||
return RemappingJvmConstructorExtensionVisitor(super.visitExtensions(type) as JvmConstructorExtensionVisitor?)
|
||||
}
|
||||
|
||||
override fun visitValueParameter(flags: Flags, name: String): KmValueParameterVisitor {
|
||||
return RemappingKmValueParameterVisitor(super.visitValueParameter(flags, name))
|
||||
}
|
||||
}
|
||||
|
||||
inner class RemappingJvmConstructorExtensionVisitor(delegate: JvmConstructorExtensionVisitor?) : JvmConstructorExtensionVisitor(delegate) {
|
||||
override fun visit(signature: JvmMethodSignature?) {
|
||||
super.visit(remapJvmMethodSignature(signature))
|
||||
}
|
||||
}
|
||||
|
||||
inner class RemappingKmPackageVisitor(delegate: KmPackageVisitor?) : KmPackageVisitor(delegate) {
|
||||
override fun visitExtensions(type: KmExtensionType): KmPackageExtensionVisitor {
|
||||
return RemappingJvmPackageExtensionVisitor(super.visitExtensions(type) as JvmPackageExtensionVisitor?)
|
||||
}
|
||||
|
||||
override fun visitFunction(flags: Flags, name: String): KmFunctionVisitor {
|
||||
return RemappingKmFunctionVisitor(super.visitFunction(flags, name))
|
||||
}
|
||||
|
||||
override fun visitProperty(
|
||||
flags: Flags,
|
||||
name: String,
|
||||
getterFlags: Flags,
|
||||
setterFlags: Flags,
|
||||
): KmPropertyVisitor {
|
||||
return RemappingKmPropertyVisitor(super.visitProperty(flags, name, getterFlags, setterFlags))
|
||||
}
|
||||
|
||||
override fun visitTypeAlias(flags: Flags, name: String): KmTypeAliasVisitor {
|
||||
return RemappingKmTypeAliasVisitor(super.visitTypeAlias(flags, name))
|
||||
}
|
||||
}
|
||||
|
||||
inner class RemappingJvmPackageExtensionVisitor(delegate: JvmPackageExtensionVisitor?) : JvmPackageExtensionVisitor(delegate) {
|
||||
override fun visitLocalDelegatedProperty(
|
||||
flags: Flags,
|
||||
name: String,
|
||||
getterFlags: Flags,
|
||||
setterFlags: Flags,
|
||||
): KmPropertyVisitor {
|
||||
return RemappingKmPropertyVisitor(super.visitLocalDelegatedProperty(flags, name, getterFlags, setterFlags))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -28,7 +28,6 @@ allprojects {
|
||||
modImplementation "net.fabricmc:fabric-loader:0.11.2"
|
||||
|
||||
modImplementation "net.fabricmc.fabric-api:fabric-api:0.31.0+1.16"
|
||||
|
||||
}
|
||||
|
||||
jar {
|
||||
|
||||
Reference in New Issue
Block a user