From aa80e1baf92f3327383b36466a771e92d8a91b05 Mon Sep 17 00:00:00 2001
From: Roel Spilker <r.spilker@gmail.com>
Date: Tue, 16 Jul 2019 02:04:11 +0200
Subject: Fixes #1197, add Objects.requireNonNull and
 Preconditions.checkkNotNull to supported null-check styles

---
 .../resource/after-delombok/NonNullWithGuava.java  | 35 ++++++++++++++++++++
 .../resource/after-delombok/NonNullWithJdk.java    | 36 +++++++++++++++++++++
 .../resource/after-ecj/NonNullWithGuava.java       | 36 +++++++++++++++++++++
 .../resource/after-ecj/NonNullWithJdk.java         | 37 ++++++++++++++++++++++
 .../resource/before/NonNullWithGuava.java          | 33 +++++++++++++++++++
 test/transform/resource/before/NonNullWithJdk.java | 34 ++++++++++++++++++++
 6 files changed, 211 insertions(+)
 create mode 100644 test/transform/resource/after-delombok/NonNullWithGuava.java
 create mode 100644 test/transform/resource/after-delombok/NonNullWithJdk.java
 create mode 100644 test/transform/resource/after-ecj/NonNullWithGuava.java
 create mode 100644 test/transform/resource/after-ecj/NonNullWithJdk.java
 create mode 100644 test/transform/resource/before/NonNullWithGuava.java
 create mode 100644 test/transform/resource/before/NonNullWithJdk.java

(limited to 'test/transform')

