private String getBalance(JavaClass unit) { StringBuilder info = new StringBuilder(); info.append("内聚性指数("); info.append(MetricsFormat.toFormattedMetrics(unit.balance())); info.append(")=内聚值("); info.append(MetricsFormat.toFormattedMetrics(unit.cohesion())); info.append(")/内聚值("); info.append(MetricsFormat.toFormattedMetrics(unit.cohesion())); info.append(")+分组耦合最大顺序差值("); info.append(MetricsFormat.toFormattedMetrics(unit.getGroupCouplingInfo().getMaxDifference())); info.append(");\n"); info.append("分组耦合顺序值为:\n"); for (GroupCouplingItem groupCouplingInfo : unit.getGroupCouplingInfo().getGroupCouplingItems()) { info.append(groupCouplingInfo); info.append("\n"); } info.append("分组耦合顺序差值为:\n"); for (Float difference : unit.getGroupCouplingInfo().getDifferences()) { info.append(MetricsFormat.toFormattedMetrics(difference)); info.append("\n"); } info.append("分组耦合最大顺序差值为:"); info.append(MetricsFormat.toFormattedMetrics(unit.getGroupCouplingInfo().getMaxDifference())); return info.toString(); }
@Override protected boolean have(FeatureCheckContext context) { if (context.getAbstractMethods() != null && context.getSubClasses() != null) { for (JavaClass subClass : context.getSubClasses()) { for (Method method : subClass.getSelfMethods()) { if (!method.isConstruction() && method.getSelfLineCount() >= 5) { for (Method superMethod : context.getAbstractMethods()) { if (method.isOverride(superMethod)) { this.setPatternInfo(method.getName()); return true; } } } } } } return false; }