insert same notnull annotation as exist on the existing field (IDEA-79436)

This commit is contained in:
anna
2011-12-29 15:43:49 +01:00
parent c81e2d4b9a
commit c3ce1ae00f
9 changed files with 78 additions and 25 deletions
@@ -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);
}
}
}