mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
cleanup language level checks for inspection applicability
This commit is contained in:
+14
-14
@@ -44,24 +44,24 @@ public class RedundantLambdaCodeBlockInspection extends AbstractBaseJavaLocalIns
|
||||
@NotNull
|
||||
@Override
|
||||
public PsiElementVisitor buildVisitor(@NotNull final ProblemsHolder holder, boolean isOnTheFly) {
|
||||
if (!PsiUtil.isLanguageLevel8OrHigher(holder.getFile())) {
|
||||
return PsiElementVisitor.EMPTY_VISITOR;
|
||||
}
|
||||
return new JavaElementVisitor() {
|
||||
@Override
|
||||
public void visitLambdaExpression(PsiLambdaExpression expression) {
|
||||
super.visitLambdaExpression(expression);
|
||||
if (PsiUtil.isLanguageLevel8OrHigher(expression)) {
|
||||
final PsiElement body = expression.getBody();
|
||||
final PsiExpression psiExpression = isCodeBlockRedundant(body);
|
||||
if (psiExpression != null) {
|
||||
final PsiElement errorElement;
|
||||
final PsiElement parent = psiExpression.getParent();
|
||||
if (parent instanceof PsiReturnStatement) {
|
||||
errorElement = parent.getFirstChild();
|
||||
} else {
|
||||
errorElement = body.getFirstChild();
|
||||
}
|
||||
holder.registerProblem(errorElement, "Statement lambda can be replaced with expression lambda",
|
||||
ProblemHighlightType.LIKE_UNUSED_SYMBOL, new ReplaceWithExprFix());
|
||||
final PsiElement body = expression.getBody();
|
||||
final PsiExpression psiExpression = isCodeBlockRedundant(body);
|
||||
if (psiExpression != null) {
|
||||
final PsiElement errorElement;
|
||||
final PsiElement parent = psiExpression.getParent();
|
||||
if (parent instanceof PsiReturnStatement) {
|
||||
errorElement = parent.getFirstChild();
|
||||
} else {
|
||||
errorElement = body.getFirstChild();
|
||||
}
|
||||
holder.registerProblem(errorElement, "Statement lambda can be replaced with expression lambda",
|
||||
ProblemHighlightType.LIKE_UNUSED_SYMBOL, new ReplaceWithExprFix());
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
+1
-2
@@ -2,7 +2,6 @@
|
||||
package com.intellij.codeInspection;
|
||||
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.pom.java.LanguageLevel;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.codeStyle.CodeStyleManager;
|
||||
import com.intellij.psi.codeStyle.JavaCodeStyleManager;
|
||||
@@ -15,7 +14,7 @@ public class VariableTypeCanBeExplicitInspection extends AbstractBaseJavaLocalIn
|
||||
@NotNull
|
||||
@Override
|
||||
public PsiElementVisitor buildVisitor(@NotNull ProblemsHolder holder, boolean isOnTheFly) {
|
||||
if (!PsiUtil.getLanguageLevel(holder.getFile()).isAtLeast(LanguageLevel.JDK_10)) {
|
||||
if (!PsiUtil.isLanguageLevel10OrHigher(holder.getFile())) { //var won't be parsed as inferred type otherwise
|
||||
return PsiElementVisitor.EMPTY_VISITOR;
|
||||
}
|
||||
PsiElementFactory elementFactory = JavaPsiFacade.getElementFactory(holder.getProject());
|
||||
|
||||
+7
@@ -19,7 +19,9 @@ import com.intellij.codeInspection.ProblemDescriptor;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiExpression;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.psi.PsiLambdaExpression;
|
||||
import com.intellij.psi.util.PsiUtil;
|
||||
import com.intellij.refactoring.util.RefactoringUtil;
|
||||
import com.siyeh.InspectionGadgetsBundle;
|
||||
import com.siyeh.ig.BaseInspection;
|
||||
@@ -43,6 +45,11 @@ public class LambdaBodyCanBeCodeBlockInspection extends BaseInspection {
|
||||
return getDisplayName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldInspect(PsiFile file) {
|
||||
return PsiUtil.isLanguageLevel8OrHigher(file);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BaseInspectionVisitor buildVisitor() {
|
||||
return new OneLineLambda2CodeBlockVisitor();
|
||||
|
||||
Reference in New Issue
Block a user