| 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 | @SuppressWarnings("NullAway") | |
| 77 | public static class XmlPackage { | |
| 78 | @XmlAttribute(name = "name") | |
| 79 | private String name; | |
| 80 | ||
| 81 | @XmlElement(name = "Stats") | |
| 82 | private XmlStats stats; | |
| 83 | ||
| 84 | @XmlElementWrapper(name = "AbstractClasses") | |
| 85 | @XmlElement(name = "Class") | |
| 86 | private List<XmlClass> abstractClasses = new ArrayList<>(); | |
| 87 | ||
| 88 | @XmlElementWrapper(name = "ConcreteClasses") | |
| 89 | @XmlElement(name = "Class") | |
| 90 | private List<XmlClass> concreteClasses = new ArrayList<>(); | |
| 91 | ||
| 92 | @XmlElementWrapper(name = "DependsUpon") | |
| 93 | @XmlElement(name = "Package") | |
| 94 | private List<String> dependsUpon = new ArrayList<>(); | |
| 95 | ||
| 96 | @XmlElementWrapper(name = "UsedBy") | |
| 97 | @XmlElement(name = "Package") | |
| 98 | private List<String> usedBy = new ArrayList<>(); | |
| 99 | ||
| 100 | @XmlElement(name = "error") | |
| 101 | private String error; | |
| 102 | } | |
| 103 | ||
| 104 | /** | |
| 105 | * Contains information from the {@code Stats} element. | |
| 106 | */ | |
| 107 | @Data | |
| 108 | public static class XmlStats { | |
| 109 | @XmlElement(name = "TotalClasses") | |
| 110 | private int totalClasses; | |
| 111 | ||
| 112 | @XmlElement(name = "ConcreteClasses") | |
| 113 | private int concreteClasses; | |
| 114 | ||
| 115 | @XmlElement(name = "AbstractClasses") | |
| 116 | private int abstractClasses; | |
| 117 | ||
| 118 | @XmlElement(name = "HasPackageInfo") | |
| 119 | private boolean hasPackageInfo; | |
| 120 | ||
| 121 | @XmlElement(name = "Ca") | |
| 122 | private int afferentCouplings; | |
| 123 | ||
| 124 | @XmlElement(name = "Ce") | |
| 125 | private int efferentCouplings; | |
| 126 | ||
| 127 | @XmlElement(name = "A") | |
| 128 | private double abstractness; | |
| 129 | ||
| 130 | @XmlElement(name = "I") | |
| 131 | private double instability; | |
| 132 | ||
| 133 | @XmlElement(name = "D") | |
| 134 | private double distance; | |
| 135 | ||
| 136 | @XmlElement(name = "V") | |
| 137 | private int volatility; | |
| 138 | } | |
| 139 | ||
| 140 | /** | |
| 141 | * Contains information from the {@code Class} element. | |
| 142 | */ | |
| 143 | @Data | |
| 144 | @SuppressWarnings("NullAway") | |
| 145 | public static class XmlClass { | |
| 146 | @XmlAttribute(name = "sourceFile") | |
| 147 | private String sourceFile; | |
| 148 | ||
| 149 | @XmlValue | |
| 150 | private String name; | |
| 151 | } | |
| 152 | ||
| 153 | /** | |
| 154 | * Contains information from the {@code Cycles} element. | |
| 155 | */ | |
| 156 | @Data | |
| 157 | @SuppressWarnings("NullAway") | |
| 158 | public static class XmlPackageWithCycle { | |
| 159 | @XmlAttribute(name = "Name") | |
| 160 | private String name; | |
| 161 | ||
| 162 | @XmlElement(name = "Package") | |
| 163 | private List<String> packagesInCycle = new ArrayList<>(); | |
| 164 | } | |
| 165 | } | |
Mutations | ||
| 48 |
1.1 2.2 3.3 |
|
| 57 |
1.1 2.2 3.3 |
|
| 69 |
1.1 2.2 3.3 |