/// <summary> /// ノードを生成する。 /// </summary> /// <param name="definition">Ruby定数定義情報のインスタンス。</param> /// <param name="objectDefinitionMap">オブジェクト定義のマップ。</param> /// <returns>生成したツリーノード。</returns> public static RubyConstantTreeNode Create( RubyConstantDefinition definition, Dictionary<string, RubyObjectDefinition> objectDefinitionMap) { var ret = new RubyConstantTreeNode(); ret.ImageKey = "RubyConstantIcon.ico"; ret.SelectedImageKey = ret.ImageKey; ret.Tag = definition; ret.Text = String.Format( "{0} = {1}", definition.Name, WarlockDatabase.GetStringImage(definition.Value) ); return ret; }
/// <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; }