diff --git a/test/transform/resource/after-delombok/NonNullWithGuava.java b/test/transform/resource/after-delombok/NonNullWithGuava.java
new file mode 100644
index 00000000..b3c13d30
--- /dev/null
+++ b/test/transform/resource/after-delombok/NonNullWithGuava.java
@@ -0,0 +1,35 @@
+import static com.google.common.base.Preconditions.*;
+public class NonNullWithGuava {
+	@lombok.NonNull
+	private String test;
+	public void testMethod(@lombok.NonNull String arg) {
+		com.google.common.base.Preconditions.checkNotNull(arg, "arg is marked non-null but is null");
+		System.out.println(arg);
+	}
+	public void testMethodWithCheck1(@lombok.NonNull String arg) {
+		checkNotNull(arg);
+	}
+	public void testMethodWithCheckAssign(@lombok.NonNull String arg) {
+		test = checkNotNull(arg);
+	}
+	public void testMethodWithCheck2(@lombok.NonNull String arg) {
+		com.google.common.base.Preconditions.checkNotNull(arg);
+	}
+	public void testMethodWithFakeCheck1(@lombok.NonNull String arg) {
+		com.google.common.base.Preconditions.checkNotNull(arg, "arg is marked non-null but is null");
+		checkNotNull("");
+	}
+	public void testMethodWithFakeCheck2(@lombok.NonNull String arg) {
+		com.google.common.base.Preconditions.checkNotNull(arg, "arg is marked non-null but is null");
+		com.google.common.base.Preconditions.checkNotNull(test);
+	}
+	public void testMethodWithFakeCheckAssign(@lombok.NonNull String arg) {
+		com.google.common.base.Preconditions.checkNotNull(arg, "arg is marked non-null but is null");
+		test = checkNotNull(test);
+	}
+	@java.lang.SuppressWarnings("all")
+	public void setTest(@lombok.NonNull final String test) {
+		com.google.common.base.Preconditions.checkNotNull(test, "test is marked non-null but is null");
+		this.test = test;
+	}
+}
\ No newline at end of file
diff --git a/test/transform/resource/after-delombok/NonNullWithJdk.java b/test/transform/resource/after-delombok/NonNullWithJdk.java
new file mode 100644
index 00000000..d7e2958c
--- /dev/null
+++ b/test/transform/resource/after-delombok/NonNullWithJdk.java
@@ -0,0 +1,36 @@
+//version 7:
+import static java.util.Objects.*;
+public class NonNullWithJdk {
+	@lombok.NonNull
+	private String test;
+	public void testMethod(@lombok.NonNull String arg) {
+		java.util.Objects.requireNonNull(arg, "arg is marked non-null but is null");
+		System.out.println(arg);
+	}
+	public void testMethodWithCheck1(@lombok.NonNull String arg) {
+		requireNonNull(arg);
+	}
+	public void testMethodWithCheckAssign(@lombok.NonNull String arg) {
+		test = requireNonNull(arg);
+	}
+	public void testMethodWithCheck2(@lombok.NonNull String arg) {
+		java.util.Objects.requireNonNull(arg);
+	}
+	public void testMethodWithFakeCheck1(@lombok.NonNull String arg) {
+		java.util.Objects.requireNonNull(arg, "arg is marked non-null but is null");
+		requireNonNull("");
+	}
+	public void testMethodWithFakeCheck2(@lombok.NonNull String arg) {
+		java.util.Objects.requireNonNull(arg, "arg is marked non-null but is null");
+		java.util.Objects.requireNonNull(test);
+	}
+	public void testMethodWithFakeCheckAssign(@lombok.NonNull String arg) {
+		java.util.Objects.requireNonNull(arg, "arg is marked non-null but is null");
+		test = requireNonNull(test);
+	}
+	@java.lang.SuppressWarnings("all")
+	public void setTest(@lombok.NonNull final String test) {
+		java.util.Objects.requireNonNull(test, "test is marked non-null but is null");
+		this.test = test;
+	}
+}
\ No newline at end of file
diff --git a/test/transform/resource/after-ecj/NonNullWithGuava.java b/test/transform/resource/after-ecj/NonNullWithGuava.java
new file mode 100644
index 00000000..c7f5a7fe
--- /dev/null
+++ b/test/transform/resource/after-ecj/NonNullWithGuava.java
@@ -0,0 +1,36 @@
+import static com.google.common.base.Preconditions.*;
+public class NonNullWithGuava {
+  private @lombok.NonNull @lombok.Setter String test;
+  public NonNullWithGuava() {
+    super();
+  }
+  public void testMethod(@lombok.NonNull String arg) {
+    com.google.common.base.Preconditions.checkNotNull(arg, "arg is marked non-null but is null");
+    System.out.println(arg);
+  }
+  public void testMethodWithCheck1(@lombok.NonNull String arg) {
+    checkNotNull(arg);
+  }
+  public void testMethodWithCheckAssign(@lombok.NonNull String arg) {
+    test = checkNotNull(arg);
+  }
+  public void testMethodWithCheck2(@lombok.NonNull String arg) {
+    com.google.common.base.Preconditions.checkNotNull(arg);
+  }
+  public void testMethodWithFakeCheck1(@lombok.NonNull String arg) {
+    com.google.common.base.Preconditions.checkNotNull(arg, "arg is marked non-null but is null");
+    checkNotNull("");
+  }
+  public void testMethodWithFakeCheck2(@lombok.NonNull String arg) {
+    com.google.common.base.Preconditions.checkNotNull(arg, "arg is marked non-null but is null");
+    com.google.common.base.Preconditions.checkNotNull(test);
+  }
+  public void testMethodWithFakeCheckAssign(@lombok.NonNull String arg) {
+    com.google.common.base.Preconditions.checkNotNull(arg, "arg is marked non-null but is null");
+    test = checkNotNull(test);
+  }
+  public @java.lang.SuppressWarnings("all") void setTest(final @lombok.NonNull String test) {
+    com.google.common.base.Preconditions.checkNotNull(test, "test is marked non-null but is null");
+    this.test = test;
+  }
+}
diff --git a/test/transform/resource/after-ecj/NonNullWithJdk.java b/test/transform/resource/after-ecj/NonNullWithJdk.java
new file mode 100644
index 00000000..7d522260
--- /dev/null
+++ b/test/transform/resource/after-ecj/NonNullWithJdk.java
@@ -0,0 +1,37 @@
+//version 7:
+import static java.util.Objects.*;
+public class NonNullWithJdk {
+  private @lombok.NonNull @lombok.Setter String test;
+  public NonNullWithJdk() {
+    super();
+  }
+  public void testMethod(@lombok.NonNull String arg) {
+    java.util.Objects.requireNonNull(arg, "arg is marked non-null but is null");
+    System.out.println(arg);
+  }
+  public void testMethodWithCheck1(@lombok.NonNull String arg) {
+    requireNonNull(arg);
+  }
+  public void testMethodWithCheckAssign(@lombok.NonNull String arg) {
+    test = requireNonNull(arg);
+  }
+  public void testMethodWithCheck2(@lombok.NonNull String arg) {
+    java.util.Objects.requireNonNull(arg);
+  }
+  public void testMethodWithFakeCheck1(@lombok.NonNull String arg) {
+    java.util.Objects.requireNonNull(arg, "arg is marked non-null but is null");
+    requireNonNull("");
+  }
+  public void testMethodWithFakeCheck2(@lombok.NonNull String arg) {
+    java.util.Objects.requireNonNull(arg, "arg is marked non-null but is null");
+    java.util.Objects.requireNonNull(test);
+  }
+  public void testMethodWithFakeCheckAssign(@lombok.NonNull String arg) {
+    java.util.Objects.requireNonNull(arg, "arg is marked non-null but is null");
+    test = requireNonNull(test);
+  }
+  public @java.lang.SuppressWarnings("all") void setTest(final @lombok.NonNull String test) {
+    java.util.Objects.requireNonNull(test, "test is marked non-null but is null");
+    this.test = test;
+  }
+}
diff --git a/test/transform/resource/before/NonNullWithGuava.java b/test/transform/resource/before/NonNullWithGuava.java
new file mode 100644
index 00000000..dc877daa
--- /dev/null
+++ b/test/transform/resource/before/NonNullWithGuava.java
@@ -0,0 +1,33 @@
+//CONF: lombok.nonNull.exceptionType = Guava
+import static com.google.common.base.Preconditions.*;
+public class NonNullWithGuava {
+	@lombok.NonNull @lombok.Setter private String test;
+
+	public void testMethod(@lombok.NonNull String arg) {
+		System.out.println(arg);
+	}
+
+	public void testMethodWithCheck1(@lombok.NonNull String arg) {
+		checkNotNull(arg);
+	}
+
+	public void testMethodWithCheckAssign(@lombok.NonNull String arg) {
+		test = checkNotNull(arg);
+	}
+
+	public void testMethodWithCheck2(@lombok.NonNull String arg) {
+		com.google.common.base.Preconditions.checkNotNull(arg);
+	}
+
+	public void testMethodWithFakeCheck1(@lombok.NonNull String arg) {
+		checkNotNull("");
+	}
+
+	public void testMethodWithFakeCheck2(@lombok.NonNull String arg) {
+		com.google.common.base.Preconditions.checkNotNull(test);
+	}
+	
+	public void testMethodWithFakeCheckAssign(@lombok.NonNull String arg) {
+		test = checkNotNull(test);
+	}
+}
diff --git a/test/transform/resource/before/NonNullWithJdk.java b/test/transform/resource/before/NonNullWithJdk.java
new file mode 100644
index 00000000..c8cbf2ee
--- /dev/null
+++ b/test/transform/resource/before/NonNullWithJdk.java
@@ -0,0 +1,34 @@
+//version 7:
+//CONF: lombok.nonNull.exceptionType = Jdk
+import static java.util.Objects.*;
+public class NonNullWithJdk {
+	@lombok.NonNull @lombok.Setter private String test;
+
+	public void testMethod(@lombok.NonNull String arg) {
+		System.out.println(arg);
+	}
+
+	public void testMethodWithCheck1(@lombok.NonNull String arg) {
+		requireNonNull(arg);
+	}
+
+	public void testMethodWithCheckAssign(@lombok.NonNull String arg) {
+		test = requireNonNull(arg);
+	}
+
+	public void testMethodWithCheck2(@lombok.NonNull String arg) {
+		java.util.Objects.requireNonNull(arg);
+	}
+
+	public void testMethodWithFakeCheck1(@lombok.NonNull String arg) {
+		requireNonNull("");
+	}
+
+	public void testMethodWithFakeCheck2(@lombok.NonNull String arg) {
+		java.util.Objects.requireNonNull(test);
+	}
+	
+	public void testMethodWithFakeCheckAssign(@lombok.NonNull String arg) {
+		test = requireNonNull(test);
+	}
+}
-- 
cgit