mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
PatternVariableCanBeUsedInspection: avoid suggestion for non-effectively-final variables (IDEA-CR-57035)
GitOrigin-RevId: 4b4130ab3de71edebe0506652bde403b8aed9450
This commit is contained in:
committed by
intellij-monorepo-bot
parent
df2595e5c2
commit
af785cc1ce
@@ -2,6 +2,7 @@
|
||||
package com.intellij.codeInspection;
|
||||
|
||||
import com.intellij.codeInsight.PsiEquivalenceUtil;
|
||||
import com.intellij.codeInsight.daemon.impl.analysis.HighlightControlFlowUtil;
|
||||
import com.intellij.codeInsight.daemon.impl.analysis.HighlightUtil;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.psi.*;
|
||||
@@ -38,6 +39,8 @@ public class PatternVariableCanBeUsedInspection extends AbstractBaseJavaLocalIns
|
||||
if (scope == null) return;
|
||||
PsiDeclarationStatement declaration = ObjectUtils.tryCast(variable.getParent(), PsiDeclarationStatement.class);
|
||||
if (declaration == null) return;
|
||||
if (!variable.hasModifierProperty(PsiModifier.FINAL) &&
|
||||
!HighlightControlFlowUtil.isEffectivelyFinal(variable, scope, null)) return;
|
||||
PsiElement context = declaration;
|
||||
PsiElement parent = context.getParent();
|
||||
if (parent instanceof PsiCodeBlock) {
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
// "Replace 's' with pattern variable" "false"
|
||||
class X {
|
||||
void test(Object obj) {
|
||||
if (obj instanceof String) {
|
||||
String <caret>s = (String)obj;
|
||||
System.out.println(s);
|
||||
s = s.trim();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user