From 1d8d3f1134473acdeb58e4515dcf70e60a228c01 Mon Sep 17 00:00:00 2001 From: Anna Kozlova Date: Mon, 26 May 2014 09:45:00 +0400 Subject: [PATCH] lambda: ignore results of assignment is used for expression lambda (IDEA-125473) --- .../NestedAssignmentInspection.java | 6 ++-- .../NestedAssignmentInspectionTest.java | 36 +++++++++++++++++++ 2 files changed, 38 insertions(+), 4 deletions(-) create mode 100644 plugins/InspectionGadgets/testsrc/com/siyeh/ig/assignment/NestedAssignmentInspectionTest.java diff --git a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/assignment/NestedAssignmentInspection.java b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/assignment/NestedAssignmentInspection.java index e28f3238282e..d8a2fe116114 100644 --- a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/assignment/NestedAssignmentInspection.java +++ b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/assignment/NestedAssignmentInspection.java @@ -15,10 +15,7 @@ */ package com.siyeh.ig.assignment; -import com.intellij.psi.PsiAssignmentExpression; -import com.intellij.psi.PsiElement; -import com.intellij.psi.PsiExpressionListStatement; -import com.intellij.psi.PsiExpressionStatement; +import com.intellij.psi.*; import com.siyeh.InspectionGadgetsBundle; import com.siyeh.ig.BaseInspection; import com.siyeh.ig.BaseInspectionVisitor; @@ -57,6 +54,7 @@ public class NestedAssignmentInspection extends BaseInspection { } final PsiElement grandparent = parent.getParent(); if (parent instanceof PsiExpressionStatement || + parent instanceof PsiLambdaExpression || grandparent instanceof PsiExpressionListStatement) { return; } diff --git a/plugins/InspectionGadgets/testsrc/com/siyeh/ig/assignment/NestedAssignmentInspectionTest.java b/plugins/InspectionGadgets/testsrc/com/siyeh/ig/assignment/NestedAssignmentInspectionTest.java new file mode 100644 index 000000000000..61474dbebf9c --- /dev/null +++ b/plugins/InspectionGadgets/testsrc/com/siyeh/ig/assignment/NestedAssignmentInspectionTest.java @@ -0,0 +1,36 @@ +/* + * Copyright 2000-2014 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.ig.assignment; + +import com.intellij.codeInspection.InspectionProfileEntry; +import com.siyeh.ig.LightInspectionTestCase; + +public class NestedAssignmentInspectionTest extends LightInspectionTestCase { + + public void testLambda() throws Exception { + doTest("class Test {" + + " {" + + " int[] array = new int[1];" + + " Runnable r = () -> array[0] = 0;" + + " }" + + "}"); + } + + @Override + protected InspectionProfileEntry getInspection() { + return new NestedAssignmentInspection(); + } +} \ No newline at end of file