mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-04-19 13:02:30 +07:00
anonymous -> lambda: stop on calls to j.l.Object methods of anonym classes (IDEA-203343)
This commit is contained in:
@@ -472,8 +472,9 @@ public class AnonymousCanBeLambdaInspection extends AbstractBaseJavaLocalInspect
|
||||
PsiCallExpression callExpression) {
|
||||
if (psiMethod != null && !psiMethod.hasModifierProperty(PsiModifier.STATIC)) {
|
||||
final PsiClass containingClass = psiMethod.getContainingClass();
|
||||
if (containingClass != null && CommonClassNames.JAVA_LANG_OBJECT.equals(containingClass.getQualifiedName())) {
|
||||
return false;
|
||||
if (containingClass != null &&
|
||||
CommonClassNames.JAVA_LANG_OBJECT.equals(containingClass.getQualifiedName())) {
|
||||
return !(callExpression instanceof PsiMethodCallExpression && ((PsiMethodCallExpression)callExpression).getMethodExpression().isQualified());
|
||||
}
|
||||
|
||||
if (callExpression instanceof PsiMethodCallExpression &&
|
||||
@@ -517,11 +518,7 @@ public class AnonymousCanBeLambdaInspection extends AbstractBaseJavaLocalInspect
|
||||
super.visitMethodCallExpression(methodCallExpression);
|
||||
final PsiMethod psiMethod = methodCallExpression.resolveMethod();
|
||||
if (psiMethod == myMethod ||
|
||||
functionalInterfaceMethodReferenced(psiMethod, myAnonymClass, methodCallExpression) ||
|
||||
psiMethod != null &&
|
||||
!methodCallExpression.getMethodExpression().isQualified() &&
|
||||
"getClass".equals(psiMethod.getName()) &&
|
||||
psiMethod.getParameterList().isEmpty()) {
|
||||
functionalInterfaceMethodReferenced(psiMethod, myAnonymClass, methodCallExpression)) {
|
||||
myBodyContainsForbiddenRefs = true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
// "Fix all 'Anonymous type can be replaced with lambda' problems in file" "true"
|
||||
import java.util.concurrent.Callable;
|
||||
class MyTest {
|
||||
|
||||
interface A {
|
||||
void foo();
|
||||
default void m() {}
|
||||
}
|
||||
|
||||
static {
|
||||
Callable<Integer> c = new Callable<Integer>() {
|
||||
@Override
|
||||
public Integer call() {
|
||||
return hashCode();
|
||||
}
|
||||
};
|
||||
A a = new A() {
|
||||
@Override
|
||||
public void foo() {
|
||||
m();
|
||||
}
|
||||
};
|
||||
A b = () -> new Object();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
// "Fix all 'Anonymous type can be replaced with lambda' problems in file" "true"
|
||||
import java.util.concurrent.Callable;
|
||||
class MyTest {
|
||||
|
||||
interface A {
|
||||
void foo();
|
||||
default void m() {}
|
||||
}
|
||||
|
||||
static {
|
||||
Callable<Integer> c = new Callable<Integer>() {
|
||||
@Override
|
||||
public Integer call() {
|
||||
return hashCode();
|
||||
}
|
||||
};
|
||||
A a = new A() {
|
||||
@Override
|
||||
public void foo() {
|
||||
m();
|
||||
}
|
||||
};
|
||||
A b = new <caret>A() {
|
||||
@Override
|
||||
public void foo() {
|
||||
new Object();
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user