limpbizkit | c808df0 | 2007-08-25 03:25:13 +0000 | [diff] [blame] | 1 | package com.google.inject; |
| 2 | |
| 3 | import java.lang.annotation.Annotation; |
| 4 | |
| 5 | /** |
| 6 | * Whether a member supports null values injected. |
| 7 | * |
| 8 | * <p>Support for {@code Nullable} annotations in Guice is loose. |
| 9 | * Any annotation type whose simplename is "Nullable" is sufficient to indicate |
| 10 | * support for null values injected. |
| 11 | * |
| 12 | * <p>This allows support for JSR-305's |
| 13 | * <a href="http://groups.google.com/group/jsr-305/web/proposed-annotations"> |
| 14 | * javax.annotation.meta.Nullable</a> annotation and IntelliJ IDEA's |
| 15 | * <a href="http://www.jetbrains.com/idea/documentation/howto.html"> |
| 16 | * org.jetbrains.annotations.Nullable</a>. |
| 17 | * |
| 18 | * @author jessewilson@google.com (Jesse Wilson) |
| 19 | */ |
| 20 | enum Nullability { |
| 21 | |
| 22 | NULLABLE, |
| 23 | |
| 24 | NOT_NULLABLE; |
| 25 | |
| 26 | static Nullability forAnnotations(Annotation[] annotations) { |
| 27 | for(Annotation a : annotations) { |
| 28 | if ("Nullable".equals(a.annotationType().getSimpleName())) { |
| 29 | return NULLABLE; |
| 30 | } |
| 31 | } |
| 32 | return NOT_NULLABLE; |
| 33 | } |
| 34 | } |