mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-18 09:34:34 +07:00
insert same notnull annotation as exist on the existing field (IDEA-79436)
This commit is contained in:
+9
-6
@@ -270,12 +270,7 @@ 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);
|
||||
}
|
||||
notNull(project, field, parameter);
|
||||
AssignFieldFromParameterAction.addFieldAssignmentStatement(project, field, parameter, editor);
|
||||
created = true;
|
||||
}
|
||||
@@ -283,6 +278,14 @@ public class CreateConstructorParameterFromFieldFix implements IntentionAction {
|
||||
return created;
|
||||
}
|
||||
|
||||
private static void notNull(Project project, PsiField field, PsiParameter parameter) {
|
||||
final String notNull = NullableNotNullManager.getInstance(field.getProject()).getNotNull(field);
|
||||
if (notNull != null) {
|
||||
final PsiAnnotation annotation = JavaPsiFacade.getElementFactory(project).createAnnotationFromText("@" + notNull, field);
|
||||
parameter.getModifierList().addBefore(annotation, null);
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static PsiParameter findParamByName(String newName, PsiParameter[] newParameters) {
|
||||
PsiParameter parameter = null;
|
||||
|
||||
+3
-3
@@ -274,9 +274,9 @@ public class GenerateConstructorHandler extends GenerateMembersHandlerBase {
|
||||
PsiParameter parm = factory.createParameter(parmName, field.getType());
|
||||
|
||||
final NullableNotNullManager nullableManager = NullableNotNullManager.getInstance(field.getProject());
|
||||
if (nullableManager.isNotNull(field, false)) {
|
||||
final PsiAnnotation annotation = factory.createAnnotationFromText("@" + nullableManager.getDefaultNotNull(), field);
|
||||
parm.getModifierList().addAfter(annotation, null);
|
||||
final String notNull = nullableManager.getNotNull(field);
|
||||
if (notNull != null) {
|
||||
parm.getModifierList().addAfter(factory.createAnnotationFromText("@" + notNull, field), null);
|
||||
}
|
||||
|
||||
constructor.getParameterList().add(parm);
|
||||
|
||||
+8
-4
@@ -216,10 +216,14 @@ public class CreateFieldFromParameterAction implements IntentionAction {
|
||||
modifierList.setModifierProperty(PsiModifier.FINAL, isFinal);
|
||||
|
||||
final NullableNotNullManager manager = NullableNotNullManager.getInstance(project);
|
||||
if (manager.isNullable(myParameter, false)) {
|
||||
modifierList.addAfter(factory.createAnnotationFromText("@" + manager.getDefaultNullable(), field), null);
|
||||
} else if (isFinal && manager.isNotNull(myParameter, false)) {
|
||||
modifierList.addAfter(factory.createAnnotationFromText("@" + manager.getDefaultNotNull(), field), null);
|
||||
final String nullable = manager.getNullable(myParameter);
|
||||
if (nullable != null) {
|
||||
modifierList.addAfter(factory.createAnnotationFromText("@" + nullable, field), null);
|
||||
} else if (isFinal) {
|
||||
final String notNull = manager.getNotNull(myParameter);
|
||||
if (notNull != null) {
|
||||
modifierList.addAfter(factory.createAnnotationFromText("@" + notNull, field), null);
|
||||
}
|
||||
}
|
||||
|
||||
PsiCodeBlock methodBody = method.getBody();
|
||||
|
||||
+8
-4
@@ -517,11 +517,15 @@ public class InheritanceToDelegationProcessor extends BaseRefactoringProcessor {
|
||||
final PsiModifierList modifierList = methodToAdd.getModifierList();
|
||||
final NullableNotNullManager manager = NullableNotNullManager.getInstance(myProject);
|
||||
modifierList.setModifierProperty(PsiModifier.ABSTRACT, false);
|
||||
if (manager.isNullable(method, false)) {
|
||||
modifierList.addAfter(myFactory.createAnnotationFromText("@" + manager.getDefaultNullable(), methodToAdd), null);
|
||||
final String nullable = manager.getNullable(method);
|
||||
if (nullable != null) {
|
||||
modifierList.addAfter(myFactory.createAnnotationFromText("@" + nullable, methodToAdd), null);
|
||||
}
|
||||
else if (manager.isNotNull(method, false)) {
|
||||
modifierList.addAfter(myFactory.createAnnotationFromText("@" + manager.getDefaultNotNull(), methodToAdd), null);
|
||||
else {
|
||||
final String notNull = manager.getNotNull(method);
|
||||
if (notNull != null) {
|
||||
modifierList.addAfter(myFactory.createAnnotationFromText("@" + notNull, methodToAdd), null);
|
||||
}
|
||||
}
|
||||
|
||||
final String delegationBody = getDelegationBody(methodToAdd, delegationTarget);
|
||||
|
||||
Reference in New Issue
Block a user