lucenenet-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From synhers...@apache.org
Subject [01/13] git commit: Fixed reflectWith and made TestAttributes pass
Date Mon, 15 Sep 2014 22:52:52 GMT
Repository: lucenenet
Updated Branches:
  refs/heads/master 531b4af02 -> f8ab0de0b


Fixed reflectWith and made TestAttributes pass

Fixed some private fields that were renamed by the Java->C# converter
tool and caused the test to fail. Changed reflectWith to match the
proper calls to C# methods to match their Java counterparts.


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

Branch: refs/heads/master
Commit: 8db47fa3ae4f065414175781d6ba06ea1ac82148
Parents: 8010160
Author: Prad Nelluru <prnell@microsoft.com>
Authored: Tue Sep 9 13:32:53 2014 -0700
Committer: Prad Nelluru <prnell@microsoft.com>
Committed: Tue Sep 9 13:32:53 2014 -0700

----------------------------------------------------------------------
 .../Analysis/Tokenattributes/FlagsAttribute.cs  | 14 ++++++------
 .../Tokenattributes/KeywordAttribute.cs         | 14 ++++++------
 .../Analysis/Tokenattributes/OffsetAttribute.cs | 24 ++++++++++----------
 .../Tokenattributes/PayloadAttribute.cs         | 24 ++++++++++----------
 .../Tokenattributes/PositionLengthAttribute.cs  | 14 ++++++------
 src/Lucene.Net.Core/Util/Attribute.cs           |  6 +++--
 src/Lucene.Net.TestFramework/Util/TestUtil.cs   |  5 +++-
 .../Tokenattributes/TestSimpleAttributeImpl.cs  |  3 +--
 8 files changed, 54 insertions(+), 50 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucenenet/blob/8db47fa3/src/Lucene.Net.Core/Analysis/Tokenattributes/FlagsAttribute.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Core/Analysis/Tokenattributes/FlagsAttribute.cs b/src/Lucene.Net.Core/Analysis/Tokenattributes/FlagsAttribute.cs
index f9d13d2..b519b96 100644
--- a/src/Lucene.Net.Core/Analysis/Tokenattributes/FlagsAttribute.cs
+++ b/src/Lucene.Net.Core/Analysis/Tokenattributes/FlagsAttribute.cs
@@ -25,7 +25,7 @@ namespace Lucene.Net.Analysis.Tokenattributes
     /// Default implementation of <seealso cref="FlagsAttribute"/>. </summary>
     public class FlagsAttribute : Attribute, IFlagsAttribute, ICloneable
     {
-        private int Flags_Renamed = 0;
+        private int flags = 0;
 
         /// <summary>
         /// Initialize this attribute with no bits set </summary>
@@ -37,17 +37,17 @@ namespace Lucene.Net.Analysis.Tokenattributes
         {
             get
             {
-                return Flags_Renamed;
+                return flags;
             }
             set
             {
-                this.Flags_Renamed = value;
+                this.flags = value;
             }
         }
 
         public override void Clear()
         {
-            Flags_Renamed = 0;
+            flags = 0;
         }
 
         public override bool Equals(object other)
@@ -59,7 +59,7 @@ namespace Lucene.Net.Analysis.Tokenattributes
 
             if (other is FlagsAttribute)
             {
-                return ((FlagsAttribute)other).Flags_Renamed == Flags_Renamed;
+                return ((FlagsAttribute)other).flags == flags;
             }
 
             return false;
@@ -67,13 +67,13 @@ namespace Lucene.Net.Analysis.Tokenattributes
 
         public override int GetHashCode()
         {
-            return Flags_Renamed;
+            return flags;
         }
 
         public override void CopyTo(Attribute target)
         {
             FlagsAttribute t = (FlagsAttribute)target;
-            t.Flags = Flags_Renamed;
+            t.Flags = flags;
         }
     }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/8db47fa3/src/Lucene.Net.Core/Analysis/Tokenattributes/KeywordAttribute.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Core/Analysis/Tokenattributes/KeywordAttribute.cs b/src/Lucene.Net.Core/Analysis/Tokenattributes/KeywordAttribute.cs
