mirror of
https://github.com/LegacyModdingMC/UniMix.git
synced 2026-11-20 12:19:52 +00:00
Add silent option to Unique
This commit is contained in:
1 parent
50660894fc
commit
057f0fd905
2 files changed
+20
-4
No files matched your search
@@ -48,7 +48,8 @@ import java.lang.annotation.Target;
|
||||
* <dl>
|
||||
* <dt>public methods</dt>
|
||||
* <dd>public methods marked with this annotation are <b>discarded</b> if a
|
||||
* matching target exists. A <tt>warning</tt>-level message is generated.</dd>
|
||||
* matching target exists. Unless {@link #silent} is set to <tt>true</tt>, a
|
||||
* <tt>warning</tt>-level message is generated.</dd>
|
||||
* <dt>private and protected methods</dt>
|
||||
* <dd>non-public methods are <b>renamed</b> if a matching target method is
|
||||
* found, this allows utility methods to be safely assigned meaningful names
|
||||
@@ -68,5 +69,16 @@ import java.lang.annotation.Target;
|
||||
@Target({ ElementType.METHOD, ElementType.FIELD, ElementType.TYPE })
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface Unique {
|
||||
|
||||
/**
|
||||
* If this annotation is applied to a public method in a mixin and a
|
||||
* conflicting method is found in a target class, then a
|
||||
* <tt>warning</tt>-level message is generated in the log. To suppress this
|
||||
* message, set this value to <tt>true</tt>.
|
||||
*
|
||||
* @return true to suppress warning message when a public method is
|
||||
* discarded
|
||||
*/
|
||||
public boolean silent() default false;
|
||||
|
||||
}
|
||||
+7
-3
@@ -41,6 +41,7 @@ import org.spongepowered.asm.mixin.MixinEnvironment.CompatibilityLevel;
|
||||
import org.spongepowered.asm.mixin.MixinEnvironment.Option;
|
||||
import org.spongepowered.asm.mixin.Overwrite;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
import org.spongepowered.asm.mixin.Unique;
|
||||
import org.spongepowered.asm.mixin.gen.Accessor;
|
||||
import org.spongepowered.asm.mixin.gen.Invoker;
|
||||
import org.spongepowered.asm.mixin.gen.throwables.InvalidAccessorException;
|
||||
@@ -415,7 +416,7 @@ class MixinPreProcessorStandard {
|
||||
return false;
|
||||
}
|
||||
|
||||
String type = method.isUnique() ? "@Unique" : "synthetic";
|
||||
String type = method.isSynthetic() ? "synthetic" : "@Unique";
|
||||
|
||||
if (Bytecode.getVisibility(mixinMethod).ordinal() < Visibility.PUBLIC.ordinal()) {
|
||||
String uniqueName = context.getUniqueName(mixinMethod, false);
|
||||
@@ -430,8 +431,11 @@ class MixinPreProcessorStandard {
|
||||
+ " cannot overwrite " + target.name + target.desc + " in " + context.getTarget());
|
||||
}
|
||||
|
||||
MixinPreProcessorStandard.logger.warn("Discarding {} public method {} in {} because it already exists in {}", type, mixinMethod.name,
|
||||
this.mixin, context.getTarget());
|
||||
AnnotationNode unique = Annotations.getVisible(mixinMethod, Unique.class);
|
||||
if (unique == null || !Annotations.<Boolean>getValue(unique, "silent", Boolean.FALSE).booleanValue()) {
|
||||
MixinPreProcessorStandard.logger.warn("Discarding {} public method {} in {} because it already exists in {}", type, mixinMethod.name,
|
||||
this.mixin, context.getTarget());
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user