-
-
Notifications
You must be signed in to change notification settings - Fork 201
Expand file tree
/
Copy pathUsage.java
More file actions
73 lines (66 loc) · 2.16 KB
/
Copy pathUsage.java
File metadata and controls
73 lines (66 loc) · 2.16 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
65
66
67
68
69
70
71
72
73
/*
* Jooby https://jooby.io
* Apache License Version 2.0 https://jooby.io/LICENSE.txt
* Copyright 2014 Edgar Espina
*/
package io.jooby;
import java.lang.reflect.Executable;
import java.lang.reflect.Parameter;
import java.util.stream.Stream;
import edu.umd.cs.findbugs.annotations.NonNull;
import io.jooby.exception.ProvisioningException;
/**
* 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()).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);
}
}