Skip to content

Commit

Permalink
Add missing annotations on APT overriding methods (#2779)
Browse files Browse the repository at this point in the history
* Run tests for annotation compiler

* @nonnull GeneratedAppGlideModuleImpl.getExcludedModuleClasses

* @nonnull RequestBuilder.getDownloadOnlyRequest

* @nonnull RequestManager.as

* Fix Gradle deprecation warning (file(File) -> files(Object))
  • Loading branch information
TWiStErRob authored and sjudd committed Jan 2, 2018
1 parent fd73179 commit d7bb6f9
Show file tree
Hide file tree
Showing 25 changed files with 45 additions and 8 deletions.
5 changes: 4 additions & 1 deletion annotation/compiler/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ dependencies {
compile files(Jvm.current().getToolsJar())
}

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

def packagingFolder = file("${buildDir}/intermediates")
def repackagedJar = file("${packagingFolder}/repackaged.jar")
def proguardedJar = file("${packagingFolder}/proguarded.jar")
Expand All @@ -34,7 +37,7 @@ task compiledJar(type: Jar, dependsOn: classes) {
// Repackage compileOnly dependencies to avoid namespace collisions.
task jarjar(dependsOn: [tasks.compiledJar, configurations.compileOnly]) {
// Set up inputs and outputs to only rebuild when necessary (code change, dependency change).
inputs.file compiledJar
inputs.files compiledJar
inputs.files configurations.compileOnly
outputs.file repackagedJar

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@
* }
*
* {@literal @java.lang.Override}
* public java.util.Set<java.lang.Class<?>> getExcludedModuleClasses() {
* {@literal @android.support.annotation.NonNull}
* public java.util.Set&lt;java.lang.Class&lt;?>> getExcludedModuleClasses() {
* return appGlideModule.getExcludedModuleClasses();
* }
* }
Expand Down Expand Up @@ -164,6 +165,7 @@ private MethodSpec generateGetExcludedModuleClasses(Collection<String> excludedC
MethodSpec.Builder builder = MethodSpec.methodBuilder("getExcludedModuleClasses")
.addModifiers(Modifier.PUBLIC)
.addAnnotation(Override.class)
.addAnnotation(ClassName.get("android.support.annotation", "NonNull"))
.returns(setOfClassOfWildcardOfObject);

if (excludedClassNames.isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,9 @@ final class RequestBuilderGenerator {
ImmutableSet.of("clone", "apply", "autoLock", "lock", "autoClone");
private static final ClassName CHECK_RESULT_CLASS_NAME =
ClassName.get("android.support.annotation", "CheckResult");
private static final AnnotationSpec NON_NULL = AnnotationSpec
.builder(ClassName.get("android.support.annotation", "NonNull"))
.build();

private final ProcessingEnvironment processingEnv;
private final ProcessorUtil processorUtil;
Expand Down Expand Up @@ -429,6 +432,7 @@ private MethodSpec generateDownloadOnlyRequestMethod() {
return MethodSpec.methodBuilder("getDownloadOnlyRequest")
.addAnnotation(Override.class)
.addAnnotation(AnnotationSpec.builder(CHECK_RESULT_CLASS_NAME).build())
.addAnnotation(NON_NULL)
.returns(generatedRequestBuilderOfFile)
.addModifiers(Modifier.PROTECTED)
.addStatement("return new $T<>($T.class, $N).apply($N)",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ final class RequestManagerGenerator {
ClassName.get("android.support.annotation", "NonNull");
private static final ClassName CONTEXT_CLASS_NAME =
ClassName.get("android.content", "Context");
private static final AnnotationSpec NON_NULL = AnnotationSpec
.builder(ClassName.get("android.support.annotation", "NonNull"))
.build();

private static final String GENERATED_REQUEST_MANAGER_SIMPLE_NAME =
"GlideRequests";
Expand Down Expand Up @@ -151,10 +154,11 @@ private MethodSpec generateAsMethod(String generatedCodePackageName, TypeSpec re
return MethodSpec.methodBuilder("as")
.addModifiers(Modifier.PUBLIC)
.addAnnotation(Override.class)
.addTypeVariable(TypeVariableName.get("ResourceType"))
.addParameter(classOfResouceType, "resourceClass")
.addAnnotation(AnnotationSpec.builder(CHECK_RESULT_CLASS_NAME).build())
.addAnnotation(NON_NULL)
.addTypeVariable(TypeVariableName.get("ResourceType"))
.returns(requestBuilderOfResourceType)
.addParameter(classOfResouceType.annotated(NON_NULL), "resourceClass")
.addStatement("return new $T<>(glide, this, resourceClass, context)",
this.generatedRequestBuilderClassName)
.build();
Expand All @@ -166,7 +170,6 @@ private List<MethodSpec> generateRequestManagerRequestManagerMethodOverrides(
return FluentIterable.from(
processorUtil.findInstanceMethodsReturning(requestManagerType, requestManagerType))
.transform(new Function<ExecutableElement, MethodSpec>() {
@Nullable
@Override
public MethodSpec apply(@Nullable ExecutableElement input) {
return generateRequestManagerRequestManagerMethodOverride(generatedPackageName, input);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.bumptech.glide;

import android.content.Context;
import android.support.annotation.NonNull;
import android.util.Log;
import com.bumptech.glide.test.AppModuleWithExcludes;
import java.lang.Class;
Expand Down Expand Up @@ -37,6 +38,7 @@ public boolean isManifestParsingEnabled() {
}

@Override
@NonNull
public Set<Class<?>> getExcludedModuleClasses() {
Set<Class<?>> excludedClasses = new HashSet<Class<?>>();
excludedClasses.add(com.bumptech.glide.test.EmptyLibraryModule.class);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.bumptech.glide;

import android.content.Context;
import android.support.annotation.NonNull;
import android.util.Log;
import com.bumptech.glide.test.AppModuleWithMultipleExcludes;
import java.lang.Class;
Expand Down Expand Up @@ -38,6 +39,7 @@ public boolean isManifestParsingEnabled() {
}

@Override
@NonNull
public Set<Class<?>> getExcludedModuleClasses() {
Set<Class<?>> excludedClasses = new HashSet<Class<?>>();
excludedClasses.add(com.bumptech.glide.test.EmptyLibraryModule1.class);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.bumptech.glide;

import android.content.Context;
import android.support.annotation.NonNull;
import android.util.Log;
import com.bumptech.glide.test.EmptyAppModule;
import com.bumptech.glide.test.EmptyLibraryModule;
Expand Down Expand Up @@ -39,6 +40,7 @@ public boolean isManifestParsingEnabled() {
}

@Override
@NonNull
public Set<Class<?>> getExcludedModuleClasses() {
return Collections.emptySet();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.bumptech.glide;

import android.content.Context;
import android.support.annotation.NonNull;
import android.util.Log;
import com.bumptech.glide.test.EmptyAppModule;
import java.lang.Class;
Expand Down Expand Up @@ -36,6 +37,7 @@ public boolean isManifestParsingEnabled() {
}

@Override
@NonNull
public Set<Class<?>> getExcludedModuleClasses() {
return Collections.emptySet();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ public class GlideRequest<TranscodeType> extends RequestBuilder<TranscodeType> i

@Override
@CheckResult
@NonNull
protected GlideRequest<File> getDownloadOnlyRequest() {
return new GlideRequest<>(File.class, this).apply(DOWNLOAD_ONLY_OPTIONS);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ public GlideRequests(Glide glide, Lifecycle lifecycle, RequestManagerTreeNode tr

@Override
@CheckResult
public <ResourceType> GlideRequest<ResourceType> as(Class<ResourceType> resourceClass) {
@NonNull
public <ResourceType> GlideRequest<ResourceType> as(@NonNull Class<ResourceType> resourceClass) {
return new GlideRequest<>(glide, this, resourceClass, context);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ public class GlideRequest<TranscodeType> extends RequestBuilder<TranscodeType> i

@Override
@CheckResult
@NonNull
protected GlideRequest<File> getDownloadOnlyRequest() {
return new GlideRequest<>(File.class, this).apply(DOWNLOAD_ONLY_OPTIONS);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ public class GlideRequest<TranscodeType> extends RequestBuilder<TranscodeType> i

@Override
@CheckResult
@NonNull
protected GlideRequest<File> getDownloadOnlyRequest() {
return new GlideRequest<>(File.class, this).apply(DOWNLOAD_ONLY_OPTIONS);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ public class GlideRequest<TranscodeType> extends RequestBuilder<TranscodeType> i

@Override
@CheckResult
@NonNull
protected GlideRequest<File> getDownloadOnlyRequest() {
return new GlideRequest<>(File.class, this).apply(DOWNLOAD_ONLY_OPTIONS);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ public class GlideRequest<TranscodeType> extends RequestBuilder<TranscodeType> i

@Override
@CheckResult
@NonNull
protected GlideRequest<File> getDownloadOnlyRequest() {
return new GlideRequest<>(File.class, this).apply(DOWNLOAD_ONLY_OPTIONS);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ public class GlideRequest<TranscodeType> extends RequestBuilder<TranscodeType> i

@Override
@CheckResult
@NonNull
protected GlideRequest<File> getDownloadOnlyRequest() {
return new GlideRequest<>(File.class, this).apply(DOWNLOAD_ONLY_OPTIONS);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ public class GlideRequest<TranscodeType> extends RequestBuilder<TranscodeType> i

@Override
@CheckResult
@NonNull
protected GlideRequest<File> getDownloadOnlyRequest() {
return new GlideRequest<>(File.class, this).apply(DOWNLOAD_ONLY_OPTIONS);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ public class GlideRequest<TranscodeType> extends RequestBuilder<TranscodeType> i

@Override
@CheckResult
@NonNull
protected GlideRequest<File> getDownloadOnlyRequest() {
return new GlideRequest<>(File.class, this).apply(DOWNLOAD_ONLY_OPTIONS);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ public GlideRequests(Glide glide, Lifecycle lifecycle, RequestManagerTreeNode tr

@Override
@CheckResult
public <ResourceType> GlideRequest<ResourceType> as(Class<ResourceType> resourceClass) {
@NonNull
public <ResourceType> GlideRequest<ResourceType> as(@NonNull Class<ResourceType> resourceClass) {
return new GlideRequest<>(glide, this, resourceClass, context);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ public class GlideRequest<TranscodeType> extends RequestBuilder<TranscodeType> i

@Override
@CheckResult
@NonNull
protected GlideRequest<File> getDownloadOnlyRequest() {
return new GlideRequest<>(File.class, this).apply(DOWNLOAD_ONLY_OPTIONS);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ public class GlideRequest<TranscodeType> extends RequestBuilder<TranscodeType> i

@Override
@CheckResult
@NonNull
protected GlideRequest<File> getDownloadOnlyRequest() {
return new GlideRequest<>(File.class, this).apply(DOWNLOAD_ONLY_OPTIONS);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ public class GlideRequest<TranscodeType> extends RequestBuilder<TranscodeType> i

@Override
@CheckResult
@NonNull
protected GlideRequest<File> getDownloadOnlyRequest() {
return new GlideRequest<>(File.class, this).apply(DOWNLOAD_ONLY_OPTIONS);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ public class GlideRequest<TranscodeType> extends RequestBuilder<TranscodeType> i

@Override
@CheckResult
@NonNull
protected GlideRequest<File> getDownloadOnlyRequest() {
return new GlideRequest<>(File.class, this).apply(DOWNLOAD_ONLY_OPTIONS);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ public class GlideRequest<TranscodeType> extends RequestBuilder<TranscodeType> i

@Override
@CheckResult
@NonNull
protected GlideRequest<File> getDownloadOnlyRequest() {
return new GlideRequest<>(File.class, this).apply(DOWNLOAD_ONLY_OPTIONS);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ public class GlideRequest<TranscodeType> extends RequestBuilder<TranscodeType> i

@Override
@CheckResult
@NonNull
protected GlideRequest<File> getDownloadOnlyRequest() {
return new GlideRequest<>(File.class, this).apply(DOWNLOAD_ONLY_OPTIONS);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ public GlideRequests(Glide glide, Lifecycle lifecycle, RequestManagerTreeNode tr

@Override
@CheckResult
public <ResourceType> GlideRequest<ResourceType> as(Class<ResourceType> resourceClass) {
@NonNull
public <ResourceType> GlideRequest<ResourceType> as(@NonNull Class<ResourceType> resourceClass) {
return new GlideRequest<>(glide, this, resourceClass, context);
}

Expand Down

0 comments on commit d7bb6f9

Please sign in to comment.