Java: "Non-final field in 'enum'" tweaks

GitOrigin-RevId: 721f2edf47f5c3d671a1cdf89812833dcf59ca89
This commit is contained in:
Bas Leijdekkers
2023-03-15 18:44:09 +00:00
committed by intellij-monorepo-bot
parent a7de6245fc
commit ffc7e4630a
3 changed files with 11 additions and 25 deletions
@@ -1905,7 +1905,7 @@ ambiguous.field.access.navigate.quickfix=Navigate to apparently accessed {0, cho
add.0.to.ignore.if.annotated.by.list.quickfix=Add ''{0}'' to ''Ignore if annotated by'' list
non.final.field.in.enum.display.name=Non-final field in 'enum'
non.final.field.in.enum.problem.descriptor=Non-final field <code>#ref</code> in enum ''{0}'' #loc
non.final.field.in.enum.quickfix.option=Ignore field if quick-fix is not available
non.final.field.in.enum.quickfix.option=Ignore fields that cannot be made 'final'
externalizable.without.public.no.arg.constructor.display.name='Externalizable' class without 'public' no-arg constructor
externalizable.without.public.no.arg.constructor.problem.descriptor=Externalizable class <code>#ref</code> has no 'public' no-arg constructor #loc
make.constructor.public=Make constructor 'public'
@@ -1,22 +1,7 @@
/*
* Copyright 2000-2013 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.siyeh.ig.classlayout;
import com.intellij.codeInspection.options.OptPane;
import com.intellij.codeInspection.ui.SingleCheckboxOptionsPanel;
import com.intellij.psi.PsiClass;
import com.intellij.psi.PsiField;
import com.intellij.psi.PsiModifier;
@@ -29,9 +14,8 @@ import com.siyeh.ig.psiutils.FinalUtils;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import javax.swing.*;
import static com.intellij.codeInspection.options.OptPane.*;
import static com.intellij.codeInspection.options.OptPane.checkbox;
import static com.intellij.codeInspection.options.OptPane.pane;
/**
* @author Bas Leijdekkers
@@ -70,11 +54,11 @@ public class NonFinalFieldInEnumInspection extends BaseInspection {
@Override
public void visitField(@NotNull PsiField field) {
super.visitField(field);
final PsiClass containingClass = field.getContainingClass();
if (containingClass == null || !containingClass.isEnum()) {
if (field.hasModifierProperty(PsiModifier.FINAL)) {
return;
}
if (field.hasModifierProperty(PsiModifier.FINAL)) {
final PsiClass containingClass = field.getContainingClass();
if (containingClass == null || !containingClass.isEnum()) {
return;
}
if (onlyWarnWhenQuickFix && !FinalUtils.canBeFinal(field)) {
@@ -1,6 +1,7 @@
<html>
<body>
Reports non-final fields in enumeration types as they are rarely needed and provide a global mutable state.
Reports non-final fields in enumeration types.
Non-final fields are rarely need and provide global mutable state.
<p><b>Example:</b></p>
<pre><code>
enum Enum {
@@ -28,6 +29,7 @@ Reports non-final fields in enumeration types as they are rarely needed and prov
}
</code></pre>
<!-- tooltip end -->
Configure the `Ignore field if quick-fix is not available` checkbox to only highlight fields that can be made final by the quick-fix.
Use the `Ignore fields that cannot be made 'final'` option to only warn on fields
that can be made final using the quick-fix.
</body>
</html>