1 /** 2 * Copyright (C) 2010 Google Inc. 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.google.inject.internal; 18 19 import java.lang.annotation.Annotation; 20 21 /** 22 * Whether a member supports null values injected. 23 * 24 * <p>Support for {@code Nullable} annotations in Guice is loose. 25 * Any annotation type whose simplename is "Nullable" is sufficient to indicate 26 * support for null values injected. 27 * 28 * <p>This allows support for JSR-305's 29 * <a href="http://groups.google.com/group/jsr-305/web/proposed-annotations"> 30 * javax.annotation.meta.Nullable</a> annotation and IntelliJ IDEA's 31 * <a href="http://www.jetbrains.com/idea/documentation/howto.html"> 32 * org.jetbrains.annotations.Nullable</a>. 33 * 34 * @author jessewilson (at) google.com (Jesse Wilson) 35 */ 36 public class Nullability { 37 private Nullability() {} 38 39 public static boolean allowsNull(Annotation[] annotations) { 40 for(Annotation a : annotations) { 41 Class<? extends Annotation> type = a.annotationType(); 42 if ("Nullable".equals(type.getSimpleName())) { 43 return true; 44 } 45 } 46 return false; 47 } 48 } 49