mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-18 09:34:34 +07:00
remove this qualifier on anonym -> method ref fix
This commit is contained in:
+2
-3
@@ -19,7 +19,6 @@ import com.intellij.codeInsight.FileModificationService;
|
||||
import com.intellij.codeInsight.daemon.GroupNames;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.Condition;
|
||||
import com.intellij.openapi.util.TextRange;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.codeStyle.JavaCodeStyleManager;
|
||||
@@ -69,7 +68,7 @@ public class AnonymousCanBeMethodReferenceInspection extends BaseJavaBatchLocalI
|
||||
final PsiMethod method = aClass.getMethods()[0];
|
||||
final PsiCodeBlock body = method.getBody();
|
||||
final PsiCallExpression callExpression =
|
||||
LambdaCanBeMethodReferenceInspection.canBeMethodReferenceProblem(body, method.getParameterList().getParameters(), aClass.getBaseClassType());
|
||||
LambdaCanBeMethodReferenceInspection.canBeMethodReferenceProblem(body, method.getParameterList().getParameters(), aClass.getBaseClassType(), aClass.getParent());
|
||||
if (callExpression != null) {
|
||||
final PsiMethod resolveMethod = callExpression.resolveMethod();
|
||||
if (resolveMethod != method &&
|
||||
@@ -118,7 +117,7 @@ public class AnonymousCanBeMethodReferenceInspection extends BaseJavaBatchLocalI
|
||||
|
||||
final PsiParameter[] parameters = methods[0].getParameterList().getParameters();
|
||||
final PsiCallExpression callExpression = LambdaCanBeMethodReferenceInspection
|
||||
.canBeMethodReferenceProblem(methods[0].getBody(), parameters, anonymousClass.getBaseClassType());
|
||||
.canBeMethodReferenceProblem(methods[0].getBody(), parameters, anonymousClass.getBaseClassType(), anonymousClass.getParent());
|
||||
if (callExpression == null) return;
|
||||
final String methodRefText =
|
||||
LambdaCanBeMethodReferenceInspection.createMethodReferenceText(callExpression, anonymousClass.getBaseClassType(), parameters);
|
||||
|
||||
+15
-4
@@ -89,8 +89,16 @@ public class LambdaCanBeMethodReferenceInspection extends BaseJavaBatchLocalInsp
|
||||
|
||||
@Nullable
|
||||
public static PsiCallExpression canBeMethodReferenceProblem(@Nullable final PsiElement body,
|
||||
final PsiParameter[] parameters,
|
||||
PsiType functionalInterfaceType) {
|
||||
final PsiParameter[] parameters,
|
||||
final PsiType functionalInterfaceType) {
|
||||
return canBeMethodReferenceProblem(body, parameters, functionalInterfaceType, null);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static PsiCallExpression canBeMethodReferenceProblem(@Nullable final PsiElement body,
|
||||
final PsiParameter[] parameters,
|
||||
PsiType functionalInterfaceType,
|
||||
@Nullable PsiElement context) {
|
||||
final PsiCallExpression callExpression = extractMethodCallFromBlock(body);
|
||||
if (callExpression instanceof PsiNewExpression) {
|
||||
final PsiNewExpression newExpression = (PsiNewExpression)callExpression;
|
||||
@@ -104,7 +112,7 @@ public class LambdaCanBeMethodReferenceInspection extends BaseJavaBatchLocalInsp
|
||||
LOG.assertTrue(callExpression != null);
|
||||
final PsiElementFactory elementFactory = JavaPsiFacade.getElementFactory(callExpression.getProject());
|
||||
final PsiMethodReferenceExpression methodReferenceExpression =
|
||||
(PsiMethodReferenceExpression)elementFactory.createExpressionFromText(methodReferenceText, callExpression);
|
||||
(PsiMethodReferenceExpression)elementFactory.createExpressionFromText(methodReferenceText, context != null ? context : callExpression);
|
||||
final Map<PsiElement, PsiType> map = LambdaUtil.getFunctionalTypeMap();
|
||||
try {
|
||||
map.put(methodReferenceExpression, functionalInterfaceType);
|
||||
@@ -367,7 +375,10 @@ public class LambdaCanBeMethodReferenceInspection extends BaseJavaBatchLocalInsp
|
||||
return getClassReferenceName(containingClass);
|
||||
}
|
||||
else {
|
||||
final PsiClass parentContainingClass = PsiTreeUtil.getParentOfType(methodCall, PsiClass.class);
|
||||
PsiClass parentContainingClass = PsiTreeUtil.getParentOfType(methodCall, PsiClass.class);
|
||||
if (parentContainingClass instanceof PsiAnonymousClass) {
|
||||
parentContainingClass = PsiTreeUtil.getParentOfType(parentContainingClass, PsiClass.class, true);
|
||||
}
|
||||
PsiClass treeContainingClass = parentContainingClass;
|
||||
while (treeContainingClass != null && !InheritanceUtil.isInheritorOrSelf(treeContainingClass, containingClass, true)) {
|
||||
treeContainingClass = PsiTreeUtil.getParentOfType(treeContainingClass, PsiClass.class, true);
|
||||
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
// "Replace with method reference" "true"
|
||||
class Test {
|
||||
|
||||
private void doTest (){}
|
||||
|
||||
void foo(Runnable r){}
|
||||
|
||||
{
|
||||
foo (this::doTest);
|
||||
}
|
||||
|
||||
}
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
// "Replace with method reference" "true"
|
||||
class Test {
|
||||
|
||||
private void doTest (){}
|
||||
|
||||
void foo(Runnable r){}
|
||||
|
||||
{
|
||||
foo (new Ru<caret>nnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
doTest();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user