mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-18 09:34:34 +07:00
convert lambda to method reference: expand the acceptance range when not visible
This commit is contained in:
+6
-2
@@ -23,6 +23,7 @@ import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.Condition;
|
||||
import com.intellij.openapi.util.Conditions;
|
||||
import com.intellij.pom.java.LanguageLevel;
|
||||
import com.intellij.profile.codeInspection.InspectionProjectProfileManager;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.codeStyle.JavaCodeStyleManager;
|
||||
import com.intellij.psi.impl.source.resolve.graphInference.FunctionalInterfaceParameterizationUtil;
|
||||
@@ -102,7 +103,7 @@ public class LambdaCanBeMethodReferenceInspection extends BaseJavaBatchLocalInsp
|
||||
final PsiExpression candidate =
|
||||
canBeMethodReferenceProblem(body, expression.getParameterList().getParameters(), functionalInterfaceType, null);
|
||||
if (candidate != null) {
|
||||
holder.registerProblem(candidate,
|
||||
holder.registerProblem(InspectionProjectProfileManager.isInformationLevel(getShortName(), expression) ? expression : candidate,
|
||||
"Can be replaced with method reference",
|
||||
ProblemHighlightType.GENERIC_ERROR_OR_WARNING, new ReplaceWithMethodRefFix());
|
||||
}
|
||||
@@ -586,8 +587,11 @@ public class LambdaCanBeMethodReferenceInspection extends BaseJavaBatchLocalInsp
|
||||
|
||||
@Override
|
||||
public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) {
|
||||
final PsiElement element = descriptor.getPsiElement();
|
||||
PsiElement element = descriptor.getPsiElement();
|
||||
if (!FileModificationService.getInstance().preparePsiElementForWrite(element)) return;
|
||||
if (element instanceof PsiLambdaExpression) {
|
||||
element = LambdaUtil.extractSingleExpressionFromBody(((PsiLambdaExpression)element).getBody());
|
||||
}
|
||||
final PsiLambdaExpression lambdaExpression = PsiTreeUtil.getParentOfType(element, PsiLambdaExpression.class);
|
||||
if (lambdaExpression == null) return;
|
||||
tryConvertToMethodReference(lambdaExpression, element);
|
||||
|
||||
+11
@@ -15,6 +15,8 @@
|
||||
*/
|
||||
package com.intellij.profile.codeInspection;
|
||||
|
||||
import com.intellij.codeHighlighting.HighlightDisplayLevel;
|
||||
import com.intellij.codeInsight.daemon.HighlightDisplayKey;
|
||||
import com.intellij.codeInspection.InspectionProfile;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.psi.PsiElement;
|
||||
@@ -40,4 +42,13 @@ public abstract class InspectionProjectProfileManager implements InspectionProfi
|
||||
public InspectionProfile getInspectionProfile(PsiElement element){
|
||||
return getCurrentProfile();
|
||||
}
|
||||
|
||||
public static boolean isInformationLevel(String shortName, @NotNull PsiElement element) {
|
||||
final HighlightDisplayKey key = HighlightDisplayKey.find(shortName);
|
||||
if (key != null) {
|
||||
final HighlightDisplayLevel errorLevel = getInstance(element.getProject()).getCurrentProfile().getErrorLevel(key, element);
|
||||
return HighlightDisplayLevel.DO_NOT_SHOW.equals(errorLevel);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -146,7 +146,7 @@ public abstract class ControlFlowStatementVisitorBase extends BaseInspectionVisi
|
||||
}
|
||||
if (myKey != null) {
|
||||
final Project project = element.getProject();
|
||||
final InspectionProfile profile = InspectionProjectProfileManager.getInstance(project).getInspectionProfile();
|
||||
final InspectionProfile profile = InspectionProjectProfileManager.getInstance(project).getCurrentProfile();
|
||||
final HighlightDisplayLevel errorLevel = profile.getErrorLevel(myKey, element);
|
||||
return !HighlightDisplayLevel.DO_NOT_SHOW.equals(errorLevel);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user