feature: some test with java jsr-305 for java nullability

This commit is contained in:
RouxAntoine 2024-04-30 21:44:45 +02:00
parent 1c09ce3667
commit 3d35486983
Signed by: antoine
GPG Key ID: 098FB66FC0475E70
9 changed files with 165 additions and 0 deletions

35
.gitignore vendored Normal file
View File

@ -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

36
pom.xml Normal file
View File

@ -0,0 +1,36 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.example</groupId>
<artifactId>notNull</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<maven.compiler.source>21</maven.compiler.source>
<maven.compiler.target>21</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>com.google.code.findbugs</groupId>
<artifactId>jsr305</artifactId>
<version>3.0.2</version>
<!-- <scope>provided</scope>-->
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>6.1.6</version>
</dependency>
<dependency>
<groupId>io.vavr</groupId>
<artifactId>vavr</artifactId>
<version>1.0.0-alpha-4</version>
</dependency>
</dependencies>
</project>

View File

@ -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<Integer> option = Option.of(1);
}
}

View File

@ -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 {
}

View File

@ -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 {
}

View File

@ -0,0 +1,8 @@
//@ParametersAreNonnullByDefault
//@NonNullApi
//@NonNullFields
package application;
//import org.springframework.lang.NonNullApi;
//import org.springframework.lang.NonNullFields;

View File

@ -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
}
}

View File

@ -0,0 +1,8 @@
//@ParametersAreNonnullByDefault
//@NonNullApi
//@NonNullFields
package application.subpackage;
//import org.springframework.lang.NonNullApi;
//import org.springframework.lang.NonNullFields;

View File

@ -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;
}