mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
LVTI: don't report resource list as multiple var declaration (IDEA-CR-24864)
This commit is contained in:
+1
-2
@@ -436,8 +436,7 @@ public class HighlightUtil extends HighlightUtilBase {
|
||||
.range(typeElement).create();
|
||||
}
|
||||
|
||||
PsiLocalVariable[] localVariables = PsiTreeUtil.getChildrenOfType(parent, PsiLocalVariable.class);
|
||||
if (localVariables != null && localVariables.length > 1) {
|
||||
if (parent instanceof PsiDeclarationStatement && ((PsiDeclarationStatement)parent).getDeclaredElements().length > 1) {
|
||||
return HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR)
|
||||
.descriptionAndTooltip("'var' is not allowed in a compound declaration")
|
||||
.range(variable).create();
|
||||
|
||||
+4
-3
@@ -19,7 +19,6 @@ 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.util.PsiTreeUtil;
|
||||
import com.intellij.psi.util.PsiUtil;
|
||||
import org.jetbrains.annotations.Nls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -36,8 +35,10 @@ public class RedundantExplicitVariableTypeInspection extends BaseJavaBatchLocalI
|
||||
public void visitLocalVariable(PsiLocalVariable variable) {
|
||||
PsiTypeElement typeElement = variable.getTypeElement();
|
||||
if (!typeElement.isInferredType()) {
|
||||
PsiLocalVariable[] variables = PsiTreeUtil.getChildrenOfType(variable.getParent(), PsiLocalVariable.class);
|
||||
if (variables == null || variables.length > 1) return;
|
||||
PsiElement parent = variable.getParent();
|
||||
if (parent instanceof PsiDeclarationStatement && ((PsiDeclarationStatement)parent).getDeclaredElements().length > 1) {
|
||||
return;
|
||||
}
|
||||
doCheck(variable, (PsiLocalVariable)variable.copy(), typeElement);
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -54,7 +54,7 @@ class Main {
|
||||
|
||||
private void tryWithResources(AutoCloseable c) throws Exception {
|
||||
try (<error descr="Cannot infer type: variable initializer is 'null'">var</error> v = null) { }
|
||||
try (var v = c) { }
|
||||
try (var v = c; var v1 = c) { }
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user