From e78f2ee1153f5b810242ff9a31fad398357623b7 Mon Sep 17 00:00:00 2001 From: Sam Judd Date: Sun, 5 Nov 2017 11:28:53 -0800 Subject: [PATCH] Add support for return values from extension methods. The old style is still supported for now to avoid breaking backwards compatibility, but the new style is available, simpler to write and avoids @CheckResult warnings. --- .../compiler/ExtensionProcessor.java | 10 +- .../compiler/GlideAnnotationProcessor.java | 3 +- .../compiler/GlideExtensionValidator.java | 121 ++- .../annotation/compiler/ProcessorUtil.java | 12 +- .../compiler/RequestOptionsGenerator.java | 150 ++-- .../EmptyAppAndLibraryGlideModulesTest.java | 5 +- .../compiler/EmptyAppGlideModuleTest.java | 5 +- .../compiler/EmptyLibraryGlideModuleTest.java | 5 +- .../compiler/GlideExtensionOptionsTest.java | 21 +- .../GlideExtensionWithOptionTest.java | 8 +- .../compiler/GlideExtensionWithTypeTest.java | 5 +- .../InvalidGlideOptionsExtensionTest.java | 56 +- .../LegacyGlideExtensionOptionsTest.java | 104 +++ .../LegacyGlideExtensionWithOptionTest.java | 98 +++ .../compiler/MultipleAppGlideModuleTest.java | 5 +- .../MultipleEmptyLibraryGlideModuleTest.java | 5 +- .../MemoizeStaticMethod/Extension.java | 4 +- .../MemoizeStaticMethod/GlideOptions.java | 6 +- .../OverrideExtend/Extension.java | 4 +- .../OverrideExtend/GlideOptions.java | 7 +- .../Extension.java | 20 + .../GlideOptions.java | 551 +++++++++++++ .../GlideRequest.java | 712 +++++++++++++++++ .../OverrideReplace/Extension.java | 4 +- .../OverrideReplace/GlideOptions.java | 6 +- .../SkipStaticMethod/Extension.java | 4 +- .../SkipStaticMethod/GlideOptions.java | 6 +- .../StaticMethodName/Extension.java | 4 +- .../StaticMethodName/GlideOptions.java | 6 +- .../ExtensionWithOption.java | 4 +- .../GlideOptions.java | 6 +- .../MemoizeStaticMethod/Extension.java | 18 + .../MemoizeStaticMethod/GlideOptions.java | 574 ++++++++++++++ .../MemoizeStaticMethod/GlideRequest.java | 725 ++++++++++++++++++ .../OverrideExtend/Extension.java | 18 + .../OverrideExtend/GlideOptions.java | 565 ++++++++++++++ .../OverrideExtend/GlideRequest.java | 712 +++++++++++++++++ .../OverrideReplace/Extension.java | 18 + .../OverrideReplace/GlideOptions.java | 562 ++++++++++++++ .../OverrideReplace/GlideRequest.java | 712 +++++++++++++++++ .../SkipStaticMethod/Extension.java | 18 + .../SkipStaticMethod/GlideOptions.java | 560 ++++++++++++++ .../SkipStaticMethod/GlideRequest.java | 725 ++++++++++++++++++ .../StaticMethodName/Extension.java | 18 + .../StaticMethodName/GlideOptions.java | 568 ++++++++++++++ .../StaticMethodName/GlideRequest.java | 725 ++++++++++++++++++ .../ExtensionWithOption.java | 18 + .../GlideOptions.java | 568 ++++++++++++++ .../GlideRequest.java | 725 ++++++++++++++++++ .../glide/annotation/GlideOption.java | 48 ++ .../samples/flickr/FlickrGlideExtension.java | 34 + 51 files changed, 9719 insertions(+), 149 deletions(-) create mode 100644 annotation/compiler/test/src/test/java/com/bumptech/glide/annotation/compiler/LegacyGlideExtensionOptionsTest.java create mode 100644 annotation/compiler/test/src/test/java/com/bumptech/glide/annotation/compiler/LegacyGlideExtensionWithOptionTest.java create mode 100644 annotation/compiler/test/src/test/resources/GlideExtensionOptionsTest/OverrideExtendMultipleArguments/Extension.java create mode 100644 annotation/compiler/test/src/test/resources/GlideExtensionOptionsTest/OverrideExtendMultipleArguments/GlideOptions.java create mode 100644 annotation/compiler/test/src/test/resources/GlideExtensionOptionsTest/OverrideExtendMultipleArguments/GlideRequest.java create mode 100644 annotation/compiler/test/src/test/resources/LegacyGlideExtensionOptionsTest/MemoizeStaticMethod/Extension.java create mode 100644 annotation/compiler/test/src/test/resources/LegacyGlideExtensionOptionsTest/MemoizeStaticMethod/GlideOptions.java create mode 100644 annotation/compiler/test/src/test/resources/LegacyGlideExtensionOptionsTest/MemoizeStaticMethod/GlideRequest.java create mode 100644 annotation/compiler/test/src/test/resources/LegacyGlideExtensionOptionsTest/OverrideExtend/Extension.java create mode 100644 annotation/compiler/test/src/test/resources/LegacyGlideExtensionOptionsTest/OverrideExtend/GlideOptions.java create mode 100644 annotation/compiler/test/src/test/resources/LegacyGlideExtensionOptionsTest/OverrideExtend/GlideRequest.java create mode 100644 annotation/compiler/test/src/test/resources/LegacyGlideExtensionOptionsTest/OverrideReplace/Extension.java create mode 100644 annotation/compiler/test/src/test/resources/LegacyGlideExtensionOptionsTest/OverrideReplace/GlideOptions.java create mode 100644 annotation/compiler/test/src/test/resources/LegacyGlideExtensionOptionsTest/OverrideReplace/GlideRequest.java create mode 100644 annotation/compiler/test/src/test/resources/LegacyGlideExtensionOptionsTest/SkipStaticMethod/Extension.java create mode 100644 annotation/compiler/test/src/test/resources/LegacyGlideExtensionOptionsTest/SkipStaticMethod/GlideOptions.java create mode 100644 annotation/compiler/test/src/test/resources/LegacyGlideExtensionOptionsTest/SkipStaticMethod/GlideRequest.java create mode 100644 annotation/compiler/test/src/test/resources/LegacyGlideExtensionOptionsTest/StaticMethodName/Extension.java create mode 100644 annotation/compiler/test/src/test/resources/LegacyGlideExtensionOptionsTest/StaticMethodName/GlideOptions.java create mode 100644 annotation/compiler/test/src/test/resources/LegacyGlideExtensionOptionsTest/StaticMethodName/GlideRequest.java create mode 100644 annotation/compiler/test/src/test/resources/LegacyGlideExtensionWithOptionTest/ExtensionWithOption.java create mode 100644 annotation/compiler/test/src/test/resources/LegacyGlideExtensionWithOptionTest/GlideOptions.java create mode 100644 annotation/compiler/test/src/test/resources/LegacyGlideExtensionWithOptionTest/GlideRequest.java create mode 100644 samples/flickr/src/main/java/com/bumptech/glide/samples/flickr/FlickrGlideExtension.java diff --git a/annotation/compiler/src/main/java/com/bumptech/glide/annotation/compiler/ExtensionProcessor.java b/annotation/compiler/src/main/java/com/bumptech/glide/annotation/compiler/ExtensionProcessor.java index 4d6ac80c83..b13fdd0e42 100644 --- a/annotation/compiler/src/main/java/com/bumptech/glide/annotation/compiler/ExtensionProcessor.java +++ b/annotation/compiler/src/main/java/com/bumptech/glide/annotation/compiler/ExtensionProcessor.java @@ -5,6 +5,7 @@ import java.util.Collections; import java.util.List; import java.util.Set; +import javax.annotation.processing.ProcessingEnvironment; import javax.annotation.processing.RoundEnvironment; import javax.lang.model.element.TypeElement; @@ -15,17 +16,22 @@ final class ExtensionProcessor { private final ProcessorUtil processorUtil; private final IndexerGenerator indexerGenerator; + private final GlideExtensionValidator extensionValidator; - ExtensionProcessor(ProcessorUtil processorUtil, IndexerGenerator indexerGenerator) { + ExtensionProcessor( + ProcessingEnvironment processingEnvironment, + ProcessorUtil processorUtil, + IndexerGenerator indexerGenerator) { this.processorUtil = processorUtil; this.indexerGenerator = indexerGenerator; + extensionValidator = new GlideExtensionValidator(processingEnvironment, processorUtil); } boolean processExtensions(Set set, RoundEnvironment env) { List elements = processorUtil.getElementsFor(GlideExtension.class, env); processorUtil.debugLog("Processing types : " + elements); for (TypeElement typeElement : elements) { - GlideExtensionValidator.validateExtension(typeElement); + extensionValidator.validateExtension(typeElement); processorUtil.debugLog("Processing elements: " + typeElement.getEnclosedElements()); } diff --git a/annotation/compiler/src/main/java/com/bumptech/glide/annotation/compiler/GlideAnnotationProcessor.java b/annotation/compiler/src/main/java/com/bumptech/glide/annotation/compiler/GlideAnnotationProcessor.java index 1f69501cd5..ce6df22436 100644 --- a/annotation/compiler/src/main/java/com/bumptech/glide/annotation/compiler/GlideAnnotationProcessor.java +++ b/annotation/compiler/src/main/java/com/bumptech/glide/annotation/compiler/GlideAnnotationProcessor.java @@ -80,7 +80,8 @@ public synchronized void init(ProcessingEnvironment processingEnvironment) { IndexerGenerator indexerGenerator = new IndexerGenerator(processorUtil); libraryModuleProcessor = new LibraryModuleProcessor(processorUtil, indexerGenerator); appModuleProcessor = new AppModuleProcessor(processingEnvironment, processorUtil); - extensionProcessor = new ExtensionProcessor(processorUtil, indexerGenerator); + extensionProcessor = + new ExtensionProcessor(processingEnvironment, processorUtil, indexerGenerator); } @Override 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 18ef19d65e..8accda227c 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,6 +2,9 @@ import com.bumptech.glide.annotation.GlideOption; import com.bumptech.glide.annotation.GlideType; +import java.util.ArrayList; +import java.util.List; +import javax.annotation.processing.ProcessingEnvironment; import javax.lang.model.element.Element; import javax.lang.model.element.ElementKind; import javax.lang.model.element.ExecutableElement; @@ -21,9 +24,16 @@ */ final class GlideExtensionValidator { - private GlideExtensionValidator() { } + private final ProcessingEnvironment processingEnvironment; + private final ProcessorUtil processorUtil; - static void validateExtension(TypeElement typeElement) { + GlideExtensionValidator( + ProcessingEnvironment processingEnvironment, ProcessorUtil processorUtil) { + this.processingEnvironment = processingEnvironment; + this.processorUtil = processorUtil; + } + + void validateExtension(TypeElement typeElement) { if (!typeElement.getModifiers().contains(Modifier.PUBLIC)) { throw new IllegalArgumentException("RequestOptionsExtensions must be public"); } @@ -43,7 +53,7 @@ static void validateExtension(TypeElement typeElement) { if (element.getKind() == ElementKind.METHOD) { ExecutableElement executableElement = (ExecutableElement) element; if (executableElement.getAnnotation(GlideOption.class) != null) { - validateExtendsRequestOptions(executableElement); + validateGlideOption(executableElement); } else if (executableElement.getAnnotation(GlideType.class) != null) { validateExtendsRequestManager(executableElement); } @@ -51,21 +61,104 @@ static void validateExtension(TypeElement typeElement) { } } - private static void validateExtendsRequestOptions(ExecutableElement executableElement) { + private void validateGlideOption(ExecutableElement executableElement) { + if (isVoid(executableElement)) { + validateDeprecatedGlideOption(executableElement); + } else { + validateNewGlideOption(executableElement); + } + } + + private void validateNewGlideOption(ExecutableElement executableElement) { + validateGlideOptionParameters(executableElement); + TypeMirror returnType = executableElement.getReturnType(); + if (!isRequestOptions(returnType)) { + throw new IllegalArgumentException("@GlideOption methods should return a RequestOptions" + + " object, but given: " + returnType + ". If you're using old style @GlideOption" + + " methods, your method may have a void return type, but doing so is deprecated and" + + " support will be removed in a future version"); + } + validateGlideOptionOverride(executableElement); + } + + private void validateDeprecatedGlideOption(ExecutableElement executableElement) { validateStaticVoid(executableElement, GlideOption.class); + validateGlideOptionParameters(executableElement); + validateGlideOptionOverride(executableElement); + } + + private static void validateGlideOptionParameters(ExecutableElement executableElement) { if (executableElement.getParameters().isEmpty()) { throw new IllegalArgumentException("@GlideOption methods must take a " + "RequestOptions object as their first parameter, but given none"); } VariableElement first = executableElement.getParameters().get(0); TypeMirror expected = first.asType(); - if (!expected.toString().equals( - "com.bumptech.glide.request.RequestOptions")) { + if (!isRequestOptions(expected)) { throw new IllegalArgumentException("@GlideOption methods must take a" + " RequestOptions object as their first parameter, but given: " + expected); } } + private static boolean isRequestOptions(TypeMirror typeMirror) { + return typeMirror.toString().equals("com.bumptech.glide.request.RequestOptions"); + } + + private void validateGlideOptionOverride(ExecutableElement element) { + int overrideType = processorUtil.getOverrideType(element); + boolean isOverridingRequestOptionsMethod = isMethodInRequestOptions(element); + if (isOverridingRequestOptionsMethod && overrideType == GlideOption.OVERRIDE_NONE) { + throw new IllegalArgumentException("Accidentally attempting to override a method in" + + " RequestOptions. Add an 'override' value in the @GlideOption annotation" + + " if this is intentional. Offending method: " + + element.getEnclosingElement() + "#" + element); + } else if (!isOverridingRequestOptionsMethod && overrideType != GlideOption.OVERRIDE_NONE) { + throw new IllegalArgumentException("Requested to override an existing method in" + + " RequestOptions, but no such method was found. Offending method: " + + element.getEnclosingElement() + "#" + element); + } + } + + private boolean isMethodInRequestOptions(ExecutableElement toFind) { + // toFind is a method in a GlideExtension whose first argument is a BaseRequestOptions type. + // Since we're comparing against methods in BaseRequestOptions itself, we need to drop that + // first type. + TypeElement requestOptionsType = + processingEnvironment + .getElementUtils() + .getTypeElement(RequestOptionsGenerator.REQUEST_OPTIONS_QUALIFIED_NAME); + List toFindParameterNames = getComparableParameterNames(toFind, true /*skipFirst*/); + String toFindSimpleName = toFind.getSimpleName().toString(); + for (Element element : requestOptionsType.getEnclosedElements()) { + if (element.getKind() != ElementKind.METHOD) { + continue; + } + ExecutableElement inBase = (ExecutableElement) element; + if (toFindSimpleName.equals(inBase.getSimpleName().toString())) { + List parameterNamesInBase = + getComparableParameterNames(inBase, false /*skipFirst*/); + if (parameterNamesInBase.equals(toFindParameterNames)) { + return true; + } + } + } + return false; + } + + private static List getComparableParameterNames( + ExecutableElement element, boolean skipFirst) { + List parameters = element.getParameters(); + if (skipFirst) { + parameters = parameters.subList(1, parameters.size()); + } + List result = new ArrayList<>(parameters.size()); + for (VariableElement parameter : parameters) { + result.add(parameter.asType().toString()); + } + return result; + } + + private static void validateExtendsRequestManager(ExecutableElement executableElement) { validateStaticVoid(executableElement, GlideType.class); if (executableElement.getParameters().size() != 1) { @@ -82,13 +175,25 @@ private static void validateExtendsRequestManager(ExecutableElement executableEl } } - private static void validateStaticVoid(ExecutableElement executableElement, Class clazz) { + private static void validateStatic(ExecutableElement executableElement, Class clazz) { if (!executableElement.getModifiers().contains(Modifier.STATIC)) { throw new IllegalArgumentException("@" + clazz.getSimpleName() + " methods must be static"); } + } + + private static boolean isVoid(ExecutableElement executableElement) { TypeMirror returnType = executableElement.getReturnType(); - if (returnType.getKind() != TypeKind.VOID) { + return returnType.getKind() == TypeKind.VOID; + } + + private static void validateVoid(ExecutableElement executableElement, Class clazz) { + if (!isVoid(executableElement)) { throw new IllegalArgumentException("@" + clazz.getSimpleName() + " methods must return void"); } } + + private static void validateStaticVoid(ExecutableElement executableElement, Class clazz) { + validateStatic(executableElement, clazz); + validateVoid(executableElement, clazz); + } } diff --git a/annotation/compiler/src/main/java/com/bumptech/glide/annotation/compiler/ProcessorUtil.java b/annotation/compiler/src/main/java/com/bumptech/glide/annotation/compiler/ProcessorUtil.java index 25cd257ac4..0ec1bbd64d 100644 --- a/annotation/compiler/src/main/java/com/bumptech/glide/annotation/compiler/ProcessorUtil.java +++ b/annotation/compiler/src/main/java/com/bumptech/glide/annotation/compiler/ProcessorUtil.java @@ -3,6 +3,7 @@ import static com.bumptech.glide.annotation.compiler.GlideAnnotationProcessor.DEBUG; import com.bumptech.glide.annotation.GlideExtension; +import com.bumptech.glide.annotation.GlideOption; import com.google.common.base.Function; import com.google.common.base.Joiner; import com.google.common.base.Predicate; @@ -93,6 +94,12 @@ boolean isExtension(TypeElement element) { return element.getAnnotation(GlideExtension.class) != null; } + int getOverrideType(ExecutableElement element) { + GlideOption glideOption = + element.getAnnotation(GlideOption.class); + return glideOption.override(); + } + void writeIndexer(TypeSpec indexer) { writeClass(COMPILER_PACKAGE_NAME, indexer); } @@ -211,7 +218,6 @@ private CodeBlock generateSeeMethodJavadocInternal( return CodeBlock.of(javadocString, javadocArgs.toArray(new Object[0])); } - /** * Returns a safe String to use in a Javadoc that will function in a link. * @@ -239,8 +245,8 @@ void infoLog(String toLog) { processingEnv.getMessager().printMessage(Diagnostic.Kind.NOTE, "[" + round + "] " + toLog); } - void error(String toLog) { - processingEnv.getMessager().printMessage(Diagnostic.Kind.ERROR, toLog); + void warnLog(String toLog) { + processingEnv.getMessager().printMessage(Diagnostic.Kind.WARNING, toLog); } static CodeBlock generateCastingSuperCall(TypeName toReturn, ExecutableElement method) { 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 4677177825..597ce499e2 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 @@ -1,7 +1,6 @@ package com.bumptech.glide.annotation.compiler; import static com.bumptech.glide.annotation.GlideOption.OVERRIDE_EXTEND; -import static com.bumptech.glide.annotation.GlideOption.OVERRIDE_NONE; import com.bumptech.glide.annotation.GlideExtension; import com.bumptech.glide.annotation.GlideOption; @@ -30,12 +29,12 @@ 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; import javax.lang.model.element.Modifier; import javax.lang.model.element.TypeElement; import javax.lang.model.element.TypeParameterElement; import javax.lang.model.element.VariableElement; +import javax.lang.model.type.TypeKind; /** * Generates a new implementation of {@code com.bumptech.glide.request.RequestOptions} @@ -225,18 +224,23 @@ public String apply(VariableElement input) { private List generateMethodsForRequestOptionsExtension( ExecutableElement element) { - boolean isOverridingRequestOptionsMethod = isMethodInRequestOptions(element); - int overrideType = getOverrideType(element); - if (isOverridingRequestOptionsMethod && overrideType == OVERRIDE_NONE) { - throw new IllegalArgumentException("Accidentally attempting to override a method in" - + " RequestOptions. Add an 'override' value in the @GlideOption annotation" - + " if this is intentional. Offending method: " - + element.getEnclosingElement() + "#" + element); - } else if (!isOverridingRequestOptionsMethod && overrideType != OVERRIDE_NONE) { - throw new IllegalArgumentException("Requested to override an existing method in" - + " RequestOptions, but no such method was found. Offending method: " - + element.getEnclosingElement() + "#" + element); + if (element.getReturnType().getKind() == TypeKind.VOID) { + processorUtil.warnLog( + "The " + element.getSimpleName() + " method annotated with @GlideOption in the " + + element.getEnclosingElement().getSimpleName() + " @GlideExtension is using a legacy" + + " format. Support will be removed in a future version. Please change your method" + + " definition so that your @GlideModule annotated methods return RequestOptions" + + " objects instead of null."); + return generateMethodsForRequestOptionsExtensionDeprecated(element); + } else { + return generateMethodsForRequestOptionsExtensionNew(element); } + } + + private List generateMethodsForRequestOptionsExtensionNew( + ExecutableElement element) { + int overrideType = processorUtil.getOverrideType(element); + String methodName = element.getSimpleName().toString(); MethodSpec.Builder builder = MethodSpec.methodBuilder(methodName) .addModifiers(Modifier.PUBLIC) @@ -247,6 +251,76 @@ private List generateMethodsForRequestOptionsExtension( // The 0th element is expected to be a RequestOptions object. List parameters = element.getParameters().subList(1, element.getParameters().size()); + builder.addParameters(ProcessorUtil.getParameters(parameters)); + + String extensionRequestOptionsArgument; + if (overrideType == OVERRIDE_EXTEND) { + builder + .addJavadoc( + processorUtil.generateSeeMethodJavadoc(requestOptionsName, methodName, parameters)) + .addAnnotation(Override.class); + + List methodArgs = new ArrayList<>(); + methodArgs.add(element.getSimpleName().toString()); + String methodLiterals = ""; + if (!parameters.isEmpty()) { + for (VariableElement variable : parameters) { + methodLiterals += "$L, "; + methodArgs.add(variable.getSimpleName().toString()); + } + methodLiterals = methodLiterals.substring(0, methodLiterals.length() - 2); + } + extensionRequestOptionsArgument = CodeBlock.builder() + .add( + "super.$N(" + methodLiterals + ")", methodArgs.toArray(new Object[0])) + .build() + .toString(); + } else { + extensionRequestOptionsArgument = "this"; + } + + List args = new ArrayList<>(); + String code = "return ($T) $T.$L($L, "; + args.add(glideOptionsName); + args.add(ClassName.get(element.getEnclosingElement().asType())); + args.add(element.getSimpleName().toString()); + args.add(extensionRequestOptionsArgument); + if (!parameters.isEmpty()) { + for (VariableElement variable : parameters) { + code += "$L, "; + args.add(variable.getSimpleName().toString()); + } + } + code = code.substring(0, code.length() - 2); + code += ")"; + builder.addStatement(code, args.toArray(new Object[0])); + builder.addAnnotation(AnnotationSpec.builder(CHECK_RESULT_CLASS_NAME).build()); + + List result = new ArrayList<>(); + result.add(new MethodAndStaticVar(builder.build())); + MethodAndStaticVar methodAndVar = generateStaticMethodEquivalentForExtensionMethod(element); + if (methodAndVar != null) { + result.add(methodAndVar); + } + + return result; + } + + private List generateMethodsForRequestOptionsExtensionDeprecated( + ExecutableElement element) { + int overrideType = processorUtil.getOverrideType(element); + + String methodName = element.getSimpleName().toString(); + MethodSpec.Builder builder = MethodSpec.methodBuilder(methodName) + .addModifiers(Modifier.PUBLIC) + .addJavadoc(processorUtil.generateSeeMethodJavadoc(element)) + .varargs(element.isVarArgs()) + .returns(glideOptionsName); + + // The 0th element is expected to be a RequestOptions object. + List parameters = + element.getParameters().subList(1, element.getParameters().size()); + builder.addParameters(ProcessorUtil.getParameters(parameters)); // Generates the String and list of arguments to pass in when calling this method or super. // IE centerCrop(context) creates methodLiterals="%L" and methodArgs=[centerCrop, context]. @@ -275,7 +349,6 @@ private List generateMethodsForRequestOptionsExtension( .addAnnotation(Override.class); } - builder.addParameters(ProcessorUtil.getParameters(parameters)); // Adds: .(RequestOptions, , , ); List args = new ArrayList<>(); @@ -294,11 +367,9 @@ private List generateMethodsForRequestOptionsExtension( builder.addStatement(code, args.toArray(new Object[0])); builder.addStatement("return this"); - - List result = new ArrayList<>(); - builder.addAnnotation(AnnotationSpec.builder(CHECK_RESULT_CLASS_NAME).build()); + List result = new ArrayList<>(); result.add(new MethodAndStaticVar(builder.build())); MethodAndStaticVar methodAndVar = generateStaticMethodEquivalentForExtensionMethod(element); if (methodAndVar != null) { @@ -520,47 +591,6 @@ private boolean isAndroidContext(VariableElement variableElement) { return element.toString().equals("android.content.Context"); } - private boolean isMethodInRequestOptions(ExecutableElement toFind) { - // toFind is a method in a GlideExtension whose first argument is a BaseRequestOptions type. - // Since we're comparing against methods in BaseRequestOptions itself, we need to drop that - // first type. - List toFindParameterNames = getComparableParameterNames(toFind, true /*skipFirst*/); - String toFindSimpleName = toFind.getSimpleName().toString(); - for (Element element : requestOptionsType.getEnclosedElements()) { - if (element.getKind() != ElementKind.METHOD) { - continue; - } - ExecutableElement inBase = (ExecutableElement) element; - if (toFindSimpleName.equals(inBase.getSimpleName().toString())) { - List parameterNamesInBase = - getComparableParameterNames(inBase, false /*skipFirst*/); - if (parameterNamesInBase.equals(toFindParameterNames)) { - return true; - } - } - } - return false; - } - - private static List getComparableParameterNames( - ExecutableElement element, boolean skipFirst) { - List parameters = element.getParameters(); - if (skipFirst) { - parameters = parameters.subList(1, parameters.size()); - } - List result = new ArrayList<>(parameters.size()); - for (VariableElement parameter : parameters) { - result.add(parameter.asType().toString()); - } - return result; - } - - private static int getOverrideType(ExecutableElement element) { - GlideOption glideOption = - element.getAnnotation(GlideOption.class); - return glideOption.override(); - } - @Nullable private static String getStaticMethodName(ExecutableElement element) { GlideOption glideOption = @@ -587,10 +617,6 @@ private static final class MethodAndStaticVar { @Nullable final FieldSpec staticField; - MethodAndStaticVar() { - this(null /*method*/); - } - MethodAndStaticVar(@Nullable MethodSpec method) { this(method, null /*staticField*/); } diff --git a/annotation/compiler/test/src/test/java/com/bumptech/glide/annotation/compiler/EmptyAppAndLibraryGlideModulesTest.java b/annotation/compiler/test/src/test/java/com/bumptech/glide/annotation/compiler/EmptyAppAndLibraryGlideModulesTest.java index 03f0b95780..55f07d5af3 100644 --- a/annotation/compiler/test/src/test/java/com/bumptech/glide/annotation/compiler/EmptyAppAndLibraryGlideModulesTest.java +++ b/annotation/compiler/test/src/test/java/com/bumptech/glide/annotation/compiler/EmptyAppAndLibraryGlideModulesTest.java @@ -23,7 +23,6 @@ * {@link com.bumptech.glide.module.LibraryGlideModule} in a single project. */ public class EmptyAppAndLibraryGlideModulesTest { - private static final String DIR_NAME = EmptyAppAndLibraryGlideModulesTest.class.getSimpleName(); private Compilation compilation; @Before @@ -100,7 +99,7 @@ public void compilation_generatesExpectedIndexer() throws IOException { .isEqualTo(libraryResource(expectedClassName + ".java").getCharContent(true)); } - private static JavaFileObject forResource(String name) { - return Util.forResource(DIR_NAME, name); + private JavaFileObject forResource(String name) { + return Util.forResource(getClass().getSimpleName(), name); } } diff --git a/annotation/compiler/test/src/test/java/com/bumptech/glide/annotation/compiler/EmptyAppGlideModuleTest.java b/annotation/compiler/test/src/test/java/com/bumptech/glide/annotation/compiler/EmptyAppGlideModuleTest.java index 3f516968bf..682afa0f26 100644 --- a/annotation/compiler/test/src/test/java/com/bumptech/glide/annotation/compiler/EmptyAppGlideModuleTest.java +++ b/annotation/compiler/test/src/test/java/com/bumptech/glide/annotation/compiler/EmptyAppGlideModuleTest.java @@ -17,7 +17,6 @@ * Tests adding a single {@link com.bumptech.glide.test.EmptyAppModule} in a project. */ public class EmptyAppGlideModuleTest { - private static final String DIR_NAME = "EmptyAppGlideModuleTest"; private static final String MODULE_NAME = "EmptyAppModule.java"; private Compilation compilation; @@ -83,8 +82,8 @@ public void compilation_generatesExpectedGeneratedRequestManagerFactory() throws .isEqualTo(forResource("GeneratedRequestManagerFactory.java").getCharContent(true)); } - private static JavaFileObject forResource(String name) { - return Util.forResource(DIR_NAME, name); + private JavaFileObject forResource(String name) { + return Util.forResource(getClass().getSimpleName(), name); } } diff --git a/annotation/compiler/test/src/test/java/com/bumptech/glide/annotation/compiler/EmptyLibraryGlideModuleTest.java b/annotation/compiler/test/src/test/java/com/bumptech/glide/annotation/compiler/EmptyLibraryGlideModuleTest.java index a7effda46e..a8e459b25a 100644 --- a/annotation/compiler/test/src/test/java/com/bumptech/glide/annotation/compiler/EmptyLibraryGlideModuleTest.java +++ b/annotation/compiler/test/src/test/java/com/bumptech/glide/annotation/compiler/EmptyLibraryGlideModuleTest.java @@ -16,7 +16,6 @@ * Tests adding a single {@link com.bumptech.glide.module.LibraryGlideModule} in a project. */ public class EmptyLibraryGlideModuleTest { - private static final String DIR_NAME = "EmptyLibraryGlideModuleTest"; private static final String MODULE_NAME = "EmptyLibraryModule.java"; private Compilation compilation; @@ -44,7 +43,7 @@ public void compilation_generatesExpectedIndexer() throws IOException { .isEqualTo(forResource(expectedClassName + ".java").getCharContent(true)); } - private static JavaFileObject forResource(String name) { - return Util.forResource(DIR_NAME, name); + private JavaFileObject forResource(String name) { + return Util.forResource(getClass().getSimpleName(), name); } } diff --git a/annotation/compiler/test/src/test/java/com/bumptech/glide/annotation/compiler/GlideExtensionOptionsTest.java b/annotation/compiler/test/src/test/java/com/bumptech/glide/annotation/compiler/GlideExtensionOptionsTest.java index 2c9c1fbaaa..23bd5f121d 100644 --- a/annotation/compiler/test/src/test/java/com/bumptech/glide/annotation/compiler/GlideExtensionOptionsTest.java +++ b/annotation/compiler/test/src/test/java/com/bumptech/glide/annotation/compiler/GlideExtensionOptionsTest.java @@ -14,10 +14,9 @@ /** * Verifies only the output we expect to change based on the various configurations of GlideOptions. * - *

The output for all classes is tested in {@link GlideExtensionWithOptionTest}. + *

The output for all classes is tested in {@link LegacyGlideExtensionWithOptionTest}. */ public class GlideExtensionOptionsTest { - private static final String DIR_NAME = GlideExtensionOptionsTest.class.getSimpleName(); private static final String EXTENSION_NAME = "Extension.java"; @Test @@ -30,6 +29,18 @@ public void compilation_withOverrideExtend_validRequest() throws IOException { runTest("OverrideExtend", Subject.GlideRequest); } + @Test + public void compilation_withOverrideReplace_andMultipleArguments_validOptions() + throws IOException { + runTest("OverrideExtendMultipleArguments", Subject.GlideOptions); + } + + @Test + public void compilation_withOverrideReplace_andMultipleArguments_validRequest() + throws IOException { + runTest("OverrideExtendMultipleArguments", Subject.GlideRequest); + } + @Test public void compilation_withOverrideReplace_validOptions() throws IOException { runTest("OverrideReplace", Subject.GlideOptions); @@ -94,11 +105,11 @@ private void runTest(String subDir, Subject subject) throws IOException { .isEqualTo(forResource(subDir, subject.file()).getCharContent(true)); } - private static JavaFileObject extension(String subdir) { + private JavaFileObject extension(String subdir) { return forResource(subdir, EXTENSION_NAME); } - private static JavaFileObject forResource(String subdir, String name) { - return Util.forResource(DIR_NAME, subdir + "/" + name); + private JavaFileObject forResource(String subdir, String name) { + return Util.forResource(getClass().getSimpleName(), subdir + "/" + name); } } diff --git a/annotation/compiler/test/src/test/java/com/bumptech/glide/annotation/compiler/GlideExtensionWithOptionTest.java b/annotation/compiler/test/src/test/java/com/bumptech/glide/annotation/compiler/GlideExtensionWithOptionTest.java index d0eeb8dee0..b817a574d7 100644 --- a/annotation/compiler/test/src/test/java/com/bumptech/glide/annotation/compiler/GlideExtensionWithOptionTest.java +++ b/annotation/compiler/test/src/test/java/com/bumptech/glide/annotation/compiler/GlideExtensionWithOptionTest.java @@ -16,10 +16,10 @@ import org.junit.Test; /** - * Verifies the output of the processor with a simple single extension option. + * Verifies the output of the processor with a simple single extension option in the new + * option style where extension methods always return values. */ public class GlideExtensionWithOptionTest { - private static final String DIR_NAME = GlideExtensionWithOptionTest.class.getSimpleName(); private Compilation compilation; @Before @@ -86,7 +86,7 @@ public void compilation_generatesExpectedGeneratedRequestManagerFactory() throws .isEqualTo(appResource("GeneratedRequestManagerFactory.java").getCharContent(true)); } - private static JavaFileObject forResource(String name) { - return Util.forResource(DIR_NAME, name); + private JavaFileObject forResource(String name) { + return Util.forResource(getClass().getSimpleName(), name); } } diff --git a/annotation/compiler/test/src/test/java/com/bumptech/glide/annotation/compiler/GlideExtensionWithTypeTest.java b/annotation/compiler/test/src/test/java/com/bumptech/glide/annotation/compiler/GlideExtensionWithTypeTest.java index 525f05ac9d..c30527bcea 100644 --- a/annotation/compiler/test/src/test/java/com/bumptech/glide/annotation/compiler/GlideExtensionWithTypeTest.java +++ b/annotation/compiler/test/src/test/java/com/bumptech/glide/annotation/compiler/GlideExtensionWithTypeTest.java @@ -19,7 +19,6 @@ * Verifies the output of the processor with a simple single extension type. */ public class GlideExtensionWithTypeTest { - private static final String DIR_NAME = GlideExtensionWithTypeTest.class.getSimpleName(); private Compilation compilation; @Before @@ -86,7 +85,7 @@ public void compilation_generatesExpectedGeneratedRequestManagerFactory() throws .isEqualTo(appResource("GeneratedRequestManagerFactory.java").getCharContent(true)); } - private static JavaFileObject forResource(String name) { - return Util.forResource(DIR_NAME, name); + private JavaFileObject forResource(String name) { + return Util.forResource(getClass().getSimpleName(), name); } } 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 5f3c984354..edd87a8afc 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 @@ -99,7 +99,8 @@ public void compilation_withAnnotatedStaticMethod_withRequestOptionsArg_succeeds " @GlideOption", " public static void doSomething(RequestOptions options) {}", "}")); - assertThat(compilation).succeededWithoutWarnings(); + assertThat(compilation).succeeded(); + assertThat(compilation).hadWarningContaining("is using a legacy format."); } @Test @@ -120,7 +121,8 @@ public void compilation_withAnnotatedStaticMethod_withRequestOptionsArgAndOtherA " @GlideOption", " public static void doSomething(RequestOptions options, Object arg2) {}", "}")); - assertThat(compilation).succeededWithoutWarnings(); + assertThat(compilation).succeeded(); + assertThat(compilation).hadWarningContaining("is using a legacy format."); } @Test @@ -183,7 +185,8 @@ public void compilation_withOverrideExtend_andOverridingMethod_succeeds() { " @GlideOption(override = GlideOption.OVERRIDE_EXTEND)", " public static void centerCrop(RequestOptions options) {}", "}")); - assertThat(compilation).succeededWithoutWarnings(); + assertThat(compilation).succeeded(); + assertThat(compilation).hadWarningContaining("is using a legacy format."); } @Test @@ -225,6 +228,53 @@ public void compilation_withOverrideReplace_andOverridingMethod_succeeds() { " @GlideOption(override = GlideOption.OVERRIDE_REPLACE)", " public static void centerCrop(RequestOptions options) {}", "}")); + assertThat(compilation).succeeded(); + assertThat(compilation).hadWarningContaining("is using a legacy format."); + } + + @Test + public void compilation_withRequestOptionsReturnValue_succeeds() { + 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).succeededWithoutWarnings(); } + + @Test + public void compilation_withNonRequestOptionsReturnValue_fails() { + expectedException.expect(RuntimeException.class); + 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 Object doSomething(RequestOptions options) {", + " return options;", + " }", + "}")); + } } diff --git a/annotation/compiler/test/src/test/java/com/bumptech/glide/annotation/compiler/LegacyGlideExtensionOptionsTest.java b/annotation/compiler/test/src/test/java/com/bumptech/glide/annotation/compiler/LegacyGlideExtensionOptionsTest.java new file mode 100644 index 0000000000..174943da62 --- /dev/null +++ b/annotation/compiler/test/src/test/java/com/bumptech/glide/annotation/compiler/LegacyGlideExtensionOptionsTest.java @@ -0,0 +1,104 @@ +package com.bumptech.glide.annotation.compiler; + +import static com.bumptech.glide.annotation.compiler.test.Util.emptyAppModule; +import static com.bumptech.glide.annotation.compiler.test.Util.subpackage; +import static com.google.testing.compile.CompilationSubject.assertThat; +import static com.google.testing.compile.Compiler.javac; + +import com.bumptech.glide.annotation.compiler.test.Util; +import com.google.testing.compile.Compilation; +import java.io.IOException; +import javax.tools.JavaFileObject; +import org.junit.Test; + +/** + * Verifies only the output we expect to change based on the various configurations of GlideOptions + * when GlideOptions are defined in the legacy format. + * + *

The output for all classes is tested in {@link LegacyGlideExtensionWithOptionTest}. + */ +public class LegacyGlideExtensionOptionsTest { + private static final String EXTENSION_NAME = "Extension.java"; + + @Test + public void compilation_withOverrideExtend_validOptions() throws IOException { + runTest("OverrideExtend", Subject.GlideOptions); + } + + @Test + public void compilation_withOverrideExtend_validRequest() throws IOException { + runTest("OverrideExtend", Subject.GlideRequest); + } + + @Test + public void compilation_withOverrideReplace_validOptions() throws IOException { + runTest("OverrideReplace", Subject.GlideOptions); + } + + @Test + public void compilation_withOverrideReplace_validRequest() throws IOException { + runTest("OverrideReplace", Subject.GlideRequest); + } + + @Test + public void compilation_withStaticMethodName_validOptions() throws IOException { + runTest("StaticMethodName", Subject.GlideOptions); + } + + @Test + public void compilation_withStaticMethodName_validRequest() throws IOException { + runTest("StaticMethodName", Subject.GlideRequest); + } + + @Test + public void compilation_withMemoizeStaticMethod_validOptions() throws IOException { + runTest("MemoizeStaticMethod", Subject.GlideOptions); + } + + @Test + public void compilation_withMemoizeStaticMethod_validRequest() throws IOException { + runTest("MemoizeStaticMethod", Subject.GlideRequest); + } + + @Test + public void compilation_withSkipStaticMethod_validOptions() throws IOException { + runTest("SkipStaticMethod", Subject.GlideOptions); + } + + @Test + public void compilation_withSkipStaticMethod_validRequest() throws IOException { + runTest("SkipStaticMethod", Subject.GlideRequest); + } + + private enum Subject { + GlideOptions, + GlideRequest; + + String file() { + return name() + ".java"; + } + } + + private void runTest(String subDir, Subject subject) throws IOException { + Compilation compilation = + javac() + .withProcessors(new GlideAnnotationProcessor()) + .compile( + emptyAppModule(), + extension(subDir)); + assertThat(compilation).succeeded(); + + assertThat(compilation) + .generatedSourceFile(subpackage(subject.name())) + .contentsAsUtf8String() + .isEqualTo(forResource(subDir, subject.file()).getCharContent(true)); + } + + private JavaFileObject extension(String subdir) { + return forResource(subdir, EXTENSION_NAME); + } + + private JavaFileObject forResource(String subdir, String name) { + return Util.forResource(getClass().getSimpleName(), subdir + "/" + name); + } +} diff --git a/annotation/compiler/test/src/test/java/com/bumptech/glide/annotation/compiler/LegacyGlideExtensionWithOptionTest.java b/annotation/compiler/test/src/test/java/com/bumptech/glide/annotation/compiler/LegacyGlideExtensionWithOptionTest.java new file mode 100644 index 0000000000..c27831b5d9 --- /dev/null +++ b/annotation/compiler/test/src/test/java/com/bumptech/glide/annotation/compiler/LegacyGlideExtensionWithOptionTest.java @@ -0,0 +1,98 @@ +package com.bumptech.glide.annotation.compiler; + +import static com.bumptech.glide.annotation.compiler.test.Util.appResource; +import static com.bumptech.glide.annotation.compiler.test.Util.emptyAppModule; +import static com.bumptech.glide.annotation.compiler.test.Util.glide; +import static com.bumptech.glide.annotation.compiler.test.Util.subpackage; +import static com.google.testing.compile.CompilationSubject.assertThat; +import static com.google.testing.compile.Compiler.javac; + +import com.bumptech.glide.annotation.compiler.test.Util; +import com.google.common.truth.Truth; +import com.google.testing.compile.Compilation; +import java.io.IOException; +import javax.tools.JavaFileObject; +import org.junit.Before; +import org.junit.Test; + +/** + * Verifies the output of the processor with a simple single extension option in the legacy + * option style where extension methods always returned {@code null}. + */ +public class LegacyGlideExtensionWithOptionTest { + private Compilation compilation; + + @Before + public void setUp() { + compilation = + javac() + .withProcessors(new GlideAnnotationProcessor()) + .compile( + emptyAppModule(), + forResource("ExtensionWithOption.java")); + assertThat(compilation).succeeded(); + //noinspection ResultOfMethodCallIgnored + assertThat(compilation).hadWarningContaining( + "The squareThumb method annotated with @GlideOption in the ExtensionWithOption" + + " @GlideExtension is using a legacy format. Support will be removed in a future" + + " version. Please change your method definition so that your @GlideModule annotated" + + " methods return RequestOptions objects instead of null."); + } + + @Test + public void compilation_generatesAllExpectedFiles() { + Truth.assertThat(compilation.generatedSourceFiles()).hasSize(7); + } + + @Test + public void compilation_generatesExpectedGlideOptionsClass() throws IOException { + assertThat(compilation) + .generatedSourceFile(subpackage("GlideOptions")) + .contentsAsUtf8String() + .isEqualTo(forResource("GlideOptions.java").getCharContent(true)); + } + + @Test + public void compilation_generatesExpectedGlideRequestClass() throws IOException { + assertThat(compilation) + .generatedSourceFile(subpackage("GlideRequest")) + .contentsAsUtf8String() + .isEqualTo(forResource("GlideRequest.java").getCharContent(true)); + } + + @Test + public void compilation_generatesExpectedGlideRequestsClass() throws IOException { + assertThat(compilation) + .generatedSourceFile(subpackage("GlideRequests")) + .contentsAsUtf8String() + .isEqualTo(appResource("GlideRequests.java").getCharContent(true)); + } + + @Test + public void compilationGeneratesExpectedGlideAppClass() throws IOException { + assertThat(compilation) + .generatedSourceFile(subpackage("GlideApp")) + .contentsAsUtf8String() + .isEqualTo(appResource("GlideApp.java").getCharContent(true)); + } + + @Test + public void compilation_generatesExpectedGeneratedAppGlideModuleImpl() throws IOException { + assertThat(compilation) + .generatedSourceFile(glide("GeneratedAppGlideModuleImpl")) + .contentsAsUtf8String() + .isEqualTo(appResource("GeneratedAppGlideModuleImpl.java").getCharContent(true)); + } + + @Test + public void compilation_generatesExpectedGeneratedRequestManagerFactory() throws IOException { + assertThat(compilation) + .generatedSourceFile(glide("GeneratedRequestManagerFactory")) + .contentsAsUtf8String() + .isEqualTo(appResource("GeneratedRequestManagerFactory.java").getCharContent(true)); + } + + private JavaFileObject forResource(String name) { + return Util.forResource(getClass().getSimpleName(), name); + } +} diff --git a/annotation/compiler/test/src/test/java/com/bumptech/glide/annotation/compiler/MultipleAppGlideModuleTest.java b/annotation/compiler/test/src/test/java/com/bumptech/glide/annotation/compiler/MultipleAppGlideModuleTest.java index 40327c52b5..17f8d648ca 100644 --- a/annotation/compiler/test/src/test/java/com/bumptech/glide/annotation/compiler/MultipleAppGlideModuleTest.java +++ b/annotation/compiler/test/src/test/java/com/bumptech/glide/annotation/compiler/MultipleAppGlideModuleTest.java @@ -16,7 +16,6 @@ */ public class MultipleAppGlideModuleTest { @Rule public ExpectedException expectedException = ExpectedException.none(); - private static final String DIR_NAME = MultipleAppGlideModuleTest.class.getSimpleName(); private static final String FIRST_MODULE = "EmptyAppModule1.java"; private static final String SECOND_MODULE = "EmptyAppModule2.java"; @@ -46,7 +45,7 @@ public void compilation_withSecondModuleOnly_succeeds() { assertThat(compilation).succeededWithoutWarnings(); } - private static JavaFileObject forResource(String name) { - return Util.forResource(DIR_NAME, name); + private JavaFileObject forResource(String name) { + return Util.forResource(getClass().getSimpleName(), name); } } diff --git a/annotation/compiler/test/src/test/java/com/bumptech/glide/annotation/compiler/MultipleEmptyLibraryGlideModuleTest.java b/annotation/compiler/test/src/test/java/com/bumptech/glide/annotation/compiler/MultipleEmptyLibraryGlideModuleTest.java index 55d2b49c66..7b0bc73668 100644 --- a/annotation/compiler/test/src/test/java/com/bumptech/glide/annotation/compiler/MultipleEmptyLibraryGlideModuleTest.java +++ b/annotation/compiler/test/src/test/java/com/bumptech/glide/annotation/compiler/MultipleEmptyLibraryGlideModuleTest.java @@ -16,7 +16,6 @@ * Tests adding multiple {@link com.bumptech.glide.module.LibraryGlideModule}s in a project. */ public class MultipleEmptyLibraryGlideModuleTest { - private static final String DIR_NAME = "MultipleEmptyLibraryGlideModuleTest"; private Compilation compilation; @Before @@ -46,7 +45,7 @@ public void compilation_generatesExpectedIndexerForModules() throws IOException .isEqualTo(forResource(expectedClassName + ".java").getCharContent(true)); } - private static JavaFileObject forResource(String name) { - return Util.forResource(DIR_NAME, name); + private JavaFileObject forResource(String name) { + return Util.forResource(getClass().getSimpleName(), name); } } 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 f37b640500..e1b1e04f59 100644 --- a/annotation/compiler/test/src/test/resources/GlideExtensionOptionsTest/MemoizeStaticMethod/Extension.java +++ b/annotation/compiler/test/src/test/resources/GlideExtensionOptionsTest/MemoizeStaticMethod/Extension.java @@ -12,7 +12,7 @@ private Extension() { } @GlideOption(memoizeStaticMethod = true) - public static void test(RequestOptions requestOptions) { - requestOptions.centerCrop(); + 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 b0fb6d819a..63d8797c56 100644 --- a/annotation/compiler/test/src/test/resources/GlideExtensionOptionsTest/MemoizeStaticMethod/GlideOptions.java +++ b/annotation/compiler/test/src/test/resources/GlideExtensionOptionsTest/MemoizeStaticMethod/GlideOptions.java @@ -553,11 +553,7 @@ public final GlideOptions autoClone() { */ @CheckResult public GlideOptions test() { - if (isAutoCloneEnabled()) { - return clone().test(); - } - Extension.test(this); - return this; + return (GlideOptions) Extension.test(this); } /** 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 5bc2838f81..862baa126e 100644 --- a/annotation/compiler/test/src/test/resources/GlideExtensionOptionsTest/OverrideExtend/Extension.java +++ b/annotation/compiler/test/src/test/resources/GlideExtensionOptionsTest/OverrideExtend/Extension.java @@ -12,7 +12,7 @@ private Extension() { } @GlideOption(override = GlideOption.OVERRIDE_EXTEND) - public static void centerCrop(RequestOptions requestOptions) { - requestOptions.centerCrop(); + 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 ed6bb78120..6f568a0f11 100644 --- a/annotation/compiler/test/src/test/resources/GlideExtensionOptionsTest/OverrideExtend/GlideOptions.java +++ b/annotation/compiler/test/src/test/resources/GlideExtensionOptionsTest/OverrideExtend/GlideOptions.java @@ -547,12 +547,7 @@ public final GlideOptions autoClone() { @Override @CheckResult public GlideOptions centerCrop() { - if (isAutoCloneEnabled()) { - return clone().centerCrop(); - } - super.centerCrop(); - Extension.centerCrop(this); - return this; + return (GlideOptions) Extension.centerCrop(super.centerCrop()); } /** diff --git a/annotation/compiler/test/src/test/resources/GlideExtensionOptionsTest/OverrideExtendMultipleArguments/Extension.java b/annotation/compiler/test/src/test/resources/GlideExtensionOptionsTest/OverrideExtendMultipleArguments/Extension.java new file mode 100644 index 0000000000..714c287e5d --- /dev/null +++ b/annotation/compiler/test/src/test/resources/GlideExtensionOptionsTest/OverrideExtendMultipleArguments/Extension.java @@ -0,0 +1,20 @@ +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 final class Extension { + + private Extension() { + // Utility class. + } + + @GlideOption(override = GlideOption.OVERRIDE_EXTEND) + public static RequestOptions override(RequestOptions requestOptions, int width, int height) { + return requestOptions + .override(width, height) + .centerCrop(); + } +} diff --git a/annotation/compiler/test/src/test/resources/GlideExtensionOptionsTest/OverrideExtendMultipleArguments/GlideOptions.java b/annotation/compiler/test/src/test/resources/GlideExtensionOptionsTest/OverrideExtendMultipleArguments/GlideOptions.java new file mode 100644 index 0000000000..b29c470b63 --- /dev/null +++ b/annotation/compiler/test/src/test/resources/GlideExtensionOptionsTest/OverrideExtendMultipleArguments/GlideOptions.java @@ -0,0 +1,551 @@ +package com.bumptech.glide.test; + +import android.content.res.Resources; +import android.graphics.Bitmap; +import android.graphics.drawable.Drawable; +import android.support.annotation.CheckResult; +import android.support.annotation.DrawableRes; +import android.support.annotation.FloatRange; +import android.support.annotation.IntRange; +import android.support.annotation.NonNull; +import android.support.annotation.Nullable; +import com.bumptech.glide.Priority; +import com.bumptech.glide.load.DecodeFormat; +import com.bumptech.glide.load.Key; +import com.bumptech.glide.load.Option; +import com.bumptech.glide.load.Transformation; +import com.bumptech.glide.load.engine.DiskCacheStrategy; +import com.bumptech.glide.load.resource.bitmap.DownsampleStrategy; +import com.bumptech.glide.request.RequestOptions; +import java.lang.Class; +import java.lang.Cloneable; +import java.lang.Override; +import java.lang.SafeVarargs; +import java.lang.SuppressWarnings; + +/** + * Automatically generated from {@link com.bumptech.glide.annotation.GlideExtension} annotated classes. + * + * @see RequestOptions + * @see Extension + */ +@SuppressWarnings("deprecation") +public final class GlideOptions extends RequestOptions implements Cloneable { + private static GlideOptions fitCenterTransform0; + + private static GlideOptions centerInsideTransform1; + + private static GlideOptions centerCropTransform2; + + private static GlideOptions circleCropTransform3; + + private static GlideOptions noTransformation4; + + private static GlideOptions noAnimation5; + + /** + * @see RequestOptions#sizeMultiplierOf(float) + */ + @CheckResult + public static GlideOptions sizeMultiplierOf(@FloatRange(from = 0.0, to = 1.0) float arg0) { + return new GlideOptions().sizeMultiplier(arg0); + } + + /** + * @see RequestOptions#diskCacheStrategyOf(DiskCacheStrategy) + */ + @CheckResult + public static GlideOptions diskCacheStrategyOf(@NonNull DiskCacheStrategy arg0) { + return new GlideOptions().diskCacheStrategy(arg0); + } + + /** + * @see RequestOptions#priorityOf(Priority) + */ + @CheckResult + public static GlideOptions priorityOf(@NonNull Priority arg0) { + return new GlideOptions().priority(arg0); + } + + /** + * @see RequestOptions#placeholderOf(Drawable) + */ + @CheckResult + public static GlideOptions placeholderOf(@Nullable Drawable arg0) { + return new GlideOptions().placeholder(arg0); + } + + /** + * @see RequestOptions#placeholderOf(int) + */ + @CheckResult + public static GlideOptions placeholderOf(@DrawableRes int arg0) { + return new GlideOptions().placeholder(arg0); + } + + /** + * @see RequestOptions#errorOf(Drawable) + */ + @CheckResult + public static GlideOptions errorOf(@Nullable Drawable arg0) { + return new GlideOptions().error(arg0); + } + + /** + * @see RequestOptions#errorOf(int) + */ + @CheckResult + public static GlideOptions errorOf(@DrawableRes int arg0) { + return new GlideOptions().error(arg0); + } + + /** + * @see RequestOptions#skipMemoryCacheOf(boolean) + */ + @CheckResult + public static GlideOptions skipMemoryCacheOf(boolean skipMemoryCache) { + return new GlideOptions().skipMemoryCache(skipMemoryCache); + } + + /** + * @see RequestOptions#overrideOf(int) + */ + @CheckResult + public static GlideOptions overrideOf(@IntRange(from = 0) int arg0) { + return new GlideOptions().override(arg0); + } + + /** + * @see RequestOptions#signatureOf(Key) + */ + @CheckResult + public static GlideOptions signatureOf(@NonNull Key arg0) { + return new GlideOptions().signature(arg0); + } + + /** + * @see RequestOptions#fitCenterTransform() + */ + @CheckResult + public static GlideOptions fitCenterTransform() { + if (GlideOptions.fitCenterTransform0 == null) { + GlideOptions.fitCenterTransform0 = + new GlideOptions().fitCenter().autoClone(); + } + return GlideOptions.fitCenterTransform0; + } + + /** + * @see RequestOptions#centerInsideTransform() + */ + @CheckResult + public static GlideOptions centerInsideTransform() { + if (GlideOptions.centerInsideTransform1 == null) { + GlideOptions.centerInsideTransform1 = + new GlideOptions().centerInside().autoClone(); + } + return GlideOptions.centerInsideTransform1; + } + + /** + * @see RequestOptions#centerCropTransform() + */ + @CheckResult + public static GlideOptions centerCropTransform() { + if (GlideOptions.centerCropTransform2 == null) { + GlideOptions.centerCropTransform2 = + new GlideOptions().centerCrop().autoClone(); + } + return GlideOptions.centerCropTransform2; + } + + /** + * @see RequestOptions#circleCropTransform() + */ + @CheckResult + public static GlideOptions circleCropTransform() { + if (GlideOptions.circleCropTransform3 == null) { + GlideOptions.circleCropTransform3 = + new GlideOptions().circleCrop().autoClone(); + } + return GlideOptions.circleCropTransform3; + } + + /** + * @see RequestOptions#bitmapTransform(Transformation) + */ + @CheckResult + public static GlideOptions bitmapTransform(@NonNull Transformation arg0) { + return new GlideOptions().transform(arg0); + } + + /** + * @see RequestOptions#noTransformation() + */ + @CheckResult + public static GlideOptions noTransformation() { + if (GlideOptions.noTransformation4 == null) { + GlideOptions.noTransformation4 = + new GlideOptions().dontTransform().autoClone(); + } + return GlideOptions.noTransformation4; + } + + /** + * @see RequestOptions#option(Option, T) + */ + @CheckResult + public static GlideOptions option(@NonNull Option arg0, @NonNull T arg1) { + return new GlideOptions().set(arg0, arg1); + } + + /** + * @see RequestOptions#decodeTypeOf(Class) + */ + @CheckResult + public static GlideOptions decodeTypeOf(@NonNull Class arg0) { + return new GlideOptions().decode(arg0); + } + + /** + * @see RequestOptions#formatOf(DecodeFormat) + */ + @CheckResult + public static GlideOptions formatOf(@NonNull DecodeFormat arg0) { + return new GlideOptions().format(arg0); + } + + /** + * @see RequestOptions#frameOf(long) + */ + @CheckResult + public static GlideOptions frameOf(@IntRange(from = 0) long arg0) { + return new GlideOptions().frame(arg0); + } + + /** + * @see RequestOptions#downsampleOf(DownsampleStrategy) + */ + @CheckResult + public static GlideOptions downsampleOf(@NonNull DownsampleStrategy arg0) { + return new GlideOptions().downsample(arg0); + } + + /** + * @see RequestOptions#timeoutOf(int) + */ + @CheckResult + public static GlideOptions timeoutOf(@IntRange(from = 0) int arg0) { + return new GlideOptions().timeout(arg0); + } + + /** + * @see RequestOptions#encodeQualityOf(int) + */ + @CheckResult + public static GlideOptions encodeQualityOf(@IntRange(from = 0, to = 100) int arg0) { + return new GlideOptions().encodeQuality(arg0); + } + + /** + * @see RequestOptions#encodeFormatOf(CompressFormat) + */ + @CheckResult + public static GlideOptions encodeFormatOf(@NonNull Bitmap.CompressFormat arg0) { + return new GlideOptions().encodeFormat(arg0); + } + + /** + * @see RequestOptions#noAnimation() + */ + @CheckResult + public static GlideOptions noAnimation() { + if (GlideOptions.noAnimation5 == null) { + GlideOptions.noAnimation5 = + new GlideOptions().dontAnimate().autoClone(); + } + return GlideOptions.noAnimation5; + } + + @Override + @CheckResult + public final GlideOptions sizeMultiplier(@FloatRange(from = 0.0, to = 1.0) float arg0) { + return (GlideOptions) super.sizeMultiplier(arg0); + } + + @Override + @CheckResult + public final GlideOptions useUnlimitedSourceGeneratorsPool(boolean flag) { + return (GlideOptions) super.useUnlimitedSourceGeneratorsPool(flag); + } + + @Override + @CheckResult + public final GlideOptions useAnimationPool(boolean flag) { + return (GlideOptions) super.useAnimationPool(flag); + } + + @Override + @CheckResult + public final GlideOptions onlyRetrieveFromCache(boolean flag) { + return (GlideOptions) super.onlyRetrieveFromCache(flag); + } + + @Override + @CheckResult + public final GlideOptions diskCacheStrategy(@NonNull DiskCacheStrategy arg0) { + return (GlideOptions) super.diskCacheStrategy(arg0); + } + + @Override + @CheckResult + public final GlideOptions priority(@NonNull Priority arg0) { + return (GlideOptions) super.priority(arg0); + } + + @Override + @CheckResult + public final GlideOptions placeholder(@Nullable Drawable arg0) { + return (GlideOptions) super.placeholder(arg0); + } + + @Override + @CheckResult + public final GlideOptions placeholder(@DrawableRes int arg0) { + return (GlideOptions) super.placeholder(arg0); + } + + @Override + @CheckResult + public final GlideOptions fallback(@Nullable Drawable arg0) { + return (GlideOptions) super.fallback(arg0); + } + + @Override + @CheckResult + public final GlideOptions fallback(@DrawableRes int arg0) { + return (GlideOptions) super.fallback(arg0); + } + + @Override + @CheckResult + public final GlideOptions error(@Nullable Drawable arg0) { + return (GlideOptions) super.error(arg0); + } + + @Override + @CheckResult + public final GlideOptions error(@DrawableRes int arg0) { + return (GlideOptions) super.error(arg0); + } + + @Override + @CheckResult + public final GlideOptions theme(@Nullable Resources.Theme arg0) { + return (GlideOptions) super.theme(arg0); + } + + @Override + @CheckResult + public final GlideOptions skipMemoryCache(boolean skip) { + return (GlideOptions) super.skipMemoryCache(skip); + } + + @Override + @CheckResult + public final GlideOptions override(int size) { + return (GlideOptions) super.override(size); + } + + @Override + @CheckResult + public final GlideOptions signature(@NonNull Key arg0) { + return (GlideOptions) super.signature(arg0); + } + + @Override + @CheckResult + public final GlideOptions clone() { + return (GlideOptions) super.clone(); + } + + @Override + @CheckResult + public final GlideOptions set(@NonNull Option arg0, @NonNull T arg1) { + return (GlideOptions) super.set(arg0, arg1); + } + + @Override + @CheckResult + public final GlideOptions decode(@NonNull Class arg0) { + return (GlideOptions) super.decode(arg0); + } + + @Override + @CheckResult + public final GlideOptions encodeFormat(@NonNull Bitmap.CompressFormat arg0) { + return (GlideOptions) super.encodeFormat(arg0); + } + + @Override + @CheckResult + public final GlideOptions encodeQuality(@IntRange(from = 0, to = 100) int arg0) { + return (GlideOptions) super.encodeQuality(arg0); + } + + @Override + @CheckResult + public final GlideOptions frame(@IntRange(from = 0) long arg0) { + return (GlideOptions) super.frame(arg0); + } + + @Override + @CheckResult + public final GlideOptions format(@NonNull DecodeFormat arg0) { + return (GlideOptions) super.format(arg0); + } + + @Override + @CheckResult + public final GlideOptions disallowHardwareConfig() { + return (GlideOptions) super.disallowHardwareConfig(); + } + + @Override + @CheckResult + public final GlideOptions downsample(@NonNull DownsampleStrategy arg0) { + return (GlideOptions) super.downsample(arg0); + } + + @Override + @CheckResult + public final GlideOptions timeout(@IntRange(from = 0) int arg0) { + return (GlideOptions) super.timeout(arg0); + } + + @Override + @CheckResult + public final GlideOptions optionalCenterCrop() { + return (GlideOptions) super.optionalCenterCrop(); + } + + @Override + @CheckResult + public final GlideOptions centerCrop() { + return (GlideOptions) super.centerCrop(); + } + + @Override + @CheckResult + public final GlideOptions optionalFitCenter() { + return (GlideOptions) super.optionalFitCenter(); + } + + @Override + @CheckResult + public final GlideOptions fitCenter() { + return (GlideOptions) super.fitCenter(); + } + + @Override + @CheckResult + public final GlideOptions optionalCenterInside() { + return (GlideOptions) super.optionalCenterInside(); + } + + @Override + @CheckResult + public final GlideOptions centerInside() { + return (GlideOptions) super.centerInside(); + } + + @Override + @CheckResult + public final GlideOptions optionalCircleCrop() { + return (GlideOptions) super.optionalCircleCrop(); + } + + @Override + @CheckResult + public final GlideOptions circleCrop() { + return (GlideOptions) super.circleCrop(); + } + + @Override + @CheckResult + public final GlideOptions transform(@NonNull Transformation arg0) { + return (GlideOptions) super.transform(arg0); + } + + @Override + @SafeVarargs + @CheckResult + public final GlideOptions transforms(@NonNull Transformation... arg0) { + return (GlideOptions) super.transforms(arg0); + } + + @Override + @CheckResult + public final GlideOptions optionalTransform(@NonNull Transformation arg0) { + return (GlideOptions) super.optionalTransform(arg0); + } + + @Override + @CheckResult + public final GlideOptions optionalTransform(@NonNull Class arg0, + @NonNull Transformation arg1) { + return (GlideOptions) super.optionalTransform(arg0, arg1); + } + + @Override + @CheckResult + public final GlideOptions transform(@NonNull Class arg0, @NonNull Transformation arg1) { + return (GlideOptions) super.transform(arg0, arg1); + } + + @Override + @CheckResult + public final GlideOptions dontTransform() { + return (GlideOptions) super.dontTransform(); + } + + @Override + @CheckResult + public final GlideOptions dontAnimate() { + return (GlideOptions) super.dontAnimate(); + } + + @Override + @CheckResult + public final GlideOptions apply(@NonNull RequestOptions arg0) { + return (GlideOptions) super.apply(arg0); + } + + @Override + public final GlideOptions lock() { + return (GlideOptions) super.lock(); + } + + @Override + public final GlideOptions autoClone() { + return (GlideOptions) super.autoClone(); + } + + /** + * @see Extension#override(RequestOptions, int, int) + * @see RequestOptions#override(int, int) + */ + @Override + @CheckResult + public GlideOptions override(int width, int height) { + return (GlideOptions) Extension.override(super.override(width, height), width, height); + } + + /** + * @see Extension#override(RequestOptions, int, int) + */ + @CheckResult + public static GlideOptions overrideOf(int width, int height) { + return new GlideOptions().override(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 new file mode 100644 index 0000000000..d3c2e130b5 --- /dev/null +++ b/annotation/compiler/test/src/test/resources/GlideExtensionOptionsTest/OverrideExtendMultipleArguments/GlideRequest.java @@ -0,0 +1,712 @@ +package com.bumptech.glide.test; + +import android.content.Context; +import android.content.res.Resources; +import android.graphics.Bitmap; +import android.graphics.drawable.Drawable; +import android.net.Uri; +import android.support.annotation.CheckResult; +import android.support.annotation.DrawableRes; +import android.support.annotation.FloatRange; +import android.support.annotation.IntRange; +import android.support.annotation.NonNull; +import android.support.annotation.Nullable; +import android.support.annotation.RawRes; +import com.bumptech.glide.Glide; +import com.bumptech.glide.Priority; +import com.bumptech.glide.RequestBuilder; +import com.bumptech.glide.RequestManager; +import com.bumptech.glide.TransitionOptions; +import com.bumptech.glide.load.DecodeFormat; +import com.bumptech.glide.load.Key; +import com.bumptech.glide.load.Option; +import com.bumptech.glide.load.Transformation; +import com.bumptech.glide.load.engine.DiskCacheStrategy; +import com.bumptech.glide.load.resource.bitmap.DownsampleStrategy; +import com.bumptech.glide.request.RequestListener; +import com.bumptech.glide.request.RequestOptions; +import java.io.File; +import java.lang.Class; +import java.lang.Cloneable; +import java.lang.Deprecated; +import java.lang.Integer; +import java.lang.Object; +import java.lang.Override; +import java.lang.SafeVarargs; +import java.lang.String; +import java.lang.SuppressWarnings; +import java.net.URL; + +/** + * Contains all public methods from {@link RequestBuilder}, all options from + * {@link RequestOptions} and all generated options from + * {@link com.bumptech.glide.annotation.GlideOption} in annotated methods in + * {@link com.bumptech.glide.annotation.GlideExtension} annotated classes. + * + *

Generated code, do not modify. + * + * @see RequestBuilder + * @see RequestOptions + */ +@SuppressWarnings({ + "unused", + "deprecation" +}) +public class GlideRequest extends RequestBuilder implements Cloneable { + GlideRequest(Class transcodeClass, RequestBuilder other) { + super(transcodeClass, other); + } + + GlideRequest(Glide glide, RequestManager requestManager, Class transcodeClass, + Context context) { + super(glide, requestManager ,transcodeClass, context); + } + + @Override + @CheckResult + protected GlideRequest getDownloadOnlyRequest() { + return new GlideRequest<>(File.class, this).apply(DOWNLOAD_ONLY_OPTIONS); + } + + /** + * @see GlideOptions#sizeMultiplier(float) + */ + @CheckResult + public GlideRequest sizeMultiplier(@FloatRange(from = 0.0, to = 1.0) float arg0) { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).sizeMultiplier(arg0); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).sizeMultiplier(arg0); + } + return this; + } + + /** + * @see GlideOptions#useUnlimitedSourceGeneratorsPool(boolean) + */ + @CheckResult + public GlideRequest useUnlimitedSourceGeneratorsPool(boolean flag) { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).useUnlimitedSourceGeneratorsPool(flag); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).useUnlimitedSourceGeneratorsPool(flag); + } + return this; + } + + /** + * @see GlideOptions#useAnimationPool(boolean) + */ + @CheckResult + public GlideRequest useAnimationPool(boolean flag) { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).useAnimationPool(flag); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).useAnimationPool(flag); + } + return this; + } + + /** + * @see GlideOptions#onlyRetrieveFromCache(boolean) + */ + @CheckResult + public GlideRequest onlyRetrieveFromCache(boolean flag) { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).onlyRetrieveFromCache(flag); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).onlyRetrieveFromCache(flag); + } + return this; + } + + /** + * @see GlideOptions#diskCacheStrategy(DiskCacheStrategy) + */ + @CheckResult + public GlideRequest diskCacheStrategy(@NonNull DiskCacheStrategy arg0) { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).diskCacheStrategy(arg0); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).diskCacheStrategy(arg0); + } + return this; + } + + /** + * @see GlideOptions#priority(Priority) + */ + @CheckResult + public GlideRequest priority(@NonNull Priority arg0) { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).priority(arg0); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).priority(arg0); + } + return this; + } + + /** + * @see GlideOptions#placeholder(Drawable) + */ + @CheckResult + public GlideRequest placeholder(@Nullable Drawable arg0) { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).placeholder(arg0); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).placeholder(arg0); + } + return this; + } + + /** + * @see GlideOptions#placeholder(int) + */ + @CheckResult + public GlideRequest placeholder(@DrawableRes int arg0) { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).placeholder(arg0); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).placeholder(arg0); + } + return this; + } + + /** + * @see GlideOptions#fallback(Drawable) + */ + @CheckResult + public GlideRequest fallback(@Nullable Drawable arg0) { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).fallback(arg0); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).fallback(arg0); + } + return this; + } + + /** + * @see GlideOptions#fallback(int) + */ + @CheckResult + public GlideRequest fallback(@DrawableRes int arg0) { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).fallback(arg0); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).fallback(arg0); + } + return this; + } + + /** + * @see GlideOptions#error(Drawable) + */ + @CheckResult + public GlideRequest error(@Nullable Drawable arg0) { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).error(arg0); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).error(arg0); + } + return this; + } + + /** + * @see GlideOptions#error(int) + */ + @CheckResult + public GlideRequest error(@DrawableRes int arg0) { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).error(arg0); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).error(arg0); + } + return this; + } + + /** + * @see GlideOptions#theme(Resources.Theme) + */ + @CheckResult + public GlideRequest theme(@Nullable Resources.Theme arg0) { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).theme(arg0); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).theme(arg0); + } + return this; + } + + /** + * @see GlideOptions#skipMemoryCache(boolean) + */ + @CheckResult + public GlideRequest skipMemoryCache(boolean skip) { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).skipMemoryCache(skip); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).skipMemoryCache(skip); + } + return this; + } + + /** + * @see GlideOptions#override(int) + */ + @CheckResult + public GlideRequest override(int size) { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).override(size); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).override(size); + } + return this; + } + + /** + * @see GlideOptions#signature(Key) + */ + @CheckResult + public GlideRequest signature(@NonNull Key arg0) { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).signature(arg0); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).signature(arg0); + } + return this; + } + + /** + * @see GlideOptions#set(Option, T) + */ + @CheckResult + public GlideRequest set(@NonNull Option arg0, @NonNull T arg1) { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).set(arg0, arg1); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).set(arg0, arg1); + } + return this; + } + + /** + * @see GlideOptions#decode(Class) + */ + @CheckResult + public GlideRequest decode(@NonNull Class arg0) { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).decode(arg0); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).decode(arg0); + } + return this; + } + + /** + * @see GlideOptions#encodeFormat(Bitmap.CompressFormat) + */ + @CheckResult + public GlideRequest encodeFormat(@NonNull Bitmap.CompressFormat arg0) { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).encodeFormat(arg0); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).encodeFormat(arg0); + } + return this; + } + + /** + * @see GlideOptions#encodeQuality(int) + */ + @CheckResult + public GlideRequest encodeQuality(@IntRange(from = 0, to = 100) int arg0) { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).encodeQuality(arg0); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).encodeQuality(arg0); + } + return this; + } + + /** + * @see GlideOptions#frame(long) + */ + @CheckResult + public GlideRequest frame(@IntRange(from = 0) long arg0) { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).frame(arg0); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).frame(arg0); + } + return this; + } + + /** + * @see GlideOptions#format(DecodeFormat) + */ + @CheckResult + public GlideRequest format(@NonNull DecodeFormat arg0) { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).format(arg0); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).format(arg0); + } + return this; + } + + /** + * @see GlideOptions#disallowHardwareConfig() + */ + @CheckResult + public GlideRequest disallowHardwareConfig() { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).disallowHardwareConfig(); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).disallowHardwareConfig(); + } + return this; + } + + /** + * @see GlideOptions#downsample(DownsampleStrategy) + */ + @CheckResult + public GlideRequest downsample(@NonNull DownsampleStrategy arg0) { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).downsample(arg0); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).downsample(arg0); + } + return this; + } + + /** + * @see GlideOptions#timeout(int) + */ + @CheckResult + public GlideRequest timeout(@IntRange(from = 0) int arg0) { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).timeout(arg0); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).timeout(arg0); + } + return this; + } + + /** + * @see GlideOptions#optionalCenterCrop() + */ + @CheckResult + public GlideRequest optionalCenterCrop() { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).optionalCenterCrop(); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).optionalCenterCrop(); + } + return this; + } + + /** + * @see GlideOptions#centerCrop() + */ + @CheckResult + public GlideRequest centerCrop() { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).centerCrop(); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).centerCrop(); + } + return this; + } + + /** + * @see GlideOptions#optionalFitCenter() + */ + @CheckResult + public GlideRequest optionalFitCenter() { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).optionalFitCenter(); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).optionalFitCenter(); + } + return this; + } + + /** + * @see GlideOptions#fitCenter() + */ + @CheckResult + public GlideRequest fitCenter() { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).fitCenter(); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).fitCenter(); + } + return this; + } + + /** + * @see GlideOptions#optionalCenterInside() + */ + @CheckResult + public GlideRequest optionalCenterInside() { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).optionalCenterInside(); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).optionalCenterInside(); + } + return this; + } + + /** + * @see GlideOptions#centerInside() + */ + @CheckResult + public GlideRequest centerInside() { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).centerInside(); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).centerInside(); + } + return this; + } + + /** + * @see GlideOptions#optionalCircleCrop() + */ + @CheckResult + public GlideRequest optionalCircleCrop() { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).optionalCircleCrop(); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).optionalCircleCrop(); + } + return this; + } + + /** + * @see GlideOptions#circleCrop() + */ + @CheckResult + public GlideRequest circleCrop() { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).circleCrop(); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).circleCrop(); + } + return this; + } + + /** + * @see GlideOptions#transform(Transformation) + */ + @CheckResult + public GlideRequest transform(@NonNull Transformation arg0) { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).transform(arg0); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).transform(arg0); + } + return this; + } + + /** + * @see GlideOptions#transforms(Transformation[]) + */ + @CheckResult + @SuppressWarnings({ + "unchecked", + "varargs" + }) + public GlideRequest transforms(@NonNull Transformation... arg0) { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).transforms(arg0); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).transforms(arg0); + } + return this; + } + + /** + * @see GlideOptions#optionalTransform(Transformation) + */ + @CheckResult + public GlideRequest optionalTransform(@NonNull Transformation arg0) { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).optionalTransform(arg0); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).optionalTransform(arg0); + } + return this; + } + + /** + * @see GlideOptions#optionalTransform(Class, Transformation) + */ + @CheckResult + public GlideRequest optionalTransform(@NonNull Class arg0, + @NonNull Transformation arg1) { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).optionalTransform(arg0, arg1); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).optionalTransform(arg0, arg1); + } + return this; + } + + /** + * @see GlideOptions#transform(Class, Transformation) + */ + @CheckResult + public GlideRequest transform(@NonNull Class arg0, + @NonNull Transformation arg1) { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).transform(arg0, arg1); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).transform(arg0, arg1); + } + return this; + } + + /** + * @see GlideOptions#dontTransform() + */ + @CheckResult + public GlideRequest dontTransform() { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).dontTransform(); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).dontTransform(); + } + return this; + } + + /** + * @see GlideOptions#dontAnimate() + */ + @CheckResult + public GlideRequest dontAnimate() { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).dontAnimate(); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).dontAnimate(); + } + return this; + } + + /** + * @see GlideOptions#override(int, int) + */ + @CheckResult + public GlideRequest override(int width, int height) { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).override(width, height); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).override(width, height); + } + return this; + } + + @Override + @CheckResult + public GlideRequest apply(@NonNull RequestOptions arg0) { + return (GlideRequest) super.apply(arg0); + } + + @Override + @CheckResult + public GlideRequest transition(@NonNull TransitionOptions arg0) { + return (GlideRequest) super.transition(arg0); + } + + @Override + @CheckResult + public GlideRequest listener(@Nullable RequestListener arg0) { + return (GlideRequest) super.listener(arg0); + } + + @Override + public GlideRequest error(@Nullable RequestBuilder arg0) { + return (GlideRequest) super.error(arg0); + } + + @Override + @CheckResult + public GlideRequest thumbnail(@Nullable RequestBuilder arg0) { + return (GlideRequest) super.thumbnail(arg0); + } + + @Override + @CheckResult + @SafeVarargs + public final GlideRequest thumbnail(@Nullable RequestBuilder... arg0) { + return (GlideRequest) super.thumbnail(arg0); + } + + @Override + @CheckResult + public GlideRequest thumbnail(float sizeMultiplier) { + return (GlideRequest) super.thumbnail(sizeMultiplier); + } + + @Override + @CheckResult + public GlideRequest load(@Nullable Object arg0) { + return (GlideRequest) super.load(arg0); + } + + @Override + @CheckResult + public GlideRequest load(@Nullable Bitmap arg0) { + return (GlideRequest) super.load(arg0); + } + + @Override + @CheckResult + public GlideRequest load(@Nullable Drawable arg0) { + return (GlideRequest) super.load(arg0); + } + + @Override + @CheckResult + public GlideRequest load(@Nullable String arg0) { + return (GlideRequest) super.load(arg0); + } + + @Override + @CheckResult + public GlideRequest load(@Nullable Uri arg0) { + return (GlideRequest) super.load(arg0); + } + + @Override + @CheckResult + public GlideRequest load(@Nullable File arg0) { + return (GlideRequest) super.load(arg0); + } + + @Override + @CheckResult + public GlideRequest load(@RawRes @DrawableRes @Nullable Integer arg0) { + return (GlideRequest) super.load(arg0); + } + + @Override + @Deprecated + @CheckResult + public GlideRequest load(@Nullable URL arg0) { + return (GlideRequest) super.load(arg0); + } + + @Override + @CheckResult + public GlideRequest load(@Nullable byte[] arg0) { + return (GlideRequest) super.load(arg0); + } + + @Override + @CheckResult + public GlideRequest clone() { + return (GlideRequest) super.clone(); + } +} 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 591f857f21..ec436d7652 100644 --- a/annotation/compiler/test/src/test/resources/GlideExtensionOptionsTest/OverrideReplace/Extension.java +++ b/annotation/compiler/test/src/test/resources/GlideExtensionOptionsTest/OverrideReplace/Extension.java @@ -12,7 +12,7 @@ private Extension() { } @GlideOption(override = GlideOption.OVERRIDE_REPLACE) - public static void centerCrop(RequestOptions requestOptions) { - requestOptions.centerCrop(); + 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 823666b544..b876cbe4b2 100644 --- a/annotation/compiler/test/src/test/resources/GlideExtensionOptionsTest/OverrideReplace/GlideOptions.java +++ b/annotation/compiler/test/src/test/resources/GlideExtensionOptionsTest/OverrideReplace/GlideOptions.java @@ -545,11 +545,7 @@ public final GlideOptions autoClone() { */ @CheckResult public GlideOptions centerCrop() { - if (isAutoCloneEnabled()) { - return clone().centerCrop(); - } - Extension.centerCrop(this); - return this; + return (GlideOptions) Extension.centerCrop(this); } /** 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 448a02b747..904c55a1cc 100644 --- a/annotation/compiler/test/src/test/resources/GlideExtensionOptionsTest/SkipStaticMethod/Extension.java +++ b/annotation/compiler/test/src/test/resources/GlideExtensionOptionsTest/SkipStaticMethod/Extension.java @@ -12,7 +12,7 @@ private Extension() { } @GlideOption(skipStaticMethod = true) - public static void test(RequestOptions requestOptions) { - requestOptions.centerCrop(); + 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 c28a1716ef..78210a92ba 100644 --- a/annotation/compiler/test/src/test/resources/GlideExtensionOptionsTest/SkipStaticMethod/GlideOptions.java +++ b/annotation/compiler/test/src/test/resources/GlideExtensionOptionsTest/SkipStaticMethod/GlideOptions.java @@ -551,10 +551,6 @@ public final GlideOptions autoClone() { */ @CheckResult public GlideOptions test() { - if (isAutoCloneEnabled()) { - return clone().test(); - } - Extension.test(this); - return this; + return (GlideOptions) Extension.test(this); } } 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 b6c72bbad4..aa124c142f 100644 --- a/annotation/compiler/test/src/test/resources/GlideExtensionOptionsTest/StaticMethodName/Extension.java +++ b/annotation/compiler/test/src/test/resources/GlideExtensionOptionsTest/StaticMethodName/Extension.java @@ -12,7 +12,7 @@ private Extension() { } @GlideOption(staticMethodName = "testSomething") - public static void test(RequestOptions requestOptions) { - requestOptions.centerCrop(); + 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 5d3a801444..95f08ecd2a 100644 --- a/annotation/compiler/test/src/test/resources/GlideExtensionOptionsTest/StaticMethodName/GlideOptions.java +++ b/annotation/compiler/test/src/test/resources/GlideExtensionOptionsTest/StaticMethodName/GlideOptions.java @@ -551,11 +551,7 @@ public final GlideOptions autoClone() { */ @CheckResult public GlideOptions test() { - if (isAutoCloneEnabled()) { - return clone().test(); - } - Extension.test(this); - return this; + return (GlideOptions) Extension.test(this); } /** diff --git a/annotation/compiler/test/src/test/resources/GlideExtensionWithOptionTest/ExtensionWithOption.java b/annotation/compiler/test/src/test/resources/GlideExtensionWithOptionTest/ExtensionWithOption.java index b67065d437..8f6de00511 100644 --- a/annotation/compiler/test/src/test/resources/GlideExtensionWithOptionTest/ExtensionWithOption.java +++ b/annotation/compiler/test/src/test/resources/GlideExtensionWithOptionTest/ExtensionWithOption.java @@ -12,7 +12,7 @@ private ExtensionWithOption() { } @GlideOption - public static void squareThumb(RequestOptions requestOptions) { - requestOptions.centerCrop(); + 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 9f96d3b806..6cd0830a82 100644 --- a/annotation/compiler/test/src/test/resources/GlideExtensionWithOptionTest/GlideOptions.java +++ b/annotation/compiler/test/src/test/resources/GlideExtensionWithOptionTest/GlideOptions.java @@ -551,11 +551,7 @@ public final GlideOptions autoClone() { */ @CheckResult public GlideOptions squareThumb() { - if (isAutoCloneEnabled()) { - return clone().squareThumb(); - } - ExtensionWithOption.squareThumb(this); - return this; + return (GlideOptions) ExtensionWithOption.squareThumb(this); } /** diff --git a/annotation/compiler/test/src/test/resources/LegacyGlideExtensionOptionsTest/MemoizeStaticMethod/Extension.java b/annotation/compiler/test/src/test/resources/LegacyGlideExtensionOptionsTest/MemoizeStaticMethod/Extension.java new file mode 100644 index 0000000000..f37b640500 --- /dev/null +++ b/annotation/compiler/test/src/test/resources/LegacyGlideExtensionOptionsTest/MemoizeStaticMethod/Extension.java @@ -0,0 +1,18 @@ +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 final class Extension { + + private Extension() { + // Utility class. + } + + @GlideOption(memoizeStaticMethod = true) + public static void test(RequestOptions requestOptions) { + requestOptions.centerCrop(); + } +} diff --git a/annotation/compiler/test/src/test/resources/LegacyGlideExtensionOptionsTest/MemoizeStaticMethod/GlideOptions.java b/annotation/compiler/test/src/test/resources/LegacyGlideExtensionOptionsTest/MemoizeStaticMethod/GlideOptions.java new file mode 100644 index 0000000000..b0fb6d819a --- /dev/null +++ b/annotation/compiler/test/src/test/resources/LegacyGlideExtensionOptionsTest/MemoizeStaticMethod/GlideOptions.java @@ -0,0 +1,574 @@ +package com.bumptech.glide.test; + +import android.content.res.Resources; +import android.graphics.Bitmap; +import android.graphics.drawable.Drawable; +import android.support.annotation.CheckResult; +import android.support.annotation.DrawableRes; +import android.support.annotation.FloatRange; +import android.support.annotation.IntRange; +import android.support.annotation.NonNull; +import android.support.annotation.Nullable; +import com.bumptech.glide.Priority; +import com.bumptech.glide.load.DecodeFormat; +import com.bumptech.glide.load.Key; +import com.bumptech.glide.load.Option; +import com.bumptech.glide.load.Transformation; +import com.bumptech.glide.load.engine.DiskCacheStrategy; +import com.bumptech.glide.load.resource.bitmap.DownsampleStrategy; +import com.bumptech.glide.request.RequestOptions; +import java.lang.Class; +import java.lang.Cloneable; +import java.lang.Override; +import java.lang.SafeVarargs; +import java.lang.SuppressWarnings; + +/** + * Automatically generated from {@link com.bumptech.glide.annotation.GlideExtension} annotated classes. + * + * @see RequestOptions + * @see Extension + */ +@SuppressWarnings("deprecation") +public final class GlideOptions extends RequestOptions implements Cloneable { + private static GlideOptions fitCenterTransform1; + + private static GlideOptions centerInsideTransform2; + + private static GlideOptions centerCropTransform3; + + private static GlideOptions circleCropTransform4; + + private static GlideOptions noTransformation5; + + private static GlideOptions noAnimation6; + + private static GlideOptions testOf0; + + /** + * @see RequestOptions#sizeMultiplierOf(float) + */ + @CheckResult + public static GlideOptions sizeMultiplierOf(@FloatRange(from = 0.0, to = 1.0) float arg0) { + return new GlideOptions().sizeMultiplier(arg0); + } + + /** + * @see RequestOptions#diskCacheStrategyOf(DiskCacheStrategy) + */ + @CheckResult + public static GlideOptions diskCacheStrategyOf(@NonNull DiskCacheStrategy arg0) { + return new GlideOptions().diskCacheStrategy(arg0); + } + + /** + * @see RequestOptions#priorityOf(Priority) + */ + @CheckResult + public static GlideOptions priorityOf(@NonNull Priority arg0) { + return new GlideOptions().priority(arg0); + } + + /** + * @see RequestOptions#placeholderOf(Drawable) + */ + @CheckResult + public static GlideOptions placeholderOf(@Nullable Drawable arg0) { + return new GlideOptions().placeholder(arg0); + } + + /** + * @see RequestOptions#placeholderOf(int) + */ + @CheckResult + public static GlideOptions placeholderOf(@DrawableRes int arg0) { + return new GlideOptions().placeholder(arg0); + } + + /** + * @see RequestOptions#errorOf(Drawable) + */ + @CheckResult + public static GlideOptions errorOf(@Nullable Drawable arg0) { + return new GlideOptions().error(arg0); + } + + /** + * @see RequestOptions#errorOf(int) + */ + @CheckResult + public static GlideOptions errorOf(@DrawableRes int arg0) { + return new GlideOptions().error(arg0); + } + + /** + * @see RequestOptions#skipMemoryCacheOf(boolean) + */ + @CheckResult + public static GlideOptions skipMemoryCacheOf(boolean skipMemoryCache) { + return new GlideOptions().skipMemoryCache(skipMemoryCache); + } + + /** + * @see RequestOptions#overrideOf(int, int) + */ + @CheckResult + public static GlideOptions overrideOf(@IntRange(from = 0) int arg0, + @IntRange(from = 0) int arg1) { + return new GlideOptions().override(arg0, arg1); + } + + /** + * @see RequestOptions#overrideOf(int) + */ + @CheckResult + public static GlideOptions overrideOf(@IntRange(from = 0) int arg0) { + return new GlideOptions().override(arg0); + } + + /** + * @see RequestOptions#signatureOf(Key) + */ + @CheckResult + public static GlideOptions signatureOf(@NonNull Key arg0) { + return new GlideOptions().signature(arg0); + } + + /** + * @see RequestOptions#fitCenterTransform() + */ + @CheckResult + public static GlideOptions fitCenterTransform() { + if (GlideOptions.fitCenterTransform1 == null) { + GlideOptions.fitCenterTransform1 = + new GlideOptions().fitCenter().autoClone(); + } + return GlideOptions.fitCenterTransform1; + } + + /** + * @see RequestOptions#centerInsideTransform() + */ + @CheckResult + public static GlideOptions centerInsideTransform() { + if (GlideOptions.centerInsideTransform2 == null) { + GlideOptions.centerInsideTransform2 = + new GlideOptions().centerInside().autoClone(); + } + return GlideOptions.centerInsideTransform2; + } + + /** + * @see RequestOptions#centerCropTransform() + */ + @CheckResult + public static GlideOptions centerCropTransform() { + if (GlideOptions.centerCropTransform3 == null) { + GlideOptions.centerCropTransform3 = + new GlideOptions().centerCrop().autoClone(); + } + return GlideOptions.centerCropTransform3; + } + + /** + * @see RequestOptions#circleCropTransform() + */ + @CheckResult + public static GlideOptions circleCropTransform() { + if (GlideOptions.circleCropTransform4 == null) { + GlideOptions.circleCropTransform4 = + new GlideOptions().circleCrop().autoClone(); + } + return GlideOptions.circleCropTransform4; + } + + /** + * @see RequestOptions#bitmapTransform(Transformation) + */ + @CheckResult + public static GlideOptions bitmapTransform(@NonNull Transformation arg0) { + return new GlideOptions().transform(arg0); + } + + /** + * @see RequestOptions#noTransformation() + */ + @CheckResult + public static GlideOptions noTransformation() { + if (GlideOptions.noTransformation5 == null) { + GlideOptions.noTransformation5 = + new GlideOptions().dontTransform().autoClone(); + } + return GlideOptions.noTransformation5; + } + + /** + * @see RequestOptions#option(Option, T) + */ + @CheckResult + public static GlideOptions option(@NonNull Option arg0, @NonNull T arg1) { + return new GlideOptions().set(arg0, arg1); + } + + /** + * @see RequestOptions#decodeTypeOf(Class) + */ + @CheckResult + public static GlideOptions decodeTypeOf(@NonNull Class arg0) { + return new GlideOptions().decode(arg0); + } + + /** + * @see RequestOptions#formatOf(DecodeFormat) + */ + @CheckResult + public static GlideOptions formatOf(@NonNull DecodeFormat arg0) { + return new GlideOptions().format(arg0); + } + + /** + * @see RequestOptions#frameOf(long) + */ + @CheckResult + public static GlideOptions frameOf(@IntRange(from = 0) long arg0) { + return new GlideOptions().frame(arg0); + } + + /** + * @see RequestOptions#downsampleOf(DownsampleStrategy) + */ + @CheckResult + public static GlideOptions downsampleOf(@NonNull DownsampleStrategy arg0) { + return new GlideOptions().downsample(arg0); + } + + /** + * @see RequestOptions#timeoutOf(int) + */ + @CheckResult + public static GlideOptions timeoutOf(@IntRange(from = 0) int arg0) { + return new GlideOptions().timeout(arg0); + } + + /** + * @see RequestOptions#encodeQualityOf(int) + */ + @CheckResult + public static GlideOptions encodeQualityOf(@IntRange(from = 0, to = 100) int arg0) { + return new GlideOptions().encodeQuality(arg0); + } + + /** + * @see RequestOptions#encodeFormatOf(CompressFormat) + */ + @CheckResult + public static GlideOptions encodeFormatOf(@NonNull Bitmap.CompressFormat arg0) { + return new GlideOptions().encodeFormat(arg0); + } + + /** + * @see RequestOptions#noAnimation() + */ + @CheckResult + public static GlideOptions noAnimation() { + if (GlideOptions.noAnimation6 == null) { + GlideOptions.noAnimation6 = + new GlideOptions().dontAnimate().autoClone(); + } + return GlideOptions.noAnimation6; + } + + @Override + @CheckResult + public final GlideOptions sizeMultiplier(@FloatRange(from = 0.0, to = 1.0) float arg0) { + return (GlideOptions) super.sizeMultiplier(arg0); + } + + @Override + @CheckResult + public final GlideOptions useUnlimitedSourceGeneratorsPool(boolean flag) { + return (GlideOptions) super.useUnlimitedSourceGeneratorsPool(flag); + } + + @Override + @CheckResult + public final GlideOptions useAnimationPool(boolean flag) { + return (GlideOptions) super.useAnimationPool(flag); + } + + @Override + @CheckResult + public final GlideOptions onlyRetrieveFromCache(boolean flag) { + return (GlideOptions) super.onlyRetrieveFromCache(flag); + } + + @Override + @CheckResult + public final GlideOptions diskCacheStrategy(@NonNull DiskCacheStrategy arg0) { + return (GlideOptions) super.diskCacheStrategy(arg0); + } + + @Override + @CheckResult + public final GlideOptions priority(@NonNull Priority arg0) { + return (GlideOptions) super.priority(arg0); + } + + @Override + @CheckResult + public final GlideOptions placeholder(@Nullable Drawable arg0) { + return (GlideOptions) super.placeholder(arg0); + } + + @Override + @CheckResult + public final GlideOptions placeholder(@DrawableRes int arg0) { + return (GlideOptions) super.placeholder(arg0); + } + + @Override + @CheckResult + public final GlideOptions fallback(@Nullable Drawable arg0) { + return (GlideOptions) super.fallback(arg0); + } + + @Override + @CheckResult + public final GlideOptions fallback(@DrawableRes int arg0) { + return (GlideOptions) super.fallback(arg0); + } + + @Override + @CheckResult + public final GlideOptions error(@Nullable Drawable arg0) { + return (GlideOptions) super.error(arg0); + } + + @Override + @CheckResult + public final GlideOptions error(@DrawableRes int arg0) { + return (GlideOptions) super.error(arg0); + } + + @Override + @CheckResult + public final GlideOptions theme(@Nullable Resources.Theme arg0) { + return (GlideOptions) super.theme(arg0); + } + + @Override + @CheckResult + public final GlideOptions skipMemoryCache(boolean skip) { + return (GlideOptions) super.skipMemoryCache(skip); + } + + @Override + @CheckResult + public final GlideOptions override(int width, int height) { + return (GlideOptions) super.override(width, height); + } + + @Override + @CheckResult + public final GlideOptions override(int size) { + return (GlideOptions) super.override(size); + } + + @Override + @CheckResult + public final GlideOptions signature(@NonNull Key arg0) { + return (GlideOptions) super.signature(arg0); + } + + @Override + @CheckResult + public final GlideOptions clone() { + return (GlideOptions) super.clone(); + } + + @Override + @CheckResult + public final GlideOptions set(@NonNull Option arg0, @NonNull T arg1) { + return (GlideOptions) super.set(arg0, arg1); + } + + @Override + @CheckResult + public final GlideOptions decode(@NonNull Class arg0) { + return (GlideOptions) super.decode(arg0); + } + + @Override + @CheckResult + public final GlideOptions encodeFormat(@NonNull Bitmap.CompressFormat arg0) { + return (GlideOptions) super.encodeFormat(arg0); + } + + @Override + @CheckResult + public final GlideOptions encodeQuality(@IntRange(from = 0, to = 100) int arg0) { + return (GlideOptions) super.encodeQuality(arg0); + } + + @Override + @CheckResult + public final GlideOptions frame(@IntRange(from = 0) long arg0) { + return (GlideOptions) super.frame(arg0); + } + + @Override + @CheckResult + public final GlideOptions format(@NonNull DecodeFormat arg0) { + return (GlideOptions) super.format(arg0); + } + + @Override + @CheckResult + public final GlideOptions disallowHardwareConfig() { + return (GlideOptions) super.disallowHardwareConfig(); + } + + @Override + @CheckResult + public final GlideOptions downsample(@NonNull DownsampleStrategy arg0) { + return (GlideOptions) super.downsample(arg0); + } + + @Override + @CheckResult + public final GlideOptions timeout(@IntRange(from = 0) int arg0) { + return (GlideOptions) super.timeout(arg0); + } + + @Override + @CheckResult + public final GlideOptions optionalCenterCrop() { + return (GlideOptions) super.optionalCenterCrop(); + } + + @Override + @CheckResult + public final GlideOptions centerCrop() { + return (GlideOptions) super.centerCrop(); + } + + @Override + @CheckResult + public final GlideOptions optionalFitCenter() { + return (GlideOptions) super.optionalFitCenter(); + } + + @Override + @CheckResult + public final GlideOptions fitCenter() { + return (GlideOptions) super.fitCenter(); + } + + @Override + @CheckResult + public final GlideOptions optionalCenterInside() { + return (GlideOptions) super.optionalCenterInside(); + } + + @Override + @CheckResult + public final GlideOptions centerInside() { + return (GlideOptions) super.centerInside(); + } + + @Override + @CheckResult + public final GlideOptions optionalCircleCrop() { + return (GlideOptions) super.optionalCircleCrop(); + } + + @Override + @CheckResult + public final GlideOptions circleCrop() { + return (GlideOptions) super.circleCrop(); + } + + @Override + @CheckResult + public final GlideOptions transform(@NonNull Transformation arg0) { + return (GlideOptions) super.transform(arg0); + } + + @Override + @SafeVarargs + @CheckResult + public final GlideOptions transforms(@NonNull Transformation... arg0) { + return (GlideOptions) super.transforms(arg0); + } + + @Override + @CheckResult + public final GlideOptions optionalTransform(@NonNull Transformation arg0) { + return (GlideOptions) super.optionalTransform(arg0); + } + + @Override + @CheckResult + public final GlideOptions optionalTransform(@NonNull Class arg0, + @NonNull Transformation arg1) { + return (GlideOptions) super.optionalTransform(arg0, arg1); + } + + @Override + @CheckResult + public final GlideOptions transform(@NonNull Class arg0, @NonNull Transformation arg1) { + return (GlideOptions) super.transform(arg0, arg1); + } + + @Override + @CheckResult + public final GlideOptions dontTransform() { + return (GlideOptions) super.dontTransform(); + } + + @Override + @CheckResult + public final GlideOptions dontAnimate() { + return (GlideOptions) super.dontAnimate(); + } + + @Override + @CheckResult + public final GlideOptions apply(@NonNull RequestOptions arg0) { + return (GlideOptions) super.apply(arg0); + } + + @Override + public final GlideOptions lock() { + return (GlideOptions) super.lock(); + } + + @Override + public final GlideOptions autoClone() { + return (GlideOptions) super.autoClone(); + } + + /** + * @see Extension#test(RequestOptions) + */ + @CheckResult + public GlideOptions test() { + if (isAutoCloneEnabled()) { + return clone().test(); + } + Extension.test(this); + return this; + } + + /** + * @see Extension#test(RequestOptions) + */ + @CheckResult + public static GlideOptions testOf() { + if (GlideOptions.testOf0 == null) { + GlideOptions.testOf0 = + new GlideOptions().test().autoClone(); + } + return GlideOptions.testOf0; + } +} diff --git a/annotation/compiler/test/src/test/resources/LegacyGlideExtensionOptionsTest/MemoizeStaticMethod/GlideRequest.java b/annotation/compiler/test/src/test/resources/LegacyGlideExtensionOptionsTest/MemoizeStaticMethod/GlideRequest.java new file mode 100644 index 0000000000..323154817f --- /dev/null +++ b/annotation/compiler/test/src/test/resources/LegacyGlideExtensionOptionsTest/MemoizeStaticMethod/GlideRequest.java @@ -0,0 +1,725 @@ +package com.bumptech.glide.test; + +import android.content.Context; +import android.content.res.Resources; +import android.graphics.Bitmap; +import android.graphics.drawable.Drawable; +import android.net.Uri; +import android.support.annotation.CheckResult; +import android.support.annotation.DrawableRes; +import android.support.annotation.FloatRange; +import android.support.annotation.IntRange; +import android.support.annotation.NonNull; +import android.support.annotation.Nullable; +import android.support.annotation.RawRes; +import com.bumptech.glide.Glide; +import com.bumptech.glide.Priority; +import com.bumptech.glide.RequestBuilder; +import com.bumptech.glide.RequestManager; +import com.bumptech.glide.TransitionOptions; +import com.bumptech.glide.load.DecodeFormat; +import com.bumptech.glide.load.Key; +import com.bumptech.glide.load.Option; +import com.bumptech.glide.load.Transformation; +import com.bumptech.glide.load.engine.DiskCacheStrategy; +import com.bumptech.glide.load.resource.bitmap.DownsampleStrategy; +import com.bumptech.glide.request.RequestListener; +import com.bumptech.glide.request.RequestOptions; +import java.io.File; +import java.lang.Class; +import java.lang.Cloneable; +import java.lang.Deprecated; +import java.lang.Integer; +import java.lang.Object; +import java.lang.Override; +import java.lang.SafeVarargs; +import java.lang.String; +import java.lang.SuppressWarnings; +import java.net.URL; + +/** + * Contains all public methods from {@link RequestBuilder}, all options from + * {@link RequestOptions} and all generated options from + * {@link com.bumptech.glide.annotation.GlideOption} in annotated methods in + * {@link com.bumptech.glide.annotation.GlideExtension} annotated classes. + * + *

Generated code, do not modify. + * + * @see RequestBuilder + * @see RequestOptions + */ +@SuppressWarnings({ + "unused", + "deprecation" +}) +public class GlideRequest extends RequestBuilder implements Cloneable { + GlideRequest(Class transcodeClass, RequestBuilder other) { + super(transcodeClass, other); + } + + GlideRequest(Glide glide, RequestManager requestManager, Class transcodeClass, + Context context) { + super(glide, requestManager ,transcodeClass, context); + } + + @Override + @CheckResult + protected GlideRequest getDownloadOnlyRequest() { + return new GlideRequest<>(File.class, this).apply(DOWNLOAD_ONLY_OPTIONS); + } + + /** + * @see GlideOptions#sizeMultiplier(float) + */ + @CheckResult + public GlideRequest sizeMultiplier(@FloatRange(from = 0.0, to = 1.0) float arg0) { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).sizeMultiplier(arg0); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).sizeMultiplier(arg0); + } + return this; + } + + /** + * @see GlideOptions#useUnlimitedSourceGeneratorsPool(boolean) + */ + @CheckResult + public GlideRequest useUnlimitedSourceGeneratorsPool(boolean flag) { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).useUnlimitedSourceGeneratorsPool(flag); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).useUnlimitedSourceGeneratorsPool(flag); + } + return this; + } + + /** + * @see GlideOptions#useAnimationPool(boolean) + */ + @CheckResult + public GlideRequest useAnimationPool(boolean flag) { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).useAnimationPool(flag); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).useAnimationPool(flag); + } + return this; + } + + /** + * @see GlideOptions#onlyRetrieveFromCache(boolean) + */ + @CheckResult + public GlideRequest onlyRetrieveFromCache(boolean flag) { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).onlyRetrieveFromCache(flag); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).onlyRetrieveFromCache(flag); + } + return this; + } + + /** + * @see GlideOptions#diskCacheStrategy(DiskCacheStrategy) + */ + @CheckResult + public GlideRequest diskCacheStrategy(@NonNull DiskCacheStrategy arg0) { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).diskCacheStrategy(arg0); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).diskCacheStrategy(arg0); + } + return this; + } + + /** + * @see GlideOptions#priority(Priority) + */ + @CheckResult + public GlideRequest priority(@NonNull Priority arg0) { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).priority(arg0); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).priority(arg0); + } + return this; + } + + /** + * @see GlideOptions#placeholder(Drawable) + */ + @CheckResult + public GlideRequest placeholder(@Nullable Drawable arg0) { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).placeholder(arg0); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).placeholder(arg0); + } + return this; + } + + /** + * @see GlideOptions#placeholder(int) + */ + @CheckResult + public GlideRequest placeholder(@DrawableRes int arg0) { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).placeholder(arg0); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).placeholder(arg0); + } + return this; + } + + /** + * @see GlideOptions#fallback(Drawable) + */ + @CheckResult + public GlideRequest fallback(@Nullable Drawable arg0) { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).fallback(arg0); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).fallback(arg0); + } + return this; + } + + /** + * @see GlideOptions#fallback(int) + */ + @CheckResult + public GlideRequest fallback(@DrawableRes int arg0) { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).fallback(arg0); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).fallback(arg0); + } + return this; + } + + /** + * @see GlideOptions#error(Drawable) + */ + @CheckResult + public GlideRequest error(@Nullable Drawable arg0) { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).error(arg0); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).error(arg0); + } + return this; + } + + /** + * @see GlideOptions#error(int) + */ + @CheckResult + public GlideRequest error(@DrawableRes int arg0) { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).error(arg0); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).error(arg0); + } + return this; + } + + /** + * @see GlideOptions#theme(Resources.Theme) + */ + @CheckResult + public GlideRequest theme(@Nullable Resources.Theme arg0) { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).theme(arg0); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).theme(arg0); + } + return this; + } + + /** + * @see GlideOptions#skipMemoryCache(boolean) + */ + @CheckResult + public GlideRequest skipMemoryCache(boolean skip) { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).skipMemoryCache(skip); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).skipMemoryCache(skip); + } + return this; + } + + /** + * @see GlideOptions#override(int, int) + */ + @CheckResult + public GlideRequest override(int width, int height) { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).override(width, height); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).override(width, height); + } + return this; + } + + /** + * @see GlideOptions#override(int) + */ + @CheckResult + public GlideRequest override(int size) { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).override(size); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).override(size); + } + return this; + } + + /** + * @see GlideOptions#signature(Key) + */ + @CheckResult + public GlideRequest signature(@NonNull Key arg0) { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).signature(arg0); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).signature(arg0); + } + return this; + } + + /** + * @see GlideOptions#set(Option, T) + */ + @CheckResult + public GlideRequest set(@NonNull Option arg0, @NonNull T arg1) { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).set(arg0, arg1); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).set(arg0, arg1); + } + return this; + } + + /** + * @see GlideOptions#decode(Class) + */ + @CheckResult + public GlideRequest decode(@NonNull Class arg0) { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).decode(arg0); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).decode(arg0); + } + return this; + } + + /** + * @see GlideOptions#encodeFormat(Bitmap.CompressFormat) + */ + @CheckResult + public GlideRequest encodeFormat(@NonNull Bitmap.CompressFormat arg0) { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).encodeFormat(arg0); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).encodeFormat(arg0); + } + return this; + } + + /** + * @see GlideOptions#encodeQuality(int) + */ + @CheckResult + public GlideRequest encodeQuality(@IntRange(from = 0, to = 100) int arg0) { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).encodeQuality(arg0); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).encodeQuality(arg0); + } + return this; + } + + /** + * @see GlideOptions#frame(long) + */ + @CheckResult + public GlideRequest frame(@IntRange(from = 0) long arg0) { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).frame(arg0); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).frame(arg0); + } + return this; + } + + /** + * @see GlideOptions#format(DecodeFormat) + */ + @CheckResult + public GlideRequest format(@NonNull DecodeFormat arg0) { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).format(arg0); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).format(arg0); + } + return this; + } + + /** + * @see GlideOptions#disallowHardwareConfig() + */ + @CheckResult + public GlideRequest disallowHardwareConfig() { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).disallowHardwareConfig(); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).disallowHardwareConfig(); + } + return this; + } + + /** + * @see GlideOptions#downsample(DownsampleStrategy) + */ + @CheckResult + public GlideRequest downsample(@NonNull DownsampleStrategy arg0) { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).downsample(arg0); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).downsample(arg0); + } + return this; + } + + /** + * @see GlideOptions#timeout(int) + */ + @CheckResult + public GlideRequest timeout(@IntRange(from = 0) int arg0) { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).timeout(arg0); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).timeout(arg0); + } + return this; + } + + /** + * @see GlideOptions#optionalCenterCrop() + */ + @CheckResult + public GlideRequest optionalCenterCrop() { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).optionalCenterCrop(); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).optionalCenterCrop(); + } + return this; + } + + /** + * @see GlideOptions#centerCrop() + */ + @CheckResult + public GlideRequest centerCrop() { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).centerCrop(); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).centerCrop(); + } + return this; + } + + /** + * @see GlideOptions#optionalFitCenter() + */ + @CheckResult + public GlideRequest optionalFitCenter() { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).optionalFitCenter(); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).optionalFitCenter(); + } + return this; + } + + /** + * @see GlideOptions#fitCenter() + */ + @CheckResult + public GlideRequest fitCenter() { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).fitCenter(); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).fitCenter(); + } + return this; + } + + /** + * @see GlideOptions#optionalCenterInside() + */ + @CheckResult + public GlideRequest optionalCenterInside() { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).optionalCenterInside(); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).optionalCenterInside(); + } + return this; + } + + /** + * @see GlideOptions#centerInside() + */ + @CheckResult + public GlideRequest centerInside() { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).centerInside(); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).centerInside(); + } + return this; + } + + /** + * @see GlideOptions#optionalCircleCrop() + */ + @CheckResult + public GlideRequest optionalCircleCrop() { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).optionalCircleCrop(); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).optionalCircleCrop(); + } + return this; + } + + /** + * @see GlideOptions#circleCrop() + */ + @CheckResult + public GlideRequest circleCrop() { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).circleCrop(); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).circleCrop(); + } + return this; + } + + /** + * @see GlideOptions#transform(Transformation) + */ + @CheckResult + public GlideRequest transform(@NonNull Transformation arg0) { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).transform(arg0); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).transform(arg0); + } + return this; + } + + /** + * @see GlideOptions#transforms(Transformation[]) + */ + @CheckResult + @SuppressWarnings({ + "unchecked", + "varargs" + }) + public GlideRequest transforms(@NonNull Transformation... arg0) { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).transforms(arg0); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).transforms(arg0); + } + return this; + } + + /** + * @see GlideOptions#optionalTransform(Transformation) + */ + @CheckResult + public GlideRequest optionalTransform(@NonNull Transformation arg0) { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).optionalTransform(arg0); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).optionalTransform(arg0); + } + return this; + } + + /** + * @see GlideOptions#optionalTransform(Class, Transformation) + */ + @CheckResult + public GlideRequest optionalTransform(@NonNull Class arg0, + @NonNull Transformation arg1) { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).optionalTransform(arg0, arg1); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).optionalTransform(arg0, arg1); + } + return this; + } + + /** + * @see GlideOptions#transform(Class, Transformation) + */ + @CheckResult + public GlideRequest transform(@NonNull Class arg0, + @NonNull Transformation arg1) { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).transform(arg0, arg1); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).transform(arg0, arg1); + } + return this; + } + + /** + * @see GlideOptions#dontTransform() + */ + @CheckResult + public GlideRequest dontTransform() { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).dontTransform(); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).dontTransform(); + } + return this; + } + + /** + * @see GlideOptions#dontAnimate() + */ + @CheckResult + public GlideRequest dontAnimate() { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).dontAnimate(); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).dontAnimate(); + } + return this; + } + + /** + * @see GlideOptions#test() + */ + @CheckResult + public GlideRequest test() { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).test(); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).test(); + } + return this; + } + + @Override + @CheckResult + public GlideRequest apply(@NonNull RequestOptions arg0) { + return (GlideRequest) super.apply(arg0); + } + + @Override + @CheckResult + public GlideRequest transition(@NonNull TransitionOptions arg0) { + return (GlideRequest) super.transition(arg0); + } + + @Override + @CheckResult + public GlideRequest listener(@Nullable RequestListener arg0) { + return (GlideRequest) super.listener(arg0); + } + + @Override + public GlideRequest error(@Nullable RequestBuilder arg0) { + return (GlideRequest) super.error(arg0); + } + + @Override + @CheckResult + public GlideRequest thumbnail(@Nullable RequestBuilder arg0) { + return (GlideRequest) super.thumbnail(arg0); + } + + @Override + @CheckResult + @SafeVarargs + public final GlideRequest thumbnail(@Nullable RequestBuilder... arg0) { + return (GlideRequest) super.thumbnail(arg0); + } + + @Override + @CheckResult + public GlideRequest thumbnail(float sizeMultiplier) { + return (GlideRequest) super.thumbnail(sizeMultiplier); + } + + @Override + @CheckResult + public GlideRequest load(@Nullable Object arg0) { + return (GlideRequest) super.load(arg0); + } + + @Override + @CheckResult + public GlideRequest load(@Nullable Bitmap arg0) { + return (GlideRequest) super.load(arg0); + } + + @Override + @CheckResult + public GlideRequest load(@Nullable Drawable arg0) { + return (GlideRequest) super.load(arg0); + } + + @Override + @CheckResult + public GlideRequest load(@Nullable String arg0) { + return (GlideRequest) super.load(arg0); + } + + @Override + @CheckResult + public GlideRequest load(@Nullable Uri arg0) { + return (GlideRequest) super.load(arg0); + } + + @Override + @CheckResult + public GlideRequest load(@Nullable File arg0) { + return (GlideRequest) super.load(arg0); + } + + @Override + @CheckResult + public GlideRequest load(@RawRes @DrawableRes @Nullable Integer arg0) { + return (GlideRequest) super.load(arg0); + } + + @Override + @Deprecated + @CheckResult + public GlideRequest load(@Nullable URL arg0) { + return (GlideRequest) super.load(arg0); + } + + @Override + @CheckResult + public GlideRequest load(@Nullable byte[] arg0) { + return (GlideRequest) super.load(arg0); + } + + @Override + @CheckResult + public GlideRequest clone() { + return (GlideRequest) super.clone(); + } +} diff --git a/annotation/compiler/test/src/test/resources/LegacyGlideExtensionOptionsTest/OverrideExtend/Extension.java b/annotation/compiler/test/src/test/resources/LegacyGlideExtensionOptionsTest/OverrideExtend/Extension.java new file mode 100644 index 0000000000..5bc2838f81 --- /dev/null +++ b/annotation/compiler/test/src/test/resources/LegacyGlideExtensionOptionsTest/OverrideExtend/Extension.java @@ -0,0 +1,18 @@ +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 final class Extension { + + private Extension() { + // Utility class. + } + + @GlideOption(override = GlideOption.OVERRIDE_EXTEND) + public static void centerCrop(RequestOptions requestOptions) { + requestOptions.centerCrop(); + } +} diff --git a/annotation/compiler/test/src/test/resources/LegacyGlideExtensionOptionsTest/OverrideExtend/GlideOptions.java b/annotation/compiler/test/src/test/resources/LegacyGlideExtensionOptionsTest/OverrideExtend/GlideOptions.java new file mode 100644 index 0000000000..ed6bb78120 --- /dev/null +++ b/annotation/compiler/test/src/test/resources/LegacyGlideExtensionOptionsTest/OverrideExtend/GlideOptions.java @@ -0,0 +1,565 @@ +package com.bumptech.glide.test; + +import android.content.res.Resources; +import android.graphics.Bitmap; +import android.graphics.drawable.Drawable; +import android.support.annotation.CheckResult; +import android.support.annotation.DrawableRes; +import android.support.annotation.FloatRange; +import android.support.annotation.IntRange; +import android.support.annotation.NonNull; +import android.support.annotation.Nullable; +import com.bumptech.glide.Priority; +import com.bumptech.glide.load.DecodeFormat; +import com.bumptech.glide.load.Key; +import com.bumptech.glide.load.Option; +import com.bumptech.glide.load.Transformation; +import com.bumptech.glide.load.engine.DiskCacheStrategy; +import com.bumptech.glide.load.resource.bitmap.DownsampleStrategy; +import com.bumptech.glide.request.RequestOptions; +import java.lang.Class; +import java.lang.Cloneable; +import java.lang.Override; +import java.lang.SafeVarargs; +import java.lang.SuppressWarnings; + +/** + * Automatically generated from {@link com.bumptech.glide.annotation.GlideExtension} annotated classes. + * + * @see RequestOptions + * @see Extension + */ +@SuppressWarnings("deprecation") +public final class GlideOptions extends RequestOptions implements Cloneable { + private static GlideOptions fitCenterTransform0; + + private static GlideOptions centerInsideTransform1; + + private static GlideOptions centerCropTransform2; + + private static GlideOptions circleCropTransform3; + + private static GlideOptions noTransformation4; + + private static GlideOptions noAnimation5; + + /** + * @see RequestOptions#sizeMultiplierOf(float) + */ + @CheckResult + public static GlideOptions sizeMultiplierOf(@FloatRange(from = 0.0, to = 1.0) float arg0) { + return new GlideOptions().sizeMultiplier(arg0); + } + + /** + * @see RequestOptions#diskCacheStrategyOf(DiskCacheStrategy) + */ + @CheckResult + public static GlideOptions diskCacheStrategyOf(@NonNull DiskCacheStrategy arg0) { + return new GlideOptions().diskCacheStrategy(arg0); + } + + /** + * @see RequestOptions#priorityOf(Priority) + */ + @CheckResult + public static GlideOptions priorityOf(@NonNull Priority arg0) { + return new GlideOptions().priority(arg0); + } + + /** + * @see RequestOptions#placeholderOf(Drawable) + */ + @CheckResult + public static GlideOptions placeholderOf(@Nullable Drawable arg0) { + return new GlideOptions().placeholder(arg0); + } + + /** + * @see RequestOptions#placeholderOf(int) + */ + @CheckResult + public static GlideOptions placeholderOf(@DrawableRes int arg0) { + return new GlideOptions().placeholder(arg0); + } + + /** + * @see RequestOptions#errorOf(Drawable) + */ + @CheckResult + public static GlideOptions errorOf(@Nullable Drawable arg0) { + return new GlideOptions().error(arg0); + } + + /** + * @see RequestOptions#errorOf(int) + */ + @CheckResult + public static GlideOptions errorOf(@DrawableRes int arg0) { + return new GlideOptions().error(arg0); + } + + /** + * @see RequestOptions#skipMemoryCacheOf(boolean) + */ + @CheckResult + public static GlideOptions skipMemoryCacheOf(boolean skipMemoryCache) { + return new GlideOptions().skipMemoryCache(skipMemoryCache); + } + + /** + * @see RequestOptions#overrideOf(int, int) + */ + @CheckResult + public static GlideOptions overrideOf(@IntRange(from = 0) int arg0, + @IntRange(from = 0) int arg1) { + return new GlideOptions().override(arg0, arg1); + } + + /** + * @see RequestOptions#overrideOf(int) + */ + @CheckResult + public static GlideOptions overrideOf(@IntRange(from = 0) int arg0) { + return new GlideOptions().override(arg0); + } + + /** + * @see RequestOptions#signatureOf(Key) + */ + @CheckResult + public static GlideOptions signatureOf(@NonNull Key arg0) { + return new GlideOptions().signature(arg0); + } + + /** + * @see RequestOptions#fitCenterTransform() + */ + @CheckResult + public static GlideOptions fitCenterTransform() { + if (GlideOptions.fitCenterTransform0 == null) { + GlideOptions.fitCenterTransform0 = + new GlideOptions().fitCenter().autoClone(); + } + return GlideOptions.fitCenterTransform0; + } + + /** + * @see RequestOptions#centerInsideTransform() + */ + @CheckResult + public static GlideOptions centerInsideTransform() { + if (GlideOptions.centerInsideTransform1 == null) { + GlideOptions.centerInsideTransform1 = + new GlideOptions().centerInside().autoClone(); + } + return GlideOptions.centerInsideTransform1; + } + + /** + * @see RequestOptions#centerCropTransform() + */ + @CheckResult + public static GlideOptions centerCropTransform() { + if (GlideOptions.centerCropTransform2 == null) { + GlideOptions.centerCropTransform2 = + new GlideOptions().centerCrop().autoClone(); + } + return GlideOptions.centerCropTransform2; + } + + /** + * @see RequestOptions#circleCropTransform() + */ + @CheckResult + public static GlideOptions circleCropTransform() { + if (GlideOptions.circleCropTransform3 == null) { + GlideOptions.circleCropTransform3 = + new GlideOptions().circleCrop().autoClone(); + } + return GlideOptions.circleCropTransform3; + } + + /** + * @see RequestOptions#bitmapTransform(Transformation) + */ + @CheckResult + public static GlideOptions bitmapTransform(@NonNull Transformation arg0) { + return new GlideOptions().transform(arg0); + } + + /** + * @see RequestOptions#noTransformation() + */ + @CheckResult + public static GlideOptions noTransformation() { + if (GlideOptions.noTransformation4 == null) { + GlideOptions.noTransformation4 = + new GlideOptions().dontTransform().autoClone(); + } + return GlideOptions.noTransformation4; + } + + /** + * @see RequestOptions#option(Option, T) + */ + @CheckResult + public static GlideOptions option(@NonNull Option arg0, @NonNull T arg1) { + return new GlideOptions().set(arg0, arg1); + } + + /** + * @see RequestOptions#decodeTypeOf(Class) + */ + @CheckResult + public static GlideOptions decodeTypeOf(@NonNull Class arg0) { + return new GlideOptions().decode(arg0); + } + + /** + * @see RequestOptions#formatOf(DecodeFormat) + */ + @CheckResult + public static GlideOptions formatOf(@NonNull DecodeFormat arg0) { + return new GlideOptions().format(arg0); + } + + /** + * @see RequestOptions#frameOf(long) + */ + @CheckResult + public static GlideOptions frameOf(@IntRange(from = 0) long arg0) { + return new GlideOptions().frame(arg0); + } + + /** + * @see RequestOptions#downsampleOf(DownsampleStrategy) + */ + @CheckResult + public static GlideOptions downsampleOf(@NonNull DownsampleStrategy arg0) { + return new GlideOptions().downsample(arg0); + } + + /** + * @see RequestOptions#timeoutOf(int) + */ + @CheckResult + public static GlideOptions timeoutOf(@IntRange(from = 0) int arg0) { + return new GlideOptions().timeout(arg0); + } + + /** + * @see RequestOptions#encodeQualityOf(int) + */ + @CheckResult + public static GlideOptions encodeQualityOf(@IntRange(from = 0, to = 100) int arg0) { + return new GlideOptions().encodeQuality(arg0); + } + + /** + * @see RequestOptions#encodeFormatOf(CompressFormat) + */ + @CheckResult + public static GlideOptions encodeFormatOf(@NonNull Bitmap.CompressFormat arg0) { + return new GlideOptions().encodeFormat(arg0); + } + + /** + * @see RequestOptions#noAnimation() + */ + @CheckResult + public static GlideOptions noAnimation() { + if (GlideOptions.noAnimation5 == null) { + GlideOptions.noAnimation5 = + new GlideOptions().dontAnimate().autoClone(); + } + return GlideOptions.noAnimation5; + } + + @Override + @CheckResult + public final GlideOptions sizeMultiplier(@FloatRange(from = 0.0, to = 1.0) float arg0) { + return (GlideOptions) super.sizeMultiplier(arg0); + } + + @Override + @CheckResult + public final GlideOptions useUnlimitedSourceGeneratorsPool(boolean flag) { + return (GlideOptions) super.useUnlimitedSourceGeneratorsPool(flag); + } + + @Override + @CheckResult + public final GlideOptions useAnimationPool(boolean flag) { + return (GlideOptions) super.useAnimationPool(flag); + } + + @Override + @CheckResult + public final GlideOptions onlyRetrieveFromCache(boolean flag) { + return (GlideOptions) super.onlyRetrieveFromCache(flag); + } + + @Override + @CheckResult + public final GlideOptions diskCacheStrategy(@NonNull DiskCacheStrategy arg0) { + return (GlideOptions) super.diskCacheStrategy(arg0); + } + + @Override + @CheckResult + public final GlideOptions priority(@NonNull Priority arg0) { + return (GlideOptions) super.priority(arg0); + } + + @Override + @CheckResult + public final GlideOptions placeholder(@Nullable Drawable arg0) { + return (GlideOptions) super.placeholder(arg0); + } + + @Override + @CheckResult + public final GlideOptions placeholder(@DrawableRes int arg0) { + return (GlideOptions) super.placeholder(arg0); + } + + @Override + @CheckResult + public final GlideOptions fallback(@Nullable Drawable arg0) { + return (GlideOptions) super.fallback(arg0); + } + + @Override + @CheckResult + public final GlideOptions fallback(@DrawableRes int arg0) { + return (GlideOptions) super.fallback(arg0); + } + + @Override + @CheckResult + public final GlideOptions error(@Nullable Drawable arg0) { + return (GlideOptions) super.error(arg0); + } + + @Override + @CheckResult + public final GlideOptions error(@DrawableRes int arg0) { + return (GlideOptions) super.error(arg0); + } + + @Override + @CheckResult + public final GlideOptions theme(@Nullable Resources.Theme arg0) { + return (GlideOptions) super.theme(arg0); + } + + @Override + @CheckResult + public final GlideOptions skipMemoryCache(boolean skip) { + return (GlideOptions) super.skipMemoryCache(skip); + } + + @Override + @CheckResult + public final GlideOptions override(int width, int height) { + return (GlideOptions) super.override(width, height); + } + + @Override + @CheckResult + public final GlideOptions override(int size) { + return (GlideOptions) super.override(size); + } + + @Override + @CheckResult + public final GlideOptions signature(@NonNull Key arg0) { + return (GlideOptions) super.signature(arg0); + } + + @Override + @CheckResult + public final GlideOptions clone() { + return (GlideOptions) super.clone(); + } + + @Override + @CheckResult + public final GlideOptions set(@NonNull Option arg0, @NonNull T arg1) { + return (GlideOptions) super.set(arg0, arg1); + } + + @Override + @CheckResult + public final GlideOptions decode(@NonNull Class arg0) { + return (GlideOptions) super.decode(arg0); + } + + @Override + @CheckResult + public final GlideOptions encodeFormat(@NonNull Bitmap.CompressFormat arg0) { + return (GlideOptions) super.encodeFormat(arg0); + } + + @Override + @CheckResult + public final GlideOptions encodeQuality(@IntRange(from = 0, to = 100) int arg0) { + return (GlideOptions) super.encodeQuality(arg0); + } + + @Override + @CheckResult + public final GlideOptions frame(@IntRange(from = 0) long arg0) { + return (GlideOptions) super.frame(arg0); + } + + @Override + @CheckResult + public final GlideOptions format(@NonNull DecodeFormat arg0) { + return (GlideOptions) super.format(arg0); + } + + @Override + @CheckResult + public final GlideOptions disallowHardwareConfig() { + return (GlideOptions) super.disallowHardwareConfig(); + } + + @Override + @CheckResult + public final GlideOptions downsample(@NonNull DownsampleStrategy arg0) { + return (GlideOptions) super.downsample(arg0); + } + + @Override + @CheckResult + public final GlideOptions timeout(@IntRange(from = 0) int arg0) { + return (GlideOptions) super.timeout(arg0); + } + + @Override + @CheckResult + public final GlideOptions optionalCenterCrop() { + return (GlideOptions) super.optionalCenterCrop(); + } + + @Override + @CheckResult + public final GlideOptions optionalFitCenter() { + return (GlideOptions) super.optionalFitCenter(); + } + + @Override + @CheckResult + public final GlideOptions fitCenter() { + return (GlideOptions) super.fitCenter(); + } + + @Override + @CheckResult + public final GlideOptions optionalCenterInside() { + return (GlideOptions) super.optionalCenterInside(); + } + + @Override + @CheckResult + public final GlideOptions centerInside() { + return (GlideOptions) super.centerInside(); + } + + @Override + @CheckResult + public final GlideOptions optionalCircleCrop() { + return (GlideOptions) super.optionalCircleCrop(); + } + + @Override + @CheckResult + public final GlideOptions circleCrop() { + return (GlideOptions) super.circleCrop(); + } + + @Override + @CheckResult + public final GlideOptions transform(@NonNull Transformation arg0) { + return (GlideOptions) super.transform(arg0); + } + + @Override + @SafeVarargs + @CheckResult + public final GlideOptions transforms(@NonNull Transformation... arg0) { + return (GlideOptions) super.transforms(arg0); + } + + @Override + @CheckResult + public final GlideOptions optionalTransform(@NonNull Transformation arg0) { + return (GlideOptions) super.optionalTransform(arg0); + } + + @Override + @CheckResult + public final GlideOptions optionalTransform(@NonNull Class arg0, + @NonNull Transformation arg1) { + return (GlideOptions) super.optionalTransform(arg0, arg1); + } + + @Override + @CheckResult + public final GlideOptions transform(@NonNull Class arg0, @NonNull Transformation arg1) { + return (GlideOptions) super.transform(arg0, arg1); + } + + @Override + @CheckResult + public final GlideOptions dontTransform() { + return (GlideOptions) super.dontTransform(); + } + + @Override + @CheckResult + public final GlideOptions dontAnimate() { + return (GlideOptions) super.dontAnimate(); + } + + @Override + @CheckResult + public final GlideOptions apply(@NonNull RequestOptions arg0) { + return (GlideOptions) super.apply(arg0); + } + + @Override + public final GlideOptions lock() { + return (GlideOptions) super.lock(); + } + + @Override + public final GlideOptions autoClone() { + return (GlideOptions) super.autoClone(); + } + + /** + * @see Extension#centerCrop(RequestOptions) + * @see RequestOptions#centerCrop() + */ + @Override + @CheckResult + public GlideOptions centerCrop() { + if (isAutoCloneEnabled()) { + return clone().centerCrop(); + } + super.centerCrop(); + Extension.centerCrop(this); + return this; + } + + /** + * @see Extension#centerCrop(RequestOptions) + */ + @CheckResult + public static GlideOptions centerCropOf() { + return new GlideOptions().centerCrop(); + } +} diff --git a/annotation/compiler/test/src/test/resources/LegacyGlideExtensionOptionsTest/OverrideExtend/GlideRequest.java b/annotation/compiler/test/src/test/resources/LegacyGlideExtensionOptionsTest/OverrideExtend/GlideRequest.java new file mode 100644 index 0000000000..cc504584d3 --- /dev/null +++ b/annotation/compiler/test/src/test/resources/LegacyGlideExtensionOptionsTest/OverrideExtend/GlideRequest.java @@ -0,0 +1,712 @@ +package com.bumptech.glide.test; + +import android.content.Context; +import android.content.res.Resources; +import android.graphics.Bitmap; +import android.graphics.drawable.Drawable; +import android.net.Uri; +import android.support.annotation.CheckResult; +import android.support.annotation.DrawableRes; +import android.support.annotation.FloatRange; +import android.support.annotation.IntRange; +import android.support.annotation.NonNull; +import android.support.annotation.Nullable; +import android.support.annotation.RawRes; +import com.bumptech.glide.Glide; +import com.bumptech.glide.Priority; +import com.bumptech.glide.RequestBuilder; +import com.bumptech.glide.RequestManager; +import com.bumptech.glide.TransitionOptions; +import com.bumptech.glide.load.DecodeFormat; +import com.bumptech.glide.load.Key; +import com.bumptech.glide.load.Option; +import com.bumptech.glide.load.Transformation; +import com.bumptech.glide.load.engine.DiskCacheStrategy; +import com.bumptech.glide.load.resource.bitmap.DownsampleStrategy; +import com.bumptech.glide.request.RequestListener; +import com.bumptech.glide.request.RequestOptions; +import java.io.File; +import java.lang.Class; +import java.lang.Cloneable; +import java.lang.Deprecated; +import java.lang.Integer; +import java.lang.Object; +import java.lang.Override; +import java.lang.SafeVarargs; +import java.lang.String; +import java.lang.SuppressWarnings; +import java.net.URL; + +/** + * Contains all public methods from {@link RequestBuilder}, all options from + * {@link RequestOptions} and all generated options from + * {@link com.bumptech.glide.annotation.GlideOption} in annotated methods in + * {@link com.bumptech.glide.annotation.GlideExtension} annotated classes. + * + *

Generated code, do not modify. + * + * @see RequestBuilder + * @see RequestOptions + */ +@SuppressWarnings({ + "unused", + "deprecation" +}) +public class GlideRequest extends RequestBuilder implements Cloneable { + GlideRequest(Class transcodeClass, RequestBuilder other) { + super(transcodeClass, other); + } + + GlideRequest(Glide glide, RequestManager requestManager, Class transcodeClass, + Context context) { + super(glide, requestManager ,transcodeClass, context); + } + + @Override + @CheckResult + protected GlideRequest getDownloadOnlyRequest() { + return new GlideRequest<>(File.class, this).apply(DOWNLOAD_ONLY_OPTIONS); + } + + /** + * @see GlideOptions#sizeMultiplier(float) + */ + @CheckResult + public GlideRequest sizeMultiplier(@FloatRange(from = 0.0, to = 1.0) float arg0) { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).sizeMultiplier(arg0); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).sizeMultiplier(arg0); + } + return this; + } + + /** + * @see GlideOptions#useUnlimitedSourceGeneratorsPool(boolean) + */ + @CheckResult + public GlideRequest useUnlimitedSourceGeneratorsPool(boolean flag) { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).useUnlimitedSourceGeneratorsPool(flag); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).useUnlimitedSourceGeneratorsPool(flag); + } + return this; + } + + /** + * @see GlideOptions#useAnimationPool(boolean) + */ + @CheckResult + public GlideRequest useAnimationPool(boolean flag) { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).useAnimationPool(flag); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).useAnimationPool(flag); + } + return this; + } + + /** + * @see GlideOptions#onlyRetrieveFromCache(boolean) + */ + @CheckResult + public GlideRequest onlyRetrieveFromCache(boolean flag) { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).onlyRetrieveFromCache(flag); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).onlyRetrieveFromCache(flag); + } + return this; + } + + /** + * @see GlideOptions#diskCacheStrategy(DiskCacheStrategy) + */ + @CheckResult + public GlideRequest diskCacheStrategy(@NonNull DiskCacheStrategy arg0) { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).diskCacheStrategy(arg0); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).diskCacheStrategy(arg0); + } + return this; + } + + /** + * @see GlideOptions#priority(Priority) + */ + @CheckResult + public GlideRequest priority(@NonNull Priority arg0) { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).priority(arg0); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).priority(arg0); + } + return this; + } + + /** + * @see GlideOptions#placeholder(Drawable) + */ + @CheckResult + public GlideRequest placeholder(@Nullable Drawable arg0) { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).placeholder(arg0); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).placeholder(arg0); + } + return this; + } + + /** + * @see GlideOptions#placeholder(int) + */ + @CheckResult + public GlideRequest placeholder(@DrawableRes int arg0) { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).placeholder(arg0); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).placeholder(arg0); + } + return this; + } + + /** + * @see GlideOptions#fallback(Drawable) + */ + @CheckResult + public GlideRequest fallback(@Nullable Drawable arg0) { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).fallback(arg0); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).fallback(arg0); + } + return this; + } + + /** + * @see GlideOptions#fallback(int) + */ + @CheckResult + public GlideRequest fallback(@DrawableRes int arg0) { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).fallback(arg0); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).fallback(arg0); + } + return this; + } + + /** + * @see GlideOptions#error(Drawable) + */ + @CheckResult + public GlideRequest error(@Nullable Drawable arg0) { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).error(arg0); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).error(arg0); + } + return this; + } + + /** + * @see GlideOptions#error(int) + */ + @CheckResult + public GlideRequest error(@DrawableRes int arg0) { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).error(arg0); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).error(arg0); + } + return this; + } + + /** + * @see GlideOptions#theme(Resources.Theme) + */ + @CheckResult + public GlideRequest theme(@Nullable Resources.Theme arg0) { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).theme(arg0); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).theme(arg0); + } + return this; + } + + /** + * @see GlideOptions#skipMemoryCache(boolean) + */ + @CheckResult + public GlideRequest skipMemoryCache(boolean skip) { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).skipMemoryCache(skip); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).skipMemoryCache(skip); + } + return this; + } + + /** + * @see GlideOptions#override(int, int) + */ + @CheckResult + public GlideRequest override(int width, int height) { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).override(width, height); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).override(width, height); + } + return this; + } + + /** + * @see GlideOptions#override(int) + */ + @CheckResult + public GlideRequest override(int size) { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).override(size); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).override(size); + } + return this; + } + + /** + * @see GlideOptions#signature(Key) + */ + @CheckResult + public GlideRequest signature(@NonNull Key arg0) { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).signature(arg0); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).signature(arg0); + } + return this; + } + + /** + * @see GlideOptions#set(Option, T) + */ + @CheckResult + public GlideRequest set(@NonNull Option arg0, @NonNull T arg1) { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).set(arg0, arg1); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).set(arg0, arg1); + } + return this; + } + + /** + * @see GlideOptions#decode(Class) + */ + @CheckResult + public GlideRequest decode(@NonNull Class arg0) { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).decode(arg0); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).decode(arg0); + } + return this; + } + + /** + * @see GlideOptions#encodeFormat(Bitmap.CompressFormat) + */ + @CheckResult + public GlideRequest encodeFormat(@NonNull Bitmap.CompressFormat arg0) { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).encodeFormat(arg0); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).encodeFormat(arg0); + } + return this; + } + + /** + * @see GlideOptions#encodeQuality(int) + */ + @CheckResult + public GlideRequest encodeQuality(@IntRange(from = 0, to = 100) int arg0) { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).encodeQuality(arg0); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).encodeQuality(arg0); + } + return this; + } + + /** + * @see GlideOptions#frame(long) + */ + @CheckResult + public GlideRequest frame(@IntRange(from = 0) long arg0) { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).frame(arg0); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).frame(arg0); + } + return this; + } + + /** + * @see GlideOptions#format(DecodeFormat) + */ + @CheckResult + public GlideRequest format(@NonNull DecodeFormat arg0) { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).format(arg0); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).format(arg0); + } + return this; + } + + /** + * @see GlideOptions#disallowHardwareConfig() + */ + @CheckResult + public GlideRequest disallowHardwareConfig() { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).disallowHardwareConfig(); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).disallowHardwareConfig(); + } + return this; + } + + /** + * @see GlideOptions#downsample(DownsampleStrategy) + */ + @CheckResult + public GlideRequest downsample(@NonNull DownsampleStrategy arg0) { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).downsample(arg0); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).downsample(arg0); + } + return this; + } + + /** + * @see GlideOptions#timeout(int) + */ + @CheckResult + public GlideRequest timeout(@IntRange(from = 0) int arg0) { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).timeout(arg0); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).timeout(arg0); + } + return this; + } + + /** + * @see GlideOptions#optionalCenterCrop() + */ + @CheckResult + public GlideRequest optionalCenterCrop() { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).optionalCenterCrop(); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).optionalCenterCrop(); + } + return this; + } + + /** + * @see GlideOptions#optionalFitCenter() + */ + @CheckResult + public GlideRequest optionalFitCenter() { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).optionalFitCenter(); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).optionalFitCenter(); + } + return this; + } + + /** + * @see GlideOptions#fitCenter() + */ + @CheckResult + public GlideRequest fitCenter() { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).fitCenter(); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).fitCenter(); + } + return this; + } + + /** + * @see GlideOptions#optionalCenterInside() + */ + @CheckResult + public GlideRequest optionalCenterInside() { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).optionalCenterInside(); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).optionalCenterInside(); + } + return this; + } + + /** + * @see GlideOptions#centerInside() + */ + @CheckResult + public GlideRequest centerInside() { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).centerInside(); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).centerInside(); + } + return this; + } + + /** + * @see GlideOptions#optionalCircleCrop() + */ + @CheckResult + public GlideRequest optionalCircleCrop() { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).optionalCircleCrop(); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).optionalCircleCrop(); + } + return this; + } + + /** + * @see GlideOptions#circleCrop() + */ + @CheckResult + public GlideRequest circleCrop() { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).circleCrop(); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).circleCrop(); + } + return this; + } + + /** + * @see GlideOptions#transform(Transformation) + */ + @CheckResult + public GlideRequest transform(@NonNull Transformation arg0) { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).transform(arg0); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).transform(arg0); + } + return this; + } + + /** + * @see GlideOptions#transforms(Transformation[]) + */ + @CheckResult + @SuppressWarnings({ + "unchecked", + "varargs" + }) + public GlideRequest transforms(@NonNull Transformation... arg0) { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).transforms(arg0); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).transforms(arg0); + } + return this; + } + + /** + * @see GlideOptions#optionalTransform(Transformation) + */ + @CheckResult + public GlideRequest optionalTransform(@NonNull Transformation arg0) { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).optionalTransform(arg0); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).optionalTransform(arg0); + } + return this; + } + + /** + * @see GlideOptions#optionalTransform(Class, Transformation) + */ + @CheckResult + public GlideRequest optionalTransform(@NonNull Class arg0, + @NonNull Transformation arg1) { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).optionalTransform(arg0, arg1); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).optionalTransform(arg0, arg1); + } + return this; + } + + /** + * @see GlideOptions#transform(Class, Transformation) + */ + @CheckResult + public GlideRequest transform(@NonNull Class arg0, + @NonNull Transformation arg1) { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).transform(arg0, arg1); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).transform(arg0, arg1); + } + return this; + } + + /** + * @see GlideOptions#dontTransform() + */ + @CheckResult + public GlideRequest dontTransform() { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).dontTransform(); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).dontTransform(); + } + return this; + } + + /** + * @see GlideOptions#dontAnimate() + */ + @CheckResult + public GlideRequest dontAnimate() { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).dontAnimate(); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).dontAnimate(); + } + return this; + } + + /** + * @see GlideOptions#centerCrop() + */ + @CheckResult + public GlideRequest centerCrop() { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).centerCrop(); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).centerCrop(); + } + return this; + } + + @Override + @CheckResult + public GlideRequest apply(@NonNull RequestOptions arg0) { + return (GlideRequest) super.apply(arg0); + } + + @Override + @CheckResult + public GlideRequest transition(@NonNull TransitionOptions arg0) { + return (GlideRequest) super.transition(arg0); + } + + @Override + @CheckResult + public GlideRequest listener(@Nullable RequestListener arg0) { + return (GlideRequest) super.listener(arg0); + } + + @Override + public GlideRequest error(@Nullable RequestBuilder arg0) { + return (GlideRequest) super.error(arg0); + } + + @Override + @CheckResult + public GlideRequest thumbnail(@Nullable RequestBuilder arg0) { + return (GlideRequest) super.thumbnail(arg0); + } + + @Override + @CheckResult + @SafeVarargs + public final GlideRequest thumbnail(@Nullable RequestBuilder... arg0) { + return (GlideRequest) super.thumbnail(arg0); + } + + @Override + @CheckResult + public GlideRequest thumbnail(float sizeMultiplier) { + return (GlideRequest) super.thumbnail(sizeMultiplier); + } + + @Override + @CheckResult + public GlideRequest load(@Nullable Object arg0) { + return (GlideRequest) super.load(arg0); + } + + @Override + @CheckResult + public GlideRequest load(@Nullable Bitmap arg0) { + return (GlideRequest) super.load(arg0); + } + + @Override + @CheckResult + public GlideRequest load(@Nullable Drawable arg0) { + return (GlideRequest) super.load(arg0); + } + + @Override + @CheckResult + public GlideRequest load(@Nullable String arg0) { + return (GlideRequest) super.load(arg0); + } + + @Override + @CheckResult + public GlideRequest load(@Nullable Uri arg0) { + return (GlideRequest) super.load(arg0); + } + + @Override + @CheckResult + public GlideRequest load(@Nullable File arg0) { + return (GlideRequest) super.load(arg0); + } + + @Override + @CheckResult + public GlideRequest load(@RawRes @DrawableRes @Nullable Integer arg0) { + return (GlideRequest) super.load(arg0); + } + + @Override + @Deprecated + @CheckResult + public GlideRequest load(@Nullable URL arg0) { + return (GlideRequest) super.load(arg0); + } + + @Override + @CheckResult + public GlideRequest load(@Nullable byte[] arg0) { + return (GlideRequest) super.load(arg0); + } + + @Override + @CheckResult + public GlideRequest clone() { + return (GlideRequest) super.clone(); + } +} diff --git a/annotation/compiler/test/src/test/resources/LegacyGlideExtensionOptionsTest/OverrideReplace/Extension.java b/annotation/compiler/test/src/test/resources/LegacyGlideExtensionOptionsTest/OverrideReplace/Extension.java new file mode 100644 index 0000000000..591f857f21 --- /dev/null +++ b/annotation/compiler/test/src/test/resources/LegacyGlideExtensionOptionsTest/OverrideReplace/Extension.java @@ -0,0 +1,18 @@ +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 final class Extension { + + private Extension() { + // Utility class. + } + + @GlideOption(override = GlideOption.OVERRIDE_REPLACE) + public static void centerCrop(RequestOptions requestOptions) { + requestOptions.centerCrop(); + } +} diff --git a/annotation/compiler/test/src/test/resources/LegacyGlideExtensionOptionsTest/OverrideReplace/GlideOptions.java b/annotation/compiler/test/src/test/resources/LegacyGlideExtensionOptionsTest/OverrideReplace/GlideOptions.java new file mode 100644 index 0000000000..823666b544 --- /dev/null +++ b/annotation/compiler/test/src/test/resources/LegacyGlideExtensionOptionsTest/OverrideReplace/GlideOptions.java @@ -0,0 +1,562 @@ +package com.bumptech.glide.test; + +import android.content.res.Resources; +import android.graphics.Bitmap; +import android.graphics.drawable.Drawable; +import android.support.annotation.CheckResult; +import android.support.annotation.DrawableRes; +import android.support.annotation.FloatRange; +import android.support.annotation.IntRange; +import android.support.annotation.NonNull; +import android.support.annotation.Nullable; +import com.bumptech.glide.Priority; +import com.bumptech.glide.load.DecodeFormat; +import com.bumptech.glide.load.Key; +import com.bumptech.glide.load.Option; +import com.bumptech.glide.load.Transformation; +import com.bumptech.glide.load.engine.DiskCacheStrategy; +import com.bumptech.glide.load.resource.bitmap.DownsampleStrategy; +import com.bumptech.glide.request.RequestOptions; +import java.lang.Class; +import java.lang.Cloneable; +import java.lang.Override; +import java.lang.SafeVarargs; +import java.lang.SuppressWarnings; + +/** + * Automatically generated from {@link com.bumptech.glide.annotation.GlideExtension} annotated classes. + * + * @see RequestOptions + * @see Extension + */ +@SuppressWarnings("deprecation") +public final class GlideOptions extends RequestOptions implements Cloneable { + private static GlideOptions fitCenterTransform0; + + private static GlideOptions centerInsideTransform1; + + private static GlideOptions centerCropTransform2; + + private static GlideOptions circleCropTransform3; + + private static GlideOptions noTransformation4; + + private static GlideOptions noAnimation5; + + /** + * @see RequestOptions#sizeMultiplierOf(float) + */ + @CheckResult + public static GlideOptions sizeMultiplierOf(@FloatRange(from = 0.0, to = 1.0) float arg0) { + return new GlideOptions().sizeMultiplier(arg0); + } + + /** + * @see RequestOptions#diskCacheStrategyOf(DiskCacheStrategy) + */ + @CheckResult + public static GlideOptions diskCacheStrategyOf(@NonNull DiskCacheStrategy arg0) { + return new GlideOptions().diskCacheStrategy(arg0); + } + + /** + * @see RequestOptions#priorityOf(Priority) + */ + @CheckResult + public static GlideOptions priorityOf(@NonNull Priority arg0) { + return new GlideOptions().priority(arg0); + } + + /** + * @see RequestOptions#placeholderOf(Drawable) + */ + @CheckResult + public static GlideOptions placeholderOf(@Nullable Drawable arg0) { + return new GlideOptions().placeholder(arg0); + } + + /** + * @see RequestOptions#placeholderOf(int) + */ + @CheckResult + public static GlideOptions placeholderOf(@DrawableRes int arg0) { + return new GlideOptions().placeholder(arg0); + } + + /** + * @see RequestOptions#errorOf(Drawable) + */ + @CheckResult + public static GlideOptions errorOf(@Nullable Drawable arg0) { + return new GlideOptions().error(arg0); + } + + /** + * @see RequestOptions#errorOf(int) + */ + @CheckResult + public static GlideOptions errorOf(@DrawableRes int arg0) { + return new GlideOptions().error(arg0); + } + + /** + * @see RequestOptions#skipMemoryCacheOf(boolean) + */ + @CheckResult + public static GlideOptions skipMemoryCacheOf(boolean skipMemoryCache) { + return new GlideOptions().skipMemoryCache(skipMemoryCache); + } + + /** + * @see RequestOptions#overrideOf(int, int) + */ + @CheckResult + public static GlideOptions overrideOf(@IntRange(from = 0) int arg0, + @IntRange(from = 0) int arg1) { + return new GlideOptions().override(arg0, arg1); + } + + /** + * @see RequestOptions#overrideOf(int) + */ + @CheckResult + public static GlideOptions overrideOf(@IntRange(from = 0) int arg0) { + return new GlideOptions().override(arg0); + } + + /** + * @see RequestOptions#signatureOf(Key) + */ + @CheckResult + public static GlideOptions signatureOf(@NonNull Key arg0) { + return new GlideOptions().signature(arg0); + } + + /** + * @see RequestOptions#fitCenterTransform() + */ + @CheckResult + public static GlideOptions fitCenterTransform() { + if (GlideOptions.fitCenterTransform0 == null) { + GlideOptions.fitCenterTransform0 = + new GlideOptions().fitCenter().autoClone(); + } + return GlideOptions.fitCenterTransform0; + } + + /** + * @see RequestOptions#centerInsideTransform() + */ + @CheckResult + public static GlideOptions centerInsideTransform() { + if (GlideOptions.centerInsideTransform1 == null) { + GlideOptions.centerInsideTransform1 = + new GlideOptions().centerInside().autoClone(); + } + return GlideOptions.centerInsideTransform1; + } + + /** + * @see RequestOptions#centerCropTransform() + */ + @CheckResult + public static GlideOptions centerCropTransform() { + if (GlideOptions.centerCropTransform2 == null) { + GlideOptions.centerCropTransform2 = + new GlideOptions().centerCrop().autoClone(); + } + return GlideOptions.centerCropTransform2; + } + + /** + * @see RequestOptions#circleCropTransform() + */ + @CheckResult + public static GlideOptions circleCropTransform() { + if (GlideOptions.circleCropTransform3 == null) { + GlideOptions.circleCropTransform3 = + new GlideOptions().circleCrop().autoClone(); + } + return GlideOptions.circleCropTransform3; + } + + /** + * @see RequestOptions#bitmapTransform(Transformation) + */ + @CheckResult + public static GlideOptions bitmapTransform(@NonNull Transformation arg0) { + return new GlideOptions().transform(arg0); + } + + /** + * @see RequestOptions#noTransformation() + */ + @CheckResult + public static GlideOptions noTransformation() { + if (GlideOptions.noTransformation4 == null) { + GlideOptions.noTransformation4 = + new GlideOptions().dontTransform().autoClone(); + } + return GlideOptions.noTransformation4; + } + + /** + * @see RequestOptions#option(Option, T) + */ + @CheckResult + public static GlideOptions option(@NonNull Option arg0, @NonNull T arg1) { + return new GlideOptions().set(arg0, arg1); + } + + /** + * @see RequestOptions#decodeTypeOf(Class) + */ + @CheckResult + public static GlideOptions decodeTypeOf(@NonNull Class arg0) { + return new GlideOptions().decode(arg0); + } + + /** + * @see RequestOptions#formatOf(DecodeFormat) + */ + @CheckResult + public static GlideOptions formatOf(@NonNull DecodeFormat arg0) { + return new GlideOptions().format(arg0); + } + + /** + * @see RequestOptions#frameOf(long) + */ + @CheckResult + public static GlideOptions frameOf(@IntRange(from = 0) long arg0) { + return new GlideOptions().frame(arg0); + } + + /** + * @see RequestOptions#downsampleOf(DownsampleStrategy) + */ + @CheckResult + public static GlideOptions downsampleOf(@NonNull DownsampleStrategy arg0) { + return new GlideOptions().downsample(arg0); + } + + /** + * @see RequestOptions#timeoutOf(int) + */ + @CheckResult + public static GlideOptions timeoutOf(@IntRange(from = 0) int arg0) { + return new GlideOptions().timeout(arg0); + } + + /** + * @see RequestOptions#encodeQualityOf(int) + */ + @CheckResult + public static GlideOptions encodeQualityOf(@IntRange(from = 0, to = 100) int arg0) { + return new GlideOptions().encodeQuality(arg0); + } + + /** + * @see RequestOptions#encodeFormatOf(CompressFormat) + */ + @CheckResult + public static GlideOptions encodeFormatOf(@NonNull Bitmap.CompressFormat arg0) { + return new GlideOptions().encodeFormat(arg0); + } + + /** + * @see RequestOptions#noAnimation() + */ + @CheckResult + public static GlideOptions noAnimation() { + if (GlideOptions.noAnimation5 == null) { + GlideOptions.noAnimation5 = + new GlideOptions().dontAnimate().autoClone(); + } + return GlideOptions.noAnimation5; + } + + @Override + @CheckResult + public final GlideOptions sizeMultiplier(@FloatRange(from = 0.0, to = 1.0) float arg0) { + return (GlideOptions) super.sizeMultiplier(arg0); + } + + @Override + @CheckResult + public final GlideOptions useUnlimitedSourceGeneratorsPool(boolean flag) { + return (GlideOptions) super.useUnlimitedSourceGeneratorsPool(flag); + } + + @Override + @CheckResult + public final GlideOptions useAnimationPool(boolean flag) { + return (GlideOptions) super.useAnimationPool(flag); + } + + @Override + @CheckResult + public final GlideOptions onlyRetrieveFromCache(boolean flag) { + return (GlideOptions) super.onlyRetrieveFromCache(flag); + } + + @Override + @CheckResult + public final GlideOptions diskCacheStrategy(@NonNull DiskCacheStrategy arg0) { + return (GlideOptions) super.diskCacheStrategy(arg0); + } + + @Override + @CheckResult + public final GlideOptions priority(@NonNull Priority arg0) { + return (GlideOptions) super.priority(arg0); + } + + @Override + @CheckResult + public final GlideOptions placeholder(@Nullable Drawable arg0) { + return (GlideOptions) super.placeholder(arg0); + } + + @Override + @CheckResult + public final GlideOptions placeholder(@DrawableRes int arg0) { + return (GlideOptions) super.placeholder(arg0); + } + + @Override + @CheckResult + public final GlideOptions fallback(@Nullable Drawable arg0) { + return (GlideOptions) super.fallback(arg0); + } + + @Override + @CheckResult + public final GlideOptions fallback(@DrawableRes int arg0) { + return (GlideOptions) super.fallback(arg0); + } + + @Override + @CheckResult + public final GlideOptions error(@Nullable Drawable arg0) { + return (GlideOptions) super.error(arg0); + } + + @Override + @CheckResult + public final GlideOptions error(@DrawableRes int arg0) { + return (GlideOptions) super.error(arg0); + } + + @Override + @CheckResult + public final GlideOptions theme(@Nullable Resources.Theme arg0) { + return (GlideOptions) super.theme(arg0); + } + + @Override + @CheckResult + public final GlideOptions skipMemoryCache(boolean skip) { + return (GlideOptions) super.skipMemoryCache(skip); + } + + @Override + @CheckResult + public final GlideOptions override(int width, int height) { + return (GlideOptions) super.override(width, height); + } + + @Override + @CheckResult + public final GlideOptions override(int size) { + return (GlideOptions) super.override(size); + } + + @Override + @CheckResult + public final GlideOptions signature(@NonNull Key arg0) { + return (GlideOptions) super.signature(arg0); + } + + @Override + @CheckResult + public final GlideOptions clone() { + return (GlideOptions) super.clone(); + } + + @Override + @CheckResult + public final GlideOptions set(@NonNull Option arg0, @NonNull T arg1) { + return (GlideOptions) super.set(arg0, arg1); + } + + @Override + @CheckResult + public final GlideOptions decode(@NonNull Class arg0) { + return (GlideOptions) super.decode(arg0); + } + + @Override + @CheckResult + public final GlideOptions encodeFormat(@NonNull Bitmap.CompressFormat arg0) { + return (GlideOptions) super.encodeFormat(arg0); + } + + @Override + @CheckResult + public final GlideOptions encodeQuality(@IntRange(from = 0, to = 100) int arg0) { + return (GlideOptions) super.encodeQuality(arg0); + } + + @Override + @CheckResult + public final GlideOptions frame(@IntRange(from = 0) long arg0) { + return (GlideOptions) super.frame(arg0); + } + + @Override + @CheckResult + public final GlideOptions format(@NonNull DecodeFormat arg0) { + return (GlideOptions) super.format(arg0); + } + + @Override + @CheckResult + public final GlideOptions disallowHardwareConfig() { + return (GlideOptions) super.disallowHardwareConfig(); + } + + @Override + @CheckResult + public final GlideOptions downsample(@NonNull DownsampleStrategy arg0) { + return (GlideOptions) super.downsample(arg0); + } + + @Override + @CheckResult + public final GlideOptions timeout(@IntRange(from = 0) int arg0) { + return (GlideOptions) super.timeout(arg0); + } + + @Override + @CheckResult + public final GlideOptions optionalCenterCrop() { + return (GlideOptions) super.optionalCenterCrop(); + } + + @Override + @CheckResult + public final GlideOptions optionalFitCenter() { + return (GlideOptions) super.optionalFitCenter(); + } + + @Override + @CheckResult + public final GlideOptions fitCenter() { + return (GlideOptions) super.fitCenter(); + } + + @Override + @CheckResult + public final GlideOptions optionalCenterInside() { + return (GlideOptions) super.optionalCenterInside(); + } + + @Override + @CheckResult + public final GlideOptions centerInside() { + return (GlideOptions) super.centerInside(); + } + + @Override + @CheckResult + public final GlideOptions optionalCircleCrop() { + return (GlideOptions) super.optionalCircleCrop(); + } + + @Override + @CheckResult + public final GlideOptions circleCrop() { + return (GlideOptions) super.circleCrop(); + } + + @Override + @CheckResult + public final GlideOptions transform(@NonNull Transformation arg0) { + return (GlideOptions) super.transform(arg0); + } + + @Override + @SafeVarargs + @CheckResult + public final GlideOptions transforms(@NonNull Transformation... arg0) { + return (GlideOptions) super.transforms(arg0); + } + + @Override + @CheckResult + public final GlideOptions optionalTransform(@NonNull Transformation arg0) { + return (GlideOptions) super.optionalTransform(arg0); + } + + @Override + @CheckResult + public final GlideOptions optionalTransform(@NonNull Class arg0, + @NonNull Transformation arg1) { + return (GlideOptions) super.optionalTransform(arg0, arg1); + } + + @Override + @CheckResult + public final GlideOptions transform(@NonNull Class arg0, @NonNull Transformation arg1) { + return (GlideOptions) super.transform(arg0, arg1); + } + + @Override + @CheckResult + public final GlideOptions dontTransform() { + return (GlideOptions) super.dontTransform(); + } + + @Override + @CheckResult + public final GlideOptions dontAnimate() { + return (GlideOptions) super.dontAnimate(); + } + + @Override + @CheckResult + public final GlideOptions apply(@NonNull RequestOptions arg0) { + return (GlideOptions) super.apply(arg0); + } + + @Override + public final GlideOptions lock() { + return (GlideOptions) super.lock(); + } + + @Override + public final GlideOptions autoClone() { + return (GlideOptions) super.autoClone(); + } + + /** + * @see Extension#centerCrop(RequestOptions) + */ + @CheckResult + public GlideOptions centerCrop() { + if (isAutoCloneEnabled()) { + return clone().centerCrop(); + } + Extension.centerCrop(this); + return this; + } + + /** + * @see Extension#centerCrop(RequestOptions) + */ + @CheckResult + public static GlideOptions centerCropOf() { + return new GlideOptions().centerCrop(); + } +} diff --git a/annotation/compiler/test/src/test/resources/LegacyGlideExtensionOptionsTest/OverrideReplace/GlideRequest.java b/annotation/compiler/test/src/test/resources/LegacyGlideExtensionOptionsTest/OverrideReplace/GlideRequest.java new file mode 100644 index 0000000000..cc504584d3 --- /dev/null +++ b/annotation/compiler/test/src/test/resources/LegacyGlideExtensionOptionsTest/OverrideReplace/GlideRequest.java @@ -0,0 +1,712 @@ +package com.bumptech.glide.test; + +import android.content.Context; +import android.content.res.Resources; +import android.graphics.Bitmap; +import android.graphics.drawable.Drawable; +import android.net.Uri; +import android.support.annotation.CheckResult; +import android.support.annotation.DrawableRes; +import android.support.annotation.FloatRange; +import android.support.annotation.IntRange; +import android.support.annotation.NonNull; +import android.support.annotation.Nullable; +import android.support.annotation.RawRes; +import com.bumptech.glide.Glide; +import com.bumptech.glide.Priority; +import com.bumptech.glide.RequestBuilder; +import com.bumptech.glide.RequestManager; +import com.bumptech.glide.TransitionOptions; +import com.bumptech.glide.load.DecodeFormat; +import com.bumptech.glide.load.Key; +import com.bumptech.glide.load.Option; +import com.bumptech.glide.load.Transformation; +import com.bumptech.glide.load.engine.DiskCacheStrategy; +import com.bumptech.glide.load.resource.bitmap.DownsampleStrategy; +import com.bumptech.glide.request.RequestListener; +import com.bumptech.glide.request.RequestOptions; +import java.io.File; +import java.lang.Class; +import java.lang.Cloneable; +import java.lang.Deprecated; +import java.lang.Integer; +import java.lang.Object; +import java.lang.Override; +import java.lang.SafeVarargs; +import java.lang.String; +import java.lang.SuppressWarnings; +import java.net.URL; + +/** + * Contains all public methods from {@link RequestBuilder}, all options from + * {@link RequestOptions} and all generated options from + * {@link com.bumptech.glide.annotation.GlideOption} in annotated methods in + * {@link com.bumptech.glide.annotation.GlideExtension} annotated classes. + * + *

Generated code, do not modify. + * + * @see RequestBuilder + * @see RequestOptions + */ +@SuppressWarnings({ + "unused", + "deprecation" +}) +public class GlideRequest extends RequestBuilder implements Cloneable { + GlideRequest(Class transcodeClass, RequestBuilder other) { + super(transcodeClass, other); + } + + GlideRequest(Glide glide, RequestManager requestManager, Class transcodeClass, + Context context) { + super(glide, requestManager ,transcodeClass, context); + } + + @Override + @CheckResult + protected GlideRequest getDownloadOnlyRequest() { + return new GlideRequest<>(File.class, this).apply(DOWNLOAD_ONLY_OPTIONS); + } + + /** + * @see GlideOptions#sizeMultiplier(float) + */ + @CheckResult + public GlideRequest sizeMultiplier(@FloatRange(from = 0.0, to = 1.0) float arg0) { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).sizeMultiplier(arg0); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).sizeMultiplier(arg0); + } + return this; + } + + /** + * @see GlideOptions#useUnlimitedSourceGeneratorsPool(boolean) + */ + @CheckResult + public GlideRequest useUnlimitedSourceGeneratorsPool(boolean flag) { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).useUnlimitedSourceGeneratorsPool(flag); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).useUnlimitedSourceGeneratorsPool(flag); + } + return this; + } + + /** + * @see GlideOptions#useAnimationPool(boolean) + */ + @CheckResult + public GlideRequest useAnimationPool(boolean flag) { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).useAnimationPool(flag); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).useAnimationPool(flag); + } + return this; + } + + /** + * @see GlideOptions#onlyRetrieveFromCache(boolean) + */ + @CheckResult + public GlideRequest onlyRetrieveFromCache(boolean flag) { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).onlyRetrieveFromCache(flag); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).onlyRetrieveFromCache(flag); + } + return this; + } + + /** + * @see GlideOptions#diskCacheStrategy(DiskCacheStrategy) + */ + @CheckResult + public GlideRequest diskCacheStrategy(@NonNull DiskCacheStrategy arg0) { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).diskCacheStrategy(arg0); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).diskCacheStrategy(arg0); + } + return this; + } + + /** + * @see GlideOptions#priority(Priority) + */ + @CheckResult + public GlideRequest priority(@NonNull Priority arg0) { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).priority(arg0); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).priority(arg0); + } + return this; + } + + /** + * @see GlideOptions#placeholder(Drawable) + */ + @CheckResult + public GlideRequest placeholder(@Nullable Drawable arg0) { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).placeholder(arg0); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).placeholder(arg0); + } + return this; + } + + /** + * @see GlideOptions#placeholder(int) + */ + @CheckResult + public GlideRequest placeholder(@DrawableRes int arg0) { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).placeholder(arg0); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).placeholder(arg0); + } + return this; + } + + /** + * @see GlideOptions#fallback(Drawable) + */ + @CheckResult + public GlideRequest fallback(@Nullable Drawable arg0) { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).fallback(arg0); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).fallback(arg0); + } + return this; + } + + /** + * @see GlideOptions#fallback(int) + */ + @CheckResult + public GlideRequest fallback(@DrawableRes int arg0) { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).fallback(arg0); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).fallback(arg0); + } + return this; + } + + /** + * @see GlideOptions#error(Drawable) + */ + @CheckResult + public GlideRequest error(@Nullable Drawable arg0) { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).error(arg0); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).error(arg0); + } + return this; + } + + /** + * @see GlideOptions#error(int) + */ + @CheckResult + public GlideRequest error(@DrawableRes int arg0) { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).error(arg0); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).error(arg0); + } + return this; + } + + /** + * @see GlideOptions#theme(Resources.Theme) + */ + @CheckResult + public GlideRequest theme(@Nullable Resources.Theme arg0) { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).theme(arg0); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).theme(arg0); + } + return this; + } + + /** + * @see GlideOptions#skipMemoryCache(boolean) + */ + @CheckResult + public GlideRequest skipMemoryCache(boolean skip) { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).skipMemoryCache(skip); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).skipMemoryCache(skip); + } + return this; + } + + /** + * @see GlideOptions#override(int, int) + */ + @CheckResult + public GlideRequest override(int width, int height) { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).override(width, height); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).override(width, height); + } + return this; + } + + /** + * @see GlideOptions#override(int) + */ + @CheckResult + public GlideRequest override(int size) { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).override(size); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).override(size); + } + return this; + } + + /** + * @see GlideOptions#signature(Key) + */ + @CheckResult + public GlideRequest signature(@NonNull Key arg0) { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).signature(arg0); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).signature(arg0); + } + return this; + } + + /** + * @see GlideOptions#set(Option, T) + */ + @CheckResult + public GlideRequest set(@NonNull Option arg0, @NonNull T arg1) { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).set(arg0, arg1); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).set(arg0, arg1); + } + return this; + } + + /** + * @see GlideOptions#decode(Class) + */ + @CheckResult + public GlideRequest decode(@NonNull Class arg0) { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).decode(arg0); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).decode(arg0); + } + return this; + } + + /** + * @see GlideOptions#encodeFormat(Bitmap.CompressFormat) + */ + @CheckResult + public GlideRequest encodeFormat(@NonNull Bitmap.CompressFormat arg0) { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).encodeFormat(arg0); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).encodeFormat(arg0); + } + return this; + } + + /** + * @see GlideOptions#encodeQuality(int) + */ + @CheckResult + public GlideRequest encodeQuality(@IntRange(from = 0, to = 100) int arg0) { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).encodeQuality(arg0); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).encodeQuality(arg0); + } + return this; + } + + /** + * @see GlideOptions#frame(long) + */ + @CheckResult + public GlideRequest frame(@IntRange(from = 0) long arg0) { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).frame(arg0); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).frame(arg0); + } + return this; + } + + /** + * @see GlideOptions#format(DecodeFormat) + */ + @CheckResult + public GlideRequest format(@NonNull DecodeFormat arg0) { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).format(arg0); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).format(arg0); + } + return this; + } + + /** + * @see GlideOptions#disallowHardwareConfig() + */ + @CheckResult + public GlideRequest disallowHardwareConfig() { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).disallowHardwareConfig(); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).disallowHardwareConfig(); + } + return this; + } + + /** + * @see GlideOptions#downsample(DownsampleStrategy) + */ + @CheckResult + public GlideRequest downsample(@NonNull DownsampleStrategy arg0) { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).downsample(arg0); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).downsample(arg0); + } + return this; + } + + /** + * @see GlideOptions#timeout(int) + */ + @CheckResult + public GlideRequest timeout(@IntRange(from = 0) int arg0) { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).timeout(arg0); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).timeout(arg0); + } + return this; + } + + /** + * @see GlideOptions#optionalCenterCrop() + */ + @CheckResult + public GlideRequest optionalCenterCrop() { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).optionalCenterCrop(); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).optionalCenterCrop(); + } + return this; + } + + /** + * @see GlideOptions#optionalFitCenter() + */ + @CheckResult + public GlideRequest optionalFitCenter() { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).optionalFitCenter(); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).optionalFitCenter(); + } + return this; + } + + /** + * @see GlideOptions#fitCenter() + */ + @CheckResult + public GlideRequest fitCenter() { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).fitCenter(); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).fitCenter(); + } + return this; + } + + /** + * @see GlideOptions#optionalCenterInside() + */ + @CheckResult + public GlideRequest optionalCenterInside() { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).optionalCenterInside(); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).optionalCenterInside(); + } + return this; + } + + /** + * @see GlideOptions#centerInside() + */ + @CheckResult + public GlideRequest centerInside() { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).centerInside(); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).centerInside(); + } + return this; + } + + /** + * @see GlideOptions#optionalCircleCrop() + */ + @CheckResult + public GlideRequest optionalCircleCrop() { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).optionalCircleCrop(); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).optionalCircleCrop(); + } + return this; + } + + /** + * @see GlideOptions#circleCrop() + */ + @CheckResult + public GlideRequest circleCrop() { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).circleCrop(); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).circleCrop(); + } + return this; + } + + /** + * @see GlideOptions#transform(Transformation) + */ + @CheckResult + public GlideRequest transform(@NonNull Transformation arg0) { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).transform(arg0); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).transform(arg0); + } + return this; + } + + /** + * @see GlideOptions#transforms(Transformation[]) + */ + @CheckResult + @SuppressWarnings({ + "unchecked", + "varargs" + }) + public GlideRequest transforms(@NonNull Transformation... arg0) { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).transforms(arg0); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).transforms(arg0); + } + return this; + } + + /** + * @see GlideOptions#optionalTransform(Transformation) + */ + @CheckResult + public GlideRequest optionalTransform(@NonNull Transformation arg0) { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).optionalTransform(arg0); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).optionalTransform(arg0); + } + return this; + } + + /** + * @see GlideOptions#optionalTransform(Class, Transformation) + */ + @CheckResult + public GlideRequest optionalTransform(@NonNull Class arg0, + @NonNull Transformation arg1) { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).optionalTransform(arg0, arg1); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).optionalTransform(arg0, arg1); + } + return this; + } + + /** + * @see GlideOptions#transform(Class, Transformation) + */ + @CheckResult + public GlideRequest transform(@NonNull Class arg0, + @NonNull Transformation arg1) { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).transform(arg0, arg1); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).transform(arg0, arg1); + } + return this; + } + + /** + * @see GlideOptions#dontTransform() + */ + @CheckResult + public GlideRequest dontTransform() { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).dontTransform(); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).dontTransform(); + } + return this; + } + + /** + * @see GlideOptions#dontAnimate() + */ + @CheckResult + public GlideRequest dontAnimate() { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).dontAnimate(); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).dontAnimate(); + } + return this; + } + + /** + * @see GlideOptions#centerCrop() + */ + @CheckResult + public GlideRequest centerCrop() { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).centerCrop(); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).centerCrop(); + } + return this; + } + + @Override + @CheckResult + public GlideRequest apply(@NonNull RequestOptions arg0) { + return (GlideRequest) super.apply(arg0); + } + + @Override + @CheckResult + public GlideRequest transition(@NonNull TransitionOptions arg0) { + return (GlideRequest) super.transition(arg0); + } + + @Override + @CheckResult + public GlideRequest listener(@Nullable RequestListener arg0) { + return (GlideRequest) super.listener(arg0); + } + + @Override + public GlideRequest error(@Nullable RequestBuilder arg0) { + return (GlideRequest) super.error(arg0); + } + + @Override + @CheckResult + public GlideRequest thumbnail(@Nullable RequestBuilder arg0) { + return (GlideRequest) super.thumbnail(arg0); + } + + @Override + @CheckResult + @SafeVarargs + public final GlideRequest thumbnail(@Nullable RequestBuilder... arg0) { + return (GlideRequest) super.thumbnail(arg0); + } + + @Override + @CheckResult + public GlideRequest thumbnail(float sizeMultiplier) { + return (GlideRequest) super.thumbnail(sizeMultiplier); + } + + @Override + @CheckResult + public GlideRequest load(@Nullable Object arg0) { + return (GlideRequest) super.load(arg0); + } + + @Override + @CheckResult + public GlideRequest load(@Nullable Bitmap arg0) { + return (GlideRequest) super.load(arg0); + } + + @Override + @CheckResult + public GlideRequest load(@Nullable Drawable arg0) { + return (GlideRequest) super.load(arg0); + } + + @Override + @CheckResult + public GlideRequest load(@Nullable String arg0) { + return (GlideRequest) super.load(arg0); + } + + @Override + @CheckResult + public GlideRequest load(@Nullable Uri arg0) { + return (GlideRequest) super.load(arg0); + } + + @Override + @CheckResult + public GlideRequest load(@Nullable File arg0) { + return (GlideRequest) super.load(arg0); + } + + @Override + @CheckResult + public GlideRequest load(@RawRes @DrawableRes @Nullable Integer arg0) { + return (GlideRequest) super.load(arg0); + } + + @Override + @Deprecated + @CheckResult + public GlideRequest load(@Nullable URL arg0) { + return (GlideRequest) super.load(arg0); + } + + @Override + @CheckResult + public GlideRequest load(@Nullable byte[] arg0) { + return (GlideRequest) super.load(arg0); + } + + @Override + @CheckResult + public GlideRequest clone() { + return (GlideRequest) super.clone(); + } +} diff --git a/annotation/compiler/test/src/test/resources/LegacyGlideExtensionOptionsTest/SkipStaticMethod/Extension.java b/annotation/compiler/test/src/test/resources/LegacyGlideExtensionOptionsTest/SkipStaticMethod/Extension.java new file mode 100644 index 0000000000..448a02b747 --- /dev/null +++ b/annotation/compiler/test/src/test/resources/LegacyGlideExtensionOptionsTest/SkipStaticMethod/Extension.java @@ -0,0 +1,18 @@ +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 final class Extension { + + private Extension() { + // Utility class. + } + + @GlideOption(skipStaticMethod = true) + public static void test(RequestOptions requestOptions) { + requestOptions.centerCrop(); + } +} diff --git a/annotation/compiler/test/src/test/resources/LegacyGlideExtensionOptionsTest/SkipStaticMethod/GlideOptions.java b/annotation/compiler/test/src/test/resources/LegacyGlideExtensionOptionsTest/SkipStaticMethod/GlideOptions.java new file mode 100644 index 0000000000..c28a1716ef --- /dev/null +++ b/annotation/compiler/test/src/test/resources/LegacyGlideExtensionOptionsTest/SkipStaticMethod/GlideOptions.java @@ -0,0 +1,560 @@ +package com.bumptech.glide.test; + +import android.content.res.Resources; +import android.graphics.Bitmap; +import android.graphics.drawable.Drawable; +import android.support.annotation.CheckResult; +import android.support.annotation.DrawableRes; +import android.support.annotation.FloatRange; +import android.support.annotation.IntRange; +import android.support.annotation.NonNull; +import android.support.annotation.Nullable; +import com.bumptech.glide.Priority; +import com.bumptech.glide.load.DecodeFormat; +import com.bumptech.glide.load.Key; +import com.bumptech.glide.load.Option; +import com.bumptech.glide.load.Transformation; +import com.bumptech.glide.load.engine.DiskCacheStrategy; +import com.bumptech.glide.load.resource.bitmap.DownsampleStrategy; +import com.bumptech.glide.request.RequestOptions; +import java.lang.Class; +import java.lang.Cloneable; +import java.lang.Override; +import java.lang.SafeVarargs; +import java.lang.SuppressWarnings; + +/** + * Automatically generated from {@link com.bumptech.glide.annotation.GlideExtension} annotated classes. + * + * @see RequestOptions + * @see Extension + */ +@SuppressWarnings("deprecation") +public final class GlideOptions extends RequestOptions implements Cloneable { + private static GlideOptions fitCenterTransform0; + + private static GlideOptions centerInsideTransform1; + + private static GlideOptions centerCropTransform2; + + private static GlideOptions circleCropTransform3; + + private static GlideOptions noTransformation4; + + private static GlideOptions noAnimation5; + + /** + * @see RequestOptions#sizeMultiplierOf(float) + */ + @CheckResult + public static GlideOptions sizeMultiplierOf(@FloatRange(from = 0.0, to = 1.0) float arg0) { + return new GlideOptions().sizeMultiplier(arg0); + } + + /** + * @see RequestOptions#diskCacheStrategyOf(DiskCacheStrategy) + */ + @CheckResult + public static GlideOptions diskCacheStrategyOf(@NonNull DiskCacheStrategy arg0) { + return new GlideOptions().diskCacheStrategy(arg0); + } + + /** + * @see RequestOptions#priorityOf(Priority) + */ + @CheckResult + public static GlideOptions priorityOf(@NonNull Priority arg0) { + return new GlideOptions().priority(arg0); + } + + /** + * @see RequestOptions#placeholderOf(Drawable) + */ + @CheckResult + public static GlideOptions placeholderOf(@Nullable Drawable arg0) { + return new GlideOptions().placeholder(arg0); + } + + /** + * @see RequestOptions#placeholderOf(int) + */ + @CheckResult + public static GlideOptions placeholderOf(@DrawableRes int arg0) { + return new GlideOptions().placeholder(arg0); + } + + /** + * @see RequestOptions#errorOf(Drawable) + */ + @CheckResult + public static GlideOptions errorOf(@Nullable Drawable arg0) { + return new GlideOptions().error(arg0); + } + + /** + * @see RequestOptions#errorOf(int) + */ + @CheckResult + public static GlideOptions errorOf(@DrawableRes int arg0) { + return new GlideOptions().error(arg0); + } + + /** + * @see RequestOptions#skipMemoryCacheOf(boolean) + */ + @CheckResult + public static GlideOptions skipMemoryCacheOf(boolean skipMemoryCache) { + return new GlideOptions().skipMemoryCache(skipMemoryCache); + } + + /** + * @see RequestOptions#overrideOf(int, int) + */ + @CheckResult + public static GlideOptions overrideOf(@IntRange(from = 0) int arg0, + @IntRange(from = 0) int arg1) { + return new GlideOptions().override(arg0, arg1); + } + + /** + * @see RequestOptions#overrideOf(int) + */ + @CheckResult + public static GlideOptions overrideOf(@IntRange(from = 0) int arg0) { + return new GlideOptions().override(arg0); + } + + /** + * @see RequestOptions#signatureOf(Key) + */ + @CheckResult + public static GlideOptions signatureOf(@NonNull Key arg0) { + return new GlideOptions().signature(arg0); + } + + /** + * @see RequestOptions#fitCenterTransform() + */ + @CheckResult + public static GlideOptions fitCenterTransform() { + if (GlideOptions.fitCenterTransform0 == null) { + GlideOptions.fitCenterTransform0 = + new GlideOptions().fitCenter().autoClone(); + } + return GlideOptions.fitCenterTransform0; + } + + /** + * @see RequestOptions#centerInsideTransform() + */ + @CheckResult + public static GlideOptions centerInsideTransform() { + if (GlideOptions.centerInsideTransform1 == null) { + GlideOptions.centerInsideTransform1 = + new GlideOptions().centerInside().autoClone(); + } + return GlideOptions.centerInsideTransform1; + } + + /** + * @see RequestOptions#centerCropTransform() + */ + @CheckResult + public static GlideOptions centerCropTransform() { + if (GlideOptions.centerCropTransform2 == null) { + GlideOptions.centerCropTransform2 = + new GlideOptions().centerCrop().autoClone(); + } + return GlideOptions.centerCropTransform2; + } + + /** + * @see RequestOptions#circleCropTransform() + */ + @CheckResult + public static GlideOptions circleCropTransform() { + if (GlideOptions.circleCropTransform3 == null) { + GlideOptions.circleCropTransform3 = + new GlideOptions().circleCrop().autoClone(); + } + return GlideOptions.circleCropTransform3; + } + + /** + * @see RequestOptions#bitmapTransform(Transformation) + */ + @CheckResult + public static GlideOptions bitmapTransform(@NonNull Transformation arg0) { + return new GlideOptions().transform(arg0); + } + + /** + * @see RequestOptions#noTransformation() + */ + @CheckResult + public static GlideOptions noTransformation() { + if (GlideOptions.noTransformation4 == null) { + GlideOptions.noTransformation4 = + new GlideOptions().dontTransform().autoClone(); + } + return GlideOptions.noTransformation4; + } + + /** + * @see RequestOptions#option(Option, T) + */ + @CheckResult + public static GlideOptions option(@NonNull Option arg0, @NonNull T arg1) { + return new GlideOptions().set(arg0, arg1); + } + + /** + * @see RequestOptions#decodeTypeOf(Class) + */ + @CheckResult + public static GlideOptions decodeTypeOf(@NonNull Class arg0) { + return new GlideOptions().decode(arg0); + } + + /** + * @see RequestOptions#formatOf(DecodeFormat) + */ + @CheckResult + public static GlideOptions formatOf(@NonNull DecodeFormat arg0) { + return new GlideOptions().format(arg0); + } + + /** + * @see RequestOptions#frameOf(long) + */ + @CheckResult + public static GlideOptions frameOf(@IntRange(from = 0) long arg0) { + return new GlideOptions().frame(arg0); + } + + /** + * @see RequestOptions#downsampleOf(DownsampleStrategy) + */ + @CheckResult + public static GlideOptions downsampleOf(@NonNull DownsampleStrategy arg0) { + return new GlideOptions().downsample(arg0); + } + + /** + * @see RequestOptions#timeoutOf(int) + */ + @CheckResult + public static GlideOptions timeoutOf(@IntRange(from = 0) int arg0) { + return new GlideOptions().timeout(arg0); + } + + /** + * @see RequestOptions#encodeQualityOf(int) + */ + @CheckResult + public static GlideOptions encodeQualityOf(@IntRange(from = 0, to = 100) int arg0) { + return new GlideOptions().encodeQuality(arg0); + } + + /** + * @see RequestOptions#encodeFormatOf(CompressFormat) + */ + @CheckResult + public static GlideOptions encodeFormatOf(@NonNull Bitmap.CompressFormat arg0) { + return new GlideOptions().encodeFormat(arg0); + } + + /** + * @see RequestOptions#noAnimation() + */ + @CheckResult + public static GlideOptions noAnimation() { + if (GlideOptions.noAnimation5 == null) { + GlideOptions.noAnimation5 = + new GlideOptions().dontAnimate().autoClone(); + } + return GlideOptions.noAnimation5; + } + + @Override + @CheckResult + public final GlideOptions sizeMultiplier(@FloatRange(from = 0.0, to = 1.0) float arg0) { + return (GlideOptions) super.sizeMultiplier(arg0); + } + + @Override + @CheckResult + public final GlideOptions useUnlimitedSourceGeneratorsPool(boolean flag) { + return (GlideOptions) super.useUnlimitedSourceGeneratorsPool(flag); + } + + @Override + @CheckResult + public final GlideOptions useAnimationPool(boolean flag) { + return (GlideOptions) super.useAnimationPool(flag); + } + + @Override + @CheckResult + public final GlideOptions onlyRetrieveFromCache(boolean flag) { + return (GlideOptions) super.onlyRetrieveFromCache(flag); + } + + @Override + @CheckResult + public final GlideOptions diskCacheStrategy(@NonNull DiskCacheStrategy arg0) { + return (GlideOptions) super.diskCacheStrategy(arg0); + } + + @Override + @CheckResult + public final GlideOptions priority(@NonNull Priority arg0) { + return (GlideOptions) super.priority(arg0); + } + + @Override + @CheckResult + public final GlideOptions placeholder(@Nullable Drawable arg0) { + return (GlideOptions) super.placeholder(arg0); + } + + @Override + @CheckResult + public final GlideOptions placeholder(@DrawableRes int arg0) { + return (GlideOptions) super.placeholder(arg0); + } + + @Override + @CheckResult + public final GlideOptions fallback(@Nullable Drawable arg0) { + return (GlideOptions) super.fallback(arg0); + } + + @Override + @CheckResult + public final GlideOptions fallback(@DrawableRes int arg0) { + return (GlideOptions) super.fallback(arg0); + } + + @Override + @CheckResult + public final GlideOptions error(@Nullable Drawable arg0) { + return (GlideOptions) super.error(arg0); + } + + @Override + @CheckResult + public final GlideOptions error(@DrawableRes int arg0) { + return (GlideOptions) super.error(arg0); + } + + @Override + @CheckResult + public final GlideOptions theme(@Nullable Resources.Theme arg0) { + return (GlideOptions) super.theme(arg0); + } + + @Override + @CheckResult + public final GlideOptions skipMemoryCache(boolean skip) { + return (GlideOptions) super.skipMemoryCache(skip); + } + + @Override + @CheckResult + public final GlideOptions override(int width, int height) { + return (GlideOptions) super.override(width, height); + } + + @Override + @CheckResult + public final GlideOptions override(int size) { + return (GlideOptions) super.override(size); + } + + @Override + @CheckResult + public final GlideOptions signature(@NonNull Key arg0) { + return (GlideOptions) super.signature(arg0); + } + + @Override + @CheckResult + public final GlideOptions clone() { + return (GlideOptions) super.clone(); + } + + @Override + @CheckResult + public final GlideOptions set(@NonNull Option arg0, @NonNull T arg1) { + return (GlideOptions) super.set(arg0, arg1); + } + + @Override + @CheckResult + public final GlideOptions decode(@NonNull Class arg0) { + return (GlideOptions) super.decode(arg0); + } + + @Override + @CheckResult + public final GlideOptions encodeFormat(@NonNull Bitmap.CompressFormat arg0) { + return (GlideOptions) super.encodeFormat(arg0); + } + + @Override + @CheckResult + public final GlideOptions encodeQuality(@IntRange(from = 0, to = 100) int arg0) { + return (GlideOptions) super.encodeQuality(arg0); + } + + @Override + @CheckResult + public final GlideOptions frame(@IntRange(from = 0) long arg0) { + return (GlideOptions) super.frame(arg0); + } + + @Override + @CheckResult + public final GlideOptions format(@NonNull DecodeFormat arg0) { + return (GlideOptions) super.format(arg0); + } + + @Override + @CheckResult + public final GlideOptions disallowHardwareConfig() { + return (GlideOptions) super.disallowHardwareConfig(); + } + + @Override + @CheckResult + public final GlideOptions downsample(@NonNull DownsampleStrategy arg0) { + return (GlideOptions) super.downsample(arg0); + } + + @Override + @CheckResult + public final GlideOptions timeout(@IntRange(from = 0) int arg0) { + return (GlideOptions) super.timeout(arg0); + } + + @Override + @CheckResult + public final GlideOptions optionalCenterCrop() { + return (GlideOptions) super.optionalCenterCrop(); + } + + @Override + @CheckResult + public final GlideOptions centerCrop() { + return (GlideOptions) super.centerCrop(); + } + + @Override + @CheckResult + public final GlideOptions optionalFitCenter() { + return (GlideOptions) super.optionalFitCenter(); + } + + @Override + @CheckResult + public final GlideOptions fitCenter() { + return (GlideOptions) super.fitCenter(); + } + + @Override + @CheckResult + public final GlideOptions optionalCenterInside() { + return (GlideOptions) super.optionalCenterInside(); + } + + @Override + @CheckResult + public final GlideOptions centerInside() { + return (GlideOptions) super.centerInside(); + } + + @Override + @CheckResult + public final GlideOptions optionalCircleCrop() { + return (GlideOptions) super.optionalCircleCrop(); + } + + @Override + @CheckResult + public final GlideOptions circleCrop() { + return (GlideOptions) super.circleCrop(); + } + + @Override + @CheckResult + public final GlideOptions transform(@NonNull Transformation arg0) { + return (GlideOptions) super.transform(arg0); + } + + @Override + @SafeVarargs + @CheckResult + public final GlideOptions transforms(@NonNull Transformation... arg0) { + return (GlideOptions) super.transforms(arg0); + } + + @Override + @CheckResult + public final GlideOptions optionalTransform(@NonNull Transformation arg0) { + return (GlideOptions) super.optionalTransform(arg0); + } + + @Override + @CheckResult + public final GlideOptions optionalTransform(@NonNull Class arg0, + @NonNull Transformation arg1) { + return (GlideOptions) super.optionalTransform(arg0, arg1); + } + + @Override + @CheckResult + public final GlideOptions transform(@NonNull Class arg0, @NonNull Transformation arg1) { + return (GlideOptions) super.transform(arg0, arg1); + } + + @Override + @CheckResult + public final GlideOptions dontTransform() { + return (GlideOptions) super.dontTransform(); + } + + @Override + @CheckResult + public final GlideOptions dontAnimate() { + return (GlideOptions) super.dontAnimate(); + } + + @Override + @CheckResult + public final GlideOptions apply(@NonNull RequestOptions arg0) { + return (GlideOptions) super.apply(arg0); + } + + @Override + public final GlideOptions lock() { + return (GlideOptions) super.lock(); + } + + @Override + public final GlideOptions autoClone() { + return (GlideOptions) super.autoClone(); + } + + /** + * @see Extension#test(RequestOptions) + */ + @CheckResult + public GlideOptions test() { + if (isAutoCloneEnabled()) { + return clone().test(); + } + Extension.test(this); + return this; + } +} diff --git a/annotation/compiler/test/src/test/resources/LegacyGlideExtensionOptionsTest/SkipStaticMethod/GlideRequest.java b/annotation/compiler/test/src/test/resources/LegacyGlideExtensionOptionsTest/SkipStaticMethod/GlideRequest.java new file mode 100644 index 0000000000..323154817f --- /dev/null +++ b/annotation/compiler/test/src/test/resources/LegacyGlideExtensionOptionsTest/SkipStaticMethod/GlideRequest.java @@ -0,0 +1,725 @@ +package com.bumptech.glide.test; + +import android.content.Context; +import android.content.res.Resources; +import android.graphics.Bitmap; +import android.graphics.drawable.Drawable; +import android.net.Uri; +import android.support.annotation.CheckResult; +import android.support.annotation.DrawableRes; +import android.support.annotation.FloatRange; +import android.support.annotation.IntRange; +import android.support.annotation.NonNull; +import android.support.annotation.Nullable; +import android.support.annotation.RawRes; +import com.bumptech.glide.Glide; +import com.bumptech.glide.Priority; +import com.bumptech.glide.RequestBuilder; +import com.bumptech.glide.RequestManager; +import com.bumptech.glide.TransitionOptions; +import com.bumptech.glide.load.DecodeFormat; +import com.bumptech.glide.load.Key; +import com.bumptech.glide.load.Option; +import com.bumptech.glide.load.Transformation; +import com.bumptech.glide.load.engine.DiskCacheStrategy; +import com.bumptech.glide.load.resource.bitmap.DownsampleStrategy; +import com.bumptech.glide.request.RequestListener; +import com.bumptech.glide.request.RequestOptions; +import java.io.File; +import java.lang.Class; +import java.lang.Cloneable; +import java.lang.Deprecated; +import java.lang.Integer; +import java.lang.Object; +import java.lang.Override; +import java.lang.SafeVarargs; +import java.lang.String; +import java.lang.SuppressWarnings; +import java.net.URL; + +/** + * Contains all public methods from {@link RequestBuilder}, all options from + * {@link RequestOptions} and all generated options from + * {@link com.bumptech.glide.annotation.GlideOption} in annotated methods in + * {@link com.bumptech.glide.annotation.GlideExtension} annotated classes. + * + *

Generated code, do not modify. + * + * @see RequestBuilder + * @see RequestOptions + */ +@SuppressWarnings({ + "unused", + "deprecation" +}) +public class GlideRequest extends RequestBuilder implements Cloneable { + GlideRequest(Class transcodeClass, RequestBuilder other) { + super(transcodeClass, other); + } + + GlideRequest(Glide glide, RequestManager requestManager, Class transcodeClass, + Context context) { + super(glide, requestManager ,transcodeClass, context); + } + + @Override + @CheckResult + protected GlideRequest getDownloadOnlyRequest() { + return new GlideRequest<>(File.class, this).apply(DOWNLOAD_ONLY_OPTIONS); + } + + /** + * @see GlideOptions#sizeMultiplier(float) + */ + @CheckResult + public GlideRequest sizeMultiplier(@FloatRange(from = 0.0, to = 1.0) float arg0) { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).sizeMultiplier(arg0); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).sizeMultiplier(arg0); + } + return this; + } + + /** + * @see GlideOptions#useUnlimitedSourceGeneratorsPool(boolean) + */ + @CheckResult + public GlideRequest useUnlimitedSourceGeneratorsPool(boolean flag) { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).useUnlimitedSourceGeneratorsPool(flag); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).useUnlimitedSourceGeneratorsPool(flag); + } + return this; + } + + /** + * @see GlideOptions#useAnimationPool(boolean) + */ + @CheckResult + public GlideRequest useAnimationPool(boolean flag) { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).useAnimationPool(flag); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).useAnimationPool(flag); + } + return this; + } + + /** + * @see GlideOptions#onlyRetrieveFromCache(boolean) + */ + @CheckResult + public GlideRequest onlyRetrieveFromCache(boolean flag) { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).onlyRetrieveFromCache(flag); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).onlyRetrieveFromCache(flag); + } + return this; + } + + /** + * @see GlideOptions#diskCacheStrategy(DiskCacheStrategy) + */ + @CheckResult + public GlideRequest diskCacheStrategy(@NonNull DiskCacheStrategy arg0) { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).diskCacheStrategy(arg0); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).diskCacheStrategy(arg0); + } + return this; + } + + /** + * @see GlideOptions#priority(Priority) + */ + @CheckResult + public GlideRequest priority(@NonNull Priority arg0) { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).priority(arg0); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).priority(arg0); + } + return this; + } + + /** + * @see GlideOptions#placeholder(Drawable) + */ + @CheckResult + public GlideRequest placeholder(@Nullable Drawable arg0) { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).placeholder(arg0); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).placeholder(arg0); + } + return this; + } + + /** + * @see GlideOptions#placeholder(int) + */ + @CheckResult + public GlideRequest placeholder(@DrawableRes int arg0) { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).placeholder(arg0); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).placeholder(arg0); + } + return this; + } + + /** + * @see GlideOptions#fallback(Drawable) + */ + @CheckResult + public GlideRequest fallback(@Nullable Drawable arg0) { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).fallback(arg0); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).fallback(arg0); + } + return this; + } + + /** + * @see GlideOptions#fallback(int) + */ + @CheckResult + public GlideRequest fallback(@DrawableRes int arg0) { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).fallback(arg0); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).fallback(arg0); + } + return this; + } + + /** + * @see GlideOptions#error(Drawable) + */ + @CheckResult + public GlideRequest error(@Nullable Drawable arg0) { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).error(arg0); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).error(arg0); + } + return this; + } + + /** + * @see GlideOptions#error(int) + */ + @CheckResult + public GlideRequest error(@DrawableRes int arg0) { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).error(arg0); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).error(arg0); + } + return this; + } + + /** + * @see GlideOptions#theme(Resources.Theme) + */ + @CheckResult + public GlideRequest theme(@Nullable Resources.Theme arg0) { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).theme(arg0); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).theme(arg0); + } + return this; + } + + /** + * @see GlideOptions#skipMemoryCache(boolean) + */ + @CheckResult + public GlideRequest skipMemoryCache(boolean skip) { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).skipMemoryCache(skip); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).skipMemoryCache(skip); + } + return this; + } + + /** + * @see GlideOptions#override(int, int) + */ + @CheckResult + public GlideRequest override(int width, int height) { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).override(width, height); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).override(width, height); + } + return this; + } + + /** + * @see GlideOptions#override(int) + */ + @CheckResult + public GlideRequest override(int size) { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).override(size); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).override(size); + } + return this; + } + + /** + * @see GlideOptions#signature(Key) + */ + @CheckResult + public GlideRequest signature(@NonNull Key arg0) { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).signature(arg0); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).signature(arg0); + } + return this; + } + + /** + * @see GlideOptions#set(Option, T) + */ + @CheckResult + public GlideRequest set(@NonNull Option arg0, @NonNull T arg1) { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).set(arg0, arg1); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).set(arg0, arg1); + } + return this; + } + + /** + * @see GlideOptions#decode(Class) + */ + @CheckResult + public GlideRequest decode(@NonNull Class arg0) { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).decode(arg0); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).decode(arg0); + } + return this; + } + + /** + * @see GlideOptions#encodeFormat(Bitmap.CompressFormat) + */ + @CheckResult + public GlideRequest encodeFormat(@NonNull Bitmap.CompressFormat arg0) { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).encodeFormat(arg0); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).encodeFormat(arg0); + } + return this; + } + + /** + * @see GlideOptions#encodeQuality(int) + */ + @CheckResult + public GlideRequest encodeQuality(@IntRange(from = 0, to = 100) int arg0) { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).encodeQuality(arg0); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).encodeQuality(arg0); + } + return this; + } + + /** + * @see GlideOptions#frame(long) + */ + @CheckResult + public GlideRequest frame(@IntRange(from = 0) long arg0) { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).frame(arg0); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).frame(arg0); + } + return this; + } + + /** + * @see GlideOptions#format(DecodeFormat) + */ + @CheckResult + public GlideRequest format(@NonNull DecodeFormat arg0) { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).format(arg0); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).format(arg0); + } + return this; + } + + /** + * @see GlideOptions#disallowHardwareConfig() + */ + @CheckResult + public GlideRequest disallowHardwareConfig() { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).disallowHardwareConfig(); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).disallowHardwareConfig(); + } + return this; + } + + /** + * @see GlideOptions#downsample(DownsampleStrategy) + */ + @CheckResult + public GlideRequest downsample(@NonNull DownsampleStrategy arg0) { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).downsample(arg0); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).downsample(arg0); + } + return this; + } + + /** + * @see GlideOptions#timeout(int) + */ + @CheckResult + public GlideRequest timeout(@IntRange(from = 0) int arg0) { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).timeout(arg0); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).timeout(arg0); + } + return this; + } + + /** + * @see GlideOptions#optionalCenterCrop() + */ + @CheckResult + public GlideRequest optionalCenterCrop() { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).optionalCenterCrop(); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).optionalCenterCrop(); + } + return this; + } + + /** + * @see GlideOptions#centerCrop() + */ + @CheckResult + public GlideRequest centerCrop() { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).centerCrop(); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).centerCrop(); + } + return this; + } + + /** + * @see GlideOptions#optionalFitCenter() + */ + @CheckResult + public GlideRequest optionalFitCenter() { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).optionalFitCenter(); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).optionalFitCenter(); + } + return this; + } + + /** + * @see GlideOptions#fitCenter() + */ + @CheckResult + public GlideRequest fitCenter() { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).fitCenter(); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).fitCenter(); + } + return this; + } + + /** + * @see GlideOptions#optionalCenterInside() + */ + @CheckResult + public GlideRequest optionalCenterInside() { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).optionalCenterInside(); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).optionalCenterInside(); + } + return this; + } + + /** + * @see GlideOptions#centerInside() + */ + @CheckResult + public GlideRequest centerInside() { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).centerInside(); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).centerInside(); + } + return this; + } + + /** + * @see GlideOptions#optionalCircleCrop() + */ + @CheckResult + public GlideRequest optionalCircleCrop() { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).optionalCircleCrop(); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).optionalCircleCrop(); + } + return this; + } + + /** + * @see GlideOptions#circleCrop() + */ + @CheckResult + public GlideRequest circleCrop() { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).circleCrop(); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).circleCrop(); + } + return this; + } + + /** + * @see GlideOptions#transform(Transformation) + */ + @CheckResult + public GlideRequest transform(@NonNull Transformation arg0) { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).transform(arg0); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).transform(arg0); + } + return this; + } + + /** + * @see GlideOptions#transforms(Transformation[]) + */ + @CheckResult + @SuppressWarnings({ + "unchecked", + "varargs" + }) + public GlideRequest transforms(@NonNull Transformation... arg0) { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).transforms(arg0); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).transforms(arg0); + } + return this; + } + + /** + * @see GlideOptions#optionalTransform(Transformation) + */ + @CheckResult + public GlideRequest optionalTransform(@NonNull Transformation arg0) { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).optionalTransform(arg0); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).optionalTransform(arg0); + } + return this; + } + + /** + * @see GlideOptions#optionalTransform(Class, Transformation) + */ + @CheckResult + public GlideRequest optionalTransform(@NonNull Class arg0, + @NonNull Transformation arg1) { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).optionalTransform(arg0, arg1); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).optionalTransform(arg0, arg1); + } + return this; + } + + /** + * @see GlideOptions#transform(Class, Transformation) + */ + @CheckResult + public GlideRequest transform(@NonNull Class arg0, + @NonNull Transformation arg1) { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).transform(arg0, arg1); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).transform(arg0, arg1); + } + return this; + } + + /** + * @see GlideOptions#dontTransform() + */ + @CheckResult + public GlideRequest dontTransform() { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).dontTransform(); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).dontTransform(); + } + return this; + } + + /** + * @see GlideOptions#dontAnimate() + */ + @CheckResult + public GlideRequest dontAnimate() { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).dontAnimate(); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).dontAnimate(); + } + return this; + } + + /** + * @see GlideOptions#test() + */ + @CheckResult + public GlideRequest test() { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).test(); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).test(); + } + return this; + } + + @Override + @CheckResult + public GlideRequest apply(@NonNull RequestOptions arg0) { + return (GlideRequest) super.apply(arg0); + } + + @Override + @CheckResult + public GlideRequest transition(@NonNull TransitionOptions arg0) { + return (GlideRequest) super.transition(arg0); + } + + @Override + @CheckResult + public GlideRequest listener(@Nullable RequestListener arg0) { + return (GlideRequest) super.listener(arg0); + } + + @Override + public GlideRequest error(@Nullable RequestBuilder arg0) { + return (GlideRequest) super.error(arg0); + } + + @Override + @CheckResult + public GlideRequest thumbnail(@Nullable RequestBuilder arg0) { + return (GlideRequest) super.thumbnail(arg0); + } + + @Override + @CheckResult + @SafeVarargs + public final GlideRequest thumbnail(@Nullable RequestBuilder... arg0) { + return (GlideRequest) super.thumbnail(arg0); + } + + @Override + @CheckResult + public GlideRequest thumbnail(float sizeMultiplier) { + return (GlideRequest) super.thumbnail(sizeMultiplier); + } + + @Override + @CheckResult + public GlideRequest load(@Nullable Object arg0) { + return (GlideRequest) super.load(arg0); + } + + @Override + @CheckResult + public GlideRequest load(@Nullable Bitmap arg0) { + return (GlideRequest) super.load(arg0); + } + + @Override + @CheckResult + public GlideRequest load(@Nullable Drawable arg0) { + return (GlideRequest) super.load(arg0); + } + + @Override + @CheckResult + public GlideRequest load(@Nullable String arg0) { + return (GlideRequest) super.load(arg0); + } + + @Override + @CheckResult + public GlideRequest load(@Nullable Uri arg0) { + return (GlideRequest) super.load(arg0); + } + + @Override + @CheckResult + public GlideRequest load(@Nullable File arg0) { + return (GlideRequest) super.load(arg0); + } + + @Override + @CheckResult + public GlideRequest load(@RawRes @DrawableRes @Nullable Integer arg0) { + return (GlideRequest) super.load(arg0); + } + + @Override + @Deprecated + @CheckResult + public GlideRequest load(@Nullable URL arg0) { + return (GlideRequest) super.load(arg0); + } + + @Override + @CheckResult + public GlideRequest load(@Nullable byte[] arg0) { + return (GlideRequest) super.load(arg0); + } + + @Override + @CheckResult + public GlideRequest clone() { + return (GlideRequest) super.clone(); + } +} diff --git a/annotation/compiler/test/src/test/resources/LegacyGlideExtensionOptionsTest/StaticMethodName/Extension.java b/annotation/compiler/test/src/test/resources/LegacyGlideExtensionOptionsTest/StaticMethodName/Extension.java new file mode 100644 index 0000000000..b6c72bbad4 --- /dev/null +++ b/annotation/compiler/test/src/test/resources/LegacyGlideExtensionOptionsTest/StaticMethodName/Extension.java @@ -0,0 +1,18 @@ +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 final class Extension { + + private Extension() { + // Utility class. + } + + @GlideOption(staticMethodName = "testSomething") + public static void test(RequestOptions requestOptions) { + requestOptions.centerCrop(); + } +} diff --git a/annotation/compiler/test/src/test/resources/LegacyGlideExtensionOptionsTest/StaticMethodName/GlideOptions.java b/annotation/compiler/test/src/test/resources/LegacyGlideExtensionOptionsTest/StaticMethodName/GlideOptions.java new file mode 100644 index 0000000000..5d3a801444 --- /dev/null +++ b/annotation/compiler/test/src/test/resources/LegacyGlideExtensionOptionsTest/StaticMethodName/GlideOptions.java @@ -0,0 +1,568 @@ +package com.bumptech.glide.test; + +import android.content.res.Resources; +import android.graphics.Bitmap; +import android.graphics.drawable.Drawable; +import android.support.annotation.CheckResult; +import android.support.annotation.DrawableRes; +import android.support.annotation.FloatRange; +import android.support.annotation.IntRange; +import android.support.annotation.NonNull; +import android.support.annotation.Nullable; +import com.bumptech.glide.Priority; +import com.bumptech.glide.load.DecodeFormat; +import com.bumptech.glide.load.Key; +import com.bumptech.glide.load.Option; +import com.bumptech.glide.load.Transformation; +import com.bumptech.glide.load.engine.DiskCacheStrategy; +import com.bumptech.glide.load.resource.bitmap.DownsampleStrategy; +import com.bumptech.glide.request.RequestOptions; +import java.lang.Class; +import java.lang.Cloneable; +import java.lang.Override; +import java.lang.SafeVarargs; +import java.lang.SuppressWarnings; + +/** + * Automatically generated from {@link com.bumptech.glide.annotation.GlideExtension} annotated classes. + * + * @see RequestOptions + * @see Extension + */ +@SuppressWarnings("deprecation") +public final class GlideOptions extends RequestOptions implements Cloneable { + private static GlideOptions fitCenterTransform0; + + private static GlideOptions centerInsideTransform1; + + private static GlideOptions centerCropTransform2; + + private static GlideOptions circleCropTransform3; + + private static GlideOptions noTransformation4; + + private static GlideOptions noAnimation5; + + /** + * @see RequestOptions#sizeMultiplierOf(float) + */ + @CheckResult + public static GlideOptions sizeMultiplierOf(@FloatRange(from = 0.0, to = 1.0) float arg0) { + return new GlideOptions().sizeMultiplier(arg0); + } + + /** + * @see RequestOptions#diskCacheStrategyOf(DiskCacheStrategy) + */ + @CheckResult + public static GlideOptions diskCacheStrategyOf(@NonNull DiskCacheStrategy arg0) { + return new GlideOptions().diskCacheStrategy(arg0); + } + + /** + * @see RequestOptions#priorityOf(Priority) + */ + @CheckResult + public static GlideOptions priorityOf(@NonNull Priority arg0) { + return new GlideOptions().priority(arg0); + } + + /** + * @see RequestOptions#placeholderOf(Drawable) + */ + @CheckResult + public static GlideOptions placeholderOf(@Nullable Drawable arg0) { + return new GlideOptions().placeholder(arg0); + } + + /** + * @see RequestOptions#placeholderOf(int) + */ + @CheckResult + public static GlideOptions placeholderOf(@DrawableRes int arg0) { + return new GlideOptions().placeholder(arg0); + } + + /** + * @see RequestOptions#errorOf(Drawable) + */ + @CheckResult + public static GlideOptions errorOf(@Nullable Drawable arg0) { + return new GlideOptions().error(arg0); + } + + /** + * @see RequestOptions#errorOf(int) + */ + @CheckResult + public static GlideOptions errorOf(@DrawableRes int arg0) { + return new GlideOptions().error(arg0); + } + + /** + * @see RequestOptions#skipMemoryCacheOf(boolean) + */ + @CheckResult + public static GlideOptions skipMemoryCacheOf(boolean skipMemoryCache) { + return new GlideOptions().skipMemoryCache(skipMemoryCache); + } + + /** + * @see RequestOptions#overrideOf(int, int) + */ + @CheckResult + public static GlideOptions overrideOf(@IntRange(from = 0) int arg0, + @IntRange(from = 0) int arg1) { + return new GlideOptions().override(arg0, arg1); + } + + /** + * @see RequestOptions#overrideOf(int) + */ + @CheckResult + public static GlideOptions overrideOf(@IntRange(from = 0) int arg0) { + return new GlideOptions().override(arg0); + } + + /** + * @see RequestOptions#signatureOf(Key) + */ + @CheckResult + public static GlideOptions signatureOf(@NonNull Key arg0) { + return new GlideOptions().signature(arg0); + } + + /** + * @see RequestOptions#fitCenterTransform() + */ + @CheckResult + public static GlideOptions fitCenterTransform() { + if (GlideOptions.fitCenterTransform0 == null) { + GlideOptions.fitCenterTransform0 = + new GlideOptions().fitCenter().autoClone(); + } + return GlideOptions.fitCenterTransform0; + } + + /** + * @see RequestOptions#centerInsideTransform() + */ + @CheckResult + public static GlideOptions centerInsideTransform() { + if (GlideOptions.centerInsideTransform1 == null) { + GlideOptions.centerInsideTransform1 = + new GlideOptions().centerInside().autoClone(); + } + return GlideOptions.centerInsideTransform1; + } + + /** + * @see RequestOptions#centerCropTransform() + */ + @CheckResult + public static GlideOptions centerCropTransform() { + if (GlideOptions.centerCropTransform2 == null) { + GlideOptions.centerCropTransform2 = + new GlideOptions().centerCrop().autoClone(); + } + return GlideOptions.centerCropTransform2; + } + + /** + * @see RequestOptions#circleCropTransform() + */ + @CheckResult + public static GlideOptions circleCropTransform() { + if (GlideOptions.circleCropTransform3 == null) { + GlideOptions.circleCropTransform3 = + new GlideOptions().circleCrop().autoClone(); + } + return GlideOptions.circleCropTransform3; + } + + /** + * @see RequestOptions#bitmapTransform(Transformation) + */ + @CheckResult + public static GlideOptions bitmapTransform(@NonNull Transformation arg0) { + return new GlideOptions().transform(arg0); + } + + /** + * @see RequestOptions#noTransformation() + */ + @CheckResult + public static GlideOptions noTransformation() { + if (GlideOptions.noTransformation4 == null) { + GlideOptions.noTransformation4 = + new GlideOptions().dontTransform().autoClone(); + } + return GlideOptions.noTransformation4; + } + + /** + * @see RequestOptions#option(Option, T) + */ + @CheckResult + public static GlideOptions option(@NonNull Option arg0, @NonNull T arg1) { + return new GlideOptions().set(arg0, arg1); + } + + /** + * @see RequestOptions#decodeTypeOf(Class) + */ + @CheckResult + public static GlideOptions decodeTypeOf(@NonNull Class arg0) { + return new GlideOptions().decode(arg0); + } + + /** + * @see RequestOptions#formatOf(DecodeFormat) + */ + @CheckResult + public static GlideOptions formatOf(@NonNull DecodeFormat arg0) { + return new GlideOptions().format(arg0); + } + + /** + * @see RequestOptions#frameOf(long) + */ + @CheckResult + public static GlideOptions frameOf(@IntRange(from = 0) long arg0) { + return new GlideOptions().frame(arg0); + } + + /** + * @see RequestOptions#downsampleOf(DownsampleStrategy) + */ + @CheckResult + public static GlideOptions downsampleOf(@NonNull DownsampleStrategy arg0) { + return new GlideOptions().downsample(arg0); + } + + /** + * @see RequestOptions#timeoutOf(int) + */ + @CheckResult + public static GlideOptions timeoutOf(@IntRange(from = 0) int arg0) { + return new GlideOptions().timeout(arg0); + } + + /** + * @see RequestOptions#encodeQualityOf(int) + */ + @CheckResult + public static GlideOptions encodeQualityOf(@IntRange(from = 0, to = 100) int arg0) { + return new GlideOptions().encodeQuality(arg0); + } + + /** + * @see RequestOptions#encodeFormatOf(CompressFormat) + */ + @CheckResult + public static GlideOptions encodeFormatOf(@NonNull Bitmap.CompressFormat arg0) { + return new GlideOptions().encodeFormat(arg0); + } + + /** + * @see RequestOptions#noAnimation() + */ + @CheckResult + public static GlideOptions noAnimation() { + if (GlideOptions.noAnimation5 == null) { + GlideOptions.noAnimation5 = + new GlideOptions().dontAnimate().autoClone(); + } + return GlideOptions.noAnimation5; + } + + @Override + @CheckResult + public final GlideOptions sizeMultiplier(@FloatRange(from = 0.0, to = 1.0) float arg0) { + return (GlideOptions) super.sizeMultiplier(arg0); + } + + @Override + @CheckResult + public final GlideOptions useUnlimitedSourceGeneratorsPool(boolean flag) { + return (GlideOptions) super.useUnlimitedSourceGeneratorsPool(flag); + } + + @Override + @CheckResult + public final GlideOptions useAnimationPool(boolean flag) { + return (GlideOptions) super.useAnimationPool(flag); + } + + @Override + @CheckResult + public final GlideOptions onlyRetrieveFromCache(boolean flag) { + return (GlideOptions) super.onlyRetrieveFromCache(flag); + } + + @Override + @CheckResult + public final GlideOptions diskCacheStrategy(@NonNull DiskCacheStrategy arg0) { + return (GlideOptions) super.diskCacheStrategy(arg0); + } + + @Override + @CheckResult + public final GlideOptions priority(@NonNull Priority arg0) { + return (GlideOptions) super.priority(arg0); + } + + @Override + @CheckResult + public final GlideOptions placeholder(@Nullable Drawable arg0) { + return (GlideOptions) super.placeholder(arg0); + } + + @Override + @CheckResult + public final GlideOptions placeholder(@DrawableRes int arg0) { + return (GlideOptions) super.placeholder(arg0); + } + + @Override + @CheckResult + public final GlideOptions fallback(@Nullable Drawable arg0) { + return (GlideOptions) super.fallback(arg0); + } + + @Override + @CheckResult + public final GlideOptions fallback(@DrawableRes int arg0) { + return (GlideOptions) super.fallback(arg0); + } + + @Override + @CheckResult + public final GlideOptions error(@Nullable Drawable arg0) { + return (GlideOptions) super.error(arg0); + } + + @Override + @CheckResult + public final GlideOptions error(@DrawableRes int arg0) { + return (GlideOptions) super.error(arg0); + } + + @Override + @CheckResult + public final GlideOptions theme(@Nullable Resources.Theme arg0) { + return (GlideOptions) super.theme(arg0); + } + + @Override + @CheckResult + public final GlideOptions skipMemoryCache(boolean skip) { + return (GlideOptions) super.skipMemoryCache(skip); + } + + @Override + @CheckResult + public final GlideOptions override(int width, int height) { + return (GlideOptions) super.override(width, height); + } + + @Override + @CheckResult + public final GlideOptions override(int size) { + return (GlideOptions) super.override(size); + } + + @Override + @CheckResult + public final GlideOptions signature(@NonNull Key arg0) { + return (GlideOptions) super.signature(arg0); + } + + @Override + @CheckResult + public final GlideOptions clone() { + return (GlideOptions) super.clone(); + } + + @Override + @CheckResult + public final GlideOptions set(@NonNull Option arg0, @NonNull T arg1) { + return (GlideOptions) super.set(arg0, arg1); + } + + @Override + @CheckResult + public final GlideOptions decode(@NonNull Class arg0) { + return (GlideOptions) super.decode(arg0); + } + + @Override + @CheckResult + public final GlideOptions encodeFormat(@NonNull Bitmap.CompressFormat arg0) { + return (GlideOptions) super.encodeFormat(arg0); + } + + @Override + @CheckResult + public final GlideOptions encodeQuality(@IntRange(from = 0, to = 100) int arg0) { + return (GlideOptions) super.encodeQuality(arg0); + } + + @Override + @CheckResult + public final GlideOptions frame(@IntRange(from = 0) long arg0) { + return (GlideOptions) super.frame(arg0); + } + + @Override + @CheckResult + public final GlideOptions format(@NonNull DecodeFormat arg0) { + return (GlideOptions) super.format(arg0); + } + + @Override + @CheckResult + public final GlideOptions disallowHardwareConfig() { + return (GlideOptions) super.disallowHardwareConfig(); + } + + @Override + @CheckResult + public final GlideOptions downsample(@NonNull DownsampleStrategy arg0) { + return (GlideOptions) super.downsample(arg0); + } + + @Override + @CheckResult + public final GlideOptions timeout(@IntRange(from = 0) int arg0) { + return (GlideOptions) super.timeout(arg0); + } + + @Override + @CheckResult + public final GlideOptions optionalCenterCrop() { + return (GlideOptions) super.optionalCenterCrop(); + } + + @Override + @CheckResult + public final GlideOptions centerCrop() { + return (GlideOptions) super.centerCrop(); + } + + @Override + @CheckResult + public final GlideOptions optionalFitCenter() { + return (GlideOptions) super.optionalFitCenter(); + } + + @Override + @CheckResult + public final GlideOptions fitCenter() { + return (GlideOptions) super.fitCenter(); + } + + @Override + @CheckResult + public final GlideOptions optionalCenterInside() { + return (GlideOptions) super.optionalCenterInside(); + } + + @Override + @CheckResult + public final GlideOptions centerInside() { + return (GlideOptions) super.centerInside(); + } + + @Override + @CheckResult + public final GlideOptions optionalCircleCrop() { + return (GlideOptions) super.optionalCircleCrop(); + } + + @Override + @CheckResult + public final GlideOptions circleCrop() { + return (GlideOptions) super.circleCrop(); + } + + @Override + @CheckResult + public final GlideOptions transform(@NonNull Transformation arg0) { + return (GlideOptions) super.transform(arg0); + } + + @Override + @SafeVarargs + @CheckResult + public final GlideOptions transforms(@NonNull Transformation... arg0) { + return (GlideOptions) super.transforms(arg0); + } + + @Override + @CheckResult + public final GlideOptions optionalTransform(@NonNull Transformation arg0) { + return (GlideOptions) super.optionalTransform(arg0); + } + + @Override + @CheckResult + public final GlideOptions optionalTransform(@NonNull Class arg0, + @NonNull Transformation arg1) { + return (GlideOptions) super.optionalTransform(arg0, arg1); + } + + @Override + @CheckResult + public final GlideOptions transform(@NonNull Class arg0, @NonNull Transformation arg1) { + return (GlideOptions) super.transform(arg0, arg1); + } + + @Override + @CheckResult + public final GlideOptions dontTransform() { + return (GlideOptions) super.dontTransform(); + } + + @Override + @CheckResult + public final GlideOptions dontAnimate() { + return (GlideOptions) super.dontAnimate(); + } + + @Override + @CheckResult + public final GlideOptions apply(@NonNull RequestOptions arg0) { + return (GlideOptions) super.apply(arg0); + } + + @Override + public final GlideOptions lock() { + return (GlideOptions) super.lock(); + } + + @Override + public final GlideOptions autoClone() { + return (GlideOptions) super.autoClone(); + } + + /** + * @see Extension#test(RequestOptions) + */ + @CheckResult + public GlideOptions test() { + if (isAutoCloneEnabled()) { + return clone().test(); + } + Extension.test(this); + return this; + } + + /** + * @see Extension#test(RequestOptions) + */ + @CheckResult + public static GlideOptions testSomething() { + return new GlideOptions().test(); + } +} diff --git a/annotation/compiler/test/src/test/resources/LegacyGlideExtensionOptionsTest/StaticMethodName/GlideRequest.java b/annotation/compiler/test/src/test/resources/LegacyGlideExtensionOptionsTest/StaticMethodName/GlideRequest.java new file mode 100644 index 0000000000..323154817f --- /dev/null +++ b/annotation/compiler/test/src/test/resources/LegacyGlideExtensionOptionsTest/StaticMethodName/GlideRequest.java @@ -0,0 +1,725 @@ +package com.bumptech.glide.test; + +import android.content.Context; +import android.content.res.Resources; +import android.graphics.Bitmap; +import android.graphics.drawable.Drawable; +import android.net.Uri; +import android.support.annotation.CheckResult; +import android.support.annotation.DrawableRes; +import android.support.annotation.FloatRange; +import android.support.annotation.IntRange; +import android.support.annotation.NonNull; +import android.support.annotation.Nullable; +import android.support.annotation.RawRes; +import com.bumptech.glide.Glide; +import com.bumptech.glide.Priority; +import com.bumptech.glide.RequestBuilder; +import com.bumptech.glide.RequestManager; +import com.bumptech.glide.TransitionOptions; +import com.bumptech.glide.load.DecodeFormat; +import com.bumptech.glide.load.Key; +import com.bumptech.glide.load.Option; +import com.bumptech.glide.load.Transformation; +import com.bumptech.glide.load.engine.DiskCacheStrategy; +import com.bumptech.glide.load.resource.bitmap.DownsampleStrategy; +import com.bumptech.glide.request.RequestListener; +import com.bumptech.glide.request.RequestOptions; +import java.io.File; +import java.lang.Class; +import java.lang.Cloneable; +import java.lang.Deprecated; +import java.lang.Integer; +import java.lang.Object; +import java.lang.Override; +import java.lang.SafeVarargs; +import java.lang.String; +import java.lang.SuppressWarnings; +import java.net.URL; + +/** + * Contains all public methods from {@link RequestBuilder}, all options from + * {@link RequestOptions} and all generated options from + * {@link com.bumptech.glide.annotation.GlideOption} in annotated methods in + * {@link com.bumptech.glide.annotation.GlideExtension} annotated classes. + * + *

Generated code, do not modify. + * + * @see RequestBuilder + * @see RequestOptions + */ +@SuppressWarnings({ + "unused", + "deprecation" +}) +public class GlideRequest extends RequestBuilder implements Cloneable { + GlideRequest(Class transcodeClass, RequestBuilder other) { + super(transcodeClass, other); + } + + GlideRequest(Glide glide, RequestManager requestManager, Class transcodeClass, + Context context) { + super(glide, requestManager ,transcodeClass, context); + } + + @Override + @CheckResult + protected GlideRequest getDownloadOnlyRequest() { + return new GlideRequest<>(File.class, this).apply(DOWNLOAD_ONLY_OPTIONS); + } + + /** + * @see GlideOptions#sizeMultiplier(float) + */ + @CheckResult + public GlideRequest sizeMultiplier(@FloatRange(from = 0.0, to = 1.0) float arg0) { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).sizeMultiplier(arg0); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).sizeMultiplier(arg0); + } + return this; + } + + /** + * @see GlideOptions#useUnlimitedSourceGeneratorsPool(boolean) + */ + @CheckResult + public GlideRequest useUnlimitedSourceGeneratorsPool(boolean flag) { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).useUnlimitedSourceGeneratorsPool(flag); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).useUnlimitedSourceGeneratorsPool(flag); + } + return this; + } + + /** + * @see GlideOptions#useAnimationPool(boolean) + */ + @CheckResult + public GlideRequest useAnimationPool(boolean flag) { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).useAnimationPool(flag); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).useAnimationPool(flag); + } + return this; + } + + /** + * @see GlideOptions#onlyRetrieveFromCache(boolean) + */ + @CheckResult + public GlideRequest onlyRetrieveFromCache(boolean flag) { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).onlyRetrieveFromCache(flag); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).onlyRetrieveFromCache(flag); + } + return this; + } + + /** + * @see GlideOptions#diskCacheStrategy(DiskCacheStrategy) + */ + @CheckResult + public GlideRequest diskCacheStrategy(@NonNull DiskCacheStrategy arg0) { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).diskCacheStrategy(arg0); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).diskCacheStrategy(arg0); + } + return this; + } + + /** + * @see GlideOptions#priority(Priority) + */ + @CheckResult + public GlideRequest priority(@NonNull Priority arg0) { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).priority(arg0); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).priority(arg0); + } + return this; + } + + /** + * @see GlideOptions#placeholder(Drawable) + */ + @CheckResult + public GlideRequest placeholder(@Nullable Drawable arg0) { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).placeholder(arg0); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).placeholder(arg0); + } + return this; + } + + /** + * @see GlideOptions#placeholder(int) + */ + @CheckResult + public GlideRequest placeholder(@DrawableRes int arg0) { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).placeholder(arg0); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).placeholder(arg0); + } + return this; + } + + /** + * @see GlideOptions#fallback(Drawable) + */ + @CheckResult + public GlideRequest fallback(@Nullable Drawable arg0) { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).fallback(arg0); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).fallback(arg0); + } + return this; + } + + /** + * @see GlideOptions#fallback(int) + */ + @CheckResult + public GlideRequest fallback(@DrawableRes int arg0) { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).fallback(arg0); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).fallback(arg0); + } + return this; + } + + /** + * @see GlideOptions#error(Drawable) + */ + @CheckResult + public GlideRequest error(@Nullable Drawable arg0) { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).error(arg0); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).error(arg0); + } + return this; + } + + /** + * @see GlideOptions#error(int) + */ + @CheckResult + public GlideRequest error(@DrawableRes int arg0) { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).error(arg0); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).error(arg0); + } + return this; + } + + /** + * @see GlideOptions#theme(Resources.Theme) + */ + @CheckResult + public GlideRequest theme(@Nullable Resources.Theme arg0) { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).theme(arg0); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).theme(arg0); + } + return this; + } + + /** + * @see GlideOptions#skipMemoryCache(boolean) + */ + @CheckResult + public GlideRequest skipMemoryCache(boolean skip) { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).skipMemoryCache(skip); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).skipMemoryCache(skip); + } + return this; + } + + /** + * @see GlideOptions#override(int, int) + */ + @CheckResult + public GlideRequest override(int width, int height) { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).override(width, height); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).override(width, height); + } + return this; + } + + /** + * @see GlideOptions#override(int) + */ + @CheckResult + public GlideRequest override(int size) { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).override(size); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).override(size); + } + return this; + } + + /** + * @see GlideOptions#signature(Key) + */ + @CheckResult + public GlideRequest signature(@NonNull Key arg0) { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).signature(arg0); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).signature(arg0); + } + return this; + } + + /** + * @see GlideOptions#set(Option, T) + */ + @CheckResult + public GlideRequest set(@NonNull Option arg0, @NonNull T arg1) { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).set(arg0, arg1); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).set(arg0, arg1); + } + return this; + } + + /** + * @see GlideOptions#decode(Class) + */ + @CheckResult + public GlideRequest decode(@NonNull Class arg0) { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).decode(arg0); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).decode(arg0); + } + return this; + } + + /** + * @see GlideOptions#encodeFormat(Bitmap.CompressFormat) + */ + @CheckResult + public GlideRequest encodeFormat(@NonNull Bitmap.CompressFormat arg0) { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).encodeFormat(arg0); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).encodeFormat(arg0); + } + return this; + } + + /** + * @see GlideOptions#encodeQuality(int) + */ + @CheckResult + public GlideRequest encodeQuality(@IntRange(from = 0, to = 100) int arg0) { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).encodeQuality(arg0); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).encodeQuality(arg0); + } + return this; + } + + /** + * @see GlideOptions#frame(long) + */ + @CheckResult + public GlideRequest frame(@IntRange(from = 0) long arg0) { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).frame(arg0); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).frame(arg0); + } + return this; + } + + /** + * @see GlideOptions#format(DecodeFormat) + */ + @CheckResult + public GlideRequest format(@NonNull DecodeFormat arg0) { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).format(arg0); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).format(arg0); + } + return this; + } + + /** + * @see GlideOptions#disallowHardwareConfig() + */ + @CheckResult + public GlideRequest disallowHardwareConfig() { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).disallowHardwareConfig(); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).disallowHardwareConfig(); + } + return this; + } + + /** + * @see GlideOptions#downsample(DownsampleStrategy) + */ + @CheckResult + public GlideRequest downsample(@NonNull DownsampleStrategy arg0) { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).downsample(arg0); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).downsample(arg0); + } + return this; + } + + /** + * @see GlideOptions#timeout(int) + */ + @CheckResult + public GlideRequest timeout(@IntRange(from = 0) int arg0) { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).timeout(arg0); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).timeout(arg0); + } + return this; + } + + /** + * @see GlideOptions#optionalCenterCrop() + */ + @CheckResult + public GlideRequest optionalCenterCrop() { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).optionalCenterCrop(); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).optionalCenterCrop(); + } + return this; + } + + /** + * @see GlideOptions#centerCrop() + */ + @CheckResult + public GlideRequest centerCrop() { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).centerCrop(); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).centerCrop(); + } + return this; + } + + /** + * @see GlideOptions#optionalFitCenter() + */ + @CheckResult + public GlideRequest optionalFitCenter() { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).optionalFitCenter(); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).optionalFitCenter(); + } + return this; + } + + /** + * @see GlideOptions#fitCenter() + */ + @CheckResult + public GlideRequest fitCenter() { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).fitCenter(); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).fitCenter(); + } + return this; + } + + /** + * @see GlideOptions#optionalCenterInside() + */ + @CheckResult + public GlideRequest optionalCenterInside() { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).optionalCenterInside(); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).optionalCenterInside(); + } + return this; + } + + /** + * @see GlideOptions#centerInside() + */ + @CheckResult + public GlideRequest centerInside() { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).centerInside(); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).centerInside(); + } + return this; + } + + /** + * @see GlideOptions#optionalCircleCrop() + */ + @CheckResult + public GlideRequest optionalCircleCrop() { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).optionalCircleCrop(); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).optionalCircleCrop(); + } + return this; + } + + /** + * @see GlideOptions#circleCrop() + */ + @CheckResult + public GlideRequest circleCrop() { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).circleCrop(); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).circleCrop(); + } + return this; + } + + /** + * @see GlideOptions#transform(Transformation) + */ + @CheckResult + public GlideRequest transform(@NonNull Transformation arg0) { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).transform(arg0); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).transform(arg0); + } + return this; + } + + /** + * @see GlideOptions#transforms(Transformation[]) + */ + @CheckResult + @SuppressWarnings({ + "unchecked", + "varargs" + }) + public GlideRequest transforms(@NonNull Transformation... arg0) { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).transforms(arg0); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).transforms(arg0); + } + return this; + } + + /** + * @see GlideOptions#optionalTransform(Transformation) + */ + @CheckResult + public GlideRequest optionalTransform(@NonNull Transformation arg0) { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).optionalTransform(arg0); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).optionalTransform(arg0); + } + return this; + } + + /** + * @see GlideOptions#optionalTransform(Class, Transformation) + */ + @CheckResult + public GlideRequest optionalTransform(@NonNull Class arg0, + @NonNull Transformation arg1) { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).optionalTransform(arg0, arg1); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).optionalTransform(arg0, arg1); + } + return this; + } + + /** + * @see GlideOptions#transform(Class, Transformation) + */ + @CheckResult + public GlideRequest transform(@NonNull Class arg0, + @NonNull Transformation arg1) { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).transform(arg0, arg1); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).transform(arg0, arg1); + } + return this; + } + + /** + * @see GlideOptions#dontTransform() + */ + @CheckResult + public GlideRequest dontTransform() { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).dontTransform(); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).dontTransform(); + } + return this; + } + + /** + * @see GlideOptions#dontAnimate() + */ + @CheckResult + public GlideRequest dontAnimate() { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).dontAnimate(); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).dontAnimate(); + } + return this; + } + + /** + * @see GlideOptions#test() + */ + @CheckResult + public GlideRequest test() { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).test(); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).test(); + } + return this; + } + + @Override + @CheckResult + public GlideRequest apply(@NonNull RequestOptions arg0) { + return (GlideRequest) super.apply(arg0); + } + + @Override + @CheckResult + public GlideRequest transition(@NonNull TransitionOptions arg0) { + return (GlideRequest) super.transition(arg0); + } + + @Override + @CheckResult + public GlideRequest listener(@Nullable RequestListener arg0) { + return (GlideRequest) super.listener(arg0); + } + + @Override + public GlideRequest error(@Nullable RequestBuilder arg0) { + return (GlideRequest) super.error(arg0); + } + + @Override + @CheckResult + public GlideRequest thumbnail(@Nullable RequestBuilder arg0) { + return (GlideRequest) super.thumbnail(arg0); + } + + @Override + @CheckResult + @SafeVarargs + public final GlideRequest thumbnail(@Nullable RequestBuilder... arg0) { + return (GlideRequest) super.thumbnail(arg0); + } + + @Override + @CheckResult + public GlideRequest thumbnail(float sizeMultiplier) { + return (GlideRequest) super.thumbnail(sizeMultiplier); + } + + @Override + @CheckResult + public GlideRequest load(@Nullable Object arg0) { + return (GlideRequest) super.load(arg0); + } + + @Override + @CheckResult + public GlideRequest load(@Nullable Bitmap arg0) { + return (GlideRequest) super.load(arg0); + } + + @Override + @CheckResult + public GlideRequest load(@Nullable Drawable arg0) { + return (GlideRequest) super.load(arg0); + } + + @Override + @CheckResult + public GlideRequest load(@Nullable String arg0) { + return (GlideRequest) super.load(arg0); + } + + @Override + @CheckResult + public GlideRequest load(@Nullable Uri arg0) { + return (GlideRequest) super.load(arg0); + } + + @Override + @CheckResult + public GlideRequest load(@Nullable File arg0) { + return (GlideRequest) super.load(arg0); + } + + @Override + @CheckResult + public GlideRequest load(@RawRes @DrawableRes @Nullable Integer arg0) { + return (GlideRequest) super.load(arg0); + } + + @Override + @Deprecated + @CheckResult + public GlideRequest load(@Nullable URL arg0) { + return (GlideRequest) super.load(arg0); + } + + @Override + @CheckResult + public GlideRequest load(@Nullable byte[] arg0) { + return (GlideRequest) super.load(arg0); + } + + @Override + @CheckResult + public GlideRequest clone() { + return (GlideRequest) super.clone(); + } +} diff --git a/annotation/compiler/test/src/test/resources/LegacyGlideExtensionWithOptionTest/ExtensionWithOption.java b/annotation/compiler/test/src/test/resources/LegacyGlideExtensionWithOptionTest/ExtensionWithOption.java new file mode 100644 index 0000000000..b67065d437 --- /dev/null +++ b/annotation/compiler/test/src/test/resources/LegacyGlideExtensionWithOptionTest/ExtensionWithOption.java @@ -0,0 +1,18 @@ +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 final class ExtensionWithOption { + + private ExtensionWithOption() { + // Utility class. + } + + @GlideOption + public static void squareThumb(RequestOptions requestOptions) { + requestOptions.centerCrop(); + } +} diff --git a/annotation/compiler/test/src/test/resources/LegacyGlideExtensionWithOptionTest/GlideOptions.java b/annotation/compiler/test/src/test/resources/LegacyGlideExtensionWithOptionTest/GlideOptions.java new file mode 100644 index 0000000000..9f96d3b806 --- /dev/null +++ b/annotation/compiler/test/src/test/resources/LegacyGlideExtensionWithOptionTest/GlideOptions.java @@ -0,0 +1,568 @@ +package com.bumptech.glide.test; + +import android.content.res.Resources; +import android.graphics.Bitmap; +import android.graphics.drawable.Drawable; +import android.support.annotation.CheckResult; +import android.support.annotation.DrawableRes; +import android.support.annotation.FloatRange; +import android.support.annotation.IntRange; +import android.support.annotation.NonNull; +import android.support.annotation.Nullable; +import com.bumptech.glide.Priority; +import com.bumptech.glide.load.DecodeFormat; +import com.bumptech.glide.load.Key; +import com.bumptech.glide.load.Option; +import com.bumptech.glide.load.Transformation; +import com.bumptech.glide.load.engine.DiskCacheStrategy; +import com.bumptech.glide.load.resource.bitmap.DownsampleStrategy; +import com.bumptech.glide.request.RequestOptions; +import java.lang.Class; +import java.lang.Cloneable; +import java.lang.Override; +import java.lang.SafeVarargs; +import java.lang.SuppressWarnings; + +/** + * Automatically generated from {@link com.bumptech.glide.annotation.GlideExtension} annotated classes. + * + * @see RequestOptions + * @see ExtensionWithOption + */ +@SuppressWarnings("deprecation") +public final class GlideOptions extends RequestOptions implements Cloneable { + private static GlideOptions fitCenterTransform0; + + private static GlideOptions centerInsideTransform1; + + private static GlideOptions centerCropTransform2; + + private static GlideOptions circleCropTransform3; + + private static GlideOptions noTransformation4; + + private static GlideOptions noAnimation5; + + /** + * @see RequestOptions#sizeMultiplierOf(float) + */ + @CheckResult + public static GlideOptions sizeMultiplierOf(@FloatRange(from = 0.0, to = 1.0) float arg0) { + return new GlideOptions().sizeMultiplier(arg0); + } + + /** + * @see RequestOptions#diskCacheStrategyOf(DiskCacheStrategy) + */ + @CheckResult + public static GlideOptions diskCacheStrategyOf(@NonNull DiskCacheStrategy arg0) { + return new GlideOptions().diskCacheStrategy(arg0); + } + + /** + * @see RequestOptions#priorityOf(Priority) + */ + @CheckResult + public static GlideOptions priorityOf(@NonNull Priority arg0) { + return new GlideOptions().priority(arg0); + } + + /** + * @see RequestOptions#placeholderOf(Drawable) + */ + @CheckResult + public static GlideOptions placeholderOf(@Nullable Drawable arg0) { + return new GlideOptions().placeholder(arg0); + } + + /** + * @see RequestOptions#placeholderOf(int) + */ + @CheckResult + public static GlideOptions placeholderOf(@DrawableRes int arg0) { + return new GlideOptions().placeholder(arg0); + } + + /** + * @see RequestOptions#errorOf(Drawable) + */ + @CheckResult + public static GlideOptions errorOf(@Nullable Drawable arg0) { + return new GlideOptions().error(arg0); + } + + /** + * @see RequestOptions#errorOf(int) + */ + @CheckResult + public static GlideOptions errorOf(@DrawableRes int arg0) { + return new GlideOptions().error(arg0); + } + + /** + * @see RequestOptions#skipMemoryCacheOf(boolean) + */ + @CheckResult + public static GlideOptions skipMemoryCacheOf(boolean skipMemoryCache) { + return new GlideOptions().skipMemoryCache(skipMemoryCache); + } + + /** + * @see RequestOptions#overrideOf(int, int) + */ + @CheckResult + public static GlideOptions overrideOf(@IntRange(from = 0) int arg0, + @IntRange(from = 0) int arg1) { + return new GlideOptions().override(arg0, arg1); + } + + /** + * @see RequestOptions#overrideOf(int) + */ + @CheckResult + public static GlideOptions overrideOf(@IntRange(from = 0) int arg0) { + return new GlideOptions().override(arg0); + } + + /** + * @see RequestOptions#signatureOf(Key) + */ + @CheckResult + public static GlideOptions signatureOf(@NonNull Key arg0) { + return new GlideOptions().signature(arg0); + } + + /** + * @see RequestOptions#fitCenterTransform() + */ + @CheckResult + public static GlideOptions fitCenterTransform() { + if (GlideOptions.fitCenterTransform0 == null) { + GlideOptions.fitCenterTransform0 = + new GlideOptions().fitCenter().autoClone(); + } + return GlideOptions.fitCenterTransform0; + } + + /** + * @see RequestOptions#centerInsideTransform() + */ + @CheckResult + public static GlideOptions centerInsideTransform() { + if (GlideOptions.centerInsideTransform1 == null) { + GlideOptions.centerInsideTransform1 = + new GlideOptions().centerInside().autoClone(); + } + return GlideOptions.centerInsideTransform1; + } + + /** + * @see RequestOptions#centerCropTransform() + */ + @CheckResult + public static GlideOptions centerCropTransform() { + if (GlideOptions.centerCropTransform2 == null) { + GlideOptions.centerCropTransform2 = + new GlideOptions().centerCrop().autoClone(); + } + return GlideOptions.centerCropTransform2; + } + + /** + * @see RequestOptions#circleCropTransform() + */ + @CheckResult + public static GlideOptions circleCropTransform() { + if (GlideOptions.circleCropTransform3 == null) { + GlideOptions.circleCropTransform3 = + new GlideOptions().circleCrop().autoClone(); + } + return GlideOptions.circleCropTransform3; + } + + /** + * @see RequestOptions#bitmapTransform(Transformation) + */ + @CheckResult + public static GlideOptions bitmapTransform(@NonNull Transformation arg0) { + return new GlideOptions().transform(arg0); + } + + /** + * @see RequestOptions#noTransformation() + */ + @CheckResult + public static GlideOptions noTransformation() { + if (GlideOptions.noTransformation4 == null) { + GlideOptions.noTransformation4 = + new GlideOptions().dontTransform().autoClone(); + } + return GlideOptions.noTransformation4; + } + + /** + * @see RequestOptions#option(Option, T) + */ + @CheckResult + public static GlideOptions option(@NonNull Option arg0, @NonNull T arg1) { + return new GlideOptions().set(arg0, arg1); + } + + /** + * @see RequestOptions#decodeTypeOf(Class) + */ + @CheckResult + public static GlideOptions decodeTypeOf(@NonNull Class arg0) { + return new GlideOptions().decode(arg0); + } + + /** + * @see RequestOptions#formatOf(DecodeFormat) + */ + @CheckResult + public static GlideOptions formatOf(@NonNull DecodeFormat arg0) { + return new GlideOptions().format(arg0); + } + + /** + * @see RequestOptions#frameOf(long) + */ + @CheckResult + public static GlideOptions frameOf(@IntRange(from = 0) long arg0) { + return new GlideOptions().frame(arg0); + } + + /** + * @see RequestOptions#downsampleOf(DownsampleStrategy) + */ + @CheckResult + public static GlideOptions downsampleOf(@NonNull DownsampleStrategy arg0) { + return new GlideOptions().downsample(arg0); + } + + /** + * @see RequestOptions#timeoutOf(int) + */ + @CheckResult + public static GlideOptions timeoutOf(@IntRange(from = 0) int arg0) { + return new GlideOptions().timeout(arg0); + } + + /** + * @see RequestOptions#encodeQualityOf(int) + */ + @CheckResult + public static GlideOptions encodeQualityOf(@IntRange(from = 0, to = 100) int arg0) { + return new GlideOptions().encodeQuality(arg0); + } + + /** + * @see RequestOptions#encodeFormatOf(CompressFormat) + */ + @CheckResult + public static GlideOptions encodeFormatOf(@NonNull Bitmap.CompressFormat arg0) { + return new GlideOptions().encodeFormat(arg0); + } + + /** + * @see RequestOptions#noAnimation() + */ + @CheckResult + public static GlideOptions noAnimation() { + if (GlideOptions.noAnimation5 == null) { + GlideOptions.noAnimation5 = + new GlideOptions().dontAnimate().autoClone(); + } + return GlideOptions.noAnimation5; + } + + @Override + @CheckResult + public final GlideOptions sizeMultiplier(@FloatRange(from = 0.0, to = 1.0) float arg0) { + return (GlideOptions) super.sizeMultiplier(arg0); + } + + @Override + @CheckResult + public final GlideOptions useUnlimitedSourceGeneratorsPool(boolean flag) { + return (GlideOptions) super.useUnlimitedSourceGeneratorsPool(flag); + } + + @Override + @CheckResult + public final GlideOptions useAnimationPool(boolean flag) { + return (GlideOptions) super.useAnimationPool(flag); + } + + @Override + @CheckResult + public final GlideOptions onlyRetrieveFromCache(boolean flag) { + return (GlideOptions) super.onlyRetrieveFromCache(flag); + } + + @Override + @CheckResult + public final GlideOptions diskCacheStrategy(@NonNull DiskCacheStrategy arg0) { + return (GlideOptions) super.diskCacheStrategy(arg0); + } + + @Override + @CheckResult + public final GlideOptions priority(@NonNull Priority arg0) { + return (GlideOptions) super.priority(arg0); + } + + @Override + @CheckResult + public final GlideOptions placeholder(@Nullable Drawable arg0) { + return (GlideOptions) super.placeholder(arg0); + } + + @Override + @CheckResult + public final GlideOptions placeholder(@DrawableRes int arg0) { + return (GlideOptions) super.placeholder(arg0); + } + + @Override + @CheckResult + public final GlideOptions fallback(@Nullable Drawable arg0) { + return (GlideOptions) super.fallback(arg0); + } + + @Override + @CheckResult + public final GlideOptions fallback(@DrawableRes int arg0) { + return (GlideOptions) super.fallback(arg0); + } + + @Override + @CheckResult + public final GlideOptions error(@Nullable Drawable arg0) { + return (GlideOptions) super.error(arg0); + } + + @Override + @CheckResult + public final GlideOptions error(@DrawableRes int arg0) { + return (GlideOptions) super.error(arg0); + } + + @Override + @CheckResult + public final GlideOptions theme(@Nullable Resources.Theme arg0) { + return (GlideOptions) super.theme(arg0); + } + + @Override + @CheckResult + public final GlideOptions skipMemoryCache(boolean skip) { + return (GlideOptions) super.skipMemoryCache(skip); + } + + @Override + @CheckResult + public final GlideOptions override(int width, int height) { + return (GlideOptions) super.override(width, height); + } + + @Override + @CheckResult + public final GlideOptions override(int size) { + return (GlideOptions) super.override(size); + } + + @Override + @CheckResult + public final GlideOptions signature(@NonNull Key arg0) { + return (GlideOptions) super.signature(arg0); + } + + @Override + @CheckResult + public final GlideOptions clone() { + return (GlideOptions) super.clone(); + } + + @Override + @CheckResult + public final GlideOptions set(@NonNull Option arg0, @NonNull T arg1) { + return (GlideOptions) super.set(arg0, arg1); + } + + @Override + @CheckResult + public final GlideOptions decode(@NonNull Class arg0) { + return (GlideOptions) super.decode(arg0); + } + + @Override + @CheckResult + public final GlideOptions encodeFormat(@NonNull Bitmap.CompressFormat arg0) { + return (GlideOptions) super.encodeFormat(arg0); + } + + @Override + @CheckResult + public final GlideOptions encodeQuality(@IntRange(from = 0, to = 100) int arg0) { + return (GlideOptions) super.encodeQuality(arg0); + } + + @Override + @CheckResult + public final GlideOptions frame(@IntRange(from = 0) long arg0) { + return (GlideOptions) super.frame(arg0); + } + + @Override + @CheckResult + public final GlideOptions format(@NonNull DecodeFormat arg0) { + return (GlideOptions) super.format(arg0); + } + + @Override + @CheckResult + public final GlideOptions disallowHardwareConfig() { + return (GlideOptions) super.disallowHardwareConfig(); + } + + @Override + @CheckResult + public final GlideOptions downsample(@NonNull DownsampleStrategy arg0) { + return (GlideOptions) super.downsample(arg0); + } + + @Override + @CheckResult + public final GlideOptions timeout(@IntRange(from = 0) int arg0) { + return (GlideOptions) super.timeout(arg0); + } + + @Override + @CheckResult + public final GlideOptions optionalCenterCrop() { + return (GlideOptions) super.optionalCenterCrop(); + } + + @Override + @CheckResult + public final GlideOptions centerCrop() { + return (GlideOptions) super.centerCrop(); + } + + @Override + @CheckResult + public final GlideOptions optionalFitCenter() { + return (GlideOptions) super.optionalFitCenter(); + } + + @Override + @CheckResult + public final GlideOptions fitCenter() { + return (GlideOptions) super.fitCenter(); + } + + @Override + @CheckResult + public final GlideOptions optionalCenterInside() { + return (GlideOptions) super.optionalCenterInside(); + } + + @Override + @CheckResult + public final GlideOptions centerInside() { + return (GlideOptions) super.centerInside(); + } + + @Override + @CheckResult + public final GlideOptions optionalCircleCrop() { + return (GlideOptions) super.optionalCircleCrop(); + } + + @Override + @CheckResult + public final GlideOptions circleCrop() { + return (GlideOptions) super.circleCrop(); + } + + @Override + @CheckResult + public final GlideOptions transform(@NonNull Transformation arg0) { + return (GlideOptions) super.transform(arg0); + } + + @Override + @SafeVarargs + @CheckResult + public final GlideOptions transforms(@NonNull Transformation... arg0) { + return (GlideOptions) super.transforms(arg0); + } + + @Override + @CheckResult + public final GlideOptions optionalTransform(@NonNull Transformation arg0) { + return (GlideOptions) super.optionalTransform(arg0); + } + + @Override + @CheckResult + public final GlideOptions optionalTransform(@NonNull Class arg0, + @NonNull Transformation arg1) { + return (GlideOptions) super.optionalTransform(arg0, arg1); + } + + @Override + @CheckResult + public final GlideOptions transform(@NonNull Class arg0, @NonNull Transformation arg1) { + return (GlideOptions) super.transform(arg0, arg1); + } + + @Override + @CheckResult + public final GlideOptions dontTransform() { + return (GlideOptions) super.dontTransform(); + } + + @Override + @CheckResult + public final GlideOptions dontAnimate() { + return (GlideOptions) super.dontAnimate(); + } + + @Override + @CheckResult + public final GlideOptions apply(@NonNull RequestOptions arg0) { + return (GlideOptions) super.apply(arg0); + } + + @Override + public final GlideOptions lock() { + return (GlideOptions) super.lock(); + } + + @Override + public final GlideOptions autoClone() { + return (GlideOptions) super.autoClone(); + } + + /** + * @see ExtensionWithOption#squareThumb(RequestOptions) + */ + @CheckResult + public GlideOptions squareThumb() { + if (isAutoCloneEnabled()) { + return clone().squareThumb(); + } + ExtensionWithOption.squareThumb(this); + return this; + } + + /** + * @see ExtensionWithOption#squareThumb(RequestOptions) + */ + @CheckResult + public static GlideOptions squareThumbOf() { + return new GlideOptions().squareThumb(); + } +} diff --git a/annotation/compiler/test/src/test/resources/LegacyGlideExtensionWithOptionTest/GlideRequest.java b/annotation/compiler/test/src/test/resources/LegacyGlideExtensionWithOptionTest/GlideRequest.java new file mode 100644 index 0000000000..4a001e45ae --- /dev/null +++ b/annotation/compiler/test/src/test/resources/LegacyGlideExtensionWithOptionTest/GlideRequest.java @@ -0,0 +1,725 @@ +package com.bumptech.glide.test; + +import android.content.Context; +import android.content.res.Resources; +import android.graphics.Bitmap; +import android.graphics.drawable.Drawable; +import android.net.Uri; +import android.support.annotation.CheckResult; +import android.support.annotation.DrawableRes; +import android.support.annotation.FloatRange; +import android.support.annotation.IntRange; +import android.support.annotation.NonNull; +import android.support.annotation.Nullable; +import android.support.annotation.RawRes; +import com.bumptech.glide.Glide; +import com.bumptech.glide.Priority; +import com.bumptech.glide.RequestBuilder; +import com.bumptech.glide.RequestManager; +import com.bumptech.glide.TransitionOptions; +import com.bumptech.glide.load.DecodeFormat; +import com.bumptech.glide.load.Key; +import com.bumptech.glide.load.Option; +import com.bumptech.glide.load.Transformation; +import com.bumptech.glide.load.engine.DiskCacheStrategy; +import com.bumptech.glide.load.resource.bitmap.DownsampleStrategy; +import com.bumptech.glide.request.RequestListener; +import com.bumptech.glide.request.RequestOptions; +import java.io.File; +import java.lang.Class; +import java.lang.Cloneable; +import java.lang.Deprecated; +import java.lang.Integer; +import java.lang.Object; +import java.lang.Override; +import java.lang.SafeVarargs; +import java.lang.String; +import java.lang.SuppressWarnings; +import java.net.URL; + +/** + * Contains all public methods from {@link RequestBuilder}, all options from + * {@link RequestOptions} and all generated options from + * {@link com.bumptech.glide.annotation.GlideOption} in annotated methods in + * {@link com.bumptech.glide.annotation.GlideExtension} annotated classes. + * + *

Generated code, do not modify. + * + * @see RequestBuilder + * @see RequestOptions + */ +@SuppressWarnings({ + "unused", + "deprecation" +}) +public class GlideRequest extends RequestBuilder implements Cloneable { + GlideRequest(Class transcodeClass, RequestBuilder other) { + super(transcodeClass, other); + } + + GlideRequest(Glide glide, RequestManager requestManager, Class transcodeClass, + Context context) { + super(glide, requestManager ,transcodeClass, context); + } + + @Override + @CheckResult + protected GlideRequest getDownloadOnlyRequest() { + return new GlideRequest<>(File.class, this).apply(DOWNLOAD_ONLY_OPTIONS); + } + + /** + * @see GlideOptions#sizeMultiplier(float) + */ + @CheckResult + public GlideRequest sizeMultiplier(@FloatRange(from = 0.0, to = 1.0) float arg0) { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).sizeMultiplier(arg0); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).sizeMultiplier(arg0); + } + return this; + } + + /** + * @see GlideOptions#useUnlimitedSourceGeneratorsPool(boolean) + */ + @CheckResult + public GlideRequest useUnlimitedSourceGeneratorsPool(boolean flag) { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).useUnlimitedSourceGeneratorsPool(flag); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).useUnlimitedSourceGeneratorsPool(flag); + } + return this; + } + + /** + * @see GlideOptions#useAnimationPool(boolean) + */ + @CheckResult + public GlideRequest useAnimationPool(boolean flag) { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).useAnimationPool(flag); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).useAnimationPool(flag); + } + return this; + } + + /** + * @see GlideOptions#onlyRetrieveFromCache(boolean) + */ + @CheckResult + public GlideRequest onlyRetrieveFromCache(boolean flag) { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).onlyRetrieveFromCache(flag); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).onlyRetrieveFromCache(flag); + } + return this; + } + + /** + * @see GlideOptions#diskCacheStrategy(DiskCacheStrategy) + */ + @CheckResult + public GlideRequest diskCacheStrategy(@NonNull DiskCacheStrategy arg0) { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).diskCacheStrategy(arg0); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).diskCacheStrategy(arg0); + } + return this; + } + + /** + * @see GlideOptions#priority(Priority) + */ + @CheckResult + public GlideRequest priority(@NonNull Priority arg0) { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).priority(arg0); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).priority(arg0); + } + return this; + } + + /** + * @see GlideOptions#placeholder(Drawable) + */ + @CheckResult + public GlideRequest placeholder(@Nullable Drawable arg0) { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).placeholder(arg0); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).placeholder(arg0); + } + return this; + } + + /** + * @see GlideOptions#placeholder(int) + */ + @CheckResult + public GlideRequest placeholder(@DrawableRes int arg0) { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).placeholder(arg0); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).placeholder(arg0); + } + return this; + } + + /** + * @see GlideOptions#fallback(Drawable) + */ + @CheckResult + public GlideRequest fallback(@Nullable Drawable arg0) { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).fallback(arg0); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).fallback(arg0); + } + return this; + } + + /** + * @see GlideOptions#fallback(int) + */ + @CheckResult + public GlideRequest fallback(@DrawableRes int arg0) { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).fallback(arg0); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).fallback(arg0); + } + return this; + } + + /** + * @see GlideOptions#error(Drawable) + */ + @CheckResult + public GlideRequest error(@Nullable Drawable arg0) { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).error(arg0); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).error(arg0); + } + return this; + } + + /** + * @see GlideOptions#error(int) + */ + @CheckResult + public GlideRequest error(@DrawableRes int arg0) { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).error(arg0); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).error(arg0); + } + return this; + } + + /** + * @see GlideOptions#theme(Resources.Theme) + */ + @CheckResult + public GlideRequest theme(@Nullable Resources.Theme arg0) { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).theme(arg0); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).theme(arg0); + } + return this; + } + + /** + * @see GlideOptions#skipMemoryCache(boolean) + */ + @CheckResult + public GlideRequest skipMemoryCache(boolean skip) { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).skipMemoryCache(skip); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).skipMemoryCache(skip); + } + return this; + } + + /** + * @see GlideOptions#override(int, int) + */ + @CheckResult + public GlideRequest override(int width, int height) { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).override(width, height); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).override(width, height); + } + return this; + } + + /** + * @see GlideOptions#override(int) + */ + @CheckResult + public GlideRequest override(int size) { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).override(size); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).override(size); + } + return this; + } + + /** + * @see GlideOptions#signature(Key) + */ + @CheckResult + public GlideRequest signature(@NonNull Key arg0) { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).signature(arg0); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).signature(arg0); + } + return this; + } + + /** + * @see GlideOptions#set(Option, T) + */ + @CheckResult + public GlideRequest set(@NonNull Option arg0, @NonNull T arg1) { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).set(arg0, arg1); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).set(arg0, arg1); + } + return this; + } + + /** + * @see GlideOptions#decode(Class) + */ + @CheckResult + public GlideRequest decode(@NonNull Class arg0) { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).decode(arg0); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).decode(arg0); + } + return this; + } + + /** + * @see GlideOptions#encodeFormat(Bitmap.CompressFormat) + */ + @CheckResult + public GlideRequest encodeFormat(@NonNull Bitmap.CompressFormat arg0) { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).encodeFormat(arg0); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).encodeFormat(arg0); + } + return this; + } + + /** + * @see GlideOptions#encodeQuality(int) + */ + @CheckResult + public GlideRequest encodeQuality(@IntRange(from = 0, to = 100) int arg0) { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).encodeQuality(arg0); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).encodeQuality(arg0); + } + return this; + } + + /** + * @see GlideOptions#frame(long) + */ + @CheckResult + public GlideRequest frame(@IntRange(from = 0) long arg0) { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).frame(arg0); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).frame(arg0); + } + return this; + } + + /** + * @see GlideOptions#format(DecodeFormat) + */ + @CheckResult + public GlideRequest format(@NonNull DecodeFormat arg0) { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).format(arg0); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).format(arg0); + } + return this; + } + + /** + * @see GlideOptions#disallowHardwareConfig() + */ + @CheckResult + public GlideRequest disallowHardwareConfig() { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).disallowHardwareConfig(); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).disallowHardwareConfig(); + } + return this; + } + + /** + * @see GlideOptions#downsample(DownsampleStrategy) + */ + @CheckResult + public GlideRequest downsample(@NonNull DownsampleStrategy arg0) { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).downsample(arg0); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).downsample(arg0); + } + return this; + } + + /** + * @see GlideOptions#timeout(int) + */ + @CheckResult + public GlideRequest timeout(@IntRange(from = 0) int arg0) { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).timeout(arg0); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).timeout(arg0); + } + return this; + } + + /** + * @see GlideOptions#optionalCenterCrop() + */ + @CheckResult + public GlideRequest optionalCenterCrop() { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).optionalCenterCrop(); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).optionalCenterCrop(); + } + return this; + } + + /** + * @see GlideOptions#centerCrop() + */ + @CheckResult + public GlideRequest centerCrop() { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).centerCrop(); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).centerCrop(); + } + return this; + } + + /** + * @see GlideOptions#optionalFitCenter() + */ + @CheckResult + public GlideRequest optionalFitCenter() { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).optionalFitCenter(); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).optionalFitCenter(); + } + return this; + } + + /** + * @see GlideOptions#fitCenter() + */ + @CheckResult + public GlideRequest fitCenter() { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).fitCenter(); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).fitCenter(); + } + return this; + } + + /** + * @see GlideOptions#optionalCenterInside() + */ + @CheckResult + public GlideRequest optionalCenterInside() { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).optionalCenterInside(); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).optionalCenterInside(); + } + return this; + } + + /** + * @see GlideOptions#centerInside() + */ + @CheckResult + public GlideRequest centerInside() { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).centerInside(); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).centerInside(); + } + return this; + } + + /** + * @see GlideOptions#optionalCircleCrop() + */ + @CheckResult + public GlideRequest optionalCircleCrop() { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).optionalCircleCrop(); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).optionalCircleCrop(); + } + return this; + } + + /** + * @see GlideOptions#circleCrop() + */ + @CheckResult + public GlideRequest circleCrop() { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).circleCrop(); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).circleCrop(); + } + return this; + } + + /** + * @see GlideOptions#transform(Transformation) + */ + @CheckResult + public GlideRequest transform(@NonNull Transformation arg0) { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).transform(arg0); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).transform(arg0); + } + return this; + } + + /** + * @see GlideOptions#transforms(Transformation[]) + */ + @CheckResult + @SuppressWarnings({ + "unchecked", + "varargs" + }) + public GlideRequest transforms(@NonNull Transformation... arg0) { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).transforms(arg0); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).transforms(arg0); + } + return this; + } + + /** + * @see GlideOptions#optionalTransform(Transformation) + */ + @CheckResult + public GlideRequest optionalTransform(@NonNull Transformation arg0) { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).optionalTransform(arg0); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).optionalTransform(arg0); + } + return this; + } + + /** + * @see GlideOptions#optionalTransform(Class, Transformation) + */ + @CheckResult + public GlideRequest optionalTransform(@NonNull Class arg0, + @NonNull Transformation arg1) { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).optionalTransform(arg0, arg1); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).optionalTransform(arg0, arg1); + } + return this; + } + + /** + * @see GlideOptions#transform(Class, Transformation) + */ + @CheckResult + public GlideRequest transform(@NonNull Class arg0, + @NonNull Transformation arg1) { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).transform(arg0, arg1); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).transform(arg0, arg1); + } + return this; + } + + /** + * @see GlideOptions#dontTransform() + */ + @CheckResult + public GlideRequest dontTransform() { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).dontTransform(); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).dontTransform(); + } + return this; + } + + /** + * @see GlideOptions#dontAnimate() + */ + @CheckResult + public GlideRequest dontAnimate() { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).dontAnimate(); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).dontAnimate(); + } + return this; + } + + /** + * @see GlideOptions#squareThumb() + */ + @CheckResult + public GlideRequest squareThumb() { + if (getMutableOptions() instanceof GlideOptions) { + this.requestOptions = ((GlideOptions) getMutableOptions()).squareThumb(); + } else { + this.requestOptions = new GlideOptions().apply(this.requestOptions).squareThumb(); + } + return this; + } + + @Override + @CheckResult + public GlideRequest apply(@NonNull RequestOptions arg0) { + return (GlideRequest) super.apply(arg0); + } + + @Override + @CheckResult + public GlideRequest transition(@NonNull TransitionOptions arg0) { + return (GlideRequest) super.transition(arg0); + } + + @Override + @CheckResult + public GlideRequest listener(@Nullable RequestListener arg0) { + return (GlideRequest) super.listener(arg0); + } + + @Override + public GlideRequest error(@Nullable RequestBuilder arg0) { + return (GlideRequest) super.error(arg0); + } + + @Override + @CheckResult + public GlideRequest thumbnail(@Nullable RequestBuilder arg0) { + return (GlideRequest) super.thumbnail(arg0); + } + + @Override + @CheckResult + @SafeVarargs + public final GlideRequest thumbnail(@Nullable RequestBuilder... arg0) { + return (GlideRequest) super.thumbnail(arg0); + } + + @Override + @CheckResult + public GlideRequest thumbnail(float sizeMultiplier) { + return (GlideRequest) super.thumbnail(sizeMultiplier); + } + + @Override + @CheckResult + public GlideRequest load(@Nullable Object arg0) { + return (GlideRequest) super.load(arg0); + } + + @Override + @CheckResult + public GlideRequest load(@Nullable Bitmap arg0) { + return (GlideRequest) super.load(arg0); + } + + @Override + @CheckResult + public GlideRequest load(@Nullable Drawable arg0) { + return (GlideRequest) super.load(arg0); + } + + @Override + @CheckResult + public GlideRequest load(@Nullable String arg0) { + return (GlideRequest) super.load(arg0); + } + + @Override + @CheckResult + public GlideRequest load(@Nullable Uri arg0) { + return (GlideRequest) super.load(arg0); + } + + @Override + @CheckResult + public GlideRequest load(@Nullable File arg0) { + return (GlideRequest) super.load(arg0); + } + + @Override + @CheckResult + public GlideRequest load(@RawRes @DrawableRes @Nullable Integer arg0) { + return (GlideRequest) super.load(arg0); + } + + @Override + @Deprecated + @CheckResult + public GlideRequest load(@Nullable URL arg0) { + return (GlideRequest) super.load(arg0); + } + + @Override + @CheckResult + public GlideRequest load(@Nullable byte[] arg0) { + return (GlideRequest) super.load(arg0); + } + + @Override + @CheckResult + public GlideRequest clone() { + return (GlideRequest) super.clone(); + } +} diff --git a/annotation/src/main/java/com/bumptech/glide/annotation/GlideOption.java b/annotation/src/main/java/com/bumptech/glide/annotation/GlideOption.java index 70d7b4cbb1..7c0db39d6f 100644 --- a/annotation/src/main/java/com/bumptech/glide/annotation/GlideOption.java +++ b/annotation/src/main/java/com/bumptech/glide/annotation/GlideOption.java @@ -17,6 +17,54 @@ * *

