From 62d7464fb4f874897121591815ecb7503f7bc01b Mon Sep 17 00:00:00 2001 From: Sam Judd Date: Sun, 31 Dec 2017 11:22:13 -0800 Subject: [PATCH] Add @NonNull to generated options and warn if @NonNull is missing. Progress towards #2774. --- .../compiler/GlideExtensionValidator.java | 26 ++++++++++++++++ .../compiler/RequestOptionsGenerator.java | 5 ++++ .../InvalidGlideOptionsExtensionTest.java | 30 +++++++++++++++++++ .../MemoizeStaticMethod/Extension.java | 2 ++ .../MemoizeStaticMethod/GlideOptions.java | 1 + .../MemoizeStaticMethod/GlideRequest.java | 1 + .../OverrideExtend/Extension.java | 2 ++ .../OverrideExtend/GlideOptions.java | 1 + .../OverrideExtend/GlideRequest.java | 1 + .../Extension.java | 2 ++ .../GlideOptions.java | 1 + .../GlideRequest.java | 1 + .../OverrideReplace/Extension.java | 2 ++ .../OverrideReplace/GlideOptions.java | 1 + .../OverrideReplace/GlideRequest.java | 1 + .../SkipStaticMethod/Extension.java | 2 ++ .../SkipStaticMethod/GlideOptions.java | 1 + .../SkipStaticMethod/GlideRequest.java | 1 + .../StaticMethodName/Extension.java | 2 ++ .../StaticMethodName/GlideOptions.java | 1 + .../StaticMethodName/GlideRequest.java | 1 + .../ExtensionWithOption.java | 2 ++ .../GlideOptions.java | 1 + .../GlideRequest.java | 1 + .../MemoizeStaticMethod/GlideOptions.java | 1 + .../MemoizeStaticMethod/GlideRequest.java | 1 + .../OverrideExtend/GlideOptions.java | 1 + .../OverrideExtend/GlideRequest.java | 1 + .../OverrideReplace/GlideOptions.java | 1 + .../OverrideReplace/GlideRequest.java | 1 + .../SkipStaticMethod/GlideOptions.java | 1 + .../SkipStaticMethod/GlideRequest.java | 1 + .../StaticMethodName/GlideOptions.java | 1 + .../StaticMethodName/GlideRequest.java | 1 + .../GlideOptions.java | 1 + .../GlideRequest.java | 1 + .../samples/flickr/FlickrGlideExtension.java | 5 +++- 37 files changed, 105 insertions(+), 1 deletion(-) diff --git a/annotation/compiler/src/main/java/com/bumptech/glide/annotation/compiler/GlideExtensionValidator.java b/annotation/compiler/src/main/java/com/bumptech/glide/annotation/compiler/GlideExtensionValidator.java index baa0f2ba29..b304e682fd 100644 --- a/annotation/compiler/src/main/java/com/bumptech/glide/annotation/compiler/GlideExtensionValidator.java +++ b/annotation/compiler/src/main/java/com/bumptech/glide/annotation/compiler/GlideExtensionValidator.java @@ -2,9 +2,13 @@ import com.bumptech.glide.annotation.GlideOption; import com.bumptech.glide.annotation.GlideType; +import com.google.common.base.Function; +import com.google.common.collect.FluentIterable; import java.util.ArrayList; import java.util.List; +import java.util.Set; import javax.annotation.processing.ProcessingEnvironment; +import javax.lang.model.element.AnnotationMirror; import javax.lang.model.element.Element; import javax.lang.model.element.ElementKind; import javax.lang.model.element.ExecutableElement; @@ -14,6 +18,7 @@ import javax.lang.model.type.DeclaredType; import javax.lang.model.type.TypeKind; import javax.lang.model.type.TypeMirror; +import javax.tools.Diagnostic.Kind; /** * Validates that classes annotated with {@link com.bumptech.glide.annotation.GlideExtension} @@ -73,6 +78,7 @@ private void validateGlideOption(ExecutableElement executableElement) { } private void validateNewGlideOption(ExecutableElement executableElement) { + validateNewGlideOptionAnnotations(executableElement); validateGlideOptionParameters(executableElement); TypeMirror returnType = executableElement.getReturnType(); if (!isRequestOptions(returnType)) { @@ -84,6 +90,26 @@ private void validateNewGlideOption(ExecutableElement executableElement) { validateGlideOptionOverride(executableElement); } + private void validateNewGlideOptionAnnotations(ExecutableElement executableElement) { + Set annotationNames = + FluentIterable.from(executableElement.getAnnotationMirrors()) + .transform(new Function() { + @Override + public String apply(AnnotationMirror input) { + return input.getAnnotationType().asElement().toString(); + } + }) + .toSet(); + if (!annotationNames.contains("android.support.annotation.NonNull")) { + processingEnvironment.getMessager().printMessage( + Kind.WARNING, + executableElement.getEnclosingElement() + "#" + executableElement.getSimpleName() + + " is missing the @NonNull annotation," + + " please add it to ensure that your extension methods are always returning non-null" + + " values"); + } + } + private void validateDeprecatedGlideOption(ExecutableElement executableElement) { validateStaticVoid(executableElement, GlideOption.class); validateGlideOptionParameters(executableElement); diff --git a/annotation/compiler/src/main/java/com/bumptech/glide/annotation/compiler/RequestOptionsGenerator.java b/annotation/compiler/src/main/java/com/bumptech/glide/annotation/compiler/RequestOptionsGenerator.java index 6fcb003f09..6786022301 100644 --- a/annotation/compiler/src/main/java/com/bumptech/glide/annotation/compiler/RequestOptionsGenerator.java +++ b/annotation/compiler/src/main/java/com/bumptech/glide/annotation/compiler/RequestOptionsGenerator.java @@ -78,6 +78,8 @@ final class RequestOptionsGenerator { REQUEST_OPTIONS_PACKAGE_NAME + "." + REQUEST_OPTIONS_SIMPLE_NAME; private static final ClassName CHECK_RESULT_CLASS_NAME = ClassName.get("android.support.annotation", "CheckResult"); + private static final ClassName NON_NULL_CLASS_NAME = + ClassName.get("android.support.annotation", "NonNull"); private final ProcessingEnvironment processingEnvironment; private final ClassName requestOptionsName; @@ -298,6 +300,8 @@ private List generateMethodsForRequestOptionsExtensionNew( code = new StringBuilder(code.substring(0, code.length() - 2)); code.append(")"); builder.addStatement(code.toString(), args.toArray(new Object[0])); + + builder.addAnnotation(AnnotationSpec.builder(NON_NULL_CLASS_NAME).build()); builder.addAnnotation(AnnotationSpec.builder(CHECK_RESULT_CLASS_NAME).build()); List result = new ArrayList<>(); @@ -370,6 +374,7 @@ private List generateMethodsForRequestOptionsExtensionDeprec builder.addStatement(code.toString(), args.toArray(new Object[0])); builder.addStatement("return this"); + builder.addAnnotation(AnnotationSpec.builder(NON_NULL_CLASS_NAME).build()); builder.addAnnotation(AnnotationSpec.builder(CHECK_RESULT_CLASS_NAME).build()); List result = new ArrayList<>(); diff --git a/annotation/compiler/test/src/test/java/com/bumptech/glide/annotation/compiler/InvalidGlideOptionsExtensionTest.java b/annotation/compiler/test/src/test/java/com/bumptech/glide/annotation/compiler/InvalidGlideOptionsExtensionTest.java index 37610ab1a9..964d2bc25b 100644 --- a/annotation/compiler/test/src/test/java/com/bumptech/glide/annotation/compiler/InvalidGlideOptionsExtensionTest.java +++ b/annotation/compiler/test/src/test/java/com/bumptech/glide/annotation/compiler/InvalidGlideOptionsExtensionTest.java @@ -244,12 +244,14 @@ public void compilation_withRequestOptionsReturnValue_succeeds() { JavaFileObjects.forSourceLines( "Extension", "package com.bumptech.glide.test;", + "import android.support.annotation.NonNull;", "import com.bumptech.glide.annotation.GlideExtension;", "import com.bumptech.glide.annotation.GlideOption;", "import com.bumptech.glide.request.RequestOptions;", "@GlideExtension", "public class Extension {", " private Extension() {}", + " @NonNull", " @GlideOption", " public static RequestOptions doSomething(RequestOptions options) {", " return options;", @@ -268,16 +270,44 @@ public void compilation_withNonRequestOptionsReturnValue_fails() { JavaFileObjects.forSourceLines( "Extension", "package com.bumptech.glide.test;", + "import android.support.annotation.NonNull;", "import com.bumptech.glide.annotation.GlideExtension;", "import com.bumptech.glide.annotation.GlideOption;", "import com.bumptech.glide.request.RequestOptions;", "@GlideExtension", "public class Extension {", " private Extension() {}", + " @NonNull", " @GlideOption", " public static Object doSomething(RequestOptions options) {", " return options;", " }", "}")); } + + @Test + public void compilation_withMissingNonNullAnnotation_warns() { + Compilation compilation = javac() + .withProcessors(new GlideAnnotationProcessor()) + .compile( + emptyAppModule(), + JavaFileObjects.forSourceLines( + "Extension", + "package com.bumptech.glide.test;", + "import com.bumptech.glide.annotation.GlideExtension;", + "import com.bumptech.glide.annotation.GlideOption;", + "import com.bumptech.glide.request.RequestOptions;", + "@GlideExtension", + "public class Extension {", + " private Extension() {}", + " @GlideOption", + " public static RequestOptions doSomething(RequestOptions options) {", + " return options;", + " }", + "}")); + assertThat(compilation).succeeded(); + assertThat(compilation).hadWarningCount(1); + assertThat(compilation).hadWarningContaining("@NonNull"); + assertThat(compilation).hadWarningContaining("com.bumptech.glide.test.Extension#doSomething"); + } } diff --git a/annotation/compiler/test/src/test/resources/GlideExtensionOptionsTest/MemoizeStaticMethod/Extension.java b/annotation/compiler/test/src/test/resources/GlideExtensionOptionsTest/MemoizeStaticMethod/Extension.java index e1b1e04f59..05cf8447bd 100644 --- a/annotation/compiler/test/src/test/resources/GlideExtensionOptionsTest/MemoizeStaticMethod/Extension.java +++ b/annotation/compiler/test/src/test/resources/GlideExtensionOptionsTest/MemoizeStaticMethod/Extension.java @@ -1,5 +1,6 @@ package com.bumptech.glide.test; +import android.support.annotation.NonNull; import com.bumptech.glide.annotation.GlideExtension; import com.bumptech.glide.annotation.GlideOption; import com.bumptech.glide.request.RequestOptions; @@ -11,6 +12,7 @@ private Extension() { // Utility class. } + @NonNull @GlideOption(memoizeStaticMethod = true) public static RequestOptions test(RequestOptions requestOptions) { return requestOptions.centerCrop(); diff --git a/annotation/compiler/test/src/test/resources/GlideExtensionOptionsTest/MemoizeStaticMethod/GlideOptions.java b/annotation/compiler/test/src/test/resources/GlideExtensionOptionsTest/MemoizeStaticMethod/GlideOptions.java index b721e7f9d5..a516bf99b8 100644 --- a/annotation/compiler/test/src/test/resources/GlideExtensionOptionsTest/MemoizeStaticMethod/GlideOptions.java +++ b/annotation/compiler/test/src/test/resources/GlideExtensionOptionsTest/MemoizeStaticMethod/GlideOptions.java @@ -596,6 +596,7 @@ public final GlideOptions autoClone() { /** * @see Extension#test(RequestOptions) */ + @NonNull @CheckResult public GlideOptions test() { return (GlideOptions) Extension.test(this); diff --git a/annotation/compiler/test/src/test/resources/GlideExtensionOptionsTest/MemoizeStaticMethod/GlideRequest.java b/annotation/compiler/test/src/test/resources/GlideExtensionOptionsTest/MemoizeStaticMethod/GlideRequest.java index 5533857e58..11f06c689e 100644 --- a/annotation/compiler/test/src/test/resources/GlideExtensionOptionsTest/MemoizeStaticMethod/GlideRequest.java +++ b/annotation/compiler/test/src/test/resources/GlideExtensionOptionsTest/MemoizeStaticMethod/GlideRequest.java @@ -651,6 +651,7 @@ public GlideRequest dontAnimate() { /** * @see GlideOptions#test() */ + @NonNull @CheckResult public GlideRequest test() { if (getMutableOptions() instanceof GlideOptions) { diff --git a/annotation/compiler/test/src/test/resources/GlideExtensionOptionsTest/OverrideExtend/Extension.java b/annotation/compiler/test/src/test/resources/GlideExtensionOptionsTest/OverrideExtend/Extension.java index 862baa126e..b11fe757f6 100644 --- a/annotation/compiler/test/src/test/resources/GlideExtensionOptionsTest/OverrideExtend/Extension.java +++ b/annotation/compiler/test/src/test/resources/GlideExtensionOptionsTest/OverrideExtend/Extension.java @@ -1,5 +1,6 @@ package com.bumptech.glide.test; +import android.support.annotation.NonNull; import com.bumptech.glide.annotation.GlideExtension; import com.bumptech.glide.annotation.GlideOption; import com.bumptech.glide.request.RequestOptions; @@ -11,6 +12,7 @@ private Extension() { // Utility class. } + @NonNull @GlideOption(override = GlideOption.OVERRIDE_EXTEND) public static RequestOptions centerCrop(RequestOptions requestOptions) { return requestOptions.centerCrop(); diff --git a/annotation/compiler/test/src/test/resources/GlideExtensionOptionsTest/OverrideExtend/GlideOptions.java b/annotation/compiler/test/src/test/resources/GlideExtensionOptionsTest/OverrideExtend/GlideOptions.java index 9ece405f45..c18eb00da3 100644 --- a/annotation/compiler/test/src/test/resources/GlideExtensionOptionsTest/OverrideExtend/GlideOptions.java +++ b/annotation/compiler/test/src/test/resources/GlideExtensionOptionsTest/OverrideExtend/GlideOptions.java @@ -589,6 +589,7 @@ public final GlideOptions autoClone() { * @see RequestOptions#centerCrop() */ @Override + @NonNull @CheckResult public GlideOptions centerCrop() { return (GlideOptions) Extension.centerCrop(super.centerCrop()); diff --git a/annotation/compiler/test/src/test/resources/GlideExtensionOptionsTest/OverrideExtend/GlideRequest.java b/annotation/compiler/test/src/test/resources/GlideExtensionOptionsTest/OverrideExtend/GlideRequest.java index 3e559893c9..aaa4680a83 100644 --- a/annotation/compiler/test/src/test/resources/GlideExtensionOptionsTest/OverrideExtend/GlideRequest.java +++ b/annotation/compiler/test/src/test/resources/GlideExtensionOptionsTest/OverrideExtend/GlideRequest.java @@ -637,6 +637,7 @@ public GlideRequest dontAnimate() { /** * @see GlideOptions#centerCrop() */ + @NonNull @CheckResult public GlideRequest centerCrop() { if (getMutableOptions() instanceof GlideOptions) { diff --git a/annotation/compiler/test/src/test/resources/GlideExtensionOptionsTest/OverrideExtendMultipleArguments/Extension.java b/annotation/compiler/test/src/test/resources/GlideExtensionOptionsTest/OverrideExtendMultipleArguments/Extension.java index 714c287e5d..a0be8a2c31 100644 --- a/annotation/compiler/test/src/test/resources/GlideExtensionOptionsTest/OverrideExtendMultipleArguments/Extension.java +++ b/annotation/compiler/test/src/test/resources/GlideExtensionOptionsTest/OverrideExtendMultipleArguments/Extension.java @@ -1,5 +1,6 @@ package com.bumptech.glide.test; +import android.support.annotation.NonNull; import com.bumptech.glide.annotation.GlideExtension; import com.bumptech.glide.annotation.GlideOption; import com.bumptech.glide.request.RequestOptions; @@ -11,6 +12,7 @@ private Extension() { // Utility class. } + @NonNull @GlideOption(override = GlideOption.OVERRIDE_EXTEND) public static RequestOptions override(RequestOptions requestOptions, int width, int height) { return requestOptions diff --git a/annotation/compiler/test/src/test/resources/GlideExtensionOptionsTest/OverrideExtendMultipleArguments/GlideOptions.java b/annotation/compiler/test/src/test/resources/GlideExtensionOptionsTest/OverrideExtendMultipleArguments/GlideOptions.java index ef9428d20f..34d14a62b6 100644 --- a/annotation/compiler/test/src/test/resources/GlideExtensionOptionsTest/OverrideExtendMultipleArguments/GlideOptions.java +++ b/annotation/compiler/test/src/test/resources/GlideExtensionOptionsTest/OverrideExtendMultipleArguments/GlideOptions.java @@ -580,6 +580,7 @@ public final GlideOptions autoClone() { * @see RequestOptions#override(int, int) */ @Override + @NonNull @CheckResult public GlideOptions override(int width, int height) { return (GlideOptions) Extension.override(super.override(width, height), width, height); diff --git a/annotation/compiler/test/src/test/resources/GlideExtensionOptionsTest/OverrideExtendMultipleArguments/GlideRequest.java b/annotation/compiler/test/src/test/resources/GlideExtensionOptionsTest/OverrideExtendMultipleArguments/GlideRequest.java index cac11bc08a..c6014fb457 100644 --- a/annotation/compiler/test/src/test/resources/GlideExtensionOptionsTest/OverrideExtendMultipleArguments/GlideRequest.java +++ b/annotation/compiler/test/src/test/resources/GlideExtensionOptionsTest/OverrideExtendMultipleArguments/GlideRequest.java @@ -637,6 +637,7 @@ public GlideRequest dontAnimate() { /** * @see GlideOptions#override(int, int) */ + @NonNull @CheckResult public GlideRequest override(int width, int height) { if (getMutableOptions() instanceof GlideOptions) { diff --git a/annotation/compiler/test/src/test/resources/GlideExtensionOptionsTest/OverrideReplace/Extension.java b/annotation/compiler/test/src/test/resources/GlideExtensionOptionsTest/OverrideReplace/Extension.java index ec436d7652..78d91590fc 100644 --- a/annotation/compiler/test/src/test/resources/GlideExtensionOptionsTest/OverrideReplace/Extension.java +++ b/annotation/compiler/test/src/test/resources/GlideExtensionOptionsTest/OverrideReplace/Extension.java @@ -1,5 +1,6 @@ package com.bumptech.glide.test; +import android.support.annotation.NonNull; import com.bumptech.glide.annotation.GlideExtension; import com.bumptech.glide.annotation.GlideOption; import com.bumptech.glide.request.RequestOptions; @@ -11,6 +12,7 @@ private Extension() { // Utility class. } + @NonNull @GlideOption(override = GlideOption.OVERRIDE_REPLACE) public static RequestOptions centerCrop(RequestOptions requestOptions) { return requestOptions.centerCrop(); diff --git a/annotation/compiler/test/src/test/resources/GlideExtensionOptionsTest/OverrideReplace/GlideOptions.java b/annotation/compiler/test/src/test/resources/GlideExtensionOptionsTest/OverrideReplace/GlideOptions.java index 1ecca03187..8c4ead00e8 100644 --- a/annotation/compiler/test/src/test/resources/GlideExtensionOptionsTest/OverrideReplace/GlideOptions.java +++ b/annotation/compiler/test/src/test/resources/GlideExtensionOptionsTest/OverrideReplace/GlideOptions.java @@ -587,6 +587,7 @@ public final GlideOptions autoClone() { /** * @see Extension#centerCrop(RequestOptions) */ + @NonNull @CheckResult public GlideOptions centerCrop() { return (GlideOptions) Extension.centerCrop(this); diff --git a/annotation/compiler/test/src/test/resources/GlideExtensionOptionsTest/OverrideReplace/GlideRequest.java b/annotation/compiler/test/src/test/resources/GlideExtensionOptionsTest/OverrideReplace/GlideRequest.java index 3e559893c9..aaa4680a83 100644 --- a/annotation/compiler/test/src/test/resources/GlideExtensionOptionsTest/OverrideReplace/GlideRequest.java +++ b/annotation/compiler/test/src/test/resources/GlideExtensionOptionsTest/OverrideReplace/GlideRequest.java @@ -637,6 +637,7 @@ public GlideRequest dontAnimate() { /** * @see GlideOptions#centerCrop() */ + @NonNull @CheckResult public GlideRequest centerCrop() { if (getMutableOptions() instanceof GlideOptions) { diff --git a/annotation/compiler/test/src/test/resources/GlideExtensionOptionsTest/SkipStaticMethod/Extension.java b/annotation/compiler/test/src/test/resources/GlideExtensionOptionsTest/SkipStaticMethod/Extension.java index 904c55a1cc..69db3bc0f2 100644 --- a/annotation/compiler/test/src/test/resources/GlideExtensionOptionsTest/SkipStaticMethod/Extension.java +++ b/annotation/compiler/test/src/test/resources/GlideExtensionOptionsTest/SkipStaticMethod/Extension.java @@ -1,5 +1,6 @@ package com.bumptech.glide.test; +import android.support.annotation.NonNull; import com.bumptech.glide.annotation.GlideExtension; import com.bumptech.glide.annotation.GlideOption; import com.bumptech.glide.request.RequestOptions; @@ -11,6 +12,7 @@ private Extension() { // Utility class. } + @NonNull @GlideOption(skipStaticMethod = true) public static RequestOptions test(RequestOptions requestOptions) { return requestOptions.centerCrop(); diff --git a/annotation/compiler/test/src/test/resources/GlideExtensionOptionsTest/SkipStaticMethod/GlideOptions.java b/annotation/compiler/test/src/test/resources/GlideExtensionOptionsTest/SkipStaticMethod/GlideOptions.java index a82df71e58..a15e5a13e0 100644 --- a/annotation/compiler/test/src/test/resources/GlideExtensionOptionsTest/SkipStaticMethod/GlideOptions.java +++ b/annotation/compiler/test/src/test/resources/GlideExtensionOptionsTest/SkipStaticMethod/GlideOptions.java @@ -594,6 +594,7 @@ public final GlideOptions autoClone() { /** * @see Extension#test(RequestOptions) */ + @NonNull @CheckResult public GlideOptions test() { return (GlideOptions) Extension.test(this); diff --git a/annotation/compiler/test/src/test/resources/GlideExtensionOptionsTest/SkipStaticMethod/GlideRequest.java b/annotation/compiler/test/src/test/resources/GlideExtensionOptionsTest/SkipStaticMethod/GlideRequest.java index 5533857e58..11f06c689e 100644 --- a/annotation/compiler/test/src/test/resources/GlideExtensionOptionsTest/SkipStaticMethod/GlideRequest.java +++ b/annotation/compiler/test/src/test/resources/GlideExtensionOptionsTest/SkipStaticMethod/GlideRequest.java @@ -651,6 +651,7 @@ public GlideRequest dontAnimate() { /** * @see GlideOptions#test() */ + @NonNull @CheckResult public GlideRequest test() { if (getMutableOptions() instanceof GlideOptions) { diff --git a/annotation/compiler/test/src/test/resources/GlideExtensionOptionsTest/StaticMethodName/Extension.java b/annotation/compiler/test/src/test/resources/GlideExtensionOptionsTest/StaticMethodName/Extension.java index aa124c142f..9e05dde642 100644 --- a/annotation/compiler/test/src/test/resources/GlideExtensionOptionsTest/StaticMethodName/Extension.java +++ b/annotation/compiler/test/src/test/resources/GlideExtensionOptionsTest/StaticMethodName/Extension.java @@ -1,5 +1,6 @@ package com.bumptech.glide.test; +import android.support.annotation.NonNull; import com.bumptech.glide.annotation.GlideExtension; import com.bumptech.glide.annotation.GlideOption; import com.bumptech.glide.request.RequestOptions; @@ -11,6 +12,7 @@ private Extension() { // Utility class. } + @NonNull @GlideOption(staticMethodName = "testSomething") public static RequestOptions test(RequestOptions requestOptions) { return requestOptions.centerCrop(); diff --git a/annotation/compiler/test/src/test/resources/GlideExtensionOptionsTest/StaticMethodName/GlideOptions.java b/annotation/compiler/test/src/test/resources/GlideExtensionOptionsTest/StaticMethodName/GlideOptions.java index 7a1516c665..5fb88e94fe 100644 --- a/annotation/compiler/test/src/test/resources/GlideExtensionOptionsTest/StaticMethodName/GlideOptions.java +++ b/annotation/compiler/test/src/test/resources/GlideExtensionOptionsTest/StaticMethodName/GlideOptions.java @@ -594,6 +594,7 @@ public final GlideOptions autoClone() { /** * @see Extension#test(RequestOptions) */ + @NonNull @CheckResult public GlideOptions test() { return (GlideOptions) Extension.test(this); diff --git a/annotation/compiler/test/src/test/resources/GlideExtensionOptionsTest/StaticMethodName/GlideRequest.java b/annotation/compiler/test/src/test/resources/GlideExtensionOptionsTest/StaticMethodName/GlideRequest.java index 5533857e58..11f06c689e 100644 --- a/annotation/compiler/test/src/test/resources/GlideExtensionOptionsTest/StaticMethodName/GlideRequest.java +++ b/annotation/compiler/test/src/test/resources/GlideExtensionOptionsTest/StaticMethodName/GlideRequest.java @@ -651,6 +651,7 @@ public GlideRequest dontAnimate() { /** * @see GlideOptions#test() */ + @NonNull @CheckResult public GlideRequest test() { if (getMutableOptions() instanceof GlideOptions) { diff --git a/annotation/compiler/test/src/test/resources/GlideExtensionWithOptionTest/ExtensionWithOption.java b/annotation/compiler/test/src/test/resources/GlideExtensionWithOptionTest/ExtensionWithOption.java index 8f6de00511..9884bcefba 100644 --- a/annotation/compiler/test/src/test/resources/GlideExtensionWithOptionTest/ExtensionWithOption.java +++ b/annotation/compiler/test/src/test/resources/GlideExtensionWithOptionTest/ExtensionWithOption.java @@ -1,5 +1,6 @@ package com.bumptech.glide.test; +import android.support.annotation.NonNull; import com.bumptech.glide.annotation.GlideExtension; import com.bumptech.glide.annotation.GlideOption; import com.bumptech.glide.request.RequestOptions; @@ -11,6 +12,7 @@ private ExtensionWithOption() { // Utility class. } + @NonNull @GlideOption public static RequestOptions squareThumb(RequestOptions requestOptions) { return requestOptions.centerCrop(); diff --git a/annotation/compiler/test/src/test/resources/GlideExtensionWithOptionTest/GlideOptions.java b/annotation/compiler/test/src/test/resources/GlideExtensionWithOptionTest/GlideOptions.java index 0faea65210..a801496a47 100644 --- a/annotation/compiler/test/src/test/resources/GlideExtensionWithOptionTest/GlideOptions.java +++ b/annotation/compiler/test/src/test/resources/GlideExtensionWithOptionTest/GlideOptions.java @@ -594,6 +594,7 @@ public final GlideOptions autoClone() { /** * @see ExtensionWithOption#squareThumb(RequestOptions) */ + @NonNull @CheckResult public GlideOptions squareThumb() { return (GlideOptions) ExtensionWithOption.squareThumb(this); diff --git a/annotation/compiler/test/src/test/resources/GlideExtensionWithOptionTest/GlideRequest.java b/annotation/compiler/test/src/test/resources/GlideExtensionWithOptionTest/GlideRequest.java index f461c8ad29..35c73d0d73 100644 --- a/annotation/compiler/test/src/test/resources/GlideExtensionWithOptionTest/GlideRequest.java +++ b/annotation/compiler/test/src/test/resources/GlideExtensionWithOptionTest/GlideRequest.java @@ -651,6 +651,7 @@ public GlideRequest dontAnimate() { /** * @see GlideOptions#squareThumb() */ + @NonNull @CheckResult public GlideRequest squareThumb() { if (getMutableOptions() instanceof GlideOptions) { diff --git a/annotation/compiler/test/src/test/resources/LegacyGlideExtensionOptionsTest/MemoizeStaticMethod/GlideOptions.java b/annotation/compiler/test/src/test/resources/LegacyGlideExtensionOptionsTest/MemoizeStaticMethod/GlideOptions.java index e63a8c6367..e217989a06 100644 --- a/annotation/compiler/test/src/test/resources/LegacyGlideExtensionOptionsTest/MemoizeStaticMethod/GlideOptions.java +++ b/annotation/compiler/test/src/test/resources/LegacyGlideExtensionOptionsTest/MemoizeStaticMethod/GlideOptions.java @@ -596,6 +596,7 @@ public final GlideOptions autoClone() { /** * @see Extension#test(RequestOptions) */ + @NonNull @CheckResult public GlideOptions test() { if (isAutoCloneEnabled()) { diff --git a/annotation/compiler/test/src/test/resources/LegacyGlideExtensionOptionsTest/MemoizeStaticMethod/GlideRequest.java b/annotation/compiler/test/src/test/resources/LegacyGlideExtensionOptionsTest/MemoizeStaticMethod/GlideRequest.java index 5533857e58..11f06c689e 100644 --- a/annotation/compiler/test/src/test/resources/LegacyGlideExtensionOptionsTest/MemoizeStaticMethod/GlideRequest.java +++ b/annotation/compiler/test/src/test/resources/LegacyGlideExtensionOptionsTest/MemoizeStaticMethod/GlideRequest.java @@ -651,6 +651,7 @@ public GlideRequest dontAnimate() { /** * @see GlideOptions#test() */ + @NonNull @CheckResult public GlideRequest test() { if (getMutableOptions() instanceof GlideOptions) { diff --git a/annotation/compiler/test/src/test/resources/LegacyGlideExtensionOptionsTest/OverrideExtend/GlideOptions.java b/annotation/compiler/test/src/test/resources/LegacyGlideExtensionOptionsTest/OverrideExtend/GlideOptions.java index 0922d8cf31..7e59eb54f6 100644 --- a/annotation/compiler/test/src/test/resources/LegacyGlideExtensionOptionsTest/OverrideExtend/GlideOptions.java +++ b/annotation/compiler/test/src/test/resources/LegacyGlideExtensionOptionsTest/OverrideExtend/GlideOptions.java @@ -589,6 +589,7 @@ public final GlideOptions autoClone() { * @see RequestOptions#centerCrop() */ @Override + @NonNull @CheckResult public GlideOptions centerCrop() { if (isAutoCloneEnabled()) { diff --git a/annotation/compiler/test/src/test/resources/LegacyGlideExtensionOptionsTest/OverrideExtend/GlideRequest.java b/annotation/compiler/test/src/test/resources/LegacyGlideExtensionOptionsTest/OverrideExtend/GlideRequest.java index 3e559893c9..aaa4680a83 100644 --- a/annotation/compiler/test/src/test/resources/LegacyGlideExtensionOptionsTest/OverrideExtend/GlideRequest.java +++ b/annotation/compiler/test/src/test/resources/LegacyGlideExtensionOptionsTest/OverrideExtend/GlideRequest.java @@ -637,6 +637,7 @@ public GlideRequest dontAnimate() { /** * @see GlideOptions#centerCrop() */ + @NonNull @CheckResult public GlideRequest centerCrop() { if (getMutableOptions() instanceof GlideOptions) { diff --git a/annotation/compiler/test/src/test/resources/LegacyGlideExtensionOptionsTest/OverrideReplace/GlideOptions.java b/annotation/compiler/test/src/test/resources/LegacyGlideExtensionOptionsTest/OverrideReplace/GlideOptions.java index 2be07d97e2..83af4bee97 100644 --- a/annotation/compiler/test/src/test/resources/LegacyGlideExtensionOptionsTest/OverrideReplace/GlideOptions.java +++ b/annotation/compiler/test/src/test/resources/LegacyGlideExtensionOptionsTest/OverrideReplace/GlideOptions.java @@ -587,6 +587,7 @@ public final GlideOptions autoClone() { /** * @see Extension#centerCrop(RequestOptions) */ + @NonNull @CheckResult public GlideOptions centerCrop() { if (isAutoCloneEnabled()) { diff --git a/annotation/compiler/test/src/test/resources/LegacyGlideExtensionOptionsTest/OverrideReplace/GlideRequest.java b/annotation/compiler/test/src/test/resources/LegacyGlideExtensionOptionsTest/OverrideReplace/GlideRequest.java index 3e559893c9..aaa4680a83 100644 --- a/annotation/compiler/test/src/test/resources/LegacyGlideExtensionOptionsTest/OverrideReplace/GlideRequest.java +++ b/annotation/compiler/test/src/test/resources/LegacyGlideExtensionOptionsTest/OverrideReplace/GlideRequest.java @@ -637,6 +637,7 @@ public GlideRequest dontAnimate() { /** * @see GlideOptions#centerCrop() */ + @NonNull @CheckResult public GlideRequest centerCrop() { if (getMutableOptions() instanceof GlideOptions) { diff --git a/annotation/compiler/test/src/test/resources/LegacyGlideExtensionOptionsTest/SkipStaticMethod/GlideOptions.java b/annotation/compiler/test/src/test/resources/LegacyGlideExtensionOptionsTest/SkipStaticMethod/GlideOptions.java index f360cefae0..b639413697 100644 --- a/annotation/compiler/test/src/test/resources/LegacyGlideExtensionOptionsTest/SkipStaticMethod/GlideOptions.java +++ b/annotation/compiler/test/src/test/resources/LegacyGlideExtensionOptionsTest/SkipStaticMethod/GlideOptions.java @@ -594,6 +594,7 @@ public final GlideOptions autoClone() { /** * @see Extension#test(RequestOptions) */ + @NonNull @CheckResult public GlideOptions test() { if (isAutoCloneEnabled()) { diff --git a/annotation/compiler/test/src/test/resources/LegacyGlideExtensionOptionsTest/SkipStaticMethod/GlideRequest.java b/annotation/compiler/test/src/test/resources/LegacyGlideExtensionOptionsTest/SkipStaticMethod/GlideRequest.java index 5533857e58..11f06c689e 100644 --- a/annotation/compiler/test/src/test/resources/LegacyGlideExtensionOptionsTest/SkipStaticMethod/GlideRequest.java +++ b/annotation/compiler/test/src/test/resources/LegacyGlideExtensionOptionsTest/SkipStaticMethod/GlideRequest.java @@ -651,6 +651,7 @@ public GlideRequest dontAnimate() { /** * @see GlideOptions#test() */ + @NonNull @CheckResult public GlideRequest test() { if (getMutableOptions() instanceof GlideOptions) { diff --git a/annotation/compiler/test/src/test/resources/LegacyGlideExtensionOptionsTest/StaticMethodName/GlideOptions.java b/annotation/compiler/test/src/test/resources/LegacyGlideExtensionOptionsTest/StaticMethodName/GlideOptions.java index fc9293a653..79b4838ecc 100644 --- a/annotation/compiler/test/src/test/resources/LegacyGlideExtensionOptionsTest/StaticMethodName/GlideOptions.java +++ b/annotation/compiler/test/src/test/resources/LegacyGlideExtensionOptionsTest/StaticMethodName/GlideOptions.java @@ -594,6 +594,7 @@ public final GlideOptions autoClone() { /** * @see Extension#test(RequestOptions) */ + @NonNull @CheckResult public GlideOptions test() { if (isAutoCloneEnabled()) { diff --git a/annotation/compiler/test/src/test/resources/LegacyGlideExtensionOptionsTest/StaticMethodName/GlideRequest.java b/annotation/compiler/test/src/test/resources/LegacyGlideExtensionOptionsTest/StaticMethodName/GlideRequest.java index 5533857e58..11f06c689e 100644 --- a/annotation/compiler/test/src/test/resources/LegacyGlideExtensionOptionsTest/StaticMethodName/GlideRequest.java +++ b/annotation/compiler/test/src/test/resources/LegacyGlideExtensionOptionsTest/StaticMethodName/GlideRequest.java @@ -651,6 +651,7 @@ public GlideRequest dontAnimate() { /** * @see GlideOptions#test() */ + @NonNull @CheckResult public GlideRequest test() { if (getMutableOptions() instanceof GlideOptions) { diff --git a/annotation/compiler/test/src/test/resources/LegacyGlideExtensionWithOptionTest/GlideOptions.java b/annotation/compiler/test/src/test/resources/LegacyGlideExtensionWithOptionTest/GlideOptions.java index b3c4406a4e..7caa63811b 100644 --- a/annotation/compiler/test/src/test/resources/LegacyGlideExtensionWithOptionTest/GlideOptions.java +++ b/annotation/compiler/test/src/test/resources/LegacyGlideExtensionWithOptionTest/GlideOptions.java @@ -594,6 +594,7 @@ public final GlideOptions autoClone() { /** * @see ExtensionWithOption#squareThumb(RequestOptions) */ + @NonNull @CheckResult public GlideOptions squareThumb() { if (isAutoCloneEnabled()) { diff --git a/annotation/compiler/test/src/test/resources/LegacyGlideExtensionWithOptionTest/GlideRequest.java b/annotation/compiler/test/src/test/resources/LegacyGlideExtensionWithOptionTest/GlideRequest.java index f461c8ad29..35c73d0d73 100644 --- a/annotation/compiler/test/src/test/resources/LegacyGlideExtensionWithOptionTest/GlideRequest.java +++ b/annotation/compiler/test/src/test/resources/LegacyGlideExtensionWithOptionTest/GlideRequest.java @@ -651,6 +651,7 @@ public GlideRequest dontAnimate() { /** * @see GlideOptions#squareThumb() */ + @NonNull @CheckResult public GlideRequest squareThumb() { if (getMutableOptions() instanceof GlideOptions) { diff --git a/samples/flickr/src/main/java/com/bumptech/glide/samples/flickr/FlickrGlideExtension.java b/samples/flickr/src/main/java/com/bumptech/glide/samples/flickr/FlickrGlideExtension.java index 965dc0d2ea..1a5346d099 100644 --- a/samples/flickr/src/main/java/com/bumptech/glide/samples/flickr/FlickrGlideExtension.java +++ b/samples/flickr/src/main/java/com/bumptech/glide/samples/flickr/FlickrGlideExtension.java @@ -1,5 +1,6 @@ package com.bumptech.glide.samples.flickr; +import android.support.annotation.NonNull; import com.bumptech.glide.annotation.GlideExtension; import com.bumptech.glide.annotation.GlideOption; import com.bumptech.glide.request.RequestOptions; @@ -9,7 +10,7 @@ * Extension methods for the Flickr sample's generated API. */ // Required by Glide's annotation processor. -@SuppressWarnings("WeakerAccess") +@SuppressWarnings({"WeakerAccess", "unused"}) @GlideExtension public final class FlickrGlideExtension { @@ -17,11 +18,13 @@ private FlickrGlideExtension() { // Utility class. } + @NonNull @GlideOption public static RequestOptions squareThumb(RequestOptions requestOptions) { return requestOptions.centerCrop(); } + @NonNull @GlideOption public static RequestOptions squareMiniThumb(RequestOptions requestOptions) { return requestOptions.centerCrop().override(Api.SQUARE_THUMB_SIZE);