Skip to content

Commit d8278f4

Browse files
sjuddglide-copybara-robot
authored andcommitted
Migrate Glide to androidx
PiperOrigin-RevId: 250772542
1 parent 1be3a6c commit d8278f4

File tree

417 files changed

+1033
-999
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

417 files changed

+1033
-999
lines changed

annotation/compiler/build.gradle

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ dependencies {
1919
compile project(':annotation')
2020
// This is to support com.sun.tools.javac.util.List, currently used in RootModuleGenerator.
2121
compile files(Jvm.current().getToolsJar())
22+
annotationProcessor "com.google.auto.service:auto-service:${AUTO_SERVICE_VERSION}"
2223
}
2324

2425
// Make sure running `gradlew :annotation:compiler:check` actually does full quality control.

annotation/compiler/src/main/java/com/bumptech/glide/annotation/compiler/AppModuleGenerator.java

+8-10
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
package com.bumptech.glide.annotation.compiler;
22

3-
import static com.bumptech.glide.annotation.compiler.ProcessorUtil.nonNull;
4-
53
import com.bumptech.glide.annotation.Excludes;
64
import com.squareup.javapoet.AnnotationSpec;
75
import com.squareup.javapoet.ClassName;
@@ -68,7 +66,7 @@
6866
* }
6967
*
7068
* {@literal @java.lang.Override}
71-
* {@literal @android.support.annotation.NonNull}
69+
* {@literal @androidx.annotation.NonNull}
7270
* public java.util.Set<java.lang.Class<?>> getExcludedModuleClasses() {
7371
* return appGlideModule.getExcludedModuleClasses();
7472
* }
@@ -115,12 +113,12 @@ TypeSpec generate(TypeElement appGlideModule, Set<String> libraryGlideModuleClas
115113
.addAnnotation(Override.class)
116114
.addParameter(
117115
ParameterSpec.builder(ClassName.get("android.content", "Context"), "context")
118-
.addAnnotation(nonNull())
116+
.addAnnotation(processorUtil.nonNull())
119117
.build())
120118
.addParameter(
121119
ParameterSpec.builder(
122120
ClassName.get("com.bumptech.glide", "GlideBuilder"), "builder")
123-
.addAnnotation(nonNull())
121+
.addAnnotation(processorUtil.nonNull())
124122
.build())
125123
.addStatement("appGlideModule.applyOptions(context, builder)", appGlideModule)
126124
.build();
@@ -158,7 +156,7 @@ TypeSpec generate(TypeElement appGlideModule, Set<String> libraryGlideModuleClas
158156
builder.addMethod(
159157
MethodSpec.methodBuilder("getRequestManagerFactory")
160158
.addAnnotation(Override.class)
161-
.addAnnotation(nonNull())
159+
.addAnnotation(processorUtil.nonNull())
162160
.returns(generatedRequestManagerFactoryClassName)
163161
.addStatement("return new $T()", generatedRequestManagerFactoryClassName)
164162
.build());
@@ -178,7 +176,7 @@ private MethodSpec generateGetExcludedModuleClasses(Collection<String> excludedC
178176
MethodSpec.methodBuilder("getExcludedModuleClasses")
179177
.addModifiers(Modifier.PUBLIC)
180178
.addAnnotation(Override.class)
181-
.addAnnotation(nonNull())
179+
.addAnnotation(processorUtil.nonNull())
182180
.returns(setOfClassOfWildcardOfObject);
183181

184182
if (excludedClassNames.isEmpty()) {
@@ -209,15 +207,15 @@ private MethodSpec generateRegisterComponents(
209207
.addAnnotation(Override.class)
210208
.addParameter(
211209
ParameterSpec.builder(ClassName.get("android.content", "Context"), "context")
212-
.addAnnotation(nonNull())
210+
.addAnnotation(processorUtil.nonNull())
213211
.build())
214212
.addParameter(
215213
ParameterSpec.builder(ClassName.get("com.bumptech.glide", "Glide"), "glide")
216-
.addAnnotation(nonNull())
214+
.addAnnotation(processorUtil.nonNull())
217215
.build())
218216
.addParameter(
219217
ParameterSpec.builder(ClassName.get("com.bumptech.glide", "Registry"), "registry")
220-
.addAnnotation(nonNull())
218+
.addAnnotation(processorUtil.nonNull())
221219
.build());
222220

223221
for (String glideModule : libraryGlideModuleClassNames) {

annotation/compiler/src/main/java/com/bumptech/glide/annotation/compiler/AppModuleProcessor.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ final class AppModuleProcessor {
3939
appModuleGenerator = new AppModuleGenerator(processorUtil);
4040
requestOptionsGenerator = new RequestOptionsGenerator(processingEnv, processorUtil);
4141
requestManagerGenerator = new RequestManagerGenerator(processingEnv, processorUtil);
42-
requestManagerFactoryGenerator = new RequestManagerFactoryGenerator(processingEnv);
42+
requestManagerFactoryGenerator =
43+
new RequestManagerFactoryGenerator(processingEnv, processorUtil);
4344
glideGenerator = new GlideGenerator(processingEnv, processorUtil);
4445
requestBuilderGenerator = new RequestBuilderGenerator(processingEnv, processorUtil);
4546
}

annotation/compiler/src/main/java/com/bumptech/glide/annotation/compiler/GlideAnnotationProcessor.java

-3
Original file line numberDiff line numberDiff line change
@@ -108,9 +108,6 @@ public SourceVersion getSupportedSourceVersion() {
108108
*/
109109
@Override
110110
public boolean process(Set<? extends TypeElement> set, RoundEnvironment env) {
111-
// if (set.isEmpty() && !isGeneratedAppGlideModulePending) {
112-
// return false;
113-
// }
114111
processorUtil.process();
115112
boolean newModulesWritten = libraryModuleProcessor.processModules(env);
116113
boolean newExtensionWritten = extensionProcessor.processExtensions(env);

annotation/compiler/src/main/java/com/bumptech/glide/annotation/compiler/GlideExtensionValidator.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package com.bumptech.glide.annotation.compiler;
22

3-
import static com.bumptech.glide.annotation.compiler.ProcessorUtil.nonNull;
43
import static com.bumptech.glide.annotation.compiler.ProcessorUtil.nonNulls;
54

65
import com.bumptech.glide.annotation.GlideOption;
@@ -284,7 +283,7 @@ public String apply(AnnotationMirror input) {
284283
Kind.WARNING,
285284
getQualifiedMethodName(executableElement)
286285
+ " is missing the "
287-
+ nonNull().reflectionName()
286+
+ processorUtil.nonNull().reflectionName()
288287
+ " annotation,"
289288
+ " please add it to ensure that your extension methods are always returning"
290289
+ " non-null values");

annotation/compiler/src/main/java/com/bumptech/glide/annotation/compiler/GlideGenerator.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
* Generates a Glide look-alike that acts as the entry point to the generated API
2424
* (GlideApp.with(...)).
2525
*
26-
* <p>>Generated {@code com.bumptech.glide.Glide} look-alikes look like this (note that the name is
26+
* <p>Generated {@code com.bumptech.glide.Glide} look-alikes look like this (note that the name is
2727
* configurable in {@link com.bumptech.glide.annotation.GlideModule}):
2828
*
2929
* <pre>
@@ -64,7 +64,7 @@
6464
* return (GeneratedRequestManager) Glide.with(fragment);
6565
* }
6666
*
67-
* public static GeneratedRequestManager with(android.support.v4.app.Fragment fragment) {
67+
* public static GeneratedRequestManager with(androidx.fragment.app.Fragment fragment) {
6868
* return (GeneratedRequestManager) Glide.with(fragment);
6969
* }
7070
* </code>
@@ -171,7 +171,7 @@ private MethodSpec overrideGlideStaticMethod(ExecutableElement methodToOverride)
171171
private Builder addReturnAnnotations(Builder builder, ExecutableElement methodToOverride) {
172172
Elements elements = processingEnv.getElementUtils();
173173
TypeElement visibleForTestingTypeElement =
174-
elements.getTypeElement(ProcessorUtil.visibleForTesting().reflectionName());
174+
elements.getTypeElement(processorUtil.visibleForTesting().reflectionName());
175175
String visibleForTestingTypeQualifiedName = visibleForTestingTypeElement.toString();
176176

177177
for (AnnotationMirror mirror : methodToOverride.getAnnotationMirrors()) {

annotation/compiler/src/main/java/com/bumptech/glide/annotation/compiler/ProcessorUtil.java

+25-27
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import com.google.common.base.Joiner;
99
import com.google.common.base.Predicate;
1010
import com.google.common.collect.FluentIterable;
11+
import com.google.common.collect.ImmutableList;
1112
import com.google.common.collect.Lists;
1213
import com.squareup.javapoet.AnnotationSpec;
1314
import com.squareup.javapoet.ClassName;
@@ -24,7 +25,6 @@
2425
import java.lang.reflect.InvocationTargetException;
2526
import java.lang.reflect.Method;
2627
import java.util.ArrayList;
27-
import java.util.Arrays;
2828
import java.util.Collection;
2929
import java.util.Collections;
3030
import java.util.HashSet;
@@ -48,6 +48,7 @@
4848
import javax.lang.model.type.TypeMirror;
4949
import javax.lang.model.type.TypeVariable;
5050
import javax.lang.model.util.ElementFilter;
51+
import javax.lang.model.util.Elements;
5152
import javax.lang.model.util.Types;
5253
import javax.tools.Diagnostic;
5354

@@ -62,17 +63,17 @@ final class ProcessorUtil {
6263
GLIDE_MODULE_PACKAGE_NAME + "." + LIBRARY_GLIDE_MODULE_SIMPLE_NAME;
6364
private static final String COMPILER_PACKAGE_NAME =
6465
GlideAnnotationProcessor.class.getPackage().getName();
65-
private static final ClassName NONNULL_ANNOTATION =
66+
private static final ClassName SUPPORT_NONNULL_ANNOTATION =
6667
ClassName.get("android.support.annotation", "NonNull");
6768
private static final ClassName JETBRAINS_NOTNULL_ANNOTATION =
6869
ClassName.get("org.jetbrains.annotations", "NotNull");
6970
private static final ClassName ANDROIDX_NONNULL_ANNOTATION =
7071
ClassName.get("androidx.annotation", "NonNull");
71-
private static final ClassName CHECK_RESULT_ANNOTATION =
72+
private static final ClassName SUPPORT_CHECK_RESULT_ANNOTATION =
7273
ClassName.get("android.support.annotation", "CheckResult");
7374
private static final ClassName ANDROIDX_CHECK_RESULT_ANNOTATION =
7475
ClassName.get("androidx.annotation", "CheckResult");
75-
private static final ClassName VISIBLE_FOR_TESTING =
76+
private static final ClassName SUPPORT_VISIBLE_FOR_TESTING =
7677
ClassName.get("android.support.annotation", "VisibleForTesting");
7778
private static final ClassName ANDROIDX_VISIBLE_FOR_TESTING =
7879
ClassName.get("androidx.annotation", "VisibleForTesting");
@@ -457,36 +458,33 @@ private static List<AnnotationSpec> getAnnotations(VariableElement element) {
457458
return result;
458459
}
459460

460-
static ClassName visibleForTesting() {
461-
try {
462-
Class.forName(ANDROIDX_VISIBLE_FOR_TESTING.reflectionName());
463-
return ANDROIDX_VISIBLE_FOR_TESTING;
464-
} catch (ClassNotFoundException e) {
465-
return VISIBLE_FOR_TESTING;
466-
}
461+
ClassName visibleForTesting() {
462+
return findAnnotationClassName(ANDROIDX_VISIBLE_FOR_TESTING, SUPPORT_VISIBLE_FOR_TESTING);
467463
}
468464

469-
static ClassName nonNull() {
470-
try {
471-
Class.forName(ANDROIDX_NONNULL_ANNOTATION.reflectionName());
472-
return ANDROIDX_NONNULL_ANNOTATION;
473-
} catch (ClassNotFoundException e) {
474-
return NONNULL_ANNOTATION;
475-
}
465+
ClassName nonNull() {
466+
return findAnnotationClassName(ANDROIDX_NONNULL_ANNOTATION, SUPPORT_NONNULL_ANNOTATION);
476467
}
477468

478-
static ClassName checkResult() {
479-
try {
480-
Class.forName(ANDROIDX_CHECK_RESULT_ANNOTATION.reflectionName());
481-
return ANDROIDX_CHECK_RESULT_ANNOTATION;
482-
} catch (ClassNotFoundException e) {
483-
return CHECK_RESULT_ANNOTATION;
484-
}
469+
ClassName checkResult() {
470+
return findAnnotationClassName(
471+
ANDROIDX_CHECK_RESULT_ANNOTATION, SUPPORT_CHECK_RESULT_ANNOTATION);
485472
}
486473

487474
static List<ClassName> nonNulls() {
488-
return Arrays.asList(
489-
NONNULL_ANNOTATION, JETBRAINS_NOTNULL_ANNOTATION, ANDROIDX_NONNULL_ANNOTATION);
475+
return ImmutableList.of(
476+
SUPPORT_NONNULL_ANNOTATION, JETBRAINS_NOTNULL_ANNOTATION, ANDROIDX_NONNULL_ANNOTATION);
477+
}
478+
479+
private ClassName findAnnotationClassName(ClassName androidxName, ClassName supportName) {
480+
Elements elements = processingEnv.getElementUtils();
481+
TypeElement visibleForTestingTypeElement =
482+
elements.getTypeElement(androidxName.reflectionName());
483+
if (visibleForTestingTypeElement != null) {
484+
return androidxName;
485+
}
486+
487+
return supportName;
490488
}
491489

492490
List<ExecutableElement> findInstanceMethodsReturning(TypeElement clazz, TypeMirror returnType) {

annotation/compiler/src/main/java/com/bumptech/glide/annotation/compiler/RequestBuilderGenerator.java

+13-14
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
package com.bumptech.glide.annotation.compiler;
22

3-
import static com.bumptech.glide.annotation.compiler.ProcessorUtil.checkResult;
4-
import static com.bumptech.glide.annotation.compiler.ProcessorUtil.nonNull;
5-
63
import com.bumptech.glide.annotation.GlideExtension;
74
import com.bumptech.glide.annotation.GlideOption;
85
import com.google.common.base.Function;
@@ -109,9 +106,6 @@ final class RequestBuilderGenerator {
109106
private static final ImmutableSet<String> EXCLUDED_METHODS_FROM_BASE_REQUEST_OPTIONS =
110107
ImmutableSet.of("clone", "apply", "autoLock", "lock", "autoClone");
111108

112-
private static final AnnotationSpec NON_NULL = AnnotationSpec.builder(nonNull()).build();
113-
private static final AnnotationSpec CHECK_RESULT = AnnotationSpec.builder(checkResult()).build();
114-
115109
private final ProcessingEnvironment processingEnv;
116110
private final ProcessorUtil processorUtil;
117111
private final TypeVariableName transcodeTypeName;
@@ -433,11 +427,11 @@ private List<MethodSpec> generateConstructors() {
433427
MethodSpec.constructorBuilder()
434428
.addParameter(
435429
ParameterSpec.builder(classOfTranscodeType, "transcodeClass")
436-
.addAnnotation(nonNull())
430+
.addAnnotation(processorUtil.nonNull())
437431
.build())
438432
.addParameter(
439433
ParameterSpec.builder(requestBuilderOfWildcardOfObject, "other")
440-
.addAnnotation(nonNull())
434+
.addAnnotation(processorUtil.nonNull())
441435
.build())
442436
.addStatement("super($N, $N)", "transcodeClass", "other")
443437
.build();
@@ -447,17 +441,22 @@ private List<MethodSpec> generateConstructors() {
447441
ClassName requestManager = ClassName.get("com.bumptech.glide", "RequestManager");
448442
MethodSpec secondConstructor =
449443
MethodSpec.constructorBuilder()
450-
.addParameter(ParameterSpec.builder(glide, "glide").addAnnotation(nonNull()).build())
444+
.addParameter(
445+
ParameterSpec.builder(glide, "glide")
446+
.addAnnotation(processorUtil.nonNull())
447+
.build())
451448
.addParameter(
452449
ParameterSpec.builder(requestManager, "requestManager")
453-
.addAnnotation(nonNull())
450+
.addAnnotation(processorUtil.nonNull())
454451
.build())
455452
.addParameter(
456453
ParameterSpec.builder(classOfTranscodeType, "transcodeClass")
457-
.addAnnotation(nonNull())
454+
.addAnnotation(processorUtil.nonNull())
458455
.build())
459456
.addParameter(
460-
ParameterSpec.builder(context, "context").addAnnotation(nonNull()).build())
457+
ParameterSpec.builder(context, "context")
458+
.addAnnotation(processorUtil.nonNull())
459+
.build())
461460
.addStatement(
462461
"super($N, $N ,$N, $N)", "glide", "requestManager", "transcodeClass", "context")
463462
.build();
@@ -473,8 +472,8 @@ private MethodSpec generateDownloadOnlyRequestMethod() {
473472
ParameterizedTypeName.get(generatedRequestBuilderClassName, ClassName.get(File.class));
474473
return MethodSpec.methodBuilder("getDownloadOnlyRequest")
475474
.addAnnotation(Override.class)
476-
.addAnnotation(CHECK_RESULT)
477-
.addAnnotation(NON_NULL)
475+
.addAnnotation(processorUtil.checkResult())
476+
.addAnnotation(processorUtil.nonNull())
478477
.returns(generatedRequestBuilderOfFile)
479478
.addModifiers(Modifier.PROTECTED)
480479
.addStatement(

annotation/compiler/src/main/java/com/bumptech/glide/annotation/compiler/RequestManagerFactoryGenerator.java

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
package com.bumptech.glide.annotation.compiler;
22

3-
import static com.bumptech.glide.annotation.compiler.ProcessorUtil.nonNull;
4-
53
import com.squareup.javapoet.ClassName;
64
import com.squareup.javapoet.MethodSpec;
75
import com.squareup.javapoet.ParameterSpec;
@@ -51,8 +49,10 @@ final class RequestManagerFactoryGenerator {
5149
private final TypeElement requestManagerTreeNodeType;
5250
private final TypeElement requestManagerFactoryInterface;
5351
private final ClassName requestManagerClassName;
52+
private final ProcessorUtil processorUtil;
5453

55-
RequestManagerFactoryGenerator(ProcessingEnvironment processingEnv) {
54+
RequestManagerFactoryGenerator(ProcessingEnvironment processingEnv, ProcessorUtil processorUtil) {
55+
this.processorUtil = processorUtil;
5656
Elements elementUtils = processingEnv.getElementUtils();
5757
glideType = elementUtils.getTypeElement(GLIDE_QUALIFIED_NAME);
5858
lifecycleType = elementUtils.getTypeElement(LIFECYCLE_QUALIFIED_NAME);
@@ -75,23 +75,23 @@ TypeSpec generate(String generatedCodePackageName, TypeSpec generatedRequestMana
7575
MethodSpec.methodBuilder("build")
7676
.addModifiers(Modifier.PUBLIC)
7777
.addAnnotation(Override.class)
78-
.addAnnotation(nonNull())
78+
.addAnnotation(processorUtil.nonNull())
7979
.returns(requestManagerClassName)
8080
.addParameter(
8181
ParameterSpec.builder(ClassName.get(glideType), "glide")
82-
.addAnnotation(nonNull())
82+
.addAnnotation(processorUtil.nonNull())
8383
.build())
8484
.addParameter(
8585
ParameterSpec.builder(ClassName.get(lifecycleType), "lifecycle")
86-
.addAnnotation(nonNull())
86+
.addAnnotation(processorUtil.nonNull())
8787
.build())
8888
.addParameter(
8989
ParameterSpec.builder(ClassName.get(requestManagerTreeNodeType), "treeNode")
90-
.addAnnotation(nonNull())
90+
.addAnnotation(processorUtil.nonNull())
9191
.build())
9292
.addParameter(
9393
ParameterSpec.builder(CONTEXT_CLASS_NAME, "context")
94-
.addAnnotation(nonNull())
94+
.addAnnotation(processorUtil.nonNull())
9595
.build())
9696
.addStatement(
9797
"return new $T(glide, lifecycle, treeNode, context)",

0 commit comments

Comments
 (0)