Skip to content

Commit

Permalink
Avoid conflict between static patches and method upgrades
Browse files Browse the repository at this point in the history
  • Loading branch information
Su5eD committed Mar 14, 2024
1 parent 7a378fe commit 0e8a297
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,12 @@ public ClassPatchBuilder targetInjectionPoint(String value, String target) {

@Override
public ClassPatchBuilder modifyInjectionPoint(String value, String target, boolean resetValues) {
return transform(new ModifyInjectionPoint(value, target, resetValues));
return modifyInjectionPoint(value, target, resetValues, false);
}

@Override
public ClassPatchBuilder modifyInjectionPoint(String value, String target, boolean resetValues, boolean dontUpgrade) {
return transform(new ModifyInjectionPoint(value, target, resetValues, dontUpgrade));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ default ClassPatchBuilder modifyInjectionPoint(String value, String target) {

ClassPatchBuilder modifyInjectionPoint(String value, String target, boolean resetValues);

ClassPatchBuilder modifyInjectionPoint(String value, String target, boolean resetValues, boolean dontUpgrade);

default ClassPatchBuilder modifyInjectionPoint(String target) {
return modifyInjectionPoint(null, target);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,17 @@

import static org.sinytra.adapter.patch.PatchInstance.MIXINPATCH;

public record ModifyInjectionPoint(@Nullable String value, String target, boolean resetValues) implements MethodTransform {
public record ModifyInjectionPoint(@Nullable String value, String target, boolean resetValues, boolean dontUpgrade) implements MethodTransform {
private static final Logger LOGGER = LogUtils.getLogger();
public static final Codec<ModifyInjectionPoint> CODEC = RecordCodecBuilder.create(instance -> instance.group(
Codec.STRING.optionalFieldOf("value").forGetter(i -> Optional.ofNullable(i.value())),
Codec.STRING.fieldOf("target").forGetter(ModifyInjectionPoint::target),
Codec.BOOL.optionalFieldOf("resetValues", false).forGetter(ModifyInjectionPoint::resetValues)
Codec.BOOL.optionalFieldOf("resetValues", false).forGetter(ModifyInjectionPoint::resetValues),
Codec.BOOL.optionalFieldOf("dontUpgrade", false).forGetter(ModifyInjectionPoint::dontUpgrade)
).apply(instance, ModifyInjectionPoint::new));

public ModifyInjectionPoint(Optional<String> value, String target, boolean resetValues) {
this(value.orElse(null), target, resetValues);
public ModifyInjectionPoint(Optional<String> value, String target, boolean resetValues, boolean dontUpgrade) {
this(value.orElse(null), target, resetValues, dontUpgrade);
}

@Override
Expand All @@ -48,7 +49,9 @@ public Patch.Result apply(ClassNode classNode, MethodNode methodNode, MethodCont
if (handle != null) {
String original = handle.get();
handle.set(this.target);
MethodUpgrader.upgradeMethod(classNode, methodNode, methodContext, original, this.target);
if (!this.dontUpgrade) {
MethodUpgrader.upgradeMethod(classNode, methodNode, methodContext, original, this.target);
}
} else {
annotation.appendValue("target", this.target);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,8 @@ private void updateReplacedInjectionPoints(List<? super PatchInstance> patches,
.targetClass(this.dirtyNode.name)
.targetMethod(dirtyMethod.name + dirtyMethod.desc)
.targetInjectionPoint(oldQualifier)
.modifyInjectionPoint(callQualifier)
// Avoid automatic method upgrades when a parameter transformation is being applied
.modifyInjectionPoint(null, callQualifier, false, true)
.transformMethods(diff.createTransforms(ModifyMethodParams.TargetType.INJECTION_POINT))
.build();
patches.add(patch);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,8 @@ private static boolean findOverloadedReplacement(AnalysisContext context, Method
.targetClass(context.getDirtyNode().name)
.targetMethod(dirtyMethod.name + dirtyMethod.desc)
.targetInjectionPoint(cleanCall)
.modifyInjectionPoint(qualifier)
// Avoid automatic method upgrades when a parameter transformation is being applied
.modifyInjectionPoint(null, qualifier, false, true)
.transformMethods(diff.createTransforms(ModifyMethodParams.TargetType.INJECTION_POINT))
.build();
context.addPatch(patch);
Expand Down

0 comments on commit 0e8a297

Please sign in to comment.