diff --git a/definition/build.gradle.kts b/definition/build.gradle.kts index 782c97c..87aaa6a 100644 --- a/definition/build.gradle.kts +++ b/definition/build.gradle.kts @@ -24,8 +24,6 @@ java { withSourcesJar() } -val testClasses: SourceSet by sourceSets.creating - repositories { mavenCentral() maven { @@ -43,9 +41,9 @@ dependencies { implementation(group = "com.mojang", name = "logging", version = "1.1.1") implementation(group = "com.google.guava", "guava", version = "32.1.2-jre") implementation(group = "org.slf4j", "slf4j-api", "2.0.0") - "testClassesImplementation"(implementation(group = "net.fabricmc", name = "sponge-mixin", version = "0.14.0+mixin.0.8.6")) + implementation(group = "net.fabricmc", name = "sponge-mixin", version = "0.14.0+mixin.0.8.6") compileOnly(group = "org.jetbrains", name = "annotations", version = "24.0.1") - "testClassesImplementation"(implementation(group = "io.github.llamalad7", name = "mixinextras-common", version = "0.3.1")) + implementation(group = "io.github.llamalad7", name = "mixinextras-common", version = "0.3.1") api(platform("org.ow2.asm:asm-bom:9.5")) api(group = "org.ow2.asm", name = "asm") @@ -53,12 +51,6 @@ dependencies { api(group = "org.ow2.asm", name = "asm-tree") api(group = "org.ow2.asm", name = "asm-analysis") api(group = "org.ow2.asm", name = "asm-util") - - testImplementation(platform("org.junit:junit-bom:5.9.1")) - testImplementation("org.junit.jupiter:junit-jupiter") - testImplementation("org.assertj:assertj-core:3.25.1") - - "testRuntimeOnly"(testClasses.output) } tasks { @@ -67,20 +59,6 @@ tasks { "Implementation-Version" to project.version ) } - - test { - useJUnitPlatform() - systemProperty("adapter.definition.paramdiff.debug", true) - outputs.upToDateWhen { false } - } - - named("compileTestClassesJava", JavaCompile::class.java) { - options.compilerArgs = listOf("-parameters") - } - - named("testClasses") { - dependsOn("compileTestClassesJava") - } } publishing { diff --git a/definition/src/main/java/org/sinytra/adapter/patch/ClassPatchInstance.java b/definition/src/main/java/org/sinytra/adapter/patch/ClassPatchInstance.java index 97f098a..430900a 100644 --- a/definition/src/main/java/org/sinytra/adapter/patch/ClassPatchInstance.java +++ b/definition/src/main/java/org/sinytra/adapter/patch/ClassPatchInstance.java @@ -5,23 +5,22 @@ import com.mojang.serialization.codecs.RecordCodecBuilder; import org.objectweb.asm.commons.InstructionAdapter; import org.objectweb.asm.tree.AnnotationNode; -import org.objectweb.asm.tree.InsnList; -import org.objectweb.asm.tree.MethodInsnNode; import org.objectweb.asm.tree.MethodNode; import org.sinytra.adapter.patch.api.ClassTransform; import org.sinytra.adapter.patch.api.MethodTransform; import org.sinytra.adapter.patch.api.MixinConstants; import org.sinytra.adapter.patch.api.PatchEnvironment; -import org.sinytra.adapter.patch.selector.AnnotationHandle; -import org.sinytra.adapter.patch.selector.AnnotationValueHandle; -import org.sinytra.adapter.patch.selector.InjectionPointMatcher; -import org.sinytra.adapter.patch.selector.MethodMatcher; -import org.sinytra.adapter.patch.serialization.MethodTransformSerialization; -import org.sinytra.adapter.patch.transformer.*; +import org.sinytra.adapter.patch.analysis.selector.AnnotationHandle; +import org.sinytra.adapter.patch.analysis.selector.AnnotationValueHandle; +import org.sinytra.adapter.patch.analysis.selector.InjectionPointMatcher; +import org.sinytra.adapter.patch.analysis.selector.MethodMatcher; +import org.sinytra.adapter.patch.transformer.serialization.MethodTransformSerialization; +import org.sinytra.adapter.patch.transformer.operation.DisableMixin; +import org.sinytra.adapter.patch.transformer.operation.DivertRedirectorTransform; +import org.sinytra.adapter.patch.transformer.operation.ModifyInjectionPoint; import org.sinytra.adapter.patch.util.MethodQualifier; import java.util.*; -import java.util.function.BiConsumer; import java.util.function.Consumer; import java.util.function.Function; import java.util.function.Predicate; @@ -138,28 +137,11 @@ public ClassPatchBuilder modifyInjectionPoint(String value, String target, boole return transform(new ModifyInjectionPoint(value, target, resetValues, dontUpgrade)); } - @Override - public ClassPatchBuilder redirectShadowMethod(String original, String target, BiConsumer callFixer) { - return transform(new RedirectShadowMethod(original, target, callFixer)); - } - @Override public ClassPatchBuilder divertRedirector(Consumer patcher) { return transform(new DivertRedirectorTransform(patcher)); } - @Override - public ClassPatchBuilder updateRedirectTarget(String originalTarget, String newTarget) { - return targetInjectionPoint(originalTarget) - .transform(new ModifyRedirectToWrapper( - MethodQualifier.create(originalTarget).orElseThrow(), - MethodQualifier.create(newTarget).orElseThrow() - )) - .modifyMixinType(MixinConstants.WRAP_OPERATION, b -> b - .sameTarget() - .injectionPoint("INVOKE", newTarget)); - } - @Override public ClassPatchBuilder disable() { return transform(DisableMixin.INSTANCE); diff --git a/definition/src/main/java/org/sinytra/adapter/patch/InterfacePatchInstance.java b/definition/src/main/java/org/sinytra/adapter/patch/InterfacePatchInstance.java index 87a26cb..76c4495 100644 --- a/definition/src/main/java/org/sinytra/adapter/patch/InterfacePatchInstance.java +++ b/definition/src/main/java/org/sinytra/adapter/patch/InterfacePatchInstance.java @@ -10,10 +10,9 @@ import org.sinytra.adapter.patch.api.MethodTransform; import org.sinytra.adapter.patch.api.MixinConstants; import org.sinytra.adapter.patch.api.PatchEnvironment; -import org.sinytra.adapter.patch.selector.AnnotationHandle; -import org.sinytra.adapter.patch.selector.FieldMatcher; -import org.sinytra.adapter.patch.serialization.MethodTransformSerialization; -import org.sinytra.adapter.patch.transformer.RedirectAccessor; +import org.sinytra.adapter.patch.analysis.selector.AnnotationHandle; +import org.sinytra.adapter.patch.analysis.selector.FieldMatcher; +import org.sinytra.adapter.patch.transformer.serialization.MethodTransformSerialization; import org.sinytra.adapter.patch.util.AdapterUtil; import java.util.Collection; @@ -89,11 +88,6 @@ public InterfacePatchBuilder targetField(String... targets) { return this; } - @Override - public InterfacePatchBuilder modifyValue(String value) { - return transform(new RedirectAccessor(value)); - } - @Override public PatchInstance build() { return new InterfacePatchInstance( diff --git a/definition/src/main/java/org/sinytra/adapter/patch/MethodContextImpl.java b/definition/src/main/java/org/sinytra/adapter/patch/MethodContextImpl.java index df4a3c4..6ea1bef 100644 --- a/definition/src/main/java/org/sinytra/adapter/patch/MethodContextImpl.java +++ b/definition/src/main/java/org/sinytra/adapter/patch/MethodContextImpl.java @@ -11,8 +11,8 @@ import org.sinytra.adapter.patch.api.MethodContext; import org.sinytra.adapter.patch.api.MixinConstants; import org.sinytra.adapter.patch.api.PatchContext; -import org.sinytra.adapter.patch.selector.AnnotationHandle; -import org.sinytra.adapter.patch.selector.AnnotationValueHandle; +import org.sinytra.adapter.patch.analysis.selector.AnnotationHandle; +import org.sinytra.adapter.patch.analysis.selector.AnnotationValueHandle; import org.sinytra.adapter.patch.util.AdapterUtil; import org.sinytra.adapter.patch.util.MethodQualifier; import org.sinytra.adapter.patch.util.MockMixinRuntime; diff --git a/definition/src/main/java/org/sinytra/adapter/patch/PatchInstance.java b/definition/src/main/java/org/sinytra/adapter/patch/PatchInstance.java index f0c1757..da57adc 100644 --- a/definition/src/main/java/org/sinytra/adapter/patch/PatchInstance.java +++ b/definition/src/main/java/org/sinytra/adapter/patch/PatchInstance.java @@ -7,9 +7,9 @@ import org.objectweb.asm.tree.ClassNode; import org.objectweb.asm.tree.MethodNode; import org.sinytra.adapter.patch.api.*; -import org.sinytra.adapter.patch.selector.AnnotationHandle; -import org.sinytra.adapter.patch.selector.AnnotationValueHandle; -import org.sinytra.adapter.patch.transformer.ModifyTargetClasses; +import org.sinytra.adapter.patch.analysis.selector.AnnotationHandle; +import org.sinytra.adapter.patch.analysis.selector.AnnotationValueHandle; +import org.sinytra.adapter.patch.transformer.operation.ModifyTargetClasses; import org.sinytra.adapter.patch.util.MethodTransformBuilderImpl; import org.slf4j.Marker; import org.slf4j.MarkerFactory; diff --git a/definition/src/main/java/org/sinytra/adapter/patch/transformer/LVTSnapshot.java b/definition/src/main/java/org/sinytra/adapter/patch/analysis/LVTSnapshot.java similarity index 98% rename from definition/src/main/java/org/sinytra/adapter/patch/transformer/LVTSnapshot.java rename to definition/src/main/java/org/sinytra/adapter/patch/analysis/LVTSnapshot.java index 1f1ee97..d1a104f 100644 --- a/definition/src/main/java/org/sinytra/adapter/patch/transformer/LVTSnapshot.java +++ b/definition/src/main/java/org/sinytra/adapter/patch/analysis/LVTSnapshot.java @@ -1,4 +1,4 @@ -package org.sinytra.adapter.patch.transformer; +package org.sinytra.adapter.patch.analysis; import it.unimi.dsi.fastutil.ints.Int2IntArrayMap; import it.unimi.dsi.fastutil.ints.Int2IntMap; diff --git a/definition/src/main/java/org/sinytra/adapter/patch/analysis/LocalVarAnalyzer.java b/definition/src/main/java/org/sinytra/adapter/patch/analysis/LocalVarAnalyzer.java index c3b5c2e..4716674 100644 --- a/definition/src/main/java/org/sinytra/adapter/patch/analysis/LocalVarAnalyzer.java +++ b/definition/src/main/java/org/sinytra/adapter/patch/analysis/LocalVarAnalyzer.java @@ -6,7 +6,7 @@ import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap; import org.objectweb.asm.tree.*; import org.sinytra.adapter.patch.api.MethodTransform; -import org.sinytra.adapter.patch.transformer.param.TransformParameters; +import org.sinytra.adapter.patch.transformer.operation.param.TransformParameters; import org.sinytra.adapter.patch.util.AdapterUtil; import org.sinytra.adapter.patch.util.OpcodeUtil; diff --git a/definition/src/main/java/org/sinytra/adapter/patch/analysis/params/LayeredParamsDiffSnapshot.java b/definition/src/main/java/org/sinytra/adapter/patch/analysis/params/LayeredParamsDiffSnapshot.java index 1faa7f0..6d9cbb0 100644 --- a/definition/src/main/java/org/sinytra/adapter/patch/analysis/params/LayeredParamsDiffSnapshot.java +++ b/definition/src/main/java/org/sinytra/adapter/patch/analysis/params/LayeredParamsDiffSnapshot.java @@ -6,7 +6,7 @@ import org.objectweb.asm.Type; import org.objectweb.asm.commons.InstructionAdapter; import org.sinytra.adapter.patch.api.MethodTransform; -import org.sinytra.adapter.patch.transformer.param.*; +import org.sinytra.adapter.patch.transformer.operation.param.*; import java.util.ArrayList; import java.util.List; diff --git a/definition/src/main/java/org/sinytra/adapter/patch/analysis/params/ParametersDiff.java b/definition/src/main/java/org/sinytra/adapter/patch/analysis/params/ParametersDiff.java index 9745a51..b688b04 100644 --- a/definition/src/main/java/org/sinytra/adapter/patch/analysis/params/ParametersDiff.java +++ b/definition/src/main/java/org/sinytra/adapter/patch/analysis/params/ParametersDiff.java @@ -7,11 +7,11 @@ import org.objectweb.asm.tree.LocalVariableNode; import org.objectweb.asm.tree.MethodNode; import org.sinytra.adapter.patch.api.MethodTransform; -import org.sinytra.adapter.patch.transformer.ModifyMethodParams; -import org.sinytra.adapter.patch.transformer.param.InjectParameterTransform; -import org.sinytra.adapter.patch.transformer.param.ParamTransformTarget; -import org.sinytra.adapter.patch.transformer.param.ParameterTransformer; -import org.sinytra.adapter.patch.transformer.param.TransformParameters; +import org.sinytra.adapter.patch.transformer.operation.ModifyMethodParams; +import org.sinytra.adapter.patch.transformer.operation.param.InjectParameterTransform; +import org.sinytra.adapter.patch.transformer.operation.param.ParamTransformTarget; +import org.sinytra.adapter.patch.transformer.operation.param.ParameterTransformer; +import org.sinytra.adapter.patch.transformer.operation.param.TransformParameters; import org.sinytra.adapter.patch.util.AdapterUtil; import org.sinytra.adapter.patch.util.GeneratedVariables; diff --git a/definition/src/main/java/org/sinytra/adapter/patch/analysis/params/ParamsDiffSnapshot.java b/definition/src/main/java/org/sinytra/adapter/patch/analysis/params/ParamsDiffSnapshot.java index 5efd9df..d79d546 100644 --- a/definition/src/main/java/org/sinytra/adapter/patch/analysis/params/ParamsDiffSnapshot.java +++ b/definition/src/main/java/org/sinytra/adapter/patch/analysis/params/ParamsDiffSnapshot.java @@ -3,7 +3,7 @@ import com.mojang.datafixers.util.Pair; import org.objectweb.asm.Type; import org.sinytra.adapter.patch.api.MethodTransform; -import org.sinytra.adapter.patch.transformer.param.ParamTransformTarget; +import org.sinytra.adapter.patch.transformer.operation.param.ParamTransformTarget; import java.util.List; diff --git a/definition/src/main/java/org/sinytra/adapter/patch/analysis/params/SimpleParamsDiffSnapshot.java b/definition/src/main/java/org/sinytra/adapter/patch/analysis/params/SimpleParamsDiffSnapshot.java index 3952939..2a6a2b6 100644 --- a/definition/src/main/java/org/sinytra/adapter/patch/analysis/params/SimpleParamsDiffSnapshot.java +++ b/definition/src/main/java/org/sinytra/adapter/patch/analysis/params/SimpleParamsDiffSnapshot.java @@ -10,11 +10,11 @@ import org.objectweb.asm.commons.InstructionAdapter; import org.sinytra.adapter.patch.api.MethodTransform; import org.sinytra.adapter.patch.transformer.BundledMethodTransform; -import org.sinytra.adapter.patch.transformer.ModifyMethodParams; -import org.sinytra.adapter.patch.transformer.param.InjectParameterTransform; -import org.sinytra.adapter.patch.transformer.param.ParamTransformTarget; -import org.sinytra.adapter.patch.transformer.param.ParameterTransformer; -import org.sinytra.adapter.patch.transformer.param.TransformParameters; +import org.sinytra.adapter.patch.transformer.operation.ModifyMethodParams; +import org.sinytra.adapter.patch.transformer.operation.param.InjectParameterTransform; +import org.sinytra.adapter.patch.transformer.operation.param.ParamTransformTarget; +import org.sinytra.adapter.patch.transformer.operation.param.ParameterTransformer; +import org.sinytra.adapter.patch.transformer.operation.param.TransformParameters; import org.sinytra.adapter.patch.util.AdapterUtil; import org.slf4j.Logger; diff --git a/definition/src/main/java/org/sinytra/adapter/patch/selector/AnnotationHandle.java b/definition/src/main/java/org/sinytra/adapter/patch/analysis/selector/AnnotationHandle.java similarity index 97% rename from definition/src/main/java/org/sinytra/adapter/patch/selector/AnnotationHandle.java rename to definition/src/main/java/org/sinytra/adapter/patch/analysis/selector/AnnotationHandle.java index 2d7e82c..9701102 100644 --- a/definition/src/main/java/org/sinytra/adapter/patch/selector/AnnotationHandle.java +++ b/definition/src/main/java/org/sinytra/adapter/patch/analysis/selector/AnnotationHandle.java @@ -1,9 +1,8 @@ -package org.sinytra.adapter.patch.selector; +package org.sinytra.adapter.patch.analysis.selector; import org.objectweb.asm.tree.AnnotationNode; import java.util.*; -import java.util.stream.Stream; public final class AnnotationHandle { private AnnotationNode annotationNode; diff --git a/definition/src/main/java/org/sinytra/adapter/patch/selector/AnnotationValueHandle.java b/definition/src/main/java/org/sinytra/adapter/patch/analysis/selector/AnnotationValueHandle.java similarity index 98% rename from definition/src/main/java/org/sinytra/adapter/patch/selector/AnnotationValueHandle.java rename to definition/src/main/java/org/sinytra/adapter/patch/analysis/selector/AnnotationValueHandle.java index 40f17c5..ce439b7 100644 --- a/definition/src/main/java/org/sinytra/adapter/patch/selector/AnnotationValueHandle.java +++ b/definition/src/main/java/org/sinytra/adapter/patch/analysis/selector/AnnotationValueHandle.java @@ -1,4 +1,4 @@ -package org.sinytra.adapter.patch.selector; +package org.sinytra.adapter.patch.analysis.selector; import org.objectweb.asm.tree.AnnotationNode; diff --git a/definition/src/main/java/org/sinytra/adapter/patch/selector/FieldMatcher.java b/definition/src/main/java/org/sinytra/adapter/patch/analysis/selector/FieldMatcher.java similarity index 94% rename from definition/src/main/java/org/sinytra/adapter/patch/selector/FieldMatcher.java rename to definition/src/main/java/org/sinytra/adapter/patch/analysis/selector/FieldMatcher.java index 083b96d..33de860 100644 --- a/definition/src/main/java/org/sinytra/adapter/patch/selector/FieldMatcher.java +++ b/definition/src/main/java/org/sinytra/adapter/patch/analysis/selector/FieldMatcher.java @@ -1,4 +1,4 @@ -package org.sinytra.adapter.patch.selector; +package org.sinytra.adapter.patch.analysis.selector; import com.mojang.serialization.Codec; import org.jetbrains.annotations.Nullable; diff --git a/definition/src/main/java/org/sinytra/adapter/patch/selector/InjectionPointMatcher.java b/definition/src/main/java/org/sinytra/adapter/patch/analysis/selector/InjectionPointMatcher.java similarity index 97% rename from definition/src/main/java/org/sinytra/adapter/patch/selector/InjectionPointMatcher.java rename to definition/src/main/java/org/sinytra/adapter/patch/analysis/selector/InjectionPointMatcher.java index 47ac6bb..92fef36 100644 --- a/definition/src/main/java/org/sinytra/adapter/patch/selector/InjectionPointMatcher.java +++ b/definition/src/main/java/org/sinytra/adapter/patch/analysis/selector/InjectionPointMatcher.java @@ -1,4 +1,4 @@ -package org.sinytra.adapter.patch.selector; +package org.sinytra.adapter.patch.analysis.selector; import com.mojang.serialization.Codec; import com.mojang.serialization.codecs.RecordCodecBuilder; diff --git a/definition/src/main/java/org/sinytra/adapter/patch/selector/MethodMatcher.java b/definition/src/main/java/org/sinytra/adapter/patch/analysis/selector/MethodMatcher.java similarity index 93% rename from definition/src/main/java/org/sinytra/adapter/patch/selector/MethodMatcher.java rename to definition/src/main/java/org/sinytra/adapter/patch/analysis/selector/MethodMatcher.java index 263c693..b4a170e 100644 --- a/definition/src/main/java/org/sinytra/adapter/patch/selector/MethodMatcher.java +++ b/definition/src/main/java/org/sinytra/adapter/patch/analysis/selector/MethodMatcher.java @@ -1,4 +1,4 @@ -package org.sinytra.adapter.patch.selector; +package org.sinytra.adapter.patch.analysis.selector; import com.mojang.serialization.Codec; import org.jetbrains.annotations.Nullable; diff --git a/definition/src/main/java/org/sinytra/adapter/patch/api/ClassTransform.java b/definition/src/main/java/org/sinytra/adapter/patch/api/ClassTransform.java index e65224e..d70cc83 100644 --- a/definition/src/main/java/org/sinytra/adapter/patch/api/ClassTransform.java +++ b/definition/src/main/java/org/sinytra/adapter/patch/api/ClassTransform.java @@ -3,7 +3,7 @@ import org.jetbrains.annotations.Nullable; import org.objectweb.asm.tree.ClassNode; import org.sinytra.adapter.patch.api.Patch.Result; -import org.sinytra.adapter.patch.selector.AnnotationValueHandle; +import org.sinytra.adapter.patch.analysis.selector.AnnotationValueHandle; public interface ClassTransform { Result apply(ClassNode classNode, @Nullable AnnotationValueHandle annotation, PatchContext context); diff --git a/definition/src/main/java/org/sinytra/adapter/patch/api/MethodContext.java b/definition/src/main/java/org/sinytra/adapter/patch/api/MethodContext.java index b3c2c3d..7c8dc76 100644 --- a/definition/src/main/java/org/sinytra/adapter/patch/api/MethodContext.java +++ b/definition/src/main/java/org/sinytra/adapter/patch/api/MethodContext.java @@ -7,8 +7,8 @@ import org.objectweb.asm.tree.ClassNode; import org.objectweb.asm.tree.MethodNode; import org.sinytra.adapter.patch.analysis.LocalVariableLookup; -import org.sinytra.adapter.patch.selector.AnnotationHandle; -import org.sinytra.adapter.patch.selector.AnnotationValueHandle; +import org.sinytra.adapter.patch.analysis.selector.AnnotationHandle; +import org.sinytra.adapter.patch.analysis.selector.AnnotationValueHandle; import org.sinytra.adapter.patch.util.MethodQualifier; import org.sinytra.adapter.patch.util.provider.ClassLookup; diff --git a/definition/src/main/java/org/sinytra/adapter/patch/api/MethodTransformBuilder.java b/definition/src/main/java/org/sinytra/adapter/patch/api/MethodTransformBuilder.java index 1319722..a35b068 100644 --- a/definition/src/main/java/org/sinytra/adapter/patch/api/MethodTransformBuilder.java +++ b/definition/src/main/java/org/sinytra/adapter/patch/api/MethodTransformBuilder.java @@ -1,11 +1,11 @@ package org.sinytra.adapter.patch.api; import org.jetbrains.annotations.ApiStatus; -import org.sinytra.adapter.patch.transformer.ModifyInjectionTarget; -import org.sinytra.adapter.patch.transformer.ModifyMethodAccess; -import org.sinytra.adapter.patch.transformer.ModifyMethodParams; -import org.sinytra.adapter.patch.transformer.ModifyMixinType; -import org.sinytra.adapter.patch.transformer.param.TransformParameters; +import org.sinytra.adapter.patch.transformer.operation.ModifyInjectionTarget; +import org.sinytra.adapter.patch.transformer.operation.ModifyMethodAccess; +import org.sinytra.adapter.patch.transformer.operation.ModifyMethodParams; +import org.sinytra.adapter.patch.transformer.operation.ModifyMixinType; +import org.sinytra.adapter.patch.transformer.operation.param.TransformParameters; import java.util.List; import java.util.function.Consumer; @@ -21,14 +21,10 @@ public interface MethodTransformBuilder> { T modifyTarget(ModifyInjectionTarget.Action action, String... methods); - T modifyVariableIndex(int start, int offset); - T modifyMethodAccess(ModifyMethodAccess.AccessChange... changes); T extractMixin(String targetClass); - T splitMixin(String targetClass); - T improveModifyVar(); T modifyMixinType(String newType, Consumer consumer); diff --git a/definition/src/main/java/org/sinytra/adapter/patch/api/MethodTransformFilter.java b/definition/src/main/java/org/sinytra/adapter/patch/api/MethodTransformFilter.java new file mode 100644 index 0000000..79d996f --- /dev/null +++ b/definition/src/main/java/org/sinytra/adapter/patch/api/MethodTransformFilter.java @@ -0,0 +1,9 @@ +package org.sinytra.adapter.patch.api; + +import com.mojang.serialization.Codec; + +public interface MethodTransformFilter { + Codec codec(); + + boolean test(MethodContext methodContext); +} diff --git a/definition/src/main/java/org/sinytra/adapter/patch/api/Patch.java b/definition/src/main/java/org/sinytra/adapter/patch/api/Patch.java index e4e3a32..234c3a2 100644 --- a/definition/src/main/java/org/sinytra/adapter/patch/api/Patch.java +++ b/definition/src/main/java/org/sinytra/adapter/patch/api/Patch.java @@ -4,16 +4,13 @@ import org.objectweb.asm.Type; import org.objectweb.asm.commons.InstructionAdapter; import org.objectweb.asm.tree.ClassNode; -import org.objectweb.asm.tree.InsnList; -import org.objectweb.asm.tree.MethodInsnNode; import org.sinytra.adapter.patch.ClassPatchInstance; import org.sinytra.adapter.patch.InterfacePatchInstance; import org.sinytra.adapter.patch.PatchInstance; -import org.sinytra.adapter.patch.selector.AnnotationHandle; -import org.sinytra.adapter.patch.selector.AnnotationValueHandle; +import org.sinytra.adapter.patch.analysis.selector.AnnotationHandle; +import org.sinytra.adapter.patch.analysis.selector.AnnotationValueHandle; import java.util.List; -import java.util.function.BiConsumer; import java.util.function.Consumer; import java.util.function.Predicate; import java.util.function.Supplier; @@ -100,18 +97,12 @@ default ClassPatchBuilder modifyInjectionPoint(String target) { return modifyInjectionPoint(null, target); } - ClassPatchBuilder redirectShadowMethod(String original, String target, BiConsumer callFixer); - ClassPatchBuilder divertRedirector(Consumer patcher); - ClassPatchBuilder updateRedirectTarget(String originalTarget, String newTarget); - ClassPatchBuilder disable(); } interface InterfacePatchBuilder extends Builder { InterfacePatchBuilder targetField(String... targets); - - InterfacePatchBuilder modifyValue(String value); } } diff --git a/definition/src/main/java/org/sinytra/adapter/patch/fixes/FieldTypePatchTransformer.java b/definition/src/main/java/org/sinytra/adapter/patch/fixes/FieldTypePatchTransformer.java index ea35124..961dd90 100644 --- a/definition/src/main/java/org/sinytra/adapter/patch/fixes/FieldTypePatchTransformer.java +++ b/definition/src/main/java/org/sinytra/adapter/patch/fixes/FieldTypePatchTransformer.java @@ -7,7 +7,7 @@ import org.objectweb.asm.tree.ClassNode; import org.objectweb.asm.tree.MethodNode; import org.sinytra.adapter.patch.api.*; -import org.sinytra.adapter.patch.selector.FieldMatcher; +import org.sinytra.adapter.patch.analysis.selector.FieldMatcher; import org.sinytra.adapter.patch.util.AdapterUtil; import java.util.Collection; diff --git a/definition/src/main/java/org/sinytra/adapter/patch/fixes/FieldTypeUsageTransformer.java b/definition/src/main/java/org/sinytra/adapter/patch/fixes/FieldTypeUsageTransformer.java index 0cfe5b6..9cd24d6 100644 --- a/definition/src/main/java/org/sinytra/adapter/patch/fixes/FieldTypeUsageTransformer.java +++ b/definition/src/main/java/org/sinytra/adapter/patch/fixes/FieldTypeUsageTransformer.java @@ -10,7 +10,7 @@ import org.sinytra.adapter.patch.api.ClassTransform; import org.sinytra.adapter.patch.api.Patch; import org.sinytra.adapter.patch.api.PatchContext; -import org.sinytra.adapter.patch.selector.AnnotationValueHandle; +import org.sinytra.adapter.patch.analysis.selector.AnnotationValueHandle; import org.sinytra.adapter.patch.util.AdapterUtil; import org.slf4j.Logger; diff --git a/definition/src/main/java/org/sinytra/adapter/patch/fixes/MethodUpgrader.java b/definition/src/main/java/org/sinytra/adapter/patch/fixes/MethodUpgrader.java index e1c1c07..92c16b6 100644 --- a/definition/src/main/java/org/sinytra/adapter/patch/fixes/MethodUpgrader.java +++ b/definition/src/main/java/org/sinytra/adapter/patch/fixes/MethodUpgrader.java @@ -2,6 +2,8 @@ import com.google.common.collect.ImmutableList; import org.objectweb.asm.Type; +import org.objectweb.asm.tree.AbstractInsnNode; +import org.objectweb.asm.tree.MethodInsnNode; import org.objectweb.asm.tree.MethodNode; import org.sinytra.adapter.patch.analysis.LocalVarAnalyzer; import org.sinytra.adapter.patch.analysis.params.EnhancedParamsDiff; @@ -10,10 +12,10 @@ import org.sinytra.adapter.patch.api.MethodContext; import org.sinytra.adapter.patch.api.MethodTransform; import org.sinytra.adapter.patch.api.MixinConstants; -import org.sinytra.adapter.patch.transformer.ModifyArgsOffsetTransformer; -import org.sinytra.adapter.patch.transformer.param.ParamTransformTarget; -import org.sinytra.adapter.patch.transformer.param.ParameterTransformer; -import org.sinytra.adapter.patch.transformer.param.TransformParameters; +import org.sinytra.adapter.patch.analysis.selector.AnnotationValueHandle; +import org.sinytra.adapter.patch.transformer.operation.param.ParamTransformTarget; +import org.sinytra.adapter.patch.transformer.operation.param.ParameterTransformer; +import org.sinytra.adapter.patch.transformer.operation.param.TransformParameters; import org.sinytra.adapter.patch.util.AdapterUtil; import org.sinytra.adapter.patch.util.MethodQualifier; @@ -37,6 +39,33 @@ public static void upgradeMethod(MethodNode methodNode, MethodContext methodCont } } + // TODO This should be an automatic upgrade tbh + public static void adjustInjectorOrdinalForNewMethod(MethodInsnNode minsn, MethodContext methodContext) { + AnnotationValueHandle handle = methodContext.injectionPointAnnotationOrThrow().getValue("ordinal").orElse(null); + if (handle == null) { + return; + } + int originalOrdinal = handle.get(); + // Temporarily adjust ordinal to account for previous calls that have not been moved to the new class + if (handle != null) { + handle.set(-1); + List insns = methodContext.computeInjectionTargetInsns(methodContext.findDirtyInjectionTarget()); + handle.set(originalOrdinal); + int newOrdinal = originalOrdinal; + for (AbstractInsnNode insn : methodContext.findDirtyInjectionTarget().methodNode().instructions) { + if (insn == minsn) { + break; + } + if (insns.contains(insn)) { + newOrdinal--; + } + } + if (newOrdinal >= 0) { + handle.set(newOrdinal); + } + } + } + public static void upgradeCapturedLocals(MethodNode methodNode, MethodContext methodContext) { AdapterUtil.CapturedLocals capturedLocals = AdapterUtil.getCapturedLocals(methodNode, methodContext); if (capturedLocals == null) { diff --git a/definition/src/main/java/org/sinytra/adapter/patch/transformer/ModifyArgsOffsetTransformer.java b/definition/src/main/java/org/sinytra/adapter/patch/fixes/ModifyArgsOffsetTransformer.java similarity index 98% rename from definition/src/main/java/org/sinytra/adapter/patch/transformer/ModifyArgsOffsetTransformer.java rename to definition/src/main/java/org/sinytra/adapter/patch/fixes/ModifyArgsOffsetTransformer.java index 4780017..9b79ce2 100644 --- a/definition/src/main/java/org/sinytra/adapter/patch/transformer/ModifyArgsOffsetTransformer.java +++ b/definition/src/main/java/org/sinytra/adapter/patch/fixes/ModifyArgsOffsetTransformer.java @@ -1,4 +1,4 @@ -package org.sinytra.adapter.patch.transformer; +package org.sinytra.adapter.patch.fixes; import com.mojang.datafixers.util.Pair; import org.objectweb.asm.Type; diff --git a/definition/src/main/java/org/sinytra/adapter/patch/transformer/BundledMethodTransform.java b/definition/src/main/java/org/sinytra/adapter/patch/transformer/BundledMethodTransform.java index b6258f2..5d9ba5c 100644 --- a/definition/src/main/java/org/sinytra/adapter/patch/transformer/BundledMethodTransform.java +++ b/definition/src/main/java/org/sinytra/adapter/patch/transformer/BundledMethodTransform.java @@ -11,20 +11,13 @@ import java.util.Collections; import java.util.List; -public record BundledMethodTransform(List transforms, boolean failFast) implements MethodTransform { - public BundledMethodTransform(List transforms) { - this(transforms, false); - } +public record BundledMethodTransform(List transforms) implements MethodTransform { @Override public Patch.Result apply(ClassNode classNode, MethodNode methodNode, MethodContext methodContext, PatchContext context) { Patch.Result result = Patch.Result.PASS; for (MethodTransform transform : this.transforms) { - Patch.Result transformResult = transform.apply(classNode, methodNode, methodContext, context); - if (transformResult == Patch.Result.PASS && this.failFast) { - return result; - } - result = result.or(transformResult); + result = result.or(transform.apply(classNode, methodNode, methodContext, context)); } return result; } @@ -34,16 +27,10 @@ public static Builder builder() { } public static class Builder extends MethodTransformBuilderImpl { - private Builder() { - - } - - public BundledMethodTransform build() { - return build(false); - } + private Builder() {} - public BundledMethodTransform build(boolean failFast) { - return new BundledMethodTransform(Collections.unmodifiableList(this.transforms), failFast); + public MethodTransform build() { + return this.transforms.size() == 1 ? this.transforms.getFirst() : new BundledMethodTransform(Collections.unmodifiableList(this.transforms)); } public Patch.Result apply(MethodContext methodContext) { diff --git a/definition/src/main/java/org/sinytra/adapter/patch/transformer/ChangeModifiedVariableIndex.java b/definition/src/main/java/org/sinytra/adapter/patch/transformer/ChangeModifiedVariableIndex.java deleted file mode 100644 index 32ca520..0000000 --- a/definition/src/main/java/org/sinytra/adapter/patch/transformer/ChangeModifiedVariableIndex.java +++ /dev/null @@ -1,41 +0,0 @@ -package org.sinytra.adapter.patch.transformer; - -import com.mojang.logging.LogUtils; -import com.mojang.serialization.Codec; -import com.mojang.serialization.codecs.RecordCodecBuilder; -import org.objectweb.asm.tree.ClassNode; -import org.objectweb.asm.tree.MethodNode; -import org.sinytra.adapter.patch.api.MethodContext; -import org.sinytra.adapter.patch.api.MethodTransform; -import org.sinytra.adapter.patch.api.Patch; -import org.sinytra.adapter.patch.api.PatchContext; -import org.slf4j.Logger; - -import static org.sinytra.adapter.patch.PatchInstance.MIXINPATCH; - -public record ChangeModifiedVariableIndex(int start, int offset) implements MethodTransform { - private static final Logger LOGGER = LogUtils.getLogger(); - public static final Codec CODEC = RecordCodecBuilder.create(instance -> instance.group( - Codec.INT.fieldOf("start").forGetter(ChangeModifiedVariableIndex::start), - Codec.INT.fieldOf("offset").forGetter(ChangeModifiedVariableIndex::offset) - ).apply(instance, ChangeModifiedVariableIndex::new)); - - @Override - public Codec codec() { - return CODEC; - } - - @Override - public Patch.Result apply(ClassNode classNode, MethodNode methodNode, MethodContext methodContext, PatchContext context) { - return methodContext.methodAnnotation().getValue("index") - .filter(index -> index.get() > -1) - .map(handle -> { - int index = handle.get(); - int newIndex = index >= this.start ? index + this.offset : index; - LOGGER.info(MIXINPATCH, "Updating variable index of variable modifier method {}.{} to {}", classNode.name, methodNode.name, newIndex); - handle.set(newIndex); - return Patch.Result.APPLY; - }) - .orElse(Patch.Result.PASS); - } -} diff --git a/definition/src/main/java/org/sinytra/adapter/patch/transformer/ModifyRedirectToWrapper.java b/definition/src/main/java/org/sinytra/adapter/patch/transformer/ModifyRedirectToWrapper.java deleted file mode 100644 index bbe718b..0000000 --- a/definition/src/main/java/org/sinytra/adapter/patch/transformer/ModifyRedirectToWrapper.java +++ /dev/null @@ -1,110 +0,0 @@ -package org.sinytra.adapter.patch.transformer; - -import com.google.common.collect.ImmutableList; -import com.google.common.collect.Lists; -import org.objectweb.asm.Opcodes; -import org.objectweb.asm.Type; -import org.objectweb.asm.tree.*; -import org.sinytra.adapter.patch.analysis.MethodCallAnalyzer; -import org.sinytra.adapter.patch.api.*; -import org.sinytra.adapter.patch.transformer.param.TransformParameters; -import org.sinytra.adapter.patch.util.AdapterUtil; -import org.sinytra.adapter.patch.analysis.LocalVariableLookup; -import org.sinytra.adapter.patch.util.MethodQualifier; -import org.sinytra.adapter.patch.util.OpcodeUtil; - -import java.util.*; -import java.util.stream.Collectors; -import java.util.stream.IntStream; - -public record ModifyRedirectToWrapper(MethodQualifier originalTarget, MethodQualifier newTarget) implements MethodTransform { - private static final Type OPERATION_TYPE = Type.getObjectType("com/llamalad7/mixinextras/injector/wrapoperation/Operation"); - - @Override - public Collection getAcceptedAnnotations() { - return Set.of(MixinConstants.REDIRECT); - } - - @Override - public Patch.Result apply(ClassNode classNode, MethodNode methodNode, MethodContext methodContext, PatchContext context) { - LocalVariableLookup lookup = new LocalVariableLookup(methodNode); - Type newOwnerType = Type.getType(this.newTarget.owner()); - boolean sameOwnerType = Type.getType(this.originalTarget.owner()).equals(newOwnerType); - - int offset = ((methodNode.access & Opcodes.ACC_STATIC) == 0 ? 1 : 0) - + (!sameOwnerType ? -1 : 0); - Set paramLvtIndices = IntStream.range(offset + 1, Type.getArgumentTypes(methodNode.desc).length + offset) - .map(i -> lookup.getByOrdinal(i).index) - .boxed() - .collect(Collectors.toSet()); - List> insns = MethodCallAnalyzer.getInvocationInsns(methodNode, this.originalTarget); - if (insns.isEmpty()) { - return Patch.Result.PASS; - } - List flatInsns = insns.stream().flatMap(Collection::stream).toList(); - Set loadedLocals = insns.stream() - .map(i -> i instanceof VarInsnNode varInsn ? varInsn.var : null) - .filter(Objects::nonNull) - .collect(Collectors.toSet()); - - for (AbstractInsnNode insn : methodNode.instructions) { - if (insn instanceof VarInsnNode varInsn && paramLvtIndices.contains(varInsn.var) && !loadedLocals.contains(varInsn.var) && !flatInsns.contains(insn)) { - return Patch.Result.PASS; - } - } - - TransformParameters removeOldParamsPatch = TransformParameters.builder() - .chain(b -> { - for (int i = Type.getArgumentTypes(methodNode.desc).length - 1; i >= offset; i--) { - b.remove(i); - } - }) - .build(); - removeOldParamsPatch.apply(classNode, methodNode, methodContext, context); - - List args = Lists.reverse(ImmutableList.builder() - .add(sameOwnerType ? new Type[0] : new Type[]{newOwnerType}) - .add(Type.getArgumentTypes(this.newTarget.desc())) - .build()); - TransformParameters addNewParamsPatch = TransformParameters.builder() - .chain(b -> { - for (int i = 0; i < args.size(); i++) { - Type type = args.get(i); - b.inject(i, type); - } - b.inject(args.size(), OPERATION_TYPE); - }) - .build(); - addNewParamsPatch.apply(classNode, methodNode, methodContext, context); - - LocalVariableLookup updatedLookup = new LocalVariableLookup(methodNode); - LocalVariableNode operationVar = updatedLookup.getForType(OPERATION_TYPE).getFirst(); - int operationParamOrdinal = updatedLookup.getOrdinal(operationVar); - List localVars = new ArrayList<>(); - for (int i = 1; i < operationParamOrdinal; i++) { - localVars.add(updatedLookup.getByOrdinal(i)); - } - InsnList originalCallInsns = AdapterUtil.insnsWithAdapter(a -> { - a.load(operationVar.index, OPERATION_TYPE); - a.iconst(localVars.size()); - a.newarray(Type.getObjectType("java/lang/Object")); - for (int i = 0; i < localVars.size(); i++) { - LocalVariableNode lvn = localVars.get(i); - Type type = Type.getType(lvn.desc); - - a.dup(); - a.iconst(i); - a.load(lvn.index, type); - a.visitInsn(Opcodes.AASTORE); - } - a.invokeinterface("com/llamalad7/mixinextras/injector/wrapoperation/Operation", "call", "([Ljava/lang/Object;)Ljava/lang/Object;"); - OpcodeUtil.castObjectType(Type.getReturnType(this.newTarget.desc()), a); - }); - for (List list : insns) { - methodNode.instructions.insertBefore(list.getFirst(), originalCallInsns); - list.forEach(methodNode.instructions::remove); - } - - return Patch.Result.APPLY; - } -} diff --git a/definition/src/main/java/org/sinytra/adapter/patch/transformer/ModifyVarUpgradeToModifyExprVal.java b/definition/src/main/java/org/sinytra/adapter/patch/transformer/ModifyVarUpgradeToModifyExprVal.java index 24bc71b..c4d7a94 100644 --- a/definition/src/main/java/org/sinytra/adapter/patch/transformer/ModifyVarUpgradeToModifyExprVal.java +++ b/definition/src/main/java/org/sinytra/adapter/patch/transformer/ModifyVarUpgradeToModifyExprVal.java @@ -3,8 +3,9 @@ import org.objectweb.asm.tree.ClassNode; import org.objectweb.asm.tree.MethodNode; import org.sinytra.adapter.patch.api.*; -import org.sinytra.adapter.patch.selector.AnnotationHandle; -import org.sinytra.adapter.patch.selector.AnnotationValueHandle; +import org.sinytra.adapter.patch.analysis.selector.AnnotationHandle; +import org.sinytra.adapter.patch.analysis.selector.AnnotationValueHandle; +import org.sinytra.adapter.patch.transformer.operation.ModifyMixinType; import java.util.Collection; import java.util.Set; diff --git a/definition/src/main/java/org/sinytra/adapter/patch/transformer/RedirectAccessor.java b/definition/src/main/java/org/sinytra/adapter/patch/transformer/RedirectAccessor.java deleted file mode 100644 index abb2e61..0000000 --- a/definition/src/main/java/org/sinytra/adapter/patch/transformer/RedirectAccessor.java +++ /dev/null @@ -1,37 +0,0 @@ -package org.sinytra.adapter.patch.transformer; - -import com.mojang.logging.LogUtils; -import org.objectweb.asm.tree.ClassNode; -import org.objectweb.asm.tree.MethodNode; -import org.sinytra.adapter.patch.api.*; -import org.sinytra.adapter.patch.selector.AnnotationHandle; -import org.sinytra.adapter.patch.selector.AnnotationValueHandle; -import org.slf4j.Logger; - -import java.util.Collection; -import java.util.Set; - -import static org.sinytra.adapter.patch.PatchInstance.MIXINPATCH; - -public record RedirectAccessor(String value) implements MethodTransform { - private static final Logger LOGGER = LogUtils.getLogger(); - - @Override - public Collection getAcceptedAnnotations() { - return Set.of(MixinConstants.ACCESSOR); - } - - @Override - public Patch.Result apply(ClassNode classNode, MethodNode methodNode, MethodContext methodContext, PatchContext context) { - AnnotationHandle annotation = methodContext.methodAnnotation(); - AnnotationValueHandle valueHandle = annotation.getValue("value").orElse(null); - if (valueHandle == null) { - annotation.appendValue("value", this.value); - } - else { - valueHandle.set(this.value); - } - LOGGER.info(MIXINPATCH, "Redirecting accessor {}.{} to field {}", classNode.name, methodNode.name, this.value); - return Patch.Result.APPLY; - } -} diff --git a/definition/src/main/java/org/sinytra/adapter/patch/transformer/RedirectShadowMethod.java b/definition/src/main/java/org/sinytra/adapter/patch/transformer/RedirectShadowMethod.java deleted file mode 100644 index 8594204..0000000 --- a/definition/src/main/java/org/sinytra/adapter/patch/transformer/RedirectShadowMethod.java +++ /dev/null @@ -1,56 +0,0 @@ -package org.sinytra.adapter.patch.transformer; - -import com.mojang.logging.LogUtils; -import org.jetbrains.annotations.Nullable; -import org.objectweb.asm.tree.*; -import org.sinytra.adapter.patch.api.ClassTransform; -import org.sinytra.adapter.patch.api.MixinConstants; -import org.sinytra.adapter.patch.api.Patch; -import org.sinytra.adapter.patch.api.PatchContext; -import org.sinytra.adapter.patch.selector.AnnotationValueHandle; -import org.sinytra.adapter.patch.util.MethodQualifier; -import org.slf4j.Logger; - -import java.util.function.BiConsumer; - -import static org.sinytra.adapter.patch.PatchInstance.MIXINPATCH; - -public record RedirectShadowMethod(MethodQualifier original, MethodQualifier replacement, - BiConsumer callFixer) implements ClassTransform { - private static final Logger LOGGER = LogUtils.getLogger(); - - public RedirectShadowMethod(String original, String replacement, BiConsumer callFixer) { - this(MethodQualifier.create(original).orElseThrow(), MethodQualifier.create(replacement).orElseThrow(), callFixer); - } - - @Override - public Patch.Result apply(ClassNode classNode, @Nullable AnnotationValueHandle annotation, PatchContext context) { - for (MethodNode method : classNode.methods) { - MethodQualifier qualifier = new MethodQualifier(method.name, method.desc); - if (this.original.equals(qualifier) && method.visibleAnnotations != null) { - for (AnnotationNode methodAnn : method.visibleAnnotations) { - if (MixinConstants.SHADOW.equals(methodAnn.desc)) { - LOGGER.info(MIXINPATCH, "Redirecting shadow method {}.{} to {}{}", classNode.name, method.name, this.replacement.name(), this.replacement.desc()); - method.name = this.replacement.name(); - method.desc = this.replacement.desc(); - patchMethodCalls(classNode); - return Patch.Result.APPLY; - } - } - } - } - return Patch.Result.PASS; - } - - private void patchMethodCalls(ClassNode classNode) { - for (MethodNode method : classNode.methods) { - for (AbstractInsnNode insn : method.instructions) { - if (insn instanceof MethodInsnNode minsn && minsn.owner.equals(classNode.name) && minsn.name.equals(this.original.name()) && minsn.desc.equals(this.original.desc())) { - minsn.name = this.replacement.name(); - minsn.desc = this.replacement.desc(); - this.callFixer.accept(minsn, method.instructions); - } - } - } - } -} diff --git a/definition/src/main/java/org/sinytra/adapter/patch/transformer/SoftMethodParamsPatch.java b/definition/src/main/java/org/sinytra/adapter/patch/transformer/SoftMethodParamsPatch.java index 34b4a26..db757b8 100644 --- a/definition/src/main/java/org/sinytra/adapter/patch/transformer/SoftMethodParamsPatch.java +++ b/definition/src/main/java/org/sinytra/adapter/patch/transformer/SoftMethodParamsPatch.java @@ -9,8 +9,8 @@ import org.sinytra.adapter.patch.analysis.params.ParametersDiff; import org.sinytra.adapter.patch.api.*; import org.sinytra.adapter.patch.fixes.BytecodeFixerUpper; -import org.sinytra.adapter.patch.serialization.MethodTransformSerialization; -import org.sinytra.adapter.patch.transformer.param.TransformParameters; +import org.sinytra.adapter.patch.transformer.serialization.MethodTransformSerialization; +import org.sinytra.adapter.patch.transformer.operation.param.TransformParameters; import org.sinytra.adapter.patch.util.AdapterUtil; import org.sinytra.adapter.patch.util.MethodQualifier; diff --git a/definition/src/main/java/org/sinytra/adapter/patch/transformer/SplitMixinTransform.java b/definition/src/main/java/org/sinytra/adapter/patch/transformer/SplitMixinTransform.java deleted file mode 100644 index 87372d6..0000000 --- a/definition/src/main/java/org/sinytra/adapter/patch/transformer/SplitMixinTransform.java +++ /dev/null @@ -1,28 +0,0 @@ -package org.sinytra.adapter.patch.transformer; - -import org.objectweb.asm.Type; -import org.objectweb.asm.tree.ClassNode; -import org.objectweb.asm.tree.MethodNode; -import org.sinytra.adapter.patch.api.*; - -import java.util.Collection; -import java.util.Set; - -public record SplitMixinTransform(String targetClass) implements MethodTransform { - - @Override - public Collection getAcceptedAnnotations() { - return Set.of(MixinConstants.WRAP_WITH_CONDITION, MixinConstants.WRAP_OPERATION, MixinConstants.MODIFY_CONST, MixinConstants.MODIFY_ARG, MixinConstants.INJECT, MixinConstants.REDIRECT, MixinConstants.MODIFY_VAR, MixinConstants.MODIFY_EXPR_VAL); - } - - @Override - public Patch.Result apply(ClassNode classNode, MethodNode methodNode, MethodContext methodContext, PatchContext context) { - MethodTransform transform = new ExtractMixin(this.targetClass, false); - Patch.Result result = transform.apply(classNode, methodNode, methodContext, context); - if (methodContext.targetTypes().size() > 1) { - MethodTransform removeTarget = new ModifyTargetClasses(l -> l.remove(Type.getObjectType(this.targetClass))); - removeTarget.apply(classNode, methodNode, methodContext, context); - } - return result; - } -} diff --git a/definition/src/main/java/org/sinytra/adapter/patch/transformer/dynamic/DynamicAnonymousShadowFieldTypePatch.java b/definition/src/main/java/org/sinytra/adapter/patch/transformer/dynamic/DynamicAnonymousShadowFieldTypePatch.java index c3be393..2c43afe 100644 --- a/definition/src/main/java/org/sinytra/adapter/patch/transformer/dynamic/DynamicAnonymousShadowFieldTypePatch.java +++ b/definition/src/main/java/org/sinytra/adapter/patch/transformer/dynamic/DynamicAnonymousShadowFieldTypePatch.java @@ -9,7 +9,7 @@ import org.sinytra.adapter.patch.api.MixinConstants; import org.sinytra.adapter.patch.api.Patch; import org.sinytra.adapter.patch.api.PatchContext; -import org.sinytra.adapter.patch.selector.AnnotationValueHandle; +import org.sinytra.adapter.patch.analysis.selector.AnnotationValueHandle; import org.sinytra.adapter.patch.util.AdapterUtil; import org.slf4j.Logger; diff --git a/definition/src/main/java/org/sinytra/adapter/patch/transformer/dynamic/DynamicInheritedInjectionPointPatch.java b/definition/src/main/java/org/sinytra/adapter/patch/transformer/dynamic/DynamicInheritedInjectionPointPatch.java index d188ed9..53e5b40 100644 --- a/definition/src/main/java/org/sinytra/adapter/patch/transformer/dynamic/DynamicInheritedInjectionPointPatch.java +++ b/definition/src/main/java/org/sinytra/adapter/patch/transformer/dynamic/DynamicInheritedInjectionPointPatch.java @@ -6,8 +6,8 @@ import org.sinytra.adapter.patch.analysis.MethodCallAnalyzer; import org.sinytra.adapter.patch.api.*; import org.sinytra.adapter.patch.fixes.BytecodeFixerUpper; -import org.sinytra.adapter.patch.selector.AnnotationHandle; -import org.sinytra.adapter.patch.selector.AnnotationValueHandle; +import org.sinytra.adapter.patch.analysis.selector.AnnotationHandle; +import org.sinytra.adapter.patch.analysis.selector.AnnotationValueHandle; import org.sinytra.adapter.patch.util.MethodQualifier; import org.slf4j.Logger; diff --git a/definition/src/main/java/org/sinytra/adapter/patch/transformer/dynamic/DynamicInjectorOrdinalPatch.java b/definition/src/main/java/org/sinytra/adapter/patch/transformer/dynamic/DynamicInjectorOrdinalPatch.java index 659ef92..e15a924 100644 --- a/definition/src/main/java/org/sinytra/adapter/patch/transformer/dynamic/DynamicInjectorOrdinalPatch.java +++ b/definition/src/main/java/org/sinytra/adapter/patch/transformer/dynamic/DynamicInjectorOrdinalPatch.java @@ -10,8 +10,8 @@ import org.sinytra.adapter.patch.PatchInstance; import org.sinytra.adapter.patch.analysis.*; import org.sinytra.adapter.patch.api.*; -import org.sinytra.adapter.patch.selector.AnnotationHandle; -import org.sinytra.adapter.patch.selector.AnnotationValueHandle; +import org.sinytra.adapter.patch.analysis.selector.AnnotationHandle; +import org.sinytra.adapter.patch.analysis.selector.AnnotationValueHandle; import org.sinytra.adapter.patch.util.AdapterUtil; import org.sinytra.adapter.patch.util.GeneratedVariables; import org.sinytra.adapter.patch.util.SingleValueHandle; diff --git a/definition/src/main/java/org/sinytra/adapter/patch/transformer/dynamic/DynamicLVTPatch.java b/definition/src/main/java/org/sinytra/adapter/patch/transformer/dynamic/DynamicLVTPatch.java index 9c4406e..fb2e643 100644 --- a/definition/src/main/java/org/sinytra/adapter/patch/transformer/dynamic/DynamicLVTPatch.java +++ b/definition/src/main/java/org/sinytra/adapter/patch/transformer/dynamic/DynamicLVTPatch.java @@ -19,9 +19,9 @@ import org.sinytra.adapter.patch.analysis.params.ParamsDiffSnapshot; import org.sinytra.adapter.patch.analysis.params.SimpleParamsDiffSnapshot; import org.sinytra.adapter.patch.api.*; -import org.sinytra.adapter.patch.selector.AnnotationHandle; -import org.sinytra.adapter.patch.selector.AnnotationValueHandle; -import org.sinytra.adapter.patch.transformer.param.ParamTransformTarget; +import org.sinytra.adapter.patch.analysis.selector.AnnotationHandle; +import org.sinytra.adapter.patch.analysis.selector.AnnotationValueHandle; +import org.sinytra.adapter.patch.transformer.operation.param.ParamTransformTarget; import org.sinytra.adapter.patch.util.AdapterUtil; import org.slf4j.Logger; import org.spongepowered.asm.mixin.FabricUtil; diff --git a/definition/src/main/java/org/sinytra/adapter/patch/transformer/dynamic/DynamicModifyVarAtReturnPatch.java b/definition/src/main/java/org/sinytra/adapter/patch/transformer/dynamic/DynamicModifyVarAtReturnPatch.java index 088af1c..dba1cf4 100644 --- a/definition/src/main/java/org/sinytra/adapter/patch/transformer/dynamic/DynamicModifyVarAtReturnPatch.java +++ b/definition/src/main/java/org/sinytra/adapter/patch/transformer/dynamic/DynamicModifyVarAtReturnPatch.java @@ -10,9 +10,9 @@ import org.sinytra.adapter.patch.PatchInstance; import org.sinytra.adapter.patch.analysis.MethodCallAnalyzer; import org.sinytra.adapter.patch.api.*; -import org.sinytra.adapter.patch.selector.AnnotationHandle; -import org.sinytra.adapter.patch.selector.AnnotationValueHandle; -import org.sinytra.adapter.patch.transformer.ModifyMixinType; +import org.sinytra.adapter.patch.analysis.selector.AnnotationHandle; +import org.sinytra.adapter.patch.analysis.selector.AnnotationValueHandle; +import org.sinytra.adapter.patch.transformer.operation.ModifyMixinType; import org.sinytra.adapter.patch.util.MockMixinRuntime; import org.slf4j.Logger; import org.spongepowered.asm.mixin.injection.modify.LocalVariableDiscriminator; diff --git a/definition/src/main/java/org/sinytra/adapter/patch/transformer/dynamic/DynamicSyntheticInstanceofPatch.java b/definition/src/main/java/org/sinytra/adapter/patch/transformer/dynamic/DynamicSyntheticInstanceofPatch.java index 6f9714e..91dbccb 100644 --- a/definition/src/main/java/org/sinytra/adapter/patch/transformer/dynamic/DynamicSyntheticInstanceofPatch.java +++ b/definition/src/main/java/org/sinytra/adapter/patch/transformer/dynamic/DynamicSyntheticInstanceofPatch.java @@ -6,8 +6,8 @@ import org.sinytra.adapter.patch.analysis.InstructionMatcher; import org.sinytra.adapter.patch.analysis.MethodCallAnalyzer; import org.sinytra.adapter.patch.api.*; -import org.sinytra.adapter.patch.transformer.DisableMixin; -import org.sinytra.adapter.patch.transformer.ModifyMixinType; +import org.sinytra.adapter.patch.transformer.operation.DisableMixin; +import org.sinytra.adapter.patch.transformer.operation.ModifyMixinType; import java.util.*; diff --git a/definition/src/main/java/org/sinytra/adapter/patch/transformer/dynfix/DynFixArbitraryInjectionPoint.java b/definition/src/main/java/org/sinytra/adapter/patch/transformer/dynfix/DynFixArbitraryInjectionPoint.java index 97ec814..de01d4a 100644 --- a/definition/src/main/java/org/sinytra/adapter/patch/transformer/dynfix/DynFixArbitraryInjectionPoint.java +++ b/definition/src/main/java/org/sinytra/adapter/patch/transformer/dynfix/DynFixArbitraryInjectionPoint.java @@ -9,8 +9,8 @@ import org.sinytra.adapter.patch.api.MethodContext; import org.sinytra.adapter.patch.api.MixinConstants; import org.sinytra.adapter.patch.api.Patch; -import org.sinytra.adapter.patch.transformer.ModifyInjectionPoint; -import org.sinytra.adapter.patch.transformer.ModifyInjectionTarget; +import org.sinytra.adapter.patch.transformer.operation.ModifyInjectionPoint; +import org.sinytra.adapter.patch.transformer.operation.ModifyInjectionTarget; import org.sinytra.adapter.patch.util.AdapterUtil; import java.util.ArrayList; diff --git a/definition/src/main/java/org/sinytra/adapter/patch/transformer/dynfix/DynFixAtVariableAssignStore.java b/definition/src/main/java/org/sinytra/adapter/patch/transformer/dynfix/DynFixAtVariableAssignStore.java index b5419c1..24c4cad 100644 --- a/definition/src/main/java/org/sinytra/adapter/patch/transformer/dynfix/DynFixAtVariableAssignStore.java +++ b/definition/src/main/java/org/sinytra/adapter/patch/transformer/dynfix/DynFixAtVariableAssignStore.java @@ -6,8 +6,8 @@ import org.sinytra.adapter.patch.api.MethodContext; import org.sinytra.adapter.patch.api.MixinConstants; import org.sinytra.adapter.patch.api.Patch; -import org.sinytra.adapter.patch.transformer.ModifyInjectionPoint; -import org.sinytra.adapter.patch.transformer.ModifyInjectionTarget; +import org.sinytra.adapter.patch.transformer.operation.ModifyInjectionPoint; +import org.sinytra.adapter.patch.transformer.operation.ModifyInjectionTarget; import org.sinytra.adapter.patch.util.AdapterUtil; import org.sinytra.adapter.patch.util.OpcodeUtil; diff --git a/definition/src/main/java/org/sinytra/adapter/patch/transformer/dynfix/DynFixMethodComparison.java b/definition/src/main/java/org/sinytra/adapter/patch/transformer/dynfix/DynFixMethodComparison.java index fd8ce76..a6f9403 100644 --- a/definition/src/main/java/org/sinytra/adapter/patch/transformer/dynfix/DynFixMethodComparison.java +++ b/definition/src/main/java/org/sinytra/adapter/patch/transformer/dynfix/DynFixMethodComparison.java @@ -13,12 +13,12 @@ import org.sinytra.adapter.patch.api.MethodContext; import org.sinytra.adapter.patch.api.MixinConstants; import org.sinytra.adapter.patch.api.Patch; -import org.sinytra.adapter.patch.selector.AnnotationHandle; -import org.sinytra.adapter.patch.selector.AnnotationValueHandle; +import org.sinytra.adapter.patch.fixes.MethodUpgrader; +import org.sinytra.adapter.patch.analysis.selector.AnnotationHandle; import org.sinytra.adapter.patch.transformer.BundledMethodTransform; -import org.sinytra.adapter.patch.transformer.MirrorableExtractMixin; -import org.sinytra.adapter.patch.transformer.ModifyInjectionPoint; -import org.sinytra.adapter.patch.transformer.param.*; +import org.sinytra.adapter.patch.transformer.operation.ModifyInjectionPoint; +import org.sinytra.adapter.patch.transformer.operation.param.*; +import org.sinytra.adapter.patch.transformer.pipeline.MethodTransformationPipeline; import org.sinytra.adapter.patch.util.AdapterUtil; import java.util.HashSet; @@ -201,52 +201,22 @@ private static Patch.Result attemptExtractMixin(MethodInsnNode minsn, MethodCont if (targetClass == null) { return Patch.Result.PASS; } + MethodNode targetMethod = methodContext.patchContext().environment().dirtyClassLookup().findMethod(minsn.owner, minsn.name, minsn.desc).orElse(null); if (targetMethod == null) { return Patch.Result.PASS; } - adjustInjectorOrdinalForNewMethod(minsn, methodContext); + + MethodUpgrader.adjustInjectorOrdinalForNewMethod(minsn, methodContext); List newTargetInsns = methodContext.findInjectionTargetInsns(new MethodContext.TargetPair(targetClass, targetMethod)); if (newTargetInsns.isEmpty()) { return Patch.Result.PASS; } - Patch.Result res = BundledMethodTransform.builder() - .extractMixin(minsn.owner) - // Applied only if previous transform succeeds - .modifyTarget(minsn.name + minsn.desc) - .build(true) - .apply(methodContext); - if (res != Patch.Result.PASS) { - return res; - } - // Extraction failed? Let's try something else - return new MirrorableExtractMixin(targetClass.name, minsn).apply(methodContext); - } - // TODO This should be an automatic upgrade tbh - private static void adjustInjectorOrdinalForNewMethod(MethodInsnNode minsn, MethodContext methodContext) { - AnnotationValueHandle handle = methodContext.injectionPointAnnotationOrThrow().getValue("ordinal").orElse(null); - if (handle == null) { - return; - } - int originalOrdinal = handle.get(); - // Temporarily adjust ordinal to account for previous calls that have not been moved to the new class - if (handle != null) { - handle.set(-1); - List insns = methodContext.computeInjectionTargetInsns(methodContext.findDirtyInjectionTarget()); - handle.set(originalOrdinal); - int newOrdinal = originalOrdinal; - for (AbstractInsnNode insn : methodContext.findDirtyInjectionTarget().methodNode().instructions) { - if (insn == minsn) { - break; - } - if (insns.contains(insn)) { - newOrdinal--; - } - } - if (newOrdinal >= 0) { - handle.set(newOrdinal); - } - } + return MethodTransformationPipeline.builder(b -> b.extractMixin(minsn.owner)) + .onSuccess(b -> b.modifyTarget(minsn.name + minsn.desc)) + // Extraction failed? Let's try something else + .onFail(() -> new MirrorableExtractMixin(targetClass.name, minsn)) + .apply(methodContext); } } diff --git a/definition/src/main/java/org/sinytra/adapter/patch/transformer/dynfix/DynFixSliceBoundary.java b/definition/src/main/java/org/sinytra/adapter/patch/transformer/dynfix/DynFixSliceBoundary.java index 8d7b8d9..b325d36 100644 --- a/definition/src/main/java/org/sinytra/adapter/patch/transformer/dynfix/DynFixSliceBoundary.java +++ b/definition/src/main/java/org/sinytra/adapter/patch/transformer/dynfix/DynFixSliceBoundary.java @@ -5,8 +5,8 @@ import org.objectweb.asm.tree.*; import org.sinytra.adapter.patch.api.MethodContext; import org.sinytra.adapter.patch.api.Patch; -import org.sinytra.adapter.patch.selector.AnnotationHandle; -import org.sinytra.adapter.patch.selector.AnnotationValueHandle; +import org.sinytra.adapter.patch.analysis.selector.AnnotationHandle; +import org.sinytra.adapter.patch.analysis.selector.AnnotationValueHandle; import org.sinytra.adapter.patch.util.MethodQualifier; import org.sinytra.adapter.patch.util.MockMixinRuntime; import org.spongepowered.asm.mixin.injection.code.ISliceContext; diff --git a/definition/src/main/java/org/sinytra/adapter/patch/transformer/dynfix/DynFixSplitMethod.java b/definition/src/main/java/org/sinytra/adapter/patch/transformer/dynfix/DynFixSplitMethod.java index 249d1f9..1651b98 100644 --- a/definition/src/main/java/org/sinytra/adapter/patch/transformer/dynfix/DynFixSplitMethod.java +++ b/definition/src/main/java/org/sinytra/adapter/patch/transformer/dynfix/DynFixSplitMethod.java @@ -6,7 +6,7 @@ import org.sinytra.adapter.patch.analysis.MethodCallAnalyzer; import org.sinytra.adapter.patch.api.MethodContext; import org.sinytra.adapter.patch.api.Patch; -import org.sinytra.adapter.patch.transformer.ModifyInjectionTarget; +import org.sinytra.adapter.patch.transformer.operation.ModifyInjectionTarget; import org.sinytra.adapter.patch.util.AdapterUtil; import org.sinytra.adapter.patch.util.OpcodeUtil; import org.slf4j.Logger; diff --git a/definition/src/main/java/org/sinytra/adapter/patch/transformer/MirrorableExtractMixin.java b/definition/src/main/java/org/sinytra/adapter/patch/transformer/dynfix/MirrorableExtractMixin.java similarity index 97% rename from definition/src/main/java/org/sinytra/adapter/patch/transformer/MirrorableExtractMixin.java rename to definition/src/main/java/org/sinytra/adapter/patch/transformer/dynfix/MirrorableExtractMixin.java index 19cad56..ea51574 100644 --- a/definition/src/main/java/org/sinytra/adapter/patch/transformer/MirrorableExtractMixin.java +++ b/definition/src/main/java/org/sinytra/adapter/patch/transformer/dynfix/MirrorableExtractMixin.java @@ -1,4 +1,4 @@ -package org.sinytra.adapter.patch.transformer; +package org.sinytra.adapter.patch.transformer.dynfix; import com.google.common.collect.ImmutableList; import org.objectweb.asm.Opcodes; @@ -8,6 +8,7 @@ import org.objectweb.asm.tree.*; import org.sinytra.adapter.patch.analysis.MethodCallAnalyzer; import org.sinytra.adapter.patch.api.*; +import org.sinytra.adapter.patch.transformer.BundledMethodTransform; import org.sinytra.adapter.patch.util.AdapterUtil; import org.sinytra.adapter.patch.util.OpcodeUtil; diff --git a/definition/src/main/java/org/sinytra/adapter/patch/transformer/filter/InjectionPointTransformerFilter.java b/definition/src/main/java/org/sinytra/adapter/patch/transformer/filter/InjectionPointTransformerFilter.java deleted file mode 100644 index 92b650c..0000000 --- a/definition/src/main/java/org/sinytra/adapter/patch/transformer/filter/InjectionPointTransformerFilter.java +++ /dev/null @@ -1,49 +0,0 @@ -package org.sinytra.adapter.patch.transformer.filter; - -import com.mojang.serialization.Codec; -import com.mojang.serialization.codecs.RecordCodecBuilder; -import org.objectweb.asm.tree.ClassNode; -import org.objectweb.asm.tree.MethodNode; -import org.sinytra.adapter.patch.api.MethodContext; -import org.sinytra.adapter.patch.api.MethodTransform; -import org.sinytra.adapter.patch.api.Patch; -import org.sinytra.adapter.patch.api.PatchContext; -import org.sinytra.adapter.patch.selector.AnnotationValueHandle; -import org.sinytra.adapter.patch.selector.InjectionPointMatcher; -import org.sinytra.adapter.patch.serialization.MethodTransformSerialization; - -import java.util.Collection; -import java.util.List; - -public record InjectionPointTransformerFilter(MethodTransform wrapped, List excludedInjectionPoints) implements MethodTransform { - public static final Codec CODEC = RecordCodecBuilder.create(instance -> instance.group( - MethodTransformSerialization.METHOD_TRANSFORM_CODEC.fieldOf("wrapped").forGetter(InjectionPointTransformerFilter::wrapped), - InjectionPointMatcher.CODEC.listOf().fieldOf("excludedInjectionPoints").forGetter(InjectionPointTransformerFilter::excludedInjectionPoints) - ).apply(instance, InjectionPointTransformerFilter::new)); - - public static InjectionPointTransformerFilter create(MethodTransform wrapped, List excludedInjectionPoints) { - return new InjectionPointTransformerFilter(wrapped, excludedInjectionPoints.stream().map(str -> new InjectionPointMatcher((String) null, str)).toList()); - } - - @Override - public Codec codec() { - return CODEC; - } - - @Override - public Collection getAcceptedAnnotations() { - return this.wrapped.getAcceptedAnnotations(); - } - - @Override - public Patch.Result apply(ClassNode classNode, MethodNode methodNode, MethodContext methodContext, PatchContext context) { - String injectionPoint = methodContext.injectionPointAnnotation().getValue("target") - .map(AnnotationValueHandle::get) - .map(context::remap) - .orElse(null); - if (injectionPoint != null && this.excludedInjectionPoints.stream().anyMatch(matcher -> matcher.test(null, injectionPoint))) { - return Patch.Result.PASS; - } - return this.wrapped.apply(classNode, methodNode, methodContext, context); - } -} diff --git a/definition/src/main/java/org/sinytra/adapter/patch/transformer/DisableMixin.java b/definition/src/main/java/org/sinytra/adapter/patch/transformer/operation/DisableMixin.java similarity index 95% rename from definition/src/main/java/org/sinytra/adapter/patch/transformer/DisableMixin.java rename to definition/src/main/java/org/sinytra/adapter/patch/transformer/operation/DisableMixin.java index ef43b85..af82c08 100644 --- a/definition/src/main/java/org/sinytra/adapter/patch/transformer/DisableMixin.java +++ b/definition/src/main/java/org/sinytra/adapter/patch/transformer/operation/DisableMixin.java @@ -1,4 +1,4 @@ -package org.sinytra.adapter.patch.transformer; +package org.sinytra.adapter.patch.transformer.operation; import com.mojang.logging.LogUtils; import com.mojang.serialization.Codec; diff --git a/definition/src/main/java/org/sinytra/adapter/patch/transformer/DivertRedirectorTransform.java b/definition/src/main/java/org/sinytra/adapter/patch/transformer/operation/DivertRedirectorTransform.java similarity index 94% rename from definition/src/main/java/org/sinytra/adapter/patch/transformer/DivertRedirectorTransform.java rename to definition/src/main/java/org/sinytra/adapter/patch/transformer/operation/DivertRedirectorTransform.java index d1b1b1c..4a87a71 100644 --- a/definition/src/main/java/org/sinytra/adapter/patch/transformer/DivertRedirectorTransform.java +++ b/definition/src/main/java/org/sinytra/adapter/patch/transformer/operation/DivertRedirectorTransform.java @@ -1,10 +1,10 @@ -package org.sinytra.adapter.patch.transformer; +package org.sinytra.adapter.patch.transformer.operation; import org.objectweb.asm.Opcodes; import org.objectweb.asm.commons.InstructionAdapter; import org.objectweb.asm.tree.*; import org.sinytra.adapter.patch.api.*; -import org.sinytra.adapter.patch.selector.AnnotationValueHandle; +import org.sinytra.adapter.patch.analysis.selector.AnnotationValueHandle; import org.sinytra.adapter.patch.util.MethodQualifier; import java.util.Collection; diff --git a/definition/src/main/java/org/sinytra/adapter/patch/transformer/ExtractMixin.java b/definition/src/main/java/org/sinytra/adapter/patch/transformer/operation/ExtractMixin.java similarity index 99% rename from definition/src/main/java/org/sinytra/adapter/patch/transformer/ExtractMixin.java rename to definition/src/main/java/org/sinytra/adapter/patch/transformer/operation/ExtractMixin.java index b6b5961..ec10989 100644 --- a/definition/src/main/java/org/sinytra/adapter/patch/transformer/ExtractMixin.java +++ b/definition/src/main/java/org/sinytra/adapter/patch/transformer/operation/ExtractMixin.java @@ -1,4 +1,4 @@ -package org.sinytra.adapter.patch.transformer; +package org.sinytra.adapter.patch.transformer.operation; import it.unimi.dsi.fastutil.ints.Int2IntMap; import it.unimi.dsi.fastutil.ints.Int2ObjectMap; @@ -9,7 +9,7 @@ import org.sinytra.adapter.patch.analysis.LocalVarAnalyzer; import org.sinytra.adapter.patch.analysis.LocalVariableLookup; import org.sinytra.adapter.patch.api.*; -import org.sinytra.adapter.patch.transformer.param.TransformParameters; +import org.sinytra.adapter.patch.transformer.operation.param.TransformParameters; import org.sinytra.adapter.patch.util.AdapterUtil; import org.sinytra.adapter.patch.util.OpcodeUtil; diff --git a/definition/src/main/java/org/sinytra/adapter/patch/transformer/ModifyInjectionPoint.java b/definition/src/main/java/org/sinytra/adapter/patch/transformer/operation/ModifyInjectionPoint.java similarity index 93% rename from definition/src/main/java/org/sinytra/adapter/patch/transformer/ModifyInjectionPoint.java rename to definition/src/main/java/org/sinytra/adapter/patch/transformer/operation/ModifyInjectionPoint.java index fdc9801..7ac2dd1 100644 --- a/definition/src/main/java/org/sinytra/adapter/patch/transformer/ModifyInjectionPoint.java +++ b/definition/src/main/java/org/sinytra/adapter/patch/transformer/operation/ModifyInjectionPoint.java @@ -1,4 +1,4 @@ -package org.sinytra.adapter.patch.transformer; +package org.sinytra.adapter.patch.transformer.operation; import com.mojang.logging.LogUtils; import com.mojang.serialization.Codec; @@ -11,8 +11,8 @@ import org.sinytra.adapter.patch.api.Patch; import org.sinytra.adapter.patch.api.PatchContext; import org.sinytra.adapter.patch.fixes.MethodUpgrader; -import org.sinytra.adapter.patch.selector.AnnotationHandle; -import org.sinytra.adapter.patch.selector.AnnotationValueHandle; +import org.sinytra.adapter.patch.analysis.selector.AnnotationHandle; +import org.sinytra.adapter.patch.analysis.selector.AnnotationValueHandle; import org.slf4j.Logger; import java.util.Optional; diff --git a/definition/src/main/java/org/sinytra/adapter/patch/transformer/ModifyInjectionTarget.java b/definition/src/main/java/org/sinytra/adapter/patch/transformer/operation/ModifyInjectionTarget.java similarity index 94% rename from definition/src/main/java/org/sinytra/adapter/patch/transformer/ModifyInjectionTarget.java rename to definition/src/main/java/org/sinytra/adapter/patch/transformer/operation/ModifyInjectionTarget.java index c5f1a4d..ed8ec22 100644 --- a/definition/src/main/java/org/sinytra/adapter/patch/transformer/ModifyInjectionTarget.java +++ b/definition/src/main/java/org/sinytra/adapter/patch/transformer/operation/ModifyInjectionTarget.java @@ -1,4 +1,4 @@ -package org.sinytra.adapter.patch.transformer; +package org.sinytra.adapter.patch.transformer.operation; import com.mojang.logging.LogUtils; import com.mojang.serialization.Codec; @@ -7,8 +7,8 @@ import org.objectweb.asm.tree.MethodNode; import org.sinytra.adapter.patch.api.*; import org.sinytra.adapter.patch.fixes.MethodUpgrader; -import org.sinytra.adapter.patch.selector.AnnotationHandle; -import org.sinytra.adapter.patch.selector.AnnotationValueHandle; +import org.sinytra.adapter.patch.analysis.selector.AnnotationHandle; +import org.sinytra.adapter.patch.analysis.selector.AnnotationValueHandle; import org.sinytra.adapter.patch.util.MethodQualifier; import org.slf4j.Logger; diff --git a/definition/src/main/java/org/sinytra/adapter/patch/transformer/ModifyMethodAccess.java b/definition/src/main/java/org/sinytra/adapter/patch/transformer/operation/ModifyMethodAccess.java similarity index 98% rename from definition/src/main/java/org/sinytra/adapter/patch/transformer/ModifyMethodAccess.java rename to definition/src/main/java/org/sinytra/adapter/patch/transformer/operation/ModifyMethodAccess.java index 00a3439..5aefe76 100644 --- a/definition/src/main/java/org/sinytra/adapter/patch/transformer/ModifyMethodAccess.java +++ b/definition/src/main/java/org/sinytra/adapter/patch/transformer/operation/ModifyMethodAccess.java @@ -1,4 +1,4 @@ -package org.sinytra.adapter.patch.transformer; +package org.sinytra.adapter.patch.transformer.operation; import com.mojang.logging.LogUtils; import com.mojang.serialization.Codec; diff --git a/definition/src/main/java/org/sinytra/adapter/patch/transformer/ModifyMethodParams.java b/definition/src/main/java/org/sinytra/adapter/patch/transformer/operation/ModifyMethodParams.java similarity index 96% rename from definition/src/main/java/org/sinytra/adapter/patch/transformer/ModifyMethodParams.java rename to definition/src/main/java/org/sinytra/adapter/patch/transformer/operation/ModifyMethodParams.java index ad99ee6..4d98e07 100644 --- a/definition/src/main/java/org/sinytra/adapter/patch/transformer/ModifyMethodParams.java +++ b/definition/src/main/java/org/sinytra/adapter/patch/transformer/operation/ModifyMethodParams.java @@ -1,4 +1,4 @@ -package org.sinytra.adapter.patch.transformer; +package org.sinytra.adapter.patch.transformer.operation; import com.mojang.datafixers.util.Pair; import com.mojang.logging.LogUtils; @@ -15,10 +15,12 @@ import org.sinytra.adapter.patch.api.*; import org.sinytra.adapter.patch.fixes.BytecodeFixerUpper; import org.sinytra.adapter.patch.fixes.TypeAdapter; -import org.sinytra.adapter.patch.selector.AnnotationHandle; -import org.sinytra.adapter.patch.transformer.param.InjectParameterTransform; -import org.sinytra.adapter.patch.transformer.param.ParamTransformTarget; -import org.sinytra.adapter.patch.transformer.param.SwapParametersTransformer; +import org.sinytra.adapter.patch.analysis.selector.AnnotationHandle; +import org.sinytra.adapter.patch.analysis.LVTSnapshot; +import org.sinytra.adapter.patch.fixes.ModifyArgsOffsetTransformer; +import org.sinytra.adapter.patch.transformer.operation.param.InjectParameterTransform; +import org.sinytra.adapter.patch.transformer.operation.param.ParamTransformTarget; +import org.sinytra.adapter.patch.transformer.operation.param.SwapParametersTransformer; import org.sinytra.adapter.patch.util.AdapterUtil; import org.sinytra.adapter.patch.util.SingleValueHandle; import org.slf4j.Logger; @@ -27,10 +29,11 @@ import java.util.function.Consumer; import static org.sinytra.adapter.patch.PatchInstance.MIXINPATCH; -import static org.sinytra.adapter.patch.transformer.param.ParamTransformationUtil.calculateLVTIndex; -import static org.sinytra.adapter.patch.transformer.param.ParamTransformationUtil.findWrapOperationOriginalCall; +import static org.sinytra.adapter.patch.transformer.operation.param.ParamTransformationUtil.calculateLVTIndex; +import static org.sinytra.adapter.patch.transformer.operation.param.ParamTransformationUtil.findWrapOperationOriginalCall; // TODO Refactor +@Deprecated public record ModifyMethodParams(SimpleParamsDiffSnapshot context, ParamTransformTarget targetType, boolean ignoreOffset, @Nullable LVTFixer lvtFixer) implements MethodTransform { public static final Codec CODEC = RecordCodecBuilder.create(instance -> instance.group( SimpleParamsDiffSnapshot.CODEC.fieldOf("context").forGetter(ModifyMethodParams::context), diff --git a/definition/src/main/java/org/sinytra/adapter/patch/transformer/ModifyMixinType.java b/definition/src/main/java/org/sinytra/adapter/patch/transformer/operation/ModifyMixinType.java similarity index 93% rename from definition/src/main/java/org/sinytra/adapter/patch/transformer/ModifyMixinType.java rename to definition/src/main/java/org/sinytra/adapter/patch/transformer/operation/ModifyMixinType.java index 35a50bc..54e4f9b 100644 --- a/definition/src/main/java/org/sinytra/adapter/patch/transformer/ModifyMixinType.java +++ b/definition/src/main/java/org/sinytra/adapter/patch/transformer/operation/ModifyMixinType.java @@ -1,12 +1,12 @@ -package org.sinytra.adapter.patch.transformer; +package org.sinytra.adapter.patch.transformer.operation; import org.objectweb.asm.AnnotationVisitor; import org.objectweb.asm.tree.AnnotationNode; import org.objectweb.asm.tree.ClassNode; import org.objectweb.asm.tree.MethodNode; import org.sinytra.adapter.patch.api.*; -import org.sinytra.adapter.patch.selector.AnnotationHandle; -import org.sinytra.adapter.patch.selector.AnnotationValueHandle; +import org.sinytra.adapter.patch.analysis.selector.AnnotationHandle; +import org.sinytra.adapter.patch.analysis.selector.AnnotationValueHandle; import java.util.List; import java.util.Map; diff --git a/definition/src/main/java/org/sinytra/adapter/patch/transformer/ModifyTargetClasses.java b/definition/src/main/java/org/sinytra/adapter/patch/transformer/operation/ModifyTargetClasses.java similarity index 89% rename from definition/src/main/java/org/sinytra/adapter/patch/transformer/ModifyTargetClasses.java rename to definition/src/main/java/org/sinytra/adapter/patch/transformer/operation/ModifyTargetClasses.java index aef820a..7a9625d 100644 --- a/definition/src/main/java/org/sinytra/adapter/patch/transformer/ModifyTargetClasses.java +++ b/definition/src/main/java/org/sinytra/adapter/patch/transformer/operation/ModifyTargetClasses.java @@ -1,4 +1,4 @@ -package org.sinytra.adapter.patch.transformer; +package org.sinytra.adapter.patch.transformer.operation; import org.objectweb.asm.Type; import org.objectweb.asm.tree.ClassNode; @@ -7,7 +7,7 @@ import org.sinytra.adapter.patch.api.MethodTransform; import org.sinytra.adapter.patch.api.Patch; import org.sinytra.adapter.patch.api.PatchContext; -import org.sinytra.adapter.patch.selector.AnnotationValueHandle; +import org.sinytra.adapter.patch.analysis.selector.AnnotationValueHandle; import java.util.ArrayList; import java.util.List; diff --git a/definition/src/main/java/org/sinytra/adapter/patch/transformer/param/InjectParameterTransform.java b/definition/src/main/java/org/sinytra/adapter/patch/transformer/operation/param/InjectParameterTransform.java similarity index 90% rename from definition/src/main/java/org/sinytra/adapter/patch/transformer/param/InjectParameterTransform.java rename to definition/src/main/java/org/sinytra/adapter/patch/transformer/operation/param/InjectParameterTransform.java index ca98874..8e40438 100644 --- a/definition/src/main/java/org/sinytra/adapter/patch/transformer/param/InjectParameterTransform.java +++ b/definition/src/main/java/org/sinytra/adapter/patch/transformer/operation/param/InjectParameterTransform.java @@ -1,4 +1,4 @@ -package org.sinytra.adapter.patch.transformer.param; +package org.sinytra.adapter.patch.transformer.operation.param; import com.mojang.datafixers.util.Pair; import com.mojang.serialization.Codec; @@ -11,17 +11,17 @@ import org.sinytra.adapter.patch.api.MixinConstants; import org.sinytra.adapter.patch.api.Patch; import org.sinytra.adapter.patch.api.PatchContext; -import org.sinytra.adapter.patch.selector.AnnotationHandle; -import org.sinytra.adapter.patch.transformer.LVTSnapshot; -import org.sinytra.adapter.patch.transformer.ModifyArgsOffsetTransformer; +import org.sinytra.adapter.patch.analysis.selector.AnnotationHandle; +import org.sinytra.adapter.patch.analysis.LVTSnapshot; +import org.sinytra.adapter.patch.fixes.ModifyArgsOffsetTransformer; import org.sinytra.adapter.patch.util.AdapterUtil; import java.util.ArrayList; import java.util.Arrays; import java.util.List; -import static org.sinytra.adapter.patch.transformer.param.ParamTransformationUtil.calculateLVTIndex; -import static org.sinytra.adapter.patch.transformer.param.ParamTransformationUtil.extractWrapOperation; +import static org.sinytra.adapter.patch.transformer.operation.param.ParamTransformationUtil.calculateLVTIndex; +import static org.sinytra.adapter.patch.transformer.operation.param.ParamTransformationUtil.extractWrapOperation; public record InjectParameterTransform(int index, Type type, boolean upgradeWrapOperation) implements ParameterTransformer { static final Codec CODEC = RecordCodecBuilder.create(in -> in.group( diff --git a/definition/src/main/java/org/sinytra/adapter/patch/transformer/param/InlineParameterTransformer.java b/definition/src/main/java/org/sinytra/adapter/patch/transformer/operation/param/InlineParameterTransformer.java similarity index 94% rename from definition/src/main/java/org/sinytra/adapter/patch/transformer/param/InlineParameterTransformer.java rename to definition/src/main/java/org/sinytra/adapter/patch/transformer/operation/param/InlineParameterTransformer.java index cd27341..852c235 100644 --- a/definition/src/main/java/org/sinytra/adapter/patch/transformer/param/InlineParameterTransformer.java +++ b/definition/src/main/java/org/sinytra/adapter/patch/transformer/operation/param/InlineParameterTransformer.java @@ -1,4 +1,4 @@ -package org.sinytra.adapter.patch.transformer.param; +package org.sinytra.adapter.patch.transformer.operation.param; import com.mojang.logging.LogUtils; import org.objectweb.asm.Type; @@ -7,7 +7,7 @@ import org.sinytra.adapter.patch.api.MethodContext; import org.sinytra.adapter.patch.api.Patch; import org.sinytra.adapter.patch.api.PatchContext; -import org.sinytra.adapter.patch.transformer.LVTSnapshot; +import org.sinytra.adapter.patch.analysis.LVTSnapshot; import org.sinytra.adapter.patch.util.AdapterUtil; import org.slf4j.Logger; diff --git a/definition/src/main/java/org/sinytra/adapter/patch/transformer/param/MoveParametersTransformer.java b/definition/src/main/java/org/sinytra/adapter/patch/transformer/operation/param/MoveParametersTransformer.java similarity index 95% rename from definition/src/main/java/org/sinytra/adapter/patch/transformer/param/MoveParametersTransformer.java rename to definition/src/main/java/org/sinytra/adapter/patch/transformer/operation/param/MoveParametersTransformer.java index f0818db..38aaf81 100644 --- a/definition/src/main/java/org/sinytra/adapter/patch/transformer/param/MoveParametersTransformer.java +++ b/definition/src/main/java/org/sinytra/adapter/patch/transformer/operation/param/MoveParametersTransformer.java @@ -1,4 +1,4 @@ -package org.sinytra.adapter.patch.transformer.param; +package org.sinytra.adapter.patch.transformer.operation.param; import com.mojang.logging.LogUtils; import com.mojang.serialization.Codec; @@ -12,7 +12,7 @@ import org.sinytra.adapter.patch.api.MethodContext; import org.sinytra.adapter.patch.api.Patch; import org.sinytra.adapter.patch.api.PatchContext; -import org.sinytra.adapter.patch.transformer.LVTSnapshot; +import org.sinytra.adapter.patch.analysis.LVTSnapshot; import org.sinytra.adapter.patch.util.AdapterUtil; import org.slf4j.Logger; diff --git a/definition/src/main/java/org/sinytra/adapter/patch/transformer/param/ParamTransformTarget.java b/definition/src/main/java/org/sinytra/adapter/patch/transformer/operation/param/ParamTransformTarget.java similarity index 90% rename from definition/src/main/java/org/sinytra/adapter/patch/transformer/param/ParamTransformTarget.java rename to definition/src/main/java/org/sinytra/adapter/patch/transformer/operation/param/ParamTransformTarget.java index 5d9160f..8b2cc25 100644 --- a/definition/src/main/java/org/sinytra/adapter/patch/transformer/param/ParamTransformTarget.java +++ b/definition/src/main/java/org/sinytra/adapter/patch/transformer/operation/param/ParamTransformTarget.java @@ -1,8 +1,8 @@ -package org.sinytra.adapter.patch.transformer.param; +package org.sinytra.adapter.patch.transformer.operation.param; import com.mojang.serialization.Codec; import org.sinytra.adapter.patch.api.MixinConstants; -import org.sinytra.adapter.patch.selector.AnnotationHandle; +import org.sinytra.adapter.patch.analysis.selector.AnnotationHandle; import java.util.Arrays; import java.util.HashSet; diff --git a/definition/src/main/java/org/sinytra/adapter/patch/transformer/param/ParamTransformationUtil.java b/definition/src/main/java/org/sinytra/adapter/patch/transformer/operation/param/ParamTransformationUtil.java similarity index 98% rename from definition/src/main/java/org/sinytra/adapter/patch/transformer/param/ParamTransformationUtil.java rename to definition/src/main/java/org/sinytra/adapter/patch/transformer/operation/param/ParamTransformationUtil.java index 54465b3..c922fe2 100644 --- a/definition/src/main/java/org/sinytra/adapter/patch/transformer/param/ParamTransformationUtil.java +++ b/definition/src/main/java/org/sinytra/adapter/patch/transformer/operation/param/ParamTransformationUtil.java @@ -1,4 +1,4 @@ -package org.sinytra.adapter.patch.transformer.param; +package org.sinytra.adapter.patch.transformer.operation.param; import it.unimi.dsi.fastutil.ints.IntArrayList; import it.unimi.dsi.fastutil.ints.IntList; @@ -8,7 +8,7 @@ import org.sinytra.adapter.patch.analysis.MethodCallAnalyzer; import org.sinytra.adapter.patch.api.MethodContext; import org.sinytra.adapter.patch.api.MixinConstants; -import org.sinytra.adapter.patch.selector.AnnotationHandle; +import org.sinytra.adapter.patch.analysis.selector.AnnotationHandle; import org.sinytra.adapter.patch.util.AdapterUtil; import org.sinytra.adapter.patch.util.MethodQualifier; diff --git a/definition/src/main/java/org/sinytra/adapter/patch/transformer/param/ParameterTransformer.java b/definition/src/main/java/org/sinytra/adapter/patch/transformer/operation/param/ParameterTransformer.java similarity index 91% rename from definition/src/main/java/org/sinytra/adapter/patch/transformer/param/ParameterTransformer.java rename to definition/src/main/java/org/sinytra/adapter/patch/transformer/operation/param/ParameterTransformer.java index 9f03180..d6aa880 100644 --- a/definition/src/main/java/org/sinytra/adapter/patch/transformer/param/ParameterTransformer.java +++ b/definition/src/main/java/org/sinytra/adapter/patch/transformer/operation/param/ParameterTransformer.java @@ -1,4 +1,4 @@ -package org.sinytra.adapter.patch.transformer.param; +package org.sinytra.adapter.patch.transformer.operation.param; import com.mojang.serialization.Codec; import org.objectweb.asm.Type; diff --git a/definition/src/main/java/org/sinytra/adapter/patch/transformer/param/RemoveParameterTransformer.java b/definition/src/main/java/org/sinytra/adapter/patch/transformer/operation/param/RemoveParameterTransformer.java similarity index 90% rename from definition/src/main/java/org/sinytra/adapter/patch/transformer/param/RemoveParameterTransformer.java rename to definition/src/main/java/org/sinytra/adapter/patch/transformer/operation/param/RemoveParameterTransformer.java index 52a33ea..3ecf40d 100644 --- a/definition/src/main/java/org/sinytra/adapter/patch/transformer/param/RemoveParameterTransformer.java +++ b/definition/src/main/java/org/sinytra/adapter/patch/transformer/operation/param/RemoveParameterTransformer.java @@ -1,20 +1,19 @@ -package org.sinytra.adapter.patch.transformer.param; +package org.sinytra.adapter.patch.transformer.operation.param; import com.mojang.serialization.Codec; import org.objectweb.asm.Type; -import org.objectweb.asm.tree.AnnotationNode; import org.objectweb.asm.tree.ClassNode; import org.objectweb.asm.tree.LocalVariableNode; import org.objectweb.asm.tree.MethodNode; import org.sinytra.adapter.patch.api.MethodContext; import org.sinytra.adapter.patch.api.Patch; import org.sinytra.adapter.patch.api.PatchContext; -import org.sinytra.adapter.patch.transformer.LVTSnapshot; +import org.sinytra.adapter.patch.analysis.LVTSnapshot; import org.sinytra.adapter.patch.util.AdapterUtil; import java.util.List; -import static org.sinytra.adapter.patch.transformer.param.ParamTransformationUtil.extractWrapOperation; +import static org.sinytra.adapter.patch.transformer.operation.param.ParamTransformationUtil.extractWrapOperation; public record RemoveParameterTransformer(int index, boolean upgradeWrapOperation) implements ParameterTransformer { public static final Codec CODEC = Codec.intRange(0, 255) diff --git a/definition/src/main/java/org/sinytra/adapter/patch/transformer/param/ReplaceParametersTransformer.java b/definition/src/main/java/org/sinytra/adapter/patch/transformer/operation/param/ReplaceParametersTransformer.java similarity index 96% rename from definition/src/main/java/org/sinytra/adapter/patch/transformer/param/ReplaceParametersTransformer.java rename to definition/src/main/java/org/sinytra/adapter/patch/transformer/operation/param/ReplaceParametersTransformer.java index 980cbc6..9e9e027 100644 --- a/definition/src/main/java/org/sinytra/adapter/patch/transformer/param/ReplaceParametersTransformer.java +++ b/definition/src/main/java/org/sinytra/adapter/patch/transformer/operation/param/ReplaceParametersTransformer.java @@ -1,4 +1,4 @@ -package org.sinytra.adapter.patch.transformer.param; +package org.sinytra.adapter.patch.transformer.operation.param; import com.mojang.logging.LogUtils; import com.mojang.serialization.Codec; @@ -18,7 +18,7 @@ import java.util.List; import static org.sinytra.adapter.patch.PatchInstance.MIXINPATCH; -import static org.sinytra.adapter.patch.transformer.param.ParamTransformationUtil.findWrapOperationOriginalCall; +import static org.sinytra.adapter.patch.transformer.operation.param.ParamTransformationUtil.findWrapOperationOriginalCall; public record ReplaceParametersTransformer(int index, Type type, boolean upgradeUsage) implements ParameterTransformer { static final Codec CODEC = RecordCodecBuilder.create(in -> in.group( diff --git a/definition/src/main/java/org/sinytra/adapter/patch/transformer/param/SubstituteParameterTransformer.java b/definition/src/main/java/org/sinytra/adapter/patch/transformer/operation/param/SubstituteParameterTransformer.java similarity index 91% rename from definition/src/main/java/org/sinytra/adapter/patch/transformer/param/SubstituteParameterTransformer.java rename to definition/src/main/java/org/sinytra/adapter/patch/transformer/operation/param/SubstituteParameterTransformer.java index a465c53..bd7efcf 100644 --- a/definition/src/main/java/org/sinytra/adapter/patch/transformer/param/SubstituteParameterTransformer.java +++ b/definition/src/main/java/org/sinytra/adapter/patch/transformer/operation/param/SubstituteParameterTransformer.java @@ -1,4 +1,4 @@ -package org.sinytra.adapter.patch.transformer.param; +package org.sinytra.adapter.patch.transformer.operation.param; import com.mojang.logging.LogUtils; import com.mojang.serialization.Codec; @@ -9,13 +9,13 @@ import org.sinytra.adapter.patch.api.MethodContext; import org.sinytra.adapter.patch.api.Patch; import org.sinytra.adapter.patch.api.PatchContext; -import org.sinytra.adapter.patch.transformer.LVTSnapshot; +import org.sinytra.adapter.patch.analysis.LVTSnapshot; import org.sinytra.adapter.patch.util.AdapterUtil; import org.slf4j.Logger; import java.util.List; -import static org.sinytra.adapter.patch.transformer.param.ParamTransformationUtil.calculateLVTIndex; +import static org.sinytra.adapter.patch.transformer.operation.param.ParamTransformationUtil.calculateLVTIndex; public record SubstituteParameterTransformer(int target, int substitute) implements ParameterTransformer { static final Codec CODEC = RecordCodecBuilder.create(in -> in.group( diff --git a/definition/src/main/java/org/sinytra/adapter/patch/transformer/param/SwapParametersTransformer.java b/definition/src/main/java/org/sinytra/adapter/patch/transformer/operation/param/SwapParametersTransformer.java similarity index 98% rename from definition/src/main/java/org/sinytra/adapter/patch/transformer/param/SwapParametersTransformer.java rename to definition/src/main/java/org/sinytra/adapter/patch/transformer/operation/param/SwapParametersTransformer.java index 607f75e..adc1f55 100644 --- a/definition/src/main/java/org/sinytra/adapter/patch/transformer/param/SwapParametersTransformer.java +++ b/definition/src/main/java/org/sinytra/adapter/patch/transformer/operation/param/SwapParametersTransformer.java @@ -1,4 +1,4 @@ -package org.sinytra.adapter.patch.transformer.param; +package org.sinytra.adapter.patch.transformer.operation.param; import com.mojang.logging.LogUtils; import com.mojang.serialization.Codec; diff --git a/definition/src/main/java/org/sinytra/adapter/patch/transformer/param/TransformParameters.java b/definition/src/main/java/org/sinytra/adapter/patch/transformer/operation/param/TransformParameters.java similarity index 97% rename from definition/src/main/java/org/sinytra/adapter/patch/transformer/param/TransformParameters.java rename to definition/src/main/java/org/sinytra/adapter/patch/transformer/operation/param/TransformParameters.java index ec34ee0..348ef8f 100644 --- a/definition/src/main/java/org/sinytra/adapter/patch/transformer/param/TransformParameters.java +++ b/definition/src/main/java/org/sinytra/adapter/patch/transformer/operation/param/TransformParameters.java @@ -1,4 +1,4 @@ -package org.sinytra.adapter.patch.transformer.param; +package org.sinytra.adapter.patch.transformer.operation.param; import com.google.common.collect.BiMap; import com.google.common.collect.ImmutableBiMap; @@ -13,7 +13,7 @@ import org.objectweb.asm.tree.ClassNode; import org.objectweb.asm.tree.MethodNode; import org.sinytra.adapter.patch.api.*; -import org.sinytra.adapter.patch.selector.AnnotationHandle; +import org.sinytra.adapter.patch.analysis.selector.AnnotationHandle; import java.util.*; import java.util.function.Consumer; diff --git a/definition/src/main/java/org/sinytra/adapter/patch/transformer/pipeline/InjectionPointTransformerFilter.java b/definition/src/main/java/org/sinytra/adapter/patch/transformer/pipeline/InjectionPointTransformerFilter.java new file mode 100644 index 0000000..68ce885 --- /dev/null +++ b/definition/src/main/java/org/sinytra/adapter/patch/transformer/pipeline/InjectionPointTransformerFilter.java @@ -0,0 +1,34 @@ +package org.sinytra.adapter.patch.transformer.pipeline; + +import com.mojang.serialization.Codec; +import com.mojang.serialization.codecs.RecordCodecBuilder; +import org.sinytra.adapter.patch.api.MethodContext; +import org.sinytra.adapter.patch.api.MethodTransformFilter; +import org.sinytra.adapter.patch.analysis.selector.AnnotationValueHandle; +import org.sinytra.adapter.patch.analysis.selector.InjectionPointMatcher; + +import java.util.List; + +public record InjectionPointTransformerFilter(List excludedInjectionPoints) implements MethodTransformFilter { + public static final Codec CODEC = RecordCodecBuilder.create(instance -> instance.group( + InjectionPointMatcher.CODEC.listOf().fieldOf("excludedInjectionPoints").forGetter(InjectionPointTransformerFilter::excludedInjectionPoints) + ).apply(instance, InjectionPointTransformerFilter::new)); + + public static InjectionPointTransformerFilter create(List excludedInjectionPoints) { + return new InjectionPointTransformerFilter(excludedInjectionPoints.stream().map(str -> new InjectionPointMatcher((String) null, str)).toList()); + } + + @Override + public Codec codec() { + return CODEC; + } + + @Override + public boolean test(MethodContext methodContext) { + String injectionPoint = methodContext.injectionPointAnnotation().getValue("target") + .map(AnnotationValueHandle::get) + .map(methodContext.patchContext()::remap) + .orElse(null); + return injectionPoint == null || this.excludedInjectionPoints.stream().noneMatch(matcher -> matcher.test(null, injectionPoint)); + } +} diff --git a/definition/src/main/java/org/sinytra/adapter/patch/transformer/pipeline/MethodTransformationPipeline.java b/definition/src/main/java/org/sinytra/adapter/patch/transformer/pipeline/MethodTransformationPipeline.java new file mode 100644 index 0000000..67c3228 --- /dev/null +++ b/definition/src/main/java/org/sinytra/adapter/patch/transformer/pipeline/MethodTransformationPipeline.java @@ -0,0 +1,115 @@ +package org.sinytra.adapter.patch.transformer.pipeline; + +import com.mojang.serialization.Codec; +import com.mojang.serialization.codecs.RecordCodecBuilder; +import org.objectweb.asm.tree.ClassNode; +import org.objectweb.asm.tree.MethodNode; +import org.sinytra.adapter.patch.api.*; +import org.sinytra.adapter.patch.transformer.serialization.MethodTransformFilterSerialization; +import org.sinytra.adapter.patch.transformer.serialization.MethodTransformSerialization; +import org.sinytra.adapter.patch.transformer.BundledMethodTransform; + +import java.util.ArrayList; +import java.util.List; +import java.util.function.Consumer; +import java.util.function.Supplier; + +public class MethodTransformationPipeline implements MethodTransform { + public static final Codec CODEC = RecordCodecBuilder.create(instance -> instance.group( + MethodTransformSerialization.METHOD_TRANSFORM_CODEC.fieldOf("transform").forGetter(m -> m.transform), + MethodTransformFilterSerialization.METHOD_TRANSFORM_FILTER_CODEC.listOf().fieldOf("filters").forGetter(m -> m.filters) + ).apply(instance, MethodTransformationPipeline::new)); + + private final MethodTransform transform; + private final List> onSuccess; + private final List> onFail; + private final List filters; + + private MethodTransformationPipeline(MethodTransform transform, List filters) { + this(transform, List.of(), List.of(), filters); + } + + private MethodTransformationPipeline(MethodTransform transform, List> onSuccess, List> onFail, List filters) { + this.transform = transform; + this.onSuccess = onSuccess; + this.onFail = onFail; + this.filters = filters; + } + + @Override + public Patch.Result apply(ClassNode classNode, MethodNode methodNode, MethodContext methodContext, PatchContext context) { + for (MethodTransformFilter filter : filters) { + if (!filter.test(methodContext)) { + return Patch.Result.PASS; + } + } + Patch.Result result = this.transform.apply(methodContext); + for (Supplier supplier : result == Patch.Result.PASS ? this.onFail : this.onSuccess) { + result = result.or(supplier.get().apply(methodContext)); + } + return result; + } + + public static Builder builder(MethodTransform transform) { + return new Builder(transform); + } + + public static Builder builder(Consumer> consumer) { + BundledMethodTransform.Builder builder = BundledMethodTransform.builder(); + consumer.accept(builder); + return new Builder(builder.build()); + } + + public static class Builder { + private final MethodTransform transform; + private final List> onSuccess = new ArrayList<>(); + private final List> onFail = new ArrayList<>(); + private final List filters = new ArrayList<>(); + + private Builder(MethodTransform transform) { + this.transform = transform; + } + + public Builder onSuccess(Supplier onSuccess) { + this.onSuccess.add(onSuccess); + return this; + } + + public Builder onSuccess(Consumer> consumer) { + BundledMethodTransform.Builder builder = BundledMethodTransform.builder(); + consumer.accept(builder); + this.onSuccess.add(builder::build); + return this; + } + + public Builder onFail(Supplier onFail) { + this.onFail.add(onFail); + return this; + } + + public Builder onFail(Consumer> consumer) { + BundledMethodTransform.Builder builder = BundledMethodTransform.builder(); + consumer.accept(builder); + this.onFail.add(builder::build); + return this; + } + + public Builder filter(MethodTransformFilter filter) { + this.filters.add(filter); + return this; + } + + public Builder filter(List filter) { + this.filters.addAll(filter); + return this; + } + + public MethodTransformationPipeline build() { + return new MethodTransformationPipeline(this.transform, this.onSuccess, this.onFail, this.filters); + } + + public Patch.Result apply(MethodContext methodContext) { + return build().apply(methodContext); + } + } +} diff --git a/definition/src/main/java/org/sinytra/adapter/patch/transformer/serialization/MethodTransformFilterSerialization.java b/definition/src/main/java/org/sinytra/adapter/patch/transformer/serialization/MethodTransformFilterSerialization.java new file mode 100644 index 0000000..5a989f8 --- /dev/null +++ b/definition/src/main/java/org/sinytra/adapter/patch/transformer/serialization/MethodTransformFilterSerialization.java @@ -0,0 +1,29 @@ +package org.sinytra.adapter.patch.transformer.serialization; + +import com.google.common.collect.BiMap; +import com.google.common.collect.ImmutableBiMap; +import com.mojang.serialization.Codec; +import com.mojang.serialization.DataResult; +import org.sinytra.adapter.patch.api.MethodTransformFilter; +import org.sinytra.adapter.patch.transformer.pipeline.InjectionPointTransformerFilter; + +import java.util.Objects; + +public class MethodTransformFilterSerialization { + public static final Codec METHOD_TRANSFORM_FILTER_CODEC = + Codec.STRING.partialDispatch("type", transform -> DataResult.success(getTransformFilterName(transform)), name -> { + Codec entryCodec = MethodTransformFilterSerialization.FILTER_CODECS.get(name); + if (entryCodec != null) { + return DataResult.success(entryCodec.fieldOf("transform")); + } + return DataResult.error(() -> "Missing codec for transformer filter " + name); + }); + + private static final BiMap> FILTER_CODECS = ImmutableBiMap.>builder() + .put("injection_point", InjectionPointTransformerFilter.CODEC) + .build(); + + private static String getTransformFilterName(MethodTransformFilter transform) { + return Objects.requireNonNull(FILTER_CODECS.inverse().get(transform.codec()), "Missing name for transformer " + transform); + } +} diff --git a/definition/src/main/java/org/sinytra/adapter/patch/serialization/MethodTransformSerialization.java b/definition/src/main/java/org/sinytra/adapter/patch/transformer/serialization/MethodTransformSerialization.java similarity index 79% rename from definition/src/main/java/org/sinytra/adapter/patch/serialization/MethodTransformSerialization.java rename to definition/src/main/java/org/sinytra/adapter/patch/transformer/serialization/MethodTransformSerialization.java index ce17711..d391342 100644 --- a/definition/src/main/java/org/sinytra/adapter/patch/serialization/MethodTransformSerialization.java +++ b/definition/src/main/java/org/sinytra/adapter/patch/transformer/serialization/MethodTransformSerialization.java @@ -1,13 +1,14 @@ -package org.sinytra.adapter.patch.serialization; +package org.sinytra.adapter.patch.transformer.serialization; import com.google.common.collect.BiMap; import com.google.common.collect.ImmutableBiMap; import com.mojang.serialization.Codec; import com.mojang.serialization.DataResult; import org.sinytra.adapter.patch.api.MethodTransform; -import org.sinytra.adapter.patch.transformer.*; -import org.sinytra.adapter.patch.transformer.filter.InjectionPointTransformerFilter; -import org.sinytra.adapter.patch.transformer.param.TransformParameters; +import org.sinytra.adapter.patch.transformer.SoftMethodParamsPatch; +import org.sinytra.adapter.patch.transformer.operation.*; +import org.sinytra.adapter.patch.transformer.operation.param.TransformParameters; +import org.sinytra.adapter.patch.transformer.pipeline.MethodTransformationPipeline; import java.util.Objects; @@ -23,14 +24,13 @@ public class MethodTransformSerialization { private static final BiMap> TRANSFORMER_CODECS = ImmutableBiMap.>builder() .put("disable_mixin", DisableMixin.CODEC) - .put("change_modified_variable", ChangeModifiedVariableIndex.CODEC) .put("modify_injection_point", ModifyInjectionPoint.CODEC) .put("modify_injection_target", ModifyInjectionTarget.CODEC) .put("modfiy_access", ModifyMethodAccess.CODEC) .put("modify_method", ModifyMethodParams.CODEC) .put("transform_parameters", TransformParameters.CODEC) .put("soft_modify_method", SoftMethodParamsPatch.CODEC) - .put("injection_point_filter", InjectionPointTransformerFilter.CODEC) + .put("pipeline_transform", MethodTransformationPipeline.CODEC) .build(); private static String getTransformName(MethodTransform transform) { diff --git a/definition/src/main/java/org/sinytra/adapter/patch/serialization/PatchSerialization.java b/definition/src/main/java/org/sinytra/adapter/patch/transformer/serialization/PatchSerialization.java similarity index 97% rename from definition/src/main/java/org/sinytra/adapter/patch/serialization/PatchSerialization.java rename to definition/src/main/java/org/sinytra/adapter/patch/transformer/serialization/PatchSerialization.java index b78f92d..151e58f 100644 --- a/definition/src/main/java/org/sinytra/adapter/patch/serialization/PatchSerialization.java +++ b/definition/src/main/java/org/sinytra/adapter/patch/transformer/serialization/PatchSerialization.java @@ -1,4 +1,4 @@ -package org.sinytra.adapter.patch.serialization; +package org.sinytra.adapter.patch.transformer.serialization; import com.google.common.collect.BiMap; import com.google.common.collect.ImmutableBiMap; diff --git a/definition/src/main/java/org/sinytra/adapter/patch/util/AdapterUtil.java b/definition/src/main/java/org/sinytra/adapter/patch/util/AdapterUtil.java index 7f035f8..ce9f2ef 100644 --- a/definition/src/main/java/org/sinytra/adapter/patch/util/AdapterUtil.java +++ b/definition/src/main/java/org/sinytra/adapter/patch/util/AdapterUtil.java @@ -15,8 +15,8 @@ import org.sinytra.adapter.patch.api.MethodContext; import org.sinytra.adapter.patch.api.MixinConstants; import org.sinytra.adapter.patch.api.PatchEnvironment; -import org.sinytra.adapter.patch.selector.AnnotationHandle; -import org.sinytra.adapter.patch.selector.AnnotationValueHandle; +import org.sinytra.adapter.patch.analysis.selector.AnnotationHandle; +import org.sinytra.adapter.patch.analysis.selector.AnnotationValueHandle; import org.slf4j.Logger; import org.spongepowered.asm.mixin.gen.AccessorInfo; diff --git a/definition/src/main/java/org/sinytra/adapter/patch/util/MethodQualifier.java b/definition/src/main/java/org/sinytra/adapter/patch/util/MethodQualifier.java index 53fb03e..c7a8988 100644 --- a/definition/src/main/java/org/sinytra/adapter/patch/util/MethodQualifier.java +++ b/definition/src/main/java/org/sinytra/adapter/patch/util/MethodQualifier.java @@ -20,6 +20,7 @@ public record MethodQualifier(@Nullable String owner, @Nullable String name, @Nu public MethodQualifier(@Nullable String name, @Nullable String desc) { this(null, name, desc); } + @Nullable public static Optional create(String qualifier) { Matcher matcher = METHOD_QUALIFIER_PATTERN.matcher(qualifier); diff --git a/definition/src/main/java/org/sinytra/adapter/patch/util/MethodTransformBuilderImpl.java b/definition/src/main/java/org/sinytra/adapter/patch/util/MethodTransformBuilderImpl.java index 3358c7a..41bb611 100644 --- a/definition/src/main/java/org/sinytra/adapter/patch/util/MethodTransformBuilderImpl.java +++ b/definition/src/main/java/org/sinytra/adapter/patch/util/MethodTransformBuilderImpl.java @@ -3,7 +3,8 @@ import org.sinytra.adapter.patch.api.MethodTransform; import org.sinytra.adapter.patch.api.MethodTransformBuilder; import org.sinytra.adapter.patch.transformer.*; -import org.sinytra.adapter.patch.transformer.param.TransformParameters; +import org.sinytra.adapter.patch.transformer.operation.*; +import org.sinytra.adapter.patch.transformer.operation.param.TransformParameters; import java.util.ArrayList; import java.util.List; @@ -36,11 +37,6 @@ public T modifyTarget(ModifyInjectionTarget.Action action, String... methods) { return transform(new ModifyInjectionTarget(List.of(methods), action)); } - @Override - public T modifyVariableIndex(int start, int offset) { - return transform(new ChangeModifiedVariableIndex(start, offset)); - } - @Override public T modifyMethodAccess(ModifyMethodAccess.AccessChange... changes) { return transform(new ModifyMethodAccess(List.of(changes))); @@ -48,15 +44,10 @@ public T modifyMethodAccess(ModifyMethodAccess.AccessChange... changes) { @Override public T extractMixin(String targetClass) { - return transform(ModifyVarUpgradeToModifyExprVal.INSTANCE) + return improveModifyVar() .transform(new ExtractMixin(targetClass)); } - @Override - public T splitMixin(String targetClass) { - return transform(new SplitMixinTransform(targetClass)); - } - @Override public T improveModifyVar() { return transform(ModifyVarUpgradeToModifyExprVal.INSTANCE); diff --git a/definition/src/main/java/org/sinytra/adapter/patch/util/OpcodeUtil.java b/definition/src/main/java/org/sinytra/adapter/patch/util/OpcodeUtil.java index 896bd38..e36f7df 100644 --- a/definition/src/main/java/org/sinytra/adapter/patch/util/OpcodeUtil.java +++ b/definition/src/main/java/org/sinytra/adapter/patch/util/OpcodeUtil.java @@ -1,6 +1,5 @@ package org.sinytra.adapter.patch.util; -import org.objectweb.asm.MethodVisitor; import org.objectweb.asm.Opcodes; import org.objectweb.asm.Type; import org.objectweb.asm.tree.MethodNode; @@ -22,8 +21,7 @@ Type.FLOAT_TYPE, new BoxedType(float.class, Float.class), Type.DOUBLE_TYPE, new BoxedType(double.class, Double.class) ); - public record BoxedType(Class primitiveClass, Class boxedClass) { - } + public record BoxedType(Class primitiveClass, Class boxedClass) {} public static boolean isStoreOpcode(int opcode) { return opcode >= Opcodes.ISTORE && opcode <= Opcodes.ASTORE; @@ -53,17 +51,6 @@ public static int getReturnOpcode(int sort) { return Opcodes.IRETURN + INSN_TYPE_OFFSETS_EXTENDED.indexOf(sort) + 1; } - public static void castObjectType(Type to, MethodVisitor visitor) { - BoxedType boxed = BOXED_TYPES.get(to); - if (boxed != null) { - String boxedName = boxed.boxedClass().getName().replace('.', '/'); - String conversionMethod = boxed.primitiveClass().getName() + "Value"; - String conversionDesc = Type.getMethodDescriptor(to); - visitor.visitTypeInsn(Opcodes.CHECKCAST, boxedName); - visitor.visitMethodInsn(Opcodes.INVOKEVIRTUAL, boxedName, conversionMethod, conversionDesc, false); - } - } - public static int getAccessVisibility(int access) { return access & 0x7; } diff --git a/definition/src/test/java/org/sinytra/adapter/patch/test/mixin/MixinPatchTest.java b/definition/src/test/java/org/sinytra/adapter/patch/test/mixin/MixinPatchTest.java deleted file mode 100644 index 34a398d..0000000 --- a/definition/src/test/java/org/sinytra/adapter/patch/test/mixin/MixinPatchTest.java +++ /dev/null @@ -1,133 +0,0 @@ -package org.sinytra.adapter.patch.test.mixin; - -import org.sinytra.adapter.patch.api.Patch; -import org.sinytra.adapter.patch.api.PatchEnvironment; -import org.sinytra.adapter.patch.api.RefmapHolder; -import org.assertj.core.api.Assertions; -import org.objectweb.asm.ClassReader; -import org.objectweb.asm.tree.*; -import org.spongepowered.asm.mixin.FabricUtil; - -import java.io.IOException; -import java.io.InputStream; -import java.lang.reflect.Field; -import java.util.Comparator; -import java.util.List; -import java.util.Optional; -import java.util.function.Predicate; -import java.util.stream.Collectors; -import java.util.stream.StreamSupport; - -public abstract class MixinPatchTest { - protected LoadResult load(String className, Patch patch) throws Exception { - final ClassNode patched = load(className); - final PatchEnvironment env = PatchEnvironment.create( - new RefmapHolder() { - @Override - public String remap(String cls, String reference) { - return reference; - } - - @Override - public void copyEntries(String from, String to) { - - } - }, - name -> { - try { - final ClassNode node = new ClassNode(); - new ClassReader(name).accept(node, 0); - return Optional.of(node); - } catch (Exception exception) { - return Optional.empty(); - } - }, - null, - FabricUtil.COMPATIBILITY_LATEST - ); - patch.apply(patched, env); - return new LoadResult(patched, load(className)); - } - - protected void assertSameCode( - String className, - String testName, - Patch.ClassPatchBuilder patch - ) throws Exception { - final LoadResult result = load(className, patch.build()); - final MethodNode patched = result.patched.methods - .stream().filter(m -> m.name.equals(testName)) - .findFirst().orElseThrow(); - final MethodNode expected = result.expected.methods - .stream().filter(m -> m.name.equals(testName + "Expected")) - .findFirst().orElseThrow(); - - Assertions.assertThat(patched.parameters) - .as("Parameters") - .usingElementComparator(Comparator.comparing(p -> p.name)) - .withRepresentation(object -> ((List) object) - .stream().map(par -> par.name) - .collect(Collectors.joining("\n"))) - .isEqualTo(expected.parameters); - - final Predicate dontTest = i -> i instanceof LineNumberNode; - Assertions.assertThat(patched.instructions.iterator()) - .toIterable() - .as("Instructions") - .filteredOn(dontTest.negate()) - .usingElementComparator(new InsnComparator()) - .isEqualTo(StreamSupport.stream(expected.instructions.spliterator(), false) - .filter(dontTest.negate()).toList()); - - Assertions.assertThat(patched.localVariables) - .as("LVT") - .usingElementComparator(Comparator.comparingInt(n -> n.index) - .thenComparing(n -> n.name) - .thenComparing(n -> n.desc)) - .withRepresentation(object -> { - if (object instanceof LocalVariableNode[] lvn) { - object = List.of(lvn); - } - return ((List) object).stream() - .map(n -> n.index + ": " + n.name + " (" + n.desc + ")") - .collect(Collectors.joining("\n")); - }) - .containsExactlyInAnyOrder(expected.localVariables.toArray(LocalVariableNode[]::new)); - } - - public static class InsnComparator implements Comparator { - @Override - public int compare(AbstractInsnNode o1, AbstractInsnNode o2) { - if (o1.getClass() != o2.getClass() || o1.getType() != o2.getType()) { - return -1; - } - - for (final Field field : o1.getClass().getDeclaredFields()) { - field.setAccessible(true); - if (!field.getType().isPrimitive() && field.getType() != String.class) { - continue; - } - try { - if (((Comparable) field.get(o1)).compareTo(field.get(o2)) != 0) { - return -1; - } - } catch (Exception exception) { - throw new RuntimeException(exception); - } - } - - return 0; - } - } - - public record LoadResult(ClassNode patched, ClassNode expected) { - } - - protected ClassNode load(String name) throws IOException { - final ClassNode n = new ClassNode(); - try (final InputStream is = MixinPatchTest.class.getResourceAsStream("/" + name + ".class")) { - new ClassReader(is).accept(n, 0); - } - return n; - } -} diff --git a/definition/src/test/java/org/sinytra/adapter/patch/test/mixin/ParameterInjectionTest.java b/definition/src/test/java/org/sinytra/adapter/patch/test/mixin/ParameterInjectionTest.java deleted file mode 100644 index 19dbffe..0000000 --- a/definition/src/test/java/org/sinytra/adapter/patch/test/mixin/ParameterInjectionTest.java +++ /dev/null @@ -1,46 +0,0 @@ -package org.sinytra.adapter.patch.test.mixin; - -import org.sinytra.adapter.patch.api.Patch; -import org.junit.jupiter.api.Test; -import org.objectweb.asm.Type; - -import java.util.concurrent.atomic.AtomicInteger; - -public class ParameterInjectionTest extends MixinPatchTest { - @Test - void testRedirectInjection() throws Exception { - assertSameCode( - "org/sinytra/adapter/test/mixins/ParameterInjectionMixin", - "testRedirectInjection", - Patch.builder() - .targetMethod("testRedirect") - .targetInjectionPoint("Ljava/lang/String;repeat()Ljava/lang/String;") - .modifyInjectionPoint("Ljava/lang/String;repeat(I)Ljava/lang/String;") - // This is with cursed auto offsets - .transformParams(builder -> builder.inject(0, Type.INT_TYPE) - .withOffset()) - ); - } - - @Test - void testBigParameterInjection() throws Exception { - assertSameCode( - "org/sinytra/adapter/test/mixins/ParameterInjectionMixin", - "testBigParameterInjection", - Patch.builder() - .targetMethod("testTargetBig") - .transformParams(builder -> builder.inject(1, Type.DOUBLE_TYPE)) - ); - } - - @Test - void testWrapOpInjection() throws Exception { - assertSameCode( - "org/sinytra/adapter/test/mixins/ParameterInjectionMixin", - "testWrapOperation", - Patch.builder() - .targetMethod("testTargetWrap") - .transformParams(builder -> builder.inject(2, Type.getType(AtomicInteger.class))) - ); - } -} diff --git a/definition/src/test/java/org/sinytra/adapter/patch/test/mixin/ParameterInlineTest.java b/definition/src/test/java/org/sinytra/adapter/patch/test/mixin/ParameterInlineTest.java deleted file mode 100644 index 9f78b49..0000000 --- a/definition/src/test/java/org/sinytra/adapter/patch/test/mixin/ParameterInlineTest.java +++ /dev/null @@ -1,33 +0,0 @@ -package org.sinytra.adapter.patch.test.mixin; - -import org.sinytra.adapter.patch.api.MixinConstants; -import org.sinytra.adapter.patch.api.Patch; -import org.junit.jupiter.api.Test; - -public class ParameterInlineTest extends MixinPatchTest { - @Test - void testSimpleInline() throws Exception { - assertSameCode( - "org/sinytra/adapter/test/mixins/ParameterInlineMixin", - "testSimpleInline", - Patch.builder() - .targetInjectionPoint("") - .targetMethod("simple") - .targetMixinType(MixinConstants.INJECT) - .transformParams(params -> params.inline(3, adapter -> adapter.visitLdcInsn("inlined"))) - ); - } - - @Test - void testBigInline() throws Exception { - assertSameCode( - "org/sinytra/adapter/test/mixins/ParameterInlineMixin", - "testBigInline", - Patch.builder() - .targetInjectionPoint("") - .targetMethod("big") - .targetMixinType(MixinConstants.INJECT) - .transformParams(params -> params.inline(2, adapter -> adapter.visitLdcInsn(43.0d))) - ); - } -} diff --git a/definition/src/test/java/org/sinytra/adapter/patch/test/mixin/ParameterRemoveTest.java b/definition/src/test/java/org/sinytra/adapter/patch/test/mixin/ParameterRemoveTest.java deleted file mode 100644 index bd6fa05..0000000 --- a/definition/src/test/java/org/sinytra/adapter/patch/test/mixin/ParameterRemoveTest.java +++ /dev/null @@ -1,31 +0,0 @@ -package org.sinytra.adapter.patch.test.mixin; - -import org.sinytra.adapter.patch.api.MixinConstants; -import org.sinytra.adapter.patch.api.Patch; -import org.junit.jupiter.api.Test; - -public class ParameterRemoveTest extends MixinPatchTest { - @Test - void testSimpleRemove() throws Exception { - assertSameCode( - "org/sinytra/adapter/test/mixins/ParameterRemoveMixin", - "testSimpleRemove", - Patch.builder() - .targetInjectionPoint("") - .targetMethod("testSimple") - .targetMixinType(MixinConstants.INJECT) - .transformParams(params -> params.remove(2)) - ); - } - - @Test - void testWrapOpRemove() throws Exception { - assertSameCode( - "org/sinytra/adapter/test/mixins/ParameterRemoveMixin", - "testWrapOpRemove", - Patch.builder() - .targetMethod("testWrapOp") - .transformParams(params -> params.remove(2)) - ); - } -} diff --git a/definition/src/test/java/org/sinytra/adapter/patch/test/mixin/ParameterSubstitutionTest.java b/definition/src/test/java/org/sinytra/adapter/patch/test/mixin/ParameterSubstitutionTest.java deleted file mode 100644 index 1d873c6..0000000 --- a/definition/src/test/java/org/sinytra/adapter/patch/test/mixin/ParameterSubstitutionTest.java +++ /dev/null @@ -1,47 +0,0 @@ -package org.sinytra.adapter.patch.test.mixin; - -import org.sinytra.adapter.patch.api.MixinConstants; -import org.sinytra.adapter.patch.api.Patch; -import org.junit.jupiter.api.Test; - -public class ParameterSubstitutionTest extends MixinPatchTest { - @Test - void testSimpleSubstitution() throws Exception { - assertSameCode( - "org/sinytra/adapter/test/mixins/ParameterSubstitutionMixin", - "testSubstitution", - Patch.builder() - .targetInjectionPoint("") - .targetMethod("injectTarget") - .targetMixinType(MixinConstants.INJECT) - .transformParams(params -> params.substitute(1, 0)) - ); - } - - @Test - void testBigSubstitution() throws Exception { - assertSameCode( - "org/sinytra/adapter/test/mixins/ParameterSubstitutionMixin", - "testBigSubstitution", - Patch.builder() - .targetInjectionPoint("") - .targetMethod("injectTarget2") - .targetMixinType(MixinConstants.INJECT) - .transformParams(params -> params.substitute(2, 0)) - ); - } - - @Test - void testComplexSubstitution() throws Exception { - assertSameCode( - "org/sinytra/adapter/test/mixins/ParameterSubstitutionMixin", - "testComplexSubstitution", - Patch.builder() - .targetInjectionPoint("") - .targetMethod("injectTarget3") - .targetMixinType(MixinConstants.INJECT) - .transformParams(params -> params.substitute(1, 2)) - ); - } - -} diff --git a/definition/src/test/java/org/sinytra/adapter/patch/test/mixin/ParameterSwapTest.java b/definition/src/test/java/org/sinytra/adapter/patch/test/mixin/ParameterSwapTest.java deleted file mode 100644 index be91ea7..0000000 --- a/definition/src/test/java/org/sinytra/adapter/patch/test/mixin/ParameterSwapTest.java +++ /dev/null @@ -1,51 +0,0 @@ -package org.sinytra.adapter.patch.test.mixin; - -import org.sinytra.adapter.patch.api.MixinConstants; -import org.sinytra.adapter.patch.api.Patch; -import org.junit.jupiter.api.Test; - -public class ParameterSwapTest extends MixinPatchTest { - - // Test swap between two parameters of size 1 - @Test - void testSimpleSwap() throws Exception { - assertSameCode( - "org/sinytra/adapter/test/mixins/ParameterSwapMixin", - "testSwap", - Patch.builder() - .targetInjectionPoint("") - .targetMethod("injectTarget") - .targetMixinType(MixinConstants.INJECT) - .transformParams(params -> params.swap(0, 1)) - ); - } - - // Test multiple sequential swaps - @Test - void testComplexSwap() throws Exception { - assertSameCode( - "org/sinytra/adapter/test/mixins/ParameterSwapMixin", - "testComplexSwap", - Patch.builder() - .targetInjectionPoint("") - .targetMethod("injectTarget2") - .targetMixinType(MixinConstants.INJECT) - .transformParams(params -> params.swap(2, 1) - .swap(1, 0)) - ); - } - - // Test to make sure that longs and doubles (which use 2 LVT spaces) are accounted for - @Test - void testBigSwap() throws Exception { - assertSameCode( - "org/sinytra/adapter/test/mixins/ParameterSwapMixin", - "testBigSwap", - Patch.builder() - .targetInjectionPoint("") - .targetMethod("injectTarget3") - .targetMixinType(MixinConstants.INJECT) - .transformParams(params -> params.swap(0, 1)) - ); - } -} diff --git a/definition/src/testClasses/java/org/sinytra/adapter/test/mixins/ParameterInjectionMixin.java b/definition/src/testClasses/java/org/sinytra/adapter/test/mixins/ParameterInjectionMixin.java deleted file mode 100644 index 9c232d3..0000000 --- a/definition/src/testClasses/java/org/sinytra/adapter/test/mixins/ParameterInjectionMixin.java +++ /dev/null @@ -1,42 +0,0 @@ -package org.sinytra.adapter.test.mixins; - -import com.llamalad7.mixinextras.injector.wrapoperation.Operation; -import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation; -import org.sinytra.adapter.test.classes.ParameterInjection; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.Redirect; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; - -import java.util.concurrent.atomic.AtomicInteger; - -@Mixin(ParameterInjection.class) -public class ParameterInjectionMixin { - @Redirect(method = "testRedirect(Ljava/lang/String;I)V", at = @At(value = "INVOKE", target = "Ljava/lang/String;repeat()Ljava/lang/String;")) - private String testRedirectInjection(String owner) { - return owner.repeat(1); - } - - private String testRedirectInjectionExpected(String owner, int adapter_injected_1) { - return owner.repeat(1); - } - - @Inject(method = "testTargetBig(JDF)V", at = @At("HEAD")) - private void testBigParameterInjection(long a, float c, CallbackInfo ci) { - System.out.println(c / a); - } - - private void testBigParameterInjectionExpected(long a, double adapter_injected_1, float c, CallbackInfo ci) { - System.out.println(c / a); - } - - @WrapOperation(method = "testTargetWrap(Lorg/sinytra/adapter/test/classes/ParameterInjection$SomeClass;Ljava/lang/String;Ljava/util/concurrent/atomic/AtomicInteger;)V", at = @At(value = "INVOKE", target = "Lorg/sinytra/adapter/test/classes/ParameterInjection$SomeClass;execute(Ljava/lang/String;Ljava/util/concurrent/atomic/AtomicInteger;)V")) - private void testWrapOperation(ParameterInjection.SomeClass someClass, String p1, Operation operation) { - operation.call(someClass, p1); - } - - private void testWrapOperationExpected(ParameterInjection.SomeClass someClass, String p1, AtomicInteger adapter_injected_2, Operation operation) { - operation.call(someClass, p1, adapter_injected_2); - } -} diff --git a/definition/src/testClasses/java/org/sinytra/adapter/test/mixins/ParameterInlineMixin.java b/definition/src/testClasses/java/org/sinytra/adapter/test/mixins/ParameterInlineMixin.java deleted file mode 100644 index 6e1ee85..0000000 --- a/definition/src/testClasses/java/org/sinytra/adapter/test/mixins/ParameterInlineMixin.java +++ /dev/null @@ -1,29 +0,0 @@ -package org.sinytra.adapter.test.mixins; - -import org.sinytra.adapter.test.classes.ParameterInline; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; - -@Mixin(ParameterInline.class) -public class ParameterInlineMixin { - @Inject(method = "simple(ILjava/lang/String;ILjava/lang/String;)V", at = @At("HEAD")) - private static void testSimpleInline(int p1, String p2, int p3, String p4) { - System.out.println(p4); - } - - private static void testSimpleInlineExpected(int p1, String p2, int p3) { - System.out.println("inlined"); - } - - @Inject(method = "big(IDI)V", at = @At("HEAD")) - private static void testBigInline(int p1, double p2, double p3, int p4) { - System.out.println(p3 * p2); - System.out.println("p4: " + p4); - } - - private static void testBigInlineExpected(int p1, double p2, int p4) { - System.out.println(43d * p2); - System.out.println("p4: " + p4); - } -} diff --git a/definition/src/testClasses/java/org/sinytra/adapter/test/mixins/ParameterRemoveMixin.java b/definition/src/testClasses/java/org/sinytra/adapter/test/mixins/ParameterRemoveMixin.java deleted file mode 100644 index f3e8efb..0000000 --- a/definition/src/testClasses/java/org/sinytra/adapter/test/mixins/ParameterRemoveMixin.java +++ /dev/null @@ -1,31 +0,0 @@ -package org.sinytra.adapter.test.mixins; - -import com.llamalad7.mixinextras.injector.wrapoperation.Operation; -import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation; -import org.sinytra.adapter.test.classes.ParameterRemove; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; - -import java.util.concurrent.atomic.AtomicBoolean; - -@Mixin(ParameterRemove.class) -public class ParameterRemoveMixin { - @Inject(method = "testSimple(IC)V", at = @At("HEAD")) - private static void testSimpleRemove(int p1, char p2, boolean p3) { - System.out.println("Hi: " + p2 / p1); - } - - private static void testSimpleRemoveExpected(int p1, char p2) { - System.out.println("Hi: " + p2 / p1); - } - - @WrapOperation(method = "testWrapOp(Lorg/sinytra/adapter/test/classes/ParameterRemove$SObj;Ljava/util/concurrent/atomic/AtomicBoolean;)V", at = @At(value = "INVOKE", target = "Lorg/sinytra/adapter/test/classes/ParameterRemove$SObj;call(Ljava/util/concurrent/atomic/AtomicBoolean;)V")) - private static void testWrapOpRemove(ParameterRemove.SObj obj, AtomicBoolean p1, int p2, Operation operation) { - System.out.println(operation.call(obj, p1, p2)); - } - - private static void testWrapOpRemoveExpected(ParameterRemove.SObj obj, AtomicBoolean p1, Operation operation) { - System.out.println(operation.call(obj, p1)); - } -} diff --git a/definition/src/testClasses/java/org/sinytra/adapter/test/mixins/ParameterSubstitutionMixin.java b/definition/src/testClasses/java/org/sinytra/adapter/test/mixins/ParameterSubstitutionMixin.java deleted file mode 100644 index 1412888..0000000 --- a/definition/src/testClasses/java/org/sinytra/adapter/test/mixins/ParameterSubstitutionMixin.java +++ /dev/null @@ -1,38 +0,0 @@ -package org.sinytra.adapter.test.mixins; - -import org.sinytra.adapter.test.classes.ParameterSubstitution; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; - -@Mixin(ParameterSubstitution.class) -public class ParameterSubstitutionMixin { - @Inject(at = @At("HEAD"), method = "injectTarget(I)V") - private void testSubstitution(int a, int a1, CallbackInfo ci) { - System.out.println(a + a1); - } - - private void testSubstitutionExpected(int a, CallbackInfo ci) { - System.out.println(a + a); - } - - @Inject(at = @At("HEAD"), method = "injectTarget2(JLjava/lang/String;)V") - private void testBigSubstitution(long a, String b, long a1, CallbackInfo ci) { - System.out.println(b + ": " + a + a1); - } - - private void testBigSubstitutionExpected(long a, String b, CallbackInfo ci) { - System.out.println(b + ": " + a + a); - } - - @Inject(at = @At("HEAD"), method = "injectTarget3(JDLjava/lang/String;)V") - private void testComplexSubstitution(long a, double b, double b1, String c, CallbackInfo ci) { - System.out.println(c + ": " + a + (b + b1 / 2)); - } - - // Substitute b with b1 - private void testComplexSubstitutionExpected(long a, double b1, String c, CallbackInfo ci) { - System.out.println(c + ": " + a + (b1 + b1 / 2)); - } -} diff --git a/definition/src/testClasses/java/org/sinytra/adapter/test/mixins/ParameterSwapMixin.java b/definition/src/testClasses/java/org/sinytra/adapter/test/mixins/ParameterSwapMixin.java deleted file mode 100644 index 22b3df9..0000000 --- a/definition/src/testClasses/java/org/sinytra/adapter/test/mixins/ParameterSwapMixin.java +++ /dev/null @@ -1,39 +0,0 @@ -package org.sinytra.adapter.test.mixins; - -import org.sinytra.adapter.test.classes.ParameterSwap; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; - -@Mixin(ParameterSwap.class) -public class ParameterSwapMixin { - @Inject(method = "injectTarget(Ljava/lang/String;I)V", at = @At(value = "HEAD")) - private void testSwap(int theInt, String theString, CallbackInfo ci) { - System.out.println("Int: " + theInt); - System.out.println("Str: " + theString); - } - - private void testSwapExpected(String theString, int theInt, CallbackInfo ci) { - System.out.println("Int: " + theInt); - System.out.println("Str: " + theString); - } - - @Inject(method = "injectTarget2(Ljava/lang/String;SJ)V", at = @At("HEAD")) - private void testComplexSwap(int theInt, short theShort, String theString, CallbackInfo ci) { - System.out.println(theString.repeat(theInt + theShort)); - } - - private void testComplexSwapExpected(String theString, int theInt, short theShort, CallbackInfo ci) { - System.out.println(theString.repeat(theInt + theShort)); - } - - @Inject(method = "injectTarget3(Ljava/lang/String;J)V", at = @At("HEAD")) - private void testBigSwap(long theLong, String theString, CallbackInfo ci) { - System.out.println(theString.repeat((int)theLong / 2)); - } - - private void testBigSwapExpected(String theString, long theLong, CallbackInfo ci) { - System.out.println(theString.repeat((int)theLong / 2)); - } -} diff --git a/plugin/src/main/java/org/sinytra/adapter/gradle/AdapterCompareJarTask.java b/plugin/src/main/java/org/sinytra/adapter/gradle/AdapterCompareJarTask.java index 0e9a8c5..abb2fd0 100644 --- a/plugin/src/main/java/org/sinytra/adapter/gradle/AdapterCompareJarTask.java +++ b/plugin/src/main/java/org/sinytra/adapter/gradle/AdapterCompareJarTask.java @@ -15,7 +15,7 @@ import org.sinytra.adapter.patch.LVTOffsets; import org.sinytra.adapter.patch.PatchInstance; import org.sinytra.adapter.patch.api.Patch; -import org.sinytra.adapter.patch.serialization.PatchSerialization; +import org.sinytra.adapter.patch.transformer.serialization.PatchSerialization; import org.sinytra.adapter.patch.util.MethodQualifier; import org.sinytra.adapter.patch.util.provider.ClassLookup; import org.sinytra.adapter.patch.util.provider.ZipClassLookup; diff --git a/plugin/src/main/java/org/sinytra/adapter/gradle/ClassAnalyzer.java b/plugin/src/main/java/org/sinytra/adapter/gradle/ClassAnalyzer.java index f6423f8..2e50ade 100644 --- a/plugin/src/main/java/org/sinytra/adapter/gradle/ClassAnalyzer.java +++ b/plugin/src/main/java/org/sinytra/adapter/gradle/ClassAnalyzer.java @@ -21,10 +21,10 @@ import org.sinytra.adapter.patch.analysis.params.LayeredParamsDiffSnapshot; import org.sinytra.adapter.patch.analysis.params.ParametersDiff; import org.sinytra.adapter.patch.api.Patch; -import org.sinytra.adapter.patch.transformer.ModifyInjectionTarget; -import org.sinytra.adapter.patch.transformer.ModifyMethodAccess; +import org.sinytra.adapter.patch.transformer.operation.ModifyInjectionTarget; +import org.sinytra.adapter.patch.transformer.operation.ModifyMethodAccess; import org.sinytra.adapter.patch.transformer.SoftMethodParamsPatch; -import org.sinytra.adapter.patch.transformer.param.ParamTransformTarget; +import org.sinytra.adapter.patch.transformer.operation.param.ParamTransformTarget; import org.sinytra.adapter.patch.util.MethodQualifier; import org.sinytra.adapter.patch.util.provider.ClassLookup; import org.slf4j.Logger; diff --git a/plugin/src/main/java/org/sinytra/adapter/gradle/analysis/OverloadedMethods.java b/plugin/src/main/java/org/sinytra/adapter/gradle/analysis/OverloadedMethods.java index 1987f62..b494b28 100644 --- a/plugin/src/main/java/org/sinytra/adapter/gradle/analysis/OverloadedMethods.java +++ b/plugin/src/main/java/org/sinytra/adapter/gradle/analysis/OverloadedMethods.java @@ -4,8 +4,9 @@ import org.sinytra.adapter.gradle.util.MatchResult; import org.sinytra.adapter.patch.analysis.MethodCallAnalyzer; import org.sinytra.adapter.patch.api.MethodTransform; -import org.sinytra.adapter.patch.transformer.ModifyInjectionTarget; -import org.sinytra.adapter.patch.transformer.filter.InjectionPointTransformerFilter; +import org.sinytra.adapter.patch.transformer.pipeline.MethodTransformationPipeline; +import org.sinytra.adapter.patch.transformer.operation.ModifyInjectionTarget; +import org.sinytra.adapter.patch.transformer.pipeline.InjectionPointTransformerFilter; import org.jetbrains.annotations.Nullable; import org.objectweb.asm.Opcodes; import org.objectweb.asm.Type; @@ -141,9 +142,9 @@ public static MatchResult checkParameters(Type[] parameterTypes, Type[] dirtyPar public record MethodOverload(boolean isFullMatch, MethodNode methodNode, List excludedInjectionPoints) { public MethodTransform getPatchTargetTransform(MethodNode method) { - return this.excludedInjectionPoints.isEmpty() - ? new ModifyInjectionTarget(List.of(method.name + method.desc)) - : InjectionPointTransformerFilter.create(new ModifyInjectionTarget(List.of(method.name + method.desc)), this.excludedInjectionPoints); + return MethodTransformationPipeline.builder(new ModifyInjectionTarget(List.of(method.name + method.desc))) + .filter(InjectionPointTransformerFilter.create(this.excludedInjectionPoints)) + .build(); } } } diff --git a/plugin/src/main/java/org/sinytra/adapter/gradle/analysis/ReplacedMethodCalls.java b/plugin/src/main/java/org/sinytra/adapter/gradle/analysis/ReplacedMethodCalls.java index 5bde0ca..ae0acad 100644 --- a/plugin/src/main/java/org/sinytra/adapter/gradle/analysis/ReplacedMethodCalls.java +++ b/plugin/src/main/java/org/sinytra/adapter/gradle/analysis/ReplacedMethodCalls.java @@ -7,7 +7,7 @@ import org.sinytra.adapter.patch.analysis.InstructionMatcher; import org.sinytra.adapter.patch.analysis.MethodCallAnalyzer; import org.sinytra.adapter.patch.analysis.params.ParametersDiff; -import org.sinytra.adapter.patch.transformer.param.ParamTransformTarget; +import org.sinytra.adapter.patch.transformer.operation.param.ParamTransformTarget; import org.sinytra.adapter.patch.util.MethodQualifier; import org.apache.commons.lang3.ArrayUtils; import org.objectweb.asm.Type; diff --git a/definition/src/test/java/org/sinytra/adapter/patch/test/EnhancedParamsDiffTest.java b/test/src/test/java/org/sinytra/adapter/patch/test/EnhancedParamsDiffTest.java similarity index 100% rename from definition/src/test/java/org/sinytra/adapter/patch/test/EnhancedParamsDiffTest.java rename to test/src/test/java/org/sinytra/adapter/patch/test/EnhancedParamsDiffTest.java diff --git a/definition/src/test/java/org/sinytra/adapter/patch/test/ParameterComparisonTest.java b/test/src/test/java/org/sinytra/adapter/patch/test/ParameterComparisonTest.java similarity index 96% rename from definition/src/test/java/org/sinytra/adapter/patch/test/ParameterComparisonTest.java rename to test/src/test/java/org/sinytra/adapter/patch/test/ParameterComparisonTest.java index 3e5b6ba..bcab2fd 100644 --- a/definition/src/test/java/org/sinytra/adapter/patch/test/ParameterComparisonTest.java +++ b/test/src/test/java/org/sinytra/adapter/patch/test/ParameterComparisonTest.java @@ -1,12 +1,12 @@ package org.sinytra.adapter.patch.test; import org.junit.jupiter.api.Test; -import org.objectweb.asm.ClassReader; import org.objectweb.asm.Type; import org.objectweb.asm.tree.ClassNode; import org.objectweb.asm.tree.MethodNode; import org.sinytra.adapter.patch.analysis.params.ParametersDiff; import org.sinytra.adapter.patch.analysis.params.SimpleParamsDiffSnapshot; +import org.sinytra.adapter.patch.test.mixin.MinecraftMixinPatchTest; import org.sinytra.adapter.patch.transformer.dynamic.DynamicLVTPatch; import java.io.IOException; @@ -97,13 +97,8 @@ public void testCompareAppendedParameters() { @Test public void testMethodParameterNameComparison() throws IOException { - ClassReader cleanReader = new ClassReader("org.sinytra.adapter.patch.test.CleanDummyClass"); - ClassNode cleanNode = new ClassNode(); - cleanReader.accept(cleanNode, 0); - - ClassReader dirtyReader = new ClassReader("org.sinytra.adapter.patch.test.DirtyDummyClass"); - ClassNode dirtyNode = new ClassNode(); - dirtyReader.accept(dirtyNode, 0); + ClassNode cleanNode = MinecraftMixinPatchTest.loadClass("org/sinytra/adapter/test/CleanDummyClass"); + ClassNode dirtyNode = MinecraftMixinPatchTest.loadClass("org/sinytra/adapter/test/DirtyDummyClass"); MethodNode cleanMethod = cleanNode.methods.stream().filter(m -> m.name.equals("namedInsertionTest")).findFirst().orElseThrow(); MethodNode dirtyMethod = dirtyNode.methods.stream().filter(m -> m.name.equals("namedInsertionTest")).findFirst().orElseThrow(); diff --git a/test/src/test/java/org/sinytra/adapter/patch/test/mixin/MinecraftMixinPatchTest.java b/test/src/test/java/org/sinytra/adapter/patch/test/mixin/MinecraftMixinPatchTest.java index 13cdfa8..9f69326 100644 --- a/test/src/test/java/org/sinytra/adapter/patch/test/mixin/MinecraftMixinPatchTest.java +++ b/test/src/test/java/org/sinytra/adapter/patch/test/mixin/MinecraftMixinPatchTest.java @@ -8,8 +8,8 @@ import org.sinytra.adapter.patch.api.MixinClassGenerator; import org.sinytra.adapter.patch.api.MixinConstants; import org.sinytra.adapter.patch.api.PatchEnvironment; -import org.sinytra.adapter.patch.selector.AnnotationHandle; -import org.sinytra.adapter.patch.selector.AnnotationValueHandle; +import org.sinytra.adapter.patch.analysis.selector.AnnotationHandle; +import org.sinytra.adapter.patch.analysis.selector.AnnotationValueHandle; import org.sinytra.adapter.patch.util.AdapterUtil; import org.sinytra.adapter.patch.util.provider.ClassLookup; import org.sinytra.adapter.patch.util.provider.ZipClassLookup; @@ -121,7 +121,7 @@ public int compare(AbstractInsnNode o1, AbstractInsnNode o2) { public record LoadResult(PatchEnvironment env, ClassNode patched, ClassNode expected) { } - protected ClassNode loadClass(String name) throws IOException { + public static ClassNode loadClass(String name) throws IOException { final ClassNode n = new ClassNode(); try (final InputStream is = MinecraftMixinPatchTest.class.getClassLoader().getResourceAsStream(name + ".class")) { new ClassReader(is).accept(n, 0); diff --git a/definition/src/test/java/org/sinytra/adapter/patch/test/CleanDummyClass.java b/test/src/testClasses/java/org/sinytra/adapter/test/CleanDummyClass.java similarity index 85% rename from definition/src/test/java/org/sinytra/adapter/patch/test/CleanDummyClass.java rename to test/src/testClasses/java/org/sinytra/adapter/test/CleanDummyClass.java index 63ab3a2..0c02d28 100644 --- a/definition/src/test/java/org/sinytra/adapter/patch/test/CleanDummyClass.java +++ b/test/src/testClasses/java/org/sinytra/adapter/test/CleanDummyClass.java @@ -1,4 +1,4 @@ -package org.sinytra.adapter.patch.test; +package org.sinytra.adapter.test; public class CleanDummyClass { public void namedInsertionTest(Object obj, double p_110986_, double p_110987_, double p_110988_, float p_110989_, float p_110990_, float p_110991_, float p_110992_, float p_110993_, int p_110994_) { diff --git a/definition/src/test/java/org/sinytra/adapter/patch/test/DirtyDummyClass.java b/test/src/testClasses/java/org/sinytra/adapter/test/DirtyDummyClass.java similarity index 86% rename from definition/src/test/java/org/sinytra/adapter/patch/test/DirtyDummyClass.java rename to test/src/testClasses/java/org/sinytra/adapter/test/DirtyDummyClass.java index 1356459..92e47f5 100644 --- a/definition/src/test/java/org/sinytra/adapter/patch/test/DirtyDummyClass.java +++ b/test/src/testClasses/java/org/sinytra/adapter/test/DirtyDummyClass.java @@ -1,4 +1,4 @@ -package org.sinytra.adapter.patch.test; +package org.sinytra.adapter.test; public class DirtyDummyClass { public void namedInsertionTest(Object obj, double p_110986_, double p_110987_, double p_110988_, float p_110989_, float p_110990_, float p_110991_, float alpha, float p_110992_, float p_110993_, int p_110994_) { diff --git a/definition/src/testClasses/java/org/sinytra/adapter/test/classes/ParameterInjection.java b/test/src/testClasses/java/org/sinytra/adapter/test/classes/ParameterInjection.java similarity index 100% rename from definition/src/testClasses/java/org/sinytra/adapter/test/classes/ParameterInjection.java rename to test/src/testClasses/java/org/sinytra/adapter/test/classes/ParameterInjection.java diff --git a/definition/src/testClasses/java/org/sinytra/adapter/test/classes/ParameterInline.java b/test/src/testClasses/java/org/sinytra/adapter/test/classes/ParameterInline.java similarity index 100% rename from definition/src/testClasses/java/org/sinytra/adapter/test/classes/ParameterInline.java rename to test/src/testClasses/java/org/sinytra/adapter/test/classes/ParameterInline.java diff --git a/definition/src/testClasses/java/org/sinytra/adapter/test/classes/ParameterRemove.java b/test/src/testClasses/java/org/sinytra/adapter/test/classes/ParameterRemove.java similarity index 100% rename from definition/src/testClasses/java/org/sinytra/adapter/test/classes/ParameterRemove.java rename to test/src/testClasses/java/org/sinytra/adapter/test/classes/ParameterRemove.java diff --git a/definition/src/testClasses/java/org/sinytra/adapter/test/classes/ParameterSubstitution.java b/test/src/testClasses/java/org/sinytra/adapter/test/classes/ParameterSubstitution.java similarity index 100% rename from definition/src/testClasses/java/org/sinytra/adapter/test/classes/ParameterSubstitution.java rename to test/src/testClasses/java/org/sinytra/adapter/test/classes/ParameterSubstitution.java diff --git a/definition/src/testClasses/java/org/sinytra/adapter/test/classes/ParameterSwap.java b/test/src/testClasses/java/org/sinytra/adapter/test/classes/ParameterSwap.java similarity index 100% rename from definition/src/testClasses/java/org/sinytra/adapter/test/classes/ParameterSwap.java rename to test/src/testClasses/java/org/sinytra/adapter/test/classes/ParameterSwap.java