Methods with this annotation will only be found if they belong to classes annotated with * {@link GlideExtension}. + * + *

The preferred way of writing extension methods returns the provided + * {@code com.bumptech.glide.request.RequestOptions} object with one or more methods called on it. + * You must not return a newly instantiated {@code com.bumptech.glide.request.RequestOptions} object + * as doing so my cause a {@code ClassCastException} at runtime. Calling either + * {@code com.bumptech.glide.request.RequestOptions#autoClone()} or + * {@code com.bumptech.glide.request.RequestOptions#lock()} is safe, but unnecessary and should + * typically be avoided. The preferred style looks like: + * + *

+ * {@code
+ * @GlideExtenion
+ * public class MyExtension {
+ *   private MyExtension() {}
+ *
+ *   @GlideOption
+ *   public static RequestOptions myOption(RequestOptions options) {
+ *     return options
+ *         .optionOne()
+ *         .optionTwo();
+ *   }
+ * }
+ * }
+ * 
+ * + *

The deprecated way of writing extension methods is simply a static void method. The + * {@code com.bumptech.glide.request.RequestOptions} object is cloned before it is passed to this + * method to avoid an option method returning a new instance, but using methods like + * {@code com.bumptech.glide.request.RequestOptions#clone()} or + * {@code com.bumptech.glide.request.RequestOptions#autoClone()} can result in options applied in + * the method being silently ignored. Prefer the new style whenever possible. + * + *

+ * {@code
+ * @GlideExtenion
+ * public class MyExtension {
+ *   private MyExtension() {}
+ *
+ *   // Deprecated! Use the new style of GlideOption extensions instead.
+ *   @GlideOption
+ *   public static void myOption(RequestOptions options) {
+ *     options
+ *         .optionOne()
+ *         .optionTwo();
+ *   }
+ * }
+ * }
+ * 
*/ @Target(ElementType.METHOD) // Needs to be parsed from class files in JAR. 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 new file mode 100644 index 0000000000..9a56e52bd7 --- /dev/null +++ b/samples/flickr/src/main/java/com/bumptech/glide/samples/flickr/FlickrGlideExtension.java @@ -0,0 +1,34 @@ +package com.bumptech.glide.samples.flickr; + +import com.bumptech.glide.annotation.GlideExtension; +import com.bumptech.glide.annotation.GlideOption; +import com.bumptech.glide.request.RequestOptions; +import com.bumptech.glide.samples.flickr.api.Api; + +/** + * Extension methods for the Flickr sample's generated API. + */ +@GlideExtension +public final class FlickrGlideExtension { + + private FlickrGlideExtension() { + // Utility class. + } + + @GlideOption + public static RequestOptions squareThumb(RequestOptions requestOptions) { + return requestOptions + .centerCrop(); + } + + @GlideOption + public static RequestOptions squareMiniThumb(RequestOptions requestOptions) { + return requestOptions.centerCrop().override(Api.SQUARE_THUMB_SIZE); + } + + @GlideOption(override = GlideOption.OVERRIDE_EXTEND) + public static RequestOptions centerCrop(RequestOptions options) { + return options; + // Empty. + } +}