lambda: ignore results of assignment is used for expression lambda (IDEA-125473)

This commit is contained in:
Anna Kozlova
2014-05-26 09:45:00 +04:00
parent eaa9ce63f6
commit 1d8d3f1134
2 changed files with 38 additions and 4 deletions
@@ -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;
}
@@ -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();
}
}