{"action":"created","comment":{"url":"https://api.github.com/repos/broadinstitute/cromwell/pulls/comments/37201677","id":37201677,"diff_hunk":"@@ -1,14 +1,168 @@\n package cromwell.binding\n \n+import cromwell.binding.AstTools.AstNodeName\n+import cromwell.parser.WdlParser.{AstList, Ast, AstNode}\n+import scala.collection.JavaConverters._\n+\n+\n+object Scope {\n+\n+  /**\n+   * Utility class to generate a ScopeTree from an Ast.\n+   */\n+  private class ScopeTreeGenerator {\n+\n+    /* Keep track of the # of created Scatter nodes. */\n+    var scatterCount: Int = 0\n+\n+  /*\n+  * Retrieve the list of AstNodes from the AST body.\n+  * Return empty seq if body is null or is not a list.\n+  */\n+    private def getChildrenList(ast: Ast): Seq[AstNode] = {\n+      val body: AstNode = ast.getAttribute(\"body\")\n+      if(body == null) Seq.empty\n+      else {\n+        body match {\n+          case list: AstList => list.asScala.toVector\n+          case _ => Seq.empty\n+        }\n+      }\n+    }\n+\n+    /**\n+     * Generate recursively all descendant Scopes for the workflow.\n+     * Should only be called during apply with a root Ast\n+     * @param node current working node\n+     * @param namespaces namespaces\n+     * @param tasks tasks\n+     * @param wdlSyntaxErrorFormatter formatter\n+     * @return Some(instance of Scope) if the node has a Scope equivalent, None otherwise\n+     */\n+    def generateScopeTree(node: AstNode, namespaces: Seq[WdlNamespace], tasks: Seq[Task], wdlSyntaxErrorFormatter: WdlSyntaxErrorFormatter): Option[Scope] = {\n+      node match {\n+          //WORKFLOW\n+        case w: Ast if w.getName.equals(AstNodeName.Workflow) =>\n+          val workflowChildren = getChildrenList(w) flatMap (generateScopeTree(_, namespaces, tasks, wdlSyntaxErrorFormatter))\n+          val workflow: Workflow = Workflow(w, wdlSyntaxErrorFormatter)\n+          workflow.setChildren(workflowChildren)\n+          Some(workflow)\n+\n+          //CALL\n+        case c: Ast if c.getName.equals(AstNodeName.Call) => Some(Call(c, namespaces, tasks, wdlSyntaxErrorFormatter))\n+\n+          //SCATTER\n+        case s: Ast if s.getName.equals(AstNodeName.Scatter) =>\n+          // Need to create the Scatter before generating its children to have the correct index layout order\n+          val scatter = Scatter(s, scatterCount)\n+          scatterCount += 1\n+          val scatterChildren = getChildrenList(s) flatMap (generateScopeTree(_, namespaces, tasks, wdlSyntaxErrorFormatter))\n+          scatter.setChildren(scatterChildren)\n+          Some(scatter)\n+\n+        /* Cases need to be added here to support new scopes */\n+        case _ => None\n+      }\n+    }\n+  }\n+\n+  /**\n+   * Generate a Scope Tree from an Ast Node.\n+   * Node must match a Scope (currently: Workflow, Scatter or Scope)\n+   * @param node node to build tree from\n+   * @param namespaces namespaces used\n+   * @param tasks tasks\n+   * @param wdlSyntaxErrorFormatter wdl formatter\n+   * @throws UnsupportedOperationException if node does not match any supported Scopes\n+   * @return generated Scope Tree.\n+   */\n+  def generateTree(node: AstNode, namespaces: Seq[WdlNamespace], tasks: Seq[Task], wdlSyntaxErrorFormatter: WdlSyntaxErrorFormatter): Scope = {\n+    new ScopeTreeGenerator().generateScopeTree(node, namespaces, tasks, wdlSyntaxErrorFormatter)\n+    .getOrElse(throw new UnsupportedOperationException(\"Input node cannot be instantiated as a Scope\"))\n+  }\n+  \n+  /**\n+   * Helper method to collect Calls from a Seq of Scopes. \n+   * /!\\ NON-RECURSIVE.","path":"src/main/scala/cromwell/binding/Scope.scala","position":86,"original_position":86,"commit_id":"9bad58b098acc6f5047d608b8e74847d08657336","original_commit_id":"9bad58b098acc6f5047d608b8e74847d08657336","user":{"login":"mcovarr","id":10790523,"avatar_url":"https://avatars.githubusercontent.com/u/10790523?v=3","gravatar_id":"","url":"https://api.github.com/users/mcovarr","html_url":"https://github.com/mcovarr","followers_url":"https://api.github.com/users/mcovarr/followers","following_url":"https://api.github.com/users/mcovarr/following{/other_user}","gists_url":"https://api.github.com/users/mcovarr/gists{/gist_id}","starred_url":"https://api.github.com/users/mcovarr/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mcovarr/subscriptions","organizations_url":"https://api.github.com/users/mcovarr/orgs","repos_url":"https://api.github.com/users/mcovarr/repos","events_url":"https://api.github.com/users/mcovarr/events{/privacy}","received_events_url":"https://api.github.com/users/mcovarr/received_events","type":"User","site_admin":false},"body":":smile: ","created_at":"2015-08-17T15:46:13Z","updated_at":"2015-08-17T15:46:13Z","html_url":"https://github.com/broadinstitute/cromwell/pull/138#discussion_r37201677","pull_request_url":"https://api.github.com/repos/broadinstitute/cromwell/pulls/138","_links":{"self":{"href":"https://api.github.com/repos/broadinstitute/cromwell/pulls/comments/37201677"},"html":{"href":"https://github.com/broadinstitute/cromwell/pull/138#discussion_r37201677"},"pull_request":{"href":"https://api.github.com/repos/broadinstitute/cromwell/pulls/138"}}},"pull_request":{"url":"https://api.github.com/repos/broadinstitute/cromwell/pulls/138","id":42593305,"html_url":"https://github.com/broadinstitute/cromwell/pull/138","diff_url":"https://github.com/broadinstitute/cromwell/pull/138.diff","patch_url":"https://github.com/broadinstitute/cromwell/pull/138.patch","issue_url":"https://api.github.com/repos/broadinstitute/cromwell/issues/138","number":138,"state":"open","locked":false,"title":"Scatter support","user":{"login":"Horneth","id":2978948,"avatar_url":"https://avatars.githubusercontent.com/u/2978948?v=3","gravatar_id":"","url":"https://api.github.com/users/Horneth","html_url":"https://github.com/Horneth","followers_url":"https://api.github.com/users/Horneth/followers","following_url":"https://api.github.com/users/Horneth/following{/other_user}","gists_url":"https://api.github.com/users/Horneth/gists{/gist_id}","starred_url":"https://api.github.com/users/Horneth/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Horneth/subscriptions","organizations_url":"https://api.github.com/users/Horneth/orgs","repos_url":"https://api.github.com/users/Horneth/repos","events_url":"https://api.github.com/users/Horneth/events{/privacy}","received_events_url":"https://api.github.com/users/Horneth/received_events","type":"User","site_admin":false},"body":"","created_at":"2015-08-17T14:23:52Z","updated_at":"2015-08-17T15:46:13Z","closed_at":null,"merged_at":null,"merge_commit_sha":"e0b30fe148ab808889680e5316aeabba0b8611c5","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/broadinstitute/cromwell/pulls/138/commits","review_comments_url":"https://api.github.com/repos/broadinstitute/cromwell/pulls/138/comments","review_comment_url":"https://api.github.com/repos/broadinstitute/cromwell/pulls/comments{/number}","comments_url":"https://api.github.com/repos/broadinstitute/cromwell/issues/138/comments","statuses_url":"https://api.github.com/repos/broadinstitute/cromwell/statuses/9bad58b098acc6f5047d608b8e74847d08657336","head":{"label":"broadinstitute:tj_UpdateWDLNSforScatter","ref":"tj_UpdateWDLNSforScatter","sha":"9bad58b098acc6f5047d608b8e74847d08657336","user":{"login":"broadinstitute","id":393552,"avatar_url":"https://avatars.githubusercontent.com/u/393552?v=3","gravatar_id":"","url":"https://api.github.com/users/broadinstitute","html_url":"https://github.com/broadinstitute","followers_url":"https://api.github.com/users/broadinstitute/followers","following_url":"https://api.github.com/users/broadinstitute/following{/other_user}","gists_url":"https://api.github.com/users/broadinstitute/gists{/gist_id}","starred_url":"https://api.github.com/users/broadinstitute/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/broadinstitute/subscriptions","organizations_url":"https://api.github.com/users/broadinstitute/orgs","repos_url":"https://api.github.com/users/broadinstitute/repos","events_url":"https://api.github.com/users/broadinstitute/events{/privacy}","received_events_url":"https://api.github.com/users/broadinstitute/received_events","type":"Organization","site_admin":false},"repo":{"id":34136406,"name":"cromwell","full_name":"broadinstitute/cromwell","owner":{"login":"broadinstitute","id":393552,"avatar_url":"https://avatars.githubusercontent.com/u/393552?v=3","gravatar_id":"","url":"https://api.github.com/users/broadinstitute","html_url":"https://github.com/broadinstitute","followers_url":"https://api.github.com/users/broadinstitute/followers","following_url":"https://api.github.com/users/broadinstitute/following{/other_user}","gists_url":"https://api.github.com/users/broadinstitute/gists{/gist_id}","starred_url":"https://api.github.com/users/broadinstitute/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/broadinstitute/subscriptions","organizations_url":"https://api.github.com/users/broadinstitute/orgs","repos_url":"https://api.github.com/users/broadinstitute/repos","events_url":"https://api.github.com/users/broadinstitute/events{/privacy}","received_events_url":"https://api.github.com/users/broadinstitute/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/broadinstitute/cromwell","description":"Workflow Execution Engine using WDL","fork":false,"url":"https://api.github.com/repos/broadinstitute/cromwell","forks_url":"https://api.github.com/repos/broadinstitute/cromwell/forks","keys_url":"https://api.github.com/repos/broadinstitute/cromwell/keys{/key_id}","collaborators_url":"https://api.github.com/repos/broadinstitute/cromwell/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/broadinstitute/cromwell/teams","hooks_url":"https://api.github.com/repos/broadinstitute/cromwell/hooks","issue_events_url":"https://api.github.com/repos/broadinstitute/cromwell/issues/events{/number}","events_url":"https://api.github.com/repos/broadinstitute/cromwell/events","assignees_url":"https://api.github.com/repos/broadinstitute/cromwell/assignees{/user}","branches_url":"https://api.github.com/repos/broadinstitute/cromwell/branches{/branch}","tags_url":"https://api.github.com/repos/broadinstitute/cromwell/tags","blobs_url":"https://api.github.com/repos/broadinstitute/cromwell/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/broadinstitute/cromwell/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/broadinstitute/cromwell/git/refs{/sha}","trees_url":"https://api.github.com/repos/broadinstitute/cromwell/git/trees{/sha}","statuses_url":"https://api.github.com/repos/broadinstitute/cromwell/statuses/{sha}","languages_url":"https://api.github.com/repos/broadinstitute/cromwell/languages","stargazers_url":"https://api.github.com/repos/broadinstitute/cromwell/stargazers","contributors_url":"https://api.github.com/repos/broadinstitute/cromwell/contributors","subscribers_url":"https://api.github.com/repos/broadinstitute/cromwell/subscribers","subscription_url":"https://api.github.com/repos/broadinstitute/cromwell/subscription","commits_url":"https://api.github.com/repos/broadinstitute/cromwell/commits{/sha}","git_commits_url":"https://api.github.com/repos/broadinstitute/cromwell/git/commits{/sha}","comments_url":"https://api.github.com/repos/broadinstitute/cromwell/comments{/number}","issue_comment_url":"https://api.github.com/repos/broadinstitute/cromwell/issues/comments{/number}","contents_url":"https://api.github.com/repos/broadinstitute/cromwell/contents/{+path}","compare_url":"https://api.github.com/repos/broadinstitute/cromwell/compare/{base}...{head}","merges_url":"https://api.github.com/repos/broadinstitute/cromwell/merges","archive_url":"https://api.github.com/repos/broadinstitute/cromwell/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/broadinstitute/cromwell/downloads","issues_url":"https://api.github.com/repos/broadinstitute/cromwell/issues{/number}","pulls_url":"https://api.github.com/repos/broadinstitute/cromwell/pulls{/number}","milestones_url":"https://api.github.com/repos/broadinstitute/cromwell/milestones{/number}","notifications_url":"https://api.github.com/repos/broadinstitute/cromwell/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/broadinstitute/cromwell/labels{/name}","releases_url":"https://api.github.com/repos/broadinstitute/cromwell/releases{/id}","created_at":"2015-04-17T19:39:36Z","updated_at":"2015-08-04T19:33:59Z","pushed_at":"2015-08-17T15:17:58Z","git_url":"git://github.com/broadinstitute/cromwell.git","ssh_url":"git@github.com:broadinstitute/cromwell.git","clone_url":"https://github.com/broadinstitute/cromwell.git","svn_url":"https://github.com/broadinstitute/cromwell","homepage":"http://broadinstitute.github.io/cromwell/","size":4345,"stargazers_count":6,"watchers_count":6,"language":"Scala","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":0,"mirror_url":null,"open_issues_count":4,"forks":0,"open_issues":4,"watchers":6,"default_branch":"master"}},"base":{"label":"broadinstitute:develop","ref":"develop","sha":"92e4124ff773f02e9c02b240d90a2d2eea0a9a83","user":{"login":"broadinstitute","id":393552,"avatar_url":"https://avatars.githubusercontent.com/u/393552?v=3","gravatar_id":"","url":"https://api.github.com/users/broadinstitute","html_url":"https://github.com/broadinstitute","followers_url":"https://api.github.com/users/broadinstitute/followers","following_url":"https://api.github.com/users/broadinstitute/following{/other_user}","gists_url":"https://api.github.com/users/broadinstitute/gists{/gist_id}","starred_url":"https://api.github.com/users/broadinstitute/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/broadinstitute/subscriptions","organizations_url":"https://api.github.com/users/broadinstitute/orgs","repos_url":"https://api.github.com/users/broadinstitute/repos","events_url":"https://api.github.com/users/broadinstitute/events{/privacy}","received_events_url":"https://api.github.com/users/broadinstitute/received_events","type":"Organization","site_admin":false},"repo":{"id":34136406,"name":"cromwell","full_name":"broadinstitute/cromwell","owner":{"login":"broadinstitute","id":393552,"avatar_url":"https://avatars.githubusercontent.com/u/393552?v=3","gravatar_id":"","url":"https://api.github.com/users/broadinstitute","html_url":"https://github.com/broadinstitute","followers_url":"https://api.github.com/users/broadinstitute/followers","following_url":"https://api.github.com/users/broadinstitute/following{/other_user}","gists_url":"https://api.github.com/users/broadinstitute/gists{/gist_id}","starred_url":"https://api.github.com/users/broadinstitute/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/broadinstitute/subscriptions","organizations_url":"https://api.github.com/users/broadinstitute/orgs","repos_url":"https://api.github.com/users/broadinstitute/repos","events_url":"https://api.github.com/users/broadinstitute/events{/privacy}","received_events_url":"https://api.github.com/users/broadinstitute/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/broadinstitute/cromwell","description":"Workflow Execution Engine using WDL","fork":false,"url":"https://api.github.com/repos/broadinstitute/cromwell","forks_url":"https://api.github.com/repos/broadinstitute/cromwell/forks","keys_url":"https://api.github.com/repos/broadinstitute/cromwell/keys{/key_id}","collaborators_url":"https://api.github.com/repos/broadinstitute/cromwell/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/broadinstitute/cromwell/teams","hooks_url":"https://api.github.com/repos/broadinstitute/cromwell/hooks","issue_events_url":"https://api.github.com/repos/broadinstitute/cromwell/issues/events{/number}","events_url":"https://api.github.com/repos/broadinstitute/cromwell/events","assignees_url":"https://api.github.com/repos/broadinstitute/cromwell/assignees{/user}","branches_url":"https://api.github.com/repos/broadinstitute/cromwell/branches{/branch}","tags_url":"https://api.github.com/repos/broadinstitute/cromwell/tags","blobs_url":"https://api.github.com/repos/broadinstitute/cromwell/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/broadinstitute/cromwell/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/broadinstitute/cromwell/git/refs{/sha}","trees_url":"https://api.github.com/repos/broadinstitute/cromwell/git/trees{/sha}","statuses_url":"https://api.github.com/repos/broadinstitute/cromwell/statuses/{sha}","languages_url":"https://api.github.com/repos/broadinstitute/cromwell/languages","stargazers_url":"https://api.github.com/repos/broadinstitute/cromwell/stargazers","contributors_url":"https://api.github.com/repos/broadinstitute/cromwell/contributors","subscribers_url":"https://api.github.com/repos/broadinstitute/cromwell/subscribers","subscription_url":"https://api.github.com/repos/broadinstitute/cromwell/subscription","commits_url":"https://api.github.com/repos/broadinstitute/cromwell/commits{/sha}","git_commits_url":"https://api.github.com/repos/broadinstitute/cromwell/git/commits{/sha}","comments_url":"https://api.github.com/repos/broadinstitute/cromwell/comments{/number}","issue_comment_url":"https://api.github.com/repos/broadinstitute/cromwell/issues/comments{/number}","contents_url":"https://api.github.com/repos/broadinstitute/cromwell/contents/{+path}","compare_url":"https://api.github.com/repos/broadinstitute/cromwell/compare/{base}...{head}","merges_url":"https://api.github.com/repos/broadinstitute/cromwell/merges","archive_url":"https://api.github.com/repos/broadinstitute/cromwell/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/broadinstitute/cromwell/downloads","issues_url":"https://api.github.com/repos/broadinstitute/cromwell/issues{/number}","pulls_url":"https://api.github.com/repos/broadinstitute/cromwell/pulls{/number}","milestones_url":"https://api.github.com/repos/broadinstitute/cromwell/milestones{/number}","notifications_url":"https://api.github.com/repos/broadinstitute/cromwell/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/broadinstitute/cromwell/labels{/name}","releases_url":"https://api.github.com/repos/broadinstitute/cromwell/releases{/id}","created_at":"2015-04-17T19:39:36Z","updated_at":"2015-08-04T19:33:59Z","pushed_at":"2015-08-17T15:17:58Z","git_url":"git://github.com/broadinstitute/cromwell.git","ssh_url":"git@github.com:broadinstitute/cromwell.git","clone_url":"https://github.com/broadinstitute/cromwell.git","svn_url":"https://github.com/broadinstitute/cromwell","homepage":"http://broadinstitute.github.io/cromwell/","size":4345,"stargazers_count":6,"watchers_count":6,"language":"Scala","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":0,"mirror_url":null,"open_issues_count":4,"forks":0,"open_issues":4,"watchers":6,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/broadinstitute/cromwell/pulls/138"},"html":{"href":"https://github.com/broadinstitute/cromwell/pull/138"},"issue":{"href":"https://api.github.com/repos/broadinstitute/cromwell/issues/138"},"comments":{"href":"https://api.github.com/repos/broadinstitute/cromwell/issues/138/comments"},"review_comments":{"href":"https://api.github.com/repos/broadinstitute/cromwell/pulls/138/comments"},"review_comment":{"href":"https://api.github.com/repos/broadinstitute/cromwell/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/broadinstitute/cromwell/pulls/138/commits"},"statuses":{"href":"https://api.github.com/repos/broadinstitute/cromwell/statuses/9bad58b098acc6f5047d608b8e74847d08657336"}}}}