index f29fcdc..7942d10 100644
--- a/src/Lucene.Net.Core/Analysis/Tokenattributes/KeywordAttribute.cs
+++ b/src/Lucene.Net.Core/Analysis/Tokenattributes/KeywordAttribute.cs
@@ -23,7 +23,7 @@ namespace Lucene.Net.Analysis.Tokenattributes
     /// Default implementation of <seealso cref="KeywordAttribute"/>. </summary>
     public sealed class KeywordAttribute : Attribute, IKeywordAttribute
     {
-        private bool Keyword_Renamed;
+        private bool keyword;
 
         /// <summary>
         /// Initialize this attribute with the keyword value as false. </summary>
@@ -33,18 +33,18 @@ namespace Lucene.Net.Analysis.Tokenattributes
 
         public override void Clear()
         {
-            Keyword_Renamed = false;
+            keyword = false;
         }
 
         public override void CopyTo(Attribute target)
         {
             KeywordAttribute attr = (KeywordAttribute)target;
-            attr.Keyword = Keyword_Renamed;
+            attr.Keyword = keyword;
         }
 
         public override int GetHashCode()
         {
-            return Keyword_Renamed ? 31 : 37;
+            return keyword ? 31 : 37;
         }
 
         public override bool Equals(object obj)
@@ -58,18 +58,18 @@ namespace Lucene.Net.Analysis.Tokenattributes
                 return false;
             }
             KeywordAttribute other = (KeywordAttribute)obj;
-            return Keyword_Renamed == other.Keyword_Renamed;
+            return keyword == other.keyword;
         }
 
         public bool Keyword
         {
             get
             {
-                return Keyword_Renamed;
+                return keyword;
             }
             set
             {
-                Keyword_Renamed = value;
+                keyword = value;
             }
         }
     }

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/8db47fa3/src/Lucene.Net.Core/Analysis/Tokenattributes/OffsetAttribute.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Core/Analysis/Tokenattributes/OffsetAttribute.cs b/src/Lucene.Net.Core/Analysis/Tokenattributes/OffsetAttribute.cs
index ab00547..6a4317d 100644
--- a/src/Lucene.Net.Core/Analysis/Tokenattributes/OffsetAttribute.cs
+++ b/src/Lucene.Net.Core/Analysis/Tokenattributes/OffsetAttribute.cs
@@ -25,8 +25,8 @@ namespace Lucene.Net.Analysis.Tokenattributes
     /// Default implementation of <seealso cref="OffsetAttribute"/>. </summary>
     public class OffsetAttribute : Attribute, IOffsetAttribute, ICloneable
     {
-        private int StartOffset_Renamed;
-        private int EndOffset_Renamed;
+        private int startOffset;
+        private int endOffset;
 
         /// <summary>
         /// Initialize this attribute with startOffset and endOffset of 0. </summary>
@@ -36,7 +36,7 @@ namespace Lucene.Net.Analysis.Tokenattributes
 
         public int StartOffset()
         {
-            return StartOffset_Renamed;
+            return startOffset;
         }
 
         public void SetOffset(int startOffset, int endOffset)
@@ -52,21 +52,21 @@ namespace Lucene.Net.Analysis.Tokenattributes
                 throw new System.ArgumentException("startOffset must be non-negative, and
endOffset must be >= startOffset, " + "startOffset=" + startOffset + ",endOffset=" + endOffset);
             }
 
-            this.StartOffset_Renamed = startOffset;
-            this.EndOffset_Renamed = endOffset;
+            this.startOffset = startOffset;
+            this.endOffset = endOffset;
         }
 
         public int EndOffset()
         {
-            return EndOffset_Renamed;
+            return endOffset;
         }
 
         public override void Clear()
         {
             // TODO: we could use -1 as default here?  Then we can
             // assert in setOffset...
-            StartOffset_Renamed = 0;
-            EndOffset_Renamed = 0;
+            startOffset = 0;
+            endOffset = 0;
         }
 
         public override bool Equals(object other)
@@ -79,7 +79,7 @@ namespace Lucene.Net.Analysis.Tokenattributes
             if (other is OffsetAttribute)
             {
                 OffsetAttribute o = (OffsetAttribute)other;
-                return o.StartOffset_Renamed == StartOffset_Renamed && o.EndOffset_Renamed
== EndOffset_Renamed;
+                return o.startOffset == startOffset && o.endOffset == endOffset;
             }
 
             return false;
@@ -87,15 +87,15 @@ namespace Lucene.Net.Analysis.Tokenattributes
 
         public override int GetHashCode()
         {
-            int code = StartOffset_Renamed;
-            code = code * 31 + EndOffset_Renamed;
+            int code = startOffset;
+            code = code * 31 + endOffset;
             return code;
         }
 
         public override void CopyTo(Attribute target)
         {
             OffsetAttribute t = (OffsetAttribute)target;
-            t.SetOffset(StartOffset_Renamed, EndOffset_Renamed);
+            t.SetOffset(startOffset, endOffset);
         }
     }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/8db47fa3/src/Lucene.Net.Core/Analysis/Tokenattributes/PayloadAttribute.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Core/Analysis/Tokenattributes/PayloadAttribute.cs b/src/Lucene.Net.Core/Analysis/Tokenattributes/PayloadAttribute.cs
