def value(self, ast: AST) -> List[int]: lines: List[int] = [] for node in ast.get_proxy_nodes(ASTNodeType.METHOD_DECLARATION): method_name = node.name if method_name.startswith('get') and self._check_body_nodes( node.body): lines.append(node.line) return sorted(lines)
def _find_local_method_invocations(method_ast: AST) -> Set[str]: invoked_methods: Set[str] = set() for method_invocation in method_ast.get_proxy_nodes( ASTNodeType.METHOD_INVOCATION): if method_invocation.qualifier is None: invoked_methods.add(method_invocation.member) return invoked_methods
def _find_fields_usage(method_ast: AST) -> Set[str]: local_variables: Set[str] = set() for variable_declaration in method_ast.get_proxy_nodes( ASTNodeType.LOCAL_VARIABLE_DECLARATION): local_variables.update(variable_declaration.names) method_declaration = method_ast.get_root() for parameter in method_declaration.parameters: local_variables.add(parameter.name) used_fields: Set[str] = set() for member_reference in method_ast.get_proxy_nodes( ASTNodeType.MEMBER_REFERENCE): if member_reference.qualifier is None and \ member_reference.member not in local_variables: used_fields.add(member_reference.member) return used_fields
def get_variables_decl_in_node(method_decl: AST) -> List[str]: names = [] for x in method_decl.get_proxy_nodes(ASTNodeType.VARIABLE_DECLARATOR): if hasattr(x, 'name'): names.append(x.name) elif hasattr(x, 'names'): names.extend(x.names) for x in method_decl.get_proxy_nodes(ASTNodeType.VARIABLE_DECLARATION): if hasattr(x, 'name'): names.append(x.name) elif hasattr(x, 'names'): names.extend(x.names) for x in method_decl.get_proxy_nodes(ASTNodeType.TRY_RESOURCE): names.append(x.name) return names
def value(self, ast: AST) -> int: metric = 0 for node in ast.get_proxy_nodes(*NCSSMetric._keyword_node_types, *NCSSMetric._declarations_node_types, *NCSSMetric._misc_node_types): metric += 1 if node.node_type == ASTNodeType.IF_STATEMENT and self._has_pure_else_statements( node): metric += 1 elif node.node_type == ASTNodeType.TRY_STATEMENT and self._has_finally_block( node): metric += 1 return metric