mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-18 09:34:34 +07:00
add constructor parameter from field: annotate as @NotNull if necessary (IDEA-59977)
This commit is contained in:
+7
@@ -16,6 +16,7 @@
|
||||
package com.intellij.codeInsight.daemon.impl.quickfix;
|
||||
|
||||
import com.intellij.codeInsight.CodeInsightUtilBase;
|
||||
import com.intellij.codeInsight.NullableNotNullManager;
|
||||
import com.intellij.codeInsight.daemon.QuickFixBundle;
|
||||
import com.intellij.codeInsight.daemon.impl.analysis.HighlightControlFlowUtil;
|
||||
import com.intellij.codeInsight.generation.PsiMethodMember;
|
||||
@@ -246,6 +247,12 @@ public class CreateConstructorParameterFromFieldFix implements IntentionAction {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
final NullableNotNullManager nullableManager = NullableNotNullManager.getInstance(field.getProject());
|
||||
if (nullableManager.isNotNull(field, false)) {
|
||||
final PsiAnnotation annotation = JavaPsiFacade.getElementFactory(project).createAnnotationFromText(
|
||||
"@" + nullableManager.getDefaultNotNull(), field);
|
||||
parameter.getModifierList().addBefore(annotation, null);
|
||||
}
|
||||
AssignFieldFromParameterAction.addFieldAssignmentStatement(project, field, parameter, editor);
|
||||
created = true;
|
||||
}
|
||||
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
// "Add constructor parameter" "true"
|
||||
import org.jetbrains.annotations.*;
|
||||
class A {
|
||||
@NotNull private final Object field;
|
||||
|
||||
A(@NotNull Object field, String... strs) {
|
||||
this.field = field;<caret>
|
||||
}
|
||||
|
||||
}
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
// "Add constructor parameter" "true"
|
||||
import org.jetbrains.annotations.*;
|
||||
class A {
|
||||
@NotNull private final Object <caret>field;
|
||||
|
||||
A(String... strs) {
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user