[java] local can be final: check class for resources (IDEA-288150)

GitOrigin-RevId: 1910c9203725e2c49fb56fc0c92121f5f56c99ce
This commit is contained in:
Anna Kozlova
2022-02-08 14:28:11 +00:00
committed by intellij-monorepo-bot
parent 80f7ee2e2a
commit d7dbf79cb8
2 changed files with 19 additions and 3 deletions
@@ -1,4 +1,4 @@
// Copyright 2000-2021 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.codeInspection.localCanBeFinal;
import com.intellij.codeInspection.*;
@@ -158,6 +158,9 @@ public class LocalCanBeFinal extends AbstractBaseJavaLocalInspectionTool impleme
@Override
public void visitResourceVariable(PsiResourceVariable variable) {
if (PsiTreeUtil.getParentOfType(variable, PsiClass.class) != PsiTreeUtil.getParentOfType(body, PsiClass.class)) {
return;
}
result.add(variable);
}
@@ -1,5 +1,4 @@
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.*;
class Test {
String m() {
@@ -10,4 +9,18 @@ class Test {
}
return null;
}
void n() {
new Runnable() {
@Override
public void run() {
try (InputStream <warning descr="Variable 'is' can have 'final' modifier">is</warning> = new FileInputStream(new File("b"))) {
System.out.println(is);
}
catch (final IOException e) {
throw new RuntimeException(e);
}
}
};
}
}