From b3a27f385d08dd4f114d31317a604f06434bb06e Mon Sep 17 00:00:00 2001 From: Ankit Date: Sun, 12 Jan 2025 13:21:15 -0800 Subject: [PATCH] Use TypeUse Annotations for Jspecify and Checkers frameworks --- .../cs/riple/core/checkers/nullaway/NullAway.java | 14 ++++++++++---- .../java/edu/ucr/cs/riple/core/util/Utility.java | 11 +++++++++++ 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/annotator-core/src/main/java/edu/ucr/cs/riple/core/checkers/nullaway/NullAway.java b/annotator-core/src/main/java/edu/ucr/cs/riple/core/checkers/nullaway/NullAway.java index 9b5f37a20..c2ca6f9e6 100644 --- a/annotator-core/src/main/java/edu/ucr/cs/riple/core/checkers/nullaway/NullAway.java +++ b/annotator-core/src/main/java/edu/ucr/cs/riple/core/checkers/nullaway/NullAway.java @@ -39,6 +39,7 @@ import edu.ucr.cs.riple.injector.changes.AddAnnotation; import edu.ucr.cs.riple.injector.changes.AddMarkerAnnotation; import edu.ucr.cs.riple.injector.changes.AddSingleElementAnnotation; +import edu.ucr.cs.riple.injector.changes.AddTypeUseMarkerAnnotation; import edu.ucr.cs.riple.injector.location.Location; import edu.ucr.cs.riple.injector.location.OnField; import edu.ucr.cs.riple.injector.location.OnParameter; @@ -129,10 +130,15 @@ private NullAwayError deserializeErrorFromTSVLine(ModuleInfo moduleInfo, String if (nonnullTarget != null && nonnullTarget.isOnField()) { nonnullTarget = extendVariableList(nonnullTarget.toField(), moduleInfo); } - Set annotations = - nonnullTarget == null - ? Set.of() - : Set.of(new AddMarkerAnnotation(nonnullTarget, config.nullableAnnot)); + Set annotations; + if (nonnullTarget == null) { + annotations = Set.of(); + } else if (Utility.isTypeUseAnnotation(config.nullableAnnot)) { + annotations = Set.of(new AddTypeUseMarkerAnnotation(nonnullTarget, config.nullableAnnot)); + } else { + annotations = Set.of(new AddMarkerAnnotation(nonnullTarget, config.nullableAnnot)); + } + return createError( errorType, errorMessage, diff --git a/annotator-core/src/main/java/edu/ucr/cs/riple/core/util/Utility.java b/annotator-core/src/main/java/edu/ucr/cs/riple/core/util/Utility.java index 52acc3db7..971d437b8 100644 --- a/annotator-core/src/main/java/edu/ucr/cs/riple/core/util/Utility.java +++ b/annotator-core/src/main/java/edu/ucr/cs/riple/core/util/Utility.java @@ -303,4 +303,15 @@ public static List readFileLines(Path path) { throw new RuntimeException("Exception while reading file: " + path, e); } } + + /** + * Check whether an annotation is a type-use annotation. + * + * @param annotName annotation name + * @return true if we annotName is a type-use annotation, false otherwise + */ + public static boolean isTypeUseAnnotation(String annotName) { + return annotName.contains(".jspecify.annotations.Nullable") + || annotName.contains(".checkerframework.checker.nullness.qual.Nullable"); + } }