Skip to content

Commit

Permalink
Remove unused annotation imports in Checker stubs (#1510)
Browse files Browse the repository at this point in the history
  • Loading branch information
PawelLipski authored Feb 4, 2023
1 parent 7a3bb25 commit 250a7ae
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
1 change: 0 additions & 1 deletion config/checker/com.intellij.astub
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@

import org.checkerframework.checker.guieffect.qual.AlwaysSafe;
import org.checkerframework.checker.guieffect.qual.PolyUI;
import org.checkerframework.checker.guieffect.qual.PolyUIEffect;
import org.checkerframework.checker.guieffect.qual.PolyUIType;
import org.checkerframework.checker.guieffect.qual.SafeEffect;
Expand Down
22 changes: 13 additions & 9 deletions scripts/enforce-astub-explicit-annotation-import
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,20 @@ source "$self_dir"/utils.sh
exit_code=0

for file in $(git ls-files '*.astub'); do
# Print the lines present in the first output but missing from the second
# First <(...) covers all annotations used across the file,
# second <(...) covers all symbols imported in the file.
output=$(comm -23 \
<(grep -Po '(?<=@)[a-zA-Z0-9.]*' "$file" | sort -u) \
<(grep -Po '(?<=import ).*(?=;)' "$file" | rev | cut -d. -f1 | rev | sort -u)
)
annotations_imported_in_file=$(grep -Po '(?<=import ).*(?=;)' "$file" | rev | cut -d. -f1 | rev | sort -u)
annotations_used_across_file=$(grep -Po '(?<=@)[a-zA-Z0-9.]*' "$file" | sort -u)

if [[ $output ]]; then
echo "$file: $(echo -n "$output" | tr '\n' ',' | sed 's/,/, /g') must be imported explicitly"
# Print the lines missing from the first input but present in the second
unimported_annotations=$(comm -13 <(echo "$annotations_imported_in_file") <(echo "$annotations_used_across_file"))
if [[ $unimported_annotations ]]; then
echo "$file: $(echo -n "$unimported_annotations" | tr '\n' ',' | sed 's/,/, /g') must be imported explicitly"
exit_code=1
fi

# Print the lines present in the first input but missing from the second
unused_annotations=$(comm -23 <(echo "$annotations_imported_in_file") <(echo "$annotations_used_across_file"))
if [[ $unused_annotations ]]; then
echo "$file: $(echo -n "$unused_annotations" | tr '\n' ',' | sed 's/,/, /g') imported but unused"
exit_code=1
fi
done
Expand Down

0 comments on commit 250a7ae

Please sign in to comment.