def DCC_class_level(self, class_entity: und.Ent): """ DCC - Class Level Direct Class Coupling :param class_entity: The class entity :return: Number of other classes a class relates to, either through a shared attribute or a parameter in a method. """ others = list() if "Interface" in class_entity.kindname(): return 0 for ref in class_entity.refs("Define", "Variable"): if ref.ent().type() in self.all_classes: others.append(ref.ent().type()) kind_filter = "Method ~Unknown ~Jar ~Library ~Constructor ~Implicit ~Lambda ~External" for ref in class_entity.refs("Define", kind_filter): for ref2 in ref.ent().refs("Java Define", "Java Parameter"): if ref2.ent().type() in self.all_classes: others.append(ref2.ent().type()) for ref in class_entity.refs("Define", kind_filter): for ref2 in ref.ent().refs("Java Use Return"): if ref2.ent().type() in self.all_classes: others.append(ref2.ent().type()) return len(set(others))
def NOP_class_level(self, class_entity: und.Ent): """ NOP - Class Level Number of Polymorphic Methods Any method that can be used by a class and its descendants. :param class_entity: The class entity :return: Counts of the number of methods in a class excluding private, static and final ones. """ if "Final" in class_entity.kindname(): return 0 all_methods = class_entity.metric(['CountDeclMethodAll' ]).get('CountDeclMethodAll', 0) # private_methods = class_entity.metric(['CountDeclMethodPrivate']).get('CountDeclMethodPrivate', 0) # static_methods = class_entity.metric(['CountDeclClassMethod']).get('CountDeclClassMethod', 0) # final_methods = 0 if "Interface" in class_entity.kindname(): return all_methods private_or_static_or_final = 0 kind_filter = 'Java Method ~Jar ~Library ~Constructor ~Implicit ~Lambda ~External' for ref in class_entity.refs('Define', kind_filter): if "Final" in ref.ent().kindname() or "Private" in ref.ent( ).kindname() or "Static" in ref.ent().kindname(): private_or_static_or_final += 1 number_of_polymorphic_methods = all_methods - private_or_static_or_final # print(class_entity.longname(), number_of_polymorphic_methods) return number_of_polymorphic_methods if number_of_polymorphic_methods >= 0 else 0
def MOA_class_level(self, class_entity: und.Ent): """ MOA - Class Level Measure of Aggregation :param class_entity: The class entity. :return: Count of number of attributes whose type is user defined class(es). """ counter = 0 for ref in class_entity.refs("Define, Typed, Set, Create", "Java Variable, Parameter"): if ref.ent().type() in self.user_defined_classes: counter += 1 filter_ = "Method ~Unknown ~Jar ~Library ~Constructor ~Implicit ~Lambda ~External" for ref in class_entity.refs("Define, Typed, Set, Create", filter_): for ref2 in ref.ent().refs( "Define, Typed, Set, Create", "Java Variable ~Unknown, Java Parameter"): if ref2.ent().type() in self.user_defined_classes: counter += 1 return counter