Curl Global Community
循環インポートの解決 - Printable Version

+- Curl Global Community (https://communities.curl.com)
+-- Forum: Discussions (https://communities.curl.com/forumdisplay.php?fid=1)
+--- Forum: General Curl questions (https://communities.curl.com/forumdisplay.php?fid=2)
+--- Thread: 循環インポートの解決 (/showthread.php?tid=829)



循環インポートの解決 - umemura - 01-22-2013

自分の設計がよろしくないのが理由なのですが、
Curlで開発をしている際に、「パッケージの循環参照」の問題がでることがあります。

循環参照を解決するために、プロジェクト内のパッケージの参照関係をわかりやすくあらわす方法はありますか?




RE: 循環インポートの解決 - umemura - 03-22-2013

とりあえず、参照関係をツリーにすれば確認しやすいかもですね。



Code:
{curl 8.0 applet}
{curl-file-attributes character-encoding = "utf8"}
{applet manifest = "manifest.mcurl",
    {compiler-directives careful? = true}
}
{def parent-vbox = {VBox border-width = 2pt, border-color = "orange"}}
{def child-vbox = {VBox  border-width = 2pt, border-color = "blue"}}

{import * from COM.CURL.LIB.ENVIRONMENT}
{def applet = {get-the-applet}}
{def current-package = {get-current-package}}
{def current-manifest = {get-current-manifest}}
{define-class public PackageTreeItemLabel {inherits Frame}
  field public label:String
  {constructor public {default label:String, ...}
    set self.label = label
    {construct-super
        label,
        margin = 2px,
        {splice ...}}
  }
  field _self-highlight?:bool = false
  {getter public {self-highlight?}:bool
    {return self._self-highlight?}
  }
  {setter public {self-highlight? val:bool}:void
    set self._self-highlight? = val
    {if val then
        set self.border-color = "blue"
        set self.border-width = 1px
     else
        {unset self.border-color}
        {unset self.border-width}
    }
  }
  {setter public {parent-highlight? val:bool}:void
    {if val then
        set self.border-color = "orange"
        set self.border-width = 2px
     else
        {unset self.border-color}
        {unset self.border-width}
    }
  }
}
{define-class package PackageTreeItem {inherits DefaultTreeItem}
  {constructor package {default node:TreeNode}
    {construct-super node}
    {self.add-event-handler
        {on PointerPress do
            set self.highlight?  =true
            {if-non-null tree = self.control then
                {tree.walk-nodes
                    {proc {node:TreeNode}:bool
                        {type-switch node.node-data
                         case ptil:PackageTreeItemLabel do
                            def self-label = (self.node.node-data asa PackageTreeItemLabel).label
                            set ptil.self-highlight? = (self-label ==  ptil.label) true
                            {if ptil.self-highlight? then
                                {if-non-null parent = node.parent then
                                    {tree.expand-node parent}
                                    def parent-label = parent.node-data asa PackageTreeItemLabel
                                    set parent-label.parent-highlight? = ptil.self-highlight?
                                }
                            }
                        }
                        {return false}
                    },
                    enter-collapsed-nodes? = true
                }
            }
        }
    }
  }
}
{define-proc {make-tree-node p:Package}:#TreeNode
    let tree:#TreeNode = null
    {if-non-null prj-name =  current-manifest.name, p-name = p.name then
        ||プロジェクト名+パッケージ名になっていることが前提
        def found-index = {p-name.find-string prj-name}
        {if found-index > -1 then
            def start = found-index +  prj-name.size
            def length = p-name.size - start
            set tree = {TreeNode node-data =
                {PackageTreeItemLabel {p-name.substr start, length}}}
            {for ip in p.imported-packages do
                {if-non-null node = {make-tree-node ip} then
                    {tree.append node}
                }
            }
        }
    }
    {return tree}
}
{CommandButton
    label= "パッケージツリーの表示",
    {on Action do
        let tree:TreeNode = {TreeNode node-data = {PackageTreeItemLabel current-manifest.name asa String}}
        {for cs in current-manifest do
            {switch cs.component-type
             case "package" do
                {try
                    let p:Package =
                        {import-package
                            {ComponentSelector name = cs.name}
                        }
                    {dump p}
                    {if-non-null node = {make-tree-node p} then
                        {tree.append node}
                    }
                 catch e:Exception do
                    {tree.append {TreeNode node-data = "[" & cs.name & "]:読み込みエラー"} }
                }
            }
        }
        def v =
            {View
                width = 5in, height = 4in,
                {ScrollBox
                    hstretch? = true, vstretch? = true,
                        {TreeControl
                            data-model =
                                {TreeModel
                                    root = tree
                                },
                            tree-item-creation-proc =
                                {proc {node:TreeNode}:TreeItem
                                    {return {PackageTreeItem node}}
                                }
                        }
                }
            }
        {v.show}
    }
}