Skip to content

Commit

Permalink
Rewrite some references to JSpecify @Nullable to prevent their bein…
Browse files Browse the repository at this point in the history
…g rewritten.

RELNOTES=n/a
PiperOrigin-RevId: 382304083
  • Loading branch information
eamonnmcmanus authored and Google Java Core Libraries committed Jun 30, 2021
1 parent c68b2ff commit 2ee7f62
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,9 @@ public void testEqualsParameterAnnotation() throws ReflectiveOperationException
.isAtLeast(8.0);
Class<? extends Annotation> jspecifyNullable;
try {
// We write this using .concat in order to hide it from rewriting rules.
jspecifyNullable =
Class.forName("org.jspecify.nullness.Nullable").asSubclass(Annotation.class);
Class.forName("org".concat(".jspecify.nullness.Nullable")).asSubclass(Annotation.class);
} catch (ClassNotFoundException e) {
throw new AssumptionViolatedException("No JSpecify @Nullable available", e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -560,16 +560,17 @@ static NoNullableRef of(String foo) {
}
}

// Tests that we generate equals(@org.jspecify.nullness.Nullable x) if that annotation is
// Tests that we generate equals(@Nullable x) using JSpecify @Nullable if that annotation is
// available and there is no other @Nullable type annotation mentioned in the @AutoValue class.
// If there *are* other @Nullable type annotations, other test methods here will check that they
// are used instead.
@Test
public void testDefaultToJSpecifyNullable() throws ReflectiveOperationException {
Class<? extends Annotation> jspecifyNullable;
try {
// We write this using .concat in order to hide it from rewriting rules.
jspecifyNullable =
Class.forName("org.jspecify.nullness.Nullable").asSubclass(Annotation.class);
Class.forName("org".concat(".jspecify.nullness.Nullable")).asSubclass(Annotation.class);
} catch (ClassNotFoundException e) {
throw new AssumptionViolatedException("No JSpecify @Nullable available", e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ class Nullables {
*/
static final String NULLABLE_OPTION = "com.google.auto.value.NullableTypeAnnotation";

private static final String DEFAULT_NULLABLE = "org.jspecify.nullness.Nullable";
// We write this using .concat in order to hide it from rewriting rules.
private static final String DEFAULT_NULLABLE = "org".concat(".jspecify.nullness.Nullable");

private final Optional<AnnotationMirror> defaultNullable;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -737,7 +737,7 @@ public void nullableSetterForNonNullableParameter() {
"package foo.bar;",
"",
"import com.google.auto.value.AutoBuilder;",
"import org.jspecify.nullness.Nullable;",
"import org.checkerframework.checker.nullness.qual.Nullable;",
"",
"class Baz {",
" Baz(String thing) {}",
Expand All @@ -750,7 +750,7 @@ public void nullableSetterForNonNullableParameter() {
"}");
JavaFileObject nullableFileObject =
JavaFileObjects.forSourceLines(
"org.jspecify.nullness.Nullable",
"org.checkerframework.checker.nullness.qual.Nullable",
"package org.jspecify.nullness;",
"",
"import java.lang.annotation.ElementType;",
Expand Down

0 comments on commit 2ee7f62

Please sign in to comment.