From 38c6a24c3935ff3c92c052e210fd95e07fbad38e Mon Sep 17 00:00:00 2001 From: Anna Kozlova Date: Mon, 2 Sep 2013 12:59:52 +0400 Subject: [PATCH] method refs: mismatched collection query (IDEA-112981) --- .../ig/bugs/CollectionQueryCalledVisitor.java | 11 ++++++++++ .../MismatchedCollectionQueryUpdate.java | 21 +++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/bugs/CollectionQueryCalledVisitor.java b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/bugs/CollectionQueryCalledVisitor.java index 2c35b34f7a66..44400f7d4b91 100644 --- a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/bugs/CollectionQueryCalledVisitor.java +++ b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/bugs/CollectionQueryCalledVisitor.java @@ -96,6 +96,17 @@ class CollectionQueryCalledVisitor extends JavaRecursiveElementVisitor { checkQualifier(qualifier); } + + @Override + public void visitMethodReferenceExpression(PsiMethodReferenceExpression expression) { + if (queried) return; + final String methodName = expression.getReferenceName(); + if (methodName == null) { + return; + } + checkQualifier(expression.getQualifierExpression()); + } + private void checkQualifier(PsiExpression expression) { if (queried) { return; diff --git a/plugins/InspectionGadgets/test/com/siyeh/igtest/bugs/mismatched_collection_query_update/MismatchedCollectionQueryUpdate.java b/plugins/InspectionGadgets/test/com/siyeh/igtest/bugs/mismatched_collection_query_update/MismatchedCollectionQueryUpdate.java index e88aa2031cd7..d956505d511c 100644 --- a/plugins/InspectionGadgets/test/com/siyeh/igtest/bugs/mismatched_collection_query_update/MismatchedCollectionQueryUpdate.java +++ b/plugins/InspectionGadgets/test/com/siyeh/igtest/bugs/mismatched_collection_query_update/MismatchedCollectionQueryUpdate.java @@ -1,3 +1,18 @@ +/* + * Copyright 2000-2013 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package com.siyeh.igtest.bugs.mismatched_collection_query_update; import java.util.*; @@ -190,4 +205,10 @@ class MethReference { interface I { boolean _(E e); } + + void qTest() { + Map map = new HashMap<>(); + map.put(1, true); + I mapper = map::get; + } }