Lines 37-42
Link Here
|
37 |
import java.util.Collections; |
37 |
import java.util.Collections; |
38 |
import java.util.EnumSet; |
38 |
import java.util.EnumSet; |
39 |
import java.util.HashMap; |
39 |
import java.util.HashMap; |
|
|
40 |
import java.util.HashSet; |
40 |
import java.util.IdentityHashMap; |
41 |
import java.util.IdentityHashMap; |
41 |
import java.util.Iterator; |
42 |
import java.util.Iterator; |
42 |
import java.util.LinkedList; |
43 |
import java.util.LinkedList; |
Lines 364-399
Link Here
|
364 |
return result; |
365 |
return result; |
365 |
} |
366 |
} |
366 |
|
367 |
|
367 |
private static State getStateFromAnnotations(CompilationInfo info, Element e) { |
|
|
368 |
return getStateFromAnnotations(info, e, State.POSSIBLE_NULL); |
369 |
} |
370 |
|
371 |
private static final AnnotationMirrorGetter OVERRIDE_ANNOTATIONS = Lookup.getDefault().lookup(AnnotationMirrorGetter.class); |
368 |
private static final AnnotationMirrorGetter OVERRIDE_ANNOTATIONS = Lookup.getDefault().lookup(AnnotationMirrorGetter.class); |
372 |
|
369 |
|
373 |
private static State getStateFromAnnotations(CompilationInfo info, Element e, State def) { |
370 |
private static State getStateFromAnnotations(CompilationInfo info, Element e) { |
374 |
if (e == null) return def; |
371 |
if (e == null) { |
|
|
372 |
return State.POSSIBLE_NULL; |
373 |
} |
375 |
|
374 |
|
376 |
Iterable<? extends AnnotationMirror> mirrors = OVERRIDE_ANNOTATIONS != null ? OVERRIDE_ANNOTATIONS.getAnnotationMirrors(info, e) : null; |
375 |
Iterable<? extends AnnotationMirror> mirrors = OVERRIDE_ANNOTATIONS != null ? OVERRIDE_ANNOTATIONS.getAnnotationMirrors(info, e) : null; |
377 |
|
376 |
|
378 |
if (mirrors == null) mirrors = e.getAnnotationMirrors(); |
377 |
if (mirrors == null) { |
|
|
378 |
mirrors = e.getAnnotationMirrors(); |
379 |
} |
379 |
|
380 |
|
380 |
for (AnnotationMirror am : mirrors) { |
381 |
Set<String> names = getSimpleNames(mirrors); |
381 |
String simpleName = ((TypeElement) am.getAnnotationType().asElement()).getSimpleName().toString(); |
|
|
382 |
|
382 |
|
383 |
if ("Nullable".equals(simpleName) || "NullAllowed".equals(simpleName)) { |
383 |
if (containsAny(names, "Nullable", "NullAllowed", "CheckForNull")) { |
384 |
return State.POSSIBLE_NULL_REPORT; |
384 |
return State.POSSIBLE_NULL_REPORT; |
385 |
} |
385 |
} |
386 |
|
386 |
|
387 |
if ("CheckForNull".equals(simpleName)) { |
387 |
if (containsAny(names, "NotNull", "NonNull", "Nonnull")) { |
|
|
388 |
return State.NOT_NULL; |
389 |
} |
390 |
|
391 |
names = getSimpleNames(info.getElements().getPackageOf(e).getAnnotationMirrors()); |
392 |
|
393 |
if (e.getKind() == ElementKind.PARAMETER) { |
394 |
if (names.contains("ParametersAreNonnullByDefault")) { |
395 |
return State.NOT_NULL; |
396 |
} else if (names.contains("ParametersAreNullableByDefault")) { |
388 |
return State.POSSIBLE_NULL_REPORT; |
397 |
return State.POSSIBLE_NULL_REPORT; |
389 |
} |
398 |
} |
390 |
|
399 |
} else if (e.getKind() == ElementKind.METHOD && containsAny(names, "ReturnValuesAreNonnullByDefault", "ReturnTypesAreNonnullByDefault")) { |
391 |
if ("NotNull".equals(simpleName) || "NonNull".equals(simpleName) || "Nonnull".equals(simpleName)) { |
|
|
392 |
return State.NOT_NULL; |
400 |
return State.NOT_NULL; |
393 |
} |
401 |
} |
|
|
402 |
return State.POSSIBLE_NULL; |
394 |
} |
403 |
} |
395 |
|
404 |
|
396 |
return def; |
405 |
private static Set<String> getSimpleNames(Iterable<? extends AnnotationMirror> mirrors) { |
|
|
406 |
Iterator<? extends AnnotationMirror> it = mirrors.iterator(); |
407 |
if (!it.hasNext()) { |
408 |
return Collections.emptySet(); |
409 |
} |
410 |
Set<String> names = new HashSet<String>(); |
411 |
while (it.hasNext()) { |
412 |
names.add(((TypeElement) it.next().getAnnotationType().asElement()).getSimpleName().toString()); |
413 |
} |
414 |
return names; |
415 |
} |
416 |
|
417 |
private static boolean containsAny(Set<String> set, String... values) { |
418 |
if (set.isEmpty()) { |
419 |
return false; |
420 |
} |
421 |
for (String v : values) { |
422 |
if (set.contains(v)) { |
423 |
return true; |
424 |
} |
425 |
} |
426 |
return false; |
397 |
} |
427 |
} |
398 |
|
428 |
|
399 |
public interface AnnotationMirrorGetter { |
429 |
public interface AnnotationMirrorGetter { |