index b69342a..c13e1f7 100644
--- a/src/Lucene.Net.Core/Analysis/Tokenattributes/PayloadAttribute.cs
+++ b/src/Lucene.Net.Core/Analysis/Tokenattributes/PayloadAttribute.cs
@@ -26,7 +26,7 @@ namespace Lucene.Net.Analysis.Tokenattributes
     /// Default implementation of <seealso cref="PayloadAttribute"/>. </summary>
     public class PayloadAttribute : Attribute, IPayloadAttribute, ICloneable
     {
-        private BytesRef Payload_Renamed;
+        private BytesRef payload;
 
         /// <summary>
         /// Initialize this attribute with no payload.
@@ -40,32 +40,32 @@ namespace Lucene.Net.Analysis.Tokenattributes
         /// </summary>
         public PayloadAttribute(BytesRef payload)
         {
-            this.Payload_Renamed = payload;
+            this.payload = payload;
         }
 
         public BytesRef Payload
         {
             get
             {
-                return this.Payload_Renamed;
+                return this.payload;
             }
             set
             {
-                this.Payload_Renamed = value;
+                this.payload = value;
             }
         }
 
         public override void Clear()
         {
-            Payload_Renamed = null;
+            payload = null;
         }
 
         public override object Clone()
         {
             PayloadAttribute clone = (PayloadAttribute)base.Clone();
-            if (Payload_Renamed != null)
+            if (payload != null)
             {
-                clone.Payload_Renamed = (BytesRef)Payload_Renamed.Clone();
+                clone.payload = (BytesRef)payload.Clone();
             }
             return clone;
         }
@@ -80,12 +80,12 @@ namespace Lucene.Net.Analysis.Tokenattributes
             if (other is PayloadAttribute)
             {
                 PayloadAttribute o = (PayloadAttribute)other;
-                if (o.Payload_Renamed == null || Payload_Renamed == null)
+                if (o.payload == null || payload == null)
                 {
-                    return o.Payload_Renamed == null && Payload_Renamed == null;
+                    return o.payload == null && payload == null;
                 }
 
-                return o.Payload_Renamed.Equals(Payload_Renamed);
+                return o.payload.Equals(payload);
             }
 
             return false;
@@ -93,13 +93,13 @@ namespace Lucene.Net.Analysis.Tokenattributes
 
         public override int GetHashCode()
         {
-            return (Payload_Renamed == null) ? 0 : Payload_Renamed.GetHashCode();
+            return (payload == null) ? 0 : payload.GetHashCode();
         }
 
         public override void CopyTo(Attribute target)
         {
             PayloadAttribute t = (PayloadAttribute)target;
-            t.Payload = (Payload_Renamed == null) ? null : (BytesRef)Payload_Renamed.Clone();
+            t.Payload = (payload == null) ? null : (BytesRef)payload.Clone();
         }
     }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/8db47fa3/src/Lucene.Net.Core/Analysis/Tokenattributes/PositionLengthAttribute.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Core/Analysis/Tokenattributes/PositionLengthAttribute.cs b/src/Lucene.Net.Core/Analysis/Tokenattributes/PositionLengthAttribute.cs
index 8f6a7e4..559ef52 100644
--- a/src/Lucene.Net.Core/Analysis/Tokenattributes/PositionLengthAttribute.cs
+++ b/src/Lucene.Net.Core/Analysis/Tokenattributes/PositionLengthAttribute.cs
@@ -25,7 +25,7 @@ namespace Lucene.Net.Analysis.Tokenattributes
     /// Default implementation of <seealso cref="PositionLengthAttribute"/>. </summary>
     public class PositionLengthAttribute : Attribute, IPositionLengthAttribute, ICloneable
     {
-        private int PositionLength_Renamed = 1;
+        private int positionLength = 1;
 
         /// <summary>
         /// Initializes this attribute with position length of 1. </summary>
@@ -41,17 +41,17 @@ namespace Lucene.Net.Analysis.Tokenattributes
                 {
                     throw new System.ArgumentException("Position length must be 1 or greater:
got " + value);
                 }
-                this.PositionLength_Renamed = value;
+                this.positionLength = value;
             }
             get
             {
-                return PositionLength_Renamed;
+                return positionLength;
             }
         }
 
         public override void Clear()
         {
-            this.PositionLength_Renamed = 1;
+            this.positionLength = 1;
         }
 
         public override bool Equals(object other)
@@ -64,7 +64,7 @@ namespace Lucene.Net.Analysis.Tokenattributes
             if (other is PositionLengthAttribute)
             {
                 PositionLengthAttribute _other = (PositionLengthAttribute)other;
-                return PositionLength_Renamed == _other.PositionLength_Renamed;
+                return positionLength == _other.positionLength;
             }
 
             return false;
