-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
150 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
.idea/ | ||
*.iml | ||
target/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,28 @@ | ||
# avaje-lang | ||
# avaje-lang | ||
|
||
Provides `@NonNullAPI` and `@Nullable` for APIs | ||
|
||
## Step 1. Add dependency | ||
|
||
```xml | ||
<dependency> | ||
<groupId>io.avaje</groupId> | ||
<artifactId>avaje-lang</artifactId> | ||
<version>1.0</version> | ||
</dependency> | ||
``` | ||
|
||
## Step 2. Put `@NonNullAPI` on either package-info or a type | ||
|
||
This defines the return type and parameters to be `@Nonnull` by default | ||
|
||
## Step 3. Put `@Nullable` on anything that can be nullable | ||
|
||
|
||
# How it works | ||
|
||
These annotations are meta annotations using `jsr-305` annotations (`javax.annotation`) | ||
and are then honored by most tools - IntelliJ etc. | ||
|
||
Note that these annotations are RetentionType CLASS and expected to be used at compile time | ||
only via static analysis and can not be read or used at runtime. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
<?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>io.avaje</groupId> | ||
<artifactId>avaje-lang</artifactId> | ||
<version>1.0</version> | ||
|
||
<parent> | ||
<groupId>org.avaje</groupId> | ||
<artifactId>java8-oss</artifactId> | ||
<version>3.2</version> | ||
</parent> | ||
|
||
<scm> | ||
<developerConnection>scm:git:git@github.com:avaje/avaje-lang.git</developerConnection> | ||
<tag>HEAD</tag> | ||
</scm> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>io.avaje</groupId> | ||
<artifactId>avaje-jsr305</artifactId> | ||
<version>1.2</version> | ||
<scope>provided</scope> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.moditect</groupId> | ||
<artifactId>moditect-maven-plugin</artifactId> | ||
<version>1.0.0.RC1</version> | ||
<executions> | ||
<execution> | ||
<id>add-module-infos</id> | ||
<phase>package</phase> | ||
<goals> | ||
<goal>add-module-info</goal> | ||
</goals> | ||
<configuration> | ||
<jvmVersion>9</jvmVersion> | ||
<module> | ||
<moduleInfoFile>src/main/java9/module-info.java</moduleInfoFile> | ||
</module> | ||
</configuration> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
|
||
</project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package io.avaje.lang; | ||
|
||
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; | ||
|
||
import javax.annotation.Nonnull; | ||
import javax.annotation.meta.TypeQualifierDefault; | ||
|
||
/** | ||
* A common annotation to declare that parameters and return values | ||
* are to be considered as non-nullable by default for a given package. | ||
* | ||
* <p>Leverages JSR-305 meta-annotations to indicate nullability in Java to common | ||
* tools with JSR-305 support and used by Kotlin to infer nullability of API. | ||
* | ||
* <p>Should be used in association with Nullable annotations at parameter | ||
* and return value level. | ||
*/ | ||
@Target({ElementType.PACKAGE, ElementType.TYPE}) | ||
@Retention(RetentionPolicy.CLASS) | ||
@Documented | ||
@Nonnull | ||
@TypeQualifierDefault({ElementType.METHOD, ElementType.PARAMETER}) | ||
public @interface NonNullApi { | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package io.avaje.lang; | ||
|
||
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; | ||
|
||
import javax.annotation.Nonnull; | ||
import javax.annotation.meta.TypeQualifierNickname; | ||
import javax.annotation.meta.When; | ||
|
||
/** | ||
* A common annotation to declare that annotated elements can be {@code null}. | ||
* | ||
* <p>Leverages JSR-305 meta-annotations to indicate nullability in Java to common | ||
* tools with JSR-305 support and used by Kotlin to infer nullability. | ||
* | ||
* <p>Should be used at parameter, return value, and field level. Methods override should | ||
* repeat parent {@code @Nullable} annotations unless they behave differently. | ||
* | ||
* <p>Can be used in association with {@code @NonNullApi} to override the default | ||
* non-nullable semantic to nullable. | ||
*/ | ||
@Target({ElementType.METHOD, ElementType.PARAMETER, ElementType.FIELD}) | ||
@Retention(RetentionPolicy.CLASS) | ||
@Documented | ||
@Nonnull(when = When.MAYBE) | ||
@TypeQualifierNickname | ||
public @interface Nullable { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module io.avaje.lang { | ||
exports io.avaje.lang; | ||
} |