diff --git a/android/guava-testlib/src/com/google/common/testing/NullPointerTester.java b/android/guava-testlib/src/com/google/common/testing/NullPointerTester.java index 37aa4fe828bc..c59b0c764119 100644 --- a/android/guava-testlib/src/com/google/common/testing/NullPointerTester.java +++ b/android/guava-testlib/src/com/google/common/testing/NullPointerTester.java @@ -474,15 +474,12 @@ static boolean isPrimitiveOrNullable(Parameter param) { return param.getType().getRawType().isPrimitive() || isNullable(param); } - private static final ImmutableSet NULLABLE_ANNOTATIONS = - ImmutableSet.of( - "javax.annotation.CheckForNull", - "javax.annotation.Nullable", - "org.checkerframework.checker.nullness.compatqual.NullableDecl"); + private static final ImmutableSet NULLABLE_ANNOTATION_SIMPLE_NAMES = + ImmutableSet.of("CheckForNull", "Nullable", "NullableDecl", "NullableType"); static boolean isNullable(AnnotatedElement e) { for (Annotation annotation : e.getAnnotations()) { - if (NULLABLE_ANNOTATIONS.contains(annotation.annotationType().getName())) { + if (NULLABLE_ANNOTATION_SIMPLE_NAMES.contains(annotation.annotationType().getSimpleName())) { return true; } } diff --git a/guava-testlib/src/com/google/common/testing/NullPointerTester.java b/guava-testlib/src/com/google/common/testing/NullPointerTester.java index 37aa4fe828bc..01a4b3a62e7f 100644 --- a/guava-testlib/src/com/google/common/testing/NullPointerTester.java +++ b/guava-testlib/src/com/google/common/testing/NullPointerTester.java @@ -474,15 +474,21 @@ static boolean isPrimitiveOrNullable(Parameter param) { return param.getType().getRawType().isPrimitive() || isNullable(param); } - private static final ImmutableSet NULLABLE_ANNOTATIONS = - ImmutableSet.of( - "javax.annotation.CheckForNull", - "javax.annotation.Nullable", - "org.checkerframework.checker.nullness.compatqual.NullableDecl"); + private static final ImmutableSet NULLABLE_ANNOTATION_SIMPLE_NAMES = + ImmutableSet.of("CheckForNull", "Nullable", "NullableDecl", "NullableType"); static boolean isNullable(AnnotatedElement e) { - for (Annotation annotation : e.getAnnotations()) { - if (NULLABLE_ANNOTATIONS.contains(annotation.annotationType().getName())) { + return isNullable(e.getAnnotations()); + } + + static boolean isNullable(Parameter param) { + return isNullable(param.getAnnotatedType().getAnnotations()) + || isNullable(param.getAnnotations()); + } + + private static boolean isNullable(Annotation[] annotations) { + for (Annotation annotation : annotations) { + if (NULLABLE_ANNOTATION_SIMPLE_NAMES.contains(annotation.annotationType().getSimpleName())) { return true; } } diff --git a/guava/src/com/google/common/reflect/Invokable.java b/guava/src/com/google/common/reflect/Invokable.java index 3900244ae4c4..0c416ad68fba 100644 --- a/guava/src/com/google/common/reflect/Invokable.java +++ b/guava/src/com/google/common/reflect/Invokable.java @@ -21,6 +21,7 @@ import com.google.errorprone.annotations.CanIgnoreReturnValue; import java.lang.annotation.Annotation; import java.lang.reflect.AccessibleObject; +import java.lang.reflect.AnnotatedType; import java.lang.reflect.Constructor; import java.lang.reflect.GenericDeclaration; import java.lang.reflect.InvocationTargetException; @@ -116,9 +117,12 @@ public final TypeToken getReturnType() { public final ImmutableList getParameters() { Type[] parameterTypes = getGenericParameterTypes(); Annotation[][] annotations = getParameterAnnotations(); + AnnotatedType[] annotatedTypes = getAnnotatedParameterTypes(); ImmutableList.Builder builder = ImmutableList.builder(); for (int i = 0; i < parameterTypes.length; i++) { - builder.add(new Parameter(this, i, TypeToken.of(parameterTypes[i]), annotations[i])); + builder.add( + new Parameter( + this, i, TypeToken.of(parameterTypes[i]), annotations[i], annotatedTypes[i])); } return builder.build(); } @@ -178,6 +182,8 @@ abstract Object invokeInternal(@NullableDecl Object receiver, Object[] args) abstract Type[] getGenericParameterTypes(); + abstract AnnotatedType[] getAnnotatedParameterTypes(); + /** This should never return a type that's not a subtype of Throwable. */ abstract Type[] getGenericExceptionTypes(); @@ -210,6 +216,11 @@ Type[] getGenericParameterTypes() { return method.getGenericParameterTypes(); } + @Override + AnnotatedType[] getAnnotatedParameterTypes() { + return method.getAnnotatedParameterTypes(); + } + @Override Type[] getGenericExceptionTypes() { return method.getGenericExceptionTypes(); @@ -287,6 +298,11 @@ Type[] getGenericParameterTypes() { return types; } + @Override + AnnotatedType[] getAnnotatedParameterTypes() { + return constructor.getAnnotatedParameterTypes(); + } + @Override Type[] getGenericExceptionTypes() { return constructor.getGenericExceptionTypes(); diff --git a/guava/src/com/google/common/reflect/Parameter.java b/guava/src/com/google/common/reflect/Parameter.java index 64810e45fce3..6b4b26145164 100644 --- a/guava/src/com/google/common/reflect/Parameter.java +++ b/guava/src/com/google/common/reflect/Parameter.java @@ -21,6 +21,7 @@ import com.google.common.collect.ImmutableList; import java.lang.annotation.Annotation; import java.lang.reflect.AnnotatedElement; +import java.lang.reflect.AnnotatedType; import org.checkerframework.checker.nullness.compatqual.NullableDecl; /** @@ -36,13 +37,19 @@ public final class Parameter implements AnnotatedElement { private final int position; private final TypeToken type; private final ImmutableList annotations; + private final AnnotatedType annotatedType; Parameter( - Invokable declaration, int position, TypeToken type, Annotation[] annotations) { + Invokable declaration, + int position, + TypeToken type, + Annotation[] annotations, + AnnotatedType annotatedType) { this.declaration = declaration; this.position = position; this.type = type; this.annotations = ImmutableList.copyOf(annotations); + this.annotatedType = annotatedType; } /** Returns the type of the parameter. */ @@ -104,6 +111,12 @@ public A[] getDeclaredAnnotationsByType(Class annotati return FluentIterable.from(annotations).filter(annotationType).toArray(annotationType); } + /** @since NEXT */ + // @Override on JDK8 + public AnnotatedType getAnnotatedType() { + return annotatedType; + } + @Override public boolean equals(@NullableDecl Object obj) { if (obj instanceof Parameter) {