From 60dee5c4cbb72078e74f5f37034d7522ad7c8baa Mon Sep 17 00:00:00 2001 From: akwizgran Date: Mon, 10 Oct 2016 13:21:59 +0100 Subject: [PATCH] Added null safety annotations. --- briar-api/build.gradle | 6 ++++ .../nullsafety/FieldsNotNullByDefault.java | 26 +++++++++++++++ .../nullsafety/MethodsNotNullByDefault.java | 28 ++++++++++++++++ .../api/nullsafety/NotNullByDefault.java | 32 +++++++++++++++++++ .../ParametersNotNullByDefault.java | 28 ++++++++++++++++ 5 files changed, 120 insertions(+) create mode 100644 briar-api/src/org/briarproject/api/nullsafety/FieldsNotNullByDefault.java create mode 100644 briar-api/src/org/briarproject/api/nullsafety/MethodsNotNullByDefault.java create mode 100644 briar-api/src/org/briarproject/api/nullsafety/NotNullByDefault.java create mode 100644 briar-api/src/org/briarproject/api/nullsafety/ParametersNotNullByDefault.java diff --git a/briar-api/build.gradle b/briar-api/build.gradle index 479b38fdc..42314bfd5 100644 --- a/briar-api/build.gradle +++ b/briar-api/build.gradle @@ -4,10 +4,15 @@ targetCompatibility = 1.6 apply plugin: 'witness' +repositories { + mavenCentral() +} + dependencies { compile "com.google.dagger:dagger:2.0.2" compile 'com.google.dagger:dagger-compiler:2.0.2' compile 'org.jetbrains:annotations-java5:15.0' + compile 'com.google.code.findbugs:jsr305:3.0.1' } dependencyVerification { @@ -18,6 +23,7 @@ dependencyVerification { 'javax.inject:javax.inject:91c77044a50c481636c32d916fd89c9118a72195390452c81065080f957de7ff', 'com.google.dagger:dagger-producers:99ec15e8a0507ba569e7655bc1165ee5e5ca5aa914b3c8f7e2c2458f724edd6b', 'com.google.guava:guava:d664fbfc03d2e5ce9cab2a44fb01f1d0bf9dfebeccc1a473b1f9ea31f79f6f99', + 'com.google.code.findbugs:jsr305:c885ce34249682bc0236b4a7d56efcc12048e6135a5baf7a9cde8ad8cda13fcd' ] } diff --git a/briar-api/src/org/briarproject/api/nullsafety/FieldsNotNullByDefault.java b/briar-api/src/org/briarproject/api/nullsafety/FieldsNotNullByDefault.java new file mode 100644 index 000000000..bdfd8f523 --- /dev/null +++ b/briar-api/src/org/briarproject/api/nullsafety/FieldsNotNullByDefault.java @@ -0,0 +1,26 @@ +package org.briarproject.api.nullsafety; + +import java.lang.annotation.Documented; +import java.lang.annotation.Retention; + +import javax.annotation.Nonnull; +import javax.annotation.meta.TypeQualifierDefault; + +import static java.lang.annotation.ElementType.FIELD; +import static java.lang.annotation.RetentionPolicy.RUNTIME; + +/** + * This annotation can be applied to a package or class to indicate that + * the fields in that element are non-null by default unless: + * + */ +@Documented +@Nonnull +@TypeQualifierDefault(FIELD) +@Retention(RUNTIME) +public @interface FieldsNotNullByDefault { +} diff --git a/briar-api/src/org/briarproject/api/nullsafety/MethodsNotNullByDefault.java b/briar-api/src/org/briarproject/api/nullsafety/MethodsNotNullByDefault.java new file mode 100644 index 000000000..417e792de --- /dev/null +++ b/briar-api/src/org/briarproject/api/nullsafety/MethodsNotNullByDefault.java @@ -0,0 +1,28 @@ +package org.briarproject.api.nullsafety; + +import java.lang.annotation.Documented; +import java.lang.annotation.Retention; + +import javax.annotation.Nonnull; +import javax.annotation.meta.TypeQualifierDefault; + +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.RetentionPolicy.RUNTIME; + +/** + * This annotation can be applied to a package or class to indicate that + * the methods in that element are non-null by default unless: + * + */ +@Documented +@Nonnull +@TypeQualifierDefault(METHOD) +@Retention(RUNTIME) +public @interface MethodsNotNullByDefault { +} diff --git a/briar-api/src/org/briarproject/api/nullsafety/NotNullByDefault.java b/briar-api/src/org/briarproject/api/nullsafety/NotNullByDefault.java new file mode 100644 index 000000000..29ae96b7c --- /dev/null +++ b/briar-api/src/org/briarproject/api/nullsafety/NotNullByDefault.java @@ -0,0 +1,32 @@ +package org.briarproject.api.nullsafety; + +import java.lang.annotation.Documented; +import java.lang.annotation.Retention; + +import javax.annotation.Nonnull; +import javax.annotation.meta.TypeQualifierDefault; + +import static java.lang.annotation.ElementType.FIELD; +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.ElementType.PARAMETER; +import static java.lang.annotation.RetentionPolicy.RUNTIME; + +/** + * This annotation can be applied to a package or class to indicate that + * the fields, methods and parameters in that element are non-null by default + * unless: + * + */ +@Documented +@Nonnull +@TypeQualifierDefault({FIELD, METHOD, PARAMETER}) +@Retention(RUNTIME) +public @interface NotNullByDefault { +} diff --git a/briar-api/src/org/briarproject/api/nullsafety/ParametersNotNullByDefault.java b/briar-api/src/org/briarproject/api/nullsafety/ParametersNotNullByDefault.java new file mode 100644 index 000000000..ac5de25e2 --- /dev/null +++ b/briar-api/src/org/briarproject/api/nullsafety/ParametersNotNullByDefault.java @@ -0,0 +1,28 @@ +package org.briarproject.api.nullsafety; + +import java.lang.annotation.Documented; +import java.lang.annotation.Retention; + +import javax.annotation.Nonnull; +import javax.annotation.meta.TypeQualifierDefault; + +import static java.lang.annotation.ElementType.PARAMETER; +import static java.lang.annotation.RetentionPolicy.RUNTIME; + +/** + * This annotation can be applied to a package or class to indicate that + * the method parameters in that element are non-null by default unless: + * + */ +@Documented +@Nonnull +@TypeQualifierDefault(PARAMETER) +@Retention(RUNTIME) +public @interface ParametersNotNullByDefault { +}