1 | package com.reallifedeveloper.maven.jdepend.xml; | |
2 | ||
3 | import java.util.ArrayList; | |
4 | import java.util.List; | |
5 | import java.util.Optional; | |
6 | ||
7 | import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; | |
8 | import jakarta.xml.bind.annotation.XmlAccessType; | |
9 | import jakarta.xml.bind.annotation.XmlAccessorType; | |
10 | import jakarta.xml.bind.annotation.XmlAttribute; | |
11 | import jakarta.xml.bind.annotation.XmlElement; | |
12 | import jakarta.xml.bind.annotation.XmlElementWrapper; | |
13 | import jakarta.xml.bind.annotation.XmlRootElement; | |
14 | import jakarta.xml.bind.annotation.XmlValue; | |
15 | import lombok.Data; | |
16 | import lombok.experimental.Accessors; | |
17 | ||
18 | /** | |
19 | * A representation of the XML report generated by JDepend. | |
20 | * | |
21 | * @author RealLifeDeveloper | |
22 | */ | |
23 | @XmlRootElement(name = "JDepend") | |
24 | @XmlAccessorType(XmlAccessType.FIELD) | |
25 | @Data | |
26 | @Accessors(fluent = true) | |
27 | @SuppressWarnings("PMD.AvoidDuplicateLiterals") | |
28 | @SuppressFBWarnings(value = "EI_EXPOSE_REP", justification = "The classes here are mutable for convenience; we can simply use lombok.Data") | |
29 | public class XmlReport { | |
30 | ||
31 | @XmlElementWrapper(name = "Packages") | |
32 | @XmlElement(name = "Package") | |
33 | private List<XmlPackage> packages = new ArrayList<>(); | |
34 | ||
35 | @XmlElementWrapper(name = "Cycles") | |
36 | @XmlElement(name = "Package") | |
37 | private List<XmlPackageWithCycle> cycles = new ArrayList<>(); | |
38 | ||
39 | /** | |
40 | * Gives the packages that were successfully analyzed by JDepend. | |
41 | * <p> | |
42 | * The XML report generataed by JDepend includes external packages, e.g., {@code java.lang}, but with an error message saying something | |
43 | * like {@code package referenced, but not analyzed}. | |
44 | * | |
45 | * @return the packages that were successfully analyzed by JDepend | |
46 | */ | |
47 | public List<XmlPackage> packagesWithoutError() { | |
48 |
3
1. lambda$packagesWithoutError$0 : negated conditional → KILLED 2. lambda$packagesWithoutError$0 : replaced boolean return with true for com/reallifedeveloper/maven/jdepend/xml/XmlReport::lambda$packagesWithoutError$0 → KILLED 3. packagesWithoutError : replaced return value with Collections.emptyList for com/reallifedeveloper/maven/jdepend/xml/XmlReport::packagesWithoutError → KILLED |
return packages().stream().filter(p -> p.error() == null).toList(); |
49 | } | |
50 | ||
51 | /** | |
52 | * Gives the packages that were included in the JDepend report, but not successfully analyzed. | |
53 | * | |
54 | * @return the packages that were included in the JDepend report, but not successfully analyzed | |
55 | */ | |
56 | public List<XmlPackage> packagesWithError() { | |
57 |
3
1. lambda$packagesWithError$1 : negated conditional → KILLED 2. packagesWithError : replaced return value with Collections.emptyList for com/reallifedeveloper/maven/jdepend/xml/XmlReport::packagesWithError → KILLED 3. lambda$packagesWithError$1 : replaced boolean return with true for com/reallifedeveloper/maven/jdepend/xml/XmlReport::lambda$packagesWithError$1 → KILLED |
return packages().stream().filter(p -> p.error() != null).toList(); |
58 | } | |
59 | ||
60 | /** | |
61 | * If the given package has any cycles, provides information about this. | |
62 | * | |
63 | * @param packageName the name of the package to check | |
64 | * | |
65 | * @return an optional containing an {@link XmlPackageWithCycle} if the package named {@code packageName} contains cycles, an empty | |
66 | * optional otherwise | |
67 | */ | |
68 | public Optional<XmlPackageWithCycle> findPackageWithCycle(String packageName) { | |
69 |
3
1. lambda$findPackageWithCycle$2 : replaced boolean return with false for com/reallifedeveloper/maven/jdepend/xml/XmlReport::lambda$findPackageWithCycle$2 → KILLED 2. findPackageWithCycle : replaced return value with Optional.empty for com/reallifedeveloper/maven/jdepend/xml/XmlReport::findPackageWithCycle → KILLED 3. lambda$findPackageWithCycle$2 : replaced boolean return with true for com/reallifedeveloper/maven/jdepend/xml/XmlReport::lambda$findPackageWithCycle$2 → KILLED |
return cycles().stream().filter(c -> packageName.equals(c.name())).findFirst(); |
70 | } | |
71 | ||
72 | /** | |
73 | * Contains information from the {@code Package} element. | |
74 | */ | |
75 | @Data | |
76 | public static class XmlPackage { | |
77 | @XmlAttribute(name = "name") | |
78 | private String name; | |
79 | ||
80 | @XmlElement(name = "Stats") | |
81 | private XmlStats stats; | |
82 | ||
83 | @XmlElementWrapper(name = "AbstractClasses") | |
84 | @XmlElement(name = "Class") | |
85 | private List<XmlClass> abstractClasses = new ArrayList<>(); | |
86 | ||
87 | @XmlElementWrapper(name = "ConcreteClasses") | |
88 | @XmlElement(name = "Class") | |
89 | private List<XmlClass> concreteClasses = new ArrayList<>(); | |
90 | ||
91 | @XmlElementWrapper(name = "DependsUpon") | |
92 | @XmlElement(name = "Package") | |
93 | private List<String> dependsUpon = new ArrayList<>(); | |
94 | ||
95 | @XmlElementWrapper(name = "UsedBy") | |
96 | @XmlElement(name = "Package") | |
97 | private List<String> usedBy = new ArrayList<>(); | |
98 | ||
99 | @XmlElement(name = "error") | |
100 | private String error; | |
101 | } | |
102 | ||
103 | /** | |
104 | * Contains information from the {@code Stats} element. | |
105 | */ | |
106 | @Data | |
107 | public static class XmlStats { | |
108 | @XmlElement(name = "TotalClasses") | |
109 | private int totalClasses; | |
110 | ||
111 | @XmlElement(name = "ConcreteClasses") | |
112 | private int concreteClasses; | |
113 | ||
114 | @XmlElement(name = "AbstractClasses") | |
115 | private int abstractClasses; | |
116 | ||
117 | @XmlElement(name = "HasPackageInfo") | |
118 | private boolean hasPackageInfo; | |
119 | ||
120 | @XmlElement(name = "Ca") | |
121 | private int afferentCouplings; | |
122 | ||
123 | @XmlElement(name = "Ce") | |
124 | private int efferentCouplings; | |
125 | ||
126 | @XmlElement(name = "A") | |
127 | private double abstractness; | |
128 | ||
129 | @XmlElement(name = "I") | |
130 | private double instability; | |
131 | ||
132 | @XmlElement(name = "D") | |
133 | private double distance; | |
134 | ||
135 | @XmlElement(name = "V") | |
136 | private int volatility; | |
137 | } | |
138 | ||
139 | /** | |
140 | * Contains information from the {@code Class} element. | |
141 | */ | |
142 | @Data | |
143 | public static class XmlClass { | |
144 | @XmlAttribute(name = "sourceFile") | |
145 | private String sourceFile; | |
146 | ||
147 | @XmlValue | |
148 | private String name; | |
149 | } | |
150 | ||
151 | /** | |
152 | * Contains information from the {@code Cycles} element. | |
153 | */ | |
154 | @Data | |
155 | public static class XmlPackageWithCycle { | |
156 | @XmlAttribute(name = "Name") | |
157 | private String name; | |
158 | ||
159 | @XmlElement(name = "Package") | |
160 | private List<String> packagesInCycle = new ArrayList<>(); | |
161 | } | |
162 | } | |
Mutations | ||
48 |
1.1 2.2 3.3 |
|
57 |
1.1 2.2 3.3 |
|
69 |
1.1 2.2 3.3 |