<dependency> <groupId>org.jmetrix</groupId> <artifactId>jmetrix</artifactId> <version>1.2.0</version> </dependency> import org.jmetrix.api.Analyzer; import org.jmetrix.api.metric.MetricType; import org.jmetrix.api.method.Method; import org.jmetrix.api.method.Metric; import org.jmetrix.api.metric.MetricCollector; import org.jmetrix.api.model.Location; import org.jmetrix.api.model.Model; import org.jmetrix.api.model.Type; import java.io.File; import java.io.IOException; public class CodeQualityAnalyzer { public static void main(String[] args) throws IOException { Analyzer analyzer = new Analyzer(); analyzer.addMetric(MetricType.CYCLO); analyzer.addMetric(MetricType.NCSS); File library = new File("path/to/library.jar"); analyzer.addModel(library); analyzer.analyze(); Model model = analyzer.getModel(library); for (Type type : model.getTypes()) { for (Method method : type.getMethods()) { for (Metric metric : method.getMetrics()) { System.out.println("Method: " + method.getName()); System.out.println("Metric Name: " + metric.getName()); System.out.println("Metric Value: " + metric.getValue()); System.out.println("Location: " + metric.getLocation()); } } } } }


上一篇:
下一篇:
切换中文