1 | package fr.sii.ogham.core.builder.priority; | |
2 | ||
3 | import static java.util.Arrays.asList; | |
4 | ||
5 | import fr.sii.ogham.core.builder.context.BuildContext; | |
6 | ||
7 | /** | |
8 | * Provide the priority of an implementation based on {@link Priority} | |
9 | * annotation that is present on the class (if any). | |
10 | * | |
11 | * <p> | |
12 | * If no annotation or no priority is configured, then a default priority is | |
13 | * provided (delegating to another {@link PriorityProvider} implementation). | |
14 | * | |
15 | * @author Aurélien Baudet | |
16 | * | |
17 | */ | |
18 | public class AnnotationPriorityProvider implements PriorityProvider<Class<?>> { | |
19 | private final BuildContext buildContext; | |
20 | private final PriorityProvider<Class<?>> defaultProvider; | |
21 | ||
22 | /** | |
23 | * Initializes with the build context and a default provider if the priority | |
24 | * is not provided through the annotation. | |
25 | * | |
26 | * @param buildContext | |
27 | * for property evaluation | |
28 | * @param defaultProvider | |
29 | * in case that there is no priority provided using the | |
30 | * annotation | |
31 | */ | |
32 | public AnnotationPriorityProvider(BuildContext buildContext, PriorityProvider<Class<?>> defaultProvider) { | |
33 | super(); | |
34 | this.buildContext = buildContext; | |
35 | this.defaultProvider = defaultProvider; | |
36 | } | |
37 | ||
38 | @Override | |
39 | public int provide(Class<?> source) { | |
40 | Priority priority = source.getAnnotation(Priority.class); | |
41 |
5
1. provide : negated conditional → SURVIVED 2. provide : negated conditional → NO_COVERAGE 3. provide : negated conditional → KILLED 4. provide : negated conditional → KILLED 5. provide : negated conditional → KILLED |
if (priority == null) { |
42 |
2
1. provide : replaced int return with 0 for fr/sii/ogham/core/builder/priority/AnnotationPriorityProvider::provide → SURVIVED 2. provide : replaced int return with 0 for fr/sii/ogham/core/builder/priority/AnnotationPriorityProvider::provide → NO_COVERAGE |
return defaultProvider.provide(source); |
43 | } | |
44 | int value = computePriority(priority.properties(), priority.defaultValue()); | |
45 |
5
1. provide : changed conditional boundary → SURVIVED 2. provide : changed conditional boundary → NO_COVERAGE 3. provide : negated conditional → NO_COVERAGE 4. provide : negated conditional → SURVIVED 5. provide : negated conditional → KILLED |
if (value > 0) { |
46 |
3
1. provide : replaced int return with 0 for fr/sii/ogham/core/builder/priority/AnnotationPriorityProvider::provide → SURVIVED 2. provide : replaced int return with 0 for fr/sii/ogham/core/builder/priority/AnnotationPriorityProvider::provide → NO_COVERAGE 3. provide : replaced int return with 0 for fr/sii/ogham/core/builder/priority/AnnotationPriorityProvider::provide → KILLED |
return value; |
47 | } | |
48 |
1
1. provide : replaced int return with 0 for fr/sii/ogham/core/builder/priority/AnnotationPriorityProvider::provide → NO_COVERAGE |
return defaultProvider.provide(source); |
49 | } | |
50 | ||
51 | private int computePriority(String[] properties, int defaultValue) { | |
52 | Integer value = buildContext.evaluate(asList(properties), Integer.class); | |
53 |
10
1. computePriority : changed conditional boundary → NO_COVERAGE 2. computePriority : negated conditional → NO_COVERAGE 3. computePriority : negated conditional → NO_COVERAGE 4. computePriority : negated conditional → KILLED 5. computePriority : negated conditional → KILLED 6. computePriority : negated conditional → KILLED 7. computePriority : negated conditional → KILLED 8. computePriority : negated conditional → KILLED 9. computePriority : negated conditional → KILLED 10. computePriority : negated conditional → KILLED |
if (value != null && value > 0) { |
54 |
1
1. computePriority : replaced int return with 0 for fr/sii/ogham/core/builder/priority/AnnotationPriorityProvider::computePriority → NO_COVERAGE |
return value; |
55 | } | |
56 |
3
1. computePriority : replaced int return with 0 for fr/sii/ogham/core/builder/priority/AnnotationPriorityProvider::computePriority → NO_COVERAGE 2. computePriority : replaced int return with 0 for fr/sii/ogham/core/builder/priority/AnnotationPriorityProvider::computePriority → SURVIVED 3. computePriority : replaced int return with 0 for fr/sii/ogham/core/builder/priority/AnnotationPriorityProvider::computePriority → KILLED |
return defaultValue; |
57 | } | |
58 | ||
59 | } | |
Mutations | ||
41 |
1.1 2.2 3.3 4.4 5.5 |
|
42 |
1.1 2.2 |
|
45 |
1.1 2.2 3.3 4.4 5.5 |
|
46 |
1.1 2.2 3.3 |
|
48 |
1.1 |
|
53 |
1.1 2.2 3.3 4.4 5.5 6.6 7.7 8.8 9.9 10.10 |
|
54 |
1.1 |
|
56 |
1.1 2.2 3.3 |