GitHub PullRequestReviewCommentEvent at 2014-09-12 00:05:13
Repository: scalding
Actor: travisbrown
Payload: {"action":"created","comment":{"url":"https://api.github.com/repos/twitter/scalding/pulls/comments/17457113","id":17457113,"diff_hunk":"@@ -0,0 +1,128 @@\n+package com.twitter.scalding.macros.impl\n+\n+import scala.language.experimental.macros\n+import scala.reflect.macros.Context\n+import scala.reflect.runtime.universe._\n+import scala.util.{ Try => BasicTry }\n+\n+import cascading.tuple.{ Tuple, TupleEntry }\n+\n+import com.twitter.scalding._\n+import com.twitter.scalding.macros.IsCaseClass\n+\n+/**\n+ * This class contains the core macro implementations. This is in a separate module to allow it to be in\n+ * a separate compilation unit, which makes it easier to provide helper methods interfacing with macros.\n+ */\n+object MacroImpl {\n+  def isCaseClassImpl[T](c: Context)(implicit T: c.WeakTypeTag[T]): c.Expr[IsCaseClass[T]] = {\n+    import c.universe._\n+    if (isCaseClassType(c)(T.tpe)) {\n+      c.Expr[IsCaseClass[T]](q\"\"\"new _root_.com.twitter.scalding.macros.impl.MacroGeneratedIsCaseClass[$T] { }\"\"\")\n+    } else {\n+      c.abort(c.enclosingPosition, \"Type parameter is not a case class\")\n+    }\n+  }\n+\n+  def caseClassTupleSetterNoProof[T]: TupleSetter[T] = macro caseClassTupleSetterNoProofImpl[T]\n+\n+  def caseClassTupleSetterImpl[T](c: Context)(proof: c.Expr[IsCaseClass[T]])(implicit T: c.WeakTypeTag[T]): c.Expr[TupleSetter[T]] =\n+    caseClassTupleSetterNoProofImpl(c)(T)\n+\n+  def caseClassTupleSetterNoProofImpl[T](c: Context)(implicit T: c.WeakTypeTag[T]): c.Expr[TupleSetter[T]] = {\n+    import c.universe._\n+    val set =\n+      T.tpe.declarations\n+        .collect { case m: MethodSymbol if m.isCaseAccessor => m }\n+        .zipWithIndex\n+        .map {\n+          case (m, idx) =>\n+            m.returnType match {\n+              case tpe if tpe =:= typeOf[String] => q\"\"\"tup.setString(${idx}, t.$m)\"\"\"\n+              case tpe if tpe =:= typeOf[Boolean] => q\"\"\"tup.setBoolean(${idx}, t.$m)\"\"\"\n+              case tpe if tpe =:= typeOf[Short] => q\"\"\"tup.setShort(${idx}, t.$m)\"\"\"\n+              case tpe if tpe =:= typeOf[Int] => q\"\"\"tup.setInteger(${idx}, t.$m)\"\"\"\n+              case tpe if tpe =:= typeOf[Long] => q\"\"\"tup.setLong(${idx}, t.$m)\"\"\"\n+              case tpe if tpe =:= typeOf[Float] => q\"\"\"tup.setFloat(${idx}, t.$m)\"\"\"\n+              case tpe if tpe =:= typeOf[Double] => q\"\"\"tup.setDouble(${idx}, t.$m)\"\"\"\n+              case tpe if isCaseClassType(c)(tpe) => q\"\"\"\n+                tup.set(\n+                  ${idx},\n+                  _root_.com.twitter.scalding.macros.impl.MacroImpl.caseClassTupleSetterNoProof[$tpe](t.$m)\n+                )\n+                \"\"\"\n+              case _ => q\"\"\"tup.set(${idx}, t.$m)\"\"\"\n+            }\n+        }\n+    val res = q\"\"\"\n+    _root_.com.twitter.scalding.macros.impl.MacroGeneratedTupleSetter[$T](\n+      { t: $T =>\n+        val tup = _root_.cascading.tuple.Tuple.size(${set.size})\n+        ..$set\n+        tup\n+      },\n+      ${set.size}\n+    )\n+    \"\"\"\n+    c.Expr[TupleSetter[T]](res)\n+  }\n+\n+  def caseClassTupleConverterNoProof[T]: TupleConverter[T] = macro caseClassTupleConverterNoProofImpl[T]\n+\n+  def caseClassTupleConverterImpl[T](c: Context)(proof: c.Expr[IsCaseClass[T]])(implicit T: c.WeakTypeTag[T]): c.Expr[TupleConverter[T]] =\n+    caseClassTupleConverterNoProofImpl(c)(T)\n+\n+  def caseClassTupleConverterNoProofImpl[T](c: Context)(implicit T: c.WeakTypeTag[T]): c.Expr[TupleConverter[T]] = {\n+    import c.universe._\n+    val get =\n+      T.tpe.declarations\n+        .collect { case m: MethodSymbol if m.isCaseAccessor => m.returnType }\n+        .zipWithIndex\n+        .map {\n+          case (returnType, idx) =>\n+            returnType match {\n+              case tpe if tpe =:= typeOf[String] => q\"\"\"tup.getString(${idx})\"\"\"\n+              case tpe if tpe =:= typeOf[Boolean] => q\"\"\"tup.getBoolean(${idx})\"\"\"\n+              case tpe if tpe =:= typeOf[Short] => q\"\"\"tup.getShort(${idx})\"\"\"\n+              case tpe if tpe =:= typeOf[Int] => q\"\"\"tup.getInteger(${idx})\"\"\"\n+              case tpe if tpe =:= typeOf[Long] => q\"\"\"tup.getLong(${idx})\"\"\"\n+              case tpe if tpe =:= typeOf[Float] => q\"\"\"tup.getFloat(${idx})\"\"\"\n+              case tpe if tpe =:= typeOf[Double] => q\"\"\"tup.getDouble(${idx})\"\"\"\n+              case tpe if isCaseClassType(c)(tpe) =>\n+                q\"\"\"\n+                _root_.com.twitter.scalding.macros.impl.MacroImpl.caseClassTupleConverterNoProof[$tpe](\n+                  new _root_.cascading.tuple.TupleEntry(tup.getObject(${idx}).asInstanceOf[_root_.cascading.tuple.Tuple])\n+                )\n+                \"\"\"\n+              case tpe => q\"\"\"tup.getObject(${idx}).asInstanceOf[$tpe]\"\"\"\n+            }\n+        }\n+    val companion = newTermName(T.tpe.typeSymbol.companionSymbol.fullName) //TODO is there a better way to get it to resolve thiss?","path":"scalding-macros/src/main/scala/com/twitter/scalding/macros/impl/MacroImpl.scala","position":100,"original_position":100,"commit_id":"c27c54e6b6346b88fae16f338bc2cfbb5caa0eb6","original_commit_id":"c27c54e6b6346b88fae16f338bc2cfbb5caa0eb6","user":{"login":"travisbrown","id":316049,"avatar_url":"https://avatars.githubusercontent.com/u/316049?v=2","gravatar_id":"bf774a4e24c33e4bb6d19ea1939f01a2","url":"https://api.github.com/users/travisbrown","html_url":"https://github.com/travisbrown","followers_url":"https://api.github.com/users/travisbrown/followers","following_url":"https://api.github.com/users/travisbrown/following{/other_user}","gists_url":"https://api.github.com/users/travisbrown/gists{/gist_id}","starred_url":"https://api.github.com/users/travisbrown/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/travisbrown/subscriptions","organizations_url":"https://api.github.com/users/travisbrown/orgs","repos_url":"https://api.github.com/users/travisbrown/repos","events_url":"https://api.github.com/users/travisbrown/events{/privacy}","received_events_url":"https://api.github.com/users/travisbrown/received_events","type":"User","site_admin":false},"body":"Does this actually work? If so I'm a little surprised. You can just use the companion symbol directly in the quasiquotes and it'll get lifted appropriately.","created_at":"2014-09-12T00:05:13Z","updated_at":"2014-09-12T00:05:13Z","html_url":"https://github.com/twitter/scalding/pull/1037#discussion_r17457113","pull_request_url":"https://api.github.com/repos/twitter/scalding/pulls/1037","_links":{"self":{"href":"https://api.github.com/repos/twitter/scalding/pulls/comments/17457113"},"html":{"href":"https://github.com/twitter/scalding/pull/1037#discussion_r17457113"},"pull_request":{"href":"https://api.github.com/repos/twitter/scalding/pulls/1037"}}},"pull_request":{"url":"https://api.github.com/repos/twitter/scalding/pulls/1037","id":20829114,"html_url":"https://github.com/twitter/scalding/pull/1037","diff_url":"https://github.com/twitter/scalding/pull/1037.diff","patch_url":"https://github.com/twitter/scalding/pull/1037.patch","issue_url":"https://api.github.com/repos/twitter/scalding/issues/1037","number":1037,"state":"open","locked":false,"title":"Macro generated case class Tuple Setter and Converter","user":{"login":"jcoveney","id":830087,"avatar_url":"https://avatars.githubusercontent.com/u/830087?v=2","gravatar_id":"c31517bb2497ca20710a294d3f8d1144","url":"https://api.github.com/users/jcoveney","html_url":"https://github.com/jcoveney","followers_url":"https://api.github.com/users/jcoveney/followers","following_url":"https://api.github.com/users/jcoveney/following{/other_user}","gists_url":"https://api.github.com/users/jcoveney/gists{/gist_id}","starred_url":"https://api.github.com/users/jcoveney/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jcoveney/subscriptions","organizations_url":"https://api.github.com/users/jcoveney/orgs","repos_url":"https://api.github.com/users/jcoveney/repos","events_url":"https://api.github.com/users/jcoveney/events{/privacy}","received_events_url":"https://api.github.com/users/jcoveney/received_events","type":"User","site_admin":false},"body":"This is a first stab at using macros to begin generating useful code for our users.\r\n\r\nCaveats:\r\n* this only works on 2.10. I play around with it by doing: ```./sbt ++2.10.4 \"scalding-macro/console\"```\r\n* this depends on macro paradise. I do this for quasiquotes, which GREATLY simplify the implementation... it isn't strictly necessary, but would greatly complicate things. quasiquotes are part of scala 2.11 so depending on macro paradise only for them seems ok to me.\r\n* I need to add tests, though I've tested it along the way of course.\r\n\r\nWhat are other things we might want to use macros for?","created_at":"2014-09-05T19:27:29Z","updated_at":"2014-09-12T00:05:13Z","closed_at":null,"merged_at":null,"merge_commit_sha":"02e84d684dd2aa1d459fe0e8f428faf4cf0b7697","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/twitter/scalding/pulls/1037/commits","review_comments_url":"https://api.github.com/repos/twitter/scalding/pulls/1037/comments","review_comment_url":"https://api.github.com/repos/twitter/scalding/pulls/comments/{number}","comments_url":"https://api.github.com/repos/twitter/scalding/issues/1037/comments","statuses_url":"https://api.github.com/repos/twitter/scalding/statuses/c27c54e6b6346b88fae16f338bc2cfbb5caa0eb6","head":{"label":"twitter:jco/macro_case_class_tuple","ref":"jco/macro_case_class_tuple","sha":"c27c54e6b6346b88fae16f338bc2cfbb5caa0eb6","user":{"login":"twitter","id":50278,"avatar_url":"https://avatars.githubusercontent.com/u/50278?v=2","gravatar_id":"2f4a8254d032a8ec5e4c48d461e54fcc","url":"https://api.github.com/users/twitter","html_url":"https://github.com/twitter","followers_url":"https://api.github.com/users/twitter/followers","following_url":"https://api.github.com/users/twitter/following{/other_user}","gists_url":"https://api.github.com/users/twitter/gists{/gist_id}","starred_url":"https://api.github.com/users/twitter/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/twitter/subscriptions","organizations_url":"https://api.github.com/users/twitter/orgs","repos_url":"https://api.github.com/users/twitter/repos","events_url":"https://api.github.com/users/twitter/events{/privacy}","received_events_url":"https://api.github.com/users/twitter/received_events","type":"Organization","site_admin":false},"repo":{"id":3146558,"name":"scalding","full_name":"twitter/scalding","owner":{"login":"twitter","id":50278,"avatar_url":"https://avatars.githubusercontent.com/u/50278?v=2","gravatar_id":"2f4a8254d032a8ec5e4c48d461e54fcc","url":"https://api.github.com/users/twitter","html_url":"https://github.com/twitter","followers_url":"https://api.github.com/users/twitter/followers","following_url":"https://api.github.com/users/twitter/following{/other_user}","gists_url":"https://api.github.com/users/twitter/gists{/gist_id}","starred_url":"https://api.github.com/users/twitter/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/twitter/subscriptions","organizations_url":"https://api.github.com/users/twitter/orgs","repos_url":"https://api.github.com/users/twitter/repos","events_url":"https://api.github.com/users/twitter/events{/privacy}","received_events_url":"https://api.github.com/users/twitter/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/twitter/scalding","description":"A Scala API for Cascading","fork":false,"url":"https://api.github.com/repos/twitter/scalding","forks_url":"https://api.github.com/repos/twitter/scalding/forks","keys_url":"https://api.github.com/repos/twitter/scalding/keys{/key_id}","collaborators_url":"https://api.github.com/repos/twitter/scalding/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/twitter/scalding/teams","hooks_url":"https://api.github.com/repos/twitter/scalding/hooks","issue_events_url":"https://api.github.com/repos/twitter/scalding/issues/events{/number}","events_url":"https://api.github.com/repos/twitter/scalding/events","assignees_url":"https://api.github.com/repos/twitter/scalding/assignees{/user}","branches_url":"https://api.github.com/repos/twitter/scalding/branches{/branch}","tags_url":"https://api.github.com/repos/twitter/scalding/tags","blobs_url":"https://api.github.com/repos/twitter/scalding/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/twitter/scalding/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/twitter/scalding/git/refs{/sha}","trees_url":"https://api.github.com/repos/twitter/scalding/git/trees{/sha}","statuses_url":"https://api.github.com/repos/twitter/scalding/statuses/{sha}","languages_url":"https://api.github.com/repos/twitter/scalding/languages","stargazers_url":"https://api.github.com/repos/twitter/scalding/stargazers","contributors_url":"https://api.github.com/repos/twitter/scalding/contributors","subscribers_url":"https://api.github.com/repos/twitter/scalding/subscribers","subscription_url":"https://api.github.com/repos/twitter/scalding/subscription","commits_url":"https://api.github.com/repos/twitter/scalding/commits{/sha}","git_commits_url":"https://api.github.com/repos/twitter/scalding/git/commits{/sha}","comments_url":"https://api.github.com/repos/twitter/scalding/comments{/number}","issue_comment_url":"https://api.github.com/repos/twitter/scalding/issues/comments/{number}","contents_url":"https://api.github.com/repos/twitter/scalding/contents/{+path}","compare_url":"https://api.github.com/repos/twitter/scalding/compare/{base}...{head}","merges_url":"https://api.github.com/repos/twitter/scalding/merges","archive_url":"https://api.github.com/repos/twitter/scalding/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/twitter/scalding/downloads","issues_url":"https://api.github.com/repos/twitter/scalding/issues{/number}","pulls_url":"https://api.github.com/repos/twitter/scalding/pulls{/number}","milestones_url":"https://api.github.com/repos/twitter/scalding/milestones{/number}","notifications_url":"https://api.github.com/repos/twitter/scalding/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/twitter/scalding/labels{/name}","releases_url":"https://api.github.com/repos/twitter/scalding/releases{/id}","created_at":"2012-01-10T16:22:08Z","updated_at":"2014-09-11T08:32:38Z","pushed_at":"2014-09-11T23:10:04Z","git_url":"git://github.com/twitter/scalding.git","ssh_url":"git@github.com:twitter/scalding.git","clone_url":"https://github.com/twitter/scalding.git","svn_url":"https://github.com/twitter/scalding","homepage":"http://twitter.com/scalding","size":28166,"stargazers_count":1697,"watchers_count":1697,"language":"Scala","has_issues":true,"has_downloads":true,"has_wiki":true,"forks_count":388,"mirror_url":null,"open_issues_count":177,"forks":388,"open_issues":177,"watchers":1697,"default_branch":"develop"}},"base":{"label":"twitter:develop","ref":"develop","sha":"15da3073124131b6f5520fe10c3b7c6072d5a26a","user":{"login":"twitter","id":50278,"avatar_url":"https://avatars.githubusercontent.com/u/50278?v=2","gravatar_id":"2f4a8254d032a8ec5e4c48d461e54fcc","url":"https://api.github.com/users/twitter","html_url":"https://github.com/twitter","followers_url":"https://api.github.com/users/twitter/followers","following_url":"https://api.github.com/users/twitter/following{/other_user}","gists_url":"https://api.github.com/users/twitter/gists{/gist_id}","starred_url":"https://api.github.com/users/twitter/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/twitter/subscriptions","organizations_url":"https://api.github.com/users/twitter/orgs","repos_url":"https://api.github.com/users/twitter/repos","events_url":"https://api.github.com/users/twitter/events{/privacy}","received_events_url":"https://api.github.com/users/twitter/received_events","type":"Organization","site_admin":false},"repo":{"id":3146558,"name":"scalding","full_name":"twitter/scalding","owner":{"login":"twitter","id":50278,"avatar_url":"https://avatars.githubusercontent.com/u/50278?v=2","gravatar_id":"2f4a8254d032a8ec5e4c48d461e54fcc","url":"https://api.github.com/users/twitter","html_url":"https://github.com/twitter","followers_url":"https://api.github.com/users/twitter/followers","following_url":"https://api.github.com/users/twitter/following{/other_user}","gists_url":"https://api.github.com/users/twitter/gists{/gist_id}","starred_url":"https://api.github.com/users/twitter/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/twitter/subscriptions","organizations_url":"https://api.github.com/users/twitter/orgs","repos_url":"https://api.github.com/users/twitter/repos","events_url":"https://api.github.com/users/twitter/events{/privacy}","received_events_url":"https://api.github.com/users/twitter/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/twitter/scalding","description":"A Scala API for Cascading","fork":false,"url":"https://api.github.com/repos/twitter/scalding","forks_url":"https://api.github.com/repos/twitter/scalding/forks","keys_url":"https://api.github.com/repos/twitter/scalding/keys{/key_id}","collaborators_url":"https://api.github.com/repos/twitter/scalding/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/twitter/scalding/teams","hooks_url":"https://api.github.com/repos/twitter/scalding/hooks","issue_events_url":"https://api.github.com/repos/twitter/scalding/issues/events{/number}","events_url":"https://api.github.com/repos/twitter/scalding/events","assignees_url":"https://api.github.com/repos/twitter/scalding/assignees{/user}","branches_url":"https://api.github.com/repos/twitter/scalding/branches{/branch}","tags_url":"https://api.github.com/repos/twitter/scalding/tags","blobs_url":"https://api.github.com/repos/twitter/scalding/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/twitter/scalding/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/twitter/scalding/git/refs{/sha}","trees_url":"https://api.github.com/repos/twitter/scalding/git/trees{/sha}","statuses_url":"https://api.github.com/repos/twitter/scalding/statuses/{sha}","languages_url":"https://api.github.com/repos/twitter/scalding/languages","stargazers_url":"https://api.github.com/repos/twitter/scalding/stargazers","contributors_url":"https://api.github.com/repos/twitter/scalding/contributors","subscribers_url":"https://api.github.com/repos/twitter/scalding/subscribers","subscription_url":"https://api.github.com/repos/twitter/scalding/subscription","commits_url":"https://api.github.com/repos/twitter/scalding/commits{/sha}","git_commits_url":"https://api.github.com/repos/twitter/scalding/git/commits{/sha}","comments_url":"https://api.github.com/repos/twitter/scalding/comments{/number}","issue_comment_url":"https://api.github.com/repos/twitter/scalding/issues/comments/{number}","contents_url":"https://api.github.com/repos/twitter/scalding/contents/{+path}","compare_url":"https://api.github.com/repos/twitter/scalding/compare/{base}...{head}","merges_url":"https://api.github.com/repos/twitter/scalding/merges","archive_url":"https://api.github.com/repos/twitter/scalding/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/twitter/scalding/downloads","issues_url":"https://api.github.com/repos/twitter/scalding/issues{/number}","pulls_url":"https://api.github.com/repos/twitter/scalding/pulls{/number}","milestones_url":"https://api.github.com/repos/twitter/scalding/milestones{/number}","notifications_url":"https://api.github.com/repos/twitter/scalding/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/twitter/scalding/labels{/name}","releases_url":"https://api.github.com/repos/twitter/scalding/releases{/id}","created_at":"2012-01-10T16:22:08Z","updated_at":"2014-09-11T08:32:38Z","pushed_at":"2014-09-11T23:10:04Z","git_url":"git://github.com/twitter/scalding.git","ssh_url":"git@github.com:twitter/scalding.git","clone_url":"https://github.com/twitter/scalding.git","svn_url":"https://github.com/twitter/scalding","homepage":"http://twitter.com/scalding","size":28166,"stargazers_count":1697,"watchers_count":1697,"language":"Scala","has_issues":true,"has_downloads":true,"has_wiki":true,"forks_count":388,"mirror_url":null,"open_issues_count":177,"forks":388,"open_issues":177,"watchers":1697,"default_branch":"develop"}},"_links":{"self":{"href":"https://api.github.com/repos/twitter/scalding/pulls/1037"},"html":{"href":"https://github.com/twitter/scalding/pull/1037"},"issue":{"href":"https://api.github.com/repos/twitter/scalding/issues/1037"},"comments":{"href":"https://api.github.com/repos/twitter/scalding/issues/1037/comments"},"review_comments":{"href":"https://api.github.com/repos/twitter/scalding/pulls/1037/comments"},"review_comment":{"href":"https://api.github.com/repos/twitter/scalding/pulls/comments/{number}"},"commits":{"href":"https://api.github.com/repos/twitter/scalding/pulls/1037/commits"},"statuses":{"href":"https://api.github.com/repos/twitter/scalding/statuses/c27c54e6b6346b88fae16f338bc2cfbb5caa0eb6"}}}}