Skip to content

Commit

Permalink
kotlin: annotated public API with NonNull annotation fix #822
Browse files Browse the repository at this point in the history
  • Loading branch information
jknack committed Oct 9, 2017
1 parent 3113ca5 commit 42e42cb
Show file tree
Hide file tree
Showing 21 changed files with 552 additions and 9 deletions.
6 changes: 6 additions & 0 deletions jooby/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,12 @@
</build>

<dependencies>
<dependency>
<groupId>com.google.code.findbugs</groupId>
<artifactId>jsr305</artifactId>
<scope>provided</scope>
</dependency>

<!-- Logging System -->
<dependency>
<groupId>org.slf4j</groupId>
Expand Down
8 changes: 8 additions & 0 deletions jooby/src/main/java/org/jooby/Asset.java
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,8 @@
import com.google.common.io.BaseEncoding;
import com.google.common.primitives.Longs;

import javax.annotation.Nonnull;

/**
* Usually a public file/resource like javascript, css, images files, etc...
* An asset consist of content type, stream and last modified since attributes, between others.
Expand Down Expand Up @@ -286,6 +288,7 @@ public MediaType type() {
*
* @return The asset name (without path).
*/
@Nonnull
default String name() {
String path = path();
int slash = path.lastIndexOf('/');
Expand All @@ -302,17 +305,20 @@ default String name() {
*
* @return The asset requested path, includes the name.
*/
@Nonnull
String path();

/**
* @return URL representing the resource.
*/
@Nonnull
URL resource();

/**
* @return Generate a weak Etag using the {@link #path()}, {@link #lastModified()} and
* {@link #length()}.
*/
@Nonnull
default String etag() {
StringBuilder b = new StringBuilder(32);
b.append("W/\"");
Expand Down Expand Up @@ -340,10 +346,12 @@ default String etag() {
* @return The content of this asset.
* @throws Exception If content can't be read it.
*/
@Nonnull
InputStream stream() throws Exception;

/**
* @return Asset media type.
*/
@Nonnull
MediaType type();
}
29 changes: 28 additions & 1 deletion jooby/src/main/java/org/jooby/Cookie.java
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,8 @@
import org.jooby.funzy.Throwing;
import org.jooby.internal.CookieImpl;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import javax.crypto.Mac;
import javax.crypto.spec.SecretKeySpec;
import java.net.URLDecoder;
Expand Down Expand Up @@ -387,6 +389,7 @@ public Definition(final String name) {
*
* @return A new cookie.
*/
@Nonnull
public Cookie toCookie() {
return new CookieImpl(this);
}
Expand All @@ -402,6 +405,7 @@ public String toString() {
* @param name A cookie's name.
* @return This definition.
*/
@Nonnull
public Definition name(final String name) {
this.name = requireNonNull(name, "A cookie name is required.");
return this;
Expand All @@ -410,6 +414,7 @@ public Definition name(final String name) {
/**
* @return Cookie's name.
*/
@Nonnull
public Optional<String> name() {
return Optional.ofNullable(name);
}
Expand All @@ -420,6 +425,7 @@ public Optional<String> name() {
* @param value A value.
* @return This definition.
*/
@Nonnull
public Definition value(final String value) {
this.value = requireNonNull(value, "A cookie value is required.");
return this;
Expand All @@ -428,6 +434,7 @@ public Definition value(final String value) {
/**
* @return Cookie's value.
*/
@Nonnull
public Optional<String> value() {
if (Strings.isNullOrEmpty(value)) {
return Optional.empty();
Expand All @@ -441,6 +448,7 @@ public Optional<String> value() {
* @param domain Cookie's domain.
* @return This definition.
*/
@Nonnull
public Definition domain(final String domain) {
this.domain = requireNonNull(domain, "A cookie domain is required.");
return this;
Expand All @@ -449,6 +457,7 @@ public Definition domain(final String domain) {
/**
* @return A cookie's domain.
*/
@Nonnull
public Optional<String> domain() {
return Optional.ofNullable(domain);
}
Expand All @@ -459,6 +468,7 @@ public Optional<String> domain() {
* @param path Cookie's path.
* @return This definition.
*/
@Nonnull
public Definition path(final String path) {
this.path = requireNonNull(path, "A cookie path is required.");
return this;
Expand All @@ -467,6 +477,7 @@ public Definition path(final String path) {
/**
* @return Get cookie's path.
*/
@Nonnull
public Optional<String> path() {
return Optional.ofNullable(path);
}
Expand All @@ -477,6 +488,7 @@ public Optional<String> path() {
* @param comment A cookie's comment.
* @return This definition.
*/
@Nonnull
public Definition comment(final String comment) {
this.comment = requireNonNull(comment, "A cookie comment is required.");
return this;
Expand All @@ -485,6 +497,7 @@ public Definition comment(final String comment) {
/**
* @return Cookie's comment.
*/
@Nonnull
public Optional<String> comment() {
return Optional.ofNullable(comment);
}
Expand All @@ -495,6 +508,7 @@ public Optional<String> comment() {
* @param httpOnly True, for HTTP Only.
* @return This definition.
*/
@Nonnull
public Definition httpOnly(final boolean httpOnly) {
this.httpOnly = httpOnly;
return this;
Expand All @@ -503,6 +517,7 @@ public Definition httpOnly(final boolean httpOnly) {
/**
* @return HTTP only flag.
*/
@Nonnull
public Optional<Boolean> httpOnly() {
return Optional.ofNullable(httpOnly);
}
Expand All @@ -513,6 +528,7 @@ public Optional<Boolean> httpOnly() {
* @param secure True, ensure that the session cookie is only transmitted via HTTPS.
* @return This definition.
*/
@Nonnull
public Definition secure(final boolean secure) {
this.secure = secure;
return this;
Expand All @@ -521,6 +537,7 @@ public Definition secure(final boolean secure) {
/**
* @return True, ensure that the session cookie is only transmitted via HTTPS.
*/
@Nonnull
public Optional<Boolean> secure() {
return Optional.ofNullable(secure);
}
Expand All @@ -543,6 +560,7 @@ public Optional<Boolean> secure() {
* means the cookie is not stored; if zero, deletes the cookie.
* @return This definition.
*/
@Nonnull
public Definition maxAge(final int maxAge) {
this.maxAge = maxAge;
return this;
Expand All @@ -564,6 +582,7 @@ public Definition maxAge(final int maxAge) {
*
* @return Cookie's max age in seconds.
*/
@Nonnull
public Optional<Integer> maxAge() {
return Optional.ofNullable(maxAge);
}
Expand Down Expand Up @@ -608,6 +627,7 @@ public class Signature {
* @param secret A secret key.
* @return A signed value.
*/
@Nonnull
public static String sign(final String value, final String secret) {
requireNonNull(value, "A value is required.");
requireNonNull(secret, "A secret is required.");
Expand All @@ -628,8 +648,9 @@ public static String sign(final String value, final String secret) {
*
* @param value A signed value.
* @param secret A secret key.
* @return A new signed value.
* @return A new signed value or null.
*/
@Nullable
public static String unsign(final String value, final String secret) {
requireNonNull(value, "A value is required.");
requireNonNull(secret, "A secret is required.");
Expand Down Expand Up @@ -659,21 +680,25 @@ public static boolean valid(final String value, final String secret) {
/**
* @return Cookie's name.
*/
@Nonnull
String name();

/**
* @return Cookie's value.
*/
@Nonnull
Optional<String> value();

/**
* @return An optional comment.
*/
@Nonnull
Optional<String> comment();

/**
* @return Cookie's domain.
*/
@Nonnull
Optional<String> domain();

/**
Expand All @@ -692,6 +717,7 @@ public static boolean valid(final String value, final String secret) {
/**
* @return Cookie's path.
*/
@Nonnull
Optional<String> path();

/**
Expand All @@ -710,5 +736,6 @@ public static boolean valid(final String value, final String secret) {
/**
* @return Encode the cookie.
*/
@Nonnull
String encode();
}
15 changes: 12 additions & 3 deletions jooby/src/main/java/org/jooby/Deferred.java
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@

import static java.util.Objects.requireNonNull;

import javax.annotation.Nonnull;
import java.util.Optional;
import java.util.concurrent.Callable;
import java.util.concurrent.Executor;
Expand Down Expand Up @@ -331,7 +332,7 @@ public class Deferred extends Result {
* @author edgar
* @since 0.10.0
*/
public static interface Initializer0 {
public interface Initializer0 {

/**
* Run the initializer block.
Expand All @@ -348,7 +349,7 @@ public static interface Initializer0 {
* @author edgar
* @since 0.10.0
*/
public static interface Initializer {
public interface Initializer {

/**
* Run the initializer block.
Expand All @@ -366,7 +367,7 @@ public static interface Initializer {
* @author edgar
* @since 0.10.0
*/
public static interface Handler {
public interface Handler {
void handle(Result result, Throwable exception);
}

Expand Down Expand Up @@ -432,6 +433,7 @@ public Deferred() {
* @param value Resolved value.
*/
@Override
@Nonnull
public Result set(final Object value) {
if (value instanceof Throwable) {
reject((Throwable) value);
Expand All @@ -447,6 +449,7 @@ public Result set(final Object value) {
*
* @return Executor to use or fallback to global/application executor.
*/
@Nonnull
public Optional<String> executor() {
return Optional.ofNullable(executor);
}
Expand All @@ -456,6 +459,7 @@ public Optional<String> executor() {
*
* @return Name of the caller thread (thread that creates this deferred object).
*/
@Nonnull
public String callerThread() {
return callerThread;
}
Expand All @@ -466,6 +470,7 @@ public String callerThread() {
*
* @param value A value for this deferred.
*/
@Nonnull
public void resolve(final Object value) {
if (value == null) {
handler.handle(null, null);
Expand Down Expand Up @@ -539,6 +544,7 @@ public void handler(final Request req, final Handler handler) throws Exception {
* @param handler Application block.
* @return A new deferred handler.
*/
@Nonnull
public static Deferred deferred(final Route.OneArgHandler handler) {
return deferred(null, handler);
}
Expand Down Expand Up @@ -574,6 +580,7 @@ public static Deferred deferred(final Route.OneArgHandler handler) {
* @param handler Application block.
* @return A new deferred.
*/
@Nonnull
public static Deferred deferred(final Route.ZeroArgHandler handler) {
return deferred(null, handler);
}
Expand All @@ -599,6 +606,7 @@ public static Deferred deferred(final Route.ZeroArgHandler handler) {
* @param handler Application block.
* @return A new deferred handler.
*/
@Nonnull
public static Deferred deferred(final String executor, final Route.ZeroArgHandler handler) {
return deferred(executor, req -> handler.handle());
}
Expand All @@ -624,6 +632,7 @@ public static Deferred deferred(final String executor, final Route.ZeroArgHandle
* @param handler Application block.
* @return A new deferred handler.
*/
@Nonnull
public static Deferred deferred(final String executor, final Route.OneArgHandler handler) {
return new Deferred(executor, (req, deferred) -> {
try {
Expand Down
Loading

0 comments on commit 42e42cb

Please sign in to comment.