diff --git a/jooby/pom.xml b/jooby/pom.xml index dcf1a87d91..70d047aa29 100644 --- a/jooby/pom.xml +++ b/jooby/pom.xml @@ -94,6 +94,12 @@ + + com.google.code.findbugs + jsr305 + provided + + org.slf4j diff --git a/jooby/src/main/java/org/jooby/Asset.java b/jooby/src/main/java/org/jooby/Asset.java index df226e8162..9f8a9a2827 100644 --- a/jooby/src/main/java/org/jooby/Asset.java +++ b/jooby/src/main/java/org/jooby/Asset.java @@ -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. @@ -286,6 +288,7 @@ public MediaType type() { * * @return The asset name (without path). */ + @Nonnull default String name() { String path = path(); int slash = path.lastIndexOf('/'); @@ -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/\""); @@ -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(); } diff --git a/jooby/src/main/java/org/jooby/Cookie.java b/jooby/src/main/java/org/jooby/Cookie.java index fcb11011ed..870313aa05 100644 --- a/jooby/src/main/java/org/jooby/Cookie.java +++ b/jooby/src/main/java/org/jooby/Cookie.java @@ -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; @@ -387,6 +389,7 @@ public Definition(final String name) { * * @return A new cookie. */ + @Nonnull public Cookie toCookie() { return new CookieImpl(this); } @@ -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; @@ -410,6 +414,7 @@ public Definition name(final String name) { /** * @return Cookie's name. */ + @Nonnull public Optional name() { return Optional.ofNullable(name); } @@ -420,6 +425,7 @@ public Optional 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; @@ -428,6 +434,7 @@ public Definition value(final String value) { /** * @return Cookie's value. */ + @Nonnull public Optional value() { if (Strings.isNullOrEmpty(value)) { return Optional.empty(); @@ -441,6 +448,7 @@ public Optional 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; @@ -449,6 +457,7 @@ public Definition domain(final String domain) { /** * @return A cookie's domain. */ + @Nonnull public Optional domain() { return Optional.ofNullable(domain); } @@ -459,6 +468,7 @@ public Optional 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; @@ -467,6 +477,7 @@ public Definition path(final String path) { /** * @return Get cookie's path. */ + @Nonnull public Optional path() { return Optional.ofNullable(path); } @@ -477,6 +488,7 @@ public Optional 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; @@ -485,6 +497,7 @@ public Definition comment(final String comment) { /** * @return Cookie's comment. */ + @Nonnull public Optional comment() { return Optional.ofNullable(comment); } @@ -495,6 +508,7 @@ public Optional comment() { * @param httpOnly True, for HTTP Only. * @return This definition. */ + @Nonnull public Definition httpOnly(final boolean httpOnly) { this.httpOnly = httpOnly; return this; @@ -503,6 +517,7 @@ public Definition httpOnly(final boolean httpOnly) { /** * @return HTTP only flag. */ + @Nonnull public Optional httpOnly() { return Optional.ofNullable(httpOnly); } @@ -513,6 +528,7 @@ public Optional 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; @@ -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 secure() { return Optional.ofNullable(secure); } @@ -543,6 +560,7 @@ public Optional 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; @@ -564,6 +582,7 @@ public Definition maxAge(final int maxAge) { * * @return Cookie's max age in seconds. */ + @Nonnull public Optional maxAge() { return Optional.ofNullable(maxAge); } @@ -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."); @@ -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."); @@ -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 value(); /** * @return An optional comment. */ + @Nonnull Optional comment(); /** * @return Cookie's domain. */ + @Nonnull Optional domain(); /** @@ -692,6 +717,7 @@ public static boolean valid(final String value, final String secret) { /** * @return Cookie's path. */ + @Nonnull Optional path(); /** @@ -710,5 +736,6 @@ public static boolean valid(final String value, final String secret) { /** * @return Encode the cookie. */ + @Nonnull String encode(); } diff --git a/jooby/src/main/java/org/jooby/Deferred.java b/jooby/src/main/java/org/jooby/Deferred.java index d9887c9d64..0d625ad695 100644 --- a/jooby/src/main/java/org/jooby/Deferred.java +++ b/jooby/src/main/java/org/jooby/Deferred.java @@ -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; @@ -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. @@ -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. @@ -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); } @@ -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); @@ -447,6 +449,7 @@ public Result set(final Object value) { * * @return Executor to use or fallback to global/application executor. */ + @Nonnull public Optional executor() { return Optional.ofNullable(executor); } @@ -456,6 +459,7 @@ public Optional executor() { * * @return Name of the caller thread (thread that creates this deferred object). */ + @Nonnull public String callerThread() { return callerThread; } @@ -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); @@ -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); } @@ -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); } @@ -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()); } @@ -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 { diff --git a/jooby/src/main/java/org/jooby/Env.java b/jooby/src/main/java/org/jooby/Env.java index 906e882141..c406804263 100644 --- a/jooby/src/main/java/org/jooby/Env.java +++ b/jooby/src/main/java/org/jooby/Env.java @@ -211,6 +211,7 @@ import static java.util.Objects.requireNonNull; import org.jooby.funzy.Throwing; +import javax.annotation.Nonnull; import java.util.Arrays; import java.util.Collections; import java.util.HashMap; @@ -263,6 +264,7 @@ interface PropertySource { * @return Value or throw {@link NoSuchElementException}. * @throws NoSuchElementException If property is missing. */ + @Nonnull String get(String key) throws NoSuchElementException; } @@ -620,6 +622,7 @@ public Env xss(final String name, final Function escaper) { /** * @return Env's name. */ + @Nonnull String name(); /** @@ -628,21 +631,25 @@ public Env xss(final String name, final Function escaper) { * @return Available {@link Router}. * @throws UnsupportedOperationException if router isn't available. */ + @Nonnull Router router() throws UnsupportedOperationException; /** * @return environment properties. */ + @Nonnull Config config(); /** * @return Default locale from application.lang. */ + @Nonnull Locale locale(); /** * @return Utility method for generating keys for named services. */ + @Nonnull default ServiceKey serviceKey() { return new ServiceKey(); } @@ -657,6 +664,7 @@ default ServiceKey serviceKey() { * @param text Text to process. * @return A processed string. */ + @Nonnull default String resolve(final String text) { return resolver().resolve(text); } @@ -666,6 +674,7 @@ default String resolve(final String text) { * * @return A resolver object. */ + @Nonnull default Resolver resolver() { return new Resolver().source(config()); } @@ -678,6 +687,7 @@ default Resolver resolver() { * @param A resulting type. * @return A resulting object. */ + @Nonnull default Optional ifMode(final String name, final Supplier fn) { if (name().equals(name)) { return Optional.of(fn.get()); @@ -688,6 +698,7 @@ default Optional ifMode(final String name, final Supplier fn) { /** * @return XSS escape functions. */ + @Nonnull Map> xss(); /** @@ -696,6 +707,7 @@ default Optional ifMode(final String name, final Supplier fn) { * @param xss XSS to combine. * @return Chain of required xss functions. */ + @Nonnull default Function xss(final String... xss) { Map> fn = xss(); BinaryOperator> reduce = Function::andThen; @@ -713,21 +725,25 @@ default Function xss(final String... xss) { * @param escaper Escape function. * @return This environment. */ + @Nonnull Env xss(String name, Function escaper); /** * @return List of start tasks. */ + @Nonnull List> startTasks(); /** * @return List of start tasks. */ + @Nonnull List> startedTasks(); /** * @return List of stop tasks. */ + @Nonnull List> stopTasks(); /** @@ -738,6 +754,7 @@ default Function xss(final String... xss) { * @param Object type. * @return This environment. */ + @Nonnull Env set(Key key, T value); /** @@ -748,6 +765,7 @@ default Function xss(final String... xss) { * @param Object type. * @return This environment. */ + @Nonnull default Env set(Class key, T value) { return set(Key.get(key), value); } @@ -759,6 +777,7 @@ default Env set(Class key, T value) { * @param Object type. * @return Object valur or empty. */ + @Nonnull Optional get(Key key); /** @@ -768,6 +787,7 @@ default Env set(Class key, T value) { * @param Object type. * @return Object valur or empty. */ + @Nonnull default Optional get(Class key) { return get(Key.get(key)); } diff --git a/jooby/src/main/java/org/jooby/LifeCycle.java b/jooby/src/main/java/org/jooby/LifeCycle.java index 50fefca9ee..fd1178b02a 100644 --- a/jooby/src/main/java/org/jooby/LifeCycle.java +++ b/jooby/src/main/java/org/jooby/LifeCycle.java @@ -207,6 +207,7 @@ import org.jooby.funzy.Throwing; import org.jooby.funzy.Try; +import javax.annotation.Nonnull; import javax.annotation.PostConstruct; import javax.annotation.PreDestroy; import java.lang.annotation.Annotation; @@ -414,6 +415,7 @@ static Optional> lifeCycleAnnotation(final Class ra * @param service Service type. Must be a singleton object. * @return This instance. */ + @Nonnull default LifeCycle lifeCycle(final Class service) { lifeCycleAnnotation(service, PostConstruct.class) .ifPresent(it -> onStart(app -> it.accept(app.require(service)))); @@ -434,6 +436,7 @@ default LifeCycle lifeCycle(final Class service) { * @param task Task to run. * @return This env. */ + @Nonnull LifeCycle onStart(Throwing.Consumer task); /** @@ -448,6 +451,7 @@ default LifeCycle lifeCycle(final Class service) { * @param task Task to run. * @return This env. */ + @Nonnull LifeCycle onStarted(Throwing.Consumer task); /** @@ -461,6 +465,7 @@ default LifeCycle lifeCycle(final Class service) { * @param task Task to run. * @return This env. */ + @Nonnull default LifeCycle onStart(final Throwing.Runnable task) { return onStart(app -> task.run()); } @@ -477,6 +482,7 @@ default LifeCycle onStart(final Throwing.Runnable task) { * @param task Task to run. * @return This env. */ + @Nonnull default LifeCycle onStarted(final Throwing.Runnable task) { return onStarted(app -> task.run()); } @@ -492,6 +498,7 @@ default LifeCycle onStarted(final Throwing.Runnable task) { * @param task Task to run. * @return This env. */ + @Nonnull default LifeCycle onStop(final Throwing.Runnable task) { return onStop(app -> task.run()); } @@ -507,6 +514,7 @@ default LifeCycle onStop(final Throwing.Runnable task) { * @param task Task to run. * @return This env. */ + @Nonnull LifeCycle onStop(Throwing.Consumer task); } diff --git a/jooby/src/main/java/org/jooby/Mutant.java b/jooby/src/main/java/org/jooby/Mutant.java index 877d3f8115..ea0983c277 100644 --- a/jooby/src/main/java/org/jooby/Mutant.java +++ b/jooby/src/main/java/org/jooby/Mutant.java @@ -213,6 +213,8 @@ import com.google.inject.TypeLiteral; import com.google.inject.util.Types; +import javax.annotation.Nonnull; + /** *

* A type safe {@link Mutant} useful for reading parameters/headers/session attributes, etc.. @@ -338,6 +340,7 @@ default long longValue(final long value) { /** * @return Get a string when possible. */ + @Nonnull default String value() { return to(String.class); } @@ -346,6 +349,7 @@ default String value() { * @param value Default value to use. * @return Get a string. */ + @Nonnull default String value(final String value) { return toOptional().orElse(value); } @@ -385,6 +389,7 @@ default double doubleValue(final double value) { * @param Enum type. * @return Get an enum when possible. */ + @Nonnull default > T toEnum(final Class type) { return to(type); } @@ -395,6 +400,7 @@ default > T toEnum(final Class type) { * @return Get an enum. */ @SuppressWarnings("unchecked") + @Nonnull default > T toEnum(final T value) { Optional optional = (Optional) toOptional(value.getClass()); return optional.orElse(value); @@ -406,6 +412,7 @@ default > T toEnum(final T value) { * @return Get list of values when possible. */ @SuppressWarnings("unchecked") + @Nonnull default List toList(final Class type) { return (List) to(TypeLiteral.get(Types.listOf(Primitives.wrap(type)))); } @@ -413,6 +420,7 @@ default List toList(final Class type) { /** * @return Get list of values when possible. */ + @Nonnull default List toList() { return toList(String.class); } @@ -420,6 +428,7 @@ default List toList() { /** * @return Get set of values when possible. */ + @Nonnull default Set toSet() { return toSet(String.class); } @@ -430,6 +439,7 @@ default Set toSet() { * @return Get set of values when possible. */ @SuppressWarnings("unchecked") + @Nonnull default Set toSet(final Class type) { return (Set) to(TypeLiteral.get(Types.setOf(Primitives.wrap(type)))); } @@ -437,6 +447,7 @@ default Set toSet(final Class type) { /** * @return Get sorted set of values when possible. */ + @Nonnull default SortedSet toSortedSet() { return toSortedSet(String.class); } @@ -447,6 +458,7 @@ default SortedSet toSortedSet() { * @return Get sorted set of values when possible. */ @SuppressWarnings("unchecked") + @Nonnull default > SortedSet toSortedSet(final Class type) { return (SortedSet) to(TypeLiteral.get( Types.newParameterizedType(SortedSet.class, Primitives.wrap(type)))); @@ -455,6 +467,7 @@ default > SortedSet toSortedSet(final Class type) /** * @return An optional string value. */ + @Nonnull default Optional toOptional() { return toOptional(String.class); } @@ -465,6 +478,7 @@ default Optional toOptional() { * @return Get an optional value when possible. */ @SuppressWarnings("unchecked") + @Nonnull default Optional toOptional(final Class type) { return (Optional) to(TypeLiteral.get( Types.newParameterizedType(Optional.class, Primitives.wrap(type)))); @@ -477,6 +491,7 @@ default Optional toOptional(final Class type) { * @param Target type. * @return Get a value when possible. */ + @Nonnull default T to(final Class type) { return to(TypeLiteral.get(type)); } @@ -488,6 +503,7 @@ default T to(final Class type) { * @param Target type. * @return Get a value when possible. */ + @Nonnull T to(TypeLiteral type); /** @@ -499,6 +515,7 @@ default T to(final Class type) { * @param Target type. * @return Get a value when possible. */ + @Nonnull default T to(final Class type, final String mtype) { return to(type, MediaType.valueOf(mtype)); } @@ -512,6 +529,7 @@ default T to(final Class type, final String mtype) { * @param Target type. * @return Get a value when possible. */ + @Nonnull default T to(final Class type, final MediaType mtype) { return to(TypeLiteral.get(type), mtype); } @@ -525,6 +543,7 @@ default T to(final Class type, final MediaType mtype) { * @param Target type. * @return Get a value when possible. */ + @Nonnull default T to(final TypeLiteral type, final String mtype) { return to(type, MediaType.valueOf(mtype)); } @@ -538,6 +557,7 @@ default T to(final TypeLiteral type, final String mtype) { * @param Target type. * @return Get a value when possible. */ + @Nonnull T to(TypeLiteral type, MediaType mtype); /** @@ -554,6 +574,7 @@ default T to(final TypeLiteral type, final String mtype) { * * @return A map view of this mutant. */ + @Nonnull Map toMap(); /** diff --git a/jooby/src/main/java/org/jooby/Registry.java b/jooby/src/main/java/org/jooby/Registry.java index 3386b3ee34..cd123bf0b7 100644 --- a/jooby/src/main/java/org/jooby/Registry.java +++ b/jooby/src/main/java/org/jooby/Registry.java @@ -207,6 +207,8 @@ import com.google.inject.TypeLiteral; import com.google.inject.name.Names; +import javax.annotation.Nonnull; + /** *

service registry

*

@@ -226,6 +228,7 @@ public interface Registry { * @param Service type. * @return A ready to use object. */ + @Nonnull default T require(final Class type) { return require(Key.get(type)); } @@ -238,6 +241,7 @@ default T require(final Class type) { * @param Service type. * @return A ready to use object. */ + @Nonnull default T require(final String name, final Class type) { return require(Key.get(type, Names.named(name))); } @@ -249,6 +253,7 @@ default T require(final String name, final Class type) { * @param Service type. * @return A ready to use object. */ + @Nonnull default T require(final TypeLiteral type) { return require(Key.get(type)); } @@ -260,6 +265,7 @@ default T require(final TypeLiteral type) { * @param Service type. * @return A ready to use object. */ + @Nonnull T require(Key key); } diff --git a/jooby/src/main/java/org/jooby/Request.java b/jooby/src/main/java/org/jooby/Request.java index 9a93ad6275..eec1e70196 100644 --- a/jooby/src/main/java/org/jooby/Request.java +++ b/jooby/src/main/java/org/jooby/Request.java @@ -223,6 +223,8 @@ import com.google.inject.Key; import com.google.inject.TypeLiteral; +import javax.annotation.Nonnull; + /** * Give you access at the current HTTP request in order to read parameters, headers and body. * @@ -671,6 +673,7 @@ public static Request unwrap(final Request req) { * * @return The request URL pathname. */ + @Nonnull default String path() { return path(false); } @@ -680,6 +683,7 @@ default String path() { * * @return Raw path, like {@link #path()} but without decoding. */ + @Nonnull String rawPath(); /** @@ -687,6 +691,7 @@ default String path() { * * @return The query string, without the leading ?. */ + @Nonnull Optional queryString(); /** @@ -701,6 +706,7 @@ default String path() { * @param escape True if we want to escape this path. * @return The request URL pathname. */ + @Nonnull default String path(final boolean escape) { String path = route().path(); return escape ? UrlEscapers.urlFragmentEscaper().escape(path) : path; @@ -712,11 +718,13 @@ default String path(final boolean escape) { * * @return Application context path.. */ + @Nonnull String contextPath(); /** * @return HTTP method. */ + @Nonnull default String method() { return route().method(); } @@ -724,11 +732,13 @@ default String method() { /** * @return The Content-Type header. Default is: {@literal*}/{@literal*}. */ + @Nonnull MediaType type(); /** * @return The value of the Accept header. Default is: {@literal*}/{@literal*}. */ + @Nonnull List accept(); /** @@ -762,6 +772,7 @@ default String method() { * @param types Types to test. * @return The best acceptable type. */ + @Nonnull default Optional accepts(final String... types) { return accepts(MediaType.valueOf(types)); } @@ -835,6 +846,7 @@ default boolean is(final List types) { * @param types Types to test. * @return The best acceptable type. */ + @Nonnull default Optional accepts(final MediaType... types) { return accepts(ImmutableList.copyOf(types)); } @@ -870,6 +882,7 @@ default Optional accepts(final MediaType... types) { * @param types Types to test for. * @return The best acceptable type. */ + @Nonnull Optional accepts(List types); /** @@ -885,6 +898,7 @@ default Optional accepts(final MediaType... types) { * * @return All the parameters. */ + @Nonnull Mutant params(); /** @@ -901,6 +915,7 @@ default Optional accepts(final MediaType... types) { * @param xss Xss filter to apply. * @return All the parameters. */ + @Nonnull Mutant params(String... xss); /** @@ -910,6 +925,7 @@ default Optional accepts(final MediaType... types) { * @param Value type. * @return Instance of object. */ + @Nonnull default T params(final Class type) { return params().to(type); } @@ -921,6 +937,7 @@ default T params(final Class type) { * @param Value type. * @return Instance of object. */ + @Nonnull default T form(final Class type) { return params().to(type); } @@ -933,6 +950,7 @@ default T form(final Class type) { * @param Value type. * @return Instance of object. */ + @Nonnull default T params(final Class type, final String... xss) { return params(xss).to(type); } @@ -945,6 +963,7 @@ default T params(final Class type, final String... xss) { * @param Value type. * @return Instance of object. */ + @Nonnull default T form(final Class type, final String... xss) { return params(xss).to(type); } @@ -976,6 +995,7 @@ default T form(final Class type, final String... xss) { * @param name A parameter's name. * @return A HTTP request parameter. */ + @Nonnull Mutant param(String name); /** @@ -1006,6 +1026,7 @@ default T form(final Class type, final String... xss) { * @param xss Xss filter to apply. * @return A HTTP request parameter. */ + @Nonnull Mutant param(String name, String... xss); /** @@ -1016,6 +1037,7 @@ default T form(final Class type, final String... xss) { * @return An {@link Upload}. * @throws IOException */ + @Nonnull default Upload file(final String name) throws IOException { List files = files(name); if (files.size() == 0) { @@ -1032,6 +1054,7 @@ default Upload file(final String name) throws IOException { * @return An {@link Upload}. * @throws IOException */ + @Nonnull default Optional ifFile(final String name) throws IOException { List files = files(name); return files.size() == 0 ? Optional.empty() : Optional.of(files.get(0)); @@ -1045,6 +1068,7 @@ default Optional ifFile(final String name) throws IOException { * @return A list of {@link Upload}. * @throws IOException */ + @Nonnull List files(final String name) throws IOException; /** @@ -1053,6 +1077,7 @@ default Optional ifFile(final String name) throws IOException { * @param name A header's name. * @return A HTTP request header. */ + @Nonnull Mutant header(String name); /** @@ -1062,11 +1087,13 @@ default Optional ifFile(final String name) throws IOException { * @param xss Xss escapers. * @return A HTTP request header. */ + @Nonnull Mutant header(final String name, final String... xss); /** * @return All the headers. */ + @Nonnull Map headers(); /** @@ -1075,11 +1102,13 @@ default Optional ifFile(final String name) throws IOException { * @param name Cookie's name. * @return A cookie or an empty optional. */ + @Nonnull Mutant cookie(String name); /** * @return All the cookies. */ + @Nonnull List cookies(); /** @@ -1089,6 +1118,7 @@ default Optional ifFile(final String name) throws IOException { * @return The HTTP body. * @throws Exception If body can't be converted or there is no HTTP body. */ + @Nonnull Mutant body() throws Exception; /** @@ -1102,6 +1132,7 @@ default Optional ifFile(final String name) throws IOException { * @return Instance of object. * @throws Exception If body can't be converted or there is no HTTP body. */ + @Nonnull default T body(final Class type) throws Exception { return body().to(type); } @@ -1112,6 +1143,7 @@ default T body(final Class type) throws Exception { * * @return A current charset. */ + @Nonnull Charset charset(); /** @@ -1119,6 +1151,7 @@ default T body(final Class type) throws Exception { * * @return A list of matching locales or empty list. */ + @Nonnull default List locales() { return locales(Locale::filter); } @@ -1140,6 +1173,7 @@ default List locales() { * @param filter A locale filter. * @return A list of matching locales. */ + @Nonnull List locales(BiFunction, List, List> filter); /** @@ -1159,6 +1193,7 @@ default List locales() { * @param filter A locale filter. * @return A matching locale. */ + @Nonnull Locale locale(BiFunction, List, Locale> filter); /** @@ -1167,6 +1202,7 @@ default List locales() { * * @return A matching locale. */ + @Nonnull default Locale locale() { return locale((priorityList, locales) -> Optional.ofNullable(Locale.lookup(priorityList, locales)) .orElse(locales.get(0))); @@ -1181,6 +1217,7 @@ default Locale locale() { /** * @return The IP address of the client or last proxy that sent the request. */ + @Nonnull String ip(); /** @@ -1192,6 +1229,7 @@ default Locale locale() { /** * @return The currently matched {@link Route}. */ + @Nonnull Route route(); /** @@ -1200,17 +1238,20 @@ default Locale locale() { * * @return The fully qualified name of the server. */ + @Nonnull String hostname(); /** * @return The current session associated with this request or if the request does not have a * session, creates one. */ + @Nonnull Session session(); /** * @return The current session associated with this request if there is one. */ + @Nonnull Optional ifSession(); /** @@ -1227,6 +1268,7 @@ default boolean xhr() { * @return The name and version of the protocol the request uses in the form * protocol/majorVersion.minorVersion, for example, HTTP/1.1 */ + @Nonnull String protocol(); /** @@ -1241,6 +1283,7 @@ default boolean xhr() { * @param value Attribute's local. NOT null. * @return This request. */ + @Nonnull Request set(String name, Object value); /** @@ -1264,6 +1307,7 @@ default boolean xhr() { * @return A mutable map with attributes from {@link FlashScope}. * @throws Err Bad request error if the {@link FlashScope} was not installed it. */ + @Nonnull default Map flash() throws Err { Optional> flash = ifGet(FlashScope.NAME); return flash.orElseThrow(() -> new Err(Status.BAD_REQUEST, @@ -1280,6 +1324,7 @@ default Map flash() throws Err { * @param value Attribute's value. * @return This request. */ + @Nonnull default Request flash(final String name, final Object value) { requireNonNull(name, "Attribute's name is required."); Map flash = flash(); @@ -1297,6 +1342,7 @@ default Request flash(final String name, final Object value) { * @param name Attribute's name. * @return Optional flash attribute. */ + @Nonnull default Optional ifFlash(final String name) { return Optional.ofNullable(flash().get(name)); } @@ -1308,6 +1354,7 @@ default Optional ifFlash(final String name) { * @return Flash attribute. * @throws Err Bad request error if flash attribute is missing. */ + @Nonnull default String flash(final String name) throws Err { return ifFlash(name) .orElseThrow(() -> new Err(Status.BAD_REQUEST, @@ -1329,6 +1376,7 @@ default boolean isSet(final String name) { * @param Target type. * @return A local attribute. */ + @Nonnull Optional ifGet(String name); /** @@ -1339,6 +1387,7 @@ default boolean isSet(final String name) { * @param Target type. * @return A local attribute. */ + @Nonnull default T get(final String name, final T def) { Optional opt = ifGet(name); return opt.orElse(def); @@ -1352,6 +1401,7 @@ default T get(final String name, final T def) { * @return A local attribute. * @throws Err with {@link Status#BAD_REQUEST}. */ + @Nonnull default T get(final String name) { Optional opt = ifGet(name); return opt.orElseThrow( @@ -1365,6 +1415,7 @@ default T get(final String name) { * @param Target type. * @return A local attribute. */ + @Nonnull Optional unset(String name); /** @@ -1372,6 +1423,7 @@ default T get(final String name) { * * @return Attributes locals. */ + @Nonnull Map attributes(); /** @@ -1381,6 +1433,7 @@ default T get(final String name) { * @param value Actual object to bind. * @return Current request. */ + @Nonnull default Request set(final Class type, final Object value) { return set(TypeLiteral.get(type), value); } @@ -1392,6 +1445,7 @@ default Request set(final Class type, final Object value) { * @param value Actual object to bind. * @return Current request. */ + @Nonnull default Request set(final TypeLiteral type, final Object value) { return set(Key.get(type), value); } @@ -1403,6 +1457,7 @@ default Request set(final TypeLiteral type, final Object value) { * @param value Actual object to bind. * @return Current request. */ + @Nonnull Request set(Key key, Object value); /** @@ -1411,6 +1466,7 @@ default Request set(final TypeLiteral type, final Object value) { * @param path Path of the resource to push. * @return This request. */ + @Nonnull default Request push(final String path) { return push(path, ImmutableMap.of()); } @@ -1422,6 +1478,7 @@ default Request push(final String path) { * @param headers Headers to send. * @return This request. */ + @Nonnull Request push(final String path, final Map headers); /** diff --git a/jooby/src/main/java/org/jooby/Response.java b/jooby/src/main/java/org/jooby/Response.java index 66b9e9ff23..211f46d97e 100644 --- a/jooby/src/main/java/org/jooby/Response.java +++ b/jooby/src/main/java/org/jooby/Response.java @@ -215,6 +215,8 @@ import com.google.common.collect.ImmutableList; +import javax.annotation.Nonnull; + /** * Give you access to the actual HTTP response. You can read/write headers and write HTTP body. * @@ -496,6 +498,7 @@ default void download(final String filename, final File file) throws Throwable { * @param value A cookie's value. * @return This response. */ + @Nonnull default Response cookie(final String name, final String value) { return cookie(new Cookie.Definition(name, value)); } @@ -506,6 +509,7 @@ default Response cookie(final String name, final String value) { * @param cookie A cookie definition. * @return This response. */ + @Nonnull Response cookie(final Cookie.Definition cookie); /** @@ -514,6 +518,7 @@ default Response cookie(final String name, final String value) { * @param cookie A cookie. * @return This response. */ + @Nonnull Response cookie(Cookie cookie); /** @@ -522,6 +527,7 @@ default Response cookie(final String name, final String value) { * @param name Cookie's name. * @return This response. */ + @Nonnull Response clearCookie(String name); /** @@ -530,6 +536,7 @@ default Response cookie(final String name, final String value) { * @param name A name. * @return A HTTP header. */ + @Nonnull Mutant header(String name); /** @@ -540,6 +547,7 @@ default Response cookie(final String name, final String value) { * @param value Header's value. * @return This response. */ + @Nonnull Response header(String name, Object value); /** @@ -550,6 +558,7 @@ default Response cookie(final String name, final String value) { * @param values Header's value. * @return This response. */ + @Nonnull default Response header(final String name, final Object... values) { return header(name, ImmutableList.builder().add(values).build()); } @@ -562,6 +571,7 @@ default Response header(final String name, final Object... values) { * @param values Header's value. * @return This response. */ + @Nonnull Response header(String name, Iterable values); /** @@ -571,6 +581,7 @@ default Response header(final String name, final Object... values) { * * @return A current charset. */ + @Nonnull Charset charset(); /** @@ -580,6 +591,7 @@ default Response header(final String name, final Object... values) { * @param charset A charset. * @return This response. */ + @Nonnull Response charset(Charset charset); /** @@ -588,11 +600,13 @@ default Response header(final String name, final Object... values) { * @param length Length of response. * @return This response. */ + @Nonnull Response length(long length); /** * @return Get the response type. */ + @Nonnull Optional type(); /** @@ -601,6 +615,7 @@ default Response header(final String name, final Object... values) { * @param type A media type. * @return This response. */ + @Nonnull Response type(MediaType type); /** @@ -609,6 +624,7 @@ default Response header(final String name, final Object... values) { * @param type A media type. * @return This response. */ + @Nonnull default Response type(final String type) { return type(MediaType.valueOf(type)); } @@ -767,6 +783,7 @@ default void redirect(final String location) throws Throwable { /** * @return A HTTP status or empty if status was not set yet. */ + @Nonnull Optional status(); /** @@ -775,6 +792,7 @@ default void redirect(final String location) throws Throwable { * @param status A HTTP status. * @return This response. */ + @Nonnull Response status(Status status); /** @@ -783,6 +801,7 @@ default void redirect(final String location) throws Throwable { * @param status A HTTP status. * @return This response. */ + @Nonnull default Response status(final int status) { return status(Status.valueOf(status)); } diff --git a/jooby/src/main/java/org/jooby/Result.java b/jooby/src/main/java/org/jooby/Result.java index 4ebb124771..b2d871acf2 100644 --- a/jooby/src/main/java/org/jooby/Result.java +++ b/jooby/src/main/java/org/jooby/Result.java @@ -215,6 +215,9 @@ import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + /** * Utility class for HTTP responses. Usually you start with a result {@link Results builder} and * then you customize (or not) one or more HTTP attribute. @@ -336,6 +339,7 @@ protected Result clone() { * @param status A new response status to use. * @return This content. */ + @Nonnull public Result status(final Status status) { this.status = requireNonNull(status, "A status is required."); return this; @@ -347,6 +351,7 @@ public Result status(final Status status) { * @param status A new response status to use. * @return This content. */ + @Nonnull public Result status(final int status) { return status(Status.valueOf(status)); } @@ -357,6 +362,7 @@ public Result status(final int status) { * @param type A content type. * @return This content. */ + @Nonnull public Result type(final MediaType type) { this.type = requireNonNull(type, "A content type is required."); return this; @@ -368,6 +374,7 @@ public Result type(final MediaType type) { * @param type A content type. * @return This content. */ + @Nonnull public Result type(final String type) { return type(MediaType.valueOf(type)); } @@ -378,6 +385,7 @@ public Result type(final String type) { * @param content A result content. * @return This content. */ + @Nonnull public Result set(final Object content) { this.value = content; return this; @@ -390,6 +398,7 @@ public Result set(final Object content) { * @param supplier An object supplier. * @return This result. */ + @Nonnull public Result when(final String type, final Supplier supplier) { return when(MediaType.valueOf(type), supplier); } @@ -401,6 +410,7 @@ public Result when(final String type, final Supplier supplier) { * @param supplier An object supplier. * @return This result. */ + @Nonnull public Result when(final MediaType type, final Supplier supplier) { return new ContentNegotiation(this).when(type, supplier); } @@ -408,6 +418,7 @@ public Result when(final MediaType type, final Supplier supplier) { /** * @return headers for content. */ + @Nonnull public Map headers() { return headers; } @@ -415,6 +426,7 @@ public Map headers() { /** * @return Body status. */ + @Nonnull public Optional status() { return Optional.ofNullable(status); } @@ -422,6 +434,7 @@ public Optional status() { /** * @return Body type. */ + @Nonnull public Optional type() { return Optional.ofNullable(type); } @@ -431,6 +444,7 @@ public Optional type() { * * @return Value or empty */ + @Nonnull public Optional ifGet() { return ifGet(MediaType.ALL); } @@ -442,6 +456,7 @@ public Optional ifGet() { * @return Value or null */ @SuppressWarnings("unchecked") + @Nullable public T get() { return (T) value; } @@ -452,6 +467,7 @@ public T get() { * @param types Accept header. * @return Result content. */ + @Nonnull public Optional ifGet(final List types) { return Optional.ofNullable(value); } @@ -464,6 +480,7 @@ public Optional ifGet(final List types) { * @return Result content or null. */ @SuppressWarnings("unchecked") + @Nullable public T get(final List types) { return (T) value; } @@ -476,6 +493,7 @@ public T get(final List types) { * @param value Header's value. * @return This content. */ + @Nonnull public Result header(final String name, final Object value) { requireNonNull(name, "Header's name is required."); requireNonNull(value, "Header's value is required."); @@ -492,6 +510,7 @@ public Result header(final String name, final Object value) { * @param values Header's values. * @return This content. */ + @Nonnull public Result header(final String name, final Object... values) { requireNonNull(name, "Header's name is required."); requireNonNull(values, "Header's values are required."); @@ -507,6 +526,7 @@ public Result header(final String name, final Object... values) { * @param values Header's values. * @return This content. */ + @Nonnull public Result header(final String name, final Iterable values) { requireNonNull(name, "Header's name is required."); requireNonNull(values, "Header's values are required."); diff --git a/jooby/src/main/java/org/jooby/Results.java b/jooby/src/main/java/org/jooby/Results.java index 92aa75e252..bf550cbafd 100644 --- a/jooby/src/main/java/org/jooby/Results.java +++ b/jooby/src/main/java/org/jooby/Results.java @@ -205,6 +205,7 @@ import static java.util.Objects.requireNonNull; +import javax.annotation.Nonnull; import java.util.function.Supplier; /** @@ -221,6 +222,7 @@ public class Results { * @param entity A result value. * @return A new result. */ + @Nonnull public static Result with(final Object entity) { return new Result().set(entity); } @@ -232,6 +234,7 @@ public static Result with(final Object entity) { * @param status A HTTP status. * @return A new result. */ + @Nonnull public static Result with(final Object entity, final Status status) { return new Result().status(status).set(entity); } @@ -243,6 +246,7 @@ public static Result with(final Object entity, final Status status) { * @param status A HTTP status. * @return A new result. */ + @Nonnull public static Result with(final Object entity, final int status) { return with(entity, Status.valueOf(status)); } @@ -253,6 +257,7 @@ public static Result with(final Object entity, final int status) { * @param status A status! * @return A new result. */ + @Nonnull public static Result with(final Status status) { requireNonNull(status, "A HTTP status is required."); return new Result().status(status); @@ -264,6 +269,7 @@ public static Result with(final Status status) { * @param status A status! * @return A new result. */ + @Nonnull public static Result with(final int status) { requireNonNull(status, "A HTTP status is required."); return new Result().status(status); @@ -272,6 +278,7 @@ public static Result with(final int status) { /** * @return A new result with {@link Status#OK}. */ + @Nonnull public static Result ok() { return with(Status.OK); } @@ -280,6 +287,7 @@ public static Result ok() { * @param view View to render. * @return A new view. */ + @Nonnull public static View html(final String view) { return new View(view); } @@ -288,6 +296,7 @@ public static View html(final String view) { * @param entity A result content! * @return A new json result. */ + @Nonnull public static Result json(final Object entity) { return with(entity, 200).type(MediaType.json); } @@ -296,6 +305,7 @@ public static Result json(final Object entity) { * @param entity A result content! * @return A new json result. */ + @Nonnull public static Result xml(final Object entity) { return with(entity, 200).type(MediaType.xml); } @@ -304,6 +314,7 @@ public static Result xml(final Object entity) { * @param entity A result content! * @return A new result with {@link Status#OK} and given content. */ + @Nonnull public static Result ok(final Object entity) { return ok().set(entity); } @@ -311,6 +322,7 @@ public static Result ok(final Object entity) { /** * @return A new result with {@link Status#ACCEPTED}. */ + @Nonnull public static Result accepted() { return with(Status.ACCEPTED); } @@ -319,6 +331,7 @@ public static Result accepted() { * @param content A result content! * @return A new result with {@link Status#ACCEPTED}. */ + @Nonnull public static Result accepted(final Object content) { return accepted().set(content); } @@ -326,6 +339,7 @@ public static Result accepted(final Object content) { /** * @return A new result with {@link Status#NO_CONTENT}. */ + @Nonnull public static Result noContent() { return with(Status.NO_CONTENT); } @@ -388,6 +402,7 @@ public static Result noContent() { * @param location A location. * @return A new result. */ + @Nonnull public static Result redirect(final String location) { return redirect(Status.FOUND, location); } @@ -450,6 +465,7 @@ public static Result redirect(final String location) { * @param location A location. * @return A new result. */ + @Nonnull public static Result tempRedirect(final String location) { return redirect(Status.TEMPORARY_REDIRECT, location); } @@ -512,6 +528,7 @@ public static Result tempRedirect(final String location) { * @param location A location. * @return A new result. */ + @Nonnull public static Result moved(final String location) { return redirect(Status.MOVED_PERMANENTLY, location); } @@ -574,6 +591,7 @@ public static Result moved(final String location) { * @param location A location. * @return A new result. */ + @Nonnull public static Result seeOther(final String location) { return redirect(Status.SEE_OTHER, location); } @@ -597,6 +615,7 @@ public static Result seeOther(final String location) { * @param supplier A result supplier. * @return A new result. */ + @Nonnull public static Result when(final String type, final Supplier supplier) { return new Result().when(type, supplier); } @@ -620,6 +639,7 @@ public static Result when(final String type, final Supplier supplier) { * @param supplier A result supplier. * @return A new result. */ + @Nonnull public static Result when(final MediaType type, final Supplier supplier) { return new Result().when(type, supplier); } diff --git a/jooby/src/main/java/org/jooby/Route.java b/jooby/src/main/java/org/jooby/Route.java index 8869c20adb..0f8cd393d6 100644 --- a/jooby/src/main/java/org/jooby/Route.java +++ b/jooby/src/main/java/org/jooby/Route.java @@ -220,6 +220,8 @@ import org.jooby.internal.SourceProvider; import org.jooby.funzy.Throwing; +import javax.annotation.Nonnull; +import javax.annotation.Nullable; import java.lang.reflect.Array; import java.lang.reflect.Method; import java.util.ArrayList; @@ -448,6 +450,7 @@ public String toString() { /** * @return Class where the route */ + @Nonnull Optional declaringClass(); } @@ -520,6 +523,7 @@ interface Mapper { * @return A new mapper. */ @SuppressWarnings({"rawtypes", "unchecked"}) + @Nonnull static Mapper chain(final Mapper it, final Mapper next) { return create(it.name() + ">" + next.name(), v -> next.map(it.map(v))); } @@ -532,6 +536,7 @@ static Mapper chain(final Mapper it, final Mapper next) { * @param Value type. * @return A new mapper. */ + @Nonnull static Mapper create(final String name, final Throwing.Function fn) { return new Route.Mapper() { @Override @@ -554,6 +559,7 @@ public String toString() { /** * @return Mapper's name. */ + @Nonnull default String name() { String name = Optional.ofNullable(Strings.emptyToNull(getClass().getSimpleName())) .orElseGet(() -> { @@ -570,6 +576,7 @@ default String name() { * @return Mapped value. * @throws Throwable If mapping fails. */ + @Nonnull Object map(T value) throws Throwable; } @@ -590,6 +597,7 @@ interface Props> { * @param value Attribute's value. * @return This instance. */ + @Nonnull T attr(String name, Object value); /** @@ -598,6 +606,7 @@ interface Props> { * @param name A renderer's name. * @return This instance. */ + @Nonnull T renderer(final String name); /** @@ -605,6 +614,7 @@ interface Props> { * * @return Explicit renderer to use or null. */ + @Nullable String renderer(); /** @@ -615,6 +625,7 @@ interface Props> { * @param name A route's name. * @return This instance. */ + @Nonnull T name(final String name); /** @@ -623,6 +634,7 @@ interface Props> { * @param consumes The media types to test for. * @return This instance. */ + @Nonnull default T consumes(final MediaType... consumes) { return consumes(Arrays.asList(consumes)); } @@ -633,6 +645,7 @@ default T consumes(final MediaType... consumes) { * @param consumes The media types to test for. * @return This instance. */ + @Nonnull default T consumes(final String... consumes) { return consumes(MediaType.valueOf(consumes)); } @@ -643,6 +656,7 @@ default T consumes(final String... consumes) { * @param consumes The media types to test for. * @return This instance. */ + @Nonnull T consumes(final List consumes); /** @@ -651,6 +665,7 @@ default T consumes(final String... consumes) { * @param produces The media types to test for. * @return This instance. */ + @Nonnull default T produces(final MediaType... produces) { return produces(Arrays.asList(produces)); } @@ -661,6 +676,7 @@ default T produces(final MediaType... produces) { * @param produces The media types to test for. * @return This instance. */ + @Nonnull default T produces(final String... produces) { return produces(MediaType.valueOf(produces)); } @@ -671,6 +687,7 @@ default T produces(final String... produces) { * @param produces The media types to test for. * @return This instance. */ + @Nonnull T produces(final List produces); /** @@ -687,6 +704,7 @@ default T produces(final String... produces) { * @param excludes A path pattern. * @return This instance. */ + @Nonnull default T excludes(final String... excludes) { return excludes(Arrays.asList(excludes)); } @@ -705,8 +723,10 @@ default T excludes(final String... excludes) { * @param excludes A path pattern. * @return This instance. */ + @Nonnull T excludes(final List excludes); + @Nonnull T map(Mapper mapper); } @@ -754,41 +774,49 @@ public List routes() { // ******************************************************************************************** // ALL // ******************************************************************************************** + @Nonnull public Group all(final String pattern, final Route.Filter filter) { newRoute("*", pattern, filter); return this; } + @Nonnull public Group all(final String pattern, final Route.Handler handler) { newRoute("*", pattern, handler); return this; } + @Nonnull public Group all(final String pattern, final Route.OneArgHandler handler) { newRoute("*", pattern, handler); return this; } + @Nonnull public Group all(final String pattern, final Route.ZeroArgHandler handler) { newRoute("*", pattern, handler); return this; } + @Nonnull public Group all(final Route.Filter filter) { newRoute("*", "", filter); return this; } + @Nonnull public Group all(final Route.Handler handler) { newRoute("*", "", handler); return this; } + @Nonnull public Group all(final Route.OneArgHandler handler) { newRoute("*", "", handler); return this; } + @Nonnull public Group all(final Route.ZeroArgHandler handler) { newRoute("*", "", handler); return this; @@ -797,41 +825,49 @@ public Group all(final Route.ZeroArgHandler handler) { // ******************************************************************************************** // GET // ******************************************************************************************** + @Nonnull public Group get(final String pattern, final Route.Filter filter) { newRoute(GET, pattern, filter); return this; } + @Nonnull public Group get(final String pattern, final Route.Handler handler) { newRoute(GET, pattern, handler); return this; } + @Nonnull public Group get(final String pattern, final Route.OneArgHandler handler) { newRoute(GET, pattern, handler); return this; } + @Nonnull public Group get(final String pattern, final Route.ZeroArgHandler handler) { newRoute(GET, pattern, handler); return this; } + @Nonnull public Group get(final Route.Filter filter) { newRoute(GET, "", filter); return this; } + @Nonnull public Group get(final Route.Handler handler) { newRoute(GET, "", handler); return this; } + @Nonnull public Group get(final Route.OneArgHandler handler) { newRoute(GET, "", handler); return this; } + @Nonnull public Group get(final Route.ZeroArgHandler handler) { newRoute(GET, "", handler); return this; @@ -840,41 +876,49 @@ public Group get(final Route.ZeroArgHandler handler) { // ******************************************************************************************** // POST // ******************************************************************************************** + @Nonnull public Group post(final String pattern, final Route.Filter filter) { newRoute(POST, pattern, filter); return this; } + @Nonnull public Group post(final String pattern, final Route.Handler handler) { newRoute(POST, pattern, handler); return this; } + @Nonnull public Group post(final String pattern, final Route.OneArgHandler handler) { newRoute(POST, pattern, handler); return this; } + @Nonnull public Group post(final String pattern, final Route.ZeroArgHandler handler) { newRoute(POST, pattern, handler); return this; } + @Nonnull public Group post(final Route.Filter filter) { newRoute(POST, "", filter); return this; } + @Nonnull public Group post(final Route.Handler handler) { newRoute(POST, "", handler); return this; } + @Nonnull public Group post(final Route.OneArgHandler handler) { newRoute(POST, "", handler); return this; } + @Nonnull public Group post(final Route.ZeroArgHandler handler) { newRoute(POST, "", handler); return this; @@ -883,41 +927,49 @@ public Group post(final Route.ZeroArgHandler handler) { // ******************************************************************************************** // PUT // ******************************************************************************************** + @Nonnull public Group put(final String pattern, final Route.Filter filter) { newRoute(PUT, pattern, filter); return this; } + @Nonnull public Group put(final String pattern, final Route.Handler handler) { newRoute(PUT, pattern, handler); return this; } + @Nonnull public Group put(final String pattern, final Route.OneArgHandler handler) { newRoute(PUT, pattern, handler); return this; } + @Nonnull public Group put(final String pattern, final Route.ZeroArgHandler handler) { newRoute(PUT, pattern, handler); return this; } + @Nonnull public Group put(final Route.Filter filter) { newRoute(PUT, "", filter); return this; } + @Nonnull public Group put(final Route.Handler handler) { newRoute(PUT, "", handler); return this; } + @Nonnull public Group put(final Route.OneArgHandler handler) { newRoute(PUT, "", handler); return this; } + @Nonnull public Group put(final Route.ZeroArgHandler handler) { newRoute(PUT, "", handler); return this; @@ -926,41 +978,49 @@ public Group put(final Route.ZeroArgHandler handler) { // ******************************************************************************************** // DELETE // ******************************************************************************************** + @Nonnull public Group delete(final String pattern, final Route.Filter filter) { newRoute(DELETE, pattern, filter); return this; } + @Nonnull public Group delete(final String pattern, final Route.Handler handler) { newRoute(DELETE, pattern, handler); return this; } + @Nonnull public Group delete(final String pattern, final Route.OneArgHandler handler) { newRoute(DELETE, pattern, handler); return this; } + @Nonnull public Group delete(final String pattern, final Route.ZeroArgHandler handler) { newRoute(DELETE, pattern, handler); return this; } + @Nonnull public Group delete(final Route.Filter filter) { newRoute(DELETE, "", filter); return this; } + @Nonnull public Group delete(final Route.Handler handler) { newRoute(DELETE, "", handler); return this; } + @Nonnull public Group delete(final Route.OneArgHandler handler) { newRoute(DELETE, "", handler); return this; } + @Nonnull public Group delete(final Route.ZeroArgHandler handler) { newRoute(DELETE, "", handler); return this; @@ -969,41 +1029,49 @@ public Group delete(final Route.ZeroArgHandler handler) { // ******************************************************************************************** // PATCH // ******************************************************************************************** + @Nonnull public Group patch(final String pattern, final Route.Filter filter) { newRoute(PATCH, pattern, filter); return this; } + @Nonnull public Group patch(final String pattern, final Route.Handler handler) { newRoute(PATCH, pattern, handler); return this; } + @Nonnull public Group patch(final String pattern, final Route.OneArgHandler handler) { newRoute(PATCH, pattern, handler); return this; } + @Nonnull public Group patch(final String pattern, final Route.ZeroArgHandler handler) { newRoute(PATCH, pattern, handler); return this; } + @Nonnull public Group patch(final Route.Filter filter) { newRoute(PATCH, "", filter); return this; } + @Nonnull public Group patch(final Route.Handler handler) { newRoute(PATCH, "", handler); return this; } + @Nonnull public Group patch(final Route.OneArgHandler handler) { newRoute(PATCH, "", handler); return this; } + @Nonnull public Group patch(final Route.ZeroArgHandler handler) { newRoute(PATCH, "", handler); return this; @@ -1016,6 +1084,7 @@ public Group patch(final Route.ZeroArgHandler handler) { * @return This instance. */ @Override + @Nonnull public Group name(final String name) { for (Definition definition : routes) { if (prefix != null) { @@ -1028,6 +1097,7 @@ public Group name(final String name) { } @Override + @Nonnull public Group consumes(final List types) { for (Definition definition : routes) { definition.consumes(types); @@ -1036,6 +1106,7 @@ public Group consumes(final List types) { } @Override + @Nonnull public Group produces(final List types) { for (Definition definition : routes) { definition.produces(types); @@ -1044,6 +1115,7 @@ public Group produces(final List types) { } @Override + @Nonnull public Group attr(final String name, final Object value) { for (Definition definition : routes) { definition.attr(name, value); @@ -1052,6 +1124,7 @@ public Group attr(final String name, final Object value) { } @Override + @Nonnull public Group excludes(final List excludes) { for (Definition definition : routes) { definition.excludes(excludes); @@ -1060,6 +1133,7 @@ public Group excludes(final List excludes) { } @Override + @Nonnull public Group map(final Mapper mapper) { for (Definition definition : routes) { definition.map(mapper); @@ -1383,11 +1457,12 @@ public Definition(final String method, final String pattern, * * @return A path pattern. */ + @Nonnull public String pattern() { return pattern; } - @Override + @Nonnull public String renderer() { return renderer; } @@ -1401,6 +1476,7 @@ public Definition renderer(final String name) { /** * @return List of path variables (if any). */ + @Nonnull public List vars() { return cpattern.vars(); } @@ -1412,6 +1488,7 @@ public List vars() { * @return Indicates if the {@link #pattern()} contains a glob charecter, like ?, * * or **. */ + @Nonnull public boolean glob() { return cpattern.glob(); } @@ -1421,6 +1498,7 @@ public boolean glob() { * * @return Source information (where the route was defined). */ + @Nonnull public Route.Source source() { return new RouteSourceImpl(declaringClass, line); } @@ -1431,6 +1509,7 @@ public Route.Source source() { * @param vars Path variables. * @return A route pattern. */ + @Nonnull public String reverse(final Map vars) { return cpattern.reverse(vars); } @@ -1441,11 +1520,13 @@ public String reverse(final Map vars) { * @param values Path variable values. * @return A route pattern. */ + @Nonnull public String reverse(final Object... values) { return cpattern.reverse(values); } @Override + @Nonnull public Definition attr(final String name, final Object value) { requireNonNull(name, "Attribute name is required."); requireNonNull(value, "Attribute value is required."); @@ -1480,6 +1561,7 @@ private boolean valid(final Object value) { * @return Attribute's value or null. */ @SuppressWarnings("unchecked") + @Nonnull public T attr(final String name) { return (T) attributes.get(name); } @@ -1487,6 +1569,7 @@ public T attr(final String name) { /** * @return A read only view of attributes. */ + @Nonnull public Map attributes() { return attributes; } @@ -1500,6 +1583,7 @@ public Map attributes() { * @param accept The Accept header. * @return A route or an empty optional. */ + @Nonnull public Optional matches(final String method, final String path, final MediaType contentType, final List accept) { @@ -1524,6 +1608,7 @@ public Optional matches(final String method, /** * @return HTTP method or *. */ + @Nonnull public String method() { return method; } @@ -1531,6 +1616,7 @@ public String method() { /** * @return Handler behind this route. */ + @Nonnull public Route.Filter filter() { return filter; } @@ -1541,6 +1627,7 @@ public Route.Filter filter() { * * @return Route name. Default is: anonymous. */ + @Nonnull public String name() { return name; } @@ -1554,6 +1641,7 @@ public String name() { * @return This definition. */ @Override + @Nonnull public Definition name(final String name) { checkArgument(!Strings.isNullOrEmpty(name), "A route's name is required."); this.name = normalize(prefix != null ? prefix + "/" + name : name); @@ -1645,6 +1733,7 @@ public Definition excludes(final List excludes) { /** * @return List of exclusion filters (if any). */ + @Nonnull public List excludes() { return excludes.stream().map(r -> r.pattern()).collect(Collectors.toList()); } @@ -1661,6 +1750,7 @@ private boolean excludes(final String path) { /** * @return All the types this route can consumes. */ + @Nonnull public List consumes() { return Collections.unmodifiableList(this.consumes); } @@ -1668,11 +1758,13 @@ public List consumes() { /** * @return All the types this route can produces. */ + @Nonnull public List produces() { return Collections.unmodifiableList(this.produces); } @Override + @Nonnull public Definition map(final Mapper mapper) { this.mapper = requireNonNull(mapper, "Mapper is required."); return this; @@ -1684,6 +1776,7 @@ public Definition map(final Mapper mapper) { * @param line Line number. * @return This instance. */ + @Nonnull public Definition line(final int line) { this.line = line; return this; @@ -1695,6 +1788,7 @@ public Definition line(final int line) { * @param declaringClass A source class. * @return This instance. */ + @Nonnull public Definition declaringClass(final String declaringClass) { this.declaringClass = declaringClass; return this; @@ -1976,6 +2070,7 @@ interface MethodHandler extends Handler { * * @return Target method. */ + @Nonnull Method method(); /** @@ -1983,6 +2078,7 @@ interface MethodHandler extends Handler { * * @return Target class. */ + @Nonnull Class implementingClass(); } @@ -2426,16 +2522,19 @@ default void next(final Request req, final Response rsp) throws Throwable { /** * @return Current request path. */ + @Nonnull String path(); /** * @return Current HTTP method. */ + @Nonnull String method(); /** * @return The currently matched pattern. */ + @Nonnull String pattern(); /** @@ -2444,6 +2543,7 @@ default void next(final Request req, final Response rsp) throws Throwable { * * @return Route name, defaults to "anonymous" */ + @Nonnull String name(); /** @@ -2457,16 +2557,19 @@ default void next(final Request req, final Response rsp) throws Throwable { * * @return The currently matched path variables (if any). */ + @Nonnull Map vars(); /** * @return List all the types this route can consumes, defaults is: {@code * / *}. */ + @Nonnull List consumes(); /** * @return List all the types this route can produces, defaults is: {@code * / *}. */ + @Nonnull List produces(); /** @@ -2483,6 +2586,7 @@ default boolean apply(final String prefix) { /** * @return All the available attributes in the execution chain. */ + @Nonnull Map attributes(); /** @@ -2493,6 +2597,7 @@ default boolean apply(final String prefix) { * @return Attribute value. */ @SuppressWarnings("unchecked") + @Nonnull default T attr(final String name) { return (T) attributes().get(name); } @@ -2502,6 +2607,7 @@ default T attr(final String name) { * * @return Explicit renderer to use or null. */ + @Nonnull String renderer(); /** @@ -2519,6 +2625,7 @@ default T attr(final String name) { * @param vars Path variables. * @return A route pattern. */ + @Nonnull String reverse(final Map vars); /** @@ -2527,6 +2634,7 @@ default T attr(final String name) { * @param values Path variable values. * @return A route pattern. */ + @Nonnull String reverse(final Object... values); /** @@ -2535,6 +2643,7 @@ default T attr(final String name) { * @param path A path to normalize. * @return A normalized path. */ + @Nonnull static String normalize(final String path) { return RoutePattern.normalize(path); } @@ -2545,6 +2654,7 @@ static String normalize(final String path) { * @param path Path. * @return Original path. */ + @Nonnull static String unerrpath(final String path) { if (path.charAt(0) == OUT_OF_PATH) { return path.substring(1); @@ -2558,6 +2668,7 @@ static String unerrpath(final String path) { * @param path Path. * @return Invalid path. */ + @Nonnull static String errpath(final String path) { return OUT_OF_PATH + path; } @@ -2567,6 +2678,7 @@ static String errpath(final String path) { * * @return Source information (where the route was defined). */ + @Nonnull Route.Source source(); /** @@ -2575,6 +2687,7 @@ static String errpath(final String path) { * @param indent Indent level * @return Output. */ + @Nonnull default String print(final int indent) { StringBuilder buff = new StringBuilder(); String[] header = {"Method", "Path", "Source", "Name", "Pattern", "Consumes", "Produces"}; @@ -2604,6 +2717,7 @@ default String print(final int indent) { * * @return Output. */ + @Nonnull default String print() { return print(0); } diff --git a/jooby/src/main/java/org/jooby/Router.java b/jooby/src/main/java/org/jooby/Router.java index b8096ccd2e..abe69645b5 100644 --- a/jooby/src/main/java/org/jooby/Router.java +++ b/jooby/src/main/java/org/jooby/Router.java @@ -211,6 +211,8 @@ import org.jooby.Route.Mapper; import org.jooby.handlers.AssetHandler; +import javax.annotation.Nonnull; + /** * Route DSL. Constructs and creates several flavors of jooby routes. * @@ -226,6 +228,7 @@ public interface Router { * @param app Routes provider. * @return This jooby instance. */ + @Nonnull Router use(final Jooby app); /** @@ -236,6 +239,7 @@ public interface Router { * @param app Routes provider. * @return This jooby instance. */ + @Nonnull Router use(final String path, final Jooby app); /** @@ -252,6 +256,7 @@ public interface Router { * @param pattern Global pattern to use. * @return A route namespace. */ + @Nonnull Route.Group use(String pattern); /** @@ -261,6 +266,7 @@ public interface Router { * @param filter A filter to execute. * @return A new route definition. */ + @Nonnull Route.Definition use(String path, Route.Filter filter); /** @@ -271,6 +277,7 @@ public interface Router { * @param filter A filter to execute. * @return A new route definition. */ + @Nonnull Route.Definition use(String method, String path, Route.Filter filter); /** @@ -283,6 +290,7 @@ public interface Router { * @param handler A handler to execute. * @return A new route definition. */ + @Nonnull Route.Definition use(String method, String path, Route.Handler handler); /** @@ -294,6 +302,7 @@ public interface Router { * @param handler A handler to execute. * @return A new route definition. */ + @Nonnull Route.Definition use(String path, Route.Handler handler); /** @@ -303,6 +312,7 @@ public interface Router { * @param handler A handler to execute. * @return A new route definition. */ + @Nonnull Route.Definition use(String path, Route.OneArgHandler handler); /** @@ -318,6 +328,7 @@ public interface Router { * @param handler A handler to execute. * @return A new route definition. */ + @Nonnull Route.Definition get(String path, Route.Handler handler); /** @@ -334,6 +345,7 @@ public interface Router { * @param handler A handler to execute. * @return A new route definition. */ + @Nonnull Route.Collection get(String path1, String path2, Route.Handler handler); /** @@ -351,6 +363,7 @@ public interface Router { * @param handler A handler to execute. * @return A new route definition. */ + @Nonnull Route.Collection get(String path1, String path2, String path3, Route.Handler handler); /** @@ -366,6 +379,7 @@ public interface Router { * @param handler A handler to execute. * @return A new route definition. */ + @Nonnull Route.Definition get(String path, Route.OneArgHandler handler); /** @@ -382,6 +396,7 @@ public interface Router { * @param handler A handler to execute. * @return A new route definition. */ + @Nonnull Route.Collection get(String path1, String path2, Route.OneArgHandler handler); /** @@ -399,6 +414,7 @@ public interface Router { * @param handler A handler to execute. * @return A new route definition. */ + @Nonnull Route.Collection get(String path1, String path2, String path3, Route.OneArgHandler handler); /** @@ -414,6 +430,7 @@ public interface Router { * @param handler A handler to execute. * @return A new route definition. */ + @Nonnull Route.Definition get(String path, Route.ZeroArgHandler handler); /** @@ -430,6 +447,7 @@ public interface Router { * @param handler A handler to execute. * @return A new route definition. */ + @Nonnull Route.Collection get(String path1, String path2, Route.ZeroArgHandler handler); /** @@ -447,6 +465,7 @@ public interface Router { * @param handler A handler to execute. * @return A new route definition. */ + @Nonnull Route.Collection get(String path1, String path2, String path3, Route.ZeroArgHandler handler); /** @@ -462,6 +481,7 @@ public interface Router { * @param filter A filter to execute. * @return A new route definition. */ + @Nonnull Route.Definition get(String path, Route.Filter filter); /** @@ -479,6 +499,7 @@ public interface Router { * @param filter A filter to execute. * @return A new route definition. */ + @Nonnull Route.Collection get(String path1, String path2, Route.Filter filter); /** @@ -496,6 +517,7 @@ public interface Router { * @param filter A filter to execute. * @return A new route definition. */ + @Nonnull Route.Collection get(String path1, String path2, String path3, Route.Filter filter); /** @@ -511,6 +533,7 @@ public interface Router { * @param handler A handler to execute. * @return A new route definition. */ + @Nonnull Route.Definition post(String path, Route.Handler handler); /** @@ -527,6 +550,7 @@ public interface Router { * @param handler A handler to execute. * @return A new route definition. */ + @Nonnull Route.Collection post(String path1, String path2, Route.Handler handler); /** @@ -544,6 +568,7 @@ public interface Router { * @param handler A handler to execute. * @return A new route definition. */ + @Nonnull Route.Collection post(String path1, String path2, String path3, Route.Handler handler); /** @@ -559,6 +584,7 @@ public interface Router { * @param handler A handler to execute. * @return A new route definition. */ + @Nonnull Route.Definition post(String path, Route.OneArgHandler handler); /** @@ -575,6 +601,7 @@ public interface Router { * @param handler A handler to execute. * @return A new route definition. */ + @Nonnull Route.Collection post(String path1, String path2, Route.OneArgHandler handler); /** @@ -592,6 +619,7 @@ public interface Router { * @param handler A handler to execute. * @return A new route definition. */ + @Nonnull Route.Collection post(String path1, String path2, String path3, Route.OneArgHandler handler); /** @@ -607,6 +635,7 @@ public interface Router { * @param handler A handler to execute. * @return A new route definition. */ + @Nonnull Route.Definition post(String path, Route.ZeroArgHandler handler); /** @@ -623,6 +652,7 @@ public interface Router { * @param handler A handler to execute. * @return A new route definition. */ + @Nonnull Route.Collection post(String path1, String path2, Route.ZeroArgHandler handler); /** @@ -640,6 +670,7 @@ public interface Router { * @param handler A handler to execute. * @return A new route definition. */ + @Nonnull Route.Collection post(String path1, String path2, String path3, Route.ZeroArgHandler handler); /** @@ -655,6 +686,7 @@ public interface Router { * @param filter A filter to execute. * @return A new route definition. */ + @Nonnull Route.Definition post(String path, Route.Filter filter); /** @@ -671,6 +703,7 @@ public interface Router { * @param filter A filter to execute. * @return A new route definition. */ + @Nonnull Route.Collection post(String path1, String path2, Route.Filter filter); /** @@ -688,6 +721,7 @@ public interface Router { * @param filter A filter to execute. * @return A new route definition. */ + @Nonnull Route.Collection post(String path1, String path2, String path3, Route.Filter filter); /** @@ -703,6 +737,7 @@ public interface Router { * @param handler A handler to execute. * @return A new route definition. */ + @Nonnull Route.Definition head(String path, Route.Handler handler); /** @@ -718,6 +753,7 @@ public interface Router { * @param handler A handler to execute. * @return A new route definition. */ + @Nonnull Route.Definition head(String path, Route.OneArgHandler handler); /** @@ -733,6 +769,7 @@ public interface Router { * @param handler A handler to execute. * @return A new route definition. */ + @Nonnull Route.Definition head(String path, Route.ZeroArgHandler handler); /** @@ -748,6 +785,7 @@ public interface Router { * @param filter A filter to execute. * @return A new route definition. */ + @Nonnull Route.Definition head(String path, Route.Filter filter); /** @@ -761,6 +799,7 @@ public interface Router { * * @return A new route definition. */ + @Nonnull Route.Definition head(); /** @@ -776,6 +815,7 @@ public interface Router { * @param handler A handler to execute. * @return A new route definition. */ + @Nonnull Route.Definition options(String path, Route.Handler handler); /** @@ -791,6 +831,7 @@ public interface Router { * @param handler A handler to execute. * @return A new route definition. */ + @Nonnull Route.Definition options(String path, Route.OneArgHandler handler); /** @@ -806,6 +847,7 @@ public interface Router { * @param handler A handler to execute. * @return A new route definition. */ + @Nonnull Route.Definition options(String path, Route.ZeroArgHandler handler); /** @@ -822,6 +864,7 @@ public interface Router { * @param filter A callback to execute. * @return A new route definition. */ + @Nonnull Route.Definition options(String path, Route.Filter filter); /** @@ -843,6 +886,7 @@ public interface Router { * * @return A new route definition. */ + @Nonnull Route.Definition options(); /** @@ -858,6 +902,7 @@ public interface Router { * @param handler A route to execute. * @return A new route definition. */ + @Nonnull Route.Definition put(String path, Route.Handler handler); /** @@ -874,6 +919,7 @@ public interface Router { * @param handler A handler to execute. * @return A new route definition. */ + @Nonnull Route.Collection put(String path1, String path2, Route.Handler handler); /** @@ -891,6 +937,7 @@ public interface Router { * @param handler A handler to execute. * @return A new route definition. */ + @Nonnull Route.Collection put(String path1, String path2, String path3, Route.Handler handler); /** @@ -906,6 +953,7 @@ public interface Router { * @param handler A handler to execute. * @return A new route definition. */ + @Nonnull Route.Definition put(String path, Route.OneArgHandler handler); /** @@ -922,6 +970,7 @@ public interface Router { * @param handler A handler to execute. * @return A new route definition. */ + @Nonnull Route.Collection put(String path1, String path2, Route.OneArgHandler handler); @@ -942,6 +991,7 @@ Route.Collection put(String path1, String path2, * @param handler A handler to execute. * @return A new route definition. */ + @Nonnull Route.Collection put(String path1, String path2, String path3, Route.OneArgHandler handler); /** @@ -957,6 +1007,7 @@ Route.Collection put(String path1, String path2, * @param handler A handler to execute. * @return A new route definition. */ + @Nonnull Route.Definition put(String path, Route.ZeroArgHandler handler); /** @@ -975,6 +1026,7 @@ Route.Collection put(String path1, String path2, * @param handler A handler to execute. * @return A new route definition. */ + @Nonnull Route.Collection put(String path1, String path2, Route.ZeroArgHandler handler); /** @@ -994,6 +1046,7 @@ Route.Collection put(String path1, String path2, * @param handler A handler to execute. * @return A new route definition. */ + @Nonnull Route.Collection put(String path1, String path2, String path3, Route.ZeroArgHandler handler); /** @@ -1009,6 +1062,7 @@ Route.Collection put(String path1, String path2, * @param filter A callback to execute. * @return A new route definition. */ + @Nonnull Route.Definition put(String path, Route.Filter filter); /** @@ -1025,6 +1079,7 @@ Route.Collection put(String path1, String path2, * @param filter A filter to execute. * @return A new route definition. */ + @Nonnull Route.Collection put(String path1, String path2, Route.Filter filter); /** @@ -1044,6 +1099,7 @@ Route.Collection put(String path1, String path2, * @param filter A filter to execute. * @return A new route definition. */ + @Nonnull Route.Collection put(String path1, String path2, String path3, Route.Filter filter); /** @@ -1059,6 +1115,7 @@ Route.Collection put(String path1, String path2, * @param handler A route to execute. * @return A new route definition. */ + @Nonnull Route.Definition patch(String path, Route.Handler handler); /** @@ -1075,6 +1132,7 @@ Route.Collection put(String path1, String path2, * @param handler A handler to execute. * @return A new route definition. */ + @Nonnull Route.Collection patch(String path1, String path2, Route.Handler handler); /** @@ -1109,6 +1167,7 @@ Route.Collection put(String path1, String path2, * @param handler A handler to execute. * @return A new route definition. */ + @Nonnull Route.Definition patch(String path, Route.OneArgHandler handler); /** @@ -1127,6 +1186,7 @@ Route.Collection put(String path1, String path2, * @param handler A handler to execute. * @return A new route definition. */ + @Nonnull Route.Collection patch(String path1, String path2, Route.OneArgHandler handler); /** @@ -1146,6 +1206,7 @@ Route.Collection put(String path1, String path2, * @param handler A handler to execute. * @return A new route definition. */ + @Nonnull Route.Collection patch(String path1, String path2, String path3, Route.OneArgHandler handler); /** @@ -1163,6 +1224,7 @@ Route.Collection put(String path1, String path2, * @param handler A handler to execute. * @return A new route definition. */ + @Nonnull Route.Definition patch(String path, Route.ZeroArgHandler handler); /** @@ -1181,6 +1243,7 @@ Route.Collection put(String path1, String path2, * @param handler A handler to execute. * @return A new route definition. */ + @Nonnull Route.Collection patch(String path1, String path2, Route.ZeroArgHandler handler); /** @@ -1200,6 +1263,7 @@ Route.Collection put(String path1, String path2, * @param handler A handler to execute. * @return A new route definition. */ + @Nonnull Route.Collection patch(String path1, String path2, String path3, Route.ZeroArgHandler handler); /** @@ -1215,6 +1279,7 @@ Route.Collection put(String path1, String path2, * @param filter A callback to execute. * @return A new route definition. */ + @Nonnull Route.Definition patch(String path, Route.Filter filter); /** @@ -1231,6 +1296,7 @@ Route.Collection put(String path1, String path2, * @param filter A filter to execute. * @return A new route definition. */ + @Nonnull Route.Collection patch(String path1, String path2, Route.Filter filter); /** @@ -1248,6 +1314,7 @@ Route.Collection put(String path1, String path2, * @param filter A filter to execute. * @return A new route definition. */ + @Nonnull Route.Collection patch(String path1, String path2, String path3, Route.Filter filter); /** @@ -1265,6 +1332,7 @@ Route.Collection put(String path1, String path2, * @param handler A handler to execute. * @return A new route definition. */ + @Nonnull Route.Definition delete(String path, Route.Handler handler); /** @@ -1283,6 +1351,7 @@ Route.Collection put(String path1, String path2, * @param handler A handler to execute. * @return A new route definition. */ + @Nonnull Route.Collection delete(String path1, String path2, Route.Handler handler); /** @@ -1302,6 +1371,7 @@ Route.Collection put(String path1, String path2, * @param handler A handler to execute. * @return A new route definition. */ + @Nonnull Route.Collection delete(String path1, String path2, String path3, Route.Handler handler); /** @@ -1319,6 +1389,7 @@ Route.Collection put(String path1, String path2, * @param handler A handler to execute. * @return A new route definition. */ + @Nonnull Route.Definition delete(String path, Route.OneArgHandler handler); /** @@ -1337,6 +1408,7 @@ Route.Collection put(String path1, String path2, * @param handler A handler to execute. * @return A new route definition. */ + @Nonnull Route.Collection delete(String path1, String path2, Route.OneArgHandler handler); /** @@ -1356,6 +1428,7 @@ Route.Collection put(String path1, String path2, * @param handler A handler to execute. * @return A new route definition. */ + @Nonnull Route.Collection delete(String path1, String path2, String path3, Route.OneArgHandler handler); /** @@ -1373,6 +1446,7 @@ Route.Collection put(String path1, String path2, * @param handler A handler to execute. * @return A new route definition. */ + @Nonnull Route.Definition delete(String path, Route.ZeroArgHandler handler); /** @@ -1389,6 +1463,7 @@ Route.Collection put(String path1, String path2, * @param handler A handler to execute. * @return A new route definition. */ + @Nonnull Route.Collection delete(String path1, String path2, Route.ZeroArgHandler handler); /** @@ -1406,6 +1481,7 @@ Route.Collection put(String path1, String path2, * @param handler A handler to execute. * @return A new route definition. */ + @Nonnull Route.Collection delete(String path1, String path2, String path3, Route.ZeroArgHandler handler); /** @@ -1422,6 +1498,7 @@ Route.Collection put(String path1, String path2, * @param filter A callback to execute. * @return A new route definition. */ + @Nonnull Route.Definition delete(String path, Route.Filter filter); /** @@ -1439,6 +1516,7 @@ Route.Collection put(String path1, String path2, * @param filter A filter to execute. * @return A new route definition. */ + @Nonnull Route.Collection delete(String path1, String path2, Route.Filter filter); /** @@ -1457,6 +1535,7 @@ Route.Collection put(String path1, String path2, * @param filter A filter to execute. * @return A new route definition. */ + @Nonnull Route.Collection delete(String path1, String path2, String path3, Route.Filter filter); @@ -1474,6 +1553,7 @@ Route.Collection delete(String path1, * @param handler A callback to execute. * @return A new route definition. */ + @Nonnull Route.Definition trace(String path, Route.Handler handler); /** @@ -1489,6 +1569,7 @@ Route.Collection delete(String path1, * @param handler A handler to execute. * @return A new route definition. */ + @Nonnull Route.Definition trace(String path, Route.OneArgHandler handler); /** @@ -1504,6 +1585,7 @@ Route.Collection delete(String path1, * @param handler A handler to execute. * @return A new route definition. */ + @Nonnull Route.Definition trace(String path, Route.ZeroArgHandler handler); /** @@ -1519,6 +1601,7 @@ Route.Collection delete(String path1, * @param filter A callback to execute. * @return A new route definition. */ + @Nonnull Route.Definition trace(String path, Route.Filter filter); /** @@ -1533,6 +1616,7 @@ Route.Collection delete(String path1, * * @return A new route definition. */ + @Nonnull Route.Definition trace(); /** @@ -1547,6 +1631,7 @@ Route.Collection delete(String path1, * @param handler A handler to execute. * @return A new route definition. */ + @Nonnull Route.Definition connect(String path, Route.Handler handler); /** @@ -1562,6 +1647,7 @@ Route.Collection delete(String path1, * @param handler A handler to execute. * @return A new route definition. */ + @Nonnull Route.Definition connect(String path, Route.OneArgHandler handler); /** @@ -1577,6 +1663,7 @@ Route.Collection delete(String path1, * @param handler A handler to execute. * @return A new route definition. */ + @Nonnull Route.Definition connect(String path, Route.ZeroArgHandler handler); /** @@ -1592,6 +1679,7 @@ Route.Collection delete(String path1, * @param filter A filter to execute. * @return A new route definition. */ + @Nonnull Route.Definition connect(String path, Route.Filter filter); /** @@ -1621,6 +1709,7 @@ Route.Collection delete(String path1, * @param path The path to publish. * @return A new route definition. */ + @Nonnull default Route.Definition assets(final String path) { return assets(path, "/"); } @@ -1654,6 +1743,7 @@ default Route.Definition assets(final String path) { * @param basedir Base directory. * @return A new route definition. */ + @Nonnull Route.Definition assets(final String path, Path basedir); /** @@ -1699,6 +1789,7 @@ default Route.Definition assets(final String path) { * @param location A resource location. * @return A new route definition. */ + @Nonnull Route.Definition assets(String path, String location); /** @@ -1709,6 +1800,7 @@ default Route.Definition assets(final String path) { * @param handler Asset handler. * @return A new route definition. */ + @Nonnull Route.Definition assets(String path, AssetHandler handler); /** @@ -1745,6 +1837,7 @@ default Route.Definition assets(final String path) { * @param routeClass A route(s) class. * @return This jooby instance. */ + @Nonnull Route.Collection use(Class routeClass); /** @@ -1802,6 +1895,7 @@ default Route.Definition assets(final String path) { * @param chain Chain of before handler. * @return A new route definition. */ + @Nonnull default Route.Collection before(final Route.Before handler, final Route.Before... chain) { return before("*", handler, chain); } @@ -1861,6 +1955,7 @@ default Route.Collection before(final Route.Before handler, final Route.Before.. * @param chain Chain of before handler. * @return A new route definition. */ + @Nonnull default Route.Collection before(final String pattern, final Route.Before handler, final Route.Before... chain) { return before("*", pattern, handler, chain); @@ -1922,6 +2017,7 @@ default Route.Collection before(final String pattern, final Route.Before handler * @param chain Chain of before handler. * @return A new route definition. */ + @Nonnull Route.Collection before(String method, String pattern, Route.Before handler, Route.Before... chain); @@ -1988,6 +2084,7 @@ Route.Collection before(String method, String pattern, Route.Before handler, * @param chain After chain. * @return A new route definition. */ + @Nonnull default Route.Collection after(final Route.After handler, final Route.After... chain) { return after("*", handler, chain); } @@ -2054,6 +2151,7 @@ default Route.Collection after(final Route.After handler, final Route.After... c * @param chain After chain. * @return A new route definition. */ + @Nonnull default Route.Collection after(final String pattern, final Route.After handler, final Route.After... chain) { return after("*", pattern, handler, chain); @@ -2123,6 +2221,7 @@ default Route.Collection after(final String pattern, final Route.After handler, * @param chain After chain. * @return A new route definition. */ + @Nonnull Route.Collection after(String method, String pattern, Route.After handler, Route.After... chain); /** @@ -2228,6 +2327,7 @@ default Route.Collection after(final String pattern, final Route.After handler, * @param chain Complete chain. * @return A new route definition. */ + @Nonnull default Route.Collection complete(final Route.Complete handler, final Route.Complete... chain) { return complete("*", handler, chain); } @@ -2336,6 +2436,7 @@ default Route.Collection complete(final Route.Complete handler, final Route.Comp * @param chain Complete chain. * @return A new route definition. */ + @Nonnull default Route.Collection complete(final String pattern, final Route.Complete handler, final Route.Complete... chain) { return complete("*", pattern, handler, chain); @@ -2445,6 +2546,7 @@ default Route.Collection complete(final String pattern, final Route.Complete han * @param chain Complete chain. * @return A new route definition. */ + @Nonnull Route.Collection complete(String method, String pattern, Route.Complete handler, Route.Complete... chain); @@ -2465,6 +2567,7 @@ Route.Collection complete(String method, String pattern, Route.Complete handler, * @param handler A connect callback. * @return A new WebSocket definition. */ + @Nonnull default WebSocket.Definition ws(final String path, final WebSocket.OnOpen1 handler) { return ws(path, (WebSocket.OnOpen) handler); } @@ -2486,12 +2589,36 @@ default WebSocket.Definition ws(final String path, final WebSocket.OnOpen1 handl * @param handler A connect callback. * @return A new WebSocket definition. */ + @Nonnull WebSocket.Definition ws(String path, WebSocket.OnOpen handler); + /** + * Append a new WebSocket handler under the given path. + * + *
+   *   ws(MyHandler.class);
+   * 
+ * + * @param handler A message callback. + * @return A new WebSocket definition. + */ + @Nonnull default WebSocket.Definition ws(final Class> handler) { return ws("", handler); } + /** + * Append a new WebSocket handler under the given path. + * + *
+   *   ws("/ws", MyHandler.class);
+   * 
+ * + * @param path A path pattern. + * @param handler A message callback. + * @return A new WebSocket definition. + */ + @Nonnull WebSocket.Definition ws(String path, Class> handler); /** @@ -2510,6 +2637,7 @@ default WebSocket.Definition ws(final Class * @param handler Callback. It might executed in a different thread (web server choice). * @return A route definition. */ + @Nonnull Route.Definition sse(String path, Sse.Handler handler); /** @@ -2528,6 +2656,7 @@ default WebSocket.Definition ws(final Class * @param handler Callback. It might executed in a different thread (web server choice). * @return A route definition. */ + @Nonnull Route.Definition sse(String path, Sse.Handler1 handler); /** @@ -2554,6 +2683,7 @@ default WebSocket.Definition ws(final Class * @param callback Route callback. * @return A route collection. */ + @Nonnull Route.Collection with(Runnable callback); /** @@ -2574,6 +2704,7 @@ default WebSocket.Definition ws(final Class * @param mapper Route mapper to append. * @return This instance. */ + @Nonnull Router map(final Mapper mapper); /** @@ -2610,6 +2741,7 @@ default WebSocket.Definition ws(final Class * @param err A route error handler. * @return This jooby instance. */ + @Nonnull Router err(Err.Handler err); /** @@ -2621,6 +2753,7 @@ default WebSocket.Definition ws(final Class * @param handler A route error handler. * @return This jooby instance. */ + @Nonnull default Router err(final Class type, final Err.Handler handler) { return err((req, rsp, x) -> { if (type.isInstance(x) || type.isInstance(x.getCause())) { @@ -2637,6 +2770,7 @@ default Router err(final Class type, final Err.Handler hand * @param handler A route error handler. * @return This jooby instance. */ + @Nonnull default Router err(final int statusCode, final Err.Handler handler) { return err((req, rsp, x) -> { if (statusCode == x.statusCode()) { @@ -2653,6 +2787,7 @@ default Router err(final int statusCode, final Err.Handler handler) { * @param handler A route error handler. * @return This jooby instance. */ + @Nonnull default Router err(final Status code, final Err.Handler handler) { return err((req, rsp, x) -> { if (code.value() == x.statusCode()) { @@ -2669,6 +2804,7 @@ default Router err(final Status code, final Err.Handler handler) { * @param handler A route error handler. * @return This jooby instance. */ + @Nonnull default Router err(final Predicate predicate, final Err.Handler handler) { return err((req, rsp, err) -> { if (predicate.test(Status.valueOf(err.statusCode()))) { @@ -2735,6 +2871,7 @@ default Router err(final Predicate predicate, final Err.Handler handler) * @return A new deferred handler. * @see Deferred */ + @Nonnull Route.OneArgHandler promise(Deferred.Initializer initializer); /** @@ -2768,6 +2905,7 @@ default Router err(final Predicate predicate, final Err.Handler handler) * @return A new deferred handler. * @see Deferred */ + @Nonnull Route.OneArgHandler promise(String executor, Deferred.Initializer initializer); /** @@ -2796,6 +2934,7 @@ default Router err(final Predicate predicate, final Err.Handler handler) * @return A new deferred handler. * @see Deferred */ + @Nonnull Route.OneArgHandler promise(Deferred.Initializer0 initializer); /** @@ -2819,6 +2958,7 @@ default Router err(final Predicate predicate, final Err.Handler handler) * @return A new deferred handler. * @see Deferred */ + @Nonnull Route.OneArgHandler promise(String executor, Deferred.Initializer0 initializer); /** @@ -2842,6 +2982,7 @@ default Router err(final Predicate predicate, final Err.Handler handler) * @param handler Application block. * @return A new deferred handler. */ + @Nonnull default Route.ZeroArgHandler deferred(final String executor, final Route.OneArgHandler handler) { return () -> Deferred.deferred(executor, handler); } @@ -2877,6 +3018,7 @@ default Route.ZeroArgHandler deferred(final String executor, final Route.OneArgH * @param handler Application block. * @return A new deferred handler. */ + @Nonnull default Route.ZeroArgHandler deferred(final Route.OneArgHandler handler) { return () -> Deferred.deferred(handler); } @@ -2902,6 +3044,7 @@ default Route.ZeroArgHandler deferred(final Route.OneArgHandler handler) { * @param handler Application block. * @return A new deferred handler. */ + @Nonnull default Route.ZeroArgHandler deferred(final String executor, final Route.ZeroArgHandler handler) { return () -> Deferred.deferred(executor, handler); } @@ -2937,6 +3080,7 @@ default Route.ZeroArgHandler deferred(final String executor, final Route.ZeroArg * @param handler Application block. * @return A new deferred handler. */ + @Nonnull default Route.ZeroArgHandler deferred(final Route.ZeroArgHandler handler) { return () -> Deferred.deferred(handler); } diff --git a/jooby/src/main/java/org/jooby/Session.java b/jooby/src/main/java/org/jooby/Session.java index 030df892af..3bd994c036 100644 --- a/jooby/src/main/java/org/jooby/Session.java +++ b/jooby/src/main/java/org/jooby/Session.java @@ -213,6 +213,8 @@ import com.google.common.io.BaseEncoding; +import javax.annotation.Nonnull; + /** *

* Sessions are created on demand via: {@link Request#session()}. @@ -525,6 +527,7 @@ interface Builder { * * @return Session ID. */ + @Nonnull String id(); /** @@ -574,11 +577,13 @@ interface Builder { * @param name Attribute's name. * @return Value as mutant. */ + @Nonnull Mutant get(final String name); /** * @return An immutable copy of local attributes. */ + @Nonnull Map attributes(); /** @@ -597,6 +602,7 @@ interface Builder { * @param value Attribute's value. * @return This session. */ + @Nonnull default Session set(final String name, final byte value) { return set(name, Byte.toString(value)); } @@ -609,6 +615,7 @@ default Session set(final String name, final byte value) { * @param value Attribute's value. * @return This session. */ + @Nonnull default Session set(final String name, final char value) { return set(name, Character.toString(value)); } @@ -621,6 +628,7 @@ default Session set(final String name, final char value) { * @param value Attribute's value. * @return This session. */ + @Nonnull default Session set(final String name, final boolean value) { return set(name, Boolean.toString(value)); } @@ -633,6 +641,7 @@ default Session set(final String name, final boolean value) { * @param value Attribute's value. * @return This session. */ + @Nonnull default Session set(final String name, final short value) { return set(name, Short.toString(value)); } @@ -645,6 +654,7 @@ default Session set(final String name, final short value) { * @param value Attribute's value. * @return This session. */ + @Nonnull default Session set(final String name, final int value) { return set(name, Integer.toString(value)); } @@ -657,6 +667,7 @@ default Session set(final String name, final int value) { * @param value Attribute's value. * @return This session. */ + @Nonnull default Session set(final String name, final long value) { return set(name, Long.toString(value)); } @@ -669,6 +680,7 @@ default Session set(final String name, final long value) { * @param value Attribute's value. * @return This session. */ + @Nonnull default Session set(final String name, final float value) { return set(name, Float.toString(value)); } @@ -681,6 +693,7 @@ default Session set(final String name, final float value) { * @param value Attribute's value. * @return This session. */ + @Nonnull default Session set(final String name, final double value) { return set(name, Double.toString(value)); } @@ -693,6 +706,7 @@ default Session set(final String name, final double value) { * @param value Attribute's value. * @return This session. */ + @Nonnull default Session set(final String name, final CharSequence value) { return set(name, value.toString()); } @@ -705,6 +719,7 @@ default Session set(final String name, final CharSequence value) { * @param value Attribute's value. * @return This session. */ + @Nonnull Session set(final String name, final String value); /** @@ -713,6 +728,7 @@ default Session set(final String name, final CharSequence value) { * @param name Attribute's name. * @return Existing value or empty optional. */ + @Nonnull Mutant unset(final String name); /** @@ -720,6 +736,7 @@ default Session set(final String name, final CharSequence value) { * * @return This session. */ + @Nonnull Session unset(); /** diff --git a/jooby/src/main/java/org/jooby/Sse.java b/jooby/src/main/java/org/jooby/Sse.java index a939ac80c9..783f502f17 100644 --- a/jooby/src/main/java/org/jooby/Sse.java +++ b/jooby/src/main/java/org/jooby/Sse.java @@ -216,6 +216,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import javax.annotation.Nonnull; import java.io.IOException; import java.nio.channels.ClosedChannelException; import java.nio.charset.StandardCharsets; @@ -737,6 +738,7 @@ protected void handshake(final Request req, final Runnable handler) throws Excep * * @return Sse unique ID (like a session ID). */ + @Nonnull public String id() { return id; } @@ -746,6 +748,7 @@ public String id() { * * @return Last event id. */ + @Nonnull public Optional lastEventId() { return lastEventId(String.class); } @@ -757,6 +760,7 @@ public Optional lastEventId() { * @param Event id type. * @return Last event id. */ + @Nonnull public Optional lastEventId(final Class type) { return lastEventId.toOptional(type); } @@ -768,6 +772,7 @@ public Optional lastEventId(final Class type) { * @param task Task to run. * @return This instance. */ + @Nonnull public Sse onClose(final Throwing.Runnable task) { onclose.set(task); return this; @@ -797,6 +802,7 @@ public Sse onClose(final Throwing.Runnable task) { * @param type Media type, like: json, xml. * @return A future. The success callback contains the {@link Event#id()}. */ + @Nonnull public CompletableFuture> send(final Object data, final String type) { return send(data, MediaType.valueOf(type)); } @@ -824,6 +830,7 @@ public CompletableFuture> send(final Object data, final String * @param type Media type, like: json, xml. * @return A future. The success callback contains the {@link Event#id()}. */ + @Nonnull public CompletableFuture> send(final Object data, final MediaType type) { return event(data).type(type).send(); } @@ -850,6 +857,7 @@ public CompletableFuture> send(final Object data, final MediaTy * @param data Event data. * @return A future. The success callback contains the {@link Event#id()}. */ + @Nonnull public CompletableFuture> send(final Object data) { return event(data).send(); } @@ -883,6 +891,7 @@ public CompletableFuture> send(final Object data) { * @param data Event data. * @return A new event. */ + @Nonnull public Event event(final Object data) { return new Event(this, data); } @@ -894,6 +903,7 @@ public Event event(final Object data) { * @param Service type. * @return A ready to use object. */ + @Nonnull public T require(final Class type) { return require(Key.get(type)); } @@ -906,6 +916,7 @@ public T require(final Class type) { * @param Service type. * @return A ready to use object. */ + @Nonnull public T require(final String name, final Class type) { return require(Key.get(type, Names.named(name))); } @@ -917,6 +928,7 @@ public T require(final String name, final Class type) { * @param Service type. * @return A ready to use object. */ + @Nonnull public T require(final TypeLiteral type) { return require(Key.get(type)); } @@ -928,6 +940,7 @@ public T require(final TypeLiteral type) { * @param Service type. * @return A ready to use object. */ + @Nonnull public T require(final Key key) { return injector.getInstance(key); } @@ -960,6 +973,7 @@ public T require(final Key key) { * @param unit Time unit. * @return This instance. */ + @Nonnull public Sse keepAlive(final int time, final TimeUnit unit) { return keepAlive(unit.toMillis(time)); } @@ -991,6 +1005,7 @@ public Sse keepAlive(final int time, final TimeUnit unit) { * @param millis Keep alive time in millis. * @return This instance. */ + @Nonnull public Sse keepAlive(final long millis) { scheduler.schedule(new KeepAlive(this, millis), millis, TimeUnit.MILLISECONDS); return this; diff --git a/jooby/src/main/java/org/jooby/Upload.java b/jooby/src/main/java/org/jooby/Upload.java index 7193493bcc..376d83fe2d 100644 --- a/jooby/src/main/java/org/jooby/Upload.java +++ b/jooby/src/main/java/org/jooby/Upload.java @@ -203,6 +203,7 @@ */ package org.jooby; +import javax.annotation.Nonnull; import java.io.Closeable; import java.io.File; import java.io.IOException; @@ -218,11 +219,13 @@ public interface Upload extends Closeable { /** * @return File's name. */ + @Nonnull String name(); /** * @return File media type. */ + @Nonnull MediaType type(); /** @@ -231,6 +234,7 @@ public interface Upload extends Closeable { * @param name Header's name. * @return A header value. */ + @Nonnull Mutant header(String name); /** @@ -239,6 +243,7 @@ public interface Upload extends Closeable { * @return A temp file. * @throws IOException If file doesn't exist. */ + @Nonnull File file() throws IOException; } diff --git a/jooby/src/main/java/org/jooby/View.java b/jooby/src/main/java/org/jooby/View.java index 0450bfdcb8..7bfa181dc8 100644 --- a/jooby/src/main/java/org/jooby/View.java +++ b/jooby/src/main/java/org/jooby/View.java @@ -205,6 +205,7 @@ import static java.util.Objects.requireNonNull; +import javax.annotation.Nonnull; import java.io.FileNotFoundException; import java.util.HashMap; import java.util.Map; @@ -273,6 +274,7 @@ protected View(final String name) { /** * @return View's name. */ + @Nonnull public String name() { return name; } @@ -284,6 +286,7 @@ public String name() { * @param value Attribute's value. * @return This view. */ + @Nonnull public View put(final String name, final Object value) { requireNonNull(name, "Model name is required."); model.put(name, value); @@ -296,6 +299,7 @@ public View put(final String name, final Object value) { * @param values Attribute's value. * @return This view. */ + @Nonnull public View put(final Map values) { values.forEach((k, v) -> model.put(k, v)); return this; @@ -304,11 +308,14 @@ public View put(final Map values) { /** * @return View's model. */ + + @Nonnull public Map model() { return model; } @Override + @Nonnull public Result set(final Object content) { throw new UnsupportedOperationException("Not allowed in views, use one of the put methods."); } diff --git a/jooby/src/main/java/org/jooby/WebSocket.java b/jooby/src/main/java/org/jooby/WebSocket.java index 18091f48b0..4da880ed57 100644 --- a/jooby/src/main/java/org/jooby/WebSocket.java +++ b/jooby/src/main/java/org/jooby/WebSocket.java @@ -219,6 +219,8 @@ import com.google.inject.Key; import com.google.inject.TypeLiteral; +import javax.annotation.Nonnull; + /** *

WebSockets

*

@@ -766,26 +768,31 @@ interface Handler extends OnClose, OnMessage, OnError, OnOpen { /** * @return Current request path. */ + @Nonnull String path(); /** * @return The currently matched pattern. */ + @Nonnull String pattern(); /** * @return The currently matched path variables (if any). */ + @Nonnull Map vars(); /** * @return The type this route can consumes, defaults is: {@code * / *}. */ + @Nonnull MediaType consumes(); /** * @return The type this route can produces, defaults is: {@code * / *}. */ + @Nonnull MediaType produces(); /** @@ -968,7 +975,5 @@ default void broadcast(final Object data, final OnError err) throws Exception { * @param err An err callback. * @throws Exception If something goes wrong. */ - void broadcast(Object data, SuccessCallback success, OnError err) - throws Exception; - + void broadcast(Object data, SuccessCallback success, OnError err) throws Exception; } diff --git a/jooby/src/main/java/org/jooby/package-info.java b/jooby/src/main/java/org/jooby/package-info.java new file mode 100644 index 0000000000..3b3b847d37 --- /dev/null +++ b/jooby/src/main/java/org/jooby/package-info.java @@ -0,0 +1,8 @@ +/** + *

do more, more easily

+ *

+ * Jooby a scalable, fast and modular micro web framework for Java and Kotlin. + *

+ */ +@javax.annotation.ParametersAreNonnullByDefault +package org.jooby; diff --git a/pom.xml b/pom.xml index bbe26576a9..d5220e14eb 100644 --- a/pom.xml +++ b/pom.xml @@ -1474,6 +1474,13 @@ ${maven-antrun-plugin.version} + + + com.google.code.findbugs + jsr305 + ${jsr305.version} + + cz.jiripinkas @@ -3007,7 +3014,7 @@ org.eclipse.jdt.apt.processorOptions/defaultOverwrite=true 2.6.1 5.2.1.Final 4.3.9.Final - 3.0.0 + 3.0.2 4.5.2 3.0.1 1.9.36