예제 #1
0
 public override void ReflectWith(IAttributeReflector reflector)
 {
     FillBytesRef();
     reflector.Reflect(typeof(ITermToBytesRefAttribute), "bytes", BytesRef.DeepCopyOf(_bytes));
     reflector.Reflect(typeof(INumericTermAttribute), "shift", Shift);
     reflector.Reflect(typeof(INumericTermAttribute), "rawValue", RawValue);
     reflector.Reflect(typeof(INumericTermAttribute), "valueSize", ValueSize);
 }
예제 #2
0
        public override void ReflectWith(IAttributeReflector reflector)
        {
            string partOfSpeech   = GetPartOfSpeech();
            string partOfSpeechEN = partOfSpeech is null ? null : ToStringUtil.GetPOSTranslation(partOfSpeech);

            reflector.Reflect <IPartOfSpeechAttribute>("partOfSpeech", partOfSpeech);
            reflector.Reflect <IPartOfSpeechAttribute>("partOfSpeech (en)", partOfSpeechEN);
        }
예제 #3
0
        public override void ReflectWith(IAttributeReflector reflector)
        {
            string reading         = GetReading();
            string readingEN       = reading is null ? null : ToStringUtil.GetRomanization(reading);
            string pronunciation   = GetPronunciation();
            string pronunciationEN = pronunciation is null ? null : ToStringUtil.GetRomanization(pronunciation);

            reflector.Reflect <IReadingAttribute>("reading", reading);
            reflector.Reflect <IReadingAttribute>("reading (en)", readingEN);
            reflector.Reflect <IReadingAttribute>("pronunciation", pronunciation);
            reflector.Reflect <IReadingAttribute>("pronunciation (en)", pronunciationEN);
        }
예제 #4
0
        public override void ReflectWith(IAttributeReflector reflector)
        {
            string type   = GetInflectionType();
            string typeEN = type is null ? null : ToStringUtil.GetInflectionTypeTranslation(type);

            reflector.Reflect <IInflectionAttribute>("inflectionType", type);
            reflector.Reflect <IInflectionAttribute>("inflectionType (en)", typeEN);
            string form   = GetInflectionForm();
            string formEN = form is null ? null : ToStringUtil.GetInflectedFormTranslation(form);

            reflector.Reflect <IInflectionAttribute>("inflectionForm", form);
            reflector.Reflect <IInflectionAttribute>("inflectionForm (en)", formEN);
        }
예제 #5
0
        /// <summary>
        /// This method is for introspection of attributes, it should simply
        /// add the key/values this attribute holds to the given <see cref="IAttributeReflector"/>.
        ///
        /// <para/>The default implementation calls <see cref="IAttributeReflector.Reflect(Type, string, object)"/> for all
        /// non-static fields from the implementing class, using the field name as key
        /// and the field value as value. The <see cref="IAttribute"/> class is also determined by Reflection.
        /// Please note that the default implementation can only handle single-Attribute
        /// implementations.
        ///
        /// <para/>Custom implementations look like this (e.g. for a combined attribute implementation):
        /// <code>
        ///     public void ReflectWith(IAttributeReflector reflector)
        ///     {
        ///         reflector.Reflect(typeof(ICharTermAttribute), "term", GetTerm());
        ///         reflector.Reflect(typeof(IPositionIncrementAttribute), "positionIncrement", GetPositionIncrement());
        ///     }
        /// </code>
        ///
        /// <para/>If you implement this method, make sure that for each invocation, the same set of <see cref="IAttribute"/>
        /// interfaces and keys are passed to <see cref="IAttributeReflector.Reflect(Type, string, object)"/> in the same order, but possibly
        /// different values. So don't automatically exclude e.g. <c>null</c> properties!
        /// </summary>
        /// <seealso cref="ReflectAsString(bool)"/>
        public virtual void ReflectWith(IAttributeReflector reflector) // LUCENENET NOTE: This method was abstract in Lucene
        {
            Type clazz = this.GetType();
            LinkedList <WeakReference <Type> > interfaces = AttributeSource.GetAttributeInterfaces(clazz);

            if (interfaces.Count != 1)
            {
                throw UnsupportedOperationException.Create(clazz.Name + " implements more than one Attribute interface, the default ReflectWith() implementation cannot handle this.");
            }

            interfaces.First.Value.TryGetTarget(out Type interf);

            //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++)
                {
                    FieldInfo f = fields[i];
                    if (f.IsStatic)
                    {
                        continue;
                    }
                    reflector.Reflect(interf, f.Name, f.GetValue(this));
                }
            }
            catch (Exception e) when(e.IsIllegalAccessException())
            {
                // this should never happen, because we're just accessing fields
                // from 'this'
                throw RuntimeException.Create(e);
            }
        }
