Repository: lucenenet Updated Branches: refs/heads/api-work cd52681c8 -> 7c282a491 (forced update)
Lucene.Net.TestFramework: Added exception logic for Nullable Enum convention Project: http://git-wip-us.apache.org/repos/asf/lucenenet/repo Commit: http://git-wip-us.apache.org/repos/asf/lucenenet/commit/12c4d91b Tree: http://git-wip-us.apache.org/repos/asf/lucenenet/tree/12c4d91b Diff: http://git-wip-us.apache.org/repos/asf/lucenenet/diff/12c4d91b Branch: refs/heads/api-work Commit: 12c4d91bf3d79c512a3348078de787fa889ee4ed Parents: da64d38 Author: Shad Storhaug <[email protected]> Authored: Fri Mar 10 22:56:34 2017 +0700 Committer: Shad Storhaug <[email protected]> Committed: Sat Mar 11 13:03:29 2017 +0700 ---------------------------------------------------------------------- src/Lucene.Net.Core/Lucene.Net.csproj | 1 + .../Support/ExceptionToNullableEnumConvention.cs | 13 +++++++++++++ src/Lucene.Net.TestFramework/Util/ApiScanTestBase.cs | 11 +++++++++-- .../Util/TestRuleSetupAndRestoreClassEnv.cs | 2 +- 4 files changed, 24 insertions(+), 3 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/lucenenet/blob/12c4d91b/src/Lucene.Net.Core/Lucene.Net.csproj ---------------------------------------------------------------------- diff --git a/src/Lucene.Net.Core/Lucene.Net.csproj b/src/Lucene.Net.Core/Lucene.Net.csproj index d094f47..db7adab 100644 --- a/src/Lucene.Net.Core/Lucene.Net.csproj +++ b/src/Lucene.Net.Core/Lucene.Net.csproj @@ -637,6 +637,7 @@ <Compile Include="Support\DataOutputStream.cs" /> <Compile Include="Support\Codecs\DefaultCodecFactory.cs" /> <Compile Include="Support\ExceptionToClassNameConventionAttribute.cs" /> + <Compile Include="Support\ExceptionToNullableEnumConvention.cs" /> <Compile Include="Support\FileStreamExtensions.cs" /> <Compile Include="Support\HashHelpers.cs" /> <Compile Include="Support\ICallable.cs" /> http://git-wip-us.apache.org/repos/asf/lucenenet/blob/12c4d91b/src/Lucene.Net.Core/Support/ExceptionToNullableEnumConvention.cs ---------------------------------------------------------------------- diff --git a/src/Lucene.Net.Core/Support/ExceptionToNullableEnumConvention.cs b/src/Lucene.Net.Core/Support/ExceptionToNullableEnumConvention.cs new file mode 100644 index 0000000..db046ba --- /dev/null +++ b/src/Lucene.Net.Core/Support/ExceptionToNullableEnumConvention.cs @@ -0,0 +1,13 @@ +using System; + +namespace Lucene.Net.Support +{ + /// <summary> + /// Use this attribute to make an exception to the nullable enum rule. + /// Some of these cannot be avoided. + /// </summary> + [AttributeUsage(AttributeTargets.Method | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Constructor, AllowMultiple = false)] + public class ExceptionToNullableEnumConvention : Attribute + { + } +} http://git-wip-us.apache.org/repos/asf/lucenenet/blob/12c4d91b/src/Lucene.Net.TestFramework/Util/ApiScanTestBase.cs ---------------------------------------------------------------------- diff --git a/src/Lucene.Net.TestFramework/Util/ApiScanTestBase.cs b/src/Lucene.Net.TestFramework/Util/ApiScanTestBase.cs index fc8b96b..42423c0 100644 --- a/src/Lucene.Net.TestFramework/Util/ApiScanTestBase.cs +++ b/src/Lucene.Net.TestFramework/Util/ApiScanTestBase.cs @@ -325,8 +325,9 @@ namespace Lucene.Net.Util //} Assert.IsFalse(names.Any(), names.Count() + " members that are type nullable enum detected. " + - "Nullable enum parameters, fields, methods, and properties should be eliminated, either by " + - "eliminating the logic that depends on 'null' or by adding a NOT_SET=0 state to the enum."); + "Nullable enum parameters, fields, methods, and properties should be eliminated (where possible), either by " + + "eliminating the logic that depends on 'null'. Sometimes, it makes sense to keep a nullable enum parameter. " + + "In those cases, mark the member with the [ExceptionToNullableEnumConvention] attribute."); } //[Test, LuceneNetSpecific] @@ -869,6 +870,12 @@ namespace Lucene.Net.Util continue; } + // Ignore properties, methods, and events with IgnoreNetNumericConventionAttribute + if (System.Attribute.IsDefined(member, typeof(ExceptionToNullableEnumConvention))) + { + continue; + } + if (member.DeclaringType.Equals(t.UnderlyingSystemType)) { if (member.MemberType == MemberTypes.Method && !(member.Name.StartsWith("get_") || member.Name.StartsWith("set_"))) http://git-wip-us.apache.org/repos/asf/lucenenet/blob/12c4d91b/src/Lucene.Net.TestFramework/Util/TestRuleSetupAndRestoreClassEnv.cs ---------------------------------------------------------------------- diff --git a/src/Lucene.Net.TestFramework/Util/TestRuleSetupAndRestoreClassEnv.cs b/src/Lucene.Net.TestFramework/Util/TestRuleSetupAndRestoreClassEnv.cs index 34ad216..abcae63 100644 --- a/src/Lucene.Net.TestFramework/Util/TestRuleSetupAndRestoreClassEnv.cs +++ b/src/Lucene.Net.TestFramework/Util/TestRuleSetupAndRestoreClassEnv.cs @@ -266,7 +266,7 @@ namespace Lucene.Net.Util //TimeZoneInfo.ConvertTime() // LUCENENET TODO: Everywhere TimeZoneInfo is supposed to be used, use this method to convert a dateTime object to the time zone similarity = random.NextBoolean() ? (Similarity)new DefaultSimilarity() : new RandomSimilarityProvider(random); - + // Check codec restrictions once at class level. try {
