前言

在Java面向对象课程的学习过程中,我们需要使用度量工具来分析自己程序的代码结构。受OO课程组以及前辈们博客提醒,笔者找到了DesigniteJava这款软件,现对此软件进行简单的说明。

一、DesigniteJava的下载与使用

Designite是一款程序设计的质量评估工具。这款工具可以用于分析Java的代码,并且识别其中存在的质量问题。Designite会检测程序的架构(architecture),设计(design)和代码异味(code smell)并且给出详细的度量分析(metrics analysis)。

Designite for Java:http://www.designite-tools.com/DesigniteJava/

最近刚和IDEA互动:https://plugins.jetbrains.com/plugin/13380-designitejava/versions

进入官网Designite for Java,下载会得到一个jar包,默认名为DesigniteJava.jar。将其放在方便使用的位置,打开命令行窗口,输入以下代码即可运行:

java -jar DesigniteJava.jar -i <源码路径> -o <分析数据输出路径>

image

输出之后,会得到以下文件。

image

二、度量指标介绍

以下截取自这里

许多翻译十分抽象,笔者没有找到好的解释,欢迎作注。

  • Detects 20 design smells 能检测20种设计异味命令抽象

    • Duplicate Abstraction:

      重复抽象,This smell arises when two or more abstractions have identical names or identical implementation or both.

    • Feature Envy:

      This smell occurs when a method seems more interested in an abstraction other than the one it actually is in.

    • Imperative Abstraction

      命令抽象,This smell arises when an operation is turned into a class.

    • Multifaceted Abstraction

      多方面抽象,This smell arises when an abstraction has more than one responsibility assigned to it.

    • Unnecessary Abstraction

      不必要的抽象,This smell occurs when an abstraction that is actually not needed (and thus could have been avoided) gets introduced in a software design.

    • Unutilized Abstraction

      未使用的抽象,This smell arises when an abstraction is left unused (either not directly used or not reachable).

    • Deficient Encapsulation

      封装不足,This smell occurs when the declared accessibility of one or more members of an abstraction is more permissive than actually required.

    • Unexploited Encapsulation

      未开发封装,This smell arises when client code uses explicit type checks (using chained if-else or switch statements that check for the type of the object) instead of exploiting the variation in types already encapsulated within a hierarchy.

    • Broken Modularization

      模块化中断,This smell arises when data and/or methods that ideally should have been localized into a single abstraction are separated and spread across multiple abstractions.

    • Cyclic-Dependent Modularization

      循环相关模块化, This smell arises when two or more abstractions depend on each other directly or indirectly (creating a tight coupling between the abstractions).

    • Insufficient Modularization

      模块化不足 ,This smell arises when an abstraction exists that has not been completely decomposed, and a further decomposition could reduce its size, implementation complexity, or both.

    • Hub-like Modularization

      轮毂式模块化,This smell arises when an abstraction has dependencies (both incoming and outgoing) with a large number of other abstractions.

    • Broken Hierarchy

      断裂的层次结构,This smell arises when a supertype and its subtype conceptually do not share an “IS-A” relationship resulting in broken substitutability.

    • Cyclic Hierarchy

      循环层次结构,This smell arises when a supertype in a hierarchy depends on any of its subtypes.

    • Deep Hierarchy

      层次过深,This smell arises when an inheritance hierarchy is “excessively” deep.

    • Missing Hierarchy

      缺少层次结构,This smell arises when a code segment uses conditional logic (typically in conjunction with “tagged types”) to explicitly manage variation in behavior where a hierarchy could have been created and used to encapsulate those variations.

    • Multipath Hierarchy

      多路径层次结构,This smell arises when a subtype inherits both directly as well as indirectly from a supertype leading to unnecessary inheritance paths in the hierarchy.

    • Rebellious Hierarchy

      叛逆性层次结构,This smell arises when a subtype rejects the methods provided by its supertype(s).

    • Wide Hierarchy

      层次过宽,This smell arises when an inheritance hierarchy is “too” wide indicating that intermediate types may be missing.

    • Unfactored Hierarchy:

      This smell arises when there is unnecessary duplication among types in a hierarchy.

  • Detects 10 implementation smells 检测10种实现异味

    • Abstract Function Call From Constructor

      构造函数调用抽象函数

    • Complex Conditional

      复杂条件

    • Complex Method

      复杂的方法

    • Empty catch clause

      空catch子句

    • Long Identifier

      长标识符

    • Long Method

      长方法

    • Long Parameter List

      长参数列表

    • Long Statement

      长语句

    • Magic Number

      魔法数字,在编程领域指的是莫名其妙出现的数字。数字的意义必须通过详细阅读才能推断出来。

      一般魔法数字都是需要使用枚举变量来替换的。

    • Missing default

      缺少默认值

  • Computes following object-oriented metrics 能计算以下面向对象的度量

    • LOC (Lines Of Code - at method and class granularity)

      代码行数

    • CC (Cyclomatic Complexity - Method)

      圈复杂度,用于衡量一个模块判定结构的复杂程度,圈复杂度越大说明程序代码质量低,且难以测试和维护。

    • PC (Parameter Count - Method)

      方法中传入的参数个数。

    • NOF (Number of Fields - Class)

      类的字段个数。

    • NOPF (Number of Public Fields - Class)

      类的公共字段个数。

    • NOM (Number of Methods - Class)

      类的方法个数。

    • NOPM (Number of Public Methods - Class)

      类的公共方法个数。

    • WMC (Weighted Methods per Class - Class)

      类的加权方法个数。

    • NC (Number of Children - Class)

      类的子类个数。

    • DIT (Depth of Inheritance Tree - Class)

      类的继承树深度。

    • LCOM (Lack of Cohesion in Methods - Class)

      方法的内聚缺乏度。

    • FANIN (Fan-in - Class)

      类调用的上级模块的个数。

    • FANOUT (Fan-out - Class)

      类直接调用的下级模块的个数。

    稍微解释一下最后三个值:

    • 秉承着高内聚低耦合的思想,LCOM的值越小越好,FANIN和FANOUT与复用性和复杂度有关,视情况判断好坏

    • FANIN和FANOUT

      • (A)FANIN(扇入)

        扇入表示一个模块被多个模块调用。

        image

      • (B)扇出

        扇出表示一个模块调用多个模块。

        image