예제 #6
0
        /// <summary>
        /// This method is for introspection of attributes, it should simply
        /// add the key/values this attribute holds to the given <see cref="IAttributeReflector"/>.
        ///
        /// <para/>The default implementation calls <see cref="IAttributeReflector.Reflect(Type, string, object)"/> for all
        /// non-static fields from the implementing class, using the field name as key
        /// and the field value as value. The <see cref="IAttribute"/> class is also determined by Reflection.
        /// Please note that the default implementation can only handle single-Attribute
        /// implementations.
        ///
        /// <para/>Custom implementations look like this (e.g. for a combined attribute implementation):
        /// <code>
        ///     public void ReflectWith(IAttributeReflector reflector)
        ///     {
        ///         reflector.Reflect(typeof(ICharTermAttribute), "term", GetTerm());
        ///         reflector.Reflect(typeof(IPositionIncrementAttribute), "positionIncrement", GetPositionIncrement());
        ///     }
        /// </code>
        ///
        /// <para/>If you implement this method, make sure that for each invocation, the same set of <see cref="IAttribute"/>
        /// interfaces and keys are passed to <see cref="IAttributeReflector.Reflect(Type, string, object)"/> in the same order, but possibly
        /// different values. So don't automatically exclude e.g. <c>null</c> properties!
        /// </summary>
        /// <seealso cref="ReflectAsString(bool)"/>
        public virtual void ReflectWith(IAttributeReflector reflector) // LUCENENET NOTE: This method was abstract in Lucene
        {
            Type clazz = this.GetType();
            LinkedList <WeakReference <Type> > interfaces = AttributeSource.GetAttributeInterfaces(clazz);

            if (interfaces.Count != 1)
            {
                throw new NotSupportedException(clazz.Name + " implements more than one Attribute interface, the default ReflectWith() implementation cannot handle this.");
            }

            interfaces.First.Value.TryGetTarget(out Type interf);

            //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++)
                {
                    FieldInfo f = fields[i];
                    if (f.IsStatic)
                    {
                        continue;
                    }
                    reflector.Reflect(interf, f.Name, f.GetValue(this));
                }
            }
            catch (MemberAccessException e)
            {
                throw new Exception(e.ToString(), e);
            }
        }
예제 #7
0
        /// <summary>
        /// this method is for introspection of attributes, it should simply
        /// add the key/values this attribute holds to the given <seealso cref="AttributeReflector"/>.
        ///
        /// <p>The default implementation calls <seealso cref="AttributeReflector#reflect"/> for all
        /// non-static fields from the implementing class, using the field name as key
        /// and the field value as value. The Attribute class is also determined by reflection.
        /// Please note that the default implementation can only handle single-Attribute
        /// implementations.
        ///
        /// <p>Custom implementations look like this (e.g. for a combined attribute implementation):
        /// <pre class="prettyprint">
        ///   public void reflectWith(AttributeReflector reflector) {
        ///     reflector.reflect(CharTermAttribute.class, "term", term());
        ///     reflector.reflect(PositionIncrementAttribute.class, "positionIncrement", getPositionIncrement());
        ///   }
        /// </pre>
        ///
        /// <p>If you implement this method, make sure that for each invocation, the same set of <seealso cref="Attribute"/>
        /// interfaces and keys are passed to <seealso cref="AttributeReflector#reflect"/> in the same order, but possibly
        /// different values. So don't automatically exclude e.g. {@code null} properties!
        /// </summary>
        /// <seealso cref= #reflectAsString(boolean) </seealso>
        public virtual void ReflectWith(IAttributeReflector reflector)
        {
            Type clazz = this.GetType();
            LinkedList <WeakReference> interfaces = AttributeSource.GetAttributeInterfaces(clazz);

            if (interfaces.Count != 1)
            {
                throw new System.NotSupportedException(clazz.Name + " implements more than one Attribute interface, the default reflectWith() implementation cannot handle this.");
            }
            //LUCENE-TODO unsure about GetType()
            Type interf = (Type)interfaces.First.Value.GetType();

            FieldInfo[] fields = clazz.GetFields(BindingFlags.Instance | BindingFlags.Public);
            try
            {
                for (int i = 0; i < fields.Length; i++)
                {
                    FieldInfo f = fields[i];
                    if (f.IsStatic)
                    {
                        continue;
                    }
                    reflector.Reflect(interf, f.Name, f.GetValue(this));
                }
            }
            catch (Exception)
            {
                // this should never happen, because we're just accessing fields
                // from 'this'
                throw new Exception("Unknown Error");
            }
        }
