Skip to content

Commit

Permalink
Improved @nonnull annotation check for Kotlin:
Browse files Browse the repository at this point in the history
Kotlin uses `org.jetbrains.annotations.NotNull` for @nonnull annotation, adding support @nonnull annotation is unnecessary. This commit adds JetBrains NonNull annotation check.
  • Loading branch information
mariotaku authored and sjudd committed Mar 2, 2018
1 parent fbf1ffc commit a1f5f10
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package com.bumptech.glide.annotation.compiler;

import static com.bumptech.glide.annotation.compiler.ProcessorUtil.nonNull;
import static com.bumptech.glide.annotation.compiler.ProcessorUtil.nonNulls;

import com.bumptech.glide.annotation.GlideOption;
import com.bumptech.glide.annotation.GlideType;
import com.google.common.base.Function;
import com.google.common.collect.FluentIterable;
import com.squareup.javapoet.ClassName;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
Expand Down Expand Up @@ -273,7 +275,14 @@ public String apply(AnnotationMirror input) {
}
})
.toSet();
if (!annotationNames.contains(nonNull().reflectionName())) {
boolean noNonNull = true;
for (ClassName nonNull : nonNulls()) {
if (annotationNames.contains(nonNull.reflectionName())) {
noNonNull = false;
break;
}
}
if (noNonNull) {
processingEnvironment.getMessager().printMessage(
Kind.WARNING,
getQualifiedMethodName(executableElement)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
Expand Down Expand Up @@ -65,6 +66,8 @@ final class ProcessorUtil {
GlideAnnotationProcessor.class.getPackage().getName();
private static final ClassName NONNULL_ANNOTATION =
ClassName.get("android.support.annotation", "NonNull");
private static final ClassName JETBRAINS_NOTNULL_ANNOTATION =
ClassName.get("org.jetbrains.annotations", "NotNull");

private final ProcessingEnvironment processingEnv;
private final TypeElement appGlideModuleType;
Expand Down Expand Up @@ -338,6 +341,10 @@ static ClassName nonNull() {
return NONNULL_ANNOTATION;
}

static List<ClassName> nonNulls() {
return Arrays.asList(NONNULL_ANNOTATION, JETBRAINS_NOTNULL_ANNOTATION);
}

List<ExecutableElement> findInstanceMethodsReturning(TypeElement clazz, TypeMirror returnType) {
return FluentIterable.from(clazz.getEnclosedElements())
.filter(new FilterPublicMethods(returnType, MethodType.INSTANCE))
Expand Down

0 comments on commit a1f5f10

Please sign in to comment.