From 3f0fec18726fb9c9f4dce614dbcfa650c1c04bf7 Mon Sep 17 00:00:00 2001 From: Reinier Zwitserloot Date: Fri, 31 Jan 2020 15:58:19 +0100 Subject: [issue #788] Add more nullity annotations where relevant (chainable setters, static constructors, builder stuff) --- .../after-delombok/BuilderSingularNullBehavior1.java | 15 ++++++++------- .../after-delombok/BuilderSingularNullBehavior2.java | 5 +++++ .../resource/after-delombok/StaticConstructor.java | 12 ++++++++++++ test/transform/resource/after-delombok/WithPlain.java | 2 ++ .../resource/after-ecj/BuilderSingularNullBehavior1.java | 16 ++++++++-------- .../resource/after-ecj/BuilderSingularNullBehavior2.java | 10 +++++----- test/transform/resource/after-ecj/StaticConstructor.java | 11 +++++++++++ test/transform/resource/after-ecj/WithPlain.java | 4 ++-- test/transform/resource/before/StaticConstructor.java | 6 ++++++ .../resource/before/ValueStaticConstructorOf.java | 13 ++++++------- test/transform/resource/before/WithPlain.java | 1 + 11 files changed, 66 insertions(+), 29 deletions(-) create mode 100644 test/transform/resource/after-delombok/StaticConstructor.java create mode 100644 test/transform/resource/after-ecj/StaticConstructor.java create mode 100644 test/transform/resource/before/StaticConstructor.java (limited to 'test/transform') diff --git a/test/transform/resource/after-delombok/BuilderSingularNullBehavior1.java b/test/transform/resource/after-delombok/BuilderSingularNullBehavior1.java index 55420ac2..32ad0a68 100644 --- a/test/transform/resource/after-delombok/BuilderSingularNullBehavior1.java +++ b/test/transform/resource/after-delombok/BuilderSingularNullBehavior1.java @@ -18,31 +18,31 @@ class BuilderSingularNullBehavior1 { BuilderSingularNullBehavior1Builder() { } @java.lang.SuppressWarnings("all") - public BuilderSingularNullBehavior1.BuilderSingularNullBehavior1Builder name(final String name) { + public BuilderSingularNullBehavior1.@org.checkerframework.checker.nullness.qual.NonNull BuilderSingularNullBehavior1Builder name(final String name) { if (this.names == null) this.names = new java.util.ArrayList(); this.names.add(name); return this; } @java.lang.SuppressWarnings("all") - public BuilderSingularNullBehavior1.BuilderSingularNullBehavior1Builder names(final java.util.@org.checkerframework.checker.nullness.qual.NonNull Collection names) { + public BuilderSingularNullBehavior1.@org.checkerframework.checker.nullness.qual.NonNull BuilderSingularNullBehavior1Builder names(final java.util.@org.checkerframework.checker.nullness.qual.NonNull Collection names) { assert names != null : "names cannot be null"; if (this.names == null) this.names = new java.util.ArrayList(); this.names.addAll(names); return this; } @java.lang.SuppressWarnings("all") - public BuilderSingularNullBehavior1.BuilderSingularNullBehavior1Builder clearNames() { + public BuilderSingularNullBehavior1.@org.checkerframework.checker.nullness.qual.NonNull BuilderSingularNullBehavior1Builder clearNames() { if (this.names != null) this.names.clear(); return this; } @java.lang.SuppressWarnings("all") - public BuilderSingularNullBehavior1.BuilderSingularNullBehavior1Builder location(final String location) { + public BuilderSingularNullBehavior1.@org.checkerframework.checker.nullness.qual.NonNull BuilderSingularNullBehavior1Builder location(final String location) { if (this.locations == null) this.locations = new java.util.ArrayList(); this.locations.add(location); return this; } @java.lang.SuppressWarnings("all") - public BuilderSingularNullBehavior1.BuilderSingularNullBehavior1Builder locations(final java.util.@org.checkerframework.checker.nullness.qual.Nullable Collection locations) { + public BuilderSingularNullBehavior1.@org.checkerframework.checker.nullness.qual.NonNull BuilderSingularNullBehavior1Builder locations(final java.util.@org.checkerframework.checker.nullness.qual.Nullable Collection locations) { if (locations != null) { if (this.locations == null) this.locations = new java.util.ArrayList(); this.locations.addAll(locations); @@ -50,10 +50,11 @@ class BuilderSingularNullBehavior1 { return this; } @java.lang.SuppressWarnings("all") - public BuilderSingularNullBehavior1.BuilderSingularNullBehavior1Builder clearLocations() { + public BuilderSingularNullBehavior1.@org.checkerframework.checker.nullness.qual.NonNull BuilderSingularNullBehavior1Builder clearLocations() { if (this.locations != null) this.locations.clear(); return this; } + @org.checkerframework.checker.nullness.qual.NonNull @java.lang.SuppressWarnings("all") public BuilderSingularNullBehavior1 build() { java.util.List names; @@ -87,7 +88,7 @@ class BuilderSingularNullBehavior1 { } } @java.lang.SuppressWarnings("all") - public static BuilderSingularNullBehavior1.BuilderSingularNullBehavior1Builder builder() { + public static BuilderSingularNullBehavior1.@org.checkerframework.checker.nullness.qual.NonNull BuilderSingularNullBehavior1Builder builder() { return new BuilderSingularNullBehavior1.BuilderSingularNullBehavior1Builder(); } } diff --git a/test/transform/resource/after-delombok/BuilderSingularNullBehavior2.java b/test/transform/resource/after-delombok/BuilderSingularNullBehavior2.java index ba70002b..e70877bf 100644 --- a/test/transform/resource/after-delombok/BuilderSingularNullBehavior2.java +++ b/test/transform/resource/after-delombok/BuilderSingularNullBehavior2.java @@ -12,12 +12,14 @@ class BuilderSingularNullBehavior2 { @java.lang.SuppressWarnings("all") BuilderSingularNullBehavior2Builder() { } + @org.springframework.lang.NonNull @java.lang.SuppressWarnings("all") public BuilderSingularNullBehavior2.BuilderSingularNullBehavior2Builder location(final String location) { if (this.locations == null) this.locations = new java.util.ArrayList(); this.locations.add(location); return this; } + @org.springframework.lang.NonNull @java.lang.SuppressWarnings("all") public BuilderSingularNullBehavior2.BuilderSingularNullBehavior2Builder locations(@org.springframework.lang.NonNull final java.util.Collection locations) { java.util.Objects.requireNonNull(locations, "locations cannot be null"); @@ -25,11 +27,13 @@ class BuilderSingularNullBehavior2 { this.locations.addAll(locations); return this; } + @org.springframework.lang.NonNull @java.lang.SuppressWarnings("all") public BuilderSingularNullBehavior2.BuilderSingularNullBehavior2Builder clearLocations() { if (this.locations != null) this.locations.clear(); return this; } + @org.springframework.lang.NonNull @java.lang.SuppressWarnings("all") public BuilderSingularNullBehavior2 build() { java.util.List locations; @@ -52,6 +56,7 @@ class BuilderSingularNullBehavior2 { return "BuilderSingularNullBehavior2.BuilderSingularNullBehavior2Builder(locations=" + this.locations + ")"; } } + @org.springframework.lang.NonNull @java.lang.SuppressWarnings("all") public static BuilderSingularNullBehavior2.BuilderSingularNullBehavior2Builder builder() { return new BuilderSingularNullBehavior2.BuilderSingularNullBehavior2Builder(); diff --git a/test/transform/resource/after-delombok/StaticConstructor.java b/test/transform/resource/after-delombok/StaticConstructor.java new file mode 100644 index 00000000..f9c862d7 --- /dev/null +++ b/test/transform/resource/after-delombok/StaticConstructor.java @@ -0,0 +1,12 @@ +public class StaticConstructor { + String name; + @java.lang.SuppressWarnings("all") + private StaticConstructor(final String name) { + this.name = name; + } + @org.checkerframework.checker.nullness.qual.NonNull + @java.lang.SuppressWarnings("all") + public static StaticConstructor of(final String name) { + return new StaticConstructor(name); + } +} \ No newline at end of file diff --git a/test/transform/resource/after-delombok/WithPlain.java b/test/transform/resource/after-delombok/WithPlain.java index 1a6ff22f..01fca04e 100644 --- a/test/transform/resource/after-delombok/WithPlain.java +++ b/test/transform/resource/after-delombok/WithPlain.java @@ -5,10 +5,12 @@ class WithPlain { this.i = i; this.foo = foo; } + @org.springframework.lang.NonNull @java.lang.SuppressWarnings("all") public WithPlain withI(final int i) { return this.i == i ? this : new WithPlain(i, this.foo); } + @org.springframework.lang.NonNull @java.lang.SuppressWarnings("all") public WithPlain withFoo(final int foo) { return this.foo == foo ? this : new WithPlain(this.i, foo); diff --git a/test/transform/resource/after-ecj/BuilderSingularNullBehavior1.java b/test/transform/resource/after-ecj/BuilderSingularNullBehavior1.java index a0725f8a..94ef45eb 100644 --- a/test/transform/resource/after-ecj/BuilderSingularNullBehavior1.java +++ b/test/transform/resource/after-ecj/BuilderSingularNullBehavior1.java @@ -8,31 +8,31 @@ import lombok.Singular; @java.lang.SuppressWarnings("all") BuilderSingularNullBehavior1Builder() { super(); } - public @java.lang.SuppressWarnings("all") BuilderSingularNullBehavior1.BuilderSingularNullBehavior1Builder name(final String name) { + public @java.lang.SuppressWarnings("all") BuilderSingularNullBehavior1.@org.checkerframework.checker.nullness.qual.NonNull BuilderSingularNullBehavior1Builder name(final String name) { if ((this.names == null)) this.names = new java.util.ArrayList(); this.names.add(name); return this; } - public @java.lang.SuppressWarnings("all") BuilderSingularNullBehavior1.BuilderSingularNullBehavior1Builder names(final java.util. @org.checkerframework.checker.nullness.qual.NonNull Collection names) { + public @java.lang.SuppressWarnings("all") BuilderSingularNullBehavior1.@org.checkerframework.checker.nullness.qual.NonNull BuilderSingularNullBehavior1Builder names(final java.util. @org.checkerframework.checker.nullness.qual.NonNull Collection names) { assert (names != null): "names cannot be null"; if ((this.names == null)) this.names = new java.util.ArrayList(); this.names.addAll(names); return this; } - public @java.lang.SuppressWarnings("all") BuilderSingularNullBehavior1.BuilderSingularNullBehavior1Builder clearNames() { + public @java.lang.SuppressWarnings("all") BuilderSingularNullBehavior1.@org.checkerframework.checker.nullness.qual.NonNull BuilderSingularNullBehavior1Builder clearNames() { if ((this.names != null)) this.names.clear(); return this; } - public @java.lang.SuppressWarnings("all") BuilderSingularNullBehavior1.BuilderSingularNullBehavior1Builder location(final String location) { + public @java.lang.SuppressWarnings("all") BuilderSingularNullBehavior1.@org.checkerframework.checker.nullness.qual.NonNull BuilderSingularNullBehavior1Builder location(final String location) { if ((this.locations == null)) this.locations = new java.util.ArrayList(); this.locations.add(location); return this; } - public @java.lang.SuppressWarnings("all") BuilderSingularNullBehavior1.BuilderSingularNullBehavior1Builder locations(final java.util. @org.checkerframework.checker.nullness.qual.Nullable Collection locations) { + public @java.lang.SuppressWarnings("all") BuilderSingularNullBehavior1.@org.checkerframework.checker.nullness.qual.NonNull BuilderSingularNullBehavior1Builder locations(final java.util. @org.checkerframework.checker.nullness.qual.Nullable Collection locations) { if ((locations != null)) { if ((this.locations == null)) @@ -41,12 +41,12 @@ import lombok.Singular; } return this; } - public @java.lang.SuppressWarnings("all") BuilderSingularNullBehavior1.BuilderSingularNullBehavior1Builder clearLocations() { + public @java.lang.SuppressWarnings("all") BuilderSingularNullBehavior1.@org.checkerframework.checker.nullness.qual.NonNull BuilderSingularNullBehavior1Builder clearLocations() { if ((this.locations != null)) this.locations.clear(); return this; } - public @java.lang.SuppressWarnings("all") BuilderSingularNullBehavior1 build() { + public @org.checkerframework.checker.nullness.qual.NonNull @java.lang.SuppressWarnings("all") BuilderSingularNullBehavior1 build() { java.util.List names; switch (((this.names == null) ? 0 : this.names.size())) { case 0 : @@ -82,7 +82,7 @@ import lombok.Singular; this.names = names; this.locations = locations; } - public static @java.lang.SuppressWarnings("all") BuilderSingularNullBehavior1.BuilderSingularNullBehavior1Builder builder() { + public static @java.lang.SuppressWarnings("all") BuilderSingularNullBehavior1.@org.checkerframework.checker.nullness.qual.NonNull BuilderSingularNullBehavior1Builder builder() { return new BuilderSingularNullBehavior1.BuilderSingularNullBehavior1Builder(); } } \ No newline at end of file diff --git a/test/transform/resource/after-ecj/BuilderSingularNullBehavior2.java b/test/transform/resource/after-ecj/BuilderSingularNullBehavior2.java index 85f9fb21..cf4bd91b 100644 --- a/test/transform/resource/after-ecj/BuilderSingularNullBehavior2.java +++ b/test/transform/resource/after-ecj/BuilderSingularNullBehavior2.java @@ -6,25 +6,25 @@ import lombok.Singular; @java.lang.SuppressWarnings("all") BuilderSingularNullBehavior2Builder() { super(); } - public @java.lang.SuppressWarnings("all") BuilderSingularNullBehavior2.BuilderSingularNullBehavior2Builder location(final String location) { + public @org.springframework.lang.NonNull @java.lang.SuppressWarnings("all") BuilderSingularNullBehavior2.BuilderSingularNullBehavior2Builder location(final String location) { if ((this.locations == null)) this.locations = new java.util.ArrayList(); this.locations.add(location); return this; } - public @java.lang.SuppressWarnings("all") BuilderSingularNullBehavior2.BuilderSingularNullBehavior2Builder locations(final @org.springframework.lang.NonNull java.util.Collection locations) { + public @org.springframework.lang.NonNull @java.lang.SuppressWarnings("all") BuilderSingularNullBehavior2.BuilderSingularNullBehavior2Builder locations(final @org.springframework.lang.NonNull java.util.Collection locations) { java.util.Objects.requireNonNull(locations, "locations cannot be null"); if ((this.locations == null)) this.locations = new java.util.ArrayList(); this.locations.addAll(locations); return this; } - public @java.lang.SuppressWarnings("all") BuilderSingularNullBehavior2.BuilderSingularNullBehavior2Builder clearLocations() { + public @org.springframework.lang.NonNull @java.lang.SuppressWarnings("all") BuilderSingularNullBehavior2.BuilderSingularNullBehavior2Builder clearLocations() { if ((this.locations != null)) this.locations.clear(); return this; } - public @java.lang.SuppressWarnings("all") BuilderSingularNullBehavior2 build() { + public @org.springframework.lang.NonNull @java.lang.SuppressWarnings("all") BuilderSingularNullBehavior2 build() { java.util.List locations; switch (((this.locations == null) ? 0 : this.locations.size())) { case 0 : @@ -47,7 +47,7 @@ import lombok.Singular; super(); this.locations = locations; } - public static @java.lang.SuppressWarnings("all") BuilderSingularNullBehavior2.BuilderSingularNullBehavior2Builder builder() { + public static @org.springframework.lang.NonNull @java.lang.SuppressWarnings("all") BuilderSingularNullBehavior2.BuilderSingularNullBehavior2Builder builder() { return new BuilderSingularNullBehavior2.BuilderSingularNullBehavior2Builder(); } } \ No newline at end of file diff --git a/test/transform/resource/after-ecj/StaticConstructor.java b/test/transform/resource/after-ecj/StaticConstructor.java new file mode 100644 index 00000000..93308faa --- /dev/null +++ b/test/transform/resource/after-ecj/StaticConstructor.java @@ -0,0 +1,11 @@ +import lombok.AllArgsConstructor; +public @AllArgsConstructor(staticName = "of") class StaticConstructor { + String name; + private @java.lang.SuppressWarnings("all") StaticConstructor(final String name) { + super(); + this.name = name; + } + public static @org.checkerframework.checker.nullness.qual.NonNull @java.lang.SuppressWarnings("all") StaticConstructor of(final String name) { + return new StaticConstructor(name); + } +} \ No newline at end of file diff --git a/test/transform/resource/after-ecj/WithPlain.java b/test/transform/resource/after-ecj/WithPlain.java index 4203f540..66a1455b 100644 --- a/test/transform/resource/after-ecj/WithPlain.java +++ b/test/transform/resource/after-ecj/WithPlain.java @@ -7,10 +7,10 @@ class WithPlain { this.i = i; this.foo = foo; } - public @java.lang.SuppressWarnings("all") WithPlain withI(final int i) { + public @org.springframework.lang.NonNull @java.lang.SuppressWarnings("all") WithPlain withI(final int i) { return ((this.i == i) ? this : new WithPlain(i, this.foo)); } - public @java.lang.SuppressWarnings("all") WithPlain withFoo(final int foo) { + public @org.springframework.lang.NonNull @java.lang.SuppressWarnings("all") WithPlain withFoo(final int foo) { return ((this.foo == foo) ? this : new WithPlain(this.i, foo)); } } diff --git a/test/transform/resource/before/StaticConstructor.java b/test/transform/resource/before/StaticConstructor.java new file mode 100644 index 00000000..eff1fa9b --- /dev/null +++ b/test/transform/resource/before/StaticConstructor.java @@ -0,0 +1,6 @@ +//CONF: lombok.addNullAnnotations = checkerframework +import lombok.AllArgsConstructor; +@AllArgsConstructor(staticName = "of") +public class StaticConstructor { + String name; +} diff --git a/test/transform/resource/before/ValueStaticConstructorOf.java b/test/transform/resource/before/ValueStaticConstructorOf.java index ac857ffd..bd318d40 100644 --- a/test/transform/resource/before/ValueStaticConstructorOf.java +++ b/test/transform/resource/before/ValueStaticConstructorOf.java @@ -1,12 +1,11 @@ import lombok.Value; @Value(staticConstructor = "of") public class ValueStaticConstructorOf { + String name; + Double price; - String name; - Double price; - - private ValueStaticConstructorOf(String name, Double price) { - this.name = name; - this.price = price; - } + private ValueStaticConstructorOf(String name, Double price) { + this.name = name; + this.price = price; + } } diff --git a/test/transform/resource/before/WithPlain.java b/test/transform/resource/before/WithPlain.java index 1b2a19c4..4f048242 100644 --- a/test/transform/resource/before/WithPlain.java +++ b/test/transform/resource/before/WithPlain.java @@ -1,3 +1,4 @@ +//CONF: lombok.addNullAnnotations = spring import lombok.With; class WithPlain { @lombok.With int i; -- cgit