Skip to content

Commit

Permalink
Stop recognizing annotations from the old package. (#181)
Browse files Browse the repository at this point in the history
  • Loading branch information
cpovirk authored Jun 26, 2024
1 parent fae43cf commit 5194e00
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 32 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ plugins {
id 'java'
id 'maven-publish'

id 'com.diffplug.spotless' version '6.14.0'
id 'com.diffplug.spotless' version '6.25.0'
id 'io.github.gradle-nexus.publish-plugin' version '1.3.0'
id 'net.ltgt.errorprone' version '3.0.1'
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ final class NullSpecAnnotatedTypeFactory

/** Constructor that takes all configuration from the provided {@code checker}. */
NullSpecAnnotatedTypeFactory(BaseTypeChecker checker, Util util) {
this(checker, util, checker.hasOption("strict"), /*withOtherWorld=*/ null);
this(checker, util, checker.hasOption("strict"), /* withOtherWorld= */ null);
}

/**
Expand All @@ -160,8 +160,6 @@ private NullSpecAnnotatedTypeFactory(

addAliasedTypeAnnotation(
"org.jspecify.annotations.NullnessUnspecified", nullnessOperatorUnspecified);
addAliasedTypeAnnotation(
"org.jspecify.nullness.NullnessUnspecified", nullnessOperatorUnspecified);

// Yes, it's valid to pass declaration annotations to addAliased*Type*Annotation.
NULLABLE_ANNOTATIONS.forEach(a -> addAliasedTypeAnnotation(a, unionNull));
Expand Down Expand Up @@ -190,7 +188,7 @@ private NullSpecAnnotatedTypeFactory(
if (!givenOtherWorld) {
withOtherWorld =
new NullSpecAnnotatedTypeFactory(
checker, util, !isLeastConvenientWorld, /*withOtherWorld=*/ this);
checker, util, !isLeastConvenientWorld, /* withOtherWorld= */ this);
}
if (isLeastConvenientWorld) {
withLeastConvenientWorld = this;
Expand Down Expand Up @@ -299,7 +297,7 @@ public boolean isSubtype(AnnotationMirror subAnno, AnnotationMirror superAnno) {
@Override
protected QualifierKindHierarchy createQualifierKindHierarchy(
Collection<Class<? extends Annotation>> qualifierClasses) {
return new DefaultQualifierKindHierarchy(qualifierClasses, /*bottom=*/ MinusNull.class) {
return new DefaultQualifierKindHierarchy(qualifierClasses, /* bottom= */ MinusNull.class) {
@Override
protected Map<DefaultQualifierKind, Set<DefaultQualifierKind>> createDirectSuperMap() {
DefaultQualifierKind minusNullKind =
Expand Down Expand Up @@ -622,13 +620,13 @@ private final class NullSpecEqualityComparer extends StructuralEqualityComparer

@Override
protected boolean checkOrAreEqual(AnnotatedTypeMirror type1, AnnotatedTypeMirror type2) {
Boolean pastResult = visitHistory.get(type1, type2, /*hierarchy=*/ unionNull);
Boolean pastResult = visitHistory.get(type1, type2, /* hierarchy= */ unionNull);
if (pastResult != null) {
return pastResult;
}

boolean result = areEqual(type1, type2);
this.visitHistory.put(type1, type2, /*hierarchy=*/ unionNull, result);
this.visitHistory.put(type1, type2, /* hierarchy= */ unionNull, result);
return result;
}

Expand Down Expand Up @@ -718,7 +716,7 @@ private final class NullSpecTypeVariableSubstitutor extends TypeVariableSubstitu
@Override
protected AnnotatedTypeMirror substituteTypeVariable(
AnnotatedTypeMirror argument, AnnotatedTypeVariable use) {
AnnotatedTypeMirror substitute = argument.deepCopy(/*copyAnnotations=*/ true);
AnnotatedTypeMirror substitute = argument.deepCopy(/* copyAnnotations= */ true);

/*
* The isNullExclusiveUnderEveryParameterization check handles cases like
Expand Down Expand Up @@ -1529,7 +1527,7 @@ protected AnnotationFormatter createAnnotationFormatter() {
@Override
public String formatAnnotationString(
Collection<? extends AnnotationMirror> annos, boolean printInvisible) {
return super.formatAnnotationString(annos, /*printInvisible=*/ false);
return super.formatAnnotationString(annos, /* printInvisible= */ false);
}
};
}
Expand All @@ -1542,7 +1540,7 @@ protected AnnotatedTypeFormatter createAnnotatedTypeFormatter() {
private final class NullSpecAnnotatedTypeFormatter implements AnnotatedTypeFormatter {
@Override
public String format(AnnotatedTypeMirror type) {
return format(type, /*printVerbose=*/ false);
return format(type, /* printVerbose= */ false);
}

@Override
Expand Down Expand Up @@ -1834,10 +1832,7 @@ private void addIfNoAnnotationPresent(AnnotatedTypeMirror type, AnnotationMirror
*/
private boolean hasNullMarkedOrEquivalent(Element elt) {
return getDeclAnnotations(elt).stream()
.anyMatch(
am ->
areSameByName(am, "org.jspecify.annotations.NullMarked")
|| areSameByName(am, "org.jspecify.nullness.NullMarked"))
.anyMatch(am -> areSameByName(am, "org.jspecify.annotations.NullMarked"))
/*
* We assume that ProtoNonnullApi is like NullMarked in that it guarantees that *all* types
* are non-null, even those that would require type annotations to annotate (e.g.,
Expand All @@ -1849,10 +1844,7 @@ private boolean hasNullMarkedOrEquivalent(Element elt) {

private boolean hasNullUnmarked(Element elt) {
return getDeclAnnotations(elt).stream()
.anyMatch(
am ->
areSameByName(am, "org.jspecify.annotations.NullUnmarked")
|| areSameByName(am, "org.jspecify.nullness.NullUnmarked"));
.anyMatch(am -> areSameByName(am, "org.jspecify.annotations.NullUnmarked"));
}

/**
Expand All @@ -1866,7 +1858,7 @@ private static boolean hasAnnotationInCode(AnnotatedConstruct construct, String
@SuppressWarnings("unchecked") // safety guaranteed by API docs
private <T extends AnnotatedTypeMirror> T withMinusNull(T type) {
// Remove the annotation from the *root* type, but preserve other annotations.
type = (T) type.deepCopy(/*copyAnnotations=*/ true);
type = (T) type.deepCopy(/* copyAnnotations= */ true);
/*
* TODO(cpovirk): In the case of a type-variable usage, I feel like we should need to *remove*
* any existing annotation but then not *add* minusNull. (This is because of the difference
Expand All @@ -1881,14 +1873,14 @@ private <T extends AnnotatedTypeMirror> T withMinusNull(T type) {
@SuppressWarnings("unchecked") // safety guaranteed by API docs
private <T extends AnnotatedTypeMirror> T withUnionNull(T type) {
// Remove the annotation from the *root* type, but preserve other annotations.
type = (T) type.deepCopy(/*copyAnnotations=*/ true);
type = (T) type.deepCopy(/* copyAnnotations= */ true);
type.replaceAnnotation(unionNull);
return type;
}

private AnnotatedDeclaredType createType(TypeElement element) {
return (AnnotatedDeclaredType)
AnnotatedTypeMirror.createType(element.asType(), this, /*isDeclaration=*/ false);
AnnotatedTypeMirror.createType(element.asType(), this, /* isDeclaration= */ false);
}

// Avoid lambdas so that our Predicates can have a useful toString() for logging purposes.
Expand Down Expand Up @@ -1983,7 +1975,6 @@ private enum Present {
"org.jetbrains.annotations.Nullable",
"org.jmlspecs.annotation.Nullable",
"org.jspecify.annotations.Nullable",
"org.jspecify.nullness.Nullable",
"org.json.Nullable",
"org.netbeans.api.annotations.common.CheckForNull",
"org.netbeans.api.annotations.common.NullAllowed",
Expand Down Expand Up @@ -2030,7 +2021,6 @@ private enum Present {
"org.jetbrains.annotations.NotNull",
"org.jmlspecs.annotation.NonNull",
"org.jspecify.annotations.NonNull",
"org.jspecify.nullness.NonNull",
"org.json.NonNull",
"org.netbeans.api.annotations.common.NonNull",
"org.springframework.lang.NonNull",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,6 @@ final class NullSpecStore extends CFAbstractStore<CFValue, NullSpecStore> {
@Override
protected boolean shouldInsert(
JavaExpression expr, CFValue value, boolean permitNondeterministic) {
return super.shouldInsert(expr, value, /*permitNondeterministic=*/ true);
return super.shouldInsert(expr, value, /* permitNondeterministic= */ true);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ private boolean overwriteGetterFromSetter(
argument.getUnderlyingType(),
getter,
setterCall.getReceiver(),
/*arguments=*/ emptyList());
/* arguments= */ emptyList());
return overwrite(getterCall, argument, store);
}

Expand Down Expand Up @@ -788,7 +788,7 @@ private boolean isReflectiveRead(MethodInvocationNode node) {
private AnnotatedTypeMirror typeWithTopLevelAnnotationsOnly(
TransferInput<CFValue, NullSpecStore> input, Node node) {
Set<AnnotationMirror> annotations = input.getValueOfSubNode(node).getAnnotations();
AnnotatedTypeMirror type = createType(node.getType(), atypeFactory, /*isDeclaration=*/ false);
AnnotatedTypeMirror type = createType(node.getType(), atypeFactory, /* isDeclaration= */ false);
type.addAnnotations(annotations);
return type;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ final class NullSpecVisitor extends BaseTypeVisitor<NullSpecAnnotatedTypeFactory
}

private void ensureNonNull(Tree tree) {
ensureNonNull(tree, /*messageKey=*/ "dereference");
ensureNonNull(tree, /* messageKey= */ "dereference");
}

private void ensureNonNull(Tree tree, String messageKey) {
Expand Down Expand Up @@ -590,10 +590,7 @@ private void checkNoNullnessAnnotations(
Set.of(
"org.jspecify.annotations.NonNull",
"org.jspecify.annotations.Nullable",
"org.jspecify.annotations.NullnessUnspecified",
"org.jspecify.nullness.NonNull",
"org.jspecify.nullness.Nullable",
"org.jspecify.nullness.NullnessUnspecified");
"org.jspecify.annotations.NullnessUnspecified");

@Override
protected boolean checkMethodReferenceAsOverride(MemberReferenceTree tree, Void p) {
Expand Down

0 comments on commit 5194e00

Please sign in to comment.