feature: some test with java jsr-305 for java nullability
This commit is contained in:
parent
1c09ce3667
commit
3d35486983
35
.gitignore
vendored
Normal file
35
.gitignore
vendored
Normal 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
36
pom.xml
Normal 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>
|
18
src/main/java/application/Main.java
Normal file
18
src/main/java/application/Main.java
Normal 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);
|
||||
}
|
||||
}
|
17
src/main/java/application/NonNullApi.java
Normal file
17
src/main/java/application/NonNullApi.java
Normal 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 {
|
||||
}
|
17
src/main/java/application/NonNullFields.java
Normal file
17
src/main/java/application/NonNullFields.java
Normal 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 {
|
||||
}
|
8
src/main/java/application/package-info.java
Normal file
8
src/main/java/application/package-info.java
Normal file
@ -0,0 +1,8 @@
|
||||
//@ParametersAreNonnullByDefault
|
||||
//@NonNullApi
|
||||
//@NonNullFields
|
||||
package application;
|
||||
|
||||
//import org.springframework.lang.NonNullApi;
|
||||
//import org.springframework.lang.NonNullFields;
|
||||
|
13
src/main/java/application/subpackage/ClassInSubPackage.java
Normal file
13
src/main/java/application/subpackage/ClassInSubPackage.java
Normal 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
|
||||
}
|
||||
}
|
8
src/main/java/application/subpackage/package-info.java
Normal file
8
src/main/java/application/subpackage/package-info.java
Normal file
@ -0,0 +1,8 @@
|
||||
//@ParametersAreNonnullByDefault
|
||||
//@NonNullApi
|
||||
//@NonNullFields
|
||||
package application.subpackage;
|
||||
|
||||
//import org.springframework.lang.NonNullApi;
|
||||
//import org.springframework.lang.NonNullFields;
|
||||
|
13
src/main/java/module-info.java
Normal file
13
src/main/java/module-info.java
Normal 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;
|
||||
}
|
Reference in New Issue
Block a user