{"action":"created","comment":{"url":"https://api.github.com/repos/square/javapoet/pulls/comments/32654949","id":32654949,"diff_hunk":"@@ -106,41 +107,69 @@ public Builder add(String format, Object... args) {\n         if (format.charAt(p) != '$') {\n           nextP = format.indexOf('$', p + 1);\n           if (nextP == -1) nextP = format.length();\n+          formatParts.add(format.substring(p, nextP));\n         } else {\n-          checkState(p + 1 < format.length(), \"dangling $ in format string %s\", format);\n-          switch (format.charAt(p + 1)) {\n+          checkState(p <= format.length(), \"dangling $ in format string %s\", format);\n+          /* Rules:\n+           * Format must be in the form $[Numeric Index]{N, L, S, T}\n+           * OR\n+           * in the form ${$, >, <, [, ]}\n+           * Numeric index is ONE BASED (for consistency with java formatting)\n+           * Numeric indexing must refer to a format argument within the args array\n+           * Only progress iteration over the argument iterator if we do not hit an indexed entry\n+           */\n+          int countOfIndexCharacters = 0;\n+          while (isSimpleDigit(format.charAt(p + countOfIndexCharacters + 1))) {\n+            countOfIndexCharacters++;\n+          }\n+          int argsIndex = -1;\n+          if (countOfIndexCharacters != 0) {\n+            argsIndex = Integer.parseInt(format.substring(p + 1, p + 1 + countOfIndexCharacters));\n+            checkArgument(argsIndex <= args.length,\n+                \"Argument index %s in '%s' is larger than number of parameters\",\n+                argsIndex, format);\n+            checkArgument(argsIndex > 0,","path":"src/main/java/com/squareup/javapoet/CodeBlock.java","position":35,"original_position":35,"commit_id":"1bf5813a21f34f7e143cc8f5a63d7b5947d904e9","original_commit_id":"1bf5813a21f34f7e143cc8f5a63d7b5947d904e9","user":{"login":"swankjesse","id":133019,"avatar_url":"https://avatars.githubusercontent.com/u/133019?v=3","gravatar_id":"","url":"https://api.github.com/users/swankjesse","html_url":"https://github.com/swankjesse","followers_url":"https://api.github.com/users/swankjesse/followers","following_url":"https://api.github.com/users/swankjesse/following{/other_user}","gists_url":"https://api.github.com/users/swankjesse/gists{/gist_id}","starred_url":"https://api.github.com/users/swankjesse/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/swankjesse/subscriptions","organizations_url":"https://api.github.com/users/swankjesse/orgs","repos_url":"https://api.github.com/users/swankjesse/repos","events_url":"https://api.github.com/users/swankjesse/events{/privacy}","received_events_url":"https://api.github.com/users/swankjesse/received_events","type":"User","site_admin":false},"body":"I think you can drop this case; we never accept the `-` character anywhere.","created_at":"2015-06-17T17:55:28Z","updated_at":"2015-06-17T17:55:28Z","html_url":"https://github.com/square/javapoet/pull/293#discussion_r32654949","pull_request_url":"https://api.github.com/repos/square/javapoet/pulls/293","_links":{"self":{"href":"https://api.github.com/repos/square/javapoet/pulls/comments/32654949"},"html":{"href":"https://github.com/square/javapoet/pull/293#discussion_r32654949"},"pull_request":{"href":"https://api.github.com/repos/square/javapoet/pulls/293"}}},"pull_request":{"url":"https://api.github.com/repos/square/javapoet/pulls/293","id":37755096,"html_url":"https://github.com/square/javapoet/pull/293","diff_url":"https://github.com/square/javapoet/pull/293.diff","patch_url":"https://github.com/square/javapoet/pull/293.patch","issue_url":"https://api.github.com/repos/square/javapoet/issues/293","number":293,"state":"open","locked":false,"title":"Added the ability to use indexes in format arguments","user":{"login":"APaloski","id":3758327,"avatar_url":"https://avatars.githubusercontent.com/u/3758327?v=3","gravatar_id":"","url":"https://api.github.com/users/APaloski","html_url":"https://github.com/APaloski","followers_url":"https://api.github.com/users/APaloski/followers","following_url":"https://api.github.com/users/APaloski/following{/other_user}","gists_url":"https://api.github.com/users/APaloski/gists{/gist_id}","starred_url":"https://api.github.com/users/APaloski/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/APaloski/subscriptions","organizations_url":"https://api.github.com/users/APaloski/orgs","repos_url":"https://api.github.com/users/APaloski/repos","events_url":"https://api.github.com/users/APaloski/events{/privacy}","received_events_url":"https://api.github.com/users/APaloski/received_events","type":"User","site_admin":false},"body":"In response to issue #238 I added in the ability to use indexes in the format strings.\r\n\r\nI used the $-index-format syntax discussed in that thread and made the index start at one to be consistent with the way that java formatters act.","created_at":"2015-06-16T02:47:21Z","updated_at":"2015-06-17T17:55:28Z","closed_at":null,"merged_at":null,"merge_commit_sha":"0d77f1a7fcd2e93a170666feb0cb6dc4f2e069f8","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/square/javapoet/pulls/293/commits","review_comments_url":"https://api.github.com/repos/square/javapoet/pulls/293/comments","review_comment_url":"https://api.github.com/repos/square/javapoet/pulls/comments{/number}","comments_url":"https://api.github.com/repos/square/javapoet/issues/293/comments","statuses_url":"https://api.github.com/repos/square/javapoet/statuses/1bf5813a21f34f7e143cc8f5a63d7b5947d904e9","head":{"label":"APaloski:master","ref":"master","sha":"1bf5813a21f34f7e143cc8f5a63d7b5947d904e9","user":{"login":"APaloski","id":3758327,"avatar_url":"https://avatars.githubusercontent.com/u/3758327?v=3","gravatar_id":"","url":"https://api.github.com/users/APaloski","html_url":"https://github.com/APaloski","followers_url":"https://api.github.com/users/APaloski/followers","following_url":"https://api.github.com/users/APaloski/following{/other_user}","gists_url":"https://api.github.com/users/APaloski/gists{/gist_id}","starred_url":"https://api.github.com/users/APaloski/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/APaloski/subscriptions","organizations_url":"https://api.github.com/users/APaloski/orgs","repos_url":"https://api.github.com/users/APaloski/repos","events_url":"https://api.github.com/users/APaloski/events{/privacy}","received_events_url":"https://api.github.com/users/APaloski/received_events","type":"User","site_admin":false},"repo":{"id":37435238,"name":"javapoet","full_name":"APaloski/javapoet","owner":{"login":"APaloski","id":3758327,"avatar_url":"https://avatars.githubusercontent.com/u/3758327?v=3","gravatar_id":"","url":"https://api.github.com/users/APaloski","html_url":"https://github.com/APaloski","followers_url":"https://api.github.com/users/APaloski/followers","following_url":"https://api.github.com/users/APaloski/following{/other_user}","gists_url":"https://api.github.com/users/APaloski/gists{/gist_id}","starred_url":"https://api.github.com/users/APaloski/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/APaloski/subscriptions","organizations_url":"https://api.github.com/users/APaloski/orgs","repos_url":"https://api.github.com/users/APaloski/repos","events_url":"https://api.github.com/users/APaloski/events{/privacy}","received_events_url":"https://api.github.com/users/APaloski/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/APaloski/javapoet","description":"A Java API for generating .java source files.","fork":true,"url":"https://api.github.com/repos/APaloski/javapoet","forks_url":"https://api.github.com/repos/APaloski/javapoet/forks","keys_url":"https://api.github.com/repos/APaloski/javapoet/keys{/key_id}","collaborators_url":"https://api.github.com/repos/APaloski/javapoet/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/APaloski/javapoet/teams","hooks_url":"https://api.github.com/repos/APaloski/javapoet/hooks","issue_events_url":"https://api.github.com/repos/APaloski/javapoet/issues/events{/number}","events_url":"https://api.github.com/repos/APaloski/javapoet/events","assignees_url":"https://api.github.com/repos/APaloski/javapoet/assignees{/user}","branches_url":"https://api.github.com/repos/APaloski/javapoet/branches{/branch}","tags_url":"https://api.github.com/repos/APaloski/javapoet/tags","blobs_url":"https://api.github.com/repos/APaloski/javapoet/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/APaloski/javapoet/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/APaloski/javapoet/git/refs{/sha}","trees_url":"https://api.github.com/repos/APaloski/javapoet/git/trees{/sha}","statuses_url":"https://api.github.com/repos/APaloski/javapoet/statuses/{sha}","languages_url":"https://api.github.com/repos/APaloski/javapoet/languages","stargazers_url":"https://api.github.com/repos/APaloski/javapoet/stargazers","contributors_url":"https://api.github.com/repos/APaloski/javapoet/contributors","subscribers_url":"https://api.github.com/repos/APaloski/javapoet/subscribers","subscription_url":"https://api.github.com/repos/APaloski/javapoet/subscription","commits_url":"https://api.github.com/repos/APaloski/javapoet/commits{/sha}","git_commits_url":"https://api.github.com/repos/APaloski/javapoet/git/commits{/sha}","comments_url":"https://api.github.com/repos/APaloski/javapoet/comments{/number}","issue_comment_url":"https://api.github.com/repos/APaloski/javapoet/issues/comments{/number}","contents_url":"https://api.github.com/repos/APaloski/javapoet/contents/{+path}","compare_url":"https://api.github.com/repos/APaloski/javapoet/compare/{base}...{head}","merges_url":"https://api.github.com/repos/APaloski/javapoet/merges","archive_url":"https://api.github.com/repos/APaloski/javapoet/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/APaloski/javapoet/downloads","issues_url":"https://api.github.com/repos/APaloski/javapoet/issues{/number}","pulls_url":"https://api.github.com/repos/APaloski/javapoet/pulls{/number}","milestones_url":"https://api.github.com/repos/APaloski/javapoet/milestones{/number}","notifications_url":"https://api.github.com/repos/APaloski/javapoet/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/APaloski/javapoet/labels{/name}","releases_url":"https://api.github.com/repos/APaloski/javapoet/releases{/id}","created_at":"2015-06-15T00:28:40Z","updated_at":"2015-06-15T00:28:40Z","pushed_at":"2015-06-17T01:31:40Z","git_url":"git://github.com/APaloski/javapoet.git","ssh_url":"git@github.com:APaloski/javapoet.git","clone_url":"https://github.com/APaloski/javapoet.git","svn_url":"https://github.com/APaloski/javapoet","homepage":"","size":1086,"stargazers_count":0,"watchers_count":0,"language":"Java","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":true,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"square:master","ref":"master","sha":"9c15424252db0f8179d381c322439630f97377f0","user":{"login":"square","id":82592,"avatar_url":"https://avatars.githubusercontent.com/u/82592?v=3","gravatar_id":"","url":"https://api.github.com/users/square","html_url":"https://github.com/square","followers_url":"https://api.github.com/users/square/followers","following_url":"https://api.github.com/users/square/following{/other_user}","gists_url":"https://api.github.com/users/square/gists{/gist_id}","starred_url":"https://api.github.com/users/square/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/square/subscriptions","organizations_url":"https://api.github.com/users/square/orgs","repos_url":"https://api.github.com/users/square/repos","events_url":"https://api.github.com/users/square/events{/privacy}","received_events_url":"https://api.github.com/users/square/received_events","type":"Organization","site_admin":false},"repo":{"id":7961991,"name":"javapoet","full_name":"square/javapoet","owner":{"login":"square","id":82592,"avatar_url":"https://avatars.githubusercontent.com/u/82592?v=3","gravatar_id":"","url":"https://api.github.com/users/square","html_url":"https://github.com/square","followers_url":"https://api.github.com/users/square/followers","following_url":"https://api.github.com/users/square/following{/other_user}","gists_url":"https://api.github.com/users/square/gists{/gist_id}","starred_url":"https://api.github.com/users/square/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/square/subscriptions","organizations_url":"https://api.github.com/users/square/orgs","repos_url":"https://api.github.com/users/square/repos","events_url":"https://api.github.com/users/square/events{/privacy}","received_events_url":"https://api.github.com/users/square/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/square/javapoet","description":"A Java API for generating .java source files.","fork":false,"url":"https://api.github.com/repos/square/javapoet","forks_url":"https://api.github.com/repos/square/javapoet/forks","keys_url":"https://api.github.com/repos/square/javapoet/keys{/key_id}","collaborators_url":"https://api.github.com/repos/square/javapoet/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/square/javapoet/teams","hooks_url":"https://api.github.com/repos/square/javapoet/hooks","issue_events_url":"https://api.github.com/repos/square/javapoet/issues/events{/number}","events_url":"https://api.github.com/repos/square/javapoet/events","assignees_url":"https://api.github.com/repos/square/javapoet/assignees{/user}","branches_url":"https://api.github.com/repos/square/javapoet/branches{/branch}","tags_url":"https://api.github.com/repos/square/javapoet/tags","blobs_url":"https://api.github.com/repos/square/javapoet/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/square/javapoet/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/square/javapoet/git/refs{/sha}","trees_url":"https://api.github.com/repos/square/javapoet/git/trees{/sha}","statuses_url":"https://api.github.com/repos/square/javapoet/statuses/{sha}","languages_url":"https://api.github.com/repos/square/javapoet/languages","stargazers_url":"https://api.github.com/repos/square/javapoet/stargazers","contributors_url":"https://api.github.com/repos/square/javapoet/contributors","subscribers_url":"https://api.github.com/repos/square/javapoet/subscribers","subscription_url":"https://api.github.com/repos/square/javapoet/subscription","commits_url":"https://api.github.com/repos/square/javapoet/commits{/sha}","git_commits_url":"https://api.github.com/repos/square/javapoet/git/commits{/sha}","comments_url":"https://api.github.com/repos/square/javapoet/comments{/number}","issue_comment_url":"https://api.github.com/repos/square/javapoet/issues/comments{/number}","contents_url":"https://api.github.com/repos/square/javapoet/contents/{+path}","compare_url":"https://api.github.com/repos/square/javapoet/compare/{base}...{head}","merges_url":"https://api.github.com/repos/square/javapoet/merges","archive_url":"https://api.github.com/repos/square/javapoet/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/square/javapoet/downloads","issues_url":"https://api.github.com/repos/square/javapoet/issues{/number}","pulls_url":"https://api.github.com/repos/square/javapoet/pulls{/number}","milestones_url":"https://api.github.com/repos/square/javapoet/milestones{/number}","notifications_url":"https://api.github.com/repos/square/javapoet/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/square/javapoet/labels{/name}","releases_url":"https://api.github.com/repos/square/javapoet/releases{/id}","created_at":"2013-02-01T16:56:30Z","updated_at":"2015-06-17T17:34:00Z","pushed_at":"2015-06-17T01:31:41Z","git_url":"git://github.com/square/javapoet.git","ssh_url":"git@github.com:square/javapoet.git","clone_url":"https://github.com/square/javapoet.git","svn_url":"https://github.com/square/javapoet","homepage":"","size":3053,"stargazers_count":1031,"watchers_count":1031,"language":"Java","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":true,"forks_count":163,"mirror_url":null,"open_issues_count":11,"forks":163,"open_issues":11,"watchers":1031,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/square/javapoet/pulls/293"},"html":{"href":"https://github.com/square/javapoet/pull/293"},"issue":{"href":"https://api.github.com/repos/square/javapoet/issues/293"},"comments":{"href":"https://api.github.com/repos/square/javapoet/issues/293/comments"},"review_comments":{"href":"https://api.github.com/repos/square/javapoet/pulls/293/comments"},"review_comment":{"href":"https://api.github.com/repos/square/javapoet/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/square/javapoet/pulls/293/commits"},"statuses":{"href":"https://api.github.com/repos/square/javapoet/statuses/1bf5813a21f34f7e143cc8f5a63d7b5947d904e9"}}}}