From efd946a22736b6223c9695dd55374bd395062669 Mon Sep 17 00:00:00 2001 From: Ankit Date: Wed, 6 Nov 2024 20:08:22 -0800 Subject: [PATCH] Added JUnits for annotation insertion/deletion on array component name --- .../riple/injector/TypeUseAnnotationTest.java | 74 +++++++++++++++++++ 1 file changed, 74 insertions(+) diff --git a/injector/src/test/java/edu/ucr/cs/riple/injector/TypeUseAnnotationTest.java b/injector/src/test/java/edu/ucr/cs/riple/injector/TypeUseAnnotationTest.java index 415b88b62..e2be561dc 100644 --- a/injector/src/test/java/edu/ucr/cs/riple/injector/TypeUseAnnotationTest.java +++ b/injector/src/test/java/edu/ucr/cs/riple/injector/TypeUseAnnotationTest.java @@ -821,4 +821,78 @@ public void nullableArrayDeletionOnReference() { "javax.annotation.Nullable")) .start(); } + + @Test + public void nullableArrayAdditionOnComponentType() { + injectorTestHelper + .addInput( + "Foo.java", + "package test;", + "import javax.annotation.Nullable;", + "public class Foo {", + " Object[] h1 = new Object[4];", + " Map h2;", + " List h3 = new ArrayList<>();", + "}") + .expectOutput( + "package test;", + "import javax.annotation.Nullable;", + "public class Foo {", + " @Nullable Object[] h1 = new Object[4];", + " @Nullable Map<@Nullable String, @Nullable String[]> h2;", + " @Nullable List<@Nullable char[]> h3 = new ArrayList<>();", + "}") + .addChanges( + new AddTypeUseMarkerAnnotation( + new OnField("Foo.java", "test.Foo", Collections.singleton("h1")), + "javax.annotation.Nullable", + ImmutableList.of(ImmutableList.of(1, 0))), + new AddTypeUseMarkerAnnotation( + new OnField("Foo.java", "test.Foo", Collections.singleton("h2")), + "javax.annotation.Nullable", + ImmutableList.of( + ImmutableList.of(0), ImmutableList.of(1, 0), ImmutableList.of(2, 1, 0))), + new AddTypeUseMarkerAnnotation( + new OnField("Foo.java", "test.Foo", Collections.singleton("h3")), + "javax.annotation.Nullable", + ImmutableList.of(ImmutableList.of(0), ImmutableList.of(1, 1, 0)))) + .start(); + } + + @Test + public void nullableArrayDeletionOnComponentType() { + injectorTestHelper + .addInput( + "Foo.java", + "package test;", + "import javax.annotation.Nullable;", + "public class Foo {", + " @Nullable Object[] h1 = new Object[4];", + " @Nullable Map<@Nullable String, @Nullable String[]> h2;", + " @Nullable List<@Nullable char[]> h3 = new ArrayList<>();", + "}") + .expectOutput( + "package test;", + "import javax.annotation.Nullable;", + "public class Foo {", + " Object[] h1 = new Object[4];", + " Map h2;", + " List h3 = new ArrayList<>();", + "}") + .addChanges( + new RemoveTypeUseMarkerAnnotation( + new OnField("Foo.java", "test.Foo", Collections.singleton("h1")), + "javax.annotation.Nullable", + ImmutableList.of(ImmutableList.of(0))), + new RemoveTypeUseMarkerAnnotation( + new OnField("Foo.java", "test.Foo", Collections.singleton("h2")), + "javax.annotation.Nullable", + ImmutableList.of( + ImmutableList.of(0), ImmutableList.of(1, 0), ImmutableList.of(2, 1, 0))), + new RemoveTypeUseMarkerAnnotation( + new OnField("Foo.java", "test.Foo", Collections.singleton("h3")), + "javax.annotation.Nullable", + ImmutableList.of(ImmutableList.of(0), ImmutableList.of(1, 1, 0)))) + .start(); + } }