From db643f5e711a1505d8b0d4839a0783227f272441 Mon Sep 17 00:00:00 2001 From: JohanLarsson Date: Mon, 5 Nov 2018 21:24:00 +0100 Subject: [PATCH 1/8] DisposableAnnotations --- .../DisposableAnnotations.csproj | 5 +++++ DisposableAnnotations/DisposeAttribute.cs | 12 ++++++++++++ DisposableAnnotations/DisposesAttribute.cs | 12 ++++++++++++ DisposableAnnotations/DontDisposeAttribute.cs | 12 ++++++++++++ IDisposableAnalyzers.sln | 6 ++++++ ValidCode/IWithAnnotations.cs | 16 ++++++++++++++++ ValidCode/ValidCode.csproj | 4 ++++ 7 files changed, 67 insertions(+) create mode 100644 DisposableAnnotations/DisposableAnnotations.csproj create mode 100644 DisposableAnnotations/DisposeAttribute.cs create mode 100644 DisposableAnnotations/DisposesAttribute.cs create mode 100644 DisposableAnnotations/DontDisposeAttribute.cs create mode 100644 ValidCode/IWithAnnotations.cs diff --git a/DisposableAnnotations/DisposableAnnotations.csproj b/DisposableAnnotations/DisposableAnnotations.csproj new file mode 100644 index 00000000..df463b7a --- /dev/null +++ b/DisposableAnnotations/DisposableAnnotations.csproj @@ -0,0 +1,5 @@ + + + netstandard1.0 + + diff --git a/DisposableAnnotations/DisposeAttribute.cs b/DisposableAnnotations/DisposeAttribute.cs new file mode 100644 index 00000000..dbc0c0d4 --- /dev/null +++ b/DisposableAnnotations/DisposeAttribute.cs @@ -0,0 +1,12 @@ +namespace DisposableAnnotations +{ + using System; + + /// + /// The return value should be disposed by caller. + /// + [AttributeUsage(AttributeTargets.ReturnValue, AllowMultiple = false, Inherited = true)] + public class DisposeAttribute : Attribute + { + } +} diff --git a/DisposableAnnotations/DisposesAttribute.cs b/DisposableAnnotations/DisposesAttribute.cs new file mode 100644 index 00000000..ab11235f --- /dev/null +++ b/DisposableAnnotations/DisposesAttribute.cs @@ -0,0 +1,12 @@ +namespace DisposableAnnotations +{ + using System; + + /// + /// The containing method owns the instance and is responsible for disposing it. + /// + [AttributeUsage(AttributeTargets.Parameter, AllowMultiple = false, Inherited = true)] + public class DisposesAttribute : Attribute + { + } +} diff --git a/DisposableAnnotations/DontDisposeAttribute.cs b/DisposableAnnotations/DontDisposeAttribute.cs new file mode 100644 index 00000000..f780058f --- /dev/null +++ b/DisposableAnnotations/DontDisposeAttribute.cs @@ -0,0 +1,12 @@ +namespace DisposableAnnotations +{ + using System; + + /// + /// The return value should not be disposed by caller. + /// + [AttributeUsage(AttributeTargets.ReturnValue, AllowMultiple = false, Inherited = true)] + public class DontDisposeAttribute : Attribute + { + } +} diff --git a/IDisposableAnalyzers.sln b/IDisposableAnalyzers.sln index c258f648..5687692a 100644 --- a/IDisposableAnalyzers.sln +++ b/IDisposableAnalyzers.sln @@ -58,6 +58,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Stubs", "Stubs\Stubs.csproj EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ValidCode", "ValidCode\ValidCode.csproj", "{C6A235B1-A780-43D5-BA1F-E31861C019F5}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DisposableAnnotations", "DisposableAnnotations\DisposableAnnotations.csproj", "{D147BB16-EB5A-4412-B501-E0DD0AFDA353}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -92,6 +94,10 @@ Global {C6A235B1-A780-43D5-BA1F-E31861C019F5}.Debug|Any CPU.Build.0 = Debug|Any CPU {C6A235B1-A780-43D5-BA1F-E31861C019F5}.Release|Any CPU.ActiveCfg = Release|Any CPU {C6A235B1-A780-43D5-BA1F-E31861C019F5}.Release|Any CPU.Build.0 = Release|Any CPU + {D147BB16-EB5A-4412-B501-E0DD0AFDA353}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {D147BB16-EB5A-4412-B501-E0DD0AFDA353}.Debug|Any CPU.Build.0 = Debug|Any CPU + {D147BB16-EB5A-4412-B501-E0DD0AFDA353}.Release|Any CPU.ActiveCfg = Release|Any CPU + {D147BB16-EB5A-4412-B501-E0DD0AFDA353}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/ValidCode/IWithAnnotations.cs b/ValidCode/IWithAnnotations.cs new file mode 100644 index 00000000..dc71a256 --- /dev/null +++ b/ValidCode/IWithAnnotations.cs @@ -0,0 +1,16 @@ +namespace ValidCode +{ + using System; + using DisposableAnnotations; + + public interface IWithAnnotations + { + [return:Dispose] + IDisposable Create(); + + [return: DontDispose] + IDisposable GetOrCreate(); + + void Add([Disposes] IDisposable disposable); + } +} diff --git a/ValidCode/ValidCode.csproj b/ValidCode/ValidCode.csproj index 0c38ebea..682e5531 100644 --- a/ValidCode/ValidCode.csproj +++ b/ValidCode/ValidCode.csproj @@ -7,4 +7,8 @@ + + + + \ No newline at end of file From c5ee579cbc10efe33c46159b81b07822ff594bc4 Mon Sep 17 00:00:00 2001 From: JohanLarsson Date: Mon, 5 Nov 2018 21:44:54 +0100 Subject: [PATCH 2/8] Rename annotation project. --- .../IDisposableAnalyzers.Test.csproj | 1 + IDisposableAnalyzers.Test/Properties/AssemblyInfo.cs | 1 + IDisposableAnalyzers.sln | 10 +++++----- .../DisposeAttribute.cs | 2 +- .../DisposesAttribute.cs | 2 +- .../DontDisposeAttribute.cs | 2 +- .../IDisposableAnnotations.csproj | 0 ValidCode/IWithAnnotations.cs | 2 +- ValidCode/ValidCode.csproj | 2 +- 9 files changed, 12 insertions(+), 10 deletions(-) rename {DisposableAnnotations => IDisposableAnnotations}/DisposeAttribute.cs (88%) rename {DisposableAnnotations => IDisposableAnnotations}/DisposesAttribute.cs (89%) rename {DisposableAnnotations => IDisposableAnnotations}/DontDisposeAttribute.cs (89%) rename DisposableAnnotations/DisposableAnnotations.csproj => IDisposableAnnotations/IDisposableAnnotations.csproj (100%) diff --git a/IDisposableAnalyzers.Test/IDisposableAnalyzers.Test.csproj b/IDisposableAnalyzers.Test/IDisposableAnalyzers.Test.csproj index 31cc076b..7ee7cacf 100644 --- a/IDisposableAnalyzers.Test/IDisposableAnalyzers.Test.csproj +++ b/IDisposableAnalyzers.Test/IDisposableAnalyzers.Test.csproj @@ -14,6 +14,7 @@ + diff --git a/IDisposableAnalyzers.Test/Properties/AssemblyInfo.cs b/IDisposableAnalyzers.Test/Properties/AssemblyInfo.cs index 7214721d..422001f7 100644 --- a/IDisposableAnalyzers.Test/Properties/AssemblyInfo.cs +++ b/IDisposableAnalyzers.Test/Properties/AssemblyInfo.cs @@ -21,4 +21,5 @@ typeof(Gu.Roslyn.AnalyzerExtensions.SyntaxTokenExt), typeof(Gu.Roslyn.CodeFixExtensions.Parse), typeof(Stubs.Extensions), + typeof(IDisposableAnnotations.DisposeAttribute), typeof(NUnit.Framework.Assert))] diff --git a/IDisposableAnalyzers.sln b/IDisposableAnalyzers.sln index 5687692a..729b1f90 100644 --- a/IDisposableAnalyzers.sln +++ b/IDisposableAnalyzers.sln @@ -58,7 +58,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Stubs", "Stubs\Stubs.csproj EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ValidCode", "ValidCode\ValidCode.csproj", "{C6A235B1-A780-43D5-BA1F-E31861C019F5}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DisposableAnnotations", "DisposableAnnotations\DisposableAnnotations.csproj", "{D147BB16-EB5A-4412-B501-E0DD0AFDA353}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "IDisposableAnnotations", "IDisposableAnnotations\IDisposableAnnotations.csproj", "{EF9E9769-BCA4-45C6-A819-21978AFA8EAC}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -94,10 +94,10 @@ Global {C6A235B1-A780-43D5-BA1F-E31861C019F5}.Debug|Any CPU.Build.0 = Debug|Any CPU {C6A235B1-A780-43D5-BA1F-E31861C019F5}.Release|Any CPU.ActiveCfg = Release|Any CPU {C6A235B1-A780-43D5-BA1F-E31861C019F5}.Release|Any CPU.Build.0 = Release|Any CPU - {D147BB16-EB5A-4412-B501-E0DD0AFDA353}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {D147BB16-EB5A-4412-B501-E0DD0AFDA353}.Debug|Any CPU.Build.0 = Debug|Any CPU - {D147BB16-EB5A-4412-B501-E0DD0AFDA353}.Release|Any CPU.ActiveCfg = Release|Any CPU - {D147BB16-EB5A-4412-B501-E0DD0AFDA353}.Release|Any CPU.Build.0 = Release|Any CPU + {EF9E9769-BCA4-45C6-A819-21978AFA8EAC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {EF9E9769-BCA4-45C6-A819-21978AFA8EAC}.Debug|Any CPU.Build.0 = Debug|Any CPU + {EF9E9769-BCA4-45C6-A819-21978AFA8EAC}.Release|Any CPU.ActiveCfg = Release|Any CPU + {EF9E9769-BCA4-45C6-A819-21978AFA8EAC}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/DisposableAnnotations/DisposeAttribute.cs b/IDisposableAnnotations/DisposeAttribute.cs similarity index 88% rename from DisposableAnnotations/DisposeAttribute.cs rename to IDisposableAnnotations/DisposeAttribute.cs index dbc0c0d4..91d9bcdb 100644 --- a/DisposableAnnotations/DisposeAttribute.cs +++ b/IDisposableAnnotations/DisposeAttribute.cs @@ -1,4 +1,4 @@ -namespace DisposableAnnotations +namespace IDisposableAnnotations { using System; diff --git a/DisposableAnnotations/DisposesAttribute.cs b/IDisposableAnnotations/DisposesAttribute.cs similarity index 89% rename from DisposableAnnotations/DisposesAttribute.cs rename to IDisposableAnnotations/DisposesAttribute.cs index ab11235f..df6b54ac 100644 --- a/DisposableAnnotations/DisposesAttribute.cs +++ b/IDisposableAnnotations/DisposesAttribute.cs @@ -1,4 +1,4 @@ -namespace DisposableAnnotations +namespace IDisposableAnnotations { using System; diff --git a/DisposableAnnotations/DontDisposeAttribute.cs b/IDisposableAnnotations/DontDisposeAttribute.cs similarity index 89% rename from DisposableAnnotations/DontDisposeAttribute.cs rename to IDisposableAnnotations/DontDisposeAttribute.cs index f780058f..a48e35d9 100644 --- a/DisposableAnnotations/DontDisposeAttribute.cs +++ b/IDisposableAnnotations/DontDisposeAttribute.cs @@ -1,4 +1,4 @@ -namespace DisposableAnnotations +namespace IDisposableAnnotations { using System; diff --git a/DisposableAnnotations/DisposableAnnotations.csproj b/IDisposableAnnotations/IDisposableAnnotations.csproj similarity index 100% rename from DisposableAnnotations/DisposableAnnotations.csproj rename to IDisposableAnnotations/IDisposableAnnotations.csproj diff --git a/ValidCode/IWithAnnotations.cs b/ValidCode/IWithAnnotations.cs index dc71a256..048e14e1 100644 --- a/ValidCode/IWithAnnotations.cs +++ b/ValidCode/IWithAnnotations.cs @@ -1,7 +1,7 @@ namespace ValidCode { using System; - using DisposableAnnotations; + using IDisposableAnnotations; public interface IWithAnnotations { diff --git a/ValidCode/ValidCode.csproj b/ValidCode/ValidCode.csproj index 682e5531..52f9bf76 100644 --- a/ValidCode/ValidCode.csproj +++ b/ValidCode/ValidCode.csproj @@ -9,6 +9,6 @@ - + \ No newline at end of file From a11f84cb66130c49b941ffc456c1098e14ad3d84 Mon Sep 17 00:00:00 2001 From: JohanLarsson Date: Mon, 5 Nov 2018 22:00:27 +0100 Subject: [PATCH 3/8] Bump version. 2.0.6.0 --- IDisposableAnalyzers/IDisposableAnalyzers.csproj | 8 +++----- IDisposableAnalyzers/paket.template | 6 ++---- RELEASE_NOTES.md | 4 ++++ 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/IDisposableAnalyzers/IDisposableAnalyzers.csproj b/IDisposableAnalyzers/IDisposableAnalyzers.csproj index 9e92e983..8175f69b 100644 --- a/IDisposableAnalyzers/IDisposableAnalyzers.csproj +++ b/IDisposableAnalyzers/IDisposableAnalyzers.csproj @@ -20,13 +20,11 @@ - 2.0.5.0 + 2.0.6.0 Johan Larsson, milleniumbug false - IDISP004 warn on explicit discard. -IDISP017 when disposing in finally. -IDISP003 when assigning in loop. - + BUGFIX: IDISP003 figure out when assigned in switch. +IDISP003 should not warn when assigning out parameter in if return. IDisposable Roslyn Diagnostic Analyzer DotnetAnalyzers BUGFIX: Handle extension methods in binary references better. diff --git a/IDisposableAnalyzers/paket.template b/IDisposableAnalyzers/paket.template index e471fe66..b4d0e36f 100644 --- a/IDisposableAnalyzers/paket.template +++ b/IDisposableAnalyzers/paket.template @@ -1,13 +1,11 @@ type project -include-referenced-projects true developmentDependency true projectUrl https://github.com/DotNetAnalyzers/IDisposableAnalyzers licenseUrl http://opensource.org/licenses/MIT releaseNotes - IDISP004 warn on explicit discard. - IDISP017 when disposing in finally. - IDISP003 when assigning in loop. + BUGFIX: IDISP003 figure out when assigned in switch. + IDISP003 should not warn when assigning out parameter in if return. excludedgroups Main diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md index 9172a35f..99ca27f5 100644 --- a/RELEASE_NOTES.md +++ b/RELEASE_NOTES.md @@ -1,3 +1,7 @@ +#### 2.0.6 +* BUGFIX: IDISP003 figure out when assigned in switch. +* IDISP003 should not warn when assigning out parameter in if return. + #### 2.0.5 * IDISP004 warn on explicit discard. * IDISP017 when disposing in finally. From 3d3249e26422b2c5cddbb611ed7bbc58dca6a2bb Mon Sep 17 00:00:00 2001 From: Johan Larsson Date: Mon, 5 Nov 2018 23:52:02 +0100 Subject: [PATCH 4/8] Rename attributes. --- IDisposableAnalyzers.Test/Properties/AssemblyInfo.cs | 2 +- IDisposableAnnotations/DisposeAttribute.cs | 12 ------------ IDisposableAnnotations/DonNotDisposeAttribute.cs | 12 ++++++++++++ IDisposableAnnotations/DontDisposeAttribute.cs | 12 ------------ IDisposableAnnotations/MustDisposeAttribute.cs | 12 ++++++++++++ ...sesAttribute.cs => TransferOwnershipAttribute.cs} | 2 +- ValidCode/IWithAnnotations.cs | 10 +++++++--- 7 files changed, 33 insertions(+), 29 deletions(-) delete mode 100644 IDisposableAnnotations/DisposeAttribute.cs create mode 100644 IDisposableAnnotations/DonNotDisposeAttribute.cs delete mode 100644 IDisposableAnnotations/DontDisposeAttribute.cs create mode 100644 IDisposableAnnotations/MustDisposeAttribute.cs rename IDisposableAnnotations/{DisposesAttribute.cs => TransferOwnershipAttribute.cs} (83%) diff --git a/IDisposableAnalyzers.Test/Properties/AssemblyInfo.cs b/IDisposableAnalyzers.Test/Properties/AssemblyInfo.cs index 422001f7..bb398b48 100644 --- a/IDisposableAnalyzers.Test/Properties/AssemblyInfo.cs +++ b/IDisposableAnalyzers.Test/Properties/AssemblyInfo.cs @@ -21,5 +21,5 @@ typeof(Gu.Roslyn.AnalyzerExtensions.SyntaxTokenExt), typeof(Gu.Roslyn.CodeFixExtensions.Parse), typeof(Stubs.Extensions), - typeof(IDisposableAnnotations.DisposeAttribute), + typeof(IDisposableAnnotations.MustDisposeAttribute), typeof(NUnit.Framework.Assert))] diff --git a/IDisposableAnnotations/DisposeAttribute.cs b/IDisposableAnnotations/DisposeAttribute.cs deleted file mode 100644 index 91d9bcdb..00000000 --- a/IDisposableAnnotations/DisposeAttribute.cs +++ /dev/null @@ -1,12 +0,0 @@ -namespace IDisposableAnnotations -{ - using System; - - /// - /// The return value should be disposed by caller. - /// - [AttributeUsage(AttributeTargets.ReturnValue, AllowMultiple = false, Inherited = true)] - public class DisposeAttribute : Attribute - { - } -} diff --git a/IDisposableAnnotations/DonNotDisposeAttribute.cs b/IDisposableAnnotations/DonNotDisposeAttribute.cs new file mode 100644 index 00000000..f8e2274f --- /dev/null +++ b/IDisposableAnnotations/DonNotDisposeAttribute.cs @@ -0,0 +1,12 @@ +namespace IDisposableAnnotations +{ + using System; + + /// + /// The return value should not be disposed by caller. + /// + [AttributeUsage(AttributeTargets.ReturnValue | AttributeTargets.Parameter, AllowMultiple = false, Inherited = true)] + public class DonNotDisposeAttribute : Attribute + { + } +} diff --git a/IDisposableAnnotations/DontDisposeAttribute.cs b/IDisposableAnnotations/DontDisposeAttribute.cs deleted file mode 100644 index a48e35d9..00000000 --- a/IDisposableAnnotations/DontDisposeAttribute.cs +++ /dev/null @@ -1,12 +0,0 @@ -namespace IDisposableAnnotations -{ - using System; - - /// - /// The return value should not be disposed by caller. - /// - [AttributeUsage(AttributeTargets.ReturnValue, AllowMultiple = false, Inherited = true)] - public class DontDisposeAttribute : Attribute - { - } -} diff --git a/IDisposableAnnotations/MustDisposeAttribute.cs b/IDisposableAnnotations/MustDisposeAttribute.cs new file mode 100644 index 00000000..f71715c0 --- /dev/null +++ b/IDisposableAnnotations/MustDisposeAttribute.cs @@ -0,0 +1,12 @@ +namespace IDisposableAnnotations +{ + using System; + + /// + /// The return value should be disposed by caller. + /// + [AttributeUsage(AttributeTargets.ReturnValue | AttributeTargets.Parameter, AllowMultiple = false, Inherited = true)] + public class MustDisposeAttribute : Attribute + { + } +} diff --git a/IDisposableAnnotations/DisposesAttribute.cs b/IDisposableAnnotations/TransferOwnershipAttribute.cs similarity index 83% rename from IDisposableAnnotations/DisposesAttribute.cs rename to IDisposableAnnotations/TransferOwnershipAttribute.cs index df6b54ac..2eb24007 100644 --- a/IDisposableAnnotations/DisposesAttribute.cs +++ b/IDisposableAnnotations/TransferOwnershipAttribute.cs @@ -6,7 +6,7 @@ namespace IDisposableAnnotations /// The containing method owns the instance and is responsible for disposing it. /// [AttributeUsage(AttributeTargets.Parameter, AllowMultiple = false, Inherited = true)] - public class DisposesAttribute : Attribute + public class TransferOwnershipAttribute : Attribute { } } diff --git a/ValidCode/IWithAnnotations.cs b/ValidCode/IWithAnnotations.cs index 048e14e1..31852d5f 100644 --- a/ValidCode/IWithAnnotations.cs +++ b/ValidCode/IWithAnnotations.cs @@ -5,12 +5,16 @@ namespace ValidCode public interface IWithAnnotations { - [return:Dispose] + [return:MustDispose] IDisposable Create(); - [return: DontDispose] + bool TryCreate([MustDispose]out IDisposable disposable); + + [return: DonNotDispose] IDisposable GetOrCreate(); - void Add([Disposes] IDisposable disposable); + bool TryGet([DonNotDispose]out IDisposable disposable); + + void Add([TransferOwnership] IDisposable disposable); } } From e0030f4e877b713f11a9bdcf7ce97702130c72e4 Mon Sep 17 00:00:00 2001 From: Johan Larsson Date: Mon, 5 Nov 2018 23:54:35 +0100 Subject: [PATCH 5/8] Formatting. --- ValidCode/IWithAnnotations.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ValidCode/IWithAnnotations.cs b/ValidCode/IWithAnnotations.cs index 31852d5f..fd388ba8 100644 --- a/ValidCode/IWithAnnotations.cs +++ b/ValidCode/IWithAnnotations.cs @@ -5,7 +5,7 @@ namespace ValidCode public interface IWithAnnotations { - [return:MustDispose] + [return: MustDispose] IDisposable Create(); bool TryCreate([MustDispose]out IDisposable disposable); From 042c52df4e2d4b1836a54c230ce71606e4374a82 Mon Sep 17 00:00:00 2001 From: Johan Larsson Date: Mon, 5 Nov 2018 23:57:25 +0100 Subject: [PATCH 6/8] Fix typo. --- .../{DonNotDisposeAttribute.cs => DoNotDisposeAttribute.cs} | 2 +- ValidCode/IWithAnnotations.cs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) rename IDisposableAnnotations/{DonNotDisposeAttribute.cs => DoNotDisposeAttribute.cs} (84%) diff --git a/IDisposableAnnotations/DonNotDisposeAttribute.cs b/IDisposableAnnotations/DoNotDisposeAttribute.cs similarity index 84% rename from IDisposableAnnotations/DonNotDisposeAttribute.cs rename to IDisposableAnnotations/DoNotDisposeAttribute.cs index f8e2274f..2b169e58 100644 --- a/IDisposableAnnotations/DonNotDisposeAttribute.cs +++ b/IDisposableAnnotations/DoNotDisposeAttribute.cs @@ -6,7 +6,7 @@ namespace IDisposableAnnotations /// The return value should not be disposed by caller. /// [AttributeUsage(AttributeTargets.ReturnValue | AttributeTargets.Parameter, AllowMultiple = false, Inherited = true)] - public class DonNotDisposeAttribute : Attribute + public class DoNotDisposeAttribute : Attribute { } } diff --git a/ValidCode/IWithAnnotations.cs b/ValidCode/IWithAnnotations.cs index fd388ba8..74419768 100644 --- a/ValidCode/IWithAnnotations.cs +++ b/ValidCode/IWithAnnotations.cs @@ -10,10 +10,10 @@ public interface IWithAnnotations bool TryCreate([MustDispose]out IDisposable disposable); - [return: DonNotDispose] + [return: DoNotDispose] IDisposable GetOrCreate(); - bool TryGet([DonNotDispose]out IDisposable disposable); + bool TryGet([DoNotDispose]out IDisposable disposable); void Add([TransferOwnership] IDisposable disposable); } From 00fb5496127116826dd09f3a8bcdce6e1ac223dc Mon Sep 17 00:00:00 2001 From: Johan Larsson Date: Tue, 6 Nov 2018 00:06:12 +0100 Subject: [PATCH 7/8] Update doc comments. --- IDisposableAnnotations/DoNotDisposeAttribute.cs | 2 +- IDisposableAnnotations/MustDisposeAttribute.cs | 2 +- IDisposableAnnotations/TransferOwnershipAttribute.cs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/IDisposableAnnotations/DoNotDisposeAttribute.cs b/IDisposableAnnotations/DoNotDisposeAttribute.cs index 2b169e58..b66a0750 100644 --- a/IDisposableAnnotations/DoNotDisposeAttribute.cs +++ b/IDisposableAnnotations/DoNotDisposeAttribute.cs @@ -3,7 +3,7 @@ namespace IDisposableAnnotations using System; /// - /// The return value should not be disposed by caller. + /// The return value must not be disposed by the caller. /// [AttributeUsage(AttributeTargets.ReturnValue | AttributeTargets.Parameter, AllowMultiple = false, Inherited = true)] public class DoNotDisposeAttribute : Attribute diff --git a/IDisposableAnnotations/MustDisposeAttribute.cs b/IDisposableAnnotations/MustDisposeAttribute.cs index f71715c0..840e4ced 100644 --- a/IDisposableAnnotations/MustDisposeAttribute.cs +++ b/IDisposableAnnotations/MustDisposeAttribute.cs @@ -3,7 +3,7 @@ namespace IDisposableAnnotations using System; /// - /// The return value should be disposed by caller. + /// The return value must be disposed by the caller. /// [AttributeUsage(AttributeTargets.ReturnValue | AttributeTargets.Parameter, AllowMultiple = false, Inherited = true)] public class MustDisposeAttribute : Attribute diff --git a/IDisposableAnnotations/TransferOwnershipAttribute.cs b/IDisposableAnnotations/TransferOwnershipAttribute.cs index 2eb24007..c43292ce 100644 --- a/IDisposableAnnotations/TransferOwnershipAttribute.cs +++ b/IDisposableAnnotations/TransferOwnershipAttribute.cs @@ -3,7 +3,7 @@ namespace IDisposableAnnotations using System; /// - /// The containing method owns the instance and is responsible for disposing it. + /// The ownership of instance is transferred and the receiver is responsible for disposing. /// [AttributeUsage(AttributeTargets.Parameter, AllowMultiple = false, Inherited = true)] public class TransferOwnershipAttribute : Attribute From 28ab9208239a7ef5a8f35344954a583e90f8e832 Mon Sep 17 00:00:00 2001 From: JohanLarsson Date: Tue, 6 Nov 2018 14:56:21 +0100 Subject: [PATCH 8/8] Rename attributes. --- IDisposableAnalyzers.Test/Properties/AssemblyInfo.cs | 2 +- ...tDisposeAttribute.cs => GivesOwnershipAttribute.cs} | 2 +- ...tDisposeAttribute.cs => KeepsOwnershipAttribute.cs} | 2 +- ...wnershipAttribute.cs => TakesOwnershipAttribute.cs} | 2 +- ValidCode/IWithAnnotations.cs | 10 +++++----- 5 files changed, 9 insertions(+), 9 deletions(-) rename IDisposableAnnotations/{MustDisposeAttribute.cs => GivesOwnershipAttribute.cs} (84%) rename IDisposableAnnotations/{DoNotDisposeAttribute.cs => KeepsOwnershipAttribute.cs} (84%) rename IDisposableAnnotations/{TransferOwnershipAttribute.cs => TakesOwnershipAttribute.cs} (83%) diff --git a/IDisposableAnalyzers.Test/Properties/AssemblyInfo.cs b/IDisposableAnalyzers.Test/Properties/AssemblyInfo.cs index bb398b48..f5a26b27 100644 --- a/IDisposableAnalyzers.Test/Properties/AssemblyInfo.cs +++ b/IDisposableAnalyzers.Test/Properties/AssemblyInfo.cs @@ -21,5 +21,5 @@ typeof(Gu.Roslyn.AnalyzerExtensions.SyntaxTokenExt), typeof(Gu.Roslyn.CodeFixExtensions.Parse), typeof(Stubs.Extensions), - typeof(IDisposableAnnotations.MustDisposeAttribute), + typeof(IDisposableAnnotations.GivesOwnershipAttribute), typeof(NUnit.Framework.Assert))] diff --git a/IDisposableAnnotations/MustDisposeAttribute.cs b/IDisposableAnnotations/GivesOwnershipAttribute.cs similarity index 84% rename from IDisposableAnnotations/MustDisposeAttribute.cs rename to IDisposableAnnotations/GivesOwnershipAttribute.cs index 840e4ced..77c8fee1 100644 --- a/IDisposableAnnotations/MustDisposeAttribute.cs +++ b/IDisposableAnnotations/GivesOwnershipAttribute.cs @@ -6,7 +6,7 @@ namespace IDisposableAnnotations /// The return value must be disposed by the caller. /// [AttributeUsage(AttributeTargets.ReturnValue | AttributeTargets.Parameter, AllowMultiple = false, Inherited = true)] - public class MustDisposeAttribute : Attribute + public class GivesOwnershipAttribute : Attribute { } } diff --git a/IDisposableAnnotations/DoNotDisposeAttribute.cs b/IDisposableAnnotations/KeepsOwnershipAttribute.cs similarity index 84% rename from IDisposableAnnotations/DoNotDisposeAttribute.cs rename to IDisposableAnnotations/KeepsOwnershipAttribute.cs index b66a0750..452ec0b5 100644 --- a/IDisposableAnnotations/DoNotDisposeAttribute.cs +++ b/IDisposableAnnotations/KeepsOwnershipAttribute.cs @@ -6,7 +6,7 @@ namespace IDisposableAnnotations /// The return value must not be disposed by the caller. /// [AttributeUsage(AttributeTargets.ReturnValue | AttributeTargets.Parameter, AllowMultiple = false, Inherited = true)] - public class DoNotDisposeAttribute : Attribute + public class KeepsOwnershipAttribute : Attribute { } } diff --git a/IDisposableAnnotations/TransferOwnershipAttribute.cs b/IDisposableAnnotations/TakesOwnershipAttribute.cs similarity index 83% rename from IDisposableAnnotations/TransferOwnershipAttribute.cs rename to IDisposableAnnotations/TakesOwnershipAttribute.cs index c43292ce..6d1f8198 100644 --- a/IDisposableAnnotations/TransferOwnershipAttribute.cs +++ b/IDisposableAnnotations/TakesOwnershipAttribute.cs @@ -6,7 +6,7 @@ namespace IDisposableAnnotations /// The ownership of instance is transferred and the receiver is responsible for disposing. /// [AttributeUsage(AttributeTargets.Parameter, AllowMultiple = false, Inherited = true)] - public class TransferOwnershipAttribute : Attribute + public class TakesOwnershipAttribute : Attribute { } } diff --git a/ValidCode/IWithAnnotations.cs b/ValidCode/IWithAnnotations.cs index 74419768..92f7faad 100644 --- a/ValidCode/IWithAnnotations.cs +++ b/ValidCode/IWithAnnotations.cs @@ -5,16 +5,16 @@ namespace ValidCode public interface IWithAnnotations { - [return: MustDispose] + [return: GivesOwnership] IDisposable Create(); - bool TryCreate([MustDispose]out IDisposable disposable); + bool TryCreate([GivesOwnership]out IDisposable disposable); - [return: DoNotDispose] + [return: KeepsOwnership] IDisposable GetOrCreate(); - bool TryGet([DoNotDispose]out IDisposable disposable); + bool TryGet([KeepsOwnership]out IDisposable disposable); - void Add([TransferOwnership] IDisposable disposable); + void Add([TakesOwnership] IDisposable disposable); } }