Skip to content

Commit

Permalink
Reformat all files excluding third_party.
Browse files Browse the repository at this point in the history
  • Loading branch information
sjudd committed May 24, 2019
1 parent 8f8a160 commit 0dcc33f
Show file tree
Hide file tree
Showing 500 changed files with 9,519 additions and 9,845 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
* runtime.
*
* <p>The generated class looks something like this:
*
* <pre>
* <code>
* final class GeneratedAppGlideModuleImpl extends com.bumptech.glide.GeneratedAppGlideModule {
Expand Down Expand Up @@ -78,8 +79,7 @@
final class AppModuleGenerator {
static final String GENERATED_ROOT_MODULE_PACKAGE_NAME = "com.bumptech.glide";
private static final String GLIDE_LOG_TAG = "Glide";
private static final String GENERATED_APP_MODULE_IMPL_SIMPLE_NAME =
"GeneratedAppGlideModuleImpl";
private static final String GENERATED_APP_MODULE_IMPL_SIMPLE_NAME = "GeneratedAppGlideModuleImpl";
private static final String GENERATED_ROOT_MODULE_SIMPLE_NAME = "GeneratedAppGlideModule";

private final ProcessorUtil processorUtil;
Expand All @@ -90,8 +90,7 @@ final class AppModuleGenerator {

TypeSpec generate(TypeElement appGlideModule, Set<String> libraryGlideModuleClassNames) {
ClassName appGlideModuleClassName = ClassName.get(appGlideModule);
List<String> excludedGlideModuleClassNames =
getExcludedGlideModuleClassNames(appGlideModule);
List<String> excludedGlideModuleClassNames = getExcludedGlideModuleClassNames(appGlideModule);

List<String> orderedLibraryGlideModuleClassNames =
new ArrayList<>(libraryGlideModuleClassNames);
Expand All @@ -114,16 +113,15 @@ TypeSpec generate(TypeElement appGlideModule, Set<String> libraryGlideModuleClas
MethodSpec.methodBuilder("applyOptions")
.addModifiers(Modifier.PUBLIC)
.addAnnotation(Override.class)
.addParameter(ParameterSpec.builder(
ClassName.get("android.content", "Context"), "context")
.addAnnotation(nonNull())
.build()
)
.addParameter(ParameterSpec.builder(
ClassName.get("com.bumptech.glide", "GlideBuilder"), "builder")
.addAnnotation(nonNull())
.build()
)
.addParameter(
ParameterSpec.builder(ClassName.get("android.content", "Context"), "context")
.addAnnotation(nonNull())
.build())
.addParameter(
ParameterSpec.builder(
ClassName.get("com.bumptech.glide", "GlideBuilder"), "builder")
.addAnnotation(nonNull())
.build())
.addStatement("appGlideModule.applyOptions(context, builder)", appGlideModule)
.build();

Expand All @@ -135,21 +133,22 @@ TypeSpec generate(TypeElement appGlideModule, Set<String> libraryGlideModuleClas
.addStatement("return appGlideModule.isManifestParsingEnabled()", appGlideModule)
.build();

Builder builder = TypeSpec.classBuilder(GENERATED_APP_MODULE_IMPL_SIMPLE_NAME)
.addModifiers(Modifier.FINAL)
.addAnnotation(
AnnotationSpec.builder(SuppressWarnings.class)
.addMember("value", "$S", "deprecation")
.build()
)
.superclass(
ClassName.get(GENERATED_ROOT_MODULE_PACKAGE_NAME, GENERATED_ROOT_MODULE_SIMPLE_NAME))
.addField(appGlideModuleClassName, "appGlideModule", Modifier.PRIVATE, Modifier.FINAL)
.addMethod(constructor)
.addMethod(applyOptions)
.addMethod(registerComponents)
.addMethod(isManifestParsingEnabled)
.addMethod(getExcludedModuleClasses);
Builder builder =
TypeSpec.classBuilder(GENERATED_APP_MODULE_IMPL_SIMPLE_NAME)
.addModifiers(Modifier.FINAL)
.addAnnotation(
AnnotationSpec.builder(SuppressWarnings.class)
.addMember("value", "$S", "deprecation")
.build())
.superclass(
ClassName.get(
GENERATED_ROOT_MODULE_PACKAGE_NAME, GENERATED_ROOT_MODULE_SIMPLE_NAME))
.addField(appGlideModuleClassName, "appGlideModule", Modifier.PRIVATE, Modifier.FINAL)
.addMethod(constructor)
.addMethod(applyOptions)
.addMethod(registerComponents)
.addMethod(isManifestParsingEnabled)
.addMethod(getExcludedModuleClasses);

ClassName generatedRequestManagerFactoryClassName =
ClassName.get(
Expand All @@ -175,17 +174,19 @@ private MethodSpec generateGetExcludedModuleClasses(Collection<String> excludedC
ParameterizedTypeName.get(ClassName.get(Set.class), classOfWildcardOfObjet);
ParameterizedTypeName hashSetOfClassOfWildcardOfObject =
ParameterizedTypeName.get(ClassName.get(HashSet.class), classOfWildcardOfObjet);
MethodSpec.Builder builder = MethodSpec.methodBuilder("getExcludedModuleClasses")
.addModifiers(Modifier.PUBLIC)
.addAnnotation(Override.class)
.addAnnotation(nonNull())
.returns(setOfClassOfWildcardOfObject);
MethodSpec.Builder builder =
MethodSpec.methodBuilder("getExcludedModuleClasses")
.addModifiers(Modifier.PUBLIC)
.addAnnotation(Override.class)
.addAnnotation(nonNull())
.returns(setOfClassOfWildcardOfObject);

if (excludedClassNames.isEmpty()) {
builder.addStatement("return $T.emptySet()", Collections.class);
} else {
builder.addStatement(
"$T excludedClasses = new $T()", setOfClassOfWildcardOfObject,
"$T excludedClasses = new $T()",
setOfClassOfWildcardOfObject,
hashSetOfClassOfWildcardOfObject);
for (String excludedClassName : excludedClassNames) {
// TODO: Remove this when we no longer support manifest parsing.
Expand All @@ -206,21 +207,18 @@ private MethodSpec generateRegisterComponents(
MethodSpec.methodBuilder("registerComponents")
.addModifiers(Modifier.PUBLIC)
.addAnnotation(Override.class)
.addParameter(ParameterSpec.builder(
ClassName.get("android.content", "Context"), "context")
.addAnnotation(nonNull())
.build()
)
.addParameter(ParameterSpec.builder(
ClassName.get("com.bumptech.glide", "Glide"), "glide")
.addAnnotation(nonNull())
.build()
)
.addParameter(ParameterSpec.builder(
ClassName.get("com.bumptech.glide", "Registry"), "registry")
.addAnnotation(nonNull())
.build()
);
.addParameter(
ParameterSpec.builder(ClassName.get("android.content", "Context"), "context")
.addAnnotation(nonNull())
.build())
.addParameter(
ParameterSpec.builder(ClassName.get("com.bumptech.glide", "Glide"), "glide")
.addAnnotation(nonNull())
.build())
.addParameter(
ParameterSpec.builder(ClassName.get("com.bumptech.glide", "Registry"), "registry")
.addAnnotation(nonNull())
.build());

for (String glideModule : libraryGlideModuleClassNames) {
if (excludedGlideModuleClassNames.contains(glideModule)) {
Expand All @@ -235,7 +233,8 @@ private MethodSpec generateRegisterComponents(
return registerComponents.build();
}

private MethodSpec generateConstructor(ClassName appGlideModule,
private MethodSpec generateConstructor(
ClassName appGlideModule,
Collection<String> libraryGlideModuleClassNames,
Collection<String> excludedGlideModuleClassNames) {
MethodSpec.Builder constructorBuilder = MethodSpec.constructorBuilder();
Expand All @@ -244,17 +243,26 @@ private MethodSpec generateConstructor(ClassName appGlideModule,
ClassName androidLogName = ClassName.get("android.util", "Log");

// Add some log lines to indicate to developers which modules where discovered.
constructorBuilder.beginControlFlow("if ($T.isLoggable($S, $T.DEBUG))",
androidLogName, GLIDE_LOG_TAG, androidLogName);
constructorBuilder.addStatement("$T.d($S, $S)", androidLogName, GLIDE_LOG_TAG,
constructorBuilder.beginControlFlow(
"if ($T.isLoggable($S, $T.DEBUG))", androidLogName, GLIDE_LOG_TAG, androidLogName);
constructorBuilder.addStatement(
"$T.d($S, $S)",
androidLogName,
GLIDE_LOG_TAG,
"Discovered AppGlideModule from annotation: " + appGlideModule);
// Excluded GlideModule classes from the manifest are logged in Glide's singleton.
for (String glideModule : libraryGlideModuleClassNames) {
if (excludedGlideModuleClassNames.contains(glideModule)) {
constructorBuilder.addStatement("$T.d($S, $S)", androidLogName, GLIDE_LOG_TAG,
constructorBuilder.addStatement(
"$T.d($S, $S)",
androidLogName,
GLIDE_LOG_TAG,
"AppGlideModule excludes LibraryGlideModule from annotation: " + glideModule);
} else {
constructorBuilder.addStatement("$T.d($S, $S)", androidLogName, GLIDE_LOG_TAG,
constructorBuilder.addStatement(
"$T.d($S, $S)",
androidLogName,
GLIDE_LOG_TAG,
"Discovered LibraryGlideModule from annotation: " + glideModule);
}
}
Expand All @@ -263,8 +271,8 @@ private MethodSpec generateConstructor(ClassName appGlideModule,
}

private List<String> getExcludedGlideModuleClassNames(TypeElement appGlideModule) {
Set<String> names = processorUtil.findClassValuesFromAnnotationOnClassAsNames(
appGlideModule, Excludes.class);
Set<String> names =
processorUtil.findClassValuesFromAnnotationOnClassAsNames(appGlideModule, Excludes.class);
List<String> result = new ArrayList<>(names);
Collections.sort(result);
return result;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,8 @@
import javax.lang.model.element.TypeElement;

/**
* Runs the final steps of Glide's annotation process and generates the combined
* {@code AppGlideModule}, {@code com.bumptech.glide.Glide},
* {@code com.bumptech.glide.RequestManager}, and
* Runs the final steps of Glide's annotation process and generates the combined {@code
* AppGlideModule}, {@code com.bumptech.glide.Glide}, {@code com.bumptech.glide.RequestManager}, and
* {@code com.bumptech.glide.request.RequestOptions} classes.
*/
final class AppModuleProcessor {
Expand Down Expand Up @@ -46,11 +45,11 @@ final class AppModuleProcessor {
}

void processModules(Set<? extends TypeElement> set, RoundEnvironment env) {
for (TypeElement element : processorUtil.getElementsFor(GlideModule.class, env)) {
if (processorUtil.isAppGlideModule(element)) {
appGlideModules.add(element);
}
}
for (TypeElement element : processorUtil.getElementsFor(GlideModule.class, env)) {
if (processorUtil.isAppGlideModule(element)) {
appGlideModules.add(element);
}
}

processorUtil.debugLog("got app modules: " + appGlideModules);

Expand Down Expand Up @@ -84,8 +83,8 @@ boolean maybeWriteAppModule() {
String generatedCodePackageName = appModule.getEnclosingElement().toString();

TypeSpec generatedRequestOptions =
requestOptionsGenerator.generate(generatedCodePackageName, indexedClassNames.extensions);
writeRequestOptions(generatedCodePackageName, generatedRequestOptions);
requestOptionsGenerator.generate(generatedCodePackageName, indexedClassNames.extensions);
writeRequestOptions(generatedCodePackageName, generatedRequestOptions);

TypeSpec generatedRequestBuilder =
requestBuilderGenerator.generate(
Expand All @@ -94,7 +93,9 @@ boolean maybeWriteAppModule() {

TypeSpec requestManager =
requestManagerGenerator.generate(
generatedCodePackageName, generatedRequestOptions, generatedRequestBuilder,
generatedCodePackageName,
generatedRequestOptions,
generatedRequestBuilder,
indexedClassNames.extensions);
writeRequestManager(generatedCodePackageName, requestManager);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
import javax.lang.model.element.TypeElement;

/**
* Writes Indexer classes annotated with {@link Index} for all
* classes found annotated with {@link GlideExtension}.
* Writes Indexer classes annotated with {@link Index} for all classes found annotated with {@link
* GlideExtension}.
*/
final class ExtensionProcessor {
private final ProcessorUtil processorUtil;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,52 +16,48 @@
* Generates classes based on Glide's annotations that configure Glide, add support for additional
* resource types, and/or extend Glide's API.
*
* <p>This processor discovers all {@code AppGlideModule} and
* {@code LibraryGlideModule} implementations that are
* annotated with {@link com.bumptech.glide.annotation.GlideModule}. Any implementations missing the
* annotation will be ignored.
* <p>This processor discovers all {@code AppGlideModule} and {@code LibraryGlideModule}
* implementations that are annotated with {@link com.bumptech.glide.annotation.GlideModule}. Any
* implementations missing the annotation will be ignored.
*
* <p>This processor also discovers all {@link com.bumptech.glide.annotation.GlideExtension}
* annotated classes.
*
* <p>Multiple classes are generated by this processor:
*
* <ul>
* <li>For {@code LibraryGlideModule}s - A GlideIndexer class in a
* specific package that will later be used by the processor to discover all
* {@code LibraryGlideModule} classes.
* <li>For {@code AppGlideModule}s - A single
* {@code AppGlideModule} implementation
* ({@code com.bumptech.glide.GeneratedAppGlideModule}) that calls all
* {@code LibraryGlideModule}s and the
* original {@code AppGlideModule} in the correct order when Glide is
* initialized.
* <li>For {@code LibraryGlideModule}s - A GlideIndexer class in a specific package that will
* later be used by the processor to discover all {@code LibraryGlideModule} classes.
* <li>For {@code AppGlideModule}s - A single {@code AppGlideModule} implementation ({@code
* com.bumptech.glide.GeneratedAppGlideModule}) that calls all {@code LibraryGlideModule}s and
* the original {@code AppGlideModule} in the correct order when Glide is initialized.
* <li>{@link com.bumptech.glide.annotation.GlideExtension}s -
* <ul>
* <li>A {@code com.bumptech.glide.request.RequestOptions} implementation that contains
* static versions of all builder methods in the base class and both static and instance
* versions of methods in all {@link com.bumptech.glide.annotation.GlideExtension}s.
* <li>If one or more methods in one or more
* {@link com.bumptech.glide.annotation.GlideExtension} annotated classes are annotated with
* {@link GlideType}:
* <ul>
* <li>A {@code com.bumptech.glide.RequestManager} implementation containing a generated
* method for each method annotated with
* {@link GlideType}.
* <li>A {@code com.bumptech.glide.manager.RequestManagerRetriever.RequestManagerFactory}
* implementation that produces the generated {@code com.bumptech.glide.RequestManager}s.
* <li>A {@code com.bumptech.glide.Glide} look-alike that implements all static methods in
* the {@code com.bumptech.glide.Glide} singleton and returns the generated
* {@code com.bumptech.glide.RequestManager} implementation when appropriate.
* </ul>
* </ul>
* <ul>
* <li>A {@code com.bumptech.glide.request.RequestOptions} implementation that contains
* static versions of all builder methods in the base class and both static and instance
* versions of methods in all {@link com.bumptech.glide.annotation.GlideExtension}s.
* <li>If one or more methods in one or more {@link
* com.bumptech.glide.annotation.GlideExtension} annotated classes are annotated with
* {@link GlideType}:
* <ul>
* <li>A {@code com.bumptech.glide.RequestManager} implementation containing a
* generated method for each method annotated with {@link GlideType}.
* <li>A {@code
* com.bumptech.glide.manager.RequestManagerRetriever.RequestManagerFactory}
* implementation that produces the generated {@code
* com.bumptech.glide.RequestManager}s.
* <li>A {@code com.bumptech.glide.Glide} look-alike that implements all static
* methods in the {@code com.bumptech.glide.Glide} singleton and returns the
* generated {@code com.bumptech.glide.RequestManager} implementation when
* appropriate.
* </ul>
* </ul>
* </ul>
*
* <p>{@code AppGlideModule} implementations must only be included in
* applications, not in libraries. There must be exactly one
* {@code AppGlideModule} implementation per
* Application. The {@code AppGlideModule} class is
* used as a signal that all modules have been found and that the final merged
* {@code com.bumptech.glide.GeneratedAppGlideModule} impl can be created.
* <p>{@code AppGlideModule} implementations must only be included in applications, not in
* libraries. There must be exactly one {@code AppGlideModule} implementation per Application. The
* {@code AppGlideModule} class is used as a signal that all modules have been found and that the
* final merged {@code com.bumptech.glide.GeneratedAppGlideModule} impl can be created.
*/
@AutoService(Processor.class)
public final class GlideAnnotationProcessor extends AbstractProcessor {
Expand Down Expand Up @@ -96,25 +92,25 @@ public SourceVersion getSupportedSourceVersion() {
return SourceVersion.latestSupported();
}

/**
* Each round we do the following:
* <ol>
* <li>Find all {@code AppGlideModule}s and save them to an instance variable (throw if > 1).
* <li>Find all {@code LibraryGlideModule}s
* <li>For each {@code LibraryGlideModule},
* write an {@code Indexer} with an Annotation with the class name.
* <li>If we wrote any {@code Indexer}s, return and wait for the next round.
* <li>If we didn't write any {@code Indexer}s and there is a {@code AppGlideModule},
* write the {@code GeneratedAppGlideModule}.
* Once the {@code GeneratedAppGlideModule} is written, we expect to be finished.
* Any further generation of related classes will result in errors.
* </ol>
*/
/**
* Each round we do the following:
*
* <ol>
* <li>Find all {@code AppGlideModule}s and save them to an instance variable (throw if > 1).
* <li>Find all {@code LibraryGlideModule}s
* <li>For each {@code LibraryGlideModule}, write an {@code Indexer} with an Annotation with the
* class name.
* <li>If we wrote any {@code Indexer}s, return and wait for the next round.
* <li>If we didn't write any {@code Indexer}s and there is a {@code AppGlideModule}, write the
* {@code GeneratedAppGlideModule}. Once the {@code GeneratedAppGlideModule} is written, we
* expect to be finished. Any further generation of related classes will result in errors.
* </ol>
*/
@Override
public boolean process(Set<? extends TypeElement> set, RoundEnvironment env) {
// if (set.isEmpty() && !isGeneratedAppGlideModulePending) {
// return false;
// }
// if (set.isEmpty() && !isGeneratedAppGlideModulePending) {
// return false;
// }
processorUtil.process();
boolean newModulesWritten = libraryModuleProcessor.processModules(env);
boolean newExtensionWritten = extensionProcessor.processExtensions(env);
Expand Down
Loading

0 comments on commit 0dcc33f

Please sign in to comment.