mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
insert same notnull annotation as exist on the existing field (IDEA-79436)
This commit is contained in:
@@ -28,6 +28,7 @@ import com.intellij.openapi.util.WriteExternalException;
|
||||
import com.intellij.psi.PsiModifierListOwner;
|
||||
import org.jdom.Element;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
@@ -88,6 +89,14 @@ public class NullableNotNullManager implements PersistentStateComponent<Element>
|
||||
public String getDefaultNullable() {
|
||||
return myDefaultNullable;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public String getNullable(PsiModifierListOwner owner) {
|
||||
for (String nullable : myNullables) {
|
||||
if (AnnotationUtil.isAnnotated(owner, nullable, false)) return nullable;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void setDefaultNullable(@NotNull String defaultNullable) {
|
||||
LOG.assertTrue(getNullables().contains(defaultNullable));
|
||||
@@ -97,6 +106,14 @@ public class NullableNotNullManager implements PersistentStateComponent<Element>
|
||||
public String getDefaultNotNull() {
|
||||
return myDefaultNotNull;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public String getNotNull(PsiModifierListOwner owner) {
|
||||
for (String notNull : myNotNulls) {
|
||||
if (AnnotationUtil.isAnnotated(owner, notNull, false)) return notNull;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void setDefaultNotNull(@NotNull String defaultNotNull) {
|
||||
LOG.assertTrue(getNotNulls().contains(defaultNotNull));
|
||||
|
||||
@@ -478,11 +478,15 @@ public class PropertyUtil {
|
||||
private static void annotateWithNullableStuff(final PsiModifierListOwner field, final PsiElementFactory factory, final PsiModifierListOwner listOwner)
|
||||
throws IncorrectOperationException {
|
||||
final NullableNotNullManager manager = NullableNotNullManager.getInstance(field.getProject());
|
||||
if (manager.isNotNull(field, false)) {
|
||||
annotate(factory, listOwner, manager.getDefaultNotNull());
|
||||
final String notNull = manager.getNotNull(field);
|
||||
if (notNull != null) {
|
||||
annotate(factory, listOwner, notNull);
|
||||
}
|
||||
else if (manager.isNullable(field, false)) {
|
||||
annotate(factory, listOwner, manager.getDefaultNullable());
|
||||
else {
|
||||
final String nullable = manager.getNullable(field);
|
||||
if (nullable != null) {
|
||||
annotate(factory, listOwner, nullable);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user