From 3d35486983784a3d6b549a9aba14e80cc67278d1 Mon Sep 17 00:00:00 2001 From: RouxAntoine Date: Tue, 30 Apr 2024 21:44:45 +0200 Subject: [PATCH] feature: some test with java jsr-305 for java nullability --- .gitignore | 35 ++++++++++++++++++ pom.xml | 36 +++++++++++++++++++ src/main/java/application/Main.java | 18 ++++++++++ src/main/java/application/NonNullApi.java | 17 +++++++++ src/main/java/application/NonNullFields.java | 17 +++++++++ src/main/java/application/package-info.java | 8 +++++ .../subpackage/ClassInSubPackage.java | 13 +++++++ .../application/subpackage/package-info.java | 8 +++++ src/main/java/module-info.java | 13 +++++++ 9 files changed, 165 insertions(+) create mode 100644 .gitignore create mode 100644 pom.xml create mode 100644 src/main/java/application/Main.java create mode 100644 src/main/java/application/NonNullApi.java create mode 100644 src/main/java/application/NonNullFields.java create mode 100644 src/main/java/application/package-info.java create mode 100644 src/main/java/application/subpackage/ClassInSubPackage.java create mode 100644 src/main/java/application/subpackage/package-info.java create mode 100644 src/main/java/module-info.java diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..b425f09 --- /dev/null +++ b/.gitignore @@ -0,0 +1,35 @@ +target/ +!.mvn/wrapper/maven-wrapper.jar +!**/src/main/**/target/ +!**/src/test/**/target/ + +### IntelliJ IDEA ### +.idea/ +*.iws +*.iml +*.ipr + +### Eclipse ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ +build/ +!**/src/main/**/build/ +!**/src/test/**/build/ + +### VS Code ### +.vscode/ + +### Mac OS ### +.DS_Store \ No newline at end of file diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..1132f67 --- /dev/null +++ b/pom.xml @@ -0,0 +1,36 @@ + + + 4.0.0 + + org.example + notNull + 1.0-SNAPSHOT + + + 21 + 21 + UTF-8 + + + + + com.google.code.findbugs + jsr305 + 3.0.2 + + + + org.springframework + spring-core + 6.1.6 + + + io.vavr + vavr + 1.0.0-alpha-4 + + + + \ No newline at end of file diff --git a/src/main/java/application/Main.java b/src/main/java/application/Main.java new file mode 100644 index 0000000..e809c7b --- /dev/null +++ b/src/main/java/application/Main.java @@ -0,0 +1,18 @@ +package application; + +import io.vavr.control.Option; + +public class Main { + + private String field = null; + + public static void main(String[] args) { + myFunction("test text"); + myFunction(null); + } + + public static void myFunction(String text) { + // DoStuff with text + Option option = Option.of(1); + } +} diff --git a/src/main/java/application/NonNullApi.java b/src/main/java/application/NonNullApi.java new file mode 100644 index 0000000..0fd27fb --- /dev/null +++ b/src/main/java/application/NonNullApi.java @@ -0,0 +1,17 @@ +package application; + +import javax.annotation.Nonnull; +import javax.annotation.meta.TypeQualifierDefault; +import java.lang.annotation.Documented; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Target({ElementType.PACKAGE, ElementType.MODULE}) +@Retention(RetentionPolicy.RUNTIME) +@Documented +@Nonnull +@TypeQualifierDefault({ElementType.METHOD, ElementType.PARAMETER}) +public @interface NonNullApi { +} diff --git a/src/main/java/application/NonNullFields.java b/src/main/java/application/NonNullFields.java new file mode 100644 index 0000000..e8e1498 --- /dev/null +++ b/src/main/java/application/NonNullFields.java @@ -0,0 +1,17 @@ +package application; + +import javax.annotation.Nonnull; +import javax.annotation.meta.TypeQualifierDefault; +import java.lang.annotation.Documented; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Target({ElementType.PACKAGE, ElementType.MODULE}) +@Retention(RetentionPolicy.RUNTIME) +@Documented +@Nonnull +@TypeQualifierDefault(ElementType.FIELD) +public @interface NonNullFields { +} diff --git a/src/main/java/application/package-info.java b/src/main/java/application/package-info.java new file mode 100644 index 0000000..33e2d77 --- /dev/null +++ b/src/main/java/application/package-info.java @@ -0,0 +1,8 @@ +//@ParametersAreNonnullByDefault +//@NonNullApi +//@NonNullFields +package application; + +//import org.springframework.lang.NonNullApi; +//import org.springframework.lang.NonNullFields; + diff --git a/src/main/java/application/subpackage/ClassInSubPackage.java b/src/main/java/application/subpackage/ClassInSubPackage.java new file mode 100644 index 0000000..5b641f9 --- /dev/null +++ b/src/main/java/application/subpackage/ClassInSubPackage.java @@ -0,0 +1,13 @@ +package application.subpackage; + +public class ClassInSubPackage { + private String field = null; + + public void callMyFunction() { + myFunction(null); + } + + public void myFunction(String text) { + // DoStuff with text + } +} diff --git a/src/main/java/application/subpackage/package-info.java b/src/main/java/application/subpackage/package-info.java new file mode 100644 index 0000000..f4852dc --- /dev/null +++ b/src/main/java/application/subpackage/package-info.java @@ -0,0 +1,8 @@ +//@ParametersAreNonnullByDefault +//@NonNullApi +//@NonNullFields +package application.subpackage; + +//import org.springframework.lang.NonNullApi; +//import org.springframework.lang.NonNullFields; + diff --git a/src/main/java/module-info.java b/src/main/java/module-info.java new file mode 100644 index 0000000..a9768ca --- /dev/null +++ b/src/main/java/module-info.java @@ -0,0 +1,13 @@ +import application.NonNullApi; +import application.NonNullFields; + +//import javax.annotation.ParametersAreNonnullByDefault; + +@NonNullApi +@NonNullFields +//@ParametersAreNonnullByDefault +module notNull { +// requires spring.core; + requires jsr305; + requires io.vavr; +} \ No newline at end of file