forked from jooby-project/jooby
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUsage.java
More file actions
64 lines (57 loc) · 2.08 KB
/
Usage.java
File metadata and controls
64 lines (57 loc) · 2.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/**
* Jooby https://jooby.io
* Apache License Version 2.0 https://jooby.io/LICENSE.txt
* Copyright 2014 Edgar Espina
*/
package io.jooby;
import io.jooby.exception.ProvisioningException;
import javax.annotation.Nonnull;
import java.lang.reflect.Executable;
import java.lang.reflect.Parameter;
import java.util.stream.Collectors;
import java.util.stream.Stream;
/**
* Usage exceptions. They provide a descriptive message with a link for a detailed section.
*
* @since 2.1.0
*/
public class Usage extends RuntimeException {
/**
* Creates a new Usage exception.
*
* @param message Message.
* @param id Link to detailed section.
*/
public Usage(@Nonnull String message, @Nonnull String id) {
super((message + "\nFor more details, please visit: " + System
.getProperty("jooby.host", "https://jooby.io") + "/usage#" + id));
}
/**
* Creates a mvc route missing exception.
*
* @param mvcRoute Mvc route.
* @return Usage exception.
*/
public static @Nonnull Usage mvcRouterNotFound(@Nonnull Class mvcRoute) {
return apt("Router not found: `" + mvcRoute.getName()
+ "`. Make sure Jooby annotation processor is configured properly.", "router-not-found");
}
/**
* Thrown when the reflective bean converter has no access to a parameter name. Compilation
* must be done using <code>parameters</code> compiler option.
*
* @param parameter Parameter.
* @return Usage exception.
*/
public static @Nonnull Usage parameterNameNotPresent(@Nonnull Parameter parameter) {
Executable executable = parameter.getDeclaringExecutable();
int p = Stream.of(executable.getParameters()).collect(Collectors.toList()).indexOf(parameter);
String message = "Unable to provision parameter at position: '" + p + "', require by: "
+ ProvisioningException.toString(parameter.getDeclaringExecutable())
+ ". Parameter's name is missing";
return new Usage(message, "bean-converter-parameter-name-missing");
}
private static Usage apt(String message, String id) {
return new Usage(message, "annotation-processing-tool-" + id);
}
}