Skip to content

Commit

Permalink
move method for cleaner diff
Browse files Browse the repository at this point in the history
  • Loading branch information
msridhar committed Dec 12, 2024
1 parent 5ada6f0 commit a2eef51
Showing 1 changed file with 38 additions and 38 deletions.
76 changes: 38 additions & 38 deletions nullaway/src/main/java/com/uber/nullaway/NullabilityUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -548,44 +548,6 @@ public static boolean isArrayElementNullable(Symbol arraySymbol, Config config)
Nullness::hasNullableDeclarationAnnotation);
}

/**
* Checks if the annotations on the elements of some array symbol satisfy some predicate.
*
* @param arraySymbol the array symbol
* @param config NullAway configuration
* @param typeUseCheck the predicate to check the type-use annotations
* @param declarationCheck the predicate to check the declaration annotations (applied only to
* varargs symbols)
* @return true if the annotations on the elements of the array symbol satisfy the given
* predicates, false otherwise
*/
private static boolean checkArrayElementAnnotations(
Symbol arraySymbol,
Config config,
BiPredicate<String, Config> typeUseCheck,
BiPredicate<Symbol, Config> declarationCheck) {
if (getTypeUseAnnotations(arraySymbol, config, /* onlyDirect= */ false)
.anyMatch(
t -> {
for (TypeAnnotationPosition.TypePathEntry entry : t.position.location) {
if (entry.tag == TypeAnnotationPosition.TypePathEntryKind.ARRAY) {
if (typeUseCheck.test(t.type.toString(), config)) {
return true;
}
}
}
return false;
})) {
return true;
}
// For varargs symbols we also check for declaration annotations on the parameter
// NOTE this flag check does not work for the varargs parameter of a method defined in bytecodes
if ((arraySymbol.flags() & Flags.VARARGS) != 0) {
return declarationCheck.test(arraySymbol, config);
}
return false;
}

/**
* Checks if the given varargs symbol has a {@code @Nullable} annotation for its elements. Works
* for both source and bytecode.
Expand Down Expand Up @@ -632,6 +594,44 @@ public static boolean nonnullVarargsElementsForSourceOrBytecode(
|| Nullness.hasNonNullDeclarationAnnotation(varargsSymbol, config);
}

/**
* Checks if the annotations on the elements of some array symbol satisfy some predicate.
*
* @param arraySymbol the array symbol
* @param config NullAway configuration
* @param typeUseCheck the predicate to check the type-use annotations
* @param declarationCheck the predicate to check the declaration annotations (applied only to
* varargs symbols)
* @return true if the annotations on the elements of the array symbol satisfy the given
* predicates, false otherwise
*/
private static boolean checkArrayElementAnnotations(
Symbol arraySymbol,
Config config,
BiPredicate<String, Config> typeUseCheck,
BiPredicate<Symbol, Config> declarationCheck) {
if (getTypeUseAnnotations(arraySymbol, config, /* onlyDirect= */ false)
.anyMatch(
t -> {
for (TypeAnnotationPosition.TypePathEntry entry : t.position.location) {
if (entry.tag == TypeAnnotationPosition.TypePathEntryKind.ARRAY) {
if (typeUseCheck.test(t.type.toString(), config)) {
return true;
}
}
}
return false;
})) {
return true;
}
// For varargs symbols we also check for declaration annotations on the parameter
// NOTE this flag check does not work for the varargs parameter of a method defined in bytecodes
if ((arraySymbol.flags() & Flags.VARARGS) != 0) {
return declarationCheck.test(arraySymbol, config);
}
return false;
}

/**
* Does the given symbol have a JetBrains @NotNull declaration annotation? Useful for workarounds
* in light of https://github.com/uber/NullAway/issues/720
Expand Down

0 comments on commit a2eef51

Please sign in to comment.