def value(self, ast: AST) -> int: method_diameters: List[int] = [ self._calcalute_diameter(method_ast) for method_ast in ast.get_subtrees(ASTNodeType.METHOD_DECLARATION) ] return max(method_diameters, default=0)
def value(self, ast: AST) -> int: complexity = 0 for method_ast in ast.get_subtrees(ASTNodeType.METHOD_DECLARATION): method_declaration_index = method_ast.get_root().node_index self.__method_name = self._get_node_name(method_ast, method_declaration_index) complexity += self._get_complexity(method_ast, method_declaration_index, 0) return complexity
def value(self, ast: AST) -> int: fan_out = 0 for class_declaration in ast.get_subtrees( ASTNodeType.CLASS_DECLARATION): fan_out += self._calculate_class_fan_out(class_declaration) return fan_out
def _calculate_class_RFC(self, java_class: AST) -> int: class_declaration = java_class.get_root() assert class_declaration.node_type == ASTNodeType.CLASS_DECLARATION rfc = 0 invoked_methods: Set[_MethodInvocationParams] = set() local_methods_names: Set[str] = set() for method_ast in java_class.get_subtrees( ASTNodeType.METHOD_DECLARATION): method_declaration = method_ast.get_root() local_methods_names.add(method_declaration.name) if "public" in method_declaration.modifiers: rfc += 1 invoked_methods |= self._get_all_method_invocation_params( method_ast) # filter out inherited methods # consider local methods with name not found # among methods names of current class as inherited invoked_methods = { invoked_method for invoked_method in invoked_methods if not invoked_method.isLocal or invoked_method.name in local_methods_names } rfc += len(invoked_methods) return rfc
def value(self, ast: AST) -> List[int]: lines: List[int] = [] for block_type in self._block_types: for block_ast in ast.get_subtrees(block_type): for overnested_block in self._find_overnested_blocks(block_ast.get_root()): lines.append(overnested_block.line) return lines
def value(self, ast: AST) -> List[int]: lines: List[int] = [] for method_declaration in ast.get_subtrees( ASTNodeType.METHOD_DECLARATION): top_level_while_loops = method_declaration.get_subtrees( ASTNodeType.WHILE_STATEMENT) if len(list(top_level_while_loops)) > 1: lines.append(method_declaration.get_root().line) return lines
def value(self, ast: AST) -> List[int]: lines: List[int] = [] for method_ast in ast.get_subtrees( ASTNodeType.METHOD_DECLARATION, ASTNodeType.CONSTRUCTOR_DECLARATION): method_declaration = method_ast.get_root() is_fully_sync_method = len(method_declaration.body) == 1 and \ method_declaration.body[0].node_type == ASTNodeType.SYNCHRONIZED_STATEMENT synchronized_statements = list( method_ast.get_proxy_nodes(ASTNodeType.SYNCHRONIZED_STATEMENT)) if len(synchronized_statements) > 0 and not is_fully_sync_method: lines.extend(statement.line for statement in synchronized_statements) return lines