From 4d48bdfe7c3806ec1995cd499ca9382ace2d8a53 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Sat, 25 Mar 2017 13:50:01 -0400 Subject: drop 'generic' prefix for rewriters since they're all generic now --- .../Finders/EventFinder.cs | 54 ++++++++++++++++++ .../Finders/FieldFinder.cs | 61 +++++++++++++++++++++ .../Finders/GenericEventFinder.cs | 54 ------------------ .../Finders/GenericFieldFinder.cs | 61 --------------------- .../Finders/GenericMethodFinder.cs | 54 ------------------ .../Finders/GenericTypeFinder.cs | 64 ---------------------- .../Finders/MethodFinder.cs | 54 ++++++++++++++++++ .../Finders/TypeFinder.cs | 64 ++++++++++++++++++++++ 8 files changed, 233 insertions(+), 233 deletions(-) create mode 100644 src/StardewModdingAPI.AssemblyRewriters/Finders/EventFinder.cs create mode 100644 src/StardewModdingAPI.AssemblyRewriters/Finders/FieldFinder.cs delete mode 100644 src/StardewModdingAPI.AssemblyRewriters/Finders/GenericEventFinder.cs delete mode 100644 src/StardewModdingAPI.AssemblyRewriters/Finders/GenericFieldFinder.cs delete mode 100644 src/StardewModdingAPI.AssemblyRewriters/Finders/GenericMethodFinder.cs delete mode 100644 src/StardewModdingAPI.AssemblyRewriters/Finders/GenericTypeFinder.cs create mode 100644 src/StardewModdingAPI.AssemblyRewriters/Finders/MethodFinder.cs create mode 100644 src/StardewModdingAPI.AssemblyRewriters/Finders/TypeFinder.cs (limited to 'src/StardewModdingAPI.AssemblyRewriters/Finders') diff --git a/src/StardewModdingAPI.AssemblyRewriters/Finders/EventFinder.cs b/src/StardewModdingAPI.AssemblyRewriters/Finders/EventFinder.cs new file mode 100644 index 00000000..359ca63e --- /dev/null +++ b/src/StardewModdingAPI.AssemblyRewriters/Finders/EventFinder.cs @@ -0,0 +1,54 @@ +using Mono.Cecil; +using Mono.Cecil.Cil; +using StardewModdingAPI.AssemblyRewriters.Framework; + +namespace StardewModdingAPI.AssemblyRewriters.Finders +{ + /// Finds CIL instructions that reference a given event. + public sealed class EventFinder : BaseMethodFinder + { + /********* + ** Properties + *********/ + /// The full type name for which to find references. + private readonly string FullTypeName; + + /// The event name for which to find references. + private readonly string EventName; + + + /********* + ** Accessors + *********/ + /// A brief noun phrase indicating what the instruction finder matches. + public override string NounPhrase { get; } + + + /********* + ** Public methods + *********/ + /// Construct an instance. + /// The full type name for which to find references. + /// The event name for which to find references. + public EventFinder(string fullTypeName, string eventName) + { + this.FullTypeName = fullTypeName; + this.EventName = eventName; + this.NounPhrase = $"obsolete {fullTypeName}.{eventName} event"; + } + + + /********* + ** Protected methods + *********/ + /// Get whether a method reference should be rewritten. + /// The IL instruction. + /// The method reference. + /// Whether the mod was compiled on a different platform. + protected override bool IsMatch(Instruction instruction, MethodReference methodRef, bool platformChanged) + { + return methodRef.DeclaringType.FullName == this.FullTypeName + && (methodRef.Name == "add_" + this.EventName || methodRef.Name == "remove_" + this.EventName); + } + } +} diff --git a/src/StardewModdingAPI.AssemblyRewriters/Finders/FieldFinder.cs b/src/StardewModdingAPI.AssemblyRewriters/Finders/FieldFinder.cs new file mode 100644 index 00000000..516641f2 --- /dev/null +++ b/src/StardewModdingAPI.AssemblyRewriters/Finders/FieldFinder.cs @@ -0,0 +1,61 @@ +using Mono.Cecil; +using Mono.Cecil.Cil; +using StardewModdingAPI.AssemblyRewriters.Framework; + +namespace StardewModdingAPI.AssemblyRewriters.Finders +{ + /// Finds CIL instructions that reference a given field. + public sealed class FieldFinder : BaseFieldFinder + { + /********* + ** Properties + *********/ + /// The full type name for which to find references. + private readonly string FullTypeName; + + /// The field name for which to find references. + private readonly string FieldName; + + /// Whether the field to match is static. + private readonly bool IsStatic; + + + /********* + ** Accessors + *********/ + /// A brief noun phrase indicating what the instruction finder matches. + public override string NounPhrase { get; } + + + /********* + ** Public methods + *********/ + /// Construct an instance. + /// The full type name for which to find references. + /// The field name for which to find references. + /// Whether the field to match is static. + public FieldFinder(string fullTypeName, string fieldName, bool isStatic) + { + this.FullTypeName = fullTypeName; + this.FieldName = fieldName; + this.IsStatic = isStatic; + this.NounPhrase = $"obsolete {fullTypeName}.{fieldName} field"; + } + + + /********* + ** Protected methods + *********/ + /// Get whether a field reference should be rewritten. + /// The IL instruction. + /// The field reference. + /// Whether the mod was compiled on a different platform. + protected override bool IsMatch(Instruction instruction, FieldReference fieldRef, bool platformChanged) + { + return + this.IsStaticField(instruction) == this.IsStatic + && fieldRef.DeclaringType.FullName == this.FullTypeName + && fieldRef.Name == this.FieldName; + } + } +} diff --git a/src/StardewModdingAPI.AssemblyRewriters/Finders/GenericEventFinder.cs b/src/StardewModdingAPI.AssemblyRewriters/Finders/GenericEventFinder.cs deleted file mode 100644 index c2a981e5..00000000 --- a/src/StardewModdingAPI.AssemblyRewriters/Finders/GenericEventFinder.cs +++ /dev/null @@ -1,54 +0,0 @@ -using Mono.Cecil; -using Mono.Cecil.Cil; -using StardewModdingAPI.AssemblyRewriters.Framework; - -namespace StardewModdingAPI.AssemblyRewriters.Finders -{ - /// Finds CIL instructions that reference a given event. - public sealed class GenericEventFinder : BaseMethodFinder - { - /********* - ** Properties - *********/ - /// The full type name for which to find references. - private readonly string FullTypeName; - - /// The event name for which to find references. - private readonly string EventName; - - - /********* - ** Accessors - *********/ - /// A brief noun phrase indicating what the instruction finder matches. - public override string NounPhrase { get; } - - - /********* - ** Public methods - *********/ - /// Construct an instance. - /// The full type name for which to find references. - /// The event name for which to find references. - public GenericEventFinder(string fullTypeName, string eventName) - { - this.FullTypeName = fullTypeName; - this.EventName = eventName; - this.NounPhrase = $"obsolete {fullTypeName}.{eventName} event"; - } - - - /********* - ** Protected methods - *********/ - /// Get whether a method reference should be rewritten. - /// The IL instruction. - /// The method reference. - /// Whether the mod was compiled on a different platform. - protected override bool IsMatch(Instruction instruction, MethodReference methodRef, bool platformChanged) - { - return methodRef.DeclaringType.FullName == this.FullTypeName - && (methodRef.Name == "add_" + this.EventName || methodRef.Name == "remove_" + this.EventName); - } - } -} diff --git a/src/StardewModdingAPI.AssemblyRewriters/Finders/GenericFieldFinder.cs b/src/StardewModdingAPI.AssemblyRewriters/Finders/GenericFieldFinder.cs deleted file mode 100644 index 056422a4..00000000 --- a/src/StardewModdingAPI.AssemblyRewriters/Finders/GenericFieldFinder.cs +++ /dev/null @@ -1,61 +0,0 @@ -using Mono.Cecil; -using Mono.Cecil.Cil; -using StardewModdingAPI.AssemblyRewriters.Framework; - -namespace StardewModdingAPI.AssemblyRewriters.Finders -{ - /// Finds CIL instructions that reference a given field. - public sealed class GenericFieldFinder : BaseFieldFinder - { - /********* - ** Properties - *********/ - /// The full type name for which to find references. - private readonly string FullTypeName; - - /// The field name for which to find references. - private readonly string FieldName; - - /// Whether the field to match is static. - private readonly bool IsStatic; - - - /********* - ** Accessors - *********/ - /// A brief noun phrase indicating what the instruction finder matches. - public override string NounPhrase { get; } - - - /********* - ** Public methods - *********/ - /// Construct an instance. - /// The full type name for which to find references. - /// The field name for which to find references. - /// Whether the field to match is static. - public GenericFieldFinder(string fullTypeName, string fieldName, bool isStatic) - { - this.FullTypeName = fullTypeName; - this.FieldName = fieldName; - this.IsStatic = isStatic; - this.NounPhrase = $"obsolete {fullTypeName}.{fieldName} field"; - } - - - /********* - ** Protected methods - *********/ - /// Get whether a field reference should be rewritten. - /// The IL instruction. - /// The field reference. - /// Whether the mod was compiled on a different platform. - protected override bool IsMatch(Instruction instruction, FieldReference fieldRef, bool platformChanged) - { - return - this.IsStaticField(instruction) == this.IsStatic - && fieldRef.DeclaringType.FullName == this.FullTypeName - && fieldRef.Name == this.FieldName; - } - } -} diff --git a/src/StardewModdingAPI.AssemblyRewriters/Finders/GenericMethodFinder.cs b/src/StardewModdingAPI.AssemblyRewriters/Finders/GenericMethodFinder.cs deleted file mode 100644 index f5443558..00000000 --- a/src/StardewModdingAPI.AssemblyRewriters/Finders/GenericMethodFinder.cs +++ /dev/null @@ -1,54 +0,0 @@ -using Mono.Cecil; -using Mono.Cecil.Cil; -using StardewModdingAPI.AssemblyRewriters.Framework; - -namespace StardewModdingAPI.AssemblyRewriters.Finders -{ - /// Finds CIL instructions that reference a given method. - public sealed class GenericMethodFinder : BaseMethodFinder - { - /********* - ** Properties - *********/ - /// The full type name for which to find references. - private readonly string FullTypeName; - - /// The method name for which to find references. - private readonly string MethodName; - - - /********* - ** Accessors - *********/ - /// A brief noun phrase indicating what the instruction finder matches. - public override string NounPhrase { get; } - - - /********* - ** Public methods - *********/ - /// Construct an instance. - /// The full type name for which to find references. - /// The method name for which to find references. - public GenericMethodFinder(string fullTypeName, string methodName) - { - this.FullTypeName = fullTypeName; - this.MethodName = methodName; - this.NounPhrase = $"obsolete {fullTypeName}.{methodName} method"; - } - - - /********* - ** Protected methods - *********/ - /// Get whether a method reference should be rewritten. - /// The IL instruction. - /// The method reference. - /// Whether the mod was compiled on a different platform. - protected override bool IsMatch(Instruction instruction, MethodReference methodRef, bool platformChanged) - { - return methodRef.DeclaringType.FullName == this.FullTypeName - && methodRef.Name == this.MethodName; - } - } -} diff --git a/src/StardewModdingAPI.AssemblyRewriters/Finders/GenericTypeFinder.cs b/src/StardewModdingAPI.AssemblyRewriters/Finders/GenericTypeFinder.cs deleted file mode 100644 index 1556cc3c..00000000 --- a/src/StardewModdingAPI.AssemblyRewriters/Finders/GenericTypeFinder.cs +++ /dev/null @@ -1,64 +0,0 @@ -using System.Linq; -using Mono.Cecil; -using Mono.Cecil.Cil; - -namespace StardewModdingAPI.AssemblyRewriters.Finders -{ - /// Finds CIL instructions that reference a given type. - public sealed class GenericTypeFinder : IInstructionFinder - { - /********* - ** Accessors - *********/ - /// The full type name for which to find references. - private readonly string FullTypeName; - - - /********* - ** Accessors - *********/ - /// A brief noun phrase indicating what the instruction finder matches. - public string NounPhrase { get; } - - - /********* - ** Public methods - *********/ - /// Construct an instance. - /// The full type name to match. - public GenericTypeFinder(string fullTypeName) - { - this.FullTypeName = fullTypeName; - this.NounPhrase = $"obsolete {fullTypeName} type"; - } - - /// Get whether a CIL instruction matches. - /// The IL instruction. - /// Whether the mod was compiled on a different platform. - public bool IsMatch(Instruction instruction, bool platformChanged) - { - string fullName = this.FullTypeName; - - // field reference - if (instruction.OpCode == OpCodes.Ldfld || instruction.OpCode == OpCodes.Ldsfld || instruction.OpCode == OpCodes.Stfld || instruction.OpCode == OpCodes.Stsfld) - { - FieldReference field = (FieldReference)instruction.Operand; - return - field.DeclaringType.FullName == fullName // field on target class - || field.FieldType.FullName == fullName; // field value is target class - } - - // method reference - if (instruction.OpCode == OpCodes.Call || instruction.OpCode == OpCodes.Callvirt) - { - MethodReference method = (MethodReference)instruction.Operand; - return - method.DeclaringType.FullName == fullName // method on target class - || method.ReturnType.FullName == fullName // method returns target class - || method.Parameters.Any(p => p.ParameterType.FullName == fullName); // method parameters - } - - return false; - } - } -} diff --git a/src/StardewModdingAPI.AssemblyRewriters/Finders/MethodFinder.cs b/src/StardewModdingAPI.AssemblyRewriters/Finders/MethodFinder.cs new file mode 100644 index 00000000..6c210d68 --- /dev/null +++ b/src/StardewModdingAPI.AssemblyRewriters/Finders/MethodFinder.cs @@ -0,0 +1,54 @@ +using Mono.Cecil; +using Mono.Cecil.Cil; +using StardewModdingAPI.AssemblyRewriters.Framework; + +namespace StardewModdingAPI.AssemblyRewriters.Finders +{ + /// Finds CIL instructions that reference a given method. + public sealed class MethodFinder : BaseMethodFinder + { + /********* + ** Properties + *********/ + /// The full type name for which to find references. + private readonly string FullTypeName; + + /// The method name for which to find references. + private readonly string MethodName; + + + /********* + ** Accessors + *********/ + /// A brief noun phrase indicating what the instruction finder matches. + public override string NounPhrase { get; } + + + /********* + ** Public methods + *********/ + /// Construct an instance. + /// The full type name for which to find references. + /// The method name for which to find references. + public MethodFinder(string fullTypeName, string methodName) + { + this.FullTypeName = fullTypeName; + this.MethodName = methodName; + this.NounPhrase = $"obsolete {fullTypeName}.{methodName} method"; + } + + + /********* + ** Protected methods + *********/ + /// Get whether a method reference should be rewritten. + /// The IL instruction. + /// The method reference. + /// Whether the mod was compiled on a different platform. + protected override bool IsMatch(Instruction instruction, MethodReference methodRef, bool platformChanged) + { + return methodRef.DeclaringType.FullName == this.FullTypeName + && methodRef.Name == this.MethodName; + } + } +} diff --git a/src/StardewModdingAPI.AssemblyRewriters/Finders/TypeFinder.cs b/src/StardewModdingAPI.AssemblyRewriters/Finders/TypeFinder.cs new file mode 100644 index 00000000..ba8e7102 --- /dev/null +++ b/src/StardewModdingAPI.AssemblyRewriters/Finders/TypeFinder.cs @@ -0,0 +1,64 @@ +using System.Linq; +using Mono.Cecil; +using Mono.Cecil.Cil; + +namespace StardewModdingAPI.AssemblyRewriters.Finders +{ + /// Finds CIL instructions that reference a given type. + public sealed class TypeFinder : IInstructionFinder + { + /********* + ** Accessors + *********/ + /// The full type name for which to find references. + private readonly string FullTypeName; + + + /********* + ** Accessors + *********/ + /// A brief noun phrase indicating what the instruction finder matches. + public string NounPhrase { get; } + + + /********* + ** Public methods + *********/ + /// Construct an instance. + /// The full type name to match. + public TypeFinder(string fullTypeName) + { + this.FullTypeName = fullTypeName; + this.NounPhrase = $"obsolete {fullTypeName} type"; + } + + /// Get whether a CIL instruction matches. + /// The IL instruction. + /// Whether the mod was compiled on a different platform. + public bool IsMatch(Instruction instruction, bool platformChanged) + { + string fullName = this.FullTypeName; + + // field reference + if (instruction.OpCode == OpCodes.Ldfld || instruction.OpCode == OpCodes.Ldsfld || instruction.OpCode == OpCodes.Stfld || instruction.OpCode == OpCodes.Stsfld) + { + FieldReference field = (FieldReference)instruction.Operand; + return + field.DeclaringType.FullName == fullName // field on target class + || field.FieldType.FullName == fullName; // field value is target class + } + + // method reference + if (instruction.OpCode == OpCodes.Call || instruction.OpCode == OpCodes.Callvirt) + { + MethodReference method = (MethodReference)instruction.Operand; + return + method.DeclaringType.FullName == fullName // method on target class + || method.ReturnType.FullName == fullName // method returns target class + || method.Parameters.Any(p => p.ParameterType.FullName == fullName); // method parameters + } + + return false; + } + } +} -- cgit