{"action":"created","comment":{"url":"https://api.github.com/repos/SonarSource/sonarqube/pulls/comments/28333864","id":28333864,"diff_hunk":"@@ -0,0 +1,115 @@\n+/*\n+ * SonarQube, open source software quality management tool.\n+ * Copyright (C) 2008-2014 SonarSource\n+ * mailto:contact AT sonarsource DOT com\n+ *\n+ * SonarQube is free software; you can redistribute it and/or\n+ * modify it under the terms of the GNU Lesser General Public\n+ * License as published by the Free Software Foundation; either\n+ * version 3 of the License, or (at your option) any later version.\n+ *\n+ * SonarQube is distributed in the hope that it will be useful,\n+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\n+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n+ * Lesser General Public License for more details.\n+ *\n+ * You should have received a copy of the GNU Lesser General Public License\n+ * along with this program; if not, write to the Free Software Foundation,\n+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.\n+ */\n+\n+package org.sonar.server.computation.source;\n+\n+import org.sonar.batch.protocol.output.BatchReport;\n+import org.sonar.server.source.db.FileSourceDb;\n+\n+import java.util.Collections;\n+import java.util.Comparator;\n+import java.util.List;\n+import java.util.Map;\n+\n+import static com.google.common.collect.Lists.newArrayList;\n+import static com.google.common.collect.Maps.newHashMap;\n+\n+public class SymbolsLineReader implements LineReader {\n+\n+  private final List<BatchReport.Symbols.Symbol> symbols;\n+  private final Map<BatchReport.Symbols.Symbol, Integer> idsBySymbol;\n+\n+  public SymbolsLineReader(List<BatchReport.Symbols.Symbol> symbols) {\n+    this.symbols = symbols;\n+    sortSymbols();\n+    this.idsBySymbol = createIdsBySymbolMap(symbols);\n+  }\n+\n+  @Override\n+  public void read(FileSourceDb.Line.Builder lineBuilder) {\n+    int line = lineBuilder.getLine();\n+    List<BatchReport.Symbols.Symbol> lineSymbols = findSymbolsMatchingLine(line);\n+    for (BatchReport.Symbols.Symbol lineSymbol : lineSymbols) {\n+      int symbolId = idsBySymbol.get(lineSymbol);\n+      StringBuilder symbolString = new StringBuilder(lineBuilder.getSymbols());\n+\n+      appendSymbol(symbolString, lineSymbol.getDeclaration(), line, symbolId, lineBuilder.getSource());\n+      for (BatchReport.Range range : lineSymbol.getReferenceList()) {\n+        appendSymbol(symbolString, range, line, symbolId, lineBuilder.getSource());\n+      }\n+\n+      if (symbolString.length() > 0) {\n+        lineBuilder.setSymbols(symbolString.toString());\n+      }\n+    }\n+  }\n+\n+  private void appendSymbol(StringBuilder lineSymbol, BatchReport.Range range, int line, int symbolId, String sourceLine) {\n+    if (matchLine(range, line)) {\n+      RangeHelper.appendRange(lineSymbol, range, line, sourceLine.length());\n+      lineSymbol.append(symbolId);\n+    }\n+  }\n+\n+  private List<BatchReport.Symbols.Symbol> findSymbolsMatchingLine(int line) {\n+    List<BatchReport.Symbols.Symbol> lineSymbols = newArrayList();\n+    for (BatchReport.Symbols.Symbol symbol : symbols) {\n+      if (matchLine(symbol.getDeclaration(), line)) {\n+        lineSymbols.add(symbol);\n+      } else {\n+        for (BatchReport.Range range : symbol.getReferenceList()) {\n+          if (matchLine(range, line)) {\n+            lineSymbols.add(symbol);\n+          }\n+        }\n+      }\n+    }\n+    return lineSymbols;\n+  }\n+\n+  private static boolean matchLine(BatchReport.Range range, int line) {\n+    return range.getStartLine() <= line && range.getEndLine() >= line;\n+  }\n+\n+  private void sortSymbols() {","path":"server/sonar-server/src/main/java/org/sonar/server/computation/source/SymbolsLineReader.java","position":null,"original_position":91,"commit_id":"23753e178209cfde90d0b5a3975f5cef7a6ee0d8","original_commit_id":"1175426e8cabbe600e4b4fd53c36c29f160292f9","user":{"login":"teryk","id":1247713,"avatar_url":"https://avatars.githubusercontent.com/u/1247713?v=3","gravatar_id":"","url":"https://api.github.com/users/teryk","html_url":"https://github.com/teryk","followers_url":"https://api.github.com/users/teryk/followers","following_url":"https://api.github.com/users/teryk/following{/other_user}","gists_url":"https://api.github.com/users/teryk/gists{/gist_id}","starred_url":"https://api.github.com/users/teryk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/teryk/subscriptions","organizations_url":"https://api.github.com/users/teryk/orgs","repos_url":"https://api.github.com/users/teryk/repos","events_url":"https://api.github.com/users/teryk/events{/privacy}","received_events_url":"https://api.github.com/users/teryk/received_events","type":"User","site_admin":false},"body":"I wanted to compare with batch way of sorting to check if it's the same ordering","created_at":"2015-04-14T14:53:24Z","updated_at":"2015-04-14T14:53:24Z","html_url":"https://github.com/SonarSource/sonarqube/pull/209#discussion_r28333864","pull_request_url":"https://api.github.com/repos/SonarSource/sonarqube/pulls/209","_links":{"self":{"href":"https://api.github.com/repos/SonarSource/sonarqube/pulls/comments/28333864"},"html":{"href":"https://github.com/SonarSource/sonarqube/pull/209#discussion_r28333864"},"pull_request":{"href":"https://api.github.com/repos/SonarSource/sonarqube/pulls/209"}}},"pull_request":{"url":"https://api.github.com/repos/SonarSource/sonarqube/pulls/209","id":33051705,"html_url":"https://github.com/SonarSource/sonarqube/pull/209","diff_url":"https://github.com/SonarSource/sonarqube/pull/209.diff","patch_url":"https://github.com/SonarSource/sonarqube/pull/209.patch","issue_url":"https://api.github.com/repos/SonarSource/sonarqube/issues/209","number":209,"state":"open","locked":false,"title":"SONAR-6258 Persist symbols into file sources","user":{"login":"julienlancelot","id":370769,"avatar_url":"https://avatars.githubusercontent.com/u/370769?v=3","gravatar_id":"","url":"https://api.github.com/users/julienlancelot","html_url":"https://github.com/julienlancelot","followers_url":"https://api.github.com/users/julienlancelot/followers","following_url":"https://api.github.com/users/julienlancelot/following{/other_user}","gists_url":"https://api.github.com/users/julienlancelot/gists{/gist_id}","starred_url":"https://api.github.com/users/julienlancelot/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/julienlancelot/subscriptions","organizations_url":"https://api.github.com/users/julienlancelot/orgs","repos_url":"https://api.github.com/users/julienlancelot/repos","events_url":"https://api.github.com/users/julienlancelot/events{/privacy}","received_events_url":"https://api.github.com/users/julienlancelot/received_events","type":"User","site_admin":false},"body":"SONAR-6258 Persist symbols into file sources","created_at":"2015-04-10T14:31:24Z","updated_at":"2015-04-14T14:53:24Z","closed_at":null,"merged_at":null,"merge_commit_sha":"03c9c321ac53f49ce051491531b4a7720d1ebec0","assignee":{"login":"julienlancelot","id":370769,"avatar_url":"https://avatars.githubusercontent.com/u/370769?v=3","gravatar_id":"","url":"https://api.github.com/users/julienlancelot","html_url":"https://github.com/julienlancelot","followers_url":"https://api.github.com/users/julienlancelot/followers","following_url":"https://api.github.com/users/julienlancelot/following{/other_user}","gists_url":"https://api.github.com/users/julienlancelot/gists{/gist_id}","starred_url":"https://api.github.com/users/julienlancelot/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/julienlancelot/subscriptions","organizations_url":"https://api.github.com/users/julienlancelot/orgs","repos_url":"https://api.github.com/users/julienlancelot/repos","events_url":"https://api.github.com/users/julienlancelot/events{/privacy}","received_events_url":"https://api.github.com/users/julienlancelot/received_events","type":"User","site_admin":false},"milestone":null,"commits_url":"https://api.github.com/repos/SonarSource/sonarqube/pulls/209/commits","review_comments_url":"https://api.github.com/repos/SonarSource/sonarqube/pulls/209/comments","review_comment_url":"https://api.github.com/repos/SonarSource/sonarqube/pulls/comments{/number}","comments_url":"https://api.github.com/repos/SonarSource/sonarqube/issues/209/comments","statuses_url":"https://api.github.com/repos/SonarSource/sonarqube/statuses/23753e178209cfde90d0b5a3975f5cef7a6ee0d8","head":{"label":"SonarSource:feature/persist_symbols","ref":"feature/persist_symbols","sha":"23753e178209cfde90d0b5a3975f5cef7a6ee0d8","user":{"login":"SonarSource","id":545988,"avatar_url":"https://avatars.githubusercontent.com/u/545988?v=3","gravatar_id":"","url":"https://api.github.com/users/SonarSource","html_url":"https://github.com/SonarSource","followers_url":"https://api.github.com/users/SonarSource/followers","following_url":"https://api.github.com/users/SonarSource/following{/other_user}","gists_url":"https://api.github.com/users/SonarSource/gists{/gist_id}","starred_url":"https://api.github.com/users/SonarSource/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/SonarSource/subscriptions","organizations_url":"https://api.github.com/users/SonarSource/orgs","repos_url":"https://api.github.com/users/SonarSource/repos","events_url":"https://api.github.com/users/SonarSource/events{/privacy}","received_events_url":"https://api.github.com/users/SonarSource/received_events","type":"Organization","site_admin":false},"repo":{"id":1222504,"name":"sonarqube","full_name":"SonarSource/sonarqube","owner":{"login":"SonarSource","id":545988,"avatar_url":"https://avatars.githubusercontent.com/u/545988?v=3","gravatar_id":"","url":"https://api.github.com/users/SonarSource","html_url":"https://github.com/SonarSource","followers_url":"https://api.github.com/users/SonarSource/followers","following_url":"https://api.github.com/users/SonarSource/following{/other_user}","gists_url":"https://api.github.com/users/SonarSource/gists{/gist_id}","starred_url":"https://api.github.com/users/SonarSource/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/SonarSource/subscriptions","organizations_url":"https://api.github.com/users/SonarSource/orgs","repos_url":"https://api.github.com/users/SonarSource/repos","events_url":"https://api.github.com/users/SonarSource/events{/privacy}","received_events_url":"https://api.github.com/users/SonarSource/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/SonarSource/sonarqube","description":"Put your technical debt under control","fork":false,"url":"https://api.github.com/repos/SonarSource/sonarqube","forks_url":"https://api.github.com/repos/SonarSource/sonarqube/forks","keys_url":"https://api.github.com/repos/SonarSource/sonarqube/keys{/key_id}","collaborators_url":"https://api.github.com/repos/SonarSource/sonarqube/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/SonarSource/sonarqube/teams","hooks_url":"https://api.github.com/repos/SonarSource/sonarqube/hooks","issue_events_url":"https://api.github.com/repos/SonarSource/sonarqube/issues/events{/number}","events_url":"https://api.github.com/repos/SonarSource/sonarqube/events","assignees_url":"https://api.github.com/repos/SonarSource/sonarqube/assignees{/user}","branches_url":"https://api.github.com/repos/SonarSource/sonarqube/branches{/branch}","tags_url":"https://api.github.com/repos/SonarSource/sonarqube/tags","blobs_url":"https://api.github.com/repos/SonarSource/sonarqube/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/SonarSource/sonarqube/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/SonarSource/sonarqube/git/refs{/sha}","trees_url":"https://api.github.com/repos/SonarSource/sonarqube/git/trees{/sha}","statuses_url":"https://api.github.com/repos/SonarSource/sonarqube/statuses/{sha}","languages_url":"https://api.github.com/repos/SonarSource/sonarqube/languages","stargazers_url":"https://api.github.com/repos/SonarSource/sonarqube/stargazers","contributors_url":"https://api.github.com/repos/SonarSource/sonarqube/contributors","subscribers_url":"https://api.github.com/repos/SonarSource/sonarqube/subscribers","subscription_url":"https://api.github.com/repos/SonarSource/sonarqube/subscription","commits_url":"https://api.github.com/repos/SonarSource/sonarqube/commits{/sha}","git_commits_url":"https://api.github.com/repos/SonarSource/sonarqube/git/commits{/sha}","comments_url":"https://api.github.com/repos/SonarSource/sonarqube/comments{/number}","issue_comment_url":"https://api.github.com/repos/SonarSource/sonarqube/issues/comments{/number}","contents_url":"https://api.github.com/repos/SonarSource/sonarqube/contents/{+path}","compare_url":"https://api.github.com/repos/SonarSource/sonarqube/compare/{base}...{head}","merges_url":"https://api.github.com/repos/SonarSource/sonarqube/merges","archive_url":"https://api.github.com/repos/SonarSource/sonarqube/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/SonarSource/sonarqube/downloads","issues_url":"https://api.github.com/repos/SonarSource/sonarqube/issues{/number}","pulls_url":"https://api.github.com/repos/SonarSource/sonarqube/pulls{/number}","milestones_url":"https://api.github.com/repos/SonarSource/sonarqube/milestones{/number}","notifications_url":"https://api.github.com/repos/SonarSource/sonarqube/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/SonarSource/sonarqube/labels{/name}","releases_url":"https://api.github.com/repos/SonarSource/sonarqube/releases{/id}","created_at":"2011-01-05T11:05:17Z","updated_at":"2015-04-14T14:39:13Z","pushed_at":"2015-04-14T14:52:37Z","git_url":"git://github.com/SonarSource/sonarqube.git","ssh_url":"git@github.com:SonarSource/sonarqube.git","clone_url":"https://github.com/SonarSource/sonarqube.git","svn_url":"https://github.com/SonarSource/sonarqube","homepage":"http://www.sonarqube.org","size":637915,"stargazers_count":567,"watchers_count":567,"language":"Java","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":318,"mirror_url":null,"open_issues_count":12,"forks":318,"open_issues":12,"watchers":567,"default_branch":"master"}},"base":{"label":"SonarSource:master","ref":"master","sha":"9dda9e9028ef9c76f2ba4e6fd95a1d6dd21f0e94","user":{"login":"SonarSource","id":545988,"avatar_url":"https://avatars.githubusercontent.com/u/545988?v=3","gravatar_id":"","url":"https://api.github.com/users/SonarSource","html_url":"https://github.com/SonarSource","followers_url":"https://api.github.com/users/SonarSource/followers","following_url":"https://api.github.com/users/SonarSource/following{/other_user}","gists_url":"https://api.github.com/users/SonarSource/gists{/gist_id}","starred_url":"https://api.github.com/users/SonarSource/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/SonarSource/subscriptions","organizations_url":"https://api.github.com/users/SonarSource/orgs","repos_url":"https://api.github.com/users/SonarSource/repos","events_url":"https://api.github.com/users/SonarSource/events{/privacy}","received_events_url":"https://api.github.com/users/SonarSource/received_events","type":"Organization","site_admin":false},"repo":{"id":1222504,"name":"sonarqube","full_name":"SonarSource/sonarqube","owner":{"login":"SonarSource","id":545988,"avatar_url":"https://avatars.githubusercontent.com/u/545988?v=3","gravatar_id":"","url":"https://api.github.com/users/SonarSource","html_url":"https://github.com/SonarSource","followers_url":"https://api.github.com/users/SonarSource/followers","following_url":"https://api.github.com/users/SonarSource/following{/other_user}","gists_url":"https://api.github.com/users/SonarSource/gists{/gist_id}","starred_url":"https://api.github.com/users/SonarSource/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/SonarSource/subscriptions","organizations_url":"https://api.github.com/users/SonarSource/orgs","repos_url":"https://api.github.com/users/SonarSource/repos","events_url":"https://api.github.com/users/SonarSource/events{/privacy}","received_events_url":"https://api.github.com/users/SonarSource/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/SonarSource/sonarqube","description":"Put your technical debt under control","fork":false,"url":"https://api.github.com/repos/SonarSource/sonarqube","forks_url":"https://api.github.com/repos/SonarSource/sonarqube/forks","keys_url":"https://api.github.com/repos/SonarSource/sonarqube/keys{/key_id}","collaborators_url":"https://api.github.com/repos/SonarSource/sonarqube/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/SonarSource/sonarqube/teams","hooks_url":"https://api.github.com/repos/SonarSource/sonarqube/hooks","issue_events_url":"https://api.github.com/repos/SonarSource/sonarqube/issues/events{/number}","events_url":"https://api.github.com/repos/SonarSource/sonarqube/events","assignees_url":"https://api.github.com/repos/SonarSource/sonarqube/assignees{/user}","branches_url":"https://api.github.com/repos/SonarSource/sonarqube/branches{/branch}","tags_url":"https://api.github.com/repos/SonarSource/sonarqube/tags","blobs_url":"https://api.github.com/repos/SonarSource/sonarqube/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/SonarSource/sonarqube/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/SonarSource/sonarqube/git/refs{/sha}","trees_url":"https://api.github.com/repos/SonarSource/sonarqube/git/trees{/sha}","statuses_url":"https://api.github.com/repos/SonarSource/sonarqube/statuses/{sha}","languages_url":"https://api.github.com/repos/SonarSource/sonarqube/languages","stargazers_url":"https://api.github.com/repos/SonarSource/sonarqube/stargazers","contributors_url":"https://api.github.com/repos/SonarSource/sonarqube/contributors","subscribers_url":"https://api.github.com/repos/SonarSource/sonarqube/subscribers","subscription_url":"https://api.github.com/repos/SonarSource/sonarqube/subscription","commits_url":"https://api.github.com/repos/SonarSource/sonarqube/commits{/sha}","git_commits_url":"https://api.github.com/repos/SonarSource/sonarqube/git/commits{/sha}","comments_url":"https://api.github.com/repos/SonarSource/sonarqube/comments{/number}","issue_comment_url":"https://api.github.com/repos/SonarSource/sonarqube/issues/comments{/number}","contents_url":"https://api.github.com/repos/SonarSource/sonarqube/contents/{+path}","compare_url":"https://api.github.com/repos/SonarSource/sonarqube/compare/{base}...{head}","merges_url":"https://api.github.com/repos/SonarSource/sonarqube/merges","archive_url":"https://api.github.com/repos/SonarSource/sonarqube/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/SonarSource/sonarqube/downloads","issues_url":"https://api.github.com/repos/SonarSource/sonarqube/issues{/number}","pulls_url":"https://api.github.com/repos/SonarSource/sonarqube/pulls{/number}","milestones_url":"https://api.github.com/repos/SonarSource/sonarqube/milestones{/number}","notifications_url":"https://api.github.com/repos/SonarSource/sonarqube/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/SonarSource/sonarqube/labels{/name}","releases_url":"https://api.github.com/repos/SonarSource/sonarqube/releases{/id}","created_at":"2011-01-05T11:05:17Z","updated_at":"2015-04-14T14:39:13Z","pushed_at":"2015-04-14T14:52:37Z","git_url":"git://github.com/SonarSource/sonarqube.git","ssh_url":"git@github.com:SonarSource/sonarqube.git","clone_url":"https://github.com/SonarSource/sonarqube.git","svn_url":"https://github.com/SonarSource/sonarqube","homepage":"http://www.sonarqube.org","size":637915,"stargazers_count":567,"watchers_count":567,"language":"Java","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":318,"mirror_url":null,"open_issues_count":12,"forks":318,"open_issues":12,"watchers":567,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/SonarSource/sonarqube/pulls/209"},"html":{"href":"https://github.com/SonarSource/sonarqube/pull/209"},"issue":{"href":"https://api.github.com/repos/SonarSource/sonarqube/issues/209"},"comments":{"href":"https://api.github.com/repos/SonarSource/sonarqube/issues/209/comments"},"review_comments":{"href":"https://api.github.com/repos/SonarSource/sonarqube/pulls/209/comments"},"review_comment":{"href":"https://api.github.com/repos/SonarSource/sonarqube/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/SonarSource/sonarqube/pulls/209/commits"},"statuses":{"href":"https://api.github.com/repos/SonarSource/sonarqube/statuses/23753e178209cfde90d0b5a3975f5cef7a6ee0d8"}}}}