def DAM_class_level(self, class_entity: und.Ent): """ DAM - Class Level Direct Access Metric :param class_entity: The class entity. :return: Ratio of the number of private and protected attributes to the total number of attributes in a class. """ if "Interface" in class_entity.kindname(): return 2.0 private_variables = len( class_entity.ents("Define", "Java Variable Private Member")) protected_variables = len( class_entity.ents("Define", "Java Variable Protected Member")) default_variables = len( class_entity.ents("Define", "Java Variable Default Member")) public_variables = len( class_entity.ents("Define", "Java Variable Public Member")) try: enum_ = private_variables + protected_variables denum_ = private_variables + protected_variables + default_variables + public_variables ratio = enum_ / denum_ except ZeroDivisionError: # logger.error('ZeroDivisionError in computing QMOOD DAM metric.') ratio = 2.0 return 1. + ratio
def MFA_class_level(self, class_entity: und.Ent): """ MFA - Class Level Measure of Functional Abstraction :param class_entity: The class entity :return: Ratio of the number of inherited methods per the total number of methods within a class. """ metrics = class_entity.metric( ['CountDeclMethod', 'CountDeclMethodAll']) local_methods = metrics.get('CountDeclMethod') all_methods = metrics.get('CountDeclMethodAll') # print(class_entity.longname(), metrics) if "Interface" in class_entity.kindname(): return 2. else: implemented_interfaces = class_entity.ents('Java Implement Couple', '~Unknown') if len(implemented_interfaces) == 0: if all_methods == 0: mfa = 0 else: mfa = round((all_methods - local_methods) / all_methods, 5) else: implemented_methods = 0 for interface_entity in implemented_interfaces: implemented_methods += interface_entity.metric( ['CountDeclMethodAll']).get('CountDeclMethodAll', 0) if all_methods == 0: mfa = 0 else: mfa = round( (all_methods - implemented_methods) / all_methods, 5) # print(class_entity.longname(), mfa) return 1. + mfa if mfa >= 0 else 1