diff options
author | Jesse Plamondon-Willard <github@jplamondonw.com> | 2017-03-25 22:08:48 -0400 |
---|---|---|
committer | Jesse Plamondon-Willard <github@jplamondonw.com> | 2017-03-25 22:08:48 -0400 |
commit | 06f5e92b88fac190f94690f1580775449014e411 (patch) | |
tree | 19e9344151d3661ca38d6cda8d5577b64c6dac07 /src/StardewModdingAPI.AssemblyRewriters | |
parent | 7b641d816466fe7d9229374c175f59ee32b8dc5c (diff) | |
download | SMAPI-06f5e92b88fac190f94690f1580775449014e411.tar.gz SMAPI-06f5e92b88fac190f94690f1580775449014e411.tar.bz2 SMAPI-06f5e92b88fac190f94690f1580775449014e411.zip |
minor cleanup
Diffstat (limited to 'src/StardewModdingAPI.AssemblyRewriters')
6 files changed, 19 insertions, 28 deletions
diff --git a/src/StardewModdingAPI.AssemblyRewriters/Finders/EventFinder.cs b/src/StardewModdingAPI.AssemblyRewriters/Finders/EventFinder.cs index 9d0184c6..848e54ff 100644 --- a/src/StardewModdingAPI.AssemblyRewriters/Finders/EventFinder.cs +++ b/src/StardewModdingAPI.AssemblyRewriters/Finders/EventFinder.cs @@ -29,11 +29,12 @@ namespace StardewModdingAPI.AssemblyRewriters.Finders /// <summary>Construct an instance.</summary> /// <param name="fullTypeName">The full type name for which to find references.</param> /// <param name="eventName">The event name for which to find references.</param> - public EventFinder(string fullTypeName, string eventName) + /// <param name="nounPhrase">A brief noun phrase indicating what the instruction finder matches (or <c>null</c> to generate one).</param> + public EventFinder(string fullTypeName, string eventName, string nounPhrase = null) { this.FullTypeName = fullTypeName; this.EventName = eventName; - this.NounPhrase = $"obsolete {fullTypeName}.{eventName} event"; + this.NounPhrase = nounPhrase ?? $"{fullTypeName}.{eventName} event"; } diff --git a/src/StardewModdingAPI.AssemblyRewriters/Finders/MethodFinder.cs b/src/StardewModdingAPI.AssemblyRewriters/Finders/MethodFinder.cs index bea549ee..d174bacd 100644 --- a/src/StardewModdingAPI.AssemblyRewriters/Finders/MethodFinder.cs +++ b/src/StardewModdingAPI.AssemblyRewriters/Finders/MethodFinder.cs @@ -29,11 +29,12 @@ namespace StardewModdingAPI.AssemblyRewriters.Finders /// <summary>Construct an instance.</summary> /// <param name="fullTypeName">The full type name for which to find references.</param> /// <param name="methodName">The method name for which to find references.</param> - public MethodFinder(string fullTypeName, string methodName) + /// <param name="nounPhrase">A brief noun phrase indicating what the instruction finder matches (or <c>null</c> to generate one).</param> + public MethodFinder(string fullTypeName, string methodName, string nounPhrase = null) { this.FullTypeName = fullTypeName; this.MethodName = methodName; - this.NounPhrase = $"obsolete {fullTypeName}.{methodName} method"; + this.NounPhrase = nounPhrase ?? $"{fullTypeName}.{methodName} method"; } diff --git a/src/StardewModdingAPI.AssemblyRewriters/Finders/TypeFinder.cs b/src/StardewModdingAPI.AssemblyRewriters/Finders/TypeFinder.cs index ba8e7102..8f492d5f 100644 --- a/src/StardewModdingAPI.AssemblyRewriters/Finders/TypeFinder.cs +++ b/src/StardewModdingAPI.AssemblyRewriters/Finders/TypeFinder.cs @@ -5,7 +5,7 @@ using Mono.Cecil.Cil; namespace StardewModdingAPI.AssemblyRewriters.Finders { /// <summary>Finds CIL instructions that reference a given type.</summary> - public sealed class TypeFinder : IInstructionFinder + public class TypeFinder : IInstructionFinder { /********* ** Accessors @@ -26,10 +26,11 @@ namespace StardewModdingAPI.AssemblyRewriters.Finders *********/ /// <summary>Construct an instance.</summary> /// <param name="fullTypeName">The full type name to match.</param> - public TypeFinder(string fullTypeName) + /// <param name="nounPhrase">A brief noun phrase indicating what the instruction finder matches (or <c>null</c> to generate one).</param> + public TypeFinder(string fullTypeName, string nounPhrase = null) { this.FullTypeName = fullTypeName; - this.NounPhrase = $"obsolete {fullTypeName} type"; + this.NounPhrase = nounPhrase ?? $"{fullTypeName} type"; } /// <summary>Get whether a CIL instruction matches.</summary> @@ -40,22 +41,22 @@ namespace StardewModdingAPI.AssemblyRewriters.Finders string fullName = this.FullTypeName; // field reference - if (instruction.OpCode == OpCodes.Ldfld || instruction.OpCode == OpCodes.Ldsfld || instruction.OpCode == OpCodes.Stfld || instruction.OpCode == OpCodes.Stsfld) + FieldReference fieldRef = RewriteHelper.AsFieldReference(instruction); + if (fieldRef != null) { - FieldReference field = (FieldReference)instruction.Operand; return - field.DeclaringType.FullName == fullName // field on target class - || field.FieldType.FullName == fullName; // field value is target class + fieldRef.DeclaringType.FullName == fullName // field on target class + || fieldRef.FieldType.FullName == fullName; // field value is target class } // method reference - if (instruction.OpCode == OpCodes.Call || instruction.OpCode == OpCodes.Callvirt) + MethodReference methodRef = RewriteHelper.AsMethodReference(instruction); + if (methodRef != null) { - 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 + methodRef.DeclaringType.FullName == fullName // method on target class + || methodRef.ReturnType.FullName == fullName // method returns target class + || methodRef.Parameters.Any(p => p.ParameterType.FullName == fullName); // method parameters } return false; diff --git a/src/StardewModdingAPI.AssemblyRewriters/Rewriters/FieldReplaceRewriter.cs b/src/StardewModdingAPI.AssemblyRewriters/Rewriters/FieldReplaceRewriter.cs index a715e07b..ffd22e7c 100644 --- a/src/StardewModdingAPI.AssemblyRewriters/Rewriters/FieldReplaceRewriter.cs +++ b/src/StardewModdingAPI.AssemblyRewriters/Rewriters/FieldReplaceRewriter.cs @@ -34,10 +34,6 @@ namespace StardewModdingAPI.AssemblyRewriters.Rewriters this.ToFieldName = toFieldName; } - - /********* - ** Protected methods - *********/ /// <summary>Rewrite a CIL instruction for compatibility.</summary> /// <param name="module">The module being rewritten.</param> /// <param name="cil">The CIL rewriter.</param> diff --git a/src/StardewModdingAPI.AssemblyRewriters/Rewriters/FieldToPropertyRewriter.cs b/src/StardewModdingAPI.AssemblyRewriters/Rewriters/FieldToPropertyRewriter.cs index 62e24559..f2f99cc1 100644 --- a/src/StardewModdingAPI.AssemblyRewriters/Rewriters/FieldToPropertyRewriter.cs +++ b/src/StardewModdingAPI.AssemblyRewriters/Rewriters/FieldToPropertyRewriter.cs @@ -32,10 +32,6 @@ namespace StardewModdingAPI.AssemblyRewriters.Rewriters this.FieldName = fieldName; } - - /********* - ** Protected methods - *********/ /// <summary>Rewrite a CIL instruction for compatibility.</summary> /// <param name="module">The module being rewritten.</param> /// <param name="cil">The CIL rewriter.</param> diff --git a/src/StardewModdingAPI.AssemblyRewriters/Rewriters/MethodParentRewriter.cs b/src/StardewModdingAPI.AssemblyRewriters/Rewriters/MethodParentRewriter.cs index 9b895056..24d4dff9 100644 --- a/src/StardewModdingAPI.AssemblyRewriters/Rewriters/MethodParentRewriter.cs +++ b/src/StardewModdingAPI.AssemblyRewriters/Rewriters/MethodParentRewriter.cs @@ -43,10 +43,6 @@ namespace StardewModdingAPI.AssemblyRewriters.Rewriters this.OnlyIfPlatformChanged = onlyIfPlatformChanged; } - - /********* - ** Protected methods - *********/ /// <summary>Get whether a CIL instruction matches.</summary> /// <param name="instruction">The IL instruction.</param> /// <param name="platformChanged">Whether the mod was compiled on a different platform.</param> |