@@ -72,13 +72,13 @@ namespace Lucene.Net.Analysis.Tokenattributes
 
         public override int GetHashCode()
         {
-            return PositionLength_Renamed;
+            return positionLength;
         }
 
         public override void CopyTo(Attribute target)
         {
             PositionLengthAttribute t = (PositionLengthAttribute)target;
-            t.PositionLength = PositionLength_Renamed;
+            t.PositionLength = positionLength;
         }
     }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/8db47fa3/src/Lucene.Net.Core/Util/Attribute.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Core/Util/Attribute.cs b/src/Lucene.Net.Core/Util/Attribute.cs
index 3a21ba2..6d00033 100644
--- a/src/Lucene.Net.Core/Util/Attribute.cs
+++ b/src/Lucene.Net.Core/Util/Attribute.cs
@@ -91,7 +91,7 @@ namespace Lucene.Net.Util
                 throw new NotSupportedException(clazz.Name + " implements more than one Attribute
interface, the default ReflectWith() implementation cannot handle this.");
             }
 
-            var interf = interfaces.First().GetType();
+            Type interf = (System.Type)interfaces.First().Target;
 
             /*object target = interfaces.First.Value;
 
@@ -100,7 +100,9 @@ namespace Lucene.Net.Util
 
             Type interf = target.GetType();// as Type;*/
 
-            FieldInfo[] fields = clazz.GetFields();// GetFields(BindingFlags.Instance | BindingFlags.Public);
+            //problem: the interfaces list has weak references that could have expired already
+
+            FieldInfo[] fields = clazz.GetFields(BindingFlags.Instance | BindingFlags.Public
| BindingFlags.NonPublic | BindingFlags.DeclaredOnly);
             try
             {
                 for (int i = 0; i < fields.Length; i++)

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/8db47fa3/src/Lucene.Net.TestFramework/Util/TestUtil.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.TestFramework/Util/TestUtil.cs b/src/Lucene.Net.TestFramework/Util/TestUtil.cs
index 09c1de1..29088c9 100644
--- a/src/Lucene.Net.TestFramework/Util/TestUtil.cs
+++ b/src/Lucene.Net.TestFramework/Util/TestUtil.cs
@@ -1017,7 +1017,10 @@ namespace Lucene.Net.Util
         {
             IDictionary<string, object> map = new Dictionary<string, object>();
             att.ReflectWith(new AttributeReflectorAnonymousInnerClassHelper(map));
-            Assert.AreEqual(reflectedValues, map, "Reflection does not produce same map");
+            IDictionary<string, object> newReflectedObjects = new Dictionary<string,
object>();
+            foreach (KeyValuePair<string, object> de in reflectedValues)
+                newReflectedObjects.Add(de.Key, (object)de.Value);
+            Assert.IsTrue(CollectionsHelper.DictEquals(newReflectedObjects, map), "Reflection
does not produce same map");
         }
 
         private class AttributeReflectorAnonymousInnerClassHelper : IAttributeReflector

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/8db47fa3/src/Lucene.Net.Tests/core/Analysis/Tokenattributes/TestSimpleAttributeImpl.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Tests/core/Analysis/Tokenattributes/TestSimpleAttributeImpl.cs
b/src/Lucene.Net.Tests/core/Analysis/Tokenattributes/TestSimpleAttributeImpl.cs
index 76ad185..9804b5b 100644
--- a/src/Lucene.Net.Tests/core/Analysis/Tokenattributes/TestSimpleAttributeImpl.cs
+++ b/src/Lucene.Net.Tests/core/Analysis/Tokenattributes/TestSimpleAttributeImpl.cs
@@ -31,10 +31,9 @@ namespace Lucene.Net.Analysis.Tokenattributes
     {
         // this checks using reflection API if the defaults are correct
         [Test]
-        [Ignore("ReflectWith test helper method doesn't work and needs fixing")]
         public virtual void TestAttributes()
         {
-            TestUtil.AssertAttributeReflection(new PositionIncrementAttribute(), CollectionsHelper.SingletonMap(typeof(IPositionIncrementAttribute).Name
+ "#PositionIncrement", (object)1));
+            TestUtil.AssertAttributeReflection(new PositionIncrementAttribute(), CollectionsHelper.SingletonMap(typeof(IPositionIncrementAttribute).Name
+ "#positionIncrement", (object)1));
             TestUtil.AssertAttributeReflection(new PositionLengthAttribute(), CollectionsHelper.SingletonMap(typeof(IPositionLengthAttribute).Name
+ "#positionLength", (object)1));
             TestUtil.AssertAttributeReflection(new FlagsAttribute(), CollectionsHelper.SingletonMap(typeof(IFlagsAttribute).Name
+ "#flags", (object)0));
             TestUtil.AssertAttributeReflection(new TypeAttribute(), CollectionsHelper.SingletonMap(typeof(ITypeAttribute).Name
+ "#type", (object)TypeAttribute_Fields.DEFAULT_TYPE));


Mime
View raw message