abstract method call in constructor: don't warn inside lambda body

This commit is contained in:
Anna.Kozlova
2016-04-12 16:34:07 +02:00
parent f0b218fc5c
commit 503c2c1d1a
3 changed files with 45 additions and 1 deletions
@@ -150,7 +150,7 @@ public class MethodCallUtils {
}
public static boolean isCallDuringObjectConstruction(PsiMethodCallExpression expression) {
final PsiMember member = PsiTreeUtil.getParentOfType(expression, PsiMethod.class, PsiClassInitializer.class, PsiField.class);
final PsiMember member = PsiTreeUtil.getParentOfType(expression, PsiMember.class, true, PsiClass.class, PsiLambdaExpression.class);
if (member == null) {
return false;
}
@@ -0,0 +1,13 @@
abstract class A {
public A() {
Runnable r = () -> foo();
Runnable r1 = new Runnable() {
public void run() {
foo();
}
};
}
abstract void foo();
}
@@ -0,0 +1,31 @@
/*
* Copyright 2000-2016 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.initialization;
import com.intellij.codeInspection.InspectionProfileEntry;
import com.siyeh.ig.LightInspectionTestCase;
public class AbstractMethodCallInConstructorInspectionTest extends LightInspectionTestCase {
public void testAbstractMethodCallInConstructor() {
doTest();
}
@Override
protected InspectionProfileEntry getInspection() {
return new AbstractMethodCallInConstructorInspection();
}
}