Simplification of "@NotNull/@Nullable problems" inspection settings

This commit is contained in:
Bas Leijdekkers
2011-09-09 15:53:55 +02:00
parent 31fa46134d
commit 8ff3af2a35
16 changed files with 55 additions and 107 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
* Copyright 2000-2011 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.
@@ -42,7 +42,7 @@ import java.util.List;
*/
public class AnnotateMethodFix implements LocalQuickFix {
private static final Logger LOG = Logger.getInstance("#com.intellij.codeInspection.AnnotateMethodFix");
private final String myAnnotation;
protected final String myAnnotation;
private final String[] myAnnotationsToRemove;
public AnnotateMethodFix(final String fqn, String... annotationsToRemove) {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2000-2010 JetBrains s.r.o.
* Copyright 2000-2011 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.
@@ -47,13 +47,10 @@ import java.awt.event.ActionListener;
import java.util.List;
public class NullableStuffInspection extends BaseLocalInspectionTool {
@SuppressWarnings({"WeakerAccess"}) public boolean REPORT_NULLABLE_METHOD_OVERRIDES_NOTNULL = true;
@SuppressWarnings({"WeakerAccess"}) public boolean REPORT_NOT_ANNOTATED_METHOD_OVERRIDES_NOTNULL = true;
@SuppressWarnings({"WeakerAccess"}) public boolean REPORT_NOTNULL_PARAMETER_OVERRIDES_NULLABLE = true;
@SuppressWarnings({"WeakerAccess"}) public boolean REPORT_NOT_ANNOTATED_PARAMETER_OVERRIDES_NOTNULL = true;
@SuppressWarnings({"WeakerAccess"}) public boolean REPORT_NOT_ANNOTATED_GETTER = true;
@SuppressWarnings({"WeakerAccess"}) public boolean REPORT_NOT_ANNOTATED_SETTER_PARAMETER = true;
@SuppressWarnings({"WeakerAccess"}) public boolean REPORT_ANNOTATION_NOT_PROPAGATED_TO_OVERRIDERS = true;
@SuppressWarnings({"WeakerAccess"}) public boolean REPORT_ANNOTATION_NOT_PROPAGATED_TO_OVERRIDERS = true; // remains for test
@SuppressWarnings({"WeakerAccess"}) public boolean REPORT_NULLS_PASSED_TO_NON_ANNOTATED_METHOD = true;
@NotNull
@@ -135,7 +132,7 @@ public class NullableStuffInspection extends BaseLocalInspectionTool {
assert parameters.length == 1 : setter.getText();
final PsiParameter parameter = parameters[0];
assert parameter != null : setter.getText();
if (REPORT_NOT_ANNOTATED_SETTER_PARAMETER && !AnnotationUtil.isAnnotated(parameter, manager.getAllAnnotations()) && !TypeConversionUtil.isPrimitiveAndNotNull(parameter.getType())) {
if (REPORT_NOT_ANNOTATED_GETTER && !AnnotationUtil.isAnnotated(parameter, manager.getAllAnnotations()) && !TypeConversionUtil.isPrimitiveAndNotNull(parameter.getType())) {
final PsiIdentifier nameIdentifier1 = parameter.getNameIdentifier();
assert nameIdentifier1 != null : parameter;
holder.registerProblem(nameIdentifier1,
@@ -197,7 +194,7 @@ public class NullableStuffInspection extends BaseLocalInspectionTool {
if (!method.equals(parameter.getDeclarationScope())) {
return true;
}
if (REPORT_NOT_ANNOTATED_SETTER_PARAMETER && !AnnotationUtil.isAnnotated(parameter, manager.getAllAnnotations())) {
if (REPORT_NOT_ANNOTATED_GETTER && !AnnotationUtil.isAnnotated(parameter, manager.getAllAnnotations())) {
final PsiIdentifier nameIdentifier2 = parameter.getNameIdentifier();
assert nameIdentifier2 != null : parameter;
holder.registerProblem(nameIdentifier2, InspectionsBundle
@@ -310,7 +307,7 @@ public class NullableStuffInspection extends BaseLocalInspectionTool {
for (MethodSignatureBackedByPsiMethod superMethodSignature : superMethodSignatures) {
PsiMethod superMethod = superMethodSignature.getMethod();
if (!reported_nullable_method_overrides_notnull
&& REPORT_NULLABLE_METHOD_OVERRIDES_NOTNULL
&& REPORT_NOTNULL_PARAMETER_OVERRIDES_NULLABLE
&& annotated.isDeclaredNullable
&& AnnotationUtil.isNotNull(superMethod)) {
reported_nullable_method_overrides_notnull = true;
@@ -330,7 +327,7 @@ public class NullableStuffInspection extends BaseLocalInspectionTool {
InspectionsBundle.message("inspection.nullable.problems.method.overrides.NotNull"),
ProblemHighlightType.GENERIC_ERROR_OR_WARNING, createAnnotateMethodFix(defaultNotNull, annotationsToRemove));
}
if (REPORT_NOTNULL_PARAMETER_OVERRIDES_NULLABLE || REPORT_NOT_ANNOTATED_PARAMETER_OVERRIDES_NOTNULL) {
if (REPORT_NOTNULL_PARAMETER_OVERRIDES_NULLABLE || REPORT_NOT_ANNOTATED_METHOD_OVERRIDES_NOTNULL) {
PsiParameter[] superParameters = superMethod.getParameterList().getParameters();
if (superParameters.length != parameters.length) {
continue;
@@ -346,7 +343,7 @@ public class NullableStuffInspection extends BaseLocalInspectionTool {
InspectionsBundle.message("inspection.nullable.problems.NotNull.parameter.overrides.Nullable"),
ProblemHighlightType.GENERIC_ERROR_OR_WARNING);
}
if (!reported_not_annotated_parameter_overrides_notnull[i] && REPORT_NOT_ANNOTATED_PARAMETER_OVERRIDES_NOTNULL) {
if (!reported_not_annotated_parameter_overrides_notnull[i] && REPORT_NOT_ANNOTATED_METHOD_OVERRIDES_NOTNULL) {
if (!AnnotationUtil.isAnnotated(parameter, nullableManager.getAllAnnotations()) &&
nullableManager.isNotNull(superParameter, false)) {
reported_not_annotated_parameter_overrides_notnull[i] = true;
@@ -452,19 +449,15 @@ public class NullableStuffInspection extends BaseLocalInspectionTool {
@NotNull
public String getName() {
return InspectionsBundle.message("annotate.overridden.methods.as.notnull");
return InspectionsBundle.message("annotate.overridden.methods.as.notnull", ClassUtil.extractClassName(myAnnotation));
}
}
private class OptionsPanel extends JPanel {
private JCheckBox myNNParameterOverridesN;
private JCheckBox myNAMethodOverridesNN;
private JCheckBox myNMethodOverridesNN;
private JCheckBox myNAParameterOverridesNN;
private JPanel myPanel;
private JCheckBox myReportNotAnnotatedSetterParameter;
private JCheckBox myReportNotAnnotatedGetter;
private JCheckBox myReportAnnotationNotPropagated;
private JCheckBox myReportNullsPassedToNonAnnotatedParameter;
private OptionsPanel() {
@@ -477,12 +470,8 @@ public class NullableStuffInspection extends BaseLocalInspectionTool {
}
};
myNAMethodOverridesNN.addActionListener(actionListener);
myNMethodOverridesNN.addActionListener(actionListener);
myNNParameterOverridesN.addActionListener(actionListener);
myNAParameterOverridesNN.addActionListener(actionListener);
myReportNotAnnotatedSetterParameter.addActionListener(actionListener);
myReportNotAnnotatedGetter.addActionListener(actionListener);
myReportAnnotationNotPropagated.addActionListener(actionListener);
myReportNullsPassedToNonAnnotatedParameter.addActionListener(actionListener);
reset();
}
@@ -490,22 +479,15 @@ public class NullableStuffInspection extends BaseLocalInspectionTool {
private void reset() {
myNNParameterOverridesN.setSelected(REPORT_NOTNULL_PARAMETER_OVERRIDES_NULLABLE);
myNAMethodOverridesNN.setSelected(REPORT_NOT_ANNOTATED_METHOD_OVERRIDES_NOTNULL);
myNMethodOverridesNN.setSelected(REPORT_NULLABLE_METHOD_OVERRIDES_NOTNULL);
myNAParameterOverridesNN.setSelected(REPORT_NOT_ANNOTATED_PARAMETER_OVERRIDES_NOTNULL);
myReportNotAnnotatedGetter.setSelected(REPORT_NOT_ANNOTATED_GETTER);
myReportNotAnnotatedSetterParameter.setSelected(REPORT_NOT_ANNOTATED_SETTER_PARAMETER);
myReportAnnotationNotPropagated.setSelected(REPORT_ANNOTATION_NOT_PROPAGATED_TO_OVERRIDERS);
myReportNullsPassedToNonAnnotatedParameter.setSelected(REPORT_NULLS_PASSED_TO_NON_ANNOTATED_METHOD);
}
private void apply() {
REPORT_NOT_ANNOTATED_METHOD_OVERRIDES_NOTNULL = myNAMethodOverridesNN.isSelected();
REPORT_NOTNULL_PARAMETER_OVERRIDES_NULLABLE = myNNParameterOverridesN.isSelected();
REPORT_NULLABLE_METHOD_OVERRIDES_NOTNULL = myNMethodOverridesNN.isSelected();
REPORT_NOT_ANNOTATED_PARAMETER_OVERRIDES_NOTNULL = myNAParameterOverridesNN.isSelected();
REPORT_NOT_ANNOTATED_SETTER_PARAMETER = myReportNotAnnotatedSetterParameter.isSelected();
REPORT_NOT_ANNOTATED_GETTER = myReportNotAnnotatedGetter.isSelected();
REPORT_ANNOTATION_NOT_PROPAGATED_TO_OVERRIDERS = myReportAnnotationNotPropagated.isSelected();
REPORT_ANNOTATION_NOT_PROPAGATED_TO_OVERRIDERS = REPORT_NOT_ANNOTATED_METHOD_OVERRIDES_NOTNULL;
REPORT_NULLS_PASSED_TO_NON_ANNOTATED_METHOD = myReportNullsPassedToNonAnnotatedParameter.isSelected();
}
}

View File

@@ -1,80 +1,48 @@
<?xml version="1.0" encoding="UTF-8"?>
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="com.intellij.codeInspection.nullable.NullableStuffInspection.OptionsPanel">
<grid id="cc1c9" binding="myPanel" layout-manager="GridLayoutManager" row-count="9" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<grid id="cc1c9" binding="myPanel" layout-manager="GridLayoutManager" row-count="5" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<xy x="69" y="57" width="333" height="235"/>
<xy x="69" y="57" width="634" height="235"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<component id="32316" class="javax.swing.JCheckBox" binding="myNMethodOverridesNN">
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text resource-bundle="messages/InspectionsBundle" key="inspection.nullable.problems.parameter.overrides.option"/>
</properties>
</component>
<component id="41568" class="javax.swing.JCheckBox" binding="myNAMethodOverridesNN">
<constraints>
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text resource-bundle="messages/InspectionsBundle" key="inspection.nullable.problems.method.overrides.option"/>
</properties>
</component>
<component id="f4e37" class="javax.swing.JCheckBox" binding="myNNParameterOverridesN">
<constraints>
<grid row="3" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text resource-bundle="messages/InspectionsBundle" key="inspection.nullable.problems.method.overrides.notnull.option"/>
</properties>
</component>
<vspacer id="c3eef">
<constraints>
<grid row="8" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
<grid row="4" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
</constraints>
</vspacer>
<component id="52f90" class="javax.swing.JCheckBox" binding="myNAParameterOverridesNN">
<constraints>
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text resource-bundle="messages/InspectionsBundle" key="inspection.nullable.problems.method.overrides.notnull"/>
</properties>
</component>
<component id="d4496" class="javax.swing.JCheckBox" binding="myReportNotAnnotatedSetterParameter" default-binding="true">
<constraints>
<grid row="4" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text resource-bundle="messages/InspectionsBundle" key="inspection.nullable.problems.not.annotated.parameters.for.annotated.field.setters"/>
</properties>
</component>
<component id="2f304" class="javax.swing.JCheckBox" binding="myReportNotAnnotatedGetter">
<constraints>
<grid row="5" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text resource-bundle="messages/InspectionsBundle" key="inspection.nullable.problems.not.annotated.getters.for.annotated.fields"/>
</properties>
</component>
<component id="93bec" class="javax.swing.JCheckBox" binding="myReportAnnotationNotPropagated" default-binding="true">
<constraints>
<grid row="6" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text resource-bundle="messages/InspectionsBundle" key="inspection.nullable.problems.annotation.not.propagated"/>
</properties>
</component>
<component id="690c8" class="javax.swing.JCheckBox" binding="myReportNullsPassedToNonAnnotatedParameter" default-binding="true">
<constraints>
<grid row="7" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
<grid row="3" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="report nulls passed to non annotated parameter"/>
<text resource-bundle="messages/InspectionsBundle" key="inspection.nullable.problems.non.annotated.passed.null"/>
</properties>
</component>
<component id="f4e37" class="javax.swing.JCheckBox" binding="myNNParameterOverridesN">
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text resource-bundle="messages/InspectionsBundle" key="inspection.nullable.problems.method.overrides.notnull.option"/>
</properties>
</component>
<component id="41568" class="javax.swing.JCheckBox" binding="myNAMethodOverridesNN">
<constraints>
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text resource-bundle="messages/InspectionsBundle" key="inspection.nullable.problems.method.overrides.option"/>
</properties>
</component>
</children>

View File

@@ -1,4 +1,4 @@
// "Annotate method as @NotNull" "true"
// "Annotate method as '@NotNull'" "true"
import org.jetbrains.annotations.NotNull;
class X {

View File

@@ -1,4 +1,4 @@
// "Annotate method as @NotNull" "true"
// "Annotate method as '@NotNull'" "true"
import org.jetbrains.annotations.NotNull;
class X {

View File

@@ -1,4 +1,4 @@
// "Annotate method as @NotNull" "true"
// "Annotate method as '@NotNull'" "true"
import org.jetbrains.annotations.NotNull;
class X {

View File

@@ -1,4 +1,4 @@
// "Annotate overridden methods as @NotNull" "true"
// "Annotate overridden methods as '@NotNull'" "true"
import org.jetbrains.annotations.NotNull;
abstract class P2 {

View File

@@ -1,4 +1,4 @@
// "Annotate overridden methods parameters as @NotNull" "true"
// "Annotate overridden method parameters as '@NotNull'" "true"
import org.jetbrains.annotations.NotNull;
abstract class P2 {

View File

@@ -1,4 +1,4 @@
// "Annotate overridden methods as @NotNull" "true"
// "Annotate overridden methods as '@NotNull'" "true"
import org.jetbrains.annotations.*;

View File

@@ -1,4 +1,4 @@
// "Annotate method as @NotNull" "true"
// "Annotate method as '@NotNull'" "true"
import org.jetbrains.annotations.NotNull;
class X {

View File

@@ -1,4 +1,4 @@
// "Annotate method as @NotNull" "true"
// "Annotate method as '@NotNull'" "true"
import org.jetbrains.annotations.NotNull;
class X {

View File

@@ -1,4 +1,4 @@
// "Annotate method as @NotNull" "true"
// "Annotate method as '@NotNull'" "true"
import org.jetbrains.annotations.NotNull;
class X {

View File

@@ -1,4 +1,4 @@
// "Annotate overridden methods as @NotNull" "true"
// "Annotate overridden methods as '@NotNull'" "true"
import org.jetbrains.annotations.NotNull;
abstract class P2 {

View File

@@ -1,4 +1,4 @@
// "Annotate overridden methods parameters as @NotNull" "true"
// "Annotate overridden method parameters as '@NotNull'" "true"
import org.jetbrains.annotations.NotNull;
abstract class P2 {

View File

@@ -1,4 +1,4 @@
// "Annotate overridden methods as @NotNull" "true"
// "Annotate overridden methods as '@NotNull'" "true"
import org.jetbrains.annotations.*;

View File

@@ -31,7 +31,7 @@ inspection.can.be.final.option1=Report methods
inspection.can.be.final.option2=Report fields
#can be static
inspection.annotate.method.quickfix.name=Annotate method as @{0}
inspection.annotate.method.quickfix.name=Annotate method as ''@{0}''
#dataflow
inspection.data.flow.display.name=Constant conditions \\& exceptions
@@ -98,9 +98,11 @@ inspection.can.be.local.variable.problem.descriptor=Variable <code>#ref</code> c
inspection.nullable.problems.display.name=@NotNull/@Nullable problems
#check box options
inspection.nullable.problems.method.overrides.notnull.option=report @NotNull &parameter overrides @Nullable
inspection.nullable.problems.method.overrides.option=report not &annotated method overrides @NotNull
inspection.nullable.problems.parameter.overrides.option=report @&Nullable method overrides @NotNull
inspection.nullable.problems.method.overrides.notnull.option=report @NotNull &parameter overrides @Nullable and @Nullable method overrides @NotNull
inspection.nullable.problems.method.overrides.option=report non-&annotated parameter or method overrides @NotNull
inspection.nullable.problems.not.annotated.getters.for.annotated.fields=report non-annotated &setter parameter or getter of annotated fields
inspection.nullable.problems.non.annotated.passed.null=report &null passed to non-annotated parameter
inspection.nullable.problems.annotation.not.propagated=report @NotNull not propagated to ove&rridden methods
#problem descriptor messages
inspection.nullable.problems.Nullable.NotNull.conflict=Cannot annotate with both @Nullable and @NotNull
@@ -113,6 +115,8 @@ inspection.nullable.problems.annotated.field.setter.parameter.conflict=Setter pa
inspection.nullable.problems.annotated.field.constructor.parameter.not.annotated=Constructor parameter for @{0} field might be annotated @{0} itself
inspection.nullable.problems.annotated.field.constructor.parameter.conflict=Constructor parameter for @{0} field is annotated @{1}
inspection.nullable.problems.NotNull.parameter.overrides.Nullable=Parameter annotated @NonNull must not override @Nullable parameter
inspection.nullable.problems.parameter.overrides.NotNull=Not annotated parameter overrides @NotNull parameter
inspection.nullable.problems.primitive.type.annotation=Primitive type members cannot be Nullable/NotNull annotated
inspection.test.only.problems.display.name=@TestOnly method call in production code
inspection.test.only.problems.test.only.method.call=Test-only method is called in production code
@@ -568,8 +572,6 @@ profile.banner.text=Inspection profile: {0} {1, choice, 0#(inactive)|1#}
profile.ide.tree.text=IDE Profiles
profile.ide.settings.banner=IDE Profiles Settings
profile.project.settings.disable.text=< Use IDE Profile >
inspection.nullable.problems.parameter.overrides.NotNull=Not annotated parameter overrides @NotNull parameter
inspection.nullable.problems.primitive.type.annotation=Primitive type members cannot be Nullable/NotNull annotated
errors.single.profile.title=Errors: ''{0}'' inspection profile
rename.inspection.profile=Rename inspection profile
rename.message.prefix.inspection.profile=Inspection profile
@@ -591,8 +593,6 @@ inconsistent.bundle.report.missing.translations=Report &missing translations
inconsistent.bundle.report.inconsistent.properties=Report &inconsistent properties
inconsistent.bundle.report.duplicate.properties.values=Report properties &overridden with the same value
inconsistent.bundle.property.inherited.with.the.same.value=Property inherited from the ''{0}'' file with the same value
inspection.nullable.problems.not.annotated.parameters.for.annotated.field.setters=report not annotated parameter to &setter for annotated field
inspection.nullable.problems.not.annotated.getters.for.annotated.fields=report not annotated &getter for annotated field
edit.inspection.options=Edit ''{0}'' Options
offline.view.title=Offline View
offline.view.editor.settings.title=Editor Settings
@@ -607,12 +607,10 @@ inspections.result.view.include.action.text=Include
xml.suppressable.for.tag.title=Suppress for tag
xml.suppressable.for.file.title=Suppress for file
xml.suppressable.all.for.file.title=Suppress all for file
inspection.nullable.problems.annotation.not.propagated=report @NotNull not propagated to ove&rridden methods
inspection.nullable.problems.method.overrides.notnull=report not annotated parameter &overrides @NotNull
annotate.overridden.methods.as.notnull=Annotate overridden methods as @NotNull
annotate.overridden.methods.as.notnull=Annotate overridden methods as ''@{0}''
nullable.stuff.problems.overridden.methods.are.not.annotated=Overridden methods are not annotated
nullable.stuff.problems.overridden.method.parameters.are.not.annotated=Overridden method parameters are not annotated
annotate.overridden.methods.parameters=Annotate overridden methods parameters as @{0}
annotate.overridden.methods.parameters=Annotate overridden method parameters as ''@{0}''
offline.inspections.library.was.not.resolved=Please configure library ''{0}'' which is used in module ''{1}''
report.suspicious.but.possibly.correct.method.calls=&Report suspicious but possibly correct method calls
unused.library.display.name=Unused library