{"action":"created","comment":{"url":"https://api.github.com/repos/SonarSource/sonar-java/pulls/comments/127156172","pull_request_review_id":49709556,"id":127156172,"diff_hunk":"@@ -0,0 +1,94 @@\n+/*\n+ * SonarQube Java\n+ * Copyright (C) 2012-2017 SonarSource SA\n+ * mailto:info AT sonarsource DOT com\n+ *\n+ * This program 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+ * This program 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+package org.sonar.java.checks;\n+\n+import com.google.common.collect.ImmutableSet;\n+\n+import org.sonar.check.Rule;\n+import org.sonar.java.checks.methods.AbstractMethodDetection;\n+import org.sonar.java.matcher.MethodMatcher;\n+import org.sonar.java.matcher.MethodMatcherCollection;\n+import org.sonar.plugins.java.api.tree.ExpressionTree;\n+import org.sonar.plugins.java.api.tree.IdentifierTree;\n+import org.sonar.plugins.java.api.tree.MemberSelectExpressionTree;\n+import org.sonar.plugins.java.api.tree.MethodInvocationTree;\n+import org.sonar.plugins.java.api.tree.Tree;\n+\n+import java.util.List;\n+import java.util.Optional;\n+import java.util.Set;\n+import java.util.stream.Collectors;\n+import java.util.stream.Stream;\n+\n+@Rule(key = \"S4034\")\n+public class PreferStreamAnyMatchCheck extends AbstractMethodDetection {\n+\n+  private static final Set<String> STREAM_TYPES = ImmutableSet.of(\"java.util.stream.Stream\", \"java.util.stream.IntStream\", \"java.util.stream.LongStream\",\n+    \"java.util.stream.DoubleStream\");\n+\n+  private static final MethodMatcherCollection FIND_METHODS = MethodMatcherCollection.create();\n+\n+  static {\n+    STREAM_TYPES.forEach(type -> {\n+      FIND_METHODS.add(MethodMatcher.create().typeDefinition(type).name(\"findFirst\").withoutParameter());\n+      FIND_METHODS.add(MethodMatcher.create().typeDefinition(type).name(\"findAny\").withoutParameter());\n+    });\n+  }\n+\n+  private static final MethodMatcherCollection FILTER_METHODS = MethodMatcherCollection.create();\n+\n+  static {\n+    STREAM_TYPES.forEach(type -> FILTER_METHODS.add(MethodMatcher.create().typeDefinition(type).name(\"filter\").withAnyParameters()));\n+  }\n+\n+  @Override\n+  protected List<MethodMatcher> getMethodInvocationMatchers() {\n+    return Stream.of(\"java.util.Optional\", \"java.util.OptionalInt\", \"java.util.OptionalLong\", \"java.util.OptionalDouble\")\n+      .map(type -> MethodMatcher.create().typeDefinition(type).name(\"isPresent\").withoutParameter())\n+      .collect(Collectors.toList());\n+  }\n+\n+  @Override\n+  protected void onMethodInvocationFound(MethodInvocationTree isPresentMIT) {\n+    previousMITInChain(isPresentMIT)\n+      .filter(FIND_METHODS::anyMatch)\n+      .ifPresent(findMIT ->\n+        previousMITInChain(findMIT).filter(FILTER_METHODS::anyMatch)\n+        .ifPresent(filterMIT ->\n+          context.reportIssue(this, identifierFromMethodInvocationChain(filterMIT), identifierFromMethodInvocationChain(isPresentMIT),","path":"java-checks/src/main/java/org/sonar/java/checks/PreferStreamAnyMatchCheck.java","position":null,"original_position":75,"commit_id":"760f6b9bd152a1fa0c5a103a65bd2eb1b8be2c6f","original_commit_id":"fc2d03e71931c168a4d3a279875ad1e3a6afa4c4","user":{"login":"saberduck","id":680437,"avatar_url":"https://avatars2.githubusercontent.com/u/680437?v=3","gravatar_id":"","url":"https://api.github.com/users/saberduck","html_url":"https://github.com/saberduck","followers_url":"https://api.github.com/users/saberduck/followers","following_url":"https://api.github.com/users/saberduck/following{/other_user}","gists_url":"https://api.github.com/users/saberduck/gists{/gist_id}","starred_url":"https://api.github.com/users/saberduck/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/saberduck/subscriptions","organizations_url":"https://api.github.com/users/saberduck/orgs","repos_url":"https://api.github.com/users/saberduck/repos","events_url":"https://api.github.com/users/saberduck/events{/privacy}","received_events_url":"https://api.github.com/users/saberduck/received_events","type":"User","site_admin":false},"body":"I didn't know about that one, good point, thanks!","created_at":"2017-07-13T08:26:02Z","updated_at":"2017-07-13T08:26:02Z","html_url":"https://github.com/SonarSource/sonar-java/pull/1568#discussion_r127156172","pull_request_url":"https://api.github.com/repos/SonarSource/sonar-java/pulls/1568","_links":{"self":{"href":"https://api.github.com/repos/SonarSource/sonar-java/pulls/comments/127156172"},"html":{"href":"https://github.com/SonarSource/sonar-java/pull/1568#discussion_r127156172"},"pull_request":{"href":"https://api.github.com/repos/SonarSource/sonar-java/pulls/1568"}}},"pull_request":{"url":"https://api.github.com/repos/SonarSource/sonar-java/pulls/1568","id":130297657,"html_url":"https://github.com/SonarSource/sonar-java/pull/1568","diff_url":"https://github.com/SonarSource/sonar-java/pull/1568.diff","patch_url":"https://github.com/SonarSource/sonar-java/pull/1568.patch","issue_url":"https://api.github.com/repos/SonarSource/sonar-java/issues/1568","number":1568,"state":"open","locked":false,"title":"SONARJAVA-2352 Stream.anyMatch should be preferred","user":{"login":"saberduck","id":680437,"avatar_url":"https://avatars2.githubusercontent.com/u/680437?v=3","gravatar_id":"","url":"https://api.github.com/users/saberduck","html_url":"https://github.com/saberduck","followers_url":"https://api.github.com/users/saberduck/followers","following_url":"https://api.github.com/users/saberduck/following{/other_user}","gists_url":"https://api.github.com/users/saberduck/gists{/gist_id}","starred_url":"https://api.github.com/users/saberduck/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/saberduck/subscriptions","organizations_url":"https://api.github.com/users/saberduck/orgs","repos_url":"https://api.github.com/users/saberduck/repos","events_url":"https://api.github.com/users/saberduck/events{/privacy}","received_events_url":"https://api.github.com/users/saberduck/received_events","type":"User","site_admin":false},"body":"","created_at":"2017-07-13T06:48:31Z","updated_at":"2017-07-13T08:26:02Z","closed_at":null,"merged_at":null,"merge_commit_sha":"b9d817220963ebc44e9603de82bf8b3746ec8622","assignee":null,"assignees":[],"requested_reviewers":[],"milestone":null,"commits_url":"https://api.github.com/repos/SonarSource/sonar-java/pulls/1568/commits","review_comments_url":"https://api.github.com/repos/SonarSource/sonar-java/pulls/1568/comments","review_comment_url":"https://api.github.com/repos/SonarSource/sonar-java/pulls/comments{/number}","comments_url":"https://api.github.com/repos/SonarSource/sonar-java/issues/1568/comments","statuses_url":"https://api.github.com/repos/SonarSource/sonar-java/statuses/760f6b9bd152a1fa0c5a103a65bd2eb1b8be2c6f","head":{"label":"SonarSource:SONARJAVA-2352","ref":"SONARJAVA-2352","sha":"760f6b9bd152a1fa0c5a103a65bd2eb1b8be2c6f","user":{"login":"SonarSource","id":545988,"avatar_url":"https://avatars3.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":5674787,"name":"sonar-java","full_name":"SonarSource/sonar-java","owner":{"login":"SonarSource","id":545988,"avatar_url":"https://avatars3.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/sonar-java","description":":coffee: SonarJava : Java static analyzer for SonarQube & SonarLint","fork":false,"url":"https://api.github.com/repos/SonarSource/sonar-java","forks_url":"https://api.github.com/repos/SonarSource/sonar-java/forks","keys_url":"https://api.github.com/repos/SonarSource/sonar-java/keys{/key_id}","collaborators_url":"https://api.github.com/repos/SonarSource/sonar-java/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/SonarSource/sonar-java/teams","hooks_url":"https://api.github.com/repos/SonarSource/sonar-java/hooks","issue_events_url":"https://api.github.com/repos/SonarSource/sonar-java/issues/events{/number}","events_url":"https://api.github.com/repos/SonarSource/sonar-java/events","assignees_url":"https://api.github.com/repos/SonarSource/sonar-java/assignees{/user}","branches_url":"https://api.github.com/repos/SonarSource/sonar-java/branches{/branch}","tags_url":"https://api.github.com/repos/SonarSource/sonar-java/tags","blobs_url":"https://api.github.com/repos/SonarSource/sonar-java/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/SonarSource/sonar-java/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/SonarSource/sonar-java/git/refs{/sha}","trees_url":"https://api.github.com/repos/SonarSource/sonar-java/git/trees{/sha}","statuses_url":"https://api.github.com/repos/SonarSource/sonar-java/statuses/{sha}","languages_url":"https://api.github.com/repos/SonarSource/sonar-java/languages","stargazers_url":"https://api.github.com/repos/SonarSource/sonar-java/stargazers","contributors_url":"https://api.github.com/repos/SonarSource/sonar-java/contributors","subscribers_url":"https://api.github.com/repos/SonarSource/sonar-java/subscribers","subscription_url":"https://api.github.com/repos/SonarSource/sonar-java/subscription","commits_url":"https://api.github.com/repos/SonarSource/sonar-java/commits{/sha}","git_commits_url":"https://api.github.com/repos/SonarSource/sonar-java/git/commits{/sha}","comments_url":"https://api.github.com/repos/SonarSource/sonar-java/comments{/number}","issue_comment_url":"https://api.github.com/repos/SonarSource/sonar-java/issues/comments{/number}","contents_url":"https://api.github.com/repos/SonarSource/sonar-java/contents/{+path}","compare_url":"https://api.github.com/repos/SonarSource/sonar-java/compare/{base}...{head}","merges_url":"https://api.github.com/repos/SonarSource/sonar-java/merges","archive_url":"https://api.github.com/repos/SonarSource/sonar-java/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/SonarSource/sonar-java/downloads","issues_url":"https://api.github.com/repos/SonarSource/sonar-java/issues{/number}","pulls_url":"https://api.github.com/repos/SonarSource/sonar-java/pulls{/number}","milestones_url":"https://api.github.com/repos/SonarSource/sonar-java/milestones{/number}","notifications_url":"https://api.github.com/repos/SonarSource/sonar-java/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/SonarSource/sonar-java/labels{/name}","releases_url":"https://api.github.com/repos/SonarSource/sonar-java/releases{/id}","deployments_url":"https://api.github.com/repos/SonarSource/sonar-java/deployments","created_at":"2012-09-04T15:53:13Z","updated_at":"2017-07-11T18:00:47Z","pushed_at":"2017-07-13T08:19:09Z","git_url":"git://github.com/SonarSource/sonar-java.git","ssh_url":"git@github.com:SonarSource/sonar-java.git","clone_url":"https://github.com/SonarSource/sonar-java.git","svn_url":"https://github.com/SonarSource/sonar-java","homepage":"","size":34535,"stargazers_count":192,"watchers_count":192,"language":"Java","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":189,"mirror_url":null,"open_issues_count":3,"forks":189,"open_issues":3,"watchers":192,"default_branch":"master"}},"base":{"label":"SonarSource:master","ref":"master","sha":"cfa67e942c2c3fc26754bb7065ab803eb9d599fe","user":{"login":"SonarSource","id":545988,"avatar_url":"https://avatars3.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":5674787,"name":"sonar-java","full_name":"SonarSource/sonar-java","owner":{"login":"SonarSource","id":545988,"avatar_url":"https://avatars3.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/sonar-java","description":":coffee: SonarJava : Java static analyzer for SonarQube & SonarLint","fork":false,"url":"https://api.github.com/repos/SonarSource/sonar-java","forks_url":"https://api.github.com/repos/SonarSource/sonar-java/forks","keys_url":"https://api.github.com/repos/SonarSource/sonar-java/keys{/key_id}","collaborators_url":"https://api.github.com/repos/SonarSource/sonar-java/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/SonarSource/sonar-java/teams","hooks_url":"https://api.github.com/repos/SonarSource/sonar-java/hooks","issue_events_url":"https://api.github.com/repos/SonarSource/sonar-java/issues/events{/number}","events_url":"https://api.github.com/repos/SonarSource/sonar-java/events","assignees_url":"https://api.github.com/repos/SonarSource/sonar-java/assignees{/user}","branches_url":"https://api.github.com/repos/SonarSource/sonar-java/branches{/branch}","tags_url":"https://api.github.com/repos/SonarSource/sonar-java/tags","blobs_url":"https://api.github.com/repos/SonarSource/sonar-java/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/SonarSource/sonar-java/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/SonarSource/sonar-java/git/refs{/sha}","trees_url":"https://api.github.com/repos/SonarSource/sonar-java/git/trees{/sha}","statuses_url":"https://api.github.com/repos/SonarSource/sonar-java/statuses/{sha}","languages_url":"https://api.github.com/repos/SonarSource/sonar-java/languages","stargazers_url":"https://api.github.com/repos/SonarSource/sonar-java/stargazers","contributors_url":"https://api.github.com/repos/SonarSource/sonar-java/contributors","subscribers_url":"https://api.github.com/repos/SonarSource/sonar-java/subscribers","subscription_url":"https://api.github.com/repos/SonarSource/sonar-java/subscription","commits_url":"https://api.github.com/repos/SonarSource/sonar-java/commits{/sha}","git_commits_url":"https://api.github.com/repos/SonarSource/sonar-java/git/commits{/sha}","comments_url":"https://api.github.com/repos/SonarSource/sonar-java/comments{/number}","issue_comment_url":"https://api.github.com/repos/SonarSource/sonar-java/issues/comments{/number}","contents_url":"https://api.github.com/repos/SonarSource/sonar-java/contents/{+path}","compare_url":"https://api.github.com/repos/SonarSource/sonar-java/compare/{base}...{head}","merges_url":"https://api.github.com/repos/SonarSource/sonar-java/merges","archive_url":"https://api.github.com/repos/SonarSource/sonar-java/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/SonarSource/sonar-java/downloads","issues_url":"https://api.github.com/repos/SonarSource/sonar-java/issues{/number}","pulls_url":"https://api.github.com/repos/SonarSource/sonar-java/pulls{/number}","milestones_url":"https://api.github.com/repos/SonarSource/sonar-java/milestones{/number}","notifications_url":"https://api.github.com/repos/SonarSource/sonar-java/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/SonarSource/sonar-java/labels{/name}","releases_url":"https://api.github.com/repos/SonarSource/sonar-java/releases{/id}","deployments_url":"https://api.github.com/repos/SonarSource/sonar-java/deployments","created_at":"2012-09-04T15:53:13Z","updated_at":"2017-07-11T18:00:47Z","pushed_at":"2017-07-13T08:19:09Z","git_url":"git://github.com/SonarSource/sonar-java.git","ssh_url":"git@github.com:SonarSource/sonar-java.git","clone_url":"https://github.com/SonarSource/sonar-java.git","svn_url":"https://github.com/SonarSource/sonar-java","homepage":"","size":34535,"stargazers_count":192,"watchers_count":192,"language":"Java","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":189,"mirror_url":null,"open_issues_count":3,"forks":189,"open_issues":3,"watchers":192,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/SonarSource/sonar-java/pulls/1568"},"html":{"href":"https://github.com/SonarSource/sonar-java/pull/1568"},"issue":{"href":"https://api.github.com/repos/SonarSource/sonar-java/issues/1568"},"comments":{"href":"https://api.github.com/repos/SonarSource/sonar-java/issues/1568/comments"},"review_comments":{"href":"https://api.github.com/repos/SonarSource/sonar-java/pulls/1568/comments"},"review_comment":{"href":"https://api.github.com/repos/SonarSource/sonar-java/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/SonarSource/sonar-java/pulls/1568/commits"},"statuses":{"href":"https://api.github.com/repos/SonarSource/sonar-java/statuses/760f6b9bd152a1fa0c5a103a65bd2eb1b8be2c6f"}}}}
{"actor":{"display_login":"saberduck"}}