LVTI: don't report resource list as multiple var declaration (IDEA-CR-24864)

This commit is contained in:
Anna.Kozlova
2017-10-02 11:52:51 +02:00
parent aa8576f3ce
commit d13ad07be9
3 changed files with 6 additions and 6 deletions
@@ -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();
@@ -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);
}
}
@@ -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) { }
}
}