Java代码度量分析工具:DesigniteJava简介的更多相关文章

  1. Java代码度量分析工具:Designite简介

    前言 在Java面向对象课程的学习过程中,我们需要使用度量工具来分析自己程序的代码结构.此类的度量工具有许多,或以插件形式存在于各个IDE中,或以.jar包的形式供用户使用.在这里,笔者向大家简单的介 ...

  2. Java代码混淆工具ProGuard

    目录 Java代码混淆工具ProGuard 简介 描述 作用的环境 功能 工作原理 下载 使用时注意事项 版本问题 JDK位数问题 Java的字节码验证问题 关于使用类似于Hibernate的对象关系 ...

  3. eclipse Java代码折叠工具

      eclipse Java代码折叠工具 CreateTime--2018年5月17日15点09分 Author:Marydon 1.问题描述 eclipse自带的代码折叠工具,无法折叠try{}ca ...

  4. Findbug插件静态java代码扫描工具使用

    本文转自http://blog.csdn.net/gaofuqi/article/details/22679609 感谢作者 FindBugs 是由马里兰大学提供的一款开源 Java静态代码分析工具. ...

  5. 把调试好的SQL语句转换为JAVA代码小工具

    关键点:Pattern实现SQL拆解.ZeroClipboard.js实现复制到剪切板 主要代码: <%@ page language="java" import=" ...

  6. GitLab - 代码仓库管理工具GitLab简介

    1 - GitLab 基于git的开源的仓库管理系统项目,使用git作为代码管理工具,并在此基础上搭建web服务,拥有与Github类似的功能. 社区版(Community Edition,CE) 企 ...

  7. Gerrit - 代码评审工具Gerrit简介与安装

    1 - 前言 Code Review 代码评审是指在软件开发过程中,对源代码的系统性检查,改进代码质量,查找系统缺陷,保证软件总体质量和提高开发者自身水平. 简单的说,Code Review是用来确认 ...

  8. java 代码分析工具——JDepend

    最近学习Mybatis的官方文档,看到了[项目文档]一节有很多内容没有见过,做个笔记,理解一下. 百科上的介绍,我竟然都看懂了,那就不找其他地方的资料了. JDepend 一个开放源代码的可以用来评价 ...

  9. [改善Java代码]让工具类不可实例化

    建议42: 让工具类不可实例化 Java项目中使用的工具类非常多,比如JDK自己的工具类java.lang.Math.java.util.Collections等都是我们经常用到的.工具类的方法和属性 ...

随机推荐

  1. NGK DeFi Baccarat或将推动BGV成为下一个千倍币!

    目前,已经接近2020年年末,但是DeFi的热潮还在持续.近日,DeFi市场传出一道重磅利好消息,便是NGK DeFi去中心化交易系统Baccarat即将上线.届时,将会引起整个区块链市场的又一次震动 ...

  2. HTTPS原理解析

    HTTPS 一些概念 http 概述 HTTP是一个客户端(用户)和服务端(网站)之间请求和应答的标准,通常使用TCP协议.其本身位于TCP/IP协议族的应用层. 特点 - 客户端&服务器 - ...

  3. 聊聊ASP.NET Core中的配置

    ​作为软件开发人员,我们当然喜欢一些可配置选项,尤其是当它允许我们改变应用程序的行为而无需修改或编译我们的应用程序时.无论你是使用新的还是旧的.NET时,可能希望利用json文件的配置.在这篇文章中, ...

  4. spring boot的 yml和properties的对比

    Spring Boot 虽然做了大量的工作来简化配置,但其配置依然是相当的复杂!支持的外部配置方式就有很多种,笔者没有去统计,也许是为了灵活使用吧.   application.yml 和 appli ...

  5. MySQL注入时常用函数

    注入常用函数 数据库相关 database() --- 返回当前数据库名 @@datadir --- 读取数据库路径 @@basedir --- 读取数据库安全路径 @@version_compile ...

  6. (三)String、StringBuilder、StringBuffer在字符串操作中的性能差异浅析

    参考资料:https://www.iteye.com/blog/hank4ever-581463 <Core Java Volume I-Fundamentals>原书第十版 <Ja ...

  7. MySQL深入研究--学习总结(2)

    前言 接上文,继续学习后续章节. 第四章&第五章<深入浅出索引> 这两章节主要介绍的索引结构及其如何合理建立索引,但是我觉得讲的比较简单. 总结回顾下吧,其实在我之前的文章< ...

  8. CVE-2016-5734-phpmyadmin-4.0.x-4.6.2-代码执行

    参考 https://www.jianshu.com/p/8e44cb1b5b5b 漏洞原因 phpMyAdmin是一套开源的.基于Web的MySQL数据库管理工具.在其查找并替换字符串功能中,将用户 ...

  9. CVE-2018-2628-WLS Core Components 反序列化

    漏洞参考 https://blog.csdn.net/csacs/article/details/87122472 漏洞概述:在 WebLogic 里,攻击者利用其他rmi绕过weblogic黑名单限 ...

  10. HTB系列之七:Bastard

    出品|MS08067实验室(www.ms08067.com) 这次挑战的是 HTB 的第7台靶机:Bastard 技能收获: PHP Unserilaize CMS Version Identify ...