Esempio n. 1
0
        public void Test_Evaluate()
        {
            IRuntimeServices rs = RuntimeSingleton.RuntimeServices;
            Introspector i = new Introspector(rs);
            MethodInfo mi = i.GetMethod(typeof(VelocityTest), "Test_Evaluate", null);
            Assert.IsNotNull(mi, "Expected to find VelocityTest.Test_Evaluate");
            Assert.IsTrue(mi.ToString().Equals("Void Test_Evaluate()"), "method not found");

            mi = i.GetMethod(typeof(ExtendedProperties), "GetString", new Object[] {"parm1", "parm2"});
            Assert.IsNotNull(mi, "Expected to find ExtendedProperties.GetString(String, String)");
            Assert.IsTrue(mi.ToString().Equals("System.String GetString(System.String, System.String)"), "method not found");
        }
Esempio n. 2
0
        private T GetSmallestContainingIntervalWorker(int start, int length, Func <T, int, int, bool> predicate)
        {
            var result = default(T);

            if (root == null || MaxEndValue(root) < start)
            {
                return(result);
            }

            int end = start + length;

            // * our interval tree is a binary tree that is ordered by a start position.
            //
            // this method works by
            // 1. find a sub tree that has biggest "start" position that is smaller than given "start" by going down right side of a tree
            // 2. once it encounters a right sub tree that it can't go down anymore, move down to left sub tree once and try #1 again
            // 3. once it gets to the position where it can't find any smaller span (both left and
            //    right sub tree doesn't contain given span) start to check whether current node
            //    contains the given "span"
            // 4. move up the spin until it finds one that contains the "span" which should be smallest span that contains the given "span"
            // 5. if it is going up from right side, it make sure to check left side of tree first.
            using (var pooledObject = SharedPools.Default <Stack <Node> >().GetPooledObject())
            {
                var spineNodes = pooledObject.Object;

                spineNodes.Push(root);
                while (spineNodes.Count > 0)
                {
                    var currentNode = spineNodes.Peek();

                    // only goes to right if right tree contains given span
                    if (Introspector.GetStart(currentNode.Value) <= start)
                    {
                        var right = currentNode.Right;
                        if (right != null && end < MaxEndValue(right))
                        {
                            spineNodes.Push(right);
                            continue;
                        }
                    }

                    // right side, sub tree doesn't contain the given span, put current node on
                    // stack, and move down to left sub tree
                    var left = currentNode.Left;
                    if (left != null && end <= MaxEndValue(left))
                    {
                        spineNodes.Push(left);
                        continue;
                    }

                    // we reached the point, where we can't go down anymore.
                    // now, go back up to find best answer
                    while (spineNodes.Count > 0)
                    {
                        currentNode = spineNodes.Pop();

                        // check whether current node meets condition
                        if (predicate(currentNode.Value, start, length))
                        {
                            // hold onto best answer
                            if (EqualityComparer <T> .Default.Equals(result, default) ||
                                (Introspector.GetStart(result) <= Introspector.GetStart(currentNode.Value) &&
                                 Introspector.GetLength(currentNode.Value) < Introspector.GetLength(result)))
                            {
                                result = currentNode.Value;
                            }
                        }

                        // there is no parent, result we currently have is the best answer
                        if (spineNodes.Count == 0)
                        {
                            return(result);
                        }

                        var parentNode = spineNodes.Peek();

                        // if we are under left side of parent node
                        if (parentNode.Left == currentNode)
                        {
                            // go one level up again
                            continue;
                        }

                        // okay, we are under right side of parent node
                        if (parentNode.Right == currentNode)
                        {
                            // try left side of parent node if it can have better answer
                            if (parentNode.Left != null && end <= MaxEndValue(parentNode.Left))
                            {
                                // right side tree doesn't have any answer or if the right side has
                                // an answer but left side can have better answer then try left side
                                if (EqualityComparer <T> .Default.Equals(result, default) ||
                                    Introspector.GetStart(parentNode.Value) == Introspector.GetStart(currentNode.Value))
                                {
                                    // put left as new root, and break out inner loop
                                    spineNodes.Push(parentNode.Left);
                                    break;
                                }
                            }

                            // no left side, go one more level up
                            continue;
                        }
                    }
                }

                return(result);
            }
        }
Esempio n. 3
0
 public BooleanPropertyExecutor(RuntimeLogger r, Introspector i, Type clazz, String propertyName) : base(r, i, clazz, propertyName)
 {
 }
Esempio n. 4
0
 /// <param name="Log">
 /// </param>
 /// <param name="introspector">
 /// </param>
 /// <param name="clazz">
 /// </param>
 /// <param name="property">
 /// </param>
 /// <since> 1.5
 /// </since>
 public BooleanPropertyExecutor(Log log, Introspector introspector, System.Type clazz, string property)
     : base(log, introspector, clazz, property)
 {
 }
Esempio n. 5
0
        private void OutputStatement(Statement exp, Object outer, bool isArgument)
        {
            Object target     = exp.Target;
            String methodName = exp.MethodName;

            if (target == null || methodName == null)
            {
                throw new NullPointerException((target == null ? "target" : "methodName") + " should not be null");
            }

            Object[] args       = exp.Arguments;
            bool     expression = exp.GetType() == typeof(Expression);
            Object   value      = (expression) ? GetValue((Expression)exp) : null;

            String    tag        = (expression && isArgument) ? "object" : "void";
            String    attributes = "";
            ValueData d          = GetValueData(value);

            // Special cases for targets.
            if (target == outer)
            {
            }
            else if (target == typeof(Array) && methodName.Equals("newInstance"))
            {
                tag        = "array";
                attributes = attributes + " class=" + Quote(((Class)args[0]).Name);
                attributes = attributes + " length=" + Quote(args[1].ToString());
                args       = new Object[] {};
            }
            else if (target.GetType() == typeof(Class))
            {
                attributes = attributes + " class=" + Quote(((Class)target).Name);
            }
            else
            {
                d.Refs = 2;
                if (d.Name == null)
                {
                    GetValueData(target).Refs++;
                    List <Statement> statements = StatementList(target);
                    if (!statements.Contains(exp))
                    {
                        statements.Add(exp);
                    }
                    OutputValue(target, outer, false);
                }
                if (expression)
                {
                    OutputValue(value, outer, isArgument);
                }
                return;
            }
            if (expression && (d.Refs > 1))
            {
                String instanceName = NameGenerator.InstanceName(value);
                d.Name     = instanceName;
                attributes = attributes + " id=" + Quote(instanceName);
            }

            // Special cases for methods.
            if ((!expression && methodName.Equals("set") && args.Length == 2 && args[0] is Integer) || (expression && methodName.Equals("get") && args.Length == 1 && args[0] is Integer))
            {
                attributes = attributes + " index=" + Quote(args[0].ToString());
                args       = (args.Length == 1) ? new Object[] {} : new Object[] { args[1] };
            }
            else if ((!expression && methodName.StartsWith("set") && args.Length == 1) || (expression && methodName.StartsWith("get") && args.Length == 0))
            {
                if (3 < methodName.Length())
                {
                    attributes = attributes + " property=" + Quote(Introspector.Decapitalize(methodName.Substring(3)));
                }
            }
            else if (!methodName.Equals("new") && !methodName.Equals("newInstance"))
            {
                attributes = attributes + " method=" + Quote(methodName);
            }
            OutputXML(tag, attributes, value, args);
        }