Exemple #1
0
        //    /**
        //     * Returns the set of all characters that may be generated as
        //     * replacement text by this transliterator.
        //     */
        //    public UnicodeSet getTargetSet() {
        //        UnicodeSet set = new UnicodeSet();
        //        for (int i=0; i<trans.length; ++i) {
        //            // This is a heuristic, and not 100% reliable.
        //            set.addAll(trans[i].getTargetSet());
        //        }
        //        return set;
        //    }

        /// <summary>
        /// Implements <see cref="Transliterator.HandleTransliterate(IReplaceable, TransliterationPosition, bool)"/>.
        /// </summary>
        protected override void HandleTransliterate(IReplaceable text,
                                                    TransliterationPosition index, bool incremental)
        {
            /* Call each transliterator with the same start value and
             * initial cursor index, but with the limit index as modified
             * by preceding transliterators.  The cursor index must be
             * reset for each transliterator to give each a chance to
             * transliterate the text.  The initial cursor index is known
             * to still point to the same place after each transliterator
             * is called because each transliterator will not change the
             * text between start and the initial value of cursor.
             *
             * IMPORTANT: After the first transliterator, each subsequent
             * transliterator only gets to transliterate text committed by
             * preceding transliterators; that is, the cursor (output
             * value) of transliterator i becomes the limit (input value)
             * of transliterator i+1.  Finally, the overall limit is fixed
             * up before we return.
             *
             * Assumptions we make here:
             * (1) contextStart <= start <= limit <= contextLimit <= text.length()
             * (2) start <= start' <= limit'  ;cursor doesn't move back
             * (3) start <= limit'            ;text before cursor unchanged
             * - start' is the value of start after calling handleKT
             * - limit' is the value of limit after calling handleKT
             */

            /*
             * Example: 3 transliterators.  This example illustrates the
             * mechanics we need to implement.  C, S, and L are the contextStart,
             * start, and limit.  gl is the globalLimit.  contextLimit is
             * equal to limit throughout.
             *
             * 1. h-u, changes hex to Unicode
             *
             *    4  7  a  d  0      4  7  a
             *    abc/u0061/u    =>  abca/u
             *    C  S       L       C   S L   gl=f->a
             *
             * 2. upup, changes "x" to "XX"
             *
             *    4  7  a       4  7  a
             *    abca/u    =>  abcAA/u
             *    C  SL         C    S
             *                       L    gl=a->b
             * 3. u-h, changes Unicode to hex
             *
             *    4  7  a        4  7  a  d  0  3
             *    abcAA/u    =>  abc/u0041/u0041/u
             *    C  S L         C              S
             *                                  L   gl=b->15
             * 4. return
             *
             *    4  7  a  d  0  3
             *    abc/u0041/u0041/u
             *    C S L
             */

            if (trans.Length < 1)
            {
                index.Start = index.Limit;
                return; // Short circuit for empty compound transliterators
            }

            // compoundLimit is the limit value for the entire compound
            // operation.  We overwrite index.limit with the previous
            // index.start.  After each transliteration, we update
            // compoundLimit for insertions or deletions that have happened.
            int compoundLimit = index.Limit;

            // compoundStart is the start for the entire compound
            // operation.
            int compoundStart = index.Start;

            int delta = 0; // delta in length

            StringBuffer log = null;

            ////CLOVER:OFF
            if (DEBUG)
            {
                log = new StringBuffer("CompoundTransliterator{" + ID +
                                       (incremental ? "}i: IN=" : "}: IN="));
                UtilityExtensions.FormatInput(log, text, index);
                Console.Out.WriteLine(Utility.Escape(log.ToString()));
            }
            ////CLOVER:ON

            // Give each transliterator a crack at the run of characters.
            // See comments at the top of the method for more detail.
            for (int i = 0; i < trans.Length; ++i)
            {
                index.Start = compoundStart; // Reset start
                int limit = index.Limit;

                if (index.Start == index.Limit)
                {
                    // Short circuit for empty range
                    ////CLOVER:OFF
                    if (DEBUG)
                    {
                        Console.Out.WriteLine("CompoundTransliterator[" + i +
                                              ".." + (trans.Length - 1) +
                                              (incremental ? "]i: " : "]: ") +
                                              UtilityExtensions.FormatInput(text, index) +
                                              " (NOTHING TO DO)");
                    }
                    ////CLOVER:ON
                    break;
                }

                ////CLOVER:OFF
                if (DEBUG)
                {
                    log.Length = 0;
                    log.Append("CompoundTransliterator[" + i + "=" +
                               trans[i].ID +
                               (incremental ? "]i: " : "]: "));
                    UtilityExtensions.FormatInput(log, text, index);
                }
                ////CLOVER:ON

                trans[i].FilteredTransliterate(text, index, incremental);

                // In a properly written transliterator, start == limit after
                // handleTransliterate() returns when incremental is false.
                // Catch cases where the subclass doesn't do this, and throw
                // an exception.  (Just pinning start to limit is a bad idea,
                // because what's probably happening is that the subclass
                // isn't transliterating all the way to the end, and it should
                // in non-incremental mode.)
                if (!incremental && index.Start != index.Limit)
                {
                    throw new Exception("ERROR: Incomplete non-incremental transliteration by " + trans[i].ID);
                }

                ////CLOVER:OFF
                if (DEBUG)
                {
                    log.Append(" => ");
                    UtilityExtensions.FormatInput(log, text, index);
                    Console.Out.WriteLine(Utility.Escape(log.ToString()));
                }
                ////CLOVER:ON

                // Cumulative delta for insertions/deletions
                delta += index.Limit - limit;

                if (incremental)
                {
                    // In the incremental case, only allow subsequent
                    // transliterators to modify what has already been
                    // completely processed by prior transliterators.  In the
                    // non-incrmental case, allow each transliterator to
                    // process the entire text.
                    index.Limit = index.Start;
                }
            }

            compoundLimit += delta;

            // Start is good where it is -- where the last transliterator left
            // it.  Limit needs to be put back where it was, modulo
            // adjustments for deletions/insertions.
            index.Limit = compoundLimit;

            ////CLOVER:OFF
            if (DEBUG)
            {
                log.Length = 0;
                log.Append("CompoundTransliterator{" + ID +
                           (incremental ? "}i: OUT=" : "}: OUT="));
                UtilityExtensions.FormatInput(log, text, index);
                Console.Out.WriteLine(Utility.Escape(log.ToString()));
            }
            ////CLOVER:ON
        }
        public JObject EmitDtoJson(XmlDocSource xmlDocSource)
        {
            var schemaObj  = new JObject();
            var assemblies = xmlDocSource.Dtos.Select(a => a.Assembly).ToArray();


            schemaObj["version"] = xmlDocSource.RouteAssembly.Version;
            var schemaProperties = new JObject();

            schemaObj["properties"] = schemaProperties;

            var types     = UtilityExtensions.GetSchemaTypes(assemblies);
            var exception = new MetadataValidationException(typeof(object), "", "Errors generating meta for types", "");

            foreach (Type type in types)
            {
                try
                {
                    var typeNode   = type.GetXmlDocTypeNodeWithJSchema();
                    var jschemaXml =
                        JschemaXmlComment.CreateFromXml(typeNode.XPathSelectElement("jschema"));

                    if (jschemaXml.Exclude)
                    {
                        continue; //Skip to next type
                    }
                    var typeObj = new JObject();
                    typeObj["id"] = type.Name;

                    if (type.IsEnum)
                    {
                        RenderEnum(type, typeObj);
                    }
                    else if (type.IsClass)
                    {
                        RenderType(type, typeObj);
                    }
                    else
                    {
                        throw new NotSupportedException(type.Name + " is not supported ");
                    }

                    ApplyDescription(typeObj, typeNode);

                    if (jschemaXml.DemoValue != null)
                    {
                        typeObj["demoValue"] = jschemaXml.DemoValue;
                    }

                    schemaProperties.Add(type.Name, typeObj);
                }
                catch (MetadataValidationException ex)
                {
                    exception.AggregatedExceptions.Add(ex);
                }
            }

            if (exception.AggregatedExceptions.Count > 0)
            {
                throw exception;
            }
            return(schemaObj);
        }
        public void GetPublicNonStaticConstructors()
        {
            var results = UtilityExtensions.GetConstructors(typeof(ComplexClass));

            Assert.Equal(1, results.Count());
        }