mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-115452 ("Local variable or parameter can be final" -- "Report local variables" setting doesn't work)
This commit is contained in:
+14
-8
@@ -224,8 +224,8 @@ public class LocalCanBeFinal extends BaseJavaBatchLocalInspectionTool {
|
||||
}
|
||||
|
||||
for (PsiVariable variable : result) {
|
||||
final PsiIdentifier nameIdenitier = variable.getNameIdentifier();
|
||||
PsiElement problemElement = nameIdenitier != null ? nameIdenitier : variable;
|
||||
final PsiIdentifier nameIdentifier = variable.getNameIdentifier();
|
||||
PsiElement problemElement = nameIdentifier != null ? nameIdentifier : variable;
|
||||
if (variable instanceof PsiParameter && !(((PsiParameter)variable).getDeclarationScope() instanceof PsiForeachStatement)) {
|
||||
problems.add(manager.createProblemDescriptor(problemElement,
|
||||
InspectionsBundle.message("inspection.can.be.local.parameter.problem.descriptor"),
|
||||
@@ -243,13 +243,19 @@ public class LocalCanBeFinal extends BaseJavaBatchLocalInspectionTool {
|
||||
|
||||
private boolean shouldBeIgnored(PsiVariable psiVariable) {
|
||||
if (psiVariable.hasModifierProperty(PsiModifier.FINAL)) return true;
|
||||
if (!isReportParameters()) {
|
||||
if (psiVariable instanceof PsiParameter) {
|
||||
final PsiElement declarationScope = ((PsiParameter)psiVariable).getDeclarationScope();
|
||||
if (declarationScope instanceof PsiMethod || declarationScope instanceof PsiLambdaExpression) return true;
|
||||
}
|
||||
return isLocalVariable(psiVariable) ? !isReportVariables() : !isReportParameters();
|
||||
}
|
||||
|
||||
private static boolean isLocalVariable(PsiVariable variable) {
|
||||
if (variable instanceof PsiLocalVariable) {
|
||||
return true;
|
||||
}
|
||||
return !isReportVariables() && psiVariable instanceof PsiLocalVariable;
|
||||
if (!(variable instanceof PsiParameter)) {
|
||||
return false;
|
||||
}
|
||||
final PsiParameter parameter = (PsiParameter)variable;
|
||||
final PsiElement declarationScope = parameter.getDeclarationScope();
|
||||
return !(declarationScope instanceof PsiMethod) && !(declarationScope instanceof PsiLambdaExpression);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<problems>
|
||||
<problem>
|
||||
<file>ForeachNotReported.java</file>
|
||||
<line>5</line>
|
||||
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Local variable or parameter can be final</problem_class>
|
||||
<description>Parameter <code>list</code> can have <code>final</code> modifier</description>
|
||||
</problem>
|
||||
</problems>
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
import java.util.*;
|
||||
|
||||
class ForeachNotReported {
|
||||
|
||||
void f(List<String> list) {
|
||||
for (String s : list) {}
|
||||
}
|
||||
}
|
||||
@@ -123,4 +123,10 @@ public class LocalCanBeFinalTest extends InspectionTestCase {
|
||||
myTool.REPORT_VARIABLES = true;
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testForeachNotReported() throws Exception {
|
||||
myTool.REPORT_PARAMETERS = true;
|
||||
myTool.REPORT_VARIABLES = false;
|
||||
doTest();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user