예제 #8
0
        public override void ReflectWith(IAttributeReflector reflector)
        {
            // when wordbreaking CJK, we use the 15924 code Japanese (Han+Hiragana+Katakana) to
            // mark runs of Chinese/Japanese. our use is correct (as for chinese Han is a subset),
            // but this is just to help prevent confusion.
            string name = code == UScript.Japanese ? "Chinese/Japanese" : GetName();

            reflector.Reflect <IScriptAttribute>("script", name);
        }
예제 #9
0
 public override void ReflectWith(IAttributeReflector reflector)
 {
     base.ReflectWith(reflector);
     reflector.Reflect(typeof(IOffsetAttribute), "startOffset", startOffset);
     reflector.Reflect(typeof(IOffsetAttribute), "endOffset", endOffset);
     reflector.Reflect(typeof(IPositionIncrementAttribute), "positionIncrement", positionIncrement);
     reflector.Reflect(typeof(IPayloadAttribute), "payload", payload);
     reflector.Reflect(typeof(IFlagsAttribute), "flags", flags);
     reflector.Reflect(typeof(ITypeAttribute), "type", type);
 }
예제 #10
0
        public virtual void ReflectWith(IAttributeReflector reflector)
        {
            Type clazz = this.GetType();
            LinkedList <WeakReference> interfaces = AttributeSource.GetAttributeInterfaces(clazz);

            if (interfaces.Count != 1)
            {
                throw new NotSupportedException(clazz.Name + " implements more than one Attribute interface, the default ReflectWith() implementation cannot handle this.");
            }

            Type interf = (System.Type)interfaces.First().Target;

            /*object target = interfaces.First.Value;
             *
             * if (target == null)
             *  return;
             *
             * Type interf = target.GetType();// as Type;*/

            //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++)
                {
                    FieldInfo f = fields[i];
                    if (f.IsStatic)
                    {
                        continue;
                    }
                    reflector.Reflect(interf, f.Name, f.GetValue(this));
                }
            }
            catch (UnauthorizedAccessException uae)
            {
                throw new Exception(uae.Message, uae);
            }
        }
예제 #11
0
 public override void ReflectWith(IAttributeReflector reflector)
 {
     reflector.Reflect(typeof(ICharTermAttribute), "term", ToString());
     FillBytesRef();
     reflector.Reflect(typeof(ITermToBytesRefAttribute), "bytes", BytesRef.DeepCopyOf(Bytes));
 }
예제 #12
0
 public override void ReflectWith(IAttributeReflector reflector)
 {
     reflector.Reflect(typeof(BaseFormAttribute), "baseForm", GetBaseForm());
 }
예제 #13
0
 public override void ReflectWith(IAttributeReflector reflector)
 {
     reflector.Reflect(typeof(ICharTermAttribute), "term", ToString());
     FillBytesRef();
     reflector.Reflect(typeof(ITermToBytesRefAttribute), "bytes", BytesRef.DeepCopyOf(Bytes));
 }