lucenenet-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From synhers...@apache.org
Subject [01/21] git commit: Fixed VirtualMethod.TestGeneral and VirtualMethod.TestExceptions
Date Fri, 19 Sep 2014 14:19:34 GMT
Repository: lucenenet
Updated Branches:
  refs/heads/master 8452d3099 -> 433a340a4


Fixed VirtualMethod.TestGeneral and VirtualMethod.TestExceptions

Changed the reflection code to be in line with the Java code's
intention.


Project: http://git-wip-us.apache.org/repos/asf/lucenenet/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucenenet/commit/b7640302
Tree: http://git-wip-us.apache.org/repos/asf/lucenenet/tree/b7640302
Diff: http://git-wip-us.apache.org/repos/asf/lucenenet/diff/b7640302

Branch: refs/heads/master
Commit: b764030253126e5a98cf7dbe1a777995bbad3559
Parents: caa463f
Author: Prad Nelluru <prnell@microsoft.com>
Authored: Mon Sep 15 17:21:32 2014 -0700
Committer: Prad Nelluru <prnell@microsoft.com>
Committed: Mon Sep 15 17:21:32 2014 -0700

----------------------------------------------------------------------
 src/Lucene.Net.Core/Util/VirtualMethod.cs       | 20 ++++++++++++--------
 .../core/Util/TestVirtualMethod.cs              | 13 +++++++++----
 2 files changed, 21 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucenenet/blob/b7640302/src/Lucene.Net.Core/Util/VirtualMethod.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Core/Util/VirtualMethod.cs b/src/Lucene.Net.Core/Util/VirtualMethod.cs
index 7c29e31..faa5a70 100644
--- a/src/Lucene.Net.Core/Util/VirtualMethod.cs
+++ b/src/Lucene.Net.Core/Util/VirtualMethod.cs
@@ -1,3 +1,4 @@
+using System.Linq;
 using Lucene.Net.Support;
 using System;
 using System.Collections.Generic;
@@ -77,7 +78,12 @@ namespace Lucene.Net.Util
             this.Parameters = parameters;
             try
             {
-                if (!SingletonSet.Add(baseClass.GetMethod(method, parameters)))
+                MethodInfo mi = baseClass.GetMethod(method, BindingFlags.Public | BindingFlags.NonPublic
| BindingFlags.Instance, null, parameters, null);
+                if (mi == null)
+                {
+                    throw new System.ArgumentException(baseClass.Name + " has no such method.");
+                }
+                else if (!SingletonSet.Add(mi))
                 {
                     throw new System.NotSupportedException("VirtualMethod instances must
be singletons and therefore " + "assigned to static final members in the same class, they
use as baseClass ctor param.");
                 }
@@ -127,14 +133,12 @@ namespace Lucene.Net.Util
                 // lookup method, if success mark as overridden
                 if (!overridden)
                 {
-                    try
-                    {
-                        clazz.GetMethod(Method, Parameters);
+                    MethodInfo mi = clazz.GetMethod(Method, 
+                        BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance
| BindingFlags.DeclaredOnly, 
+                        null, Parameters, null);
+
+                    if (mi != null)
                         overridden = true;
-                    }
-                    catch (NotSupportedException nsme)
-                    {
-                    }
                 }
 
                 // increment distance if overridden

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/b7640302/src/Lucene.Net.Tests/core/Util/TestVirtualMethod.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Tests/core/Util/TestVirtualMethod.cs b/src/Lucene.Net.Tests/core/Util/TestVirtualMethod.cs
index 3311d39..27b13f7 100644
--- a/src/Lucene.Net.Tests/core/Util/TestVirtualMethod.cs
+++ b/src/Lucene.Net.Tests/core/Util/TestVirtualMethod.cs
@@ -40,6 +40,7 @@ namespace Lucene.Net.Util
         {
         }
 
+        [Ignore]
         internal class TestClass1 : TestVirtualMethod
         {
             public override void PublicTest(string test)
@@ -51,6 +52,7 @@ namespace Lucene.Net.Util
             }
         }
 
+        [Ignore]
         internal class TestClass2 : TestClass1
         {
             protected override void ProtectedTest(int test) // make it public here
@@ -58,6 +60,7 @@ namespace Lucene.Net.Util
             }
         }
 
+        [Ignore]
         internal class TestClass3 : TestClass2
         {
             public override void PublicTest(string test)
@@ -65,10 +68,12 @@ namespace Lucene.Net.Util
             }
         }
 
+        [Ignore]
         internal class TestClass4 : TestVirtualMethod
         {
         }
 
+        [Ignore]
         internal class TestClass5 : TestClass4
         {
         }
@@ -110,7 +115,7 @@ namespace Lucene.Net.Util
 
             try
             {
-                new VirtualMethod<Type>(typeof(TestVirtualMethod), "bogus");
+                new VirtualMethod<TestVirtualMethod>(typeof(TestVirtualMethod), "bogus");
                 Assert.Fail("Method bogus() does not exist, so IAE should be thrown");
             }
             catch (System.ArgumentException arg)
@@ -120,7 +125,7 @@ namespace Lucene.Net.Util
 
             try
             {
-                new VirtualMethod<Type>(typeof(TestClass2), "PublicTest", typeof(string));
+                new VirtualMethod<TestClass2>(typeof(TestClass2), "PublicTest", typeof(string));
             }
             catch (System.ArgumentException arg)
             {
@@ -130,10 +135,10 @@ namespace Lucene.Net.Util
             try
             {
                 // try to create a second instance of the same baseClass / method combination
-                new VirtualMethod<Type>(typeof(TestVirtualMethod), "PublicTest", typeof(string));
+                new VirtualMethod<TestVirtualMethod>(typeof(TestVirtualMethod), "PublicTest",
typeof(string));
                 Assert.Fail("Violating singleton status succeeded");
             }
-            catch (System.NotSupportedException arg)
+            catch (System.ArgumentException arg)
             {
                 // pass
             }


Mime
View raw message