mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[java-inspections] Field may be final: configure implicit writes only (IDEA-314628)
GitOrigin-RevId: 2851827fd06bd453799b21ebbd16d91537b3ceac
This commit is contained in:
committed by
intellij-monorepo-bot
parent
a6960c3e4e
commit
5e70a9979d
@@ -1,4 +1,4 @@
|
||||
// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 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.intellij.codeInsight.options;
|
||||
|
||||
import com.intellij.codeInsight.NullableNotNullDialog;
|
||||
@@ -22,6 +22,7 @@ public class JavaInspectionButtons extends CustomComponentExtensionWithSwingRend
|
||||
case NULLABILITY_ANNOTATIONS -> NullableNotNullDialog.createConfigureAnnotationsButton(parent);
|
||||
case ENTRY_POINT_CODE_PATTERNS -> EntryPointsManagerImpl.createConfigureClassPatternsButton();
|
||||
case ENTRY_POINT_ANNOTATIONS -> EntryPointsManagerImpl.createConfigureAnnotationsButton();
|
||||
case IMPLICIT_WRITE_ANNOTATIONS -> EntryPointsManagerImpl.createConfigureAnnotationsButton(true);
|
||||
case DEPENDENCY_CONFIGURATION -> DependencyConfigurable.getConfigureButton();
|
||||
};
|
||||
}
|
||||
@@ -39,7 +40,14 @@ public class JavaInspectionButtons extends CustomComponentExtensionWithSwingRend
|
||||
public enum ButtonKind {
|
||||
NULLABILITY_ANNOTATIONS,
|
||||
ENTRY_POINT_CODE_PATTERNS,
|
||||
/**
|
||||
* Entry point annotations + implicit write annotations
|
||||
*/
|
||||
ENTRY_POINT_ANNOTATIONS,
|
||||
/**
|
||||
* Implicit write annotations only
|
||||
*/
|
||||
IMPLICIT_WRITE_ANNOTATIONS,
|
||||
DEPENDENCY_CONFIGURATION
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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.
|
||||
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package com.intellij.codeInspection.ex;
|
||||
|
||||
import com.intellij.codeInsight.AnnotationTargetUtil;
|
||||
@@ -34,11 +34,22 @@ public class EntryPointsManagerImpl extends EntryPointsManagerBase implements Pe
|
||||
|
||||
@Override
|
||||
public void configureAnnotations() {
|
||||
configureAnnotations(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void configureAnnotations(boolean implicitWritesOnly) {
|
||||
final List<String> list = new ArrayList<>(ADDITIONAL_ANNOTATIONS);
|
||||
final List<String> writeList = new ArrayList<>(myWriteAnnotations);
|
||||
|
||||
final JPanel listPanel = SpecialAnnotationsUtil.createSpecialAnnotationsListControl(
|
||||
list, JavaBundle.message("separator.mark.as.entry.point.if.annotated.by"), true);
|
||||
final JPanel listPanel;
|
||||
if (implicitWritesOnly) {
|
||||
listPanel = null;
|
||||
}
|
||||
else {
|
||||
listPanel = SpecialAnnotationsUtil.createSpecialAnnotationsListControl(
|
||||
list, JavaBundle.message("separator.mark.as.entry.point.if.annotated.by"), true);
|
||||
}
|
||||
Predicate<PsiClass> applicableToField = psiClass -> {
|
||||
Set<PsiAnnotation.TargetType> annotationTargets = AnnotationTargetUtil.getAnnotationTargets(psiClass);
|
||||
return annotationTargets != null && annotationTargets.contains(PsiAnnotation.TargetType.FIELD);
|
||||
@@ -57,8 +68,10 @@ public class EntryPointsManagerImpl extends EntryPointsManagerBase implements Pe
|
||||
final var constraints = new GridBagConstraints(0, GridBagConstraints.RELATIVE, 1, 1, 1, 1,
|
||||
GridBagConstraints.NORTHWEST, GridBagConstraints.BOTH,
|
||||
JBInsets.emptyInsets(), 0, 0);
|
||||
panel.add(listPanel, constraints);
|
||||
constraints.insets.top = 13;
|
||||
if (listPanel != null) {
|
||||
panel.add(listPanel, constraints);
|
||||
constraints.insets.top = 13;
|
||||
}
|
||||
panel.add(writtenAnnotationsPanel, constraints);
|
||||
return panel;
|
||||
}
|
||||
@@ -78,11 +91,15 @@ public class EntryPointsManagerImpl extends EntryPointsManagerBase implements Pe
|
||||
}
|
||||
|
||||
public static JButton createConfigureAnnotationsButton() {
|
||||
return createConfigureAnnotationsButton(false);
|
||||
}
|
||||
|
||||
public static JButton createConfigureAnnotationsButton(boolean implicitWritesOnly) {
|
||||
final JButton configureAnnotations = new JButton(JavaBundle.message("button.annotations"));
|
||||
configureAnnotations.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
getInstance(ProjectUtil.guessCurrentProject(configureAnnotations)).configureAnnotations();
|
||||
getInstance(ProjectUtil.guessCurrentProject(configureAnnotations)).configureAnnotations(implicitWritesOnly);
|
||||
}
|
||||
});
|
||||
return configureAnnotations;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright 2000-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
|
||||
/*
|
||||
* User: anna
|
||||
@@ -29,8 +29,19 @@ public abstract class EntryPointsManager implements Disposable {
|
||||
|
||||
public abstract boolean isAddNonJavaEntries();
|
||||
|
||||
/**
|
||||
* Show UI to configure entry points and implicitly written field annotations, if applicable
|
||||
*/
|
||||
public abstract void configureAnnotations();
|
||||
|
||||
/**
|
||||
* Show UI to configure entry points annotations, if applicable
|
||||
* @param implicitWritesOnly whether to configure implicitly written fields only (no entry points)
|
||||
*/
|
||||
public void configureAnnotations(boolean implicitWritesOnly) {
|
||||
configureAnnotations();
|
||||
}
|
||||
|
||||
public abstract boolean isEntryPoint(@NotNull PsiElement element);
|
||||
|
||||
/**
|
||||
|
||||
@@ -57,7 +57,7 @@ public class FieldMayBeFinalInspection extends BaseInspection implements Cleanup
|
||||
|
||||
@Override
|
||||
public @NotNull OptPane getOptionsPane() {
|
||||
return pane(JavaInspectionControls.button(JavaInspectionButtons.ButtonKind.ENTRY_POINT_ANNOTATIONS));
|
||||
return pane(JavaInspectionControls.button(JavaInspectionButtons.ButtonKind.IMPLICIT_WRITE_ANNOTATIONS));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user