Exemplo n.º 1
0
        /// <summary>
        /// ノードを生成する。
        /// </summary>
        /// <param name="definition">Rubyクラス定義情報のインスタンス。</param>
        /// <param name="objectDefinitionMap">オブジェクト定義のマップ。</param>
        /// <returns>生成したツリーノード。</returns>
        public static RubyClassTreeNode Create(
            RubyClassDefinition definition,
            Dictionary<string, RubyObjectDefinition> objectDefinitionMap)
        {
            var ret = new RubyClassTreeNode();

            ret.Text = definition.FullName;
            ret.Tag = definition;

            ret.Nodes.Add(RubyBaseObjectTreeNode.Create(definition.SuperClassName, objectDefinitionMap));
            foreach (var child in definition.Children)
            {
                ret.Nodes.Add(RubyTreeNode.Create(child, objectDefinitionMap));
            }
            foreach (var constant in definition.Methods)
            {
                ret.Nodes.Add(RubyMethodTreeNode.Create(constant, objectDefinitionMap));
            }
            foreach (var constant in definition.Constants)
            {
                ret.Nodes.Add(RubyConstantTreeNode.Create(constant, objectDefinitionMap));
            }
            foreach (var accessor in definition.Accessors)
            {
                ret.Nodes.Add(RubyAccessorTreeNode.Create(accessor, objectDefinitionMap));
            }

            return ret;
        }
Exemplo n.º 2
0
        /// <summary>
        /// Ruby定義情報を作成する。
        /// </summary>
        /// <param name="engine">ScriptEngineのインスタンス。</param>
        /// <param name="fullName">オブジェクトのフル名称。</param>
        /// <param name="name">オブジェクトの名称。</param>
        /// <param name="constant">作成元のRubyオブジェクト。</param>
        /// <returns>Ruby定義情報のインスタンス。</returns>
        private static RubyDefinition Create(
            RubyHost scriptHost,
            string fullName,
            string name,
            dynamic constant)
        {
            RubyDefinition definition;

            if (constant is RubyModule)
            {
                // モジュールもしくはクラス
                var moduleConstant = (RubyModule)constant;

                if (constant is RubyClass)
                {
                    // クラス
                    var classDefinition = new RubyClassDefinition();
                    definition = classDefinition;

                    RubyClass superClass = constant.SuperClass;
                    if (superClass != null)
                    {
                        classDefinition.SuperClassName = superClass.Name;
                    }
                }
                else
                {
                    // モジュール
                    var moduleDefinition = new RubyModuleDefinition();
                    definition = moduleDefinition;
                }
                RubyObjectDefinition objectDefinition = (RubyObjectDefinition)definition;
                objectDefinition.FullName = fullName;

                // 定数・クラスを走査
                foreach (RubySymbol childSymbol in constant.constants())
                {
                    var childName = childSymbol.String.ToString();
                    var childFullName = String.Format("{0}::{1}", fullName, childName);

                    var childConstant = scriptHost.Engine.Execute(String.Format("{0}", childFullName));
                    var childDefinition = RubyDefinition.Create(scriptHost, childFullName, childName, childConstant);

                    if (childDefinition is RubyObjectDefinition)
                    {
                        objectDefinition.Children.Add(childDefinition);
                    }
                    else if (childDefinition is RubyConstantDefinition)
                    {
                        objectDefinition.Constants.Add(childDefinition);
                    }
                }

                // シングルトンメソッドを取得
                GetMethodDefinitions(moduleConstant.GetOrCreateSingletonClass(),  RubyMethodAttributes.Singleton, objectDefinition, true);

                // インスタンスメソッドを取得
                GetMethodDefinitions(moduleConstant, RubyMethodAttributes.Instance, objectDefinition, false);

                // 各要素のソート
                objectDefinition.Children.Sort((a, b) => { return String.Compare(a.FullName, b.FullName); });
                objectDefinition.Constants.Sort((a, b) => { return String.Compare(a.Name, b.Name); });
                objectDefinition.Methods.Sort((a, b) => { return String.Compare(a.Name, b.Name); });
                objectDefinition.Accessors.Sort((a, b) => { return String.Compare(a.Name, b.Name); });
            }
            else
            {
                // クラスとモジュール以外は定数とみなす
                definition = new RubyConstantDefinition();

                var constantDefinition = (RubyConstantDefinition)definition;
                constantDefinition.Value = WarlockDatabase.DecodeRubyObject(constant);
            }

            definition.Name = name;

            return definition;
        }