{"action":"created","comment":{"url":"https://api.github.com/repos/INRIA/spoon/pulls/comments/69548493","id":69548493,"diff_hunk":"@@ -0,0 +1,61 @@\n+/**\n+ * Copyright (C) 2006-2015 INRIA and contributors\n+ * Spoon - http://spoon.gforge.inria.fr/\n+ *\n+ * This software is governed by the CeCILL-C License under French law and\n+ * abiding by the rules of distribution of free software. You can use, modify\n+ * and/or redistribute the software under the terms of the CeCILL-C license as\n+ * circulated by CEA, CNRS and INRIA at http://www.cecill.info.\n+ *\n+ * This program is distributed in the hope that it will be useful, but WITHOUT\n+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or\n+ * FITNESS FOR A PARTICULAR PURPOSE. See the CeCILL-C License for more details.\n+ *\n+ * The fact that you are presently reading this means that you have had\n+ * knowledge of the CeCILL-C license and that you accept its terms.\n+ */\n+package spoon.reflect.builder;\n+\n+import org.junit.Assert;\n+import org.junit.Test;\n+import spoon.Launcher;\n+import spoon.reflect.code.CtBinaryOperator;\n+import spoon.reflect.code.CtUnaryOperator;\n+import spoon.reflect.factory.Factory;\n+\n+public class BinaryBuilderTest {\n+\n+\t@Test\n+\tpublic void multiBuilderTest() {\n+\t\tFactory factory = new Launcher().getFactory();\n+\t\tBuilder B = factory.Builder();\n+\t\tCtUnaryOperator not = B.Not(B.Binary(B.Literal(2)).lower(B.Literal(1))).build();\n+\t\tAssert.assertEquals(\"!(2 < 1)\", not.toString());\n+\t}\n+\n+\t@Test\n+\tpublic void simpleBinaryTest() {\n+\t\tFactory factory = new Launcher().getFactory();\n+\t\tBuilder B = factory.Builder();\n+\t\tCtBinaryOperator binary = B.Binary(","path":"src/test/java/spoon/reflect/builder/BinaryBuilderTest.java","position":40,"original_position":40,"commit_id":"877668948836f50fe8de67926b08d1bf02129263","original_commit_id":"877668948836f50fe8de67926b08d1bf02129263","user":{"login":"monperrus","id":803666,"avatar_url":"https://avatars.githubusercontent.com/u/803666?v=3","gravatar_id":"","url":"https://api.github.com/users/monperrus","html_url":"https://github.com/monperrus","followers_url":"https://api.github.com/users/monperrus/followers","following_url":"https://api.github.com/users/monperrus/following{/other_user}","gists_url":"https://api.github.com/users/monperrus/gists{/gist_id}","starred_url":"https://api.github.com/users/monperrus/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/monperrus/subscriptions","organizations_url":"https://api.github.com/users/monperrus/orgs","repos_url":"https://api.github.com/users/monperrus/repos","events_url":"https://api.github.com/users/monperrus/events{/privacy}","received_events_url":"https://api.github.com/users/monperrus/received_events","type":"User","site_admin":false},"body":"infix notation? `Lit(2).times(Lit(3))`","created_at":"2016-07-05T11:41:11Z","updated_at":"2016-07-05T11:41:12Z","html_url":"https://github.com/INRIA/spoon/pull/741#discussion_r69548493","pull_request_url":"https://api.github.com/repos/INRIA/spoon/pulls/741","_links":{"self":{"href":"https://api.github.com/repos/INRIA/spoon/pulls/comments/69548493"},"html":{"href":"https://github.com/INRIA/spoon/pull/741#discussion_r69548493"},"pull_request":{"href":"https://api.github.com/repos/INRIA/spoon/pulls/741"}}},"pull_request":{"url":"https://api.github.com/repos/INRIA/spoon/pulls/741","id":76242495,"html_url":"https://github.com/INRIA/spoon/pull/741","diff_url":"https://github.com/INRIA/spoon/pull/741.diff","patch_url":"https://github.com/INRIA/spoon/pull/741.patch","issue_url":"https://api.github.com/repos/INRIA/spoon/issues/741","number":741,"state":"open","locked":false,"title":"Element Builder proposal","user":{"login":"tdurieux","id":5577568,"avatar_url":"https://avatars.githubusercontent.com/u/5577568?v=3","gravatar_id":"","url":"https://api.github.com/users/tdurieux","html_url":"https://github.com/tdurieux","followers_url":"https://api.github.com/users/tdurieux/followers","following_url":"https://api.github.com/users/tdurieux/following{/other_user}","gists_url":"https://api.github.com/users/tdurieux/gists{/gist_id}","starred_url":"https://api.github.com/users/tdurieux/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tdurieux/subscriptions","organizations_url":"https://api.github.com/users/tdurieux/orgs","repos_url":"https://api.github.com/users/tdurieux/repos","events_url":"https://api.github.com/users/tdurieux/events{/privacy}","received_events_url":"https://api.github.com/users/tdurieux/received_events","type":"User","site_admin":false},"body":"I created this PR in order to discuss the architecture of a possible new Element Builder in spoon.\r\n\r\nThe current factories are neither easy to use nor explicit. This new builder aims to solve these issues.\r\nBut I don't know yet the best solution.\r\n\r\nThis PR contains a POC of the builder. I would like to have your opinion.\r\n\r\n# Syntaxe\r\n\r\n## BinaryOperator\r\n```java\r\nBuilder B = factory.Builder();\r\nCtBinaryOperator binary = B.Binary(\r\n\t\tB.Literal(2))\r\n\t\t.plus(B.Literal(1))\r\n\t\t.lower(\r\n\t\t\t\tB.Binary(B.Literal(10))\r\n\t\t\t\t\t\t.minus(B.Literal(5))\r\n\t\t).build();\r\nAssert.assertEquals(\"(2 + 1) < (10 - 5)\", binary.toString());\r\n```\r\n\r\n## Try\r\n\r\n```java\r\nBuilder B = factory.Builder();\r\nCtTry aTry = B.Try()\r\n\t\t.inBody(B.Increment(x.Literal(1)))\r\n\t\t.createCatch()\r\n\t\t\t.parameter(\"e\", IllegalArgumentException.class)\r\n\t\t\t.inBody(x.Increment(x.Literal(1)))\r\n\t\t\t.close()\r\n\t\t.createCatch()\r\n\t\t\t.parameter(\"e\", Exception.class)\r\n\t\t\t.close()\r\n\t\t.inFinally(x.Decrement(x.Literal(1)))\r\n.build();\r\nAssert.assertEquals(\"try {\\n\"\r\n\t\t+ \"    1++;\\n\"\r\n\t\t+ \"} catch (java.lang.IllegalArgumentException e) {\\n\"\r\n\t\t+ \"    1++;\\n\"\r\n\t\t+ \"} catch (java.lang.Exception e) {\\n\"\r\n\t\t+ \"} finally {\\n\"\r\n\t\t+ \"    1--;\\n\"\r\n\t\t+ \"}\", aTry.toString());\r\n```\r\n## Method\r\n\r\n```java\r\nBuilder x = factory.Builder();\r\n\r\n\t\tCtReturn<Object> aReturn = factory.Core().createReturn();\r\n\t\taReturn.setReturnedExpression(x.Literal(1).build());\r\n\t\tCtMethod m = x.Method(\"m\")\r\n\t\t\t\t.type(int.class)\r\n\t\t\t\t.setPrivate()\r\n\t\t\t\t.setStatic()\r\n\t\t\t\t.addParam(int.class, \"x\")\r\n\t\t\t\t.inBody(aReturn).build();\r\n\t\tAssert.assertEquals(\"private static int m(int x) {\\n\"\r\n\t\t\t\t+ \"    return 1;\\n\"\r\n\t\t\t\t+ \"}\", m.toString());\r\n```\r\n# Limitations\r\n1. The builder requires a method to indicate the end of the element (here `CatchBuilder.close()`) in order to get back the parent Builder (here `TryBuilder`). It is not intuitive... \r\n\r\n2. This architecture will introduce a lot of duplicate codes. Example: all elements that have a body will have the method `inBody`. Unfortunately the inheritance will not solve this issue (in this case we need multi inheritance)\r\n","created_at":"2016-07-05T09:25:36Z","updated_at":"2016-07-05T11:41:12Z","closed_at":null,"merged_at":null,"merge_commit_sha":"e9bdbafaf023cea2dcd00707da863e0b7488ea6b","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/INRIA/spoon/pulls/741/commits","review_comments_url":"https://api.github.com/repos/INRIA/spoon/pulls/741/comments","review_comment_url":"https://api.github.com/repos/INRIA/spoon/pulls/comments{/number}","comments_url":"https://api.github.com/repos/INRIA/spoon/issues/741/comments","statuses_url":"https://api.github.com/repos/INRIA/spoon/statuses/877668948836f50fe8de67926b08d1bf02129263","head":{"label":"tdurieux:wip-feat-builder","ref":"wip-feat-builder","sha":"877668948836f50fe8de67926b08d1bf02129263","user":{"login":"tdurieux","id":5577568,"avatar_url":"https://avatars.githubusercontent.com/u/5577568?v=3","gravatar_id":"","url":"https://api.github.com/users/tdurieux","html_url":"https://github.com/tdurieux","followers_url":"https://api.github.com/users/tdurieux/followers","following_url":"https://api.github.com/users/tdurieux/following{/other_user}","gists_url":"https://api.github.com/users/tdurieux/gists{/gist_id}","starred_url":"https://api.github.com/users/tdurieux/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tdurieux/subscriptions","organizations_url":"https://api.github.com/users/tdurieux/orgs","repos_url":"https://api.github.com/users/tdurieux/repos","events_url":"https://api.github.com/users/tdurieux/events{/privacy}","received_events_url":"https://api.github.com/users/tdurieux/received_events","type":"User","site_admin":false},"repo":{"id":42295680,"name":"spoon","full_name":"tdurieux/spoon","owner":{"login":"tdurieux","id":5577568,"avatar_url":"https://avatars.githubusercontent.com/u/5577568?v=3","gravatar_id":"","url":"https://api.github.com/users/tdurieux","html_url":"https://github.com/tdurieux","followers_url":"https://api.github.com/users/tdurieux/followers","following_url":"https://api.github.com/users/tdurieux/following{/other_user}","gists_url":"https://api.github.com/users/tdurieux/gists{/gist_id}","starred_url":"https://api.github.com/users/tdurieux/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tdurieux/subscriptions","organizations_url":"https://api.github.com/users/tdurieux/orgs","repos_url":"https://api.github.com/users/tdurieux/repos","events_url":"https://api.github.com/users/tdurieux/events{/privacy}","received_events_url":"https://api.github.com/users/tdurieux/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/tdurieux/spoon","description":"Spoon is a library for analyzing and transforming Java source code.","fork":true,"url":"https://api.github.com/repos/tdurieux/spoon","forks_url":"https://api.github.com/repos/tdurieux/spoon/forks","keys_url":"https://api.github.com/repos/tdurieux/spoon/keys{/key_id}","collaborators_url":"https://api.github.com/repos/tdurieux/spoon/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/tdurieux/spoon/teams","hooks_url":"https://api.github.com/repos/tdurieux/spoon/hooks","issue_events_url":"https://api.github.com/repos/tdurieux/spoon/issues/events{/number}","events_url":"https://api.github.com/repos/tdurieux/spoon/events","assignees_url":"https://api.github.com/repos/tdurieux/spoon/assignees{/user}","branches_url":"https://api.github.com/repos/tdurieux/spoon/branches{/branch}","tags_url":"https://api.github.com/repos/tdurieux/spoon/tags","blobs_url":"https://api.github.com/repos/tdurieux/spoon/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/tdurieux/spoon/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/tdurieux/spoon/git/refs{/sha}","trees_url":"https://api.github.com/repos/tdurieux/spoon/git/trees{/sha}","statuses_url":"https://api.github.com/repos/tdurieux/spoon/statuses/{sha}","languages_url":"https://api.github.com/repos/tdurieux/spoon/languages","stargazers_url":"https://api.github.com/repos/tdurieux/spoon/stargazers","contributors_url":"https://api.github.com/repos/tdurieux/spoon/contributors","subscribers_url":"https://api.github.com/repos/tdurieux/spoon/subscribers","subscription_url":"https://api.github.com/repos/tdurieux/spoon/subscription","commits_url":"https://api.github.com/repos/tdurieux/spoon/commits{/sha}","git_commits_url":"https://api.github.com/repos/tdurieux/spoon/git/commits{/sha}","comments_url":"https://api.github.com/repos/tdurieux/spoon/comments{/number}","issue_comment_url":"https://api.github.com/repos/tdurieux/spoon/issues/comments{/number}","contents_url":"https://api.github.com/repos/tdurieux/spoon/contents/{+path}","compare_url":"https://api.github.com/repos/tdurieux/spoon/compare/{base}...{head}","merges_url":"https://api.github.com/repos/tdurieux/spoon/merges","archive_url":"https://api.github.com/repos/tdurieux/spoon/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/tdurieux/spoon/downloads","issues_url":"https://api.github.com/repos/tdurieux/spoon/issues{/number}","pulls_url":"https://api.github.com/repos/tdurieux/spoon/pulls{/number}","milestones_url":"https://api.github.com/repos/tdurieux/spoon/milestones{/number}","notifications_url":"https://api.github.com/repos/tdurieux/spoon/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/tdurieux/spoon/labels{/name}","releases_url":"https://api.github.com/repos/tdurieux/spoon/releases{/id}","deployments_url":"https://api.github.com/repos/tdurieux/spoon/deployments","created_at":"2015-09-11T08:01:22Z","updated_at":"2016-01-25T12:33:11Z","pushed_at":"2016-07-05T11:27:51Z","git_url":"git://github.com/tdurieux/spoon.git","ssh_url":"git@github.com:tdurieux/spoon.git","clone_url":"https://github.com/tdurieux/spoon.git","svn_url":"https://github.com/tdurieux/spoon","homepage":"http://spoon.gforge.inria.fr/","size":7838,"stargazers_count":0,"watchers_count":0,"language":"Java","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"INRIA:master","ref":"master","sha":"ccab0e1eda44a16eb173e28033d2ff218a8adde0","user":{"login":"INRIA","id":2951919,"avatar_url":"https://avatars.githubusercontent.com/u/2951919?v=3","gravatar_id":"","url":"https://api.github.com/users/INRIA","html_url":"https://github.com/INRIA","followers_url":"https://api.github.com/users/INRIA/followers","following_url":"https://api.github.com/users/INRIA/following{/other_user}","gists_url":"https://api.github.com/users/INRIA/gists{/gist_id}","starred_url":"https://api.github.com/users/INRIA/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/INRIA/subscriptions","organizations_url":"https://api.github.com/users/INRIA/orgs","repos_url":"https://api.github.com/users/INRIA/repos","events_url":"https://api.github.com/users/INRIA/events{/privacy}","received_events_url":"https://api.github.com/users/INRIA/received_events","type":"Organization","site_admin":false},"repo":{"id":14176513,"name":"spoon","full_name":"INRIA/spoon","owner":{"login":"INRIA","id":2951919,"avatar_url":"https://avatars.githubusercontent.com/u/2951919?v=3","gravatar_id":"","url":"https://api.github.com/users/INRIA","html_url":"https://github.com/INRIA","followers_url":"https://api.github.com/users/INRIA/followers","following_url":"https://api.github.com/users/INRIA/following{/other_user}","gists_url":"https://api.github.com/users/INRIA/gists{/gist_id}","starred_url":"https://api.github.com/users/INRIA/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/INRIA/subscriptions","organizations_url":"https://api.github.com/users/INRIA/orgs","repos_url":"https://api.github.com/users/INRIA/repos","events_url":"https://api.github.com/users/INRIA/events{/privacy}","received_events_url":"https://api.github.com/users/INRIA/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/INRIA/spoon","description":"Spoon is a library for analyzing, rewriting, transforming Java source code. It parses source files to build a well-designed AST with powerful analysis and transformation API. It fully supports Java 8.  :beers: :sparkles:","fork":false,"url":"https://api.github.com/repos/INRIA/spoon","forks_url":"https://api.github.com/repos/INRIA/spoon/forks","keys_url":"https://api.github.com/repos/INRIA/spoon/keys{/key_id}","collaborators_url":"https://api.github.com/repos/INRIA/spoon/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/INRIA/spoon/teams","hooks_url":"https://api.github.com/repos/INRIA/spoon/hooks","issue_events_url":"https://api.github.com/repos/INRIA/spoon/issues/events{/number}","events_url":"https://api.github.com/repos/INRIA/spoon/events","assignees_url":"https://api.github.com/repos/INRIA/spoon/assignees{/user}","branches_url":"https://api.github.com/repos/INRIA/spoon/branches{/branch}","tags_url":"https://api.github.com/repos/INRIA/spoon/tags","blobs_url":"https://api.github.com/repos/INRIA/spoon/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/INRIA/spoon/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/INRIA/spoon/git/refs{/sha}","trees_url":"https://api.github.com/repos/INRIA/spoon/git/trees{/sha}","statuses_url":"https://api.github.com/repos/INRIA/spoon/statuses/{sha}","languages_url":"https://api.github.com/repos/INRIA/spoon/languages","stargazers_url":"https://api.github.com/repos/INRIA/spoon/stargazers","contributors_url":"https://api.github.com/repos/INRIA/spoon/contributors","subscribers_url":"https://api.github.com/repos/INRIA/spoon/subscribers","subscription_url":"https://api.github.com/repos/INRIA/spoon/subscription","commits_url":"https://api.github.com/repos/INRIA/spoon/commits{/sha}","git_commits_url":"https://api.github.com/repos/INRIA/spoon/git/commits{/sha}","comments_url":"https://api.github.com/repos/INRIA/spoon/comments{/number}","issue_comment_url":"https://api.github.com/repos/INRIA/spoon/issues/comments{/number}","contents_url":"https://api.github.com/repos/INRIA/spoon/contents/{+path}","compare_url":"https://api.github.com/repos/INRIA/spoon/compare/{base}...{head}","merges_url":"https://api.github.com/repos/INRIA/spoon/merges","archive_url":"https://api.github.com/repos/INRIA/spoon/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/INRIA/spoon/downloads","issues_url":"https://api.github.com/repos/INRIA/spoon/issues{/number}","pulls_url":"https://api.github.com/repos/INRIA/spoon/pulls{/number}","milestones_url":"https://api.github.com/repos/INRIA/spoon/milestones{/number}","notifications_url":"https://api.github.com/repos/INRIA/spoon/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/INRIA/spoon/labels{/name}","releases_url":"https://api.github.com/repos/INRIA/spoon/releases{/id}","deployments_url":"https://api.github.com/repos/INRIA/spoon/deployments","created_at":"2013-11-06T15:29:59Z","updated_at":"2016-06-27T11:51:19Z","pushed_at":"2016-07-05T11:27:51Z","git_url":"git://github.com/INRIA/spoon.git","ssh_url":"git@github.com:INRIA/spoon.git","clone_url":"https://github.com/INRIA/spoon.git","svn_url":"https://github.com/INRIA/spoon","homepage":"http://spoon.gforge.inria.fr/","size":16803,"stargazers_count":234,"watchers_count":234,"language":"Java","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":47,"mirror_url":null,"open_issues_count":26,"forks":47,"open_issues":26,"watchers":234,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/INRIA/spoon/pulls/741"},"html":{"href":"https://github.com/INRIA/spoon/pull/741"},"issue":{"href":"https://api.github.com/repos/INRIA/spoon/issues/741"},"comments":{"href":"https://api.github.com/repos/INRIA/spoon/issues/741/comments"},"review_comments":{"href":"https://api.github.com/repos/INRIA/spoon/pulls/741/comments"},"review_comment":{"href":"https://api.github.com/repos/INRIA/spoon/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/INRIA/spoon/pulls/741/commits"},"statuses":{"href":"https://api.github.com/repos/INRIA/spoon/statuses/877668948836f50fe8de67926b08d1bf02129263"}}}}
{"actor":{"display_login":"monperrus"}}