From 4d8f187aa0af0cf839bbaf856649c7d6187899af Mon Sep 17 00:00:00 2001 From: Vitaly Protasov Date: Fri, 3 Jul 2020 14:21:10 +0300 Subject: [PATCH 01/44] refactored --- aibolit/metrics/cognitiveC/cognitive_c.py | 183 +++++++++++----------- 1 file changed, 91 insertions(+), 92 deletions(-) diff --git a/aibolit/metrics/cognitiveC/cognitive_c.py b/aibolit/metrics/cognitiveC/cognitive_c.py index b209013d..cf250402 100644 --- a/aibolit/metrics/cognitiveC/cognitive_c.py +++ b/aibolit/metrics/cognitiveC/cognitive_c.py @@ -1,52 +1,48 @@ -from javalang.tree import IfStatement, SwitchStatement, ForStatement, WhileStatement -from javalang.tree import DoStatement, CatchClause, BreakStatement, ContinueStatement -from javalang.tree import TernaryExpression, BinaryOperation, MethodDeclaration, MethodInvocation -from aibolit.utils.ast_builder import build_ast -import javalang +from aibolit.utils.ast import AST, ASTNodeType +from aibolit.utils.java_package import JavaPackage from typing import List, Any, Type increment_for: List[Type] = [ - IfStatement, - SwitchStatement, - ForStatement, - WhileStatement, - DoStatement, - CatchClause, - BreakStatement, - ContinueStatement, - TernaryExpression, - BinaryOperation, - MethodInvocation, + ASTNodeType.IF_STATEMENT, + ASTNodeType.SWITCH_STATEMENT, + ASTNodeType.FOR_STATEMENT, + ASTNodeType.WHILE_STATEMENT, + ASTNodeType.DO_STATEMENT, + ASTNodeType.CATCH_CLAUSE, + ASTNodeType.BREAK_STATEMENT, + ASTNodeType.CONTINUE_STATEMENT, + ASTNodeType.TERNARY_EXPRESSION, + ASTNodeType.BINARY_OPERATION, + ASTNodeType.METHOD_INVOCATION, ] nested_for: List[Type] = [ - IfStatement, - SwitchStatement, - ForStatement, - WhileStatement, - DoStatement, - CatchClause, + ASTNodeType.IF_STATEMENT, + ASTNodeType.SWITCH_STATEMENT, + ASTNodeType.FOR_STATEMENT, + ASTNodeType.WHILE_STATEMENT, + ASTNodeType.DO_STATEMENT, + ASTNodeType.CATCH_CLAUSE, ] logical_operators: List[str] = ['&', '&&', '^', '|', '||'] class CognitiveComplexity: - ''' - beta version of Cognitive Complexity - ''' + def __init__(self): self.complexity = 0 self.method_name = None - def _traverse_childs(self, block: Any, nested_level: int) -> None: - - for each_child in block.children: - self._get_complexity(each_child, nested_level) + def _traverse_childs(self, ast, node: Any, nested_level: int) -> None: - def _check_if_statement(self, expr: IfStatement, nested_level: int) -> None: + for each_child in ast.tree.succ[node]: + self._get_complexity(ast, each_child, nested_level) + ''' + def _check_if_statement(self, ast, expr, nested_level: int) -> None: '''function to work with IfStatement block''' - self._get_complexity(expr.condition, 0) + bin_operation_ = list(ast.children_with_type(expr, ASTNodeType.BINARY_OPERATION)) + self._get_complexity(ast, bin_operation_[0], 0) if expr.then_statement is not None: self.complexity += nested_level + 1 self._get_complexity(expr.then_statement, nested_level + 1) @@ -58,73 +54,76 @@ def _check_if_statement(self, expr: IfStatement, nested_level: int) -> None: else: self.complexity += 1 self._get_complexity(expr.else_statement, nested_level + 1) - + ''' def _increment_logical_operators(self, block: BinaryOperation, prev_operator: str) -> None: - for each_block in [block.operandr, block.operandl]: - - if isinstance(each_block, BinaryOperation) and prev_operator in logical_operators: - if prev_operator != each_block.operator: - self.complexity += 1 - - elif isinstance(each_block.operandr, BinaryOperation): - self.complexity += 1 - - self._increment_logical_operators(each_block, each_block.operator) - - def _is_recursion_call(self, block: MethodInvocation) -> bool: - if self.method_name == block.member: - return True - return False - - def _nested_methods(self, block: MethodDeclaration, nested_level: int) -> None: + print('_increment_logical_operators') + return + + def _is_recursion_call(self, ast, node) -> bool: + if ast.get_type(node) == ASTNodeType.METHOD_INVOCATION: + if self.method_name == self._get_node_name(ast, node): + return True + return False + + def _nested_methods(self, ast, node, nested_level: int) -> None: original_name = self.method_name - self.method_name = block.name - self._get_complexity(block, nested_level + 1) + self.method_name = self._get_node_name(ast, node) + self._get_complexity(ast, node, nested_level + 1) self.method_name = original_name - def _get_complexity(self, block: Any, nested_level: int) -> None: - block_arr = block if isinstance(block, List) else [block] - - for each_block in block_arr: - if hasattr(each_block, 'children'): - - if type(each_block) == MethodDeclaration and each_block.name != self.method_name: - self._nested_methods(each_block, nested_level) - - elif isinstance(each_block, IfStatement): - self._check_if_statement(each_block, nested_level) - - elif type(each_block) in increment_for and type(each_block) in nested_for: - self.complexity += 1 + nested_level - self._traverse_childs(each_block, nested_level + 1) - - elif type(each_block) in increment_for and type(each_block) not in nested_for: - if isinstance(each_block, BinaryOperation): - if each_block.operator in logical_operators: - self.complexity += 1 - self._increment_logical_operators(each_block, each_block.operator) - - elif isinstance(each_block, MethodInvocation): - is_recursion = self._is_recursion_call(each_block) - self.complexity += is_recursion - - else: + def _get_complexity(self, ast: Any, node: int, nested_level: int) -> None: + + for each_block in ast.tree.succ[node]: + each_block_name = self._get_node_name(ast, each_block) + each_block_type = ast.get_type(each_block) + + if each_block_type == ASTNodeType.METHOD_DECLARATION and each_block_name != self.method_name: + self._nested_methods(ast, each_block, nested_level) + + elif each_block_type == ASTNodeType.IF_STATEMENT: + self._check_if_statement(ast, each_block, nested_level) + + elif each_block_type in increment_for and each_block_type in nested_for: + self.complexity += 1 + nested_level + self._traverse_childs(ast, each_block, nested_level + 1) + + elif each_block_type in increment_for and each_block_type not in nested_for: + if ast.get_type(each_block) == ASTNodeType.BINARY_OPERATION: + bin_operator = ast.get_binary_operation_name(each_block) + if bin_operator in logical_operators: self.complexity += 1 - self._traverse_childs(each_block, nested_level) + self._increment_logical_operators(ast, each_block, bin_operator) + elif each_block_type == ASTNodeType.METHOD_INVOCATION: + is_recursion = self._is_recursion_call(ast, each_block) + self.complexity += is_recursion else: - self._traverse_childs(each_block, nested_level) + self.complexity += 1 + self._traverse_childs(ast, each_block, nested_level) + else: + self._traverse_childs(ast, each_block, nested_level) + + + def _get_node_name(self, ast, node) -> str: + extracted_name = None + names = list(ast.children_with_type(node, ASTNodeType.STRING)) + for each_string in names: + method_name = ast.get_attr(each_string, 'string') + if not method_name.startswith('/'): + extracted_name = method_name + return extracted_name + def value(self, filename: str) -> int: - - tree = build_ast(filename) - for _, class_body in tree.filter(javalang.tree.ClassDeclaration): - for each_object in class_body.body: - if isinstance(each_object, MethodDeclaration): - - # memorize the name for detecting recursion call - self.method_name = each_object.name - self._get_complexity(each_object, 0) - - final_value, self.complexity = self.complexity, 0 - return final_value + p = JavaPackage(filename) + for class_name in p.java_classes: + tree = p.java_classes[class_name] + print(tree) + declareted_methods = tree.subtrees_with_root_type(ASTNodeType.METHOD_DECLARATION) + for class_method in declareted_methods: + ast_each_method = AST(tree.tree.subgraph(class_method), class_method[0]) + self.method_name = self._get_node_name(ast_each_method, ast_each_method.root) + self._get_complexity(ast_each_method, class_method[0], 0) + print(self.method_name) + + return self.complexity From 9eeb9c289c8fed3a80985a8688a67a3ad07ac61b Mon Sep 17 00:00:00 2001 From: Vitaly Protasov Date: Fri, 3 Jul 2020 16:50:53 +0300 Subject: [PATCH 02/44] refactored --- aibolit/metrics/cognitiveC/cognitive_c.py | 59 ++++++++++++++--------- 1 file changed, 37 insertions(+), 22 deletions(-) diff --git a/aibolit/metrics/cognitiveC/cognitive_c.py b/aibolit/metrics/cognitiveC/cognitive_c.py index cf250402..ef6ca366 100644 --- a/aibolit/metrics/cognitiveC/cognitive_c.py +++ b/aibolit/metrics/cognitiveC/cognitive_c.py @@ -25,7 +25,7 @@ ASTNodeType.CATCH_CLAUSE, ] -logical_operators: List[str] = ['&', '&&', '^', '|', '||'] +logical_operators: List[str] = ['!', '&', '&&', '^', '|', '||'] class CognitiveComplexity: @@ -35,29 +35,41 @@ def __init__(self): self.method_name = None def _traverse_childs(self, ast, node: Any, nested_level: int) -> None: - for each_child in ast.tree.succ[node]: + #print(ast.get_type(node), ast.get_type(each_child)) self._get_complexity(ast, each_child, nested_level) - ''' + def _check_if_statement(self, ast, expr, nested_level: int) -> None: '''function to work with IfStatement block''' - bin_operation_ = list(ast.children_with_type(expr, ASTNodeType.BINARY_OPERATION)) - self._get_complexity(ast, bin_operation_[0], 0) - if expr.then_statement is not None: + bin_statement = list(ast.children_with_type(expr, ASTNodeType.BINARY_OPERATION)) + if len(bin_statement) != 0: + self._get_complexity(ast, bin_statement[0], 0) + + nested_statements = list(ast.children_with_type(expr, ASTNodeType.BLOCK_STATEMENT)) + elif_statements = list(ast.children_with_type(expr, ASTNodeType.IF_STATEMENT)) + + for i in elif_statements: + self.complexity += 1 + self._check_if_statement(ast, i, nested_level) + + for j in nested_statements: self.complexity += nested_level + 1 - self._get_complexity(expr.then_statement, nested_level + 1) + self._get_complexity(ast, j, nested_level + 1) + - if expr.else_statement is not None: - if isinstance(expr.else_statement, IfStatement): - self.complexity -= nested_level - self._check_if_statement(expr.else_statement, nested_level) - else: - self.complexity += 1 - self._get_complexity(expr.else_statement, nested_level + 1) - ''' def _increment_logical_operators(self, block: BinaryOperation, prev_operator: str) -> None: print('_increment_logical_operators') return + for each_block in [block.operandr, block.operandl]: + + if isinstance(each_block, BinaryOperation) and prev_operator in logical_operators: + if prev_operator != each_block.operator: + self.complexity += 1 + + elif isinstance(each_block.operandr, BinaryOperation): + self.complexity += 1 + + self._increment_logical_operators(ast, each_block, each_block.operator) def _is_recursion_call(self, ast, node) -> bool: if ast.get_type(node) == ASTNodeType.METHOD_INVOCATION: @@ -80,12 +92,13 @@ def _get_complexity(self, ast: Any, node: int, nested_level: int) -> None: if each_block_type == ASTNodeType.METHOD_DECLARATION and each_block_name != self.method_name: self._nested_methods(ast, each_block, nested_level) - elif each_block_type == ASTNodeType.IF_STATEMENT: - self._check_if_statement(ast, each_block, nested_level) + elif each_block_type == ASTNodeType.IF_STATEMENT: + self.complexity += 1 + self._get_complexity(ast, each_block, nested_level + 1) elif each_block_type in increment_for and each_block_type in nested_for: self.complexity += 1 + nested_level - self._traverse_childs(ast, each_block, nested_level + 1) + self._get_complexity(ast, each_block, nested_level + 1) elif each_block_type in increment_for and each_block_type not in nested_for: if ast.get_type(each_block) == ASTNodeType.BINARY_OPERATION: @@ -99,10 +112,10 @@ def _get_complexity(self, ast: Any, node: int, nested_level: int) -> None: else: self.complexity += 1 - self._traverse_childs(ast, each_block, nested_level) + self._get_complexity(ast, each_block, nested_level) else: - self._traverse_childs(ast, each_block, nested_level) + self._get_complexity(ast, each_block, nested_level) def _get_node_name(self, ast, node) -> str: @@ -110,7 +123,7 @@ def _get_node_name(self, ast, node) -> str: names = list(ast.children_with_type(node, ASTNodeType.STRING)) for each_string in names: method_name = ast.get_attr(each_string, 'string') - if not method_name.startswith('/'): + if not method_name.startswith('/') and method_name not in ['', None, []]: extracted_name = method_name return extracted_name @@ -118,7 +131,6 @@ def value(self, filename: str) -> int: p = JavaPackage(filename) for class_name in p.java_classes: tree = p.java_classes[class_name] - print(tree) declareted_methods = tree.subtrees_with_root_type(ASTNodeType.METHOD_DECLARATION) for class_method in declareted_methods: ast_each_method = AST(tree.tree.subgraph(class_method), class_method[0]) @@ -127,3 +139,6 @@ def value(self, filename: str) -> int: print(self.method_name) return self.complexity + +filename = '../test.java' +CognitiveComplexity().value(filename) \ No newline at end of file From 0a4420fa3a4e485174d863471532f93b95645b56 Mon Sep 17 00:00:00 2001 From: Yaroslav Kishchenko Date: Fri, 3 Jul 2020 19:08:55 +0300 Subject: [PATCH 03/44] GetBinaryOperationParams auxilary function in AST. --- aibolit/utils/ast.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/aibolit/utils/ast.py b/aibolit/utils/ast.py index 218fe43d..3aa8c8c7 100644 --- a/aibolit/utils/ast.py +++ b/aibolit/utils/ast.py @@ -117,6 +117,8 @@ class ASTNodeType(Enum): MemberReferenceParams = namedtuple('MemberReferenceParams', ('object_name', 'member_name', 'unary_operator')) +BinaryOperationParams = namedtuple('BinaryOperationParams', ('operation', 'left_side', 'right_side')) + class AST: _NODE_SKIPED = -1 @@ -246,6 +248,11 @@ def get_member_reference_params(self, member_reference_node: int) -> MemberRefer return member_reference_params + def get_binary_operation_params(self, binary_operation_node: int) -> BinaryOperationParams: + assert(self.get_type(binary_operation_node) == ASTNodeType.BINARY_OPERATION) + operation_node, left_side_node, right_side_node = self.tree.succ[binary_operation_node] + return BinaryOperationParams(self.get_attr(operation_node, 'string'), left_side_node, right_side_node) + @staticmethod def _build_from_javalang(tree, javalang_node: Node) -> int: node_index = len(tree) + 1 From c4aa2b2b10eeab632928f0cade6c0542e0ba5ff6 Mon Sep 17 00:00:00 2001 From: Yaroslav Kishchenko Date: Fri, 3 Jul 2020 19:31:30 +0300 Subject: [PATCH 04/44] Calculate cognitive complexity of logical expressions. --- aibolit/metrics/cognitiveC/cognitive_c.py | 57 ++++++++++++----------- 1 file changed, 30 insertions(+), 27 deletions(-) diff --git a/aibolit/metrics/cognitiveC/cognitive_c.py b/aibolit/metrics/cognitiveC/cognitive_c.py index ef6ca366..9d9df3f4 100644 --- a/aibolit/metrics/cognitiveC/cognitive_c.py +++ b/aibolit/metrics/cognitiveC/cognitive_c.py @@ -1,8 +1,10 @@ +from itertools import groupby + from aibolit.utils.ast import AST, ASTNodeType from aibolit.utils.java_package import JavaPackage -from typing import List, Any, Type +from typing import List, Any -increment_for: List[Type] = [ +increment_for: List[ASTNodeType] = [ ASTNodeType.IF_STATEMENT, ASTNodeType.SWITCH_STATEMENT, ASTNodeType.FOR_STATEMENT, @@ -16,7 +18,7 @@ ASTNodeType.METHOD_INVOCATION, ] -nested_for: List[Type] = [ +nested_for: List[ASTNodeType] = [ ASTNodeType.IF_STATEMENT, ASTNodeType.SWITCH_STATEMENT, ASTNodeType.FOR_STATEMENT, @@ -25,7 +27,7 @@ ASTNodeType.CATCH_CLAUSE, ] -logical_operators: List[str] = ['!', '&', '&&', '^', '|', '||'] +logical_operators = ['&&', '||'] class CognitiveComplexity: @@ -38,7 +40,7 @@ def _traverse_childs(self, ast, node: Any, nested_level: int) -> None: for each_child in ast.tree.succ[node]: #print(ast.get_type(node), ast.get_type(each_child)) self._get_complexity(ast, each_child, nested_level) - + def _check_if_statement(self, ast, expr, nested_level: int) -> None: '''function to work with IfStatement block''' bin_statement = list(ast.children_with_type(expr, ASTNodeType.BINARY_OPERATION)) @@ -51,26 +53,27 @@ def _check_if_statement(self, ast, expr, nested_level: int) -> None: for i in elif_statements: self.complexity += 1 self._check_if_statement(ast, i, nested_level) - + for j in nested_statements: self.complexity += nested_level + 1 self._get_complexity(ast, j, nested_level + 1) - - def _increment_logical_operators(self, block: BinaryOperation, prev_operator: str) -> None: - print('_increment_logical_operators') - return - for each_block in [block.operandr, block.operandl]: + def _increment_logical_operators(self, ast: AST, binary_operation_node: int) -> None: + logical_operators_sequence = self._create_logical_operators_sequence(ast, binary_operation_node) + self.complexity += len(list(groupby(logical_operators_sequence))) - if isinstance(each_block, BinaryOperation) and prev_operator in logical_operators: - if prev_operator != each_block.operator: - self.complexity += 1 + def _create_logical_operators_sequence(self, ast: AST, binary_operation_node: int) -> List[str]: + if ast.get_type(binary_operation_node) != ASTNodeType.BINARY_OPERATION: + return [] - elif isinstance(each_block.operandr, BinaryOperation): - self.complexity += 1 + operator, left_side_node, right_side_node = ast.get_binary_operation_params(binary_operation_node) + if operator not in logical_operators: + return [] + + left_sequence = self._create_logical_operators_sequence(ast, left_side_node) + right_sequence = self._create_logical_operators_sequence(ast, right_side_node) + return left_sequence + [operator] + right_sequence - self._increment_logical_operators(ast, each_block, each_block.operator) - def _is_recursion_call(self, ast, node) -> bool: if ast.get_type(node) == ASTNodeType.METHOD_INVOCATION: if self.method_name == self._get_node_name(ast, node): @@ -88,10 +91,10 @@ def _get_complexity(self, ast: Any, node: int, nested_level: int) -> None: for each_block in ast.tree.succ[node]: each_block_name = self._get_node_name(ast, each_block) each_block_type = ast.get_type(each_block) - + if each_block_type == ASTNodeType.METHOD_DECLARATION and each_block_name != self.method_name: self._nested_methods(ast, each_block, nested_level) - + elif each_block_type == ASTNodeType.IF_STATEMENT: self.complexity += 1 self._get_complexity(ast, each_block, nested_level + 1) @@ -99,13 +102,13 @@ def _get_complexity(self, ast: Any, node: int, nested_level: int) -> None: elif each_block_type in increment_for and each_block_type in nested_for: self.complexity += 1 + nested_level self._get_complexity(ast, each_block, nested_level + 1) - + elif each_block_type in increment_for and each_block_type not in nested_for: if ast.get_type(each_block) == ASTNodeType.BINARY_OPERATION: bin_operator = ast.get_binary_operation_name(each_block) if bin_operator in logical_operators: self.complexity += 1 - self._increment_logical_operators(ast, each_block, bin_operator) + self._increment_logical_operators(ast, each_block) elif each_block_type == ASTNodeType.METHOD_INVOCATION: is_recursion = self._is_recursion_call(ast, each_block) self.complexity += is_recursion @@ -116,8 +119,7 @@ def _get_complexity(self, ast: Any, node: int, nested_level: int) -> None: else: self._get_complexity(ast, each_block, nested_level) - - + def _get_node_name(self, ast, node) -> str: extracted_name = None names = list(ast.children_with_type(node, ASTNodeType.STRING)) @@ -126,7 +128,7 @@ def _get_node_name(self, ast, node) -> str: if not method_name.startswith('/') and method_name not in ['', None, []]: extracted_name = method_name return extracted_name - + def value(self, filename: str) -> int: p = JavaPackage(filename) for class_name in p.java_classes: @@ -137,8 +139,9 @@ def value(self, filename: str) -> int: self.method_name = self._get_node_name(ast_each_method, ast_each_method.root) self._get_complexity(ast_each_method, class_method[0], 0) print(self.method_name) - + return self.complexity + filename = '../test.java' -CognitiveComplexity().value(filename) \ No newline at end of file +CognitiveComplexity().value(filename) From 2db72b9dff8307811cc939a4ea596468d6b73710 Mon Sep 17 00:00:00 2001 From: Vitaly Protasov Date: Fri, 3 Jul 2020 19:54:46 +0300 Subject: [PATCH 05/44] fixed if stats --- aibolit/metrics/cognitiveC/cognitive_c.py | 65 ++++++++++------------- 1 file changed, 28 insertions(+), 37 deletions(-) diff --git a/aibolit/metrics/cognitiveC/cognitive_c.py b/aibolit/metrics/cognitiveC/cognitive_c.py index 9d9df3f4..913335be 100644 --- a/aibolit/metrics/cognitiveC/cognitive_c.py +++ b/aibolit/metrics/cognitiveC/cognitive_c.py @@ -35,28 +35,27 @@ class CognitiveComplexity: def __init__(self): self.complexity = 0 self.method_name = None - - def _traverse_childs(self, ast, node: Any, nested_level: int) -> None: - for each_child in ast.tree.succ[node]: - #print(ast.get_type(node), ast.get_type(each_child)) - self._get_complexity(ast, each_child, nested_level) - + def _check_if_statement(self, ast, expr, nested_level: int) -> None: '''function to work with IfStatement block''' - bin_statement = list(ast.children_with_type(expr, ASTNodeType.BINARY_OPERATION)) - if len(bin_statement) != 0: - self._get_complexity(ast, bin_statement[0], 0) - - nested_statements = list(ast.children_with_type(expr, ASTNodeType.BLOCK_STATEMENT)) - elif_statements = list(ast.children_with_type(expr, ASTNodeType.IF_STATEMENT)) - - for i in elif_statements: - self.complexity += 1 - self._check_if_statement(ast, i, nested_level) - - for j in nested_statements: - self.complexity += nested_level + 1 - self._get_complexity(ast, j, nested_level + 1) + all_child = ast.tree.succ[expr] + + for if_child in all_child: + type_child = ast.get_type(if_child) + check_nested_if = len(list(ast.children_with_type(if_child, ASTNodeType.IF_STATEMENT))) > 0 + if type_child == ASTNodeType.IF_STATEMENT: + self.complexity += 1 + nested_level + self._get_complexity(ast, if_child, nested_level + 1) + elif type_child == ASTNodeType.BLOCK_STATEMENT: + if check_nested_if: + self.complexity += 1 + nested_level + self._get_complexity(ast, if_child, nested_level + 1) + else: + if type_child in increment_for and type_child in nested_for: + self.complexity += 1 + nested_level + self._get_complexity(ast, if_child, nested_level + 1) + else: + self._get_complexity(ast, if_child, nested_level) def _increment_logical_operators(self, ast: AST, binary_operation_node: int) -> None: logical_operators_sequence = self._create_logical_operators_sequence(ast, binary_operation_node) @@ -73,7 +72,7 @@ def _create_logical_operators_sequence(self, ast: AST, binary_operation_node: in left_sequence = self._create_logical_operators_sequence(ast, left_side_node) right_sequence = self._create_logical_operators_sequence(ast, right_side_node) return left_sequence + [operator] + right_sequence - + def _is_recursion_call(self, ast, node) -> bool: if ast.get_type(node) == ASTNodeType.METHOD_INVOCATION: if self.method_name == self._get_node_name(ast, node): @@ -87,39 +86,36 @@ def _nested_methods(self, ast, node, nested_level: int) -> None: self.method_name = original_name def _get_complexity(self, ast: Any, node: int, nested_level: int) -> None: - for each_block in ast.tree.succ[node]: each_block_name = self._get_node_name(ast, each_block) each_block_type = ast.get_type(each_block) if each_block_type == ASTNodeType.METHOD_DECLARATION and each_block_name != self.method_name: self._nested_methods(ast, each_block, nested_level) - + elif each_block_type == ASTNodeType.IF_STATEMENT: self.complexity += 1 - self._get_complexity(ast, each_block, nested_level + 1) + self._check_if_statement(ast, each_block, nested_level) elif each_block_type in increment_for and each_block_type in nested_for: self.complexity += 1 + nested_level self._get_complexity(ast, each_block, nested_level + 1) - + elif each_block_type in increment_for and each_block_type not in nested_for: if ast.get_type(each_block) == ASTNodeType.BINARY_OPERATION: bin_operator = ast.get_binary_operation_name(each_block) if bin_operator in logical_operators: self.complexity += 1 - self._increment_logical_operators(ast, each_block) + self._increment_logical_operators(ast, each_block, bin_operator) elif each_block_type == ASTNodeType.METHOD_INVOCATION: is_recursion = self._is_recursion_call(ast, each_block) self.complexity += is_recursion - else: self.complexity += 1 self._get_complexity(ast, each_block, nested_level) - else: - self._get_complexity(ast, each_block, nested_level) - + self._get_complexity(ast, each_block, nested_level) + def _get_node_name(self, ast, node) -> str: extracted_name = None names = list(ast.children_with_type(node, ASTNodeType.STRING)) @@ -128,7 +124,7 @@ def _get_node_name(self, ast, node) -> str: if not method_name.startswith('/') and method_name not in ['', None, []]: extracted_name = method_name return extracted_name - + def value(self, filename: str) -> int: p = JavaPackage(filename) for class_name in p.java_classes: @@ -138,10 +134,5 @@ def value(self, filename: str) -> int: ast_each_method = AST(tree.tree.subgraph(class_method), class_method[0]) self.method_name = self._get_node_name(ast_each_method, ast_each_method.root) self._get_complexity(ast_each_method, class_method[0], 0) - print(self.method_name) - + return self.complexity - - -filename = '../test.java' -CognitiveComplexity().value(filename) From d6dfb66151b88057d690a7493f84e8d14c989f75 Mon Sep 17 00:00:00 2001 From: Vitaly Protasov Date: Fri, 3 Jul 2020 20:05:50 +0300 Subject: [PATCH 06/44] fixed if stats --- aibolit/metrics/cognitiveC/cognitive_c.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/aibolit/metrics/cognitiveC/cognitive_c.py b/aibolit/metrics/cognitiveC/cognitive_c.py index 913335be..b7790d11 100644 --- a/aibolit/metrics/cognitiveC/cognitive_c.py +++ b/aibolit/metrics/cognitiveC/cognitive_c.py @@ -65,7 +65,7 @@ def _create_logical_operators_sequence(self, ast: AST, binary_operation_node: in if ast.get_type(binary_operation_node) != ASTNodeType.BINARY_OPERATION: return [] - operator, left_side_node, right_side_node = ast.get_binary_operation_params(binary_operation_node) + operator, left_side_node, right_side_node = self.get_binary_operation_params(binary_operation_node) if operator not in logical_operators: return [] @@ -106,7 +106,7 @@ def _get_complexity(self, ast: Any, node: int, nested_level: int) -> None: bin_operator = ast.get_binary_operation_name(each_block) if bin_operator in logical_operators: self.complexity += 1 - self._increment_logical_operators(ast, each_block, bin_operator) + self._increment_logical_operators(ast, each_block) elif each_block_type == ASTNodeType.METHOD_INVOCATION: is_recursion = self._is_recursion_call(ast, each_block) self.complexity += is_recursion From 07004ce716c93fc0a96cec0f3d97cf15ca8fae81 Mon Sep 17 00:00:00 2001 From: Vitaly Protasov Date: Sat, 4 Jul 2020 14:12:43 +0300 Subject: [PATCH 07/44] new refactor --- aibolit/metrics/cognitiveC/cognitive_c.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/aibolit/metrics/cognitiveC/cognitive_c.py b/aibolit/metrics/cognitiveC/cognitive_c.py index b7790d11..6a068626 100644 --- a/aibolit/metrics/cognitiveC/cognitive_c.py +++ b/aibolit/metrics/cognitiveC/cognitive_c.py @@ -1,5 +1,4 @@ from itertools import groupby - from aibolit.utils.ast import AST, ASTNodeType from aibolit.utils.java_package import JavaPackage from typing import List, Any @@ -39,11 +38,18 @@ def __init__(self): def _check_if_statement(self, ast, expr, nested_level: int) -> None: '''function to work with IfStatement block''' all_child = ast.tree.succ[expr] - + check_else = len(list(ast.children_with_type(expr, ASTNodeType.BLOCK_STATEMENT))) > 1 + if check_else: + self.complexity += 1 + for if_child in all_child: type_child = ast.get_type(if_child) check_nested_if = len(list(ast.children_with_type(if_child, ASTNodeType.IF_STATEMENT))) > 0 if type_child == ASTNodeType.IF_STATEMENT: + check_else = len(list(ast.children_with_type(if_child, ASTNodeType.BLOCK_STATEMENT))) > 1 + if check_else: + self.complexity += 1 + self.complexity += 1 + nested_level self._get_complexity(ast, if_child, nested_level + 1) elif type_child == ASTNodeType.BLOCK_STATEMENT: @@ -65,7 +71,7 @@ def _create_logical_operators_sequence(self, ast: AST, binary_operation_node: in if ast.get_type(binary_operation_node) != ASTNodeType.BINARY_OPERATION: return [] - operator, left_side_node, right_side_node = self.get_binary_operation_params(binary_operation_node) + operator, left_side_node, right_side_node = ast.get_binary_operation_params(binary_operation_node) if operator not in logical_operators: return [] From 845f47483f23b773aeb5b454ef13521775248a77 Mon Sep 17 00:00:00 2001 From: Vitaly Protasov Date: Sat, 4 Jul 2020 14:15:11 +0300 Subject: [PATCH 08/44] add typing --- aibolit/metrics/cognitiveC/cognitive_c.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/aibolit/metrics/cognitiveC/cognitive_c.py b/aibolit/metrics/cognitiveC/cognitive_c.py index 6a068626..2a4afb57 100644 --- a/aibolit/metrics/cognitiveC/cognitive_c.py +++ b/aibolit/metrics/cognitiveC/cognitive_c.py @@ -35,7 +35,7 @@ def __init__(self): self.complexity = 0 self.method_name = None - def _check_if_statement(self, ast, expr, nested_level: int) -> None: + def _check_if_statement(self, ast: AST, expr: int, nested_level: int) -> None: '''function to work with IfStatement block''' all_child = ast.tree.succ[expr] check_else = len(list(ast.children_with_type(expr, ASTNodeType.BLOCK_STATEMENT))) > 1 @@ -79,13 +79,13 @@ def _create_logical_operators_sequence(self, ast: AST, binary_operation_node: in right_sequence = self._create_logical_operators_sequence(ast, right_side_node) return left_sequence + [operator] + right_sequence - def _is_recursion_call(self, ast, node) -> bool: + def _is_recursion_call(self, ast: AST, node: int) -> bool: if ast.get_type(node) == ASTNodeType.METHOD_INVOCATION: if self.method_name == self._get_node_name(ast, node): return True return False - def _nested_methods(self, ast, node, nested_level: int) -> None: + def _nested_methods(self, ast: AST, node: int, nested_level: int) -> None: original_name = self.method_name self.method_name = self._get_node_name(ast, node) self._get_complexity(ast, node, nested_level + 1) @@ -122,7 +122,7 @@ def _get_complexity(self, ast: Any, node: int, nested_level: int) -> None: else: self._get_complexity(ast, each_block, nested_level) - def _get_node_name(self, ast, node) -> str: + def _get_node_name(self, ast: AST, node: int) -> str: extracted_name = None names = list(ast.children_with_type(node, ASTNodeType.STRING)) for each_string in names: From 893bfee5b8dc81c2706b81f87383cd6574f3ef3e Mon Sep 17 00:00:00 2001 From: Vitaly Protasov Date: Sat, 4 Jul 2020 21:07:18 +0300 Subject: [PATCH 09/44] fixed errors --- aibolit/metrics/cognitiveC/cognitive_c.py | 114 ++++++++++------------ 1 file changed, 54 insertions(+), 60 deletions(-) diff --git a/aibolit/metrics/cognitiveC/cognitive_c.py b/aibolit/metrics/cognitiveC/cognitive_c.py index 2a4afb57..bd924eb2 100644 --- a/aibolit/metrics/cognitiveC/cognitive_c.py +++ b/aibolit/metrics/cognitiveC/cognitive_c.py @@ -34,34 +34,26 @@ class CognitiveComplexity: def __init__(self): self.complexity = 0 self.method_name = None - - def _check_if_statement(self, ast: AST, expr: int, nested_level: int) -> None: + + def _traverse_childs(self, ast: AST, node: int, nested_level: int) -> None: + for each_child in ast.tree.succ[node]: + self._get_complexity(ast, each_child, nested_level) + + def _check_if_statement(self, ast, expr, nested_level: int) -> None: '''function to work with IfStatement block''' - all_child = ast.tree.succ[expr] - check_else = len(list(ast.children_with_type(expr, ASTNodeType.BLOCK_STATEMENT))) > 1 - if check_else: - self.complexity += 1 - - for if_child in all_child: - type_child = ast.get_type(if_child) - check_nested_if = len(list(ast.children_with_type(if_child, ASTNodeType.IF_STATEMENT))) > 0 - if type_child == ASTNodeType.IF_STATEMENT: - check_else = len(list(ast.children_with_type(if_child, ASTNodeType.BLOCK_STATEMENT))) > 1 - if check_else: - self.complexity += 1 + all_childs = [i for i in ast.tree.succ[expr]] + self._get_complexity(ast, all_childs[0], 0) + if len(all_childs) >= 2: + self.complexity += nested_level + 1 + self._get_complexity(ast, all_childs[1], nested_level + 1) - self.complexity += 1 + nested_level - self._get_complexity(ast, if_child, nested_level + 1) - elif type_child == ASTNodeType.BLOCK_STATEMENT: - if check_nested_if: - self.complexity += 1 + nested_level - self._get_complexity(ast, if_child, nested_level + 1) - else: - if type_child in increment_for and type_child in nested_for: - self.complexity += 1 + nested_level - self._get_complexity(ast, if_child, nested_level + 1) + if len(all_childs) == 3: + if ast.get_type(all_childs[2]) == ASTNodeType.IF_STATEMENT: + self.complexity -= nested_level + self._check_if_statement(ast, all_childs[2], nested_level) else: - self._get_complexity(ast, if_child, nested_level) + self.complexity += 1 + self._get_complexity(ast, all_childs[2], nested_level + 1) def _increment_logical_operators(self, ast: AST, binary_operation_node: int) -> None: logical_operators_sequence = self._create_logical_operators_sequence(ast, binary_operation_node) @@ -78,51 +70,51 @@ def _create_logical_operators_sequence(self, ast: AST, binary_operation_node: in left_sequence = self._create_logical_operators_sequence(ast, left_side_node) right_sequence = self._create_logical_operators_sequence(ast, right_side_node) return left_sequence + [operator] + right_sequence - - def _is_recursion_call(self, ast: AST, node: int) -> bool: + + def _is_recursion_call(self, ast, node) -> bool: # type: ignore if ast.get_type(node) == ASTNodeType.METHOD_INVOCATION: if self.method_name == self._get_node_name(ast, node): return True return False - def _nested_methods(self, ast: AST, node: int, nested_level: int) -> None: + def _nested_methods(self, ast, node, nested_level: int) -> None: original_name = self.method_name self.method_name = self._get_node_name(ast, node) self._get_complexity(ast, node, nested_level + 1) self.method_name = original_name - def _get_complexity(self, ast: Any, node: int, nested_level: int) -> None: - for each_block in ast.tree.succ[node]: - each_block_name = self._get_node_name(ast, each_block) - each_block_type = ast.get_type(each_block) + def _get_complexity(self, ast: Any, each_block: int, nested_level: int) -> None: + each_block_name = self._get_node_name(ast, each_block) + each_block_type = ast.get_type(each_block) - if each_block_type == ASTNodeType.METHOD_DECLARATION and each_block_name != self.method_name: - self._nested_methods(ast, each_block, nested_level) - - elif each_block_type == ASTNodeType.IF_STATEMENT: - self.complexity += 1 - self._check_if_statement(ast, each_block, nested_level) - - elif each_block_type in increment_for and each_block_type in nested_for: - self.complexity += 1 + nested_level - self._get_complexity(ast, each_block, nested_level + 1) - - elif each_block_type in increment_for and each_block_type not in nested_for: - if ast.get_type(each_block) == ASTNodeType.BINARY_OPERATION: - bin_operator = ast.get_binary_operation_name(each_block) - if bin_operator in logical_operators: - self.complexity += 1 - self._increment_logical_operators(ast, each_block) - elif each_block_type == ASTNodeType.METHOD_INVOCATION: - is_recursion = self._is_recursion_call(ast, each_block) - self.complexity += is_recursion - else: + if each_block_type == ASTNodeType.METHOD_DECLARATION and each_block_name != self.method_name: + self._nested_methods(ast, each_block, nested_level) + + elif each_block_type == ASTNodeType.IF_STATEMENT: + self._check_if_statement(ast, each_block, nested_level) + + elif each_block_type in increment_for and each_block_type in nested_for: + self.complexity += 1 + nested_level + self._traverse_childs(ast, each_block, nested_level + 1) + + elif each_block_type in increment_for and each_block_type not in nested_for: + if ast.get_type(each_block) == ASTNodeType.BINARY_OPERATION: + bin_operator = ast.get_binary_operation_name(each_block) + if bin_operator in logical_operators: self.complexity += 1 - self._get_complexity(ast, each_block, nested_level) + self._increment_logical_operators(ast, each_block) + + elif each_block_type == ASTNodeType.METHOD_INVOCATION: + is_recursion = self._is_recursion_call(ast, each_block) + self.complexity += is_recursion + else: - self._get_complexity(ast, each_block, nested_level) - - def _get_node_name(self, ast: AST, node: int) -> str: + self.complexity += 1 + self._traverse_childs(ast, each_block, nested_level) + else: + self._traverse_childs(ast, each_block, nested_level) + + def _get_node_name(self, ast, node) -> str: # type: ignore extracted_name = None names = list(ast.children_with_type(node, ASTNodeType.STRING)) for each_string in names: @@ -130,15 +122,17 @@ def _get_node_name(self, ast: AST, node: int) -> str: if not method_name.startswith('/') and method_name not in ['', None, []]: extracted_name = method_name return extracted_name - + def value(self, filename: str) -> int: p = JavaPackage(filename) for class_name in p.java_classes: tree = p.java_classes[class_name] + declareted_methods = tree.subtrees_with_root_type(ASTNodeType.METHOD_DECLARATION) for class_method in declareted_methods: ast_each_method = AST(tree.tree.subgraph(class_method), class_method[0]) self.method_name = self._get_node_name(ast_each_method, ast_each_method.root) self._get_complexity(ast_each_method, class_method[0], 0) - - return self.complexity + + final_value, self.complexity = self.complexity, 0 + return final_value From 1617fbe43d4bb87a364cdc3fd63237ed6e690131 Mon Sep 17 00:00:00 2001 From: Vitaly Protasov Date: Sat, 4 Jul 2020 21:23:33 +0300 Subject: [PATCH 10/44] fixed errors --- aibolit/metrics/cognitiveC/cognitive_c.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/aibolit/metrics/cognitiveC/cognitive_c.py b/aibolit/metrics/cognitiveC/cognitive_c.py index bd924eb2..9c09bb6b 100644 --- a/aibolit/metrics/cognitiveC/cognitive_c.py +++ b/aibolit/metrics/cognitiveC/cognitive_c.py @@ -2,6 +2,7 @@ from aibolit.utils.ast import AST, ASTNodeType from aibolit.utils.java_package import JavaPackage from typing import List, Any +import re increment_for: List[ASTNodeType] = [ ASTNodeType.IF_STATEMENT, @@ -119,7 +120,7 @@ def _get_node_name(self, ast, node) -> str: # type: ignore names = list(ast.children_with_type(node, ASTNodeType.STRING)) for each_string in names: method_name = ast.get_attr(each_string, 'string') - if not method_name.startswith('/') and method_name not in ['', None, []]: + if not method_name.startswith('/') and re.search(r'[^\W\d]', method_name) is not None: extracted_name = method_name return extracted_name From 51fb56a0f3af1d71d5d5e2de1a73d41ce2b85adb Mon Sep 17 00:00:00 2001 From: Vitaly Protasov Date: Mon, 6 Jul 2020 13:04:15 +0300 Subject: [PATCH 11/44] fixed comments --- aibolit/metrics/cognitiveC/cognitive_c.py | 31 +++++++++++++++-------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/aibolit/metrics/cognitiveC/cognitive_c.py b/aibolit/metrics/cognitiveC/cognitive_c.py index 9c09bb6b..ef8fe94c 100644 --- a/aibolit/metrics/cognitiveC/cognitive_c.py +++ b/aibolit/metrics/cognitiveC/cognitive_c.py @@ -1,10 +1,10 @@ from itertools import groupby from aibolit.utils.ast import AST, ASTNodeType from aibolit.utils.java_package import JavaPackage -from typing import List, Any +from typing import List, Any, Set import re -increment_for: List[ASTNodeType] = [ +increment_for: Set[ASTNodeType] = set([ ASTNodeType.IF_STATEMENT, ASTNodeType.SWITCH_STATEMENT, ASTNodeType.FOR_STATEMENT, @@ -16,16 +16,16 @@ ASTNodeType.TERNARY_EXPRESSION, ASTNodeType.BINARY_OPERATION, ASTNodeType.METHOD_INVOCATION, -] +]) -nested_for: List[ASTNodeType] = [ +nested_for: Set[ASTNodeType] = set([ ASTNodeType.IF_STATEMENT, ASTNodeType.SWITCH_STATEMENT, ASTNodeType.FOR_STATEMENT, ASTNodeType.WHILE_STATEMENT, ASTNodeType.DO_STATEMENT, ASTNodeType.CATCH_CLAUSE, -] +]) logical_operators = ['&&', '||'] @@ -42,7 +42,7 @@ def _traverse_childs(self, ast: AST, node: int, nested_level: int) -> None: def _check_if_statement(self, ast, expr, nested_level: int) -> None: '''function to work with IfStatement block''' - all_childs = [i for i in ast.tree.succ[expr]] + all_childs = list([i for i in ast.tree.succ[expr]]) self._get_complexity(ast, all_childs[0], 0) if len(all_childs) >= 2: self.complexity += nested_level + 1 @@ -73,10 +73,10 @@ def _create_logical_operators_sequence(self, ast: AST, binary_operation_node: in return left_sequence + [operator] + right_sequence def _is_recursion_call(self, ast, node) -> bool: # type: ignore - if ast.get_type(node) == ASTNodeType.METHOD_INVOCATION: - if self.method_name == self._get_node_name(ast, node): - return True - return False + assert(ast.get_type(node) == ASTNodeType.METHOD_INVOCATION) + if self.method_name == self._get_node_name(ast, node): + return True + return False def _nested_methods(self, ast, node, nested_level: int) -> None: original_name = self.method_name @@ -116,8 +116,17 @@ def _get_complexity(self, ast: Any, each_block: int, nested_level: int) -> None: self._traverse_childs(ast, each_block, nested_level) def _get_node_name(self, ast, node) -> str: # type: ignore + ''' + here want to get the name of a given node. + Mostly, it is used to get the name of method + (choise the right one from all string types). + Checking not to start with '/' is aimed to get + rid of comments, which are all childs of node. + We check the occurance any letter in name in order + to get rid of '' string and None. + ''' extracted_name = None - names = list(ast.children_with_type(node, ASTNodeType.STRING)) + names = ast.children_with_type(node, ASTNodeType.STRING) for each_string in names: method_name = ast.get_attr(each_string, 'string') if not method_name.startswith('/') and re.search(r'[^\W\d]', method_name) is not None: From 5a0de76695f93900dceba150fd2b91be4cc0b548 Mon Sep 17 00:00:00 2001 From: Vitaly Protasov Date: Mon, 6 Jul 2020 13:45:14 +0300 Subject: [PATCH 12/44] fixed comments --- aibolit/metrics/cognitiveC/cognitive_c.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/aibolit/metrics/cognitiveC/cognitive_c.py b/aibolit/metrics/cognitiveC/cognitive_c.py index ef8fe94c..41dcb40d 100644 --- a/aibolit/metrics/cognitiveC/cognitive_c.py +++ b/aibolit/metrics/cognitiveC/cognitive_c.py @@ -72,7 +72,7 @@ def _create_logical_operators_sequence(self, ast: AST, binary_operation_node: in right_sequence = self._create_logical_operators_sequence(ast, right_side_node) return left_sequence + [operator] + right_sequence - def _is_recursion_call(self, ast, node) -> bool: # type: ignore + def _is_recursion_call(self, ast, node) -> bool: assert(ast.get_type(node) == ASTNodeType.METHOD_INVOCATION) if self.method_name == self._get_node_name(ast, node): return True @@ -84,7 +84,7 @@ def _nested_methods(self, ast, node, nested_level: int) -> None: self._get_complexity(ast, node, nested_level + 1) self.method_name = original_name - def _get_complexity(self, ast: Any, each_block: int, nested_level: int) -> None: + def _get_complexity(self, ast: AST, each_block: int, nested_level: int) -> None: each_block_name = self._get_node_name(ast, each_block) each_block_type = ast.get_type(each_block) @@ -115,7 +115,7 @@ def _get_complexity(self, ast: Any, each_block: int, nested_level: int) -> None: else: self._traverse_childs(ast, each_block, nested_level) - def _get_node_name(self, ast, node) -> str: # type: ignore + def _get_node_name(self, ast, node) -> str: ''' here want to get the name of a given node. Mostly, it is used to get the name of method @@ -132,6 +132,7 @@ def _get_node_name(self, ast, node) -> str: # type: ignore if not method_name.startswith('/') and re.search(r'[^\W\d]', method_name) is not None: extracted_name = method_name return extracted_name + return '' def value(self, filename: str) -> int: p = JavaPackage(filename) From 0325ce2c37830ea848b06562096d0cf1308556af Mon Sep 17 00:00:00 2001 From: Vitaly Protasov Date: Mon, 6 Jul 2020 15:58:56 +0300 Subject: [PATCH 13/44] fixed last comments --- aibolit/metrics/cognitiveC/cognitive_c.py | 128 ++++++++++++---------- 1 file changed, 68 insertions(+), 60 deletions(-) diff --git a/aibolit/metrics/cognitiveC/cognitive_c.py b/aibolit/metrics/cognitiveC/cognitive_c.py index 41dcb40d..941342fd 100644 --- a/aibolit/metrics/cognitiveC/cognitive_c.py +++ b/aibolit/metrics/cognitiveC/cognitive_c.py @@ -1,7 +1,7 @@ from itertools import groupby from aibolit.utils.ast import AST, ASTNodeType from aibolit.utils.java_package import JavaPackage -from typing import List, Any, Set +from typing import List, Set import re increment_for: Set[ASTNodeType] = set([ @@ -33,32 +33,38 @@ class CognitiveComplexity: def __init__(self): - self.complexity = 0 - self.method_name = None + # store the name for the considered method declaration + self.__method_name = None - def _traverse_childs(self, ast: AST, node: int, nested_level: int) -> None: + def _traverse_childs(self, ast: AST, node: int, nested_level: int) -> int: + complexity = 0 for each_child in ast.tree.succ[node]: - self._get_complexity(ast, each_child, nested_level) + complexity += self._get_complexity(ast, each_child, nested_level) + return complexity - def _check_if_statement(self, ast, expr, nested_level: int) -> None: + def _check_if_statement(self, ast, expr, nested_level: int) -> int: '''function to work with IfStatement block''' + complexity = 0 all_childs = list([i for i in ast.tree.succ[expr]]) - self._get_complexity(ast, all_childs[0], 0) + complexity += self._get_complexity(ast, all_childs[0], 0) if len(all_childs) >= 2: - self.complexity += nested_level + 1 - self._get_complexity(ast, all_childs[1], nested_level + 1) + complexity += nested_level + 1 + complexity += self._get_complexity(ast, all_childs[1], nested_level + 1) if len(all_childs) == 3: if ast.get_type(all_childs[2]) == ASTNodeType.IF_STATEMENT: - self.complexity -= nested_level - self._check_if_statement(ast, all_childs[2], nested_level) + complexity -= nested_level + complexity += self._check_if_statement(ast, all_childs[2], nested_level) else: - self.complexity += 1 - self._get_complexity(ast, all_childs[2], nested_level + 1) + complexity += 1 + complexity += self._get_complexity(ast, all_childs[2], nested_level + 1) + return complexity - def _increment_logical_operators(self, ast: AST, binary_operation_node: int) -> None: + def _increment_logical_operators(self, ast: AST, binary_operation_node: int) -> int: + complexity = 0 logical_operators_sequence = self._create_logical_operators_sequence(ast, binary_operation_node) - self.complexity += len(list(groupby(logical_operators_sequence))) + complexity += len(list(groupby(logical_operators_sequence))) + return complexity def _create_logical_operators_sequence(self, ast: AST, binary_operation_node: int) -> List[str]: if ast.get_type(binary_operation_node) != ASTNodeType.BINARY_OPERATION: @@ -74,76 +80,78 @@ def _create_logical_operators_sequence(self, ast: AST, binary_operation_node: in def _is_recursion_call(self, ast, node) -> bool: assert(ast.get_type(node) == ASTNodeType.METHOD_INVOCATION) - if self.method_name == self._get_node_name(ast, node): + if self.__method_name == self._get_node_name(ast, node): return True return False - def _nested_methods(self, ast, node, nested_level: int) -> None: - original_name = self.method_name - self.method_name = self._get_node_name(ast, node) - self._get_complexity(ast, node, nested_level + 1) - self.method_name = original_name + def _nested_methods(self, ast, node, nested_level: int) -> int: + complexity = 0 + original_name = self.__method_name + self.__method_name = self._get_node_name(ast, node) + complexity += self._get_complexity(ast, node, nested_level + 1) + self.__method_name = original_name + return complexity - def _get_complexity(self, ast: AST, each_block: int, nested_level: int) -> None: - each_block_name = self._get_node_name(ast, each_block) + def _process_not_nested_structure(self, ast: AST, each_block: int, nested_level: int) -> int: + complexity = 0 each_block_type = ast.get_type(each_block) + if each_block_type == ASTNodeType.BINARY_OPERATION: + bin_operator = ast.get_binary_operation_name(each_block) + if bin_operator in logical_operators: + complexity += 1 + complexity += self._increment_logical_operators(ast, each_block) - if each_block_type == ASTNodeType.METHOD_DECLARATION and each_block_name != self.method_name: - self._nested_methods(ast, each_block, nested_level) + elif each_block_type == ASTNodeType.METHOD_INVOCATION: + is_recursion = self._is_recursion_call(ast, each_block) + complexity += is_recursion - elif each_block_type == ASTNodeType.IF_STATEMENT: - self._check_if_statement(ast, each_block, nested_level) + else: + complexity += 1 + complexity += self._traverse_childs(ast, each_block, nested_level) + return complexity - elif each_block_type in increment_for and each_block_type in nested_for: - self.complexity += 1 + nested_level - self._traverse_childs(ast, each_block, nested_level + 1) + def _get_complexity(self, ast: AST, each_block: int, nested_level: int) -> int: + each_block_name = self._get_node_name(ast, each_block) + each_block_type = ast.get_type(each_block) + complexity = 0 - elif each_block_type in increment_for and each_block_type not in nested_for: - if ast.get_type(each_block) == ASTNodeType.BINARY_OPERATION: - bin_operator = ast.get_binary_operation_name(each_block) - if bin_operator in logical_operators: - self.complexity += 1 - self._increment_logical_operators(ast, each_block) + if each_block_type == ASTNodeType.METHOD_DECLARATION and each_block_name != self.__method_name: + complexity += self._nested_methods(ast, each_block, nested_level) - elif each_block_type == ASTNodeType.METHOD_INVOCATION: - is_recursion = self._is_recursion_call(ast, each_block) - self.complexity += is_recursion + elif each_block_type == ASTNodeType.IF_STATEMENT: + complexity += self._check_if_statement(ast, each_block, nested_level) + elif each_block_type in increment_for: + if each_block_type in nested_for: + complexity += 1 + nested_level + complexity += self._traverse_childs(ast, each_block, nested_level + 1) else: - self.complexity += 1 - self._traverse_childs(ast, each_block, nested_level) + complexity += self._process_not_nested_structure(ast, each_block, nested_level) else: - self._traverse_childs(ast, each_block, nested_level) + complexity += self._traverse_childs(ast, each_block, nested_level) + return complexity def _get_node_name(self, ast, node) -> str: - ''' - here want to get the name of a given node. - Mostly, it is used to get the name of method - (choise the right one from all string types). - Checking not to start with '/' is aimed to get - rid of comments, which are all childs of node. - We check the occurance any letter in name in order - to get rid of '' string and None. - ''' extracted_name = None names = ast.children_with_type(node, ASTNodeType.STRING) for each_string in names: method_name = ast.get_attr(each_string, 'string') + # Checking not to start with '/' is aimed to get + # rid of comments, which are all childs of node. + # We check the occurance any letter in name in order + # to get rid of '' string and None. if not method_name.startswith('/') and re.search(r'[^\W\d]', method_name) is not None: extracted_name = method_name return extracted_name return '' def value(self, filename: str) -> int: + complexity = 0 p = JavaPackage(filename) for class_name in p.java_classes: tree = p.java_classes[class_name] - - declareted_methods = tree.subtrees_with_root_type(ASTNodeType.METHOD_DECLARATION) - for class_method in declareted_methods: - ast_each_method = AST(tree.tree.subgraph(class_method), class_method[0]) - self.method_name = self._get_node_name(ast_each_method, ast_each_method.root) - self._get_complexity(ast_each_method, class_method[0], 0) - - final_value, self.complexity = self.complexity, 0 - return final_value + for method_set in tree.methods.values(): + for method_ast in method_set: + self.__method_name = self._get_node_name(method_ast, method_ast.root) + complexity += self._get_complexity(method_ast, method_ast.root, 0) + return complexity From af8ba40f539bf45fc5a80cd67dedb5458f01b1fd Mon Sep 17 00:00:00 2001 From: Vitaly Protasov Date: Mon, 6 Jul 2020 16:04:21 +0300 Subject: [PATCH 14/44] fixed last comments --- aibolit/metrics/cognitiveC/cognitive_c.py | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/aibolit/metrics/cognitiveC/cognitive_c.py b/aibolit/metrics/cognitiveC/cognitive_c.py index 941342fd..c939216e 100644 --- a/aibolit/metrics/cognitiveC/cognitive_c.py +++ b/aibolit/metrics/cognitiveC/cognitive_c.py @@ -4,13 +4,7 @@ from typing import List, Set import re -increment_for: Set[ASTNodeType] = set([ - ASTNodeType.IF_STATEMENT, - ASTNodeType.SWITCH_STATEMENT, - ASTNodeType.FOR_STATEMENT, - ASTNodeType.WHILE_STATEMENT, - ASTNodeType.DO_STATEMENT, - ASTNodeType.CATCH_CLAUSE, +only_increment_for: Set[ASTNodeType] = set([ ASTNodeType.BREAK_STATEMENT, ASTNodeType.CONTINUE_STATEMENT, ASTNodeType.TERNARY_EXPRESSION, @@ -18,7 +12,7 @@ ASTNodeType.METHOD_INVOCATION, ]) -nested_for: Set[ASTNodeType] = set([ +increment_and_nested_for: Set[ASTNodeType] = set([ ASTNodeType.IF_STATEMENT, ASTNodeType.SWITCH_STATEMENT, ASTNodeType.FOR_STATEMENT, @@ -121,12 +115,11 @@ def _get_complexity(self, ast: AST, each_block: int, nested_level: int) -> int: elif each_block_type == ASTNodeType.IF_STATEMENT: complexity += self._check_if_statement(ast, each_block, nested_level) - elif each_block_type in increment_for: - if each_block_type in nested_for: - complexity += 1 + nested_level - complexity += self._traverse_childs(ast, each_block, nested_level + 1) - else: - complexity += self._process_not_nested_structure(ast, each_block, nested_level) + elif each_block_type in increment_and_nested_for: + complexity += 1 + nested_level + complexity += self._traverse_childs(ast, each_block, nested_level + 1) + elif each_block_type in only_increment_for: + complexity += self._process_not_nested_structure(ast, each_block, nested_level) else: complexity += self._traverse_childs(ast, each_block, nested_level) return complexity From e66002a5e16c8aa19f187dc3e38e2657ae4f3502 Mon Sep 17 00:00:00 2001 From: Vitaly Protasov Date: Mon, 6 Jul 2020 16:05:55 +0300 Subject: [PATCH 15/44] fixed last comments --- aibolit/metrics/cognitiveC/cognitive_c.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/aibolit/metrics/cognitiveC/cognitive_c.py b/aibolit/metrics/cognitiveC/cognitive_c.py index c939216e..5bf67b67 100644 --- a/aibolit/metrics/cognitiveC/cognitive_c.py +++ b/aibolit/metrics/cognitiveC/cognitive_c.py @@ -118,7 +118,7 @@ def _get_complexity(self, ast: AST, each_block: int, nested_level: int) -> int: elif each_block_type in increment_and_nested_for: complexity += 1 + nested_level complexity += self._traverse_childs(ast, each_block, nested_level + 1) - elif each_block_type in only_increment_for: + elif each_block_type in only_increment_for: complexity += self._process_not_nested_structure(ast, each_block, nested_level) else: complexity += self._traverse_childs(ast, each_block, nested_level) From 4f9722fd06fb4c9d6195a9a35151d7d723c60bab Mon Sep 17 00:00:00 2001 From: Vitaly Protasov Date: Mon, 6 Jul 2020 16:06:17 +0300 Subject: [PATCH 16/44] fixed last comments --- aibolit/metrics/cognitiveC/cognitive_c.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/aibolit/metrics/cognitiveC/cognitive_c.py b/aibolit/metrics/cognitiveC/cognitive_c.py index 5bf67b67..395bf40e 100644 --- a/aibolit/metrics/cognitiveC/cognitive_c.py +++ b/aibolit/metrics/cognitiveC/cognitive_c.py @@ -118,8 +118,10 @@ def _get_complexity(self, ast: AST, each_block: int, nested_level: int) -> int: elif each_block_type in increment_and_nested_for: complexity += 1 + nested_level complexity += self._traverse_childs(ast, each_block, nested_level + 1) + elif each_block_type in only_increment_for: complexity += self._process_not_nested_structure(ast, each_block, nested_level) + else: complexity += self._traverse_childs(ast, each_block, nested_level) return complexity From c9719dc16bc42d842fd11da4c515500966aa4c91 Mon Sep 17 00:00:00 2001 From: Vitaly Protasov Date: Mon, 6 Jul 2020 18:34:00 +0300 Subject: [PATCH 17/44] refactored return if pattern --- .../if_return_if_detection/if_detection.py | 37 ++++++++----------- test/patterns/if_return_if_detection/5.java | 2 +- .../test_if_return_if.py | 8 ++-- 3 files changed, 20 insertions(+), 27 deletions(-) diff --git a/aibolit/patterns/if_return_if_detection/if_detection.py b/aibolit/patterns/if_return_if_detection/if_detection.py index b4296bec..c0f59ed3 100644 --- a/aibolit/patterns/if_return_if_detection/if_detection.py +++ b/aibolit/patterns/if_return_if_detection/if_detection.py @@ -1,19 +1,6 @@ -import javalang -from aibolit.utils.java_parser import JavalangImproved - - -class newJavalangImproved(JavalangImproved): - - def filter(self, ntypes): - nodes = self.tree_to_nodes() - array = [] - for index, i in enumerate(nodes): - if (type(i.node) in ntypes): - if type(i.node.then_statement) in [javalang.tree.BlockStatement] and i.node.else_statement is not None: - for check_return in i.node.then_statement.statements: - if type(check_return) in [javalang.tree.ReturnStatement]: - array.append(nodes[index].line) - return array +from aibolit.utils.ast import ASTNodeType +from aibolit.utils.java_package import JavaPackage +from typing import List class CountIfReturn: @@ -24,9 +11,15 @@ class CountIfReturn: def __init__(self): pass - def value(self, filename: str): - '''''' - tree = newJavalangImproved(filename) - if_decls = tree.filter([javalang.tree.IfStatement]) - - return if_decls + def value(self, filename: str) -> List[int]: + detected_lines = [] + p = JavaPackage(filename) + for class_name in p.java_classes: + tree = p.java_classes[class_name] + for index, each_object in enumerate(tree.nodes_by_type(ASTNodeType.IF_STATEMENT)): + all_childs = list([i for i in tree.tree.succ[each_object]]) + if len(all_childs) == 3: + for i in tree.tree.succ[all_childs[1]]: + if tree.get_type(i) == ASTNodeType.RETURN_STATEMENT: + detected_lines += [tree.get_attr(each_object, 'source_code_line')] + return detected_lines diff --git a/test/patterns/if_return_if_detection/5.java b/test/patterns/if_return_if_detection/5.java index ceb8b03d..a17bae48 100644 --- a/test/patterns/if_return_if_detection/5.java +++ b/test/patterns/if_return_if_detection/5.java @@ -21,4 +21,4 @@ public static void main(String[] arg) { return 2; } } -} \ No newline at end of file +} diff --git a/test/patterns/if_return_if_detection/test_if_return_if.py b/test/patterns/if_return_if_detection/test_if_return_if.py index 9e4675b2..31cbe348 100644 --- a/test/patterns/if_return_if_detection/test_if_return_if.py +++ b/test/patterns/if_return_if_detection/test_if_return_if.py @@ -30,14 +30,14 @@ class TestCountIfReturn(TestCase): dir_path = Path(os.path.realpath(__file__)).parent countifreturn = CountIfReturn() - def test_no_return_inside(self): - lines = self.countifreturn.value(Path(self.dir_path, '2.java')) - self.assertEqual(lines, []) - def test_2nd_level_inside(self): lines = self.countifreturn.value(Path(self.dir_path, '1.java')) self.assertEqual(lines, [6, 10]) + def test_no_return_inside(self): + lines = self.countifreturn.value(Path(self.dir_path, '2.java')) + self.assertEqual(lines, []) + def test_nested_one_goodreturn(self): lines = self.countifreturn.value(Path(self.dir_path, '3.java')) self.assertEqual(lines, []) From 0b60834afce533125de69d1b91d63fc1a43c4ddc Mon Sep 17 00:00:00 2001 From: Vitaly Protasov Date: Mon, 6 Jul 2020 23:55:50 +0300 Subject: [PATCH 18/44] fixed comments --- .../patterns/if_return_if_detection/if_detection.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/aibolit/patterns/if_return_if_detection/if_detection.py b/aibolit/patterns/if_return_if_detection/if_detection.py index c0f59ed3..f3c34397 100644 --- a/aibolit/patterns/if_return_if_detection/if_detection.py +++ b/aibolit/patterns/if_return_if_detection/if_detection.py @@ -13,13 +13,13 @@ def __init__(self): def value(self, filename: str) -> List[int]: detected_lines = [] - p = JavaPackage(filename) - for class_name in p.java_classes: - tree = p.java_classes[class_name] - for index, each_object in enumerate(tree.nodes_by_type(ASTNodeType.IF_STATEMENT)): - all_childs = list([i for i in tree.tree.succ[each_object]]) + ast = JavaPackage(filename).java_classes + for class_name in ast: + tree = ast[class_name] + for index, if_node in enumerate(tree.nodes_by_type(ASTNodeType.IF_STATEMENT)): + all_childs = [i for i in tree.tree.succ[if_node]] if len(all_childs) == 3: for i in tree.tree.succ[all_childs[1]]: if tree.get_type(i) == ASTNodeType.RETURN_STATEMENT: - detected_lines += [tree.get_attr(each_object, 'source_code_line')] + detected_lines += [tree.get_attr(if_node, 'source_code_line')] return detected_lines From 78fc4b996f253603441bec8368694483e611924e Mon Sep 17 00:00:00 2001 From: Vitaly Protasov Date: Tue, 7 Jul 2020 10:05:24 +0300 Subject: [PATCH 19/44] fixed false tests --- aibolit/metrics/cognitiveC/cognitive_c.py | 2 +- test/metrics/cognitiveC/test_cognitive_c.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/aibolit/metrics/cognitiveC/cognitive_c.py b/aibolit/metrics/cognitiveC/cognitive_c.py index 395bf40e..0e25b0ea 100644 --- a/aibolit/metrics/cognitiveC/cognitive_c.py +++ b/aibolit/metrics/cognitiveC/cognitive_c.py @@ -92,7 +92,6 @@ def _process_not_nested_structure(self, ast: AST, each_block: int, nested_level: if each_block_type == ASTNodeType.BINARY_OPERATION: bin_operator = ast.get_binary_operation_name(each_block) if bin_operator in logical_operators: - complexity += 1 complexity += self._increment_logical_operators(ast, each_block) elif each_block_type == ASTNodeType.METHOD_INVOCATION: @@ -102,6 +101,7 @@ def _process_not_nested_structure(self, ast: AST, each_block: int, nested_level: else: complexity += 1 complexity += self._traverse_childs(ast, each_block, nested_level) + return complexity def _get_complexity(self, ast: AST, each_block: int, nested_level: int) -> int: diff --git a/test/metrics/cognitiveC/test_cognitive_c.py b/test/metrics/cognitiveC/test_cognitive_c.py index bc52643c..b6772b7d 100644 --- a/test/metrics/cognitiveC/test_cognitive_c.py +++ b/test/metrics/cognitiveC/test_cognitive_c.py @@ -48,7 +48,7 @@ def test4(self): def test5(self): lines = self.get_cc.value(Path(self.dir_path, '5.java')) - self.assertEqual(lines, 7) + self.assertEqual(lines, 3) def test6(self): lines = self.get_cc.value(Path(self.dir_path, '6.java')) @@ -56,7 +56,7 @@ def test6(self): def test7(self): lines = self.get_cc.value(Path(self.dir_path, 'recursion.java')) - self.assertEqual(lines, 7) + self.assertEqual(lines, 6) def test8(self): lines = self.get_cc.value(Path(self.dir_path, 'nested.java')) From d7ae6516102e6ff4ce5b0c997444998dde332b47 Mon Sep 17 00:00:00 2001 From: Vitaly Protasov Date: Tue, 7 Jul 2020 11:47:15 +0300 Subject: [PATCH 20/44] added extra tests --- test/metrics/cognitiveC/1.java | 15 +++---- test/metrics/cognitiveC/2.java | 14 +++--- test/metrics/cognitiveC/3.java | 62 +++++++++++++------------- test/metrics/cognitiveC/4.java | 4 +- test/metrics/cognitiveC/5.java | 2 +- test/metrics/cognitiveC/6.java | 12 ++--- test/metrics/cognitiveC/7.java | 20 ++++----- test/metrics/cognitiveC/8.java | 20 ++++----- test/metrics/cognitiveC/recursion.java | 14 +++--- 9 files changed, 81 insertions(+), 82 deletions(-) diff --git a/test/metrics/cognitiveC/1.java b/test/metrics/cognitiveC/1.java index 3b34c27e..eca793c2 100644 --- a/test/metrics/cognitiveC/1.java +++ b/test/metrics/cognitiveC/1.java @@ -8,17 +8,17 @@ public static List readDataGet(String file) throws FileNotFoundExcepti Scanner scanner = null; try { scanner = new Scanner(new File(file)); - while(scanner.hasNextLine()) { + while(scanner.hasNextLine()) { // +1 String line = scanner.nextLine(); - if (line.startsWith("#")) { - continue; + if (line.startsWith("#")) { // +1 +1 + continue; // +1 } String[] columns = line.split("\\s+"); // skip first column and last column is the label int i = 1; int[] data = new int[columns.length-2]; - for (i=1; i readDataGet(String file) throws FileNotFoundExcepti dataset.add(instance); } } finally { - if (scanner != null) + if (scanner != null) // +1 scanner.close(); } return dataset; - } - -} \ No newline at end of file + } +} diff --git a/test/metrics/cognitiveC/2.java b/test/metrics/cognitiveC/2.java index 2eb72c5e..b4b7fb8e 100644 --- a/test/metrics/cognitiveC/2.java +++ b/test/metrics/cognitiveC/2.java @@ -3,21 +3,21 @@ class T1 { public static void main(String[] arg) { int a = 1; - if (time < 2) { + if (time < 2) { // +1 a = 1; - if (time < 3) { + if (time < 3) { // +1 +1 a = 2; - } else if (a) { + } else if (a) { // +1 a = 3; - } else { + } else { // +1 a = 4; } - } else if (a) { - if (time > 111) { + } else if (a) { // +1 + if (time > 111) { // +1 +1 a = 5; } - } else { + } else { // +1 return 5; } } diff --git a/test/metrics/cognitiveC/3.java b/test/metrics/cognitiveC/3.java index 9312a5ec..e6ab716c 100644 --- a/test/metrics/cognitiveC/3.java +++ b/test/metrics/cognitiveC/3.java @@ -1,34 +1,34 @@ - public class Parser implements ParserConstants { +public class Parser implements ParserConstants { - final public void ntDefinitions() throws ParseException { - label_1: - while (true) { - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case IDENTIFIER: - case 7: - case 12: - case 15: - case 16: - case 17: - case 18: - case 20: - case 38: - ; - break; - default: - jj_la1[0] = jj_gen; - break label_1; - } - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case 38: - ntExtendedAttributeListNonEmpty(); - break; - default: - jj_la1[1] = jj_gen; - ; - } - ntDefinition(); + final public void ntDefinitions() throws ParseException { + label_1: + while (true) { // +1 + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { // +1 +1 +1 + case IDENTIFIER: + case 7: + case 12: + case 15: + case 16: + case 17: + case 18: + case 20: + case 38: + ; + break; // +1 + default: + jj_la1[0] = jj_gen; + break label_1; // +1 } + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { // +1 +1 +1 + case 38: + ntExtendedAttributeListNonEmpty(); + break; // +1 + default: + jj_la1[1] = jj_gen; + ; + } + ntDefinition(); } - - } \ No newline at end of file + } + + } \ No newline at end of file diff --git a/test/metrics/cognitiveC/4.java b/test/metrics/cognitiveC/4.java index 9250248d..36c7c435 100644 --- a/test/metrics/cognitiveC/4.java +++ b/test/metrics/cognitiveC/4.java @@ -1,14 +1,14 @@ class Test { public static void main(String[] arg) { int a = 1; - if ( a && b && c || d || e && f) { + if ( a && b && c || d || e && f) { // +1 +3 a = 1; } } public static void main(String[] arg) { int a = 1; - if ( a && !(b && c)) { + if ( a && !(b && c)) { // +1 +2 a = 1; } } diff --git a/test/metrics/cognitiveC/5.java b/test/metrics/cognitiveC/5.java index 3de7f110..be2eadc5 100644 --- a/test/metrics/cognitiveC/5.java +++ b/test/metrics/cognitiveC/5.java @@ -1,7 +1,7 @@ class Test { public static void main(String[] arg) { int a = 1; - if ( b && c ^ a && p || 2 || 3 | 5) { + if ( b && c ^ a && p || 2 || 3 | 5) { // +1 +2 a = 1 ^ 5; } } diff --git a/test/metrics/cognitiveC/6.java b/test/metrics/cognitiveC/6.java index 4de38648..a4168db4 100644 --- a/test/metrics/cognitiveC/6.java +++ b/test/metrics/cognitiveC/6.java @@ -3,17 +3,17 @@ public static void bar() { boolean a, b = true; int j = 0; - switch (j) { + switch (j) { // +1 case 0: case 1: - case 3: if (a || b) {} break; + case 3: if (a || b) {} break; // +2 +1 +1 } - switch (j) { + switch (j) { // +1 case 0: case 1: - case 3: if (a || b) {} break; + case 3: if (a || b) {} break; // +2 +1 +1 } - if (true || a && b); - while (j++ < 20); + if (true || a && b); // +1 +2 + while (j++ < 20); // +1 } } \ No newline at end of file diff --git a/test/metrics/cognitiveC/7.java b/test/metrics/cognitiveC/7.java index d0851482..cbef9746 100644 --- a/test/metrics/cognitiveC/7.java +++ b/test/metrics/cognitiveC/7.java @@ -3,29 +3,29 @@ class T1 { public static void main(String[] arg) { int a = 1; - if (time < 2) { + if (time < 2) { // +1 a = 1; - if (time < 3) { + if (time < 3) { // +1 +1 a = 2; - } else if (a) { + } else if (a) { // +1 a = 3; - } else { + } else { // +1 a = 4; } - } else if (a) { - if (time > 111) { - if (time < 150) { + } else if (a) { // +1 + if (time > 111) { // +1 +1 + if (time < 150) { // +1 +2 binary_search(1); - if (time != 140) { + if (time = 140) { // +1 +3 a = 1; - }else { + }else { // +1 a = 3; } } a = 5; } - } else { + } else { // +1 return 5; } } diff --git a/test/metrics/cognitiveC/8.java b/test/metrics/cognitiveC/8.java index 07e3c04c..6c1c1c5a 100644 --- a/test/metrics/cognitiveC/8.java +++ b/test/metrics/cognitiveC/8.java @@ -3,29 +3,29 @@ class T1 { public static void main(String[] arg) { int a = 1; - if (time < 2) { + if (time < 2) { // +1 a = 1; - if (time < 3) { + if (time < 3) { // +2 a = 2; - } else if (a) { + } else if (a) { // +1 a = 3; - } else { + } else { // +1 a = 4; } - } else if (a) { - if (time > 111) { + } else if (a) { // +1 + if (time > 111) { // +2 a = 5; } - } else { + } else { // +1 return 5; } } public static void main(String[] arg) { int a = 1; - if (time < 2) { + if (time < 2) { // +1 a = 1; - } else { - if (1 > 2) { + } else { // +1 + if (1 > 2) { // +2 time = 2; } diff --git a/test/metrics/cognitiveC/recursion.java b/test/metrics/cognitiveC/recursion.java index 92cf7acd..a604d0e9 100644 --- a/test/metrics/cognitiveC/recursion.java +++ b/test/metrics/cognitiveC/recursion.java @@ -4,30 +4,30 @@ public int compare(String firstStr, String secondStr) { } public void recursionFucn() { System.out.println("Miss me?!"); - recursionFucn(); + recursionFucn(); // +1 } int fact(int n) { // wrong base case (it may cause // stack overflow). - if (n == 100) + if (n == 100) // +1 return 1; - else - return n*fact(n-1); + else // +1 + return n*fact(n-1); // +1 } static void printFun(int test) { - if (test < 1) + if (test < 1) // +1 return; - else { + else { // +1 System.out.printf("%d ", test); // Statement 2 - printFun(test - 1); + printFun(test - 1); // +1 System.out.printf("%d ", test); return; From eccf1c31932d66b7b6fb7b7d4271e4b948e4dbbf Mon Sep 17 00:00:00 2001 From: Evgeny Maslov Date: Tue, 7 Jul 2020 11:58:10 +0300 Subject: [PATCH 21/44] Fix --- aibolit/__main__.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/aibolit/__main__.py b/aibolit/__main__.py index 5cf63f1a..fa5c8dd2 100644 --- a/aibolit/__main__.py +++ b/aibolit/__main__.py @@ -46,6 +46,8 @@ from aibolit.config import Config from aibolit.ml_pipeline.ml_pipeline import train_process, collect_dataset from aibolit.model.model import TwoFoldRankingModel, Dataset # type: ignore # noqa: F401 +from aibolit.utils.ast import ASTNodeType +from aibolit.utils.java_package import JavaPackage dir_path = os.path.dirname(os.path.realpath(__file__)) @@ -240,6 +242,21 @@ def run_recommend_for_file(file: str, args): :param args: different command line arguments :return: dict with code lines, filename and pattern name """ + source_tree = JavaPackage(file) + for int_bu in source_tree.nodes_by_type(ASTNodeType.CLASS_DECLARATION): + a = list(source_tree.children_with_type(int_bu, ASTNodeType.ANNOTATION)) + line_number = source_tree.get_attr(int_bu, 'source_code_line') + for i in a: + c = source_tree.children_with_type(i, ASTNodeType.STRING) + for j in c: + print(source_tree.get_attr(j, 'string')) + f = list(source_tree.tree.succ[int_bu].keys())[0] + line_number = source_tree.get_attr(3209, 'source_code_line') + + + for int_bu in p.nodes_by_type(ASTNodeType.METHOD_DECLARATION): + a = p.children_with_type(int_bu, ASTNodeType.ANNOTATION) + java_file = str(Path(os.getcwd(), file)) input_params, code_lines_dict, error_string = calculate_patterns_and_metrics(java_file, args) From 4f094310827f7c55b3f0b186ace2a5b45c293441 Mon Sep 17 00:00:00 2001 From: Vitaly Protasov Date: Tue, 7 Jul 2020 12:01:44 +0300 Subject: [PATCH 22/44] fixed test --- test/metrics/cognitiveC/4.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/metrics/cognitiveC/4.java b/test/metrics/cognitiveC/4.java index 36c7c435..2d6845bc 100644 --- a/test/metrics/cognitiveC/4.java +++ b/test/metrics/cognitiveC/4.java @@ -5,7 +5,7 @@ public static void main(String[] arg) { a = 1; } } - + public static void main(String[] arg) { int a = 1; if ( a && !(b && c)) { // +1 +2 From a8e9627c8e04b1ac20b161b0d6cac0918e8ae3e7 Mon Sep 17 00:00:00 2001 From: Vitaly Protasov Date: Tue, 7 Jul 2020 12:03:49 +0300 Subject: [PATCH 23/44] finished --- .../patterns/if_return_if_detection/if_detection.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/aibolit/patterns/if_return_if_detection/if_detection.py b/aibolit/patterns/if_return_if_detection/if_detection.py index f3c34397..b7d1a298 100644 --- a/aibolit/patterns/if_return_if_detection/if_detection.py +++ b/aibolit/patterns/if_return_if_detection/if_detection.py @@ -15,11 +15,11 @@ def value(self, filename: str) -> List[int]: detected_lines = [] ast = JavaPackage(filename).java_classes for class_name in ast: - tree = ast[class_name] - for index, if_node in enumerate(tree.nodes_by_type(ASTNodeType.IF_STATEMENT)): - all_childs = [i for i in tree.tree.succ[if_node]] + java_class = ast[class_name] + for index, if_node in enumerate(java_class.nodes_by_type(ASTNodeType.IF_STATEMENT)): + all_childs = [i for i in java_class.tree.succ[if_node]] if len(all_childs) == 3: - for i in tree.tree.succ[all_childs[1]]: - if tree.get_type(i) == ASTNodeType.RETURN_STATEMENT: - detected_lines += [tree.get_attr(if_node, 'source_code_line')] + for i in java_class.tree.succ[all_childs[1]]: + if java_class.get_type(i) == ASTNodeType.RETURN_STATEMENT: + detected_lines += [java_class.get_attr(if_node, 'source_code_line')] return detected_lines From ca1b1fe4e20b1952569eea964ac38d0331a48aec Mon Sep 17 00:00:00 2001 From: Yaroslav Kishchenko Date: Tue, 7 Jul 2020 12:28:54 +0300 Subject: [PATCH 24/44] Update test/metrics/cognitiveC/4.java --- test/metrics/cognitiveC/4.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/metrics/cognitiveC/4.java b/test/metrics/cognitiveC/4.java index 2d6845bc..2ff335f4 100644 --- a/test/metrics/cognitiveC/4.java +++ b/test/metrics/cognitiveC/4.java @@ -8,9 +8,9 @@ public static void main(String[] arg) { public static void main(String[] arg) { int a = 1; - if ( a && !(b && c)) { // +1 +2 + if ( a && !(b && c)) { // +1 +1 a = 1; } } -} \ No newline at end of file +} From 17daeb5f5d35a95c04183cb416d3d25f6a49267b Mon Sep 17 00:00:00 2001 From: Vitaly Protasov Date: Tue, 7 Jul 2020 14:36:41 +0300 Subject: [PATCH 25/44] fixed imports --- aibolit/patterns/if_return_if_detection/if_detection.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/aibolit/patterns/if_return_if_detection/if_detection.py b/aibolit/patterns/if_return_if_detection/if_detection.py index b7d1a298..65f28da3 100644 --- a/aibolit/patterns/if_return_if_detection/if_detection.py +++ b/aibolit/patterns/if_return_if_detection/if_detection.py @@ -1,5 +1,5 @@ -from aibolit.utils.ast import ASTNodeType -from aibolit.utils.java_package import JavaPackage +from aibolit.ast_framework import ASTNodeType +from aibolit.ast_framework.java_package import JavaPackage from typing import List From a9eadad5927c238eb4f10a715726dfcba2edc77a Mon Sep 17 00:00:00 2001 From: Evgeny Maslov Date: Tue, 7 Jul 2020 17:34:13 +0300 Subject: [PATCH 26/44] Add function for find start and end line of a node --- aibolit/__main__.py | 53 +++++++++-------- test/recommend/test_recommend_pipeline.py | 71 ++++++++++++++++++++++- 2 files changed, 100 insertions(+), 24 deletions(-) diff --git a/aibolit/__main__.py b/aibolit/__main__.py index fa5c8dd2..e0ead5fa 100644 --- a/aibolit/__main__.py +++ b/aibolit/__main__.py @@ -45,9 +45,6 @@ from aibolit import __version__ from aibolit.config import Config from aibolit.ml_pipeline.ml_pipeline import train_process, collect_dataset -from aibolit.model.model import TwoFoldRankingModel, Dataset # type: ignore # noqa: F401 -from aibolit.utils.ast import ASTNodeType -from aibolit.utils.java_package import JavaPackage dir_path = os.path.dirname(os.path.realpath(__file__)) @@ -161,6 +158,32 @@ def __count_value(value_dict, input_params, code_lines_dict, java_file: str, is_ ) +def flatten(l): + return [item for sublist in l for item in sublist] + + +def find_start_and_end_lines(node): + max_line = node.position.line + + def traverse(node): + if hasattr(node, 'children'): + for child in node.children: + if isinstance(child, list) and (len(child) > 0): + for item in child: + traverse(item) + else: + if hasattr(child, '_position'): + nonlocal max_line + if child._position.line > max_line: + max_line = child._position.line + return + else: + return + + traverse(node) + return node.position.line, max_line + + def calculate_patterns_and_metrics(file, args): code_lines_dict = input_params = {} # type: ignore error_string = None @@ -242,21 +265,6 @@ def run_recommend_for_file(file: str, args): :param args: different command line arguments :return: dict with code lines, filename and pattern name """ - source_tree = JavaPackage(file) - for int_bu in source_tree.nodes_by_type(ASTNodeType.CLASS_DECLARATION): - a = list(source_tree.children_with_type(int_bu, ASTNodeType.ANNOTATION)) - line_number = source_tree.get_attr(int_bu, 'source_code_line') - for i in a: - c = source_tree.children_with_type(i, ASTNodeType.STRING) - for j in c: - print(source_tree.get_attr(j, 'string')) - f = list(source_tree.tree.succ[int_bu].keys())[0] - line_number = source_tree.get_attr(3209, 'source_code_line') - - - for int_bu in p.nodes_by_type(ASTNodeType.METHOD_DECLARATION): - a = p.children_with_type(int_bu, ASTNodeType.ANNOTATION) - java_file = str(Path(os.getcwd(), file)) input_params, code_lines_dict, error_string = calculate_patterns_and_metrics(java_file, args) @@ -603,12 +611,11 @@ def handle_exclude_command_line(args): def format_converter_for_pattern(results, sorted_by=None): - """Reformat data where data are sorted by patterns importance + """ + Reformat data where data are sorted by patterns importance (it is already sorted in the input). - Then lines are sorted in ascending order.""" - - def flatten(l): - return [item for sublist in l for item in sublist] + Then lines are sorted in ascending order. + """ for file in results: items = file.get('results') diff --git a/test/recommend/test_recommend_pipeline.py b/test/recommend/test_recommend_pipeline.py index 1b455d8b..985bb4ba 100644 --- a/test/recommend/test_recommend_pipeline.py +++ b/test/recommend/test_recommend_pipeline.py @@ -25,10 +25,12 @@ from pathlib import Path from unittest import TestCase +import javalang + from aibolit.config import Config from aibolit.__main__ import list_dir, calculate_patterns_and_metrics, \ - create_xml_tree, create_text, format_converter_for_pattern + create_xml_tree, create_text, format_converter_for_pattern, find_start_and_end_lines class TestRecommendPipeline(TestCase): @@ -186,3 +188,70 @@ def test_text_format_sort_by_code_line(self): text = create_text(new_mock, full_report=True) md5_hash = md5('\n'.join(text).encode('utf-8')) self.assertEqual(md5_hash.hexdigest(), '1324e129e6badbfb6e10f742667023ae') + + def test_find_start_end_line_function(self): + # Check start and end line for MethodDeclaration, + # find_start_and_end_lines is used for functions only at the moment + file = Path(self.cur_file_dir, 'start_end/LottieImageAsset.java') + with open(file, 'r', encoding='utf-8') as f: + tree = javalang.parse.parse(f.read()) + method = list(tree.filter(javalang.tree.MethodDeclaration))[0][1] + start, end = find_start_and_end_lines(method) + self.assertEqual(start, 32) + self.assertEqual(end, 59) + + def test_find_start_end_line_empty_function(self): + # Check start and end line for MethodDeclaration, + # find_start_and_end_lines is used for functions only at the moment + file = Path(self.cur_file_dir, 'start_end/EmptyFunction.java') + with open(file, 'r', encoding='utf-8') as f: + tree = javalang.parse.parse(f.read()) + method = list(tree.filter(javalang.tree.MethodDeclaration))[0][1] + start, end = find_start_and_end_lines(method) + self.assertEqual(start, 32) + self.assertEqual(end, 32) + + def test_find_start_end_line_empty_function_with_one_line(self): + file = Path(self.cur_file_dir, 'start_end/OneLineFunction.java') + with open(file, 'r', encoding='utf-8') as f: + tree = javalang.parse.parse(f.read()) + method = list(tree.filter(javalang.tree.MethodDeclaration))[0][1] + start, end = find_start_and_end_lines(method) + self.assertEqual(start, 32) + self.assertEqual(end, 32) + + def test_find_start_end_line_empty_function_with_lambda(self): + file = Path(self.cur_file_dir, 'start_end/Lambda.java') + with open(file, 'r', encoding='utf-8') as f: + tree = javalang.parse.parse(f.read()) + method = list(tree.filter(javalang.tree.MethodDeclaration))[0][1] + start, end = find_start_and_end_lines(method) + self.assertEqual(start, 32) + self.assertEqual(end, 43) + + def test_find_start_end_line_empty_function_with_anonymous_class(self): + file = Path(self.cur_file_dir, 'start_end/AnonymousClass.java') + with open(file, 'r', encoding='utf-8') as f: + tree = javalang.parse.parse(f.read()) + method = list(tree.filter(javalang.tree.MethodDeclaration))[0][1] + start, end = find_start_and_end_lines(method) + self.assertEqual(start, 32) + self.assertEqual(end, 41) + + def test_find_start_end_line_empty_function_in_anonymous_class(self): + file = Path(self.cur_file_dir, 'start_end/AnonymousClass.java') + with open(file, 'r', encoding='utf-8') as f: + tree = javalang.parse.parse(f.read()) + method = list(tree.filter(javalang.tree.MethodDeclaration))[1][1] + start, end = find_start_and_end_lines(method) + self.assertEqual(start, 37) + self.assertEqual(end, 38) + + def test_find_start_end_line_in_class(self): + file = Path(self.cur_file_dir, 'start_end/LottieImageAsset.java') + with open(file, 'r', encoding='utf-8') as f: + tree = javalang.parse.parse(f.read()) + method = list(tree.filter(javalang.tree.ClassDeclaration))[0][1] + start, end = find_start_and_end_lines(method) + self.assertEqual(start, 11) + self.assertEqual(end, 59) From 61cc07fee0dd481626c9a691d6b8a38621dcbac3 Mon Sep 17 00:00:00 2001 From: Evgeny Maslov Date: Tue, 7 Jul 2020 17:45:36 +0300 Subject: [PATCH 27/44] Add tests --- test/recommend/start_end/AnonymousClass.java | 43 +++++++++++++ test/recommend/start_end/EmptyFunction.java | 34 +++++++++++ test/recommend/start_end/Lambda.java | 45 ++++++++++++++ .../recommend/start_end/LottieImageAsset.java | 61 +++++++++++++++++++ test/recommend/start_end/OneLineFunction.java | 33 ++++++++++ 5 files changed, 216 insertions(+) create mode 100644 test/recommend/start_end/AnonymousClass.java create mode 100644 test/recommend/start_end/EmptyFunction.java create mode 100644 test/recommend/start_end/Lambda.java create mode 100644 test/recommend/start_end/LottieImageAsset.java create mode 100644 test/recommend/start_end/OneLineFunction.java diff --git a/test/recommend/start_end/AnonymousClass.java b/test/recommend/start_end/AnonymousClass.java new file mode 100644 index 00000000..97fa7b90 --- /dev/null +++ b/test/recommend/start_end/AnonymousClass.java @@ -0,0 +1,43 @@ +package com.airbnb.lottie; + +import android.graphics.Bitmap; +import androidx.annotation.Nullable; +import androidx.annotation.RestrictTo; + +/** + * Data class describing an image asset exported by bodymovin. + */ +@SuppressWarnings({"aibolit.P23", "aibolit.P11"}) +public class LottieImageAsset { + private final int width; + private final int height; + private final String id; + @SuppressWarnings("aibolit.P27") + private final String fileName; + @SuppressWarnings({"aibolit.P23", "aibolit.P22"}) + private final String dirName; + /** Pre-set a bitmap for this asset */ + @SuppressWarnings({"aibolit.P23", "aibolit.P11"}) + @Nullable private Bitmap bitmap; + + @RestrictTo(RestrictTo.Scope.LIBRARY) + public LottieImageAsset(int width, int height, String id, String fileName, String dirName) { + this.width = width; + this.height = height; + this.id = id; + this.fileName = fileName; + this.dirName = dirName; + } + + public int getWidth() { + int a = 0; + List actions = new ArrayList(); + actions.add(new Runnable() { + @Override + public void run() { + int b = 0; + } + }); + return width; + } +} diff --git a/test/recommend/start_end/EmptyFunction.java b/test/recommend/start_end/EmptyFunction.java new file mode 100644 index 00000000..81d748d1 --- /dev/null +++ b/test/recommend/start_end/EmptyFunction.java @@ -0,0 +1,34 @@ +package com.airbnb.lottie; + +import android.graphics.Bitmap; +import androidx.annotation.Nullable; +import androidx.annotation.RestrictTo; + +/** + * Data class describing an image asset exported by bodymovin. + */ +@SuppressWarnings({"aibolit.P23", "aibolit.P11"}) +public class LottieImageAsset { + private final int width; + private final int height; + private final String id; + @SuppressWarnings("aibolit.P27") + private final String fileName; + @SuppressWarnings({"aibolit.P23", "aibolit.P22"}) + private final String dirName; + /** Pre-set a bitmap for this asset */ + @SuppressWarnings({"aibolit.P23", "aibolit.P11"}) + @Nullable private Bitmap bitmap; + + @RestrictTo(RestrictTo.Scope.LIBRARY) + public LottieImageAsset(int width, int height, String id, String fileName, String dirName) { + this.width = width; + this.height = height; + this.id = id; + this.fileName = fileName; + this.dirName = dirName; + } + + public int getWidth() { + } +} diff --git a/test/recommend/start_end/Lambda.java b/test/recommend/start_end/Lambda.java new file mode 100644 index 00000000..1ce5e716 --- /dev/null +++ b/test/recommend/start_end/Lambda.java @@ -0,0 +1,45 @@ +package com.airbnb.lottie; + +import android.graphics.Bitmap; +import androidx.annotation.Nullable; +import androidx.annotation.RestrictTo; + +/** + * Data class describing an image asset exported by bodymovin. + */ +@SuppressWarnings({"aibolit.P23", "aibolit.P11"}) +public class LottieImageAsset { + private final int width; + private final int height; + private final String id; + @SuppressWarnings("aibolit.P27") + private final String fileName; + @SuppressWarnings({"aibolit.P23", "aibolit.P22"}) + private final String dirName; + /** Pre-set a bitmap for this asset */ + @SuppressWarnings({"aibolit.P23", "aibolit.P11"}) + @Nullable private Bitmap bitmap; + + @RestrictTo(RestrictTo.Scope.LIBRARY) + public LottieImageAsset(int width, int height, String id, String fileName, String dirName) { + this.width = width; + this.height = height; + this.id = id; + this.fileName = fileName; + this.dirName = dirName; + } + + public ArrayList filterWithOptionalEmpty(Long threshold) { + Function filter = last -> { + final Optional size; + if (last >= threshold) { + size = Optional.empty(); + } else { + size = Optional.of(last); + } + return size; + }; + + return array.map(filter); + } +} diff --git a/test/recommend/start_end/LottieImageAsset.java b/test/recommend/start_end/LottieImageAsset.java new file mode 100644 index 00000000..c33256db --- /dev/null +++ b/test/recommend/start_end/LottieImageAsset.java @@ -0,0 +1,61 @@ +package com.airbnb.lottie; + +import android.graphics.Bitmap; +import androidx.annotation.Nullable; +import androidx.annotation.RestrictTo; + +/** + * Data class describing an image asset exported by bodymovin. + */ +@SuppressWarnings({"aibolit.P23", "aibolit.P11"}) +public class LottieImageAsset { + private final int width; + private final int height; + private final String id; + @SuppressWarnings("aibolit.P27") + private final String fileName; + @SuppressWarnings({"aibolit.P23", "aibolit.P22"}) + private final String dirName; + /** Pre-set a bitmap for this asset */ + @SuppressWarnings({"aibolit.P23", "aibolit.P11"}) + @Nullable private Bitmap bitmap; + + @RestrictTo(RestrictTo.Scope.LIBRARY) + public LottieImageAsset(int width, int height, String id, String fileName, String dirName) { + this.width = width; + this.height = height; + this.id = id; + this.fileName = fileName; + this.dirName = dirName; + } + + private XMLStreamReader2 getStreamReader(Resource wrapper, boolean quiet) + throws XMLStreamException, IOException { + Object resource = wrapper.getResource(); + boolean isRestricted = wrapper.isParserRestricted(); + XMLStreamReader2 reader = null; + if (resource instanceof URL) { // an URL resource + reader = (XMLStreamReader2)parse((URL)resource, isRestricted); + } else if (resource instanceof String) { // a CLASSPATH resource + URL url = getResource((String)resource); + reader = (XMLStreamReader2)parse(url, isRestricted); + } else if (resource instanceof Path) { // a file resource + // Can't use FileSystem API or we get an infinite loop + // since FileSystem uses Configuration API. Use java.io.File instead. + File file = new File(((Path)resource).toUri().getPath()) + .getAbsoluteFile(); + if (file.exists()) { + if (!quiet) { + LOG.debug("parsing File " + file); + } + reader = (XMLStreamReader2)parse(new BufferedInputStream( + Files.newInputStream(file.toPath())), ((Path) resource).toString(), + isRestricted); + } + } else if (resource instanceof InputStream) { + reader = (XMLStreamReader2)parse((InputStream)resource, null, + isRestricted); + } + return reader; + } +} diff --git a/test/recommend/start_end/OneLineFunction.java b/test/recommend/start_end/OneLineFunction.java new file mode 100644 index 00000000..e4dfb879 --- /dev/null +++ b/test/recommend/start_end/OneLineFunction.java @@ -0,0 +1,33 @@ +package com.airbnb.lottie; + +import android.graphics.Bitmap; +import androidx.annotation.Nullable; +import androidx.annotation.RestrictTo; + +/** + * Data class describing an image asset exported by bodymovin. + */ +@SuppressWarnings({"aibolit.P23", "aibolit.P11"}) +public class LottieImageAsset { + private final int width; + private final int height; + private final String id; + @SuppressWarnings("aibolit.P27") + private final String fileName; + @SuppressWarnings({"aibolit.P23", "aibolit.P22"}) + private final String dirName; + /** Pre-set a bitmap for this asset */ + @SuppressWarnings({"aibolit.P23", "aibolit.P11"}) + @Nullable private Bitmap bitmap; + + @RestrictTo(RestrictTo.Scope.LIBRARY) + public LottieImageAsset(int width, int height, String id, String fileName, String dirName) { + this.width = width; + this.height = height; + this.id = id; + this.fileName = fileName; + this.dirName = dirName; + } + + public int getWidth() { int a = 0; int b = 0;} +} From 4b2e61ee4d11669737c1441edf8c0fc626e8ab3c Mon Sep 17 00:00:00 2001 From: yegor256 Date: Tue, 7 Jul 2020 19:22:04 +0300 Subject: [PATCH 28/44] rename --- README.md | 46 +++++++++++++++++++++++----------------------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/README.md b/README.md index 57e333f7..14cacdec 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,12 @@ [![PyPi version](https://img.shields.io/pypi/v/aibolit.svg)](https://pypi.org/project/aibolit/) -[![Build Status](https://travis-ci.org/yegor256/aibolit.svg)](https://travis-ci.org/yegor256/aibolit) -[![Build status](https://ci.appveyor.com/api/projects/status/1k7q7eumnhia0e3a?svg=true)](https://ci.appveyor.com/project/yegor256/aibolit) -[![Hits-of-Code](https://hitsofcode.com/github/yegor256/aibolit)](https://hitsofcode.com/view/github/yegor256/aibolit) -[![Test Coverage](https://img.shields.io/codecov/c/github/yegor256/aibolit.svg)](https://codecov.io/github/yegor256/aibolit?branch=master) -[![Maintainability](https://api.codeclimate.com/v1/badges/e90e80a143a9457ee3af/maintainability)](https://codeclimate.com/github/yegor256/aibolit/maintainability) -[![License](https://img.shields.io/badge/license-MIT-green.svg)](https://github.com/yegor256/aibolit/blob/master/LICENSE.txt) +[![Build Status](https://travis-ci.org/cqfn/aibolit.svg)](https://travis-ci.org/cqfn/aibolit) +[![Build status](https://ci.appveyor.com/api/projects/status/1k7q7eumnhia0e3a?svg=true)](https://ci.appveyor.com/project/cqfn/aibolit) +[![Hits-of-Code](https://hitsofcode.com/github/cqfn/aibolit)](https://hitsofcode.com/view/github/cqfn/aibolit) +[![Test Coverage](https://img.shields.io/codecov/c/github/cqfn/aibolit.svg)](https://codecov.io/github/cqfn/aibolit?branch=master) +[![Maintainability](https://api.codeclimate.com/v1/badges/e90e80a143a9457ee3af/maintainability)](https://codeclimate.com/github/cqfn/aibolit/maintainability) +[![License](https://img.shields.io/badge/license-MIT-green.svg)](https://github.com/cqfn/aibolit/blob/master/LICENSE.txt) First, you install it (you must have [Python 3.7.7](https://www.python.org/downloads/) and [Pip](https://pip.pypa.io/en/stable/installing/) installed): @@ -34,11 +34,11 @@ Also, you can set a folder with Java files: $ aibolit recommend --folder src/java ``` -It will run recommendation function for the model (model is located in [aibolit/binary_files/model.pkl](https://github.com/yegor256/aibolit/blob/master/aibolit/binary_files/model.pkl). -The model finds a pattern which contribution is the largest to the Cyclomatic Complexity. -If anything is found, you will see all recommendations for the mentioned patterns. -You can see the list of all patterns in [Patterns.md](https://github.com/yegor256/aibolit/blob/master/PATTERNS.md). -The output of recommendation will be redirected to the stdout. +It will run recommendation function for the model (model is located in [aibolit/binary_files/model.pkl](https://github.com/cqfn/aibolit/blob/master/aibolit/binary_files/model.pkl). +The model finds a pattern which contribution is the largest to the Cyclomatic Complexity. +If anything is found, you will see all recommendations for the mentioned patterns. +You can see the list of all patterns in [Patterns.md](https://github.com/cqfn/aibolit/blob/master/PATTERNS.md). +The output of recommendation will be redirected to the stdout. If the program has the `0` exit code, it means that all analyzed files do not have any issues. If the program has the `1` exit code, it means that at least 1 analyzed file has an issue. If the program has the `2` exit code, it means that program crash occurred. @@ -73,7 +73,7 @@ Show all patterns /mnt/d/src/java/Configuration.java[3261]: Partial synchronized (P14: 0.228 4/4) /mnt/d/src/java/Configuration.java[3727]: Partial synchronized (P14: 0.228 4/4) /mnt/d/src/java/Configuration.java[3956]: Partial synchronized (P14: 0.228 4/4) -/mnt/d/src/java/ErrorExample.java: error when calculating patterns: Can't count P1 metric: +/mnt/d/src/java/ErrorExample.java: error when calculating patterns: Can't count P1 metric: Total score: 127.67642529949538 ``` @@ -106,7 +106,7 @@ Show all patterns /mnt/d/src/java/Configuration.java[3844]: Var in the middle (P21: 30.95612931128819 1/4) /mnt/d/src/java/Configuration.java[3848]: Var in the middle (P21: 30.95612931128819 1/4) /mnt/d/src/java/Configuration.java[3956]: Partial synchronized (P14: 0.228 4/4) -/mnt/d/src/java/ErrorExample.java: error when calculating patterns: Can't count P1 metric: +/mnt/d/src/java/ErrorExample.java: error when calculating patterns: Can't count P1 metric: /mnt/d/src/java/MavenSlice.java: your code is perfect in aibolit's opinion Total score: 127.67642529949538 ``` @@ -172,8 +172,8 @@ You can also choose xml format. It will have the same format as `text` mode, but ``` -The score is the relative importance of the pattern (there is no range for it). -The larger score is, the most important pattern is. +The score is the relative importance of the pattern (there is no range for it). +The larger score is, the most important pattern is. E.g., if you have several patterns, first you need to fix the pattern with the score 5.45: ``` @@ -219,13 +219,13 @@ You can get full report with `--full` command, then all patterns will be include $ aibolit recommend --folder src/java --full ``` -You can exclude folder with `--exclude` command. The last parameter is the folder to exclude, +You can exclude folder with `--exclude` command. The last parameter is the folder to exclude, the rest of them are glob patterns. ```bash $ aibolit recommend --folder src/java --exclude=**/*Test*.java --exclude=**/*Impl*.java --exclude=/mnt/d/src/java/tests ``` -If you need help, run +If you need help, run ```bash $ aibolit recommend --help @@ -236,10 +236,10 @@ $ aibolit recommend --help - Calculates patterns and metrics - Creates a dataset - - Trains model and save it - + - Trains model and save it + Train works only with cloned git repository. - 1. Clone aibolit repository + 1. Clone aibolit repository 2. Go to `cloned_aibolit_path` 3. Run `pip install .` 4. Set env variable `export HOME_AIBOLIT=cloned_aibolit_path` (example for Linux). @@ -247,9 +247,9 @@ $ aibolit recommend --help Otherwise model will be saved into `cloned_aibolit_path/aibolit/binary_files/model.pkl` 6. If you need to set up own folder with Java files, use `--java_folder parameter`, the default value will be `scripts/target/01` of aibolit cloned repo 7. You need to install Java 13 and Maven - + Or you can use our docker image (link will be soon here) - + Run train pipeline: ```bash @@ -299,5 +299,5 @@ Using Docker recommendation pipeline $ docker run --rm -it \ -v :/in \ -v :/out \ - yegor256/aibolit-image + cqfn/aibolit-image ``` From 0dc28f5b90c36ad08acef2ad0bc8965562a50f74 Mon Sep 17 00:00:00 2001 From: yegor256 Date: Tue, 7 Jul 2020 19:23:40 +0300 Subject: [PATCH 29/44] appveyor fix --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 14cacdec..df7c4d91 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ [![PyPi version](https://img.shields.io/pypi/v/aibolit.svg)](https://pypi.org/project/aibolit/) [![Build Status](https://travis-ci.org/cqfn/aibolit.svg)](https://travis-ci.org/cqfn/aibolit) -[![Build status](https://ci.appveyor.com/api/projects/status/1k7q7eumnhia0e3a?svg=true)](https://ci.appveyor.com/project/cqfn/aibolit) +[![Build status](https://ci.appveyor.com/api/projects/status/wjjcd6amnt3p2tdg?svg=true)](https://ci.appveyor.com/project/yegor256/aibolit-lyf56) [![Hits-of-Code](https://hitsofcode.com/github/cqfn/aibolit)](https://hitsofcode.com/view/github/cqfn/aibolit) [![Test Coverage](https://img.shields.io/codecov/c/github/cqfn/aibolit.svg)](https://codecov.io/github/cqfn/aibolit?branch=master) [![Maintainability](https://api.codeclimate.com/v1/badges/e90e80a143a9457ee3af/maintainability)](https://codeclimate.com/github/cqfn/aibolit/maintainability) From c11bb4e8fbeea88ef6be8ca4367f472fbdcb325d Mon Sep 17 00:00:00 2001 From: yegor256 Date: Tue, 7 Jul 2020 19:25:47 +0300 Subject: [PATCH 30/44] redirect --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index df7c4d91..357d9155 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ [![Build status](https://ci.appveyor.com/api/projects/status/wjjcd6amnt3p2tdg?svg=true)](https://ci.appveyor.com/project/yegor256/aibolit-lyf56) [![Hits-of-Code](https://hitsofcode.com/github/cqfn/aibolit)](https://hitsofcode.com/view/github/cqfn/aibolit) [![Test Coverage](https://img.shields.io/codecov/c/github/cqfn/aibolit.svg)](https://codecov.io/github/cqfn/aibolit?branch=master) -[![Maintainability](https://api.codeclimate.com/v1/badges/e90e80a143a9457ee3af/maintainability)](https://codeclimate.com/github/cqfn/aibolit/maintainability) +[![Maintainability](https://api.codeclimate.com/v1/badges/fd7e32d8472b4d5e8ecb/maintainability)](https://codeclimate.com/github/cqfn/aibolit/maintainability) [![License](https://img.shields.io/badge/license-MIT-green.svg)](https://github.com/cqfn/aibolit/blob/master/LICENSE.txt) First, you install it (you must have [Python 3.7.7](https://www.python.org/downloads/) From a79063b20c67d77898d6c8b81673037313738ca2 Mon Sep 17 00:00:00 2001 From: yegor256 Date: Tue, 7 Jul 2020 19:31:45 +0300 Subject: [PATCH 31/44] typo --- README.md | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 357d9155..5e7357ad 100644 --- a/README.md +++ b/README.md @@ -15,8 +15,6 @@ and [Pip](https://pip.pypa.io/en/stable/installing/) installed): $ pip3 install aibolit ``` -### Recommend command - To analyze your Java sources, located at `src/java` (for example), run: ```bash @@ -231,7 +229,8 @@ If you need help, run $ aibolit recommend --help ``` -### Train command +## How to retrain it? + `Train` command does the following: - Calculates patterns and metrics From 386fe9446b6bbdac72cfe5fd98577fbef3fde904 Mon Sep 17 00:00:00 2001 From: yegor256 Date: Tue, 7 Jul 2020 19:33:38 +0300 Subject: [PATCH 32/44] remove --- docker/Dockerfile | 22 ---------------------- docker/Dockerfile.recommend | 15 --------------- docker/git_clone_and_pull_pr.sh | 19 ------------------- 3 files changed, 56 deletions(-) delete mode 100644 docker/Dockerfile delete mode 100644 docker/Dockerfile.recommend delete mode 100644 docker/git_clone_and_pull_pr.sh diff --git a/docker/Dockerfile b/docker/Dockerfile deleted file mode 100644 index 1fef06ba..00000000 --- a/docker/Dockerfile +++ /dev/null @@ -1,22 +0,0 @@ -FROM jupyter/datascience-notebook - -RUN wget -q https://github.com/yegor256/aibolit/releases/download/v1.0.0/dataset.zip -RUN wget -q https://github.com/yegor256/aibolit/releases/download/v1.0.0/halstead.jar -RUN wget -q https://github.com/yegor256/aibolit/releases/download/v1.0.0/pmd-bin.zip - -RUN pip install torch==1.5.0 catboost==0.22 pandas==1.0.0 mypy==0.770 -RUN pip install networkx==2.4 lightgbm==2.3.1 scikit-learn==0.22.1 sphinx==2.3.1 -RUN git config --global user.email "docker@example.com" -RUN git config --global user.name "Docker Dockerovich" -RUN git config --global core.editor "vim" - -USER root -RUN apt-get -y update && apt-get -y install vim -RUN apt-get -y install default-jdk maven - -USER jovyan -RUN mkdir _tmp -RUN mkdir java_files -RUN unzip -q dataset.zip -d ./java_files -ENV JAVA_FILES_PATH /home/jovyan/java_files -ENTRYPOINT [] \ No newline at end of file diff --git a/docker/Dockerfile.recommend b/docker/Dockerfile.recommend deleted file mode 100644 index f594afe9..00000000 --- a/docker/Dockerfile.recommend +++ /dev/null @@ -1,15 +0,0 @@ -FROM python - -RUN git config --global user.email "docker@example.com" -RUN git config --global user.name "Docker Dockerovich" - -# fetch and install Aibolit from source# -ADD ./git_clone_and_pull_pr.sh . -RUN chmod +x ./git_clone_and_pull_pr.sh -RUN ./git_clone_and_pull_pr.sh - -RUN mkdir in -RUN mkdir out - -ENTRYPOINT [] -CMD ["aibolit", "recommend", "--folder=./in", "--output=./out/out.xml"] \ No newline at end of file diff --git a/docker/git_clone_and_pull_pr.sh b/docker/git_clone_and_pull_pr.sh deleted file mode 100644 index 45435af3..00000000 --- a/docker/git_clone_and_pull_pr.sh +++ /dev/null @@ -1,19 +0,0 @@ -#!/bin/bash - -echo "Fetch Aibolit sources" - -DEFAULT_BRANCH=master -export PULL_ID -export GIT_BRANCH - -GIT_BRANCH=${GIT_BRANCH:-$DEFAULT_BRANCH} - -is_pull_id () [[ -n $PULL_ID ]] - -if [ -z ${PULL_ID+x} ]; then echo "PULL_ID is unset."; else echo "PULL_ID is set to '$PULL_ID'"; fi - -git clone --single-branch --branch $GIT_BRANCH https://github.com/yegor256/aibolit -cd aibolit -is_pull_id && git pull --no-edit origin pull/$PULL_ID/head -pip install -e . -mkdir -p ./scripts/target \ No newline at end of file From ebea5c8f839c311e7d2c83c31e1e9e9dbdc03b8f Mon Sep 17 00:00:00 2001 From: Anton Cheshkov Date: Wed, 8 Jul 2020 12:53:23 +0300 Subject: [PATCH 33/44] added disclaimer to test Java Files --- test/integration/samples/AbstractCommand.java | 5 +++++ test/integration/samples/ActionHistory.java | 5 +++++ test/integration/samples/AddActionPanel.java | 5 +++++ test/integration/samples/AddFIActionPanel.java | 5 +++++ test/integration/samples/AnnotationOffsetItem.java | 5 +++++ test/integration/samples/AnnotationSetReferenceItem.java | 5 +++++ test/integration/samples/AnnotationsDirectoryItem.java | 5 +++++ test/integration/samples/Assertions.java | 5 +++++ test/integration/samples/AttrProp.java | 5 +++++ test/integration/samples/BCFile.java | 5 +++++ test/integration/samples/BaseKit.java | 5 +++++ test/integration/samples/BeanCodeManager.java | 5 +++++ test/integration/samples/BellmanFordAdjacencyMatrix.java | 5 +++++ test/integration/samples/BiAnalyser.java | 5 +++++ test/integration/samples/BinaryHeap.java | 5 +++++ test/integration/samples/BinaryHeapQuickRemovals.java | 5 +++++ test/integration/samples/BlockReaderLocal.java | 5 +++++ test/integration/samples/BlockReaderLocalLegacy.java | 5 +++++ test/integration/samples/BreakpointsTreeModel.java | 5 +++++ test/integration/samples/ChainedBuffer.java | 5 +++++ test/integration/samples/ChatEndpoint.java | 5 +++++ test/integration/samples/ClassDefItem.java | 5 +++++ test/integration/samples/CleanupQueue.java | 5 +++++ test/integration/samples/ClipboardHandler.java | 5 +++++ test/integration/samples/ClusterSizeMonitor.java | 5 +++++ test/integration/samples/CodeItem.java | 5 +++++ test/integration/samples/CompactMap.java | 5 +++++ test/integration/samples/CompactSegmentTree.java | 5 +++++ test/integration/samples/ConditionalExpressionCheck.java | 5 +++++ test/integration/samples/Configuration.java | 5 +++++ test/integration/samples/ConsoleImpl.java | 5 +++++ test/integration/samples/ConsumerImpl.java | 5 +++++ test/integration/samples/DBHandle.java | 5 +++++ test/integration/samples/DBParms.java | 5 +++++ test/integration/samples/DDParser.java | 5 +++++ test/integration/samples/DataTypeArchiveDB.java | 5 +++++ test/integration/samples/DeadlockExample.java | 5 +++++ test/integration/samples/DecompileDebug.java | 5 +++++ test/integration/samples/DefaultEMLookup.java | 5 +++++ test/integration/samples/DefaultProject.java | 5 +++++ test/integration/samples/DependencyGraph.java | 5 +++++ test/integration/samples/DeterministicDependencyGraph.java | 5 +++++ test/integration/samples/DriverYieldSignal.java | 5 +++++ test/integration/samples/EncodedMethod.java | 5 +++++ test/integration/samples/Environment.java | 5 +++++ test/integration/samples/EpollEventLoop.java | 5 +++++ test/integration/samples/ExceptionDemo.java | 5 +++++ test/integration/samples/FieldAnnotation.java | 5 +++++ test/integration/samples/FoldViewFactory.java | 5 +++++ test/integration/samples/FutureStateChange.java | 5 +++++ .../samples/GeneticAlgorithm_travelingSalesman.java | 5 +++++ test/integration/samples/HyperlinkEnv.java | 5 +++++ test/integration/samples/IconListPreference.java | 5 +++++ test/integration/samples/IndexedLocalFileSystem.java | 5 +++++ test/integration/samples/IndicesClusterStateService.java | 5 +++++ test/integration/samples/IntKeyMap.java | 5 +++++ test/integration/samples/InternalEngine.java | 5 +++++ test/integration/samples/InterpDtTerm.java | 5 +++++ test/integration/samples/InterpProtoANSI.java | 5 +++++ test/integration/samples/InterpProtoANSIX.java | 5 +++++ test/integration/samples/InterpXTerm.java | 5 +++++ test/integration/samples/JShellEnvironment.java | 5 +++++ test/integration/samples/JavaTargetChooserPanelGUI.java | 5 +++++ test/integration/samples/JdbcResultsSnapshot.java | 5 +++++ test/integration/samples/KeyStrokeEditor.java | 5 +++++ test/integration/samples/LSPBindings.java | 5 +++++ test/integration/samples/LiveMemoryViewUpdater.java | 5 +++++ test/integration/samples/LoaderInfoHeader.java | 5 +++++ test/integration/samples/LoaderRelocationHeader.java | 5 +++++ test/integration/samples/LocalDataFile.java | 5 +++++ test/integration/samples/LocalDatabaseItem.java | 5 +++++ test/integration/samples/LocalJobRunner.java | 5 +++++ test/integration/samples/LocalShardSnapshot.java | 5 +++++ test/integration/samples/LocalizedBundleInfo.java | 5 +++++ test/integration/samples/LongKeyMap.java | 5 +++++ test/integration/samples/LongestCommonSubstring.java | 5 +++++ test/integration/samples/LottieImageAsset.java | 5 +++++ test/integration/samples/MessageDeduplication.java | 5 +++++ test/integration/samples/MethodAnnotation.java | 5 +++++ test/integration/samples/MethodsFeatureModes.java | 5 +++++ test/integration/samples/MfLexer.java | 5 +++++ test/integration/samples/ModifierEditor.java | 5 +++++ test/integration/samples/ModuleClassPaths.java | 5 +++++ test/integration/samples/ModuleConfigurationImpl.java | 5 +++++ test/integration/samples/ModuleRoots.java | 5 +++++ test/integration/samples/ModuleTargetChooserPanelGUI.java | 5 +++++ test/integration/samples/MultiModuleClassPathProvider.java | 5 +++++ test/integration/samples/NBClassReader.java | 5 +++++ test/integration/samples/NativeRSRawDecoder.java | 5 +++++ test/integration/samples/NativeRSRawEncoder.java | 5 +++++ test/integration/samples/NativeXORRawDecoder.java | 5 +++++ test/integration/samples/NativeXORRawEncoder.java | 5 +++++ .../samples/NodesReloadSecureSettingsRequest.java | 5 +++++ test/integration/samples/NonPersistentSubscription.java | 5 +++++ test/integration/samples/OpenSslClientContext.java | 5 +++++ test/integration/samples/OpenSslServerContext.java | 5 +++++ test/integration/samples/OpenSslX509KeyManagerFactory.java | 5 +++++ test/integration/samples/OrPattern.java | 5 +++++ test/integration/samples/OutputStreamPublisher.java | 5 +++++ test/integration/samples/PackedDatabase.java | 5 +++++ test/integration/samples/ParameterAnnotation.java | 5 +++++ test/integration/samples/PartitionManager.java | 5 +++++ test/integration/samples/PdbInfo.java | 5 +++++ test/integration/samples/PdbInfoDotNet.java | 5 +++++ .../samples/PersistentDispatcherMultipleConsumers.java | 5 +++++ .../samples/PersistentDispatcherSingleActiveConsumer.java | 5 +++++ test/integration/samples/PersistentSubscription.java | 5 +++++ test/integration/samples/PrestimeCPUCCTNodeBacked.java | 5 +++++ test/integration/samples/PrivateDatabase.java | 5 +++++ test/integration/samples/ProducerImpl.java | 5 +++++ test/integration/samples/ProfilerGCXYItemPainter.java | 5 +++++ test/integration/samples/ProfilerTreeTable.java | 5 +++++ test/integration/samples/ProgramDB.java | 5 +++++ test/integration/samples/ProgramUserDataDB.java | 5 +++++ test/integration/samples/ProjectFileManager.java | 5 +++++ test/integration/samples/PrototypesIDItem.java | 5 +++++ test/integration/samples/PulsarBolt.java | 5 +++++ test/integration/samples/PulsarOffsetBackingStore.java | 5 +++++ test/integration/samples/RecoveryMgr.java | 5 +++++ .../samples/ReferenceCountedOpenSslClientContext.java | 5 +++++ test/integration/samples/ReferenceCountedOpenSslEngine.java | 5 +++++ .../samples/ReferenceCountedOpenSslServerContext.java | 5 +++++ test/integration/samples/RefreshListeners.java | 5 +++++ test/integration/samples/RequestResponseLinkCache.java | 5 +++++ test/integration/samples/ResourceHeader.java | 5 +++++ test/integration/samples/ResourceMap.java | 5 +++++ test/integration/samples/ResultSetViewer.java | 5 +++++ test/integration/samples/ScannerUtils.java | 5 +++++ test/integration/samples/SchedulerManager.java | 5 +++++ test/integration/samples/SequenceFile.java | 5 +++++ test/integration/samples/ServiceScheduler.java | 5 +++++ test/integration/samples/SizeCalculatingEntryWriter.java | 5 +++++ test/integration/samples/SpecificationVersion.java | 5 +++++ test/integration/samples/SpellcheckerOptionsPanel.java | 5 +++++ test/integration/samples/SpillRecord.java | 5 +++++ test/integration/samples/SqlQueryManager.java | 5 +++++ test/integration/samples/SquareRootDecomposition.java | 5 +++++ test/integration/samples/StringDataItem.java | 5 +++++ test/integration/samples/SvnConfigFiles.java | 5 +++++ test/integration/samples/TFile.java | 5 +++++ test/integration/samples/TabLayout.java | 5 +++++ test/integration/samples/Table.java | 5 +++++ test/integration/samples/TableModelEditor.java | 5 +++++ test/integration/samples/TarjanAdjacencyMatrix.java | 5 +++++ test/integration/samples/TaskInfoFetcher.java | 5 +++++ test/integration/samples/TextSync.java | 5 +++++ test/integration/samples/TextSyncGroup.java | 5 +++++ test/integration/samples/ThreadData.java | 5 +++++ test/integration/samples/ToolWizardPageLog.java | 5 +++++ test/integration/samples/TreeGraphLayout.java | 5 +++++ test/integration/samples/TrieDictionary.java | 5 +++++ test/integration/samples/TruffleAccess.java | 5 +++++ test/integration/samples/Utils.java | 5 +++++ test/integration/samples/VersionFileHandler.java | 5 +++++ test/integration/samples/WatchesTreeModel.java | 5 +++++ test/integration/samples/WindowManagerImpl.java | 5 +++++ test/integration/samples/WorkspaceDocumentManagerImpl.java | 5 +++++ 157 files changed, 785 insertions(+) diff --git a/test/integration/samples/AbstractCommand.java b/test/integration/samples/AbstractCommand.java index 41a6cb54..b84678f8 100644 --- a/test/integration/samples/AbstractCommand.java +++ b/test/integration/samples/AbstractCommand.java @@ -1,3 +1,8 @@ +// This Java code is taken from a public GitHub repository +// and is used inside Aibolit only for integration testing +// purposes. The code is never compiled or executed. + + /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file diff --git a/test/integration/samples/ActionHistory.java b/test/integration/samples/ActionHistory.java index 9d8d66bd..b3f9d5de 100644 --- a/test/integration/samples/ActionHistory.java +++ b/test/integration/samples/ActionHistory.java @@ -1,3 +1,8 @@ +// This Java code is taken from a public GitHub repository +// and is used inside Aibolit only for integration testing +// purposes. The code is never compiled or executed. + + /* * DBeaver - Universal Database Manager * Copyright (C) 2010-2020 DBeaver Corp and others diff --git a/test/integration/samples/AddActionPanel.java b/test/integration/samples/AddActionPanel.java index b3a8f443..b85d1a2c 100644 --- a/test/integration/samples/AddActionPanel.java +++ b/test/integration/samples/AddActionPanel.java @@ -1,3 +1,8 @@ +// This Java code is taken from a public GitHub repository +// and is used inside Aibolit only for integration testing +// purposes. The code is never compiled or executed. + + /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file diff --git a/test/integration/samples/AddFIActionPanel.java b/test/integration/samples/AddFIActionPanel.java index e8c93628..857256cc 100644 --- a/test/integration/samples/AddFIActionPanel.java +++ b/test/integration/samples/AddFIActionPanel.java @@ -1,3 +1,8 @@ +// This Java code is taken from a public GitHub repository +// and is used inside Aibolit only for integration testing +// purposes. The code is never compiled or executed. + + /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file diff --git a/test/integration/samples/AnnotationOffsetItem.java b/test/integration/samples/AnnotationOffsetItem.java index 2ae944dd..b3b0ca5e 100644 --- a/test/integration/samples/AnnotationOffsetItem.java +++ b/test/integration/samples/AnnotationOffsetItem.java @@ -1,3 +1,8 @@ +// This Java code is taken from a public GitHub repository +// and is used inside Aibolit only for integration testing +// purposes. The code is never compiled or executed. + + /* ### * IP: GHIDRA * diff --git a/test/integration/samples/AnnotationSetReferenceItem.java b/test/integration/samples/AnnotationSetReferenceItem.java index a6b20050..0fc24106 100644 --- a/test/integration/samples/AnnotationSetReferenceItem.java +++ b/test/integration/samples/AnnotationSetReferenceItem.java @@ -1,3 +1,8 @@ +// This Java code is taken from a public GitHub repository +// and is used inside Aibolit only for integration testing +// purposes. The code is never compiled or executed. + + /* ### * IP: GHIDRA * diff --git a/test/integration/samples/AnnotationsDirectoryItem.java b/test/integration/samples/AnnotationsDirectoryItem.java index 853c6b83..b059ed4f 100644 --- a/test/integration/samples/AnnotationsDirectoryItem.java +++ b/test/integration/samples/AnnotationsDirectoryItem.java @@ -1,3 +1,8 @@ +// This Java code is taken from a public GitHub repository +// and is used inside Aibolit only for integration testing +// purposes. The code is never compiled or executed. + + /* ### * IP: GHIDRA * diff --git a/test/integration/samples/Assertions.java b/test/integration/samples/Assertions.java index 8783101d..d5fb295c 100644 --- a/test/integration/samples/Assertions.java +++ b/test/integration/samples/Assertions.java @@ -1,3 +1,8 @@ +// This Java code is taken from a public GitHub repository +// and is used inside Aibolit only for integration testing +// purposes. The code is never compiled or executed. + + /* * Licensed to Elasticsearch under one or more contributor * license agreements. See the NOTICE file distributed with diff --git a/test/integration/samples/AttrProp.java b/test/integration/samples/AttrProp.java index d7e768a0..c343d6c2 100644 --- a/test/integration/samples/AttrProp.java +++ b/test/integration/samples/AttrProp.java @@ -1,3 +1,8 @@ +// This Java code is taken from a public GitHub repository +// and is used inside Aibolit only for integration testing +// purposes. The code is never compiled or executed. + + /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file diff --git a/test/integration/samples/BCFile.java b/test/integration/samples/BCFile.java index 43d82993..5c98ed71 100644 --- a/test/integration/samples/BCFile.java +++ b/test/integration/samples/BCFile.java @@ -1,3 +1,8 @@ +// This Java code is taken from a public GitHub repository +// and is used inside Aibolit only for integration testing +// purposes. The code is never compiled or executed. + + /** * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with this diff --git a/test/integration/samples/BaseKit.java b/test/integration/samples/BaseKit.java index cd1ba15c..d4ce54fc 100644 --- a/test/integration/samples/BaseKit.java +++ b/test/integration/samples/BaseKit.java @@ -1,3 +1,8 @@ +// This Java code is taken from a public GitHub repository +// and is used inside Aibolit only for integration testing +// purposes. The code is never compiled or executed. + + /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file diff --git a/test/integration/samples/BeanCodeManager.java b/test/integration/samples/BeanCodeManager.java index d60747ff..251f2708 100644 --- a/test/integration/samples/BeanCodeManager.java +++ b/test/integration/samples/BeanCodeManager.java @@ -1,3 +1,8 @@ +// This Java code is taken from a public GitHub repository +// and is used inside Aibolit only for integration testing +// purposes. The code is never compiled or executed. + + /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file diff --git a/test/integration/samples/BellmanFordAdjacencyMatrix.java b/test/integration/samples/BellmanFordAdjacencyMatrix.java index e14357a0..58882e5a 100644 --- a/test/integration/samples/BellmanFordAdjacencyMatrix.java +++ b/test/integration/samples/BellmanFordAdjacencyMatrix.java @@ -1,3 +1,8 @@ +// This Java code is taken from a public GitHub repository +// and is used inside Aibolit only for integration testing +// purposes. The code is never compiled or executed. + + /** * An implementation of the Bellman-Ford algorithm. The algorithm finds the shortest path between a * starting node and all other nodes in the graph. The algorithm also detects negative cycles. diff --git a/test/integration/samples/BiAnalyser.java b/test/integration/samples/BiAnalyser.java index 14a23347..c21d2cb6 100644 --- a/test/integration/samples/BiAnalyser.java +++ b/test/integration/samples/BiAnalyser.java @@ -1,3 +1,8 @@ +// This Java code is taken from a public GitHub repository +// and is used inside Aibolit only for integration testing +// purposes. The code is never compiled or executed. + + /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file diff --git a/test/integration/samples/BinaryHeap.java b/test/integration/samples/BinaryHeap.java index 750af44d..b8c25100 100644 --- a/test/integration/samples/BinaryHeap.java +++ b/test/integration/samples/BinaryHeap.java @@ -1,3 +1,8 @@ +// This Java code is taken from a public GitHub repository +// and is used inside Aibolit only for integration testing +// purposes. The code is never compiled or executed. + + /** * A min priority queue implementation using a binary heap. * diff --git a/test/integration/samples/BinaryHeapQuickRemovals.java b/test/integration/samples/BinaryHeapQuickRemovals.java index 3c914fd5..9bd8f233 100644 --- a/test/integration/samples/BinaryHeapQuickRemovals.java +++ b/test/integration/samples/BinaryHeapQuickRemovals.java @@ -1,3 +1,8 @@ +// This Java code is taken from a public GitHub repository +// and is used inside Aibolit only for integration testing +// purposes. The code is never compiled or executed. + + /** * A min priority queue implementation using a binary heap. This implementation tracks each element * inside the binary heap with a hashtable for quick removals. diff --git a/test/integration/samples/BlockReaderLocal.java b/test/integration/samples/BlockReaderLocal.java index 9c1ef461..54746812 100644 --- a/test/integration/samples/BlockReaderLocal.java +++ b/test/integration/samples/BlockReaderLocal.java @@ -1,3 +1,8 @@ +// This Java code is taken from a public GitHub repository +// and is used inside Aibolit only for integration testing +// purposes. The code is never compiled or executed. + + /** * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file diff --git a/test/integration/samples/BlockReaderLocalLegacy.java b/test/integration/samples/BlockReaderLocalLegacy.java index e48ace6c..f2918eba 100644 --- a/test/integration/samples/BlockReaderLocalLegacy.java +++ b/test/integration/samples/BlockReaderLocalLegacy.java @@ -1,3 +1,8 @@ +// This Java code is taken from a public GitHub repository +// and is used inside Aibolit only for integration testing +// purposes. The code is never compiled or executed. + + /** * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file diff --git a/test/integration/samples/BreakpointsTreeModel.java b/test/integration/samples/BreakpointsTreeModel.java index d1c71288..2d2b5fd9 100644 --- a/test/integration/samples/BreakpointsTreeModel.java +++ b/test/integration/samples/BreakpointsTreeModel.java @@ -1,3 +1,8 @@ +// This Java code is taken from a public GitHub repository +// and is used inside Aibolit only for integration testing +// purposes. The code is never compiled or executed. + + /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file diff --git a/test/integration/samples/ChainedBuffer.java b/test/integration/samples/ChainedBuffer.java index 8fc65bf0..6de95cbc 100644 --- a/test/integration/samples/ChainedBuffer.java +++ b/test/integration/samples/ChainedBuffer.java @@ -1,3 +1,8 @@ +// This Java code is taken from a public GitHub repository +// and is used inside Aibolit only for integration testing +// purposes. The code is never compiled or executed. + + /* ### * IP: GHIDRA * diff --git a/test/integration/samples/ChatEndpoint.java b/test/integration/samples/ChatEndpoint.java index c4e20f4b..acf2e476 100644 --- a/test/integration/samples/ChatEndpoint.java +++ b/test/integration/samples/ChatEndpoint.java @@ -1,3 +1,8 @@ +// This Java code is taken from a public GitHub repository +// and is used inside Aibolit only for integration testing +// purposes. The code is never compiled or executed. + + package com.baeldung.websocket; import java.io.IOException; diff --git a/test/integration/samples/ClassDefItem.java b/test/integration/samples/ClassDefItem.java index e5c38e8a..cc519bcf 100644 --- a/test/integration/samples/ClassDefItem.java +++ b/test/integration/samples/ClassDefItem.java @@ -1,3 +1,8 @@ +// This Java code is taken from a public GitHub repository +// and is used inside Aibolit only for integration testing +// purposes. The code is never compiled or executed. + + /* ### * IP: GHIDRA * diff --git a/test/integration/samples/CleanupQueue.java b/test/integration/samples/CleanupQueue.java index a40a40ad..3e63c2b1 100644 --- a/test/integration/samples/CleanupQueue.java +++ b/test/integration/samples/CleanupQueue.java @@ -1,3 +1,8 @@ +// This Java code is taken from a public GitHub repository +// and is used inside Aibolit only for integration testing +// purposes. The code is never compiled or executed. + + /** * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file diff --git a/test/integration/samples/ClipboardHandler.java b/test/integration/samples/ClipboardHandler.java index 78def107..f7b9e73e 100644 --- a/test/integration/samples/ClipboardHandler.java +++ b/test/integration/samples/ClipboardHandler.java @@ -1,3 +1,8 @@ +// This Java code is taken from a public GitHub repository +// and is used inside Aibolit only for integration testing +// purposes. The code is never compiled or executed. + + /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file diff --git a/test/integration/samples/ClusterSizeMonitor.java b/test/integration/samples/ClusterSizeMonitor.java index 83bcb446..3d695b66 100644 --- a/test/integration/samples/ClusterSizeMonitor.java +++ b/test/integration/samples/ClusterSizeMonitor.java @@ -1,3 +1,8 @@ +// This Java code is taken from a public GitHub repository +// and is used inside Aibolit only for integration testing +// purposes. The code is never compiled or executed. + + /* * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/test/integration/samples/CodeItem.java b/test/integration/samples/CodeItem.java index 0f75f22b..86f787a2 100644 --- a/test/integration/samples/CodeItem.java +++ b/test/integration/samples/CodeItem.java @@ -1,3 +1,8 @@ +// This Java code is taken from a public GitHub repository +// and is used inside Aibolit only for integration testing +// purposes. The code is never compiled or executed. + + /* ### * IP: GHIDRA * diff --git a/test/integration/samples/CompactMap.java b/test/integration/samples/CompactMap.java index 4a6f17d6..6e1648bf 100644 --- a/test/integration/samples/CompactMap.java +++ b/test/integration/samples/CompactMap.java @@ -1,3 +1,8 @@ +// This Java code is taken from a public GitHub repository +// and is used inside Aibolit only for integration testing +// purposes. The code is never compiled or executed. + + /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file diff --git a/test/integration/samples/CompactSegmentTree.java b/test/integration/samples/CompactSegmentTree.java index d7352d86..7a286b00 100644 --- a/test/integration/samples/CompactSegmentTree.java +++ b/test/integration/samples/CompactSegmentTree.java @@ -1,3 +1,8 @@ +// This Java code is taken from a public GitHub repository +// and is used inside Aibolit only for integration testing +// purposes. The code is never compiled or executed. + + /** * A compact array based segment tree implementation. This segment tree supports point updates and * range queries. diff --git a/test/integration/samples/ConditionalExpressionCheck.java b/test/integration/samples/ConditionalExpressionCheck.java index 451a1af2..46a9c118 100644 --- a/test/integration/samples/ConditionalExpressionCheck.java +++ b/test/integration/samples/ConditionalExpressionCheck.java @@ -1,3 +1,8 @@ +// This Java code is taken from a public GitHub repository +// and is used inside Aibolit only for integration testing +// purposes. The code is never compiled or executed. + + package com.huawei.codecheck.customchecks; import com.puppycrawl.tools.checkstyle.api.AbstractCheck; diff --git a/test/integration/samples/Configuration.java b/test/integration/samples/Configuration.java index 5119f648..f8966bd5 100644 --- a/test/integration/samples/Configuration.java +++ b/test/integration/samples/Configuration.java @@ -1,3 +1,8 @@ +// This Java code is taken from a public GitHub repository +// and is used inside Aibolit only for integration testing +// purposes. The code is never compiled or executed. + + /** * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file diff --git a/test/integration/samples/ConsoleImpl.java b/test/integration/samples/ConsoleImpl.java index 65537a69..a4bf82b4 100644 --- a/test/integration/samples/ConsoleImpl.java +++ b/test/integration/samples/ConsoleImpl.java @@ -1,3 +1,8 @@ +// This Java code is taken from a public GitHub repository +// and is used inside Aibolit only for integration testing +// purposes. The code is never compiled or executed. + + package com.stardust.autojs.core.console; import android.content.Context; diff --git a/test/integration/samples/ConsumerImpl.java b/test/integration/samples/ConsumerImpl.java index 33f05192..6d73ad6c 100644 --- a/test/integration/samples/ConsumerImpl.java +++ b/test/integration/samples/ConsumerImpl.java @@ -1,3 +1,8 @@ +// This Java code is taken from a public GitHub repository +// and is used inside Aibolit only for integration testing +// purposes. The code is never compiled or executed. + + /** * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file diff --git a/test/integration/samples/DBHandle.java b/test/integration/samples/DBHandle.java index a99a3a43..7465e917 100644 --- a/test/integration/samples/DBHandle.java +++ b/test/integration/samples/DBHandle.java @@ -1,3 +1,8 @@ +// This Java code is taken from a public GitHub repository +// and is used inside Aibolit only for integration testing +// purposes. The code is never compiled or executed. + + /* ### * IP: GHIDRA * diff --git a/test/integration/samples/DBParms.java b/test/integration/samples/DBParms.java index 6fe402be..002ec2da 100644 --- a/test/integration/samples/DBParms.java +++ b/test/integration/samples/DBParms.java @@ -1,3 +1,8 @@ +// This Java code is taken from a public GitHub repository +// and is used inside Aibolit only for integration testing +// purposes. The code is never compiled or executed. + + /* ### * IP: GHIDRA * REVIEWED: YES diff --git a/test/integration/samples/DDParser.java b/test/integration/samples/DDParser.java index b0474922..02f7e937 100644 --- a/test/integration/samples/DDParser.java +++ b/test/integration/samples/DDParser.java @@ -1,3 +1,8 @@ +// This Java code is taken from a public GitHub repository +// and is used inside Aibolit only for integration testing +// purposes. The code is never compiled or executed. + + /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file diff --git a/test/integration/samples/DataTypeArchiveDB.java b/test/integration/samples/DataTypeArchiveDB.java index 1d9acbbe..3cddc492 100644 --- a/test/integration/samples/DataTypeArchiveDB.java +++ b/test/integration/samples/DataTypeArchiveDB.java @@ -1,3 +1,8 @@ +// This Java code is taken from a public GitHub repository +// and is used inside Aibolit only for integration testing +// purposes. The code is never compiled or executed. + + /* ### * IP: GHIDRA * diff --git a/test/integration/samples/DeadlockExample.java b/test/integration/samples/DeadlockExample.java index b7b65d11..78d056c1 100644 --- a/test/integration/samples/DeadlockExample.java +++ b/test/integration/samples/DeadlockExample.java @@ -1,3 +1,8 @@ +// This Java code is taken from a public GitHub repository +// and is used inside Aibolit only for integration testing +// purposes. The code is never compiled or executed. + + package com.baeldung.commonissues; public class DeadlockExample { diff --git a/test/integration/samples/DecompileDebug.java b/test/integration/samples/DecompileDebug.java index a19dccd5..c1ce8af0 100644 --- a/test/integration/samples/DecompileDebug.java +++ b/test/integration/samples/DecompileDebug.java @@ -1,3 +1,8 @@ +// This Java code is taken from a public GitHub repository +// and is used inside Aibolit only for integration testing +// purposes. The code is never compiled or executed. + + /* ### * IP: GHIDRA * diff --git a/test/integration/samples/DefaultEMLookup.java b/test/integration/samples/DefaultEMLookup.java index b569b432..7b95648b 100644 --- a/test/integration/samples/DefaultEMLookup.java +++ b/test/integration/samples/DefaultEMLookup.java @@ -1,3 +1,8 @@ +// This Java code is taken from a public GitHub repository +// and is used inside Aibolit only for integration testing +// purposes. The code is never compiled or executed. + + /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file diff --git a/test/integration/samples/DefaultProject.java b/test/integration/samples/DefaultProject.java index 6e53c4e8..feb3c370 100644 --- a/test/integration/samples/DefaultProject.java +++ b/test/integration/samples/DefaultProject.java @@ -1,3 +1,8 @@ +// This Java code is taken from a public GitHub repository +// and is used inside Aibolit only for integration testing +// purposes. The code is never compiled or executed. + + /* ### * IP: GHIDRA * diff --git a/test/integration/samples/DependencyGraph.java b/test/integration/samples/DependencyGraph.java index c58582f8..ad6d8141 100644 --- a/test/integration/samples/DependencyGraph.java +++ b/test/integration/samples/DependencyGraph.java @@ -1,3 +1,8 @@ +// This Java code is taken from a public GitHub repository +// and is used inside Aibolit only for integration testing +// purposes. The code is never compiled or executed. + + /* ### * IP: GHIDRA * diff --git a/test/integration/samples/DeterministicDependencyGraph.java b/test/integration/samples/DeterministicDependencyGraph.java index 523d084e..62ca1199 100644 --- a/test/integration/samples/DeterministicDependencyGraph.java +++ b/test/integration/samples/DeterministicDependencyGraph.java @@ -1,3 +1,8 @@ +// This Java code is taken from a public GitHub repository +// and is used inside Aibolit only for integration testing +// purposes. The code is never compiled or executed. + + /* ### * IP: GHIDRA * diff --git a/test/integration/samples/DriverYieldSignal.java b/test/integration/samples/DriverYieldSignal.java index 45d17815..10799cb8 100644 --- a/test/integration/samples/DriverYieldSignal.java +++ b/test/integration/samples/DriverYieldSignal.java @@ -1,3 +1,8 @@ +// This Java code is taken from a public GitHub repository +// and is used inside Aibolit only for integration testing +// purposes. The code is never compiled or executed. + + /* * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/test/integration/samples/EncodedMethod.java b/test/integration/samples/EncodedMethod.java index d4abcd49..4b4b1a45 100644 --- a/test/integration/samples/EncodedMethod.java +++ b/test/integration/samples/EncodedMethod.java @@ -1,3 +1,8 @@ +// This Java code is taken from a public GitHub repository +// and is used inside Aibolit only for integration testing +// purposes. The code is never compiled or executed. + + /* ### * IP: GHIDRA * diff --git a/test/integration/samples/Environment.java b/test/integration/samples/Environment.java index bc92b714..b0ac6ba8 100644 --- a/test/integration/samples/Environment.java +++ b/test/integration/samples/Environment.java @@ -1,3 +1,8 @@ +// This Java code is taken from a public GitHub repository +// and is used inside Aibolit only for integration testing +// purposes. The code is never compiled or executed. + + /** * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file diff --git a/test/integration/samples/EpollEventLoop.java b/test/integration/samples/EpollEventLoop.java index 526276cc..e9c674e0 100644 --- a/test/integration/samples/EpollEventLoop.java +++ b/test/integration/samples/EpollEventLoop.java @@ -1,3 +1,8 @@ +// This Java code is taken from a public GitHub repository +// and is used inside Aibolit only for integration testing +// purposes. The code is never compiled or executed. + + /* * Copyright 2014 The Netty Project * diff --git a/test/integration/samples/ExceptionDemo.java b/test/integration/samples/ExceptionDemo.java index 7b4bdf46..979f4d53 100644 --- a/test/integration/samples/ExceptionDemo.java +++ b/test/integration/samples/ExceptionDemo.java @@ -1,3 +1,8 @@ +// This Java code is taken from a public GitHub repository +// and is used inside Aibolit only for integration testing +// purposes. The code is never compiled or executed. + + package cn.itcast_02; /* diff --git a/test/integration/samples/FieldAnnotation.java b/test/integration/samples/FieldAnnotation.java index 0832429e..c38cd535 100644 --- a/test/integration/samples/FieldAnnotation.java +++ b/test/integration/samples/FieldAnnotation.java @@ -1,3 +1,8 @@ +// This Java code is taken from a public GitHub repository +// and is used inside Aibolit only for integration testing +// purposes. The code is never compiled or executed. + + /* ### * IP: GHIDRA * diff --git a/test/integration/samples/FoldViewFactory.java b/test/integration/samples/FoldViewFactory.java index 1c91044c..0b139d2d 100644 --- a/test/integration/samples/FoldViewFactory.java +++ b/test/integration/samples/FoldViewFactory.java @@ -1,3 +1,8 @@ +// This Java code is taken from a public GitHub repository +// and is used inside Aibolit only for integration testing +// purposes. The code is never compiled or executed. + + /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file diff --git a/test/integration/samples/FutureStateChange.java b/test/integration/samples/FutureStateChange.java index 1a3a3d75..d5e08cac 100644 --- a/test/integration/samples/FutureStateChange.java +++ b/test/integration/samples/FutureStateChange.java @@ -1,3 +1,8 @@ +// This Java code is taken from a public GitHub repository +// and is used inside Aibolit only for integration testing +// purposes. The code is never compiled or executed. + + /* * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/test/integration/samples/GeneticAlgorithm_travelingSalesman.java b/test/integration/samples/GeneticAlgorithm_travelingSalesman.java index 6923cd61..11b77ecd 100644 --- a/test/integration/samples/GeneticAlgorithm_travelingSalesman.java +++ b/test/integration/samples/GeneticAlgorithm_travelingSalesman.java @@ -1,3 +1,8 @@ +// This Java code is taken from a public GitHub repository +// and is used inside Aibolit only for integration testing +// purposes. The code is never compiled or executed. + + /** * An implementation of the TSP problem using a genetic algorithm. This implementation works well * for graph with < 30 nodes, beyond this it seems to struggle getting near the optimal solution. diff --git a/test/integration/samples/HyperlinkEnv.java b/test/integration/samples/HyperlinkEnv.java index e676faec..bca3029e 100644 --- a/test/integration/samples/HyperlinkEnv.java +++ b/test/integration/samples/HyperlinkEnv.java @@ -1,3 +1,8 @@ +// This Java code is taken from a public GitHub repository +// and is used inside Aibolit only for integration testing +// purposes. The code is never compiled or executed. + + /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file diff --git a/test/integration/samples/IconListPreference.java b/test/integration/samples/IconListPreference.java index 78b83252..7601f12c 100644 --- a/test/integration/samples/IconListPreference.java +++ b/test/integration/samples/IconListPreference.java @@ -1,3 +1,8 @@ +// This Java code is taken from a public GitHub repository +// and is used inside Aibolit only for integration testing +// purposes. The code is never compiled or executed. + + package com.kunfei.bookshelf.widget.prefs; import android.annotation.SuppressLint; diff --git a/test/integration/samples/IndexedLocalFileSystem.java b/test/integration/samples/IndexedLocalFileSystem.java index 8aa03203..3014f770 100644 --- a/test/integration/samples/IndexedLocalFileSystem.java +++ b/test/integration/samples/IndexedLocalFileSystem.java @@ -1,3 +1,8 @@ +// This Java code is taken from a public GitHub repository +// and is used inside Aibolit only for integration testing +// purposes. The code is never compiled or executed. + + /* ### * IP: GHIDRA * diff --git a/test/integration/samples/IndicesClusterStateService.java b/test/integration/samples/IndicesClusterStateService.java index 754635b1..0752e3ec 100644 --- a/test/integration/samples/IndicesClusterStateService.java +++ b/test/integration/samples/IndicesClusterStateService.java @@ -1,3 +1,8 @@ +// This Java code is taken from a public GitHub repository +// and is used inside Aibolit only for integration testing +// purposes. The code is never compiled or executed. + + /* * Licensed to Elasticsearch under one or more contributor * license agreements. See the NOTICE file distributed with diff --git a/test/integration/samples/IntKeyMap.java b/test/integration/samples/IntKeyMap.java index 6847a376..3a8551f4 100644 --- a/test/integration/samples/IntKeyMap.java +++ b/test/integration/samples/IntKeyMap.java @@ -1,3 +1,8 @@ +// This Java code is taken from a public GitHub repository +// and is used inside Aibolit only for integration testing +// purposes. The code is never compiled or executed. + + /* * DBeaver - Universal Database Manager * Copyright (C) 2010-2020 DBeaver Corp and others diff --git a/test/integration/samples/InternalEngine.java b/test/integration/samples/InternalEngine.java index c73ecbc8..2094b880 100644 --- a/test/integration/samples/InternalEngine.java +++ b/test/integration/samples/InternalEngine.java @@ -1,3 +1,8 @@ +// This Java code is taken from a public GitHub repository +// and is used inside Aibolit only for integration testing +// purposes. The code is never compiled or executed. + + /* * Licensed to Elasticsearch under one or more contributor * license agreements. See the NOTICE file distributed with diff --git a/test/integration/samples/InterpDtTerm.java b/test/integration/samples/InterpDtTerm.java index 988781dd..c895b3b6 100644 --- a/test/integration/samples/InterpDtTerm.java +++ b/test/integration/samples/InterpDtTerm.java @@ -1,3 +1,8 @@ +// This Java code is taken from a public GitHub repository +// and is used inside Aibolit only for integration testing +// purposes. The code is never compiled or executed. + + /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file diff --git a/test/integration/samples/InterpProtoANSI.java b/test/integration/samples/InterpProtoANSI.java index 37579e72..1e105ee5 100644 --- a/test/integration/samples/InterpProtoANSI.java +++ b/test/integration/samples/InterpProtoANSI.java @@ -1,3 +1,8 @@ +// This Java code is taken from a public GitHub repository +// and is used inside Aibolit only for integration testing +// purposes. The code is never compiled or executed. + + /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file diff --git a/test/integration/samples/InterpProtoANSIX.java b/test/integration/samples/InterpProtoANSIX.java index 38098079..af8d5643 100644 --- a/test/integration/samples/InterpProtoANSIX.java +++ b/test/integration/samples/InterpProtoANSIX.java @@ -1,3 +1,8 @@ +// This Java code is taken from a public GitHub repository +// and is used inside Aibolit only for integration testing +// purposes. The code is never compiled or executed. + + /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file diff --git a/test/integration/samples/InterpXTerm.java b/test/integration/samples/InterpXTerm.java index ef442394..ee22c6d5 100644 --- a/test/integration/samples/InterpXTerm.java +++ b/test/integration/samples/InterpXTerm.java @@ -1,3 +1,8 @@ +// This Java code is taken from a public GitHub repository +// and is used inside Aibolit only for integration testing +// purposes. The code is never compiled or executed. + + /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file diff --git a/test/integration/samples/JShellEnvironment.java b/test/integration/samples/JShellEnvironment.java index 2a3bc153..666c5e0d 100644 --- a/test/integration/samples/JShellEnvironment.java +++ b/test/integration/samples/JShellEnvironment.java @@ -1,3 +1,8 @@ +// This Java code is taken from a public GitHub repository +// and is used inside Aibolit only for integration testing +// purposes. The code is never compiled or executed. + + /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file diff --git a/test/integration/samples/JavaTargetChooserPanelGUI.java b/test/integration/samples/JavaTargetChooserPanelGUI.java index a99fffd6..1753389d 100644 --- a/test/integration/samples/JavaTargetChooserPanelGUI.java +++ b/test/integration/samples/JavaTargetChooserPanelGUI.java @@ -1,3 +1,8 @@ +// This Java code is taken from a public GitHub repository +// and is used inside Aibolit only for integration testing +// purposes. The code is never compiled or executed. + + /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file diff --git a/test/integration/samples/JdbcResultsSnapshot.java b/test/integration/samples/JdbcResultsSnapshot.java index ff5fea87..3ae5bd8f 100644 --- a/test/integration/samples/JdbcResultsSnapshot.java +++ b/test/integration/samples/JdbcResultsSnapshot.java @@ -1,3 +1,8 @@ +// This Java code is taken from a public GitHub repository +// and is used inside Aibolit only for integration testing +// purposes. The code is never compiled or executed. + + /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file diff --git a/test/integration/samples/KeyStrokeEditor.java b/test/integration/samples/KeyStrokeEditor.java index 2c846576..da11b202 100644 --- a/test/integration/samples/KeyStrokeEditor.java +++ b/test/integration/samples/KeyStrokeEditor.java @@ -1,3 +1,8 @@ +// This Java code is taken from a public GitHub repository +// and is used inside Aibolit only for integration testing +// purposes. The code is never compiled or executed. + + /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file diff --git a/test/integration/samples/LSPBindings.java b/test/integration/samples/LSPBindings.java index c45b117c..c0bc97ce 100644 --- a/test/integration/samples/LSPBindings.java +++ b/test/integration/samples/LSPBindings.java @@ -1,3 +1,8 @@ +// This Java code is taken from a public GitHub repository +// and is used inside Aibolit only for integration testing +// purposes. The code is never compiled or executed. + + /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file diff --git a/test/integration/samples/LiveMemoryViewUpdater.java b/test/integration/samples/LiveMemoryViewUpdater.java index 46ed6f66..734dc34b 100644 --- a/test/integration/samples/LiveMemoryViewUpdater.java +++ b/test/integration/samples/LiveMemoryViewUpdater.java @@ -1,3 +1,8 @@ +// This Java code is taken from a public GitHub repository +// and is used inside Aibolit only for integration testing +// purposes. The code is never compiled or executed. + + /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file diff --git a/test/integration/samples/LoaderInfoHeader.java b/test/integration/samples/LoaderInfoHeader.java index f2553cd3..11e30590 100644 --- a/test/integration/samples/LoaderInfoHeader.java +++ b/test/integration/samples/LoaderInfoHeader.java @@ -1,3 +1,8 @@ +// This Java code is taken from a public GitHub repository +// and is used inside Aibolit only for integration testing +// purposes. The code is never compiled or executed. + + /* ### * IP: GHIDRA * diff --git a/test/integration/samples/LoaderRelocationHeader.java b/test/integration/samples/LoaderRelocationHeader.java index f6f5d5d2..ca19de79 100644 --- a/test/integration/samples/LoaderRelocationHeader.java +++ b/test/integration/samples/LoaderRelocationHeader.java @@ -1,3 +1,8 @@ +// This Java code is taken from a public GitHub repository +// and is used inside Aibolit only for integration testing +// purposes. The code is never compiled or executed. + + /* ### * IP: GHIDRA * diff --git a/test/integration/samples/LocalDataFile.java b/test/integration/samples/LocalDataFile.java index 7778c9f8..01b5ef08 100644 --- a/test/integration/samples/LocalDataFile.java +++ b/test/integration/samples/LocalDataFile.java @@ -1,3 +1,8 @@ +// This Java code is taken from a public GitHub repository +// and is used inside Aibolit only for integration testing +// purposes. The code is never compiled or executed. + + /* ### * IP: GHIDRA * diff --git a/test/integration/samples/LocalDatabaseItem.java b/test/integration/samples/LocalDatabaseItem.java index d8c52883..d31d8684 100644 --- a/test/integration/samples/LocalDatabaseItem.java +++ b/test/integration/samples/LocalDatabaseItem.java @@ -1,3 +1,8 @@ +// This Java code is taken from a public GitHub repository +// and is used inside Aibolit only for integration testing +// purposes. The code is never compiled or executed. + + /* ### * IP: GHIDRA * diff --git a/test/integration/samples/LocalJobRunner.java b/test/integration/samples/LocalJobRunner.java index 0f1d759c..42c9d475 100644 --- a/test/integration/samples/LocalJobRunner.java +++ b/test/integration/samples/LocalJobRunner.java @@ -1,3 +1,8 @@ +// This Java code is taken from a public GitHub repository +// and is used inside Aibolit only for integration testing +// purposes. The code is never compiled or executed. + + /** * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file diff --git a/test/integration/samples/LocalShardSnapshot.java b/test/integration/samples/LocalShardSnapshot.java index cc9ac40c..6241714c 100644 --- a/test/integration/samples/LocalShardSnapshot.java +++ b/test/integration/samples/LocalShardSnapshot.java @@ -1,3 +1,8 @@ +// This Java code is taken from a public GitHub repository +// and is used inside Aibolit only for integration testing +// purposes. The code is never compiled or executed. + + /* * Licensed to Elasticsearch under one or more contributor * license agreements. See the NOTICE file distributed with diff --git a/test/integration/samples/LocalizedBundleInfo.java b/test/integration/samples/LocalizedBundleInfo.java index dcd71072..6035d6eb 100644 --- a/test/integration/samples/LocalizedBundleInfo.java +++ b/test/integration/samples/LocalizedBundleInfo.java @@ -1,3 +1,8 @@ +// This Java code is taken from a public GitHub repository +// and is used inside Aibolit only for integration testing +// purposes. The code is never compiled or executed. + + /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file diff --git a/test/integration/samples/LongKeyMap.java b/test/integration/samples/LongKeyMap.java index 3c64c2c4..a7627c00 100644 --- a/test/integration/samples/LongKeyMap.java +++ b/test/integration/samples/LongKeyMap.java @@ -1,3 +1,8 @@ +// This Java code is taken from a public GitHub repository +// and is used inside Aibolit only for integration testing +// purposes. The code is never compiled or executed. + + /* * DBeaver - Universal Database Manager * Copyright (C) 2010-2020 DBeaver Corp and others diff --git a/test/integration/samples/LongestCommonSubstring.java b/test/integration/samples/LongestCommonSubstring.java index f0718493..4cbe9c29 100644 --- a/test/integration/samples/LongestCommonSubstring.java +++ b/test/integration/samples/LongestCommonSubstring.java @@ -1,3 +1,8 @@ +// This Java code is taken from a public GitHub repository +// and is used inside Aibolit only for integration testing +// purposes. The code is never compiled or executed. + + /** * An implementation of the k Longest Common Substring problem. * diff --git a/test/integration/samples/LottieImageAsset.java b/test/integration/samples/LottieImageAsset.java index 2c8f1d0b..7aff55ff 100644 --- a/test/integration/samples/LottieImageAsset.java +++ b/test/integration/samples/LottieImageAsset.java @@ -1,3 +1,8 @@ +// This Java code is taken from a public GitHub repository +// and is used inside Aibolit only for integration testing +// purposes. The code is never compiled or executed. + + package com.airbnb.lottie; import android.graphics.Bitmap; diff --git a/test/integration/samples/MessageDeduplication.java b/test/integration/samples/MessageDeduplication.java index dc4604e8..2de7b22c 100644 --- a/test/integration/samples/MessageDeduplication.java +++ b/test/integration/samples/MessageDeduplication.java @@ -1,3 +1,8 @@ +// This Java code is taken from a public GitHub repository +// and is used inside Aibolit only for integration testing +// purposes. The code is never compiled or executed. + + /** * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file diff --git a/test/integration/samples/MethodAnnotation.java b/test/integration/samples/MethodAnnotation.java index 2679e34d..180cdb00 100644 --- a/test/integration/samples/MethodAnnotation.java +++ b/test/integration/samples/MethodAnnotation.java @@ -1,3 +1,8 @@ +// This Java code is taken from a public GitHub repository +// and is used inside Aibolit only for integration testing +// purposes. The code is never compiled or executed. + + /* ### * IP: GHIDRA * diff --git a/test/integration/samples/MethodsFeatureModes.java b/test/integration/samples/MethodsFeatureModes.java index 117c3b09..6fe996db 100644 --- a/test/integration/samples/MethodsFeatureModes.java +++ b/test/integration/samples/MethodsFeatureModes.java @@ -1,3 +1,8 @@ +// This Java code is taken from a public GitHub repository +// and is used inside Aibolit only for integration testing +// purposes. The code is never compiled or executed. + + /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file diff --git a/test/integration/samples/MfLexer.java b/test/integration/samples/MfLexer.java index d053cc2a..d02f10a7 100644 --- a/test/integration/samples/MfLexer.java +++ b/test/integration/samples/MfLexer.java @@ -1,3 +1,8 @@ +// This Java code is taken from a public GitHub repository +// and is used inside Aibolit only for integration testing +// purposes. The code is never compiled or executed. + + /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file diff --git a/test/integration/samples/ModifierEditor.java b/test/integration/samples/ModifierEditor.java index c473da3c..ef0398f3 100644 --- a/test/integration/samples/ModifierEditor.java +++ b/test/integration/samples/ModifierEditor.java @@ -1,3 +1,8 @@ +// This Java code is taken from a public GitHub repository +// and is used inside Aibolit only for integration testing +// purposes. The code is never compiled or executed. + + /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file diff --git a/test/integration/samples/ModuleClassPaths.java b/test/integration/samples/ModuleClassPaths.java index 65a27972..10fa3f65 100644 --- a/test/integration/samples/ModuleClassPaths.java +++ b/test/integration/samples/ModuleClassPaths.java @@ -1,3 +1,8 @@ +// This Java code is taken from a public GitHub repository +// and is used inside Aibolit only for integration testing +// purposes. The code is never compiled or executed. + + /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file diff --git a/test/integration/samples/ModuleConfigurationImpl.java b/test/integration/samples/ModuleConfigurationImpl.java index ef29a9dc..f6f033cf 100644 --- a/test/integration/samples/ModuleConfigurationImpl.java +++ b/test/integration/samples/ModuleConfigurationImpl.java @@ -1,3 +1,8 @@ +// This Java code is taken from a public GitHub repository +// and is used inside Aibolit only for integration testing +// purposes. The code is never compiled or executed. + + /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file diff --git a/test/integration/samples/ModuleRoots.java b/test/integration/samples/ModuleRoots.java index 2c1a2ad5..308ef589 100644 --- a/test/integration/samples/ModuleRoots.java +++ b/test/integration/samples/ModuleRoots.java @@ -1,3 +1,8 @@ +// This Java code is taken from a public GitHub repository +// and is used inside Aibolit only for integration testing +// purposes. The code is never compiled or executed. + + /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file diff --git a/test/integration/samples/ModuleTargetChooserPanelGUI.java b/test/integration/samples/ModuleTargetChooserPanelGUI.java index 546c00b2..bc089fec 100644 --- a/test/integration/samples/ModuleTargetChooserPanelGUI.java +++ b/test/integration/samples/ModuleTargetChooserPanelGUI.java @@ -1,3 +1,8 @@ +// This Java code is taken from a public GitHub repository +// and is used inside Aibolit only for integration testing +// purposes. The code is never compiled or executed. + + /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file diff --git a/test/integration/samples/MultiModuleClassPathProvider.java b/test/integration/samples/MultiModuleClassPathProvider.java index b77746c5..7cd47c47 100644 --- a/test/integration/samples/MultiModuleClassPathProvider.java +++ b/test/integration/samples/MultiModuleClassPathProvider.java @@ -1,3 +1,8 @@ +// This Java code is taken from a public GitHub repository +// and is used inside Aibolit only for integration testing +// purposes. The code is never compiled or executed. + + /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file diff --git a/test/integration/samples/NBClassReader.java b/test/integration/samples/NBClassReader.java index 062412f3..1a59c3aa 100644 --- a/test/integration/samples/NBClassReader.java +++ b/test/integration/samples/NBClassReader.java @@ -1,3 +1,8 @@ +// This Java code is taken from a public GitHub repository +// and is used inside Aibolit only for integration testing +// purposes. The code is never compiled or executed. + + /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file diff --git a/test/integration/samples/NativeRSRawDecoder.java b/test/integration/samples/NativeRSRawDecoder.java index dc2c33a6..abdf5ddf 100644 --- a/test/integration/samples/NativeRSRawDecoder.java +++ b/test/integration/samples/NativeRSRawDecoder.java @@ -1,3 +1,8 @@ +// This Java code is taken from a public GitHub repository +// and is used inside Aibolit only for integration testing +// purposes. The code is never compiled or executed. + + /** * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file diff --git a/test/integration/samples/NativeRSRawEncoder.java b/test/integration/samples/NativeRSRawEncoder.java index ad06927f..7fd05424 100644 --- a/test/integration/samples/NativeRSRawEncoder.java +++ b/test/integration/samples/NativeRSRawEncoder.java @@ -1,3 +1,8 @@ +// This Java code is taken from a public GitHub repository +// and is used inside Aibolit only for integration testing +// purposes. The code is never compiled or executed. + + /** * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file diff --git a/test/integration/samples/NativeXORRawDecoder.java b/test/integration/samples/NativeXORRawDecoder.java index dd708eb5..30ca0779 100644 --- a/test/integration/samples/NativeXORRawDecoder.java +++ b/test/integration/samples/NativeXORRawDecoder.java @@ -1,3 +1,8 @@ +// This Java code is taken from a public GitHub repository +// and is used inside Aibolit only for integration testing +// purposes. The code is never compiled or executed. + + /** * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file diff --git a/test/integration/samples/NativeXORRawEncoder.java b/test/integration/samples/NativeXORRawEncoder.java index 66b0a1bf..5fa6bfa1 100644 --- a/test/integration/samples/NativeXORRawEncoder.java +++ b/test/integration/samples/NativeXORRawEncoder.java @@ -1,3 +1,8 @@ +// This Java code is taken from a public GitHub repository +// and is used inside Aibolit only for integration testing +// purposes. The code is never compiled or executed. + + /** * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file diff --git a/test/integration/samples/NodesReloadSecureSettingsRequest.java b/test/integration/samples/NodesReloadSecureSettingsRequest.java index 7796fba5..954ca3cc 100644 --- a/test/integration/samples/NodesReloadSecureSettingsRequest.java +++ b/test/integration/samples/NodesReloadSecureSettingsRequest.java @@ -1,3 +1,8 @@ +// This Java code is taken from a public GitHub repository +// and is used inside Aibolit only for integration testing +// purposes. The code is never compiled or executed. + + /* * Licensed to Elasticsearch under one or more contributor * license agreements. See the NOTICE file distributed with diff --git a/test/integration/samples/NonPersistentSubscription.java b/test/integration/samples/NonPersistentSubscription.java index 65204200..4fd25b0e 100644 --- a/test/integration/samples/NonPersistentSubscription.java +++ b/test/integration/samples/NonPersistentSubscription.java @@ -1,3 +1,8 @@ +// This Java code is taken from a public GitHub repository +// and is used inside Aibolit only for integration testing +// purposes. The code is never compiled or executed. + + /** * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file diff --git a/test/integration/samples/OpenSslClientContext.java b/test/integration/samples/OpenSslClientContext.java index 7f9b39a8..206376cb 100644 --- a/test/integration/samples/OpenSslClientContext.java +++ b/test/integration/samples/OpenSslClientContext.java @@ -1,3 +1,8 @@ +// This Java code is taken from a public GitHub repository +// and is used inside Aibolit only for integration testing +// purposes. The code is never compiled or executed. + + /* * Copyright 2014 The Netty Project * diff --git a/test/integration/samples/OpenSslServerContext.java b/test/integration/samples/OpenSslServerContext.java index da342de0..dbedcefc 100644 --- a/test/integration/samples/OpenSslServerContext.java +++ b/test/integration/samples/OpenSslServerContext.java @@ -1,3 +1,8 @@ +// This Java code is taken from a public GitHub repository +// and is used inside Aibolit only for integration testing +// purposes. The code is never compiled or executed. + + /* * Copyright 2014 The Netty Project * diff --git a/test/integration/samples/OpenSslX509KeyManagerFactory.java b/test/integration/samples/OpenSslX509KeyManagerFactory.java index 2a86332f..b6d4b15c 100644 --- a/test/integration/samples/OpenSslX509KeyManagerFactory.java +++ b/test/integration/samples/OpenSslX509KeyManagerFactory.java @@ -1,3 +1,8 @@ +// This Java code is taken from a public GitHub repository +// and is used inside Aibolit only for integration testing +// purposes. The code is never compiled or executed. + + /* * Copyright 2018 The Netty Project * diff --git a/test/integration/samples/OrPattern.java b/test/integration/samples/OrPattern.java index 01c3a3de..fe5e5d1e 100644 --- a/test/integration/samples/OrPattern.java +++ b/test/integration/samples/OrPattern.java @@ -1,3 +1,8 @@ +// This Java code is taken from a public GitHub repository +// and is used inside Aibolit only for integration testing +// purposes. The code is never compiled or executed. + + /* ### * IP: GHIDRA * REVIEWED: YES diff --git a/test/integration/samples/OutputStreamPublisher.java b/test/integration/samples/OutputStreamPublisher.java index d168c1dd..a477448d 100644 --- a/test/integration/samples/OutputStreamPublisher.java +++ b/test/integration/samples/OutputStreamPublisher.java @@ -1,3 +1,8 @@ +// This Java code is taken from a public GitHub repository +// and is used inside Aibolit only for integration testing +// purposes. The code is never compiled or executed. + + /* * Copyright (c) 2017, 2019 Oracle and/or its affiliates. All rights reserved. * diff --git a/test/integration/samples/PackedDatabase.java b/test/integration/samples/PackedDatabase.java index 41bfd8c7..2467c4d6 100644 --- a/test/integration/samples/PackedDatabase.java +++ b/test/integration/samples/PackedDatabase.java @@ -1,3 +1,8 @@ +// This Java code is taken from a public GitHub repository +// and is used inside Aibolit only for integration testing +// purposes. The code is never compiled or executed. + + /* ### * IP: GHIDRA * diff --git a/test/integration/samples/ParameterAnnotation.java b/test/integration/samples/ParameterAnnotation.java index 1560c7b8..672a9bbf 100644 --- a/test/integration/samples/ParameterAnnotation.java +++ b/test/integration/samples/ParameterAnnotation.java @@ -1,3 +1,8 @@ +// This Java code is taken from a public GitHub repository +// and is used inside Aibolit only for integration testing +// purposes. The code is never compiled or executed. + + /* ### * IP: GHIDRA * diff --git a/test/integration/samples/PartitionManager.java b/test/integration/samples/PartitionManager.java index 96d6ede6..a72789b7 100644 --- a/test/integration/samples/PartitionManager.java +++ b/test/integration/samples/PartitionManager.java @@ -1,3 +1,8 @@ +// This Java code is taken from a public GitHub repository +// and is used inside Aibolit only for integration testing +// purposes. The code is never compiled or executed. + + // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. diff --git a/test/integration/samples/PdbInfo.java b/test/integration/samples/PdbInfo.java index 4abeab3c..49b18f5c 100644 --- a/test/integration/samples/PdbInfo.java +++ b/test/integration/samples/PdbInfo.java @@ -1,3 +1,8 @@ +// This Java code is taken from a public GitHub repository +// and is used inside Aibolit only for integration testing +// purposes. The code is never compiled or executed. + + /* ### * IP: GHIDRA * diff --git a/test/integration/samples/PdbInfoDotNet.java b/test/integration/samples/PdbInfoDotNet.java index 27ff8eca..ba10ea62 100644 --- a/test/integration/samples/PdbInfoDotNet.java +++ b/test/integration/samples/PdbInfoDotNet.java @@ -1,3 +1,8 @@ +// This Java code is taken from a public GitHub repository +// and is used inside Aibolit only for integration testing +// purposes. The code is never compiled or executed. + + /* ### * IP: GHIDRA * diff --git a/test/integration/samples/PersistentDispatcherMultipleConsumers.java b/test/integration/samples/PersistentDispatcherMultipleConsumers.java index 9c6b1efa..e76ae756 100644 --- a/test/integration/samples/PersistentDispatcherMultipleConsumers.java +++ b/test/integration/samples/PersistentDispatcherMultipleConsumers.java @@ -1,3 +1,8 @@ +// This Java code is taken from a public GitHub repository +// and is used inside Aibolit only for integration testing +// purposes. The code is never compiled or executed. + + /** * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file diff --git a/test/integration/samples/PersistentDispatcherSingleActiveConsumer.java b/test/integration/samples/PersistentDispatcherSingleActiveConsumer.java index c29fbc85..3f424152 100644 --- a/test/integration/samples/PersistentDispatcherSingleActiveConsumer.java +++ b/test/integration/samples/PersistentDispatcherSingleActiveConsumer.java @@ -1,3 +1,8 @@ +// This Java code is taken from a public GitHub repository +// and is used inside Aibolit only for integration testing +// purposes. The code is never compiled or executed. + + /** * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file diff --git a/test/integration/samples/PersistentSubscription.java b/test/integration/samples/PersistentSubscription.java index 88d8e45c..92983497 100644 --- a/test/integration/samples/PersistentSubscription.java +++ b/test/integration/samples/PersistentSubscription.java @@ -1,3 +1,8 @@ +// This Java code is taken from a public GitHub repository +// and is used inside Aibolit only for integration testing +// purposes. The code is never compiled or executed. + + /** * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file diff --git a/test/integration/samples/PrestimeCPUCCTNodeBacked.java b/test/integration/samples/PrestimeCPUCCTNodeBacked.java index 7e021968..25e50b97 100644 --- a/test/integration/samples/PrestimeCPUCCTNodeBacked.java +++ b/test/integration/samples/PrestimeCPUCCTNodeBacked.java @@ -1,3 +1,8 @@ +// This Java code is taken from a public GitHub repository +// and is used inside Aibolit only for integration testing +// purposes. The code is never compiled or executed. + + /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file diff --git a/test/integration/samples/PrivateDatabase.java b/test/integration/samples/PrivateDatabase.java index 372b9411..506d9c65 100644 --- a/test/integration/samples/PrivateDatabase.java +++ b/test/integration/samples/PrivateDatabase.java @@ -1,3 +1,8 @@ +// This Java code is taken from a public GitHub repository +// and is used inside Aibolit only for integration testing +// purposes. The code is never compiled or executed. + + /* ### * IP: GHIDRA * diff --git a/test/integration/samples/ProducerImpl.java b/test/integration/samples/ProducerImpl.java index 7805fa8d..369debb2 100644 --- a/test/integration/samples/ProducerImpl.java +++ b/test/integration/samples/ProducerImpl.java @@ -1,3 +1,8 @@ +// This Java code is taken from a public GitHub repository +// and is used inside Aibolit only for integration testing +// purposes. The code is never compiled or executed. + + /** * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file diff --git a/test/integration/samples/ProfilerGCXYItemPainter.java b/test/integration/samples/ProfilerGCXYItemPainter.java index d0bd4406..4b397dcf 100644 --- a/test/integration/samples/ProfilerGCXYItemPainter.java +++ b/test/integration/samples/ProfilerGCXYItemPainter.java @@ -1,3 +1,8 @@ +// This Java code is taken from a public GitHub repository +// and is used inside Aibolit only for integration testing +// purposes. The code is never compiled or executed. + + /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file diff --git a/test/integration/samples/ProfilerTreeTable.java b/test/integration/samples/ProfilerTreeTable.java index 1e61b79b..b4078cd5 100644 --- a/test/integration/samples/ProfilerTreeTable.java +++ b/test/integration/samples/ProfilerTreeTable.java @@ -1,3 +1,8 @@ +// This Java code is taken from a public GitHub repository +// and is used inside Aibolit only for integration testing +// purposes. The code is never compiled or executed. + + /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file diff --git a/test/integration/samples/ProgramDB.java b/test/integration/samples/ProgramDB.java index 3679b238..83e41f35 100644 --- a/test/integration/samples/ProgramDB.java +++ b/test/integration/samples/ProgramDB.java @@ -1,3 +1,8 @@ +// This Java code is taken from a public GitHub repository +// and is used inside Aibolit only for integration testing +// purposes. The code is never compiled or executed. + + /* ### * IP: GHIDRA * diff --git a/test/integration/samples/ProgramUserDataDB.java b/test/integration/samples/ProgramUserDataDB.java index edb64097..973c8566 100644 --- a/test/integration/samples/ProgramUserDataDB.java +++ b/test/integration/samples/ProgramUserDataDB.java @@ -1,3 +1,8 @@ +// This Java code is taken from a public GitHub repository +// and is used inside Aibolit only for integration testing +// purposes. The code is never compiled or executed. + + /* ### * IP: GHIDRA * diff --git a/test/integration/samples/ProjectFileManager.java b/test/integration/samples/ProjectFileManager.java index 8ba125c7..50db831b 100644 --- a/test/integration/samples/ProjectFileManager.java +++ b/test/integration/samples/ProjectFileManager.java @@ -1,3 +1,8 @@ +// This Java code is taken from a public GitHub repository +// and is used inside Aibolit only for integration testing +// purposes. The code is never compiled or executed. + + /* ### * IP: GHIDRA * diff --git a/test/integration/samples/PrototypesIDItem.java b/test/integration/samples/PrototypesIDItem.java index d10665ac..b59bc882 100644 --- a/test/integration/samples/PrototypesIDItem.java +++ b/test/integration/samples/PrototypesIDItem.java @@ -1,3 +1,8 @@ +// This Java code is taken from a public GitHub repository +// and is used inside Aibolit only for integration testing +// purposes. The code is never compiled or executed. + + /* ### * IP: GHIDRA * diff --git a/test/integration/samples/PulsarBolt.java b/test/integration/samples/PulsarBolt.java index d331ca2e..2b4b10e4 100644 --- a/test/integration/samples/PulsarBolt.java +++ b/test/integration/samples/PulsarBolt.java @@ -1,3 +1,8 @@ +// This Java code is taken from a public GitHub repository +// and is used inside Aibolit only for integration testing +// purposes. The code is never compiled or executed. + + /** * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file diff --git a/test/integration/samples/PulsarOffsetBackingStore.java b/test/integration/samples/PulsarOffsetBackingStore.java index d7daf82e..9c8d2624 100644 --- a/test/integration/samples/PulsarOffsetBackingStore.java +++ b/test/integration/samples/PulsarOffsetBackingStore.java @@ -1,3 +1,8 @@ +// This Java code is taken from a public GitHub repository +// and is used inside Aibolit only for integration testing +// purposes. The code is never compiled or executed. + + /** * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file diff --git a/test/integration/samples/RecoveryMgr.java b/test/integration/samples/RecoveryMgr.java index 93cd0df7..2f5ef50e 100644 --- a/test/integration/samples/RecoveryMgr.java +++ b/test/integration/samples/RecoveryMgr.java @@ -1,3 +1,8 @@ +// This Java code is taken from a public GitHub repository +// and is used inside Aibolit only for integration testing +// purposes. The code is never compiled or executed. + + /* ### * IP: GHIDRA * diff --git a/test/integration/samples/ReferenceCountedOpenSslClientContext.java b/test/integration/samples/ReferenceCountedOpenSslClientContext.java index 56893b3f..418333aa 100644 --- a/test/integration/samples/ReferenceCountedOpenSslClientContext.java +++ b/test/integration/samples/ReferenceCountedOpenSslClientContext.java @@ -1,3 +1,8 @@ +// This Java code is taken from a public GitHub repository +// and is used inside Aibolit only for integration testing +// purposes. The code is never compiled or executed. + + /* * Copyright 2016 The Netty Project * diff --git a/test/integration/samples/ReferenceCountedOpenSslEngine.java b/test/integration/samples/ReferenceCountedOpenSslEngine.java index 3822e0db..c160d14e 100644 --- a/test/integration/samples/ReferenceCountedOpenSslEngine.java +++ b/test/integration/samples/ReferenceCountedOpenSslEngine.java @@ -1,3 +1,8 @@ +// This Java code is taken from a public GitHub repository +// and is used inside Aibolit only for integration testing +// purposes. The code is never compiled or executed. + + /* * Copyright 2016 The Netty Project * diff --git a/test/integration/samples/ReferenceCountedOpenSslServerContext.java b/test/integration/samples/ReferenceCountedOpenSslServerContext.java index 6d78e6d0..1979d2ab 100644 --- a/test/integration/samples/ReferenceCountedOpenSslServerContext.java +++ b/test/integration/samples/ReferenceCountedOpenSslServerContext.java @@ -1,3 +1,8 @@ +// This Java code is taken from a public GitHub repository +// and is used inside Aibolit only for integration testing +// purposes. The code is never compiled or executed. + + /* * Copyright 2016 The Netty Project * diff --git a/test/integration/samples/RefreshListeners.java b/test/integration/samples/RefreshListeners.java index d343f863..bb4f09ee 100644 --- a/test/integration/samples/RefreshListeners.java +++ b/test/integration/samples/RefreshListeners.java @@ -1,3 +1,8 @@ +// This Java code is taken from a public GitHub repository +// and is used inside Aibolit only for integration testing +// purposes. The code is never compiled or executed. + + /* * Licensed to Elasticsearch under one or more contributor * license agreements. See the NOTICE file distributed with diff --git a/test/integration/samples/RequestResponseLinkCache.java b/test/integration/samples/RequestResponseLinkCache.java index caa51d77..9f40000b 100644 --- a/test/integration/samples/RequestResponseLinkCache.java +++ b/test/integration/samples/RequestResponseLinkCache.java @@ -1,3 +1,8 @@ +// This Java code is taken from a public GitHub repository +// and is used inside Aibolit only for integration testing +// purposes. The code is never compiled or executed. + + // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. diff --git a/test/integration/samples/ResourceHeader.java b/test/integration/samples/ResourceHeader.java index 329a6ce0..8a0eb7ae 100644 --- a/test/integration/samples/ResourceHeader.java +++ b/test/integration/samples/ResourceHeader.java @@ -1,3 +1,8 @@ +// This Java code is taken from a public GitHub repository +// and is used inside Aibolit only for integration testing +// purposes. The code is never compiled or executed. + + /* ### * IP: GHIDRA * REVIEWED: YES diff --git a/test/integration/samples/ResourceMap.java b/test/integration/samples/ResourceMap.java index afbffa40..85f5ca8a 100644 --- a/test/integration/samples/ResourceMap.java +++ b/test/integration/samples/ResourceMap.java @@ -1,3 +1,8 @@ +// This Java code is taken from a public GitHub repository +// and is used inside Aibolit only for integration testing +// purposes. The code is never compiled or executed. + + /* ### * IP: GHIDRA * REVIEWED: YES diff --git a/test/integration/samples/ResultSetViewer.java b/test/integration/samples/ResultSetViewer.java index da8d7d77..d70629fa 100644 --- a/test/integration/samples/ResultSetViewer.java +++ b/test/integration/samples/ResultSetViewer.java @@ -1,3 +1,8 @@ +// This Java code is taken from a public GitHub repository +// and is used inside Aibolit only for integration testing +// purposes. The code is never compiled or executed. + + /* * DBeaver - Universal Database Manager * Copyright (C) 2010-2020 DBeaver Corp and others diff --git a/test/integration/samples/ScannerUtils.java b/test/integration/samples/ScannerUtils.java index 267cdf1a..1eaaeb47 100644 --- a/test/integration/samples/ScannerUtils.java +++ b/test/integration/samples/ScannerUtils.java @@ -1,3 +1,8 @@ +// This Java code is taken from a public GitHub repository +// and is used inside Aibolit only for integration testing +// purposes. The code is never compiled or executed. + + /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file diff --git a/test/integration/samples/SchedulerManager.java b/test/integration/samples/SchedulerManager.java index 2e25f0f3..1c9c5913 100644 --- a/test/integration/samples/SchedulerManager.java +++ b/test/integration/samples/SchedulerManager.java @@ -1,3 +1,8 @@ +// This Java code is taken from a public GitHub repository +// and is used inside Aibolit only for integration testing +// purposes. The code is never compiled or executed. + + /** * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file diff --git a/test/integration/samples/SequenceFile.java b/test/integration/samples/SequenceFile.java index fec0a4ac..5c953428 100644 --- a/test/integration/samples/SequenceFile.java +++ b/test/integration/samples/SequenceFile.java @@ -1,3 +1,8 @@ +// This Java code is taken from a public GitHub repository +// and is used inside Aibolit only for integration testing +// purposes. The code is never compiled or executed. + + /** * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file diff --git a/test/integration/samples/ServiceScheduler.java b/test/integration/samples/ServiceScheduler.java index 458a7a1c..b6e4af95 100644 --- a/test/integration/samples/ServiceScheduler.java +++ b/test/integration/samples/ServiceScheduler.java @@ -1,3 +1,8 @@ +// This Java code is taken from a public GitHub repository +// and is used inside Aibolit only for integration testing +// purposes. The code is never compiled or executed. + + /** * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file diff --git a/test/integration/samples/SizeCalculatingEntryWriter.java b/test/integration/samples/SizeCalculatingEntryWriter.java index b46e0651..48fae96e 100644 --- a/test/integration/samples/SizeCalculatingEntryWriter.java +++ b/test/integration/samples/SizeCalculatingEntryWriter.java @@ -1,3 +1,8 @@ +// This Java code is taken from a public GitHub repository +// and is used inside Aibolit only for integration testing +// purposes. The code is never compiled or executed. + + /* * Copyright 2012-2020 the original author or authors. * diff --git a/test/integration/samples/SpecificationVersion.java b/test/integration/samples/SpecificationVersion.java index a074a6e3..3d7b2b59 100644 --- a/test/integration/samples/SpecificationVersion.java +++ b/test/integration/samples/SpecificationVersion.java @@ -1,3 +1,8 @@ +// This Java code is taken from a public GitHub repository +// and is used inside Aibolit only for integration testing +// purposes. The code is never compiled or executed. + + /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file diff --git a/test/integration/samples/SpellcheckerOptionsPanel.java b/test/integration/samples/SpellcheckerOptionsPanel.java index f744a128..47fc76f5 100644 --- a/test/integration/samples/SpellcheckerOptionsPanel.java +++ b/test/integration/samples/SpellcheckerOptionsPanel.java @@ -1,3 +1,8 @@ +// This Java code is taken from a public GitHub repository +// and is used inside Aibolit only for integration testing +// purposes. The code is never compiled or executed. + + /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file diff --git a/test/integration/samples/SpillRecord.java b/test/integration/samples/SpillRecord.java index 9e04e6fb..98b4dddd 100644 --- a/test/integration/samples/SpillRecord.java +++ b/test/integration/samples/SpillRecord.java @@ -1,3 +1,8 @@ +// This Java code is taken from a public GitHub repository +// and is used inside Aibolit only for integration testing +// purposes. The code is never compiled or executed. + + /** * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file diff --git a/test/integration/samples/SqlQueryManager.java b/test/integration/samples/SqlQueryManager.java index 33e311de..5854db7a 100644 --- a/test/integration/samples/SqlQueryManager.java +++ b/test/integration/samples/SqlQueryManager.java @@ -1,3 +1,8 @@ +// This Java code is taken from a public GitHub repository +// and is used inside Aibolit only for integration testing +// purposes. The code is never compiled or executed. + + /* * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/test/integration/samples/SquareRootDecomposition.java b/test/integration/samples/SquareRootDecomposition.java index 1e325c85..1f2810e2 100644 --- a/test/integration/samples/SquareRootDecomposition.java +++ b/test/integration/samples/SquareRootDecomposition.java @@ -1,3 +1,8 @@ +// This Java code is taken from a public GitHub repository +// and is used inside Aibolit only for integration testing +// purposes. The code is never compiled or executed. + + /** * Range queries in O(sqrt(n)) and point updates in O(1). Currently this implementation supports * summing over the entries in the array, but it can be modified to support many different diff --git a/test/integration/samples/StringDataItem.java b/test/integration/samples/StringDataItem.java index 68905a59..8fe480e8 100644 --- a/test/integration/samples/StringDataItem.java +++ b/test/integration/samples/StringDataItem.java @@ -1,3 +1,8 @@ +// This Java code is taken from a public GitHub repository +// and is used inside Aibolit only for integration testing +// purposes. The code is never compiled or executed. + + /* ### * IP: GHIDRA * diff --git a/test/integration/samples/SvnConfigFiles.java b/test/integration/samples/SvnConfigFiles.java index bdcbbb48..6e85d663 100644 --- a/test/integration/samples/SvnConfigFiles.java +++ b/test/integration/samples/SvnConfigFiles.java @@ -1,3 +1,8 @@ +// This Java code is taken from a public GitHub repository +// and is used inside Aibolit only for integration testing +// purposes. The code is never compiled or executed. + + /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file diff --git a/test/integration/samples/TFile.java b/test/integration/samples/TFile.java index 09cd2825..4e759d59 100644 --- a/test/integration/samples/TFile.java +++ b/test/integration/samples/TFile.java @@ -1,3 +1,8 @@ +// This Java code is taken from a public GitHub repository +// and is used inside Aibolit only for integration testing +// purposes. The code is never compiled or executed. + + /** * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with this diff --git a/test/integration/samples/TabLayout.java b/test/integration/samples/TabLayout.java index 7d7f68cd..5a371db0 100644 --- a/test/integration/samples/TabLayout.java +++ b/test/integration/samples/TabLayout.java @@ -1,3 +1,8 @@ +// This Java code is taken from a public GitHub repository +// and is used inside Aibolit only for integration testing +// purposes. The code is never compiled or executed. + + /* * Copyright (C) 2015 The Android Open Source Project * diff --git a/test/integration/samples/Table.java b/test/integration/samples/Table.java index 2c125cd2..0b614b31 100644 --- a/test/integration/samples/Table.java +++ b/test/integration/samples/Table.java @@ -1,3 +1,8 @@ +// This Java code is taken from a public GitHub repository +// and is used inside Aibolit only for integration testing +// purposes. The code is never compiled or executed. + + /* ### * IP: GHIDRA * diff --git a/test/integration/samples/TableModelEditor.java b/test/integration/samples/TableModelEditor.java index 07ce7005..6e5cbcae 100644 --- a/test/integration/samples/TableModelEditor.java +++ b/test/integration/samples/TableModelEditor.java @@ -1,3 +1,8 @@ +// This Java code is taken from a public GitHub repository +// and is used inside Aibolit only for integration testing +// purposes. The code is never compiled or executed. + + /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file diff --git a/test/integration/samples/TarjanAdjacencyMatrix.java b/test/integration/samples/TarjanAdjacencyMatrix.java index a053ec2c..2c78456f 100644 --- a/test/integration/samples/TarjanAdjacencyMatrix.java +++ b/test/integration/samples/TarjanAdjacencyMatrix.java @@ -1,3 +1,8 @@ +// This Java code is taken from a public GitHub repository +// and is used inside Aibolit only for integration testing +// purposes. The code is never compiled or executed. + + /** * An implementation of Tarjan's SCC algorithm for a directed graph. Time Complexity: O(V^2) * diff --git a/test/integration/samples/TaskInfoFetcher.java b/test/integration/samples/TaskInfoFetcher.java index e2312fe4..bab0bba1 100644 --- a/test/integration/samples/TaskInfoFetcher.java +++ b/test/integration/samples/TaskInfoFetcher.java @@ -1,3 +1,8 @@ +// This Java code is taken from a public GitHub repository +// and is used inside Aibolit only for integration testing +// purposes. The code is never compiled or executed. + + /* * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/test/integration/samples/TextSync.java b/test/integration/samples/TextSync.java index 35b911d0..1995f6fe 100644 --- a/test/integration/samples/TextSync.java +++ b/test/integration/samples/TextSync.java @@ -1,3 +1,8 @@ +// This Java code is taken from a public GitHub repository +// and is used inside Aibolit only for integration testing +// purposes. The code is never compiled or executed. + + /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file diff --git a/test/integration/samples/TextSyncGroup.java b/test/integration/samples/TextSyncGroup.java index 37d95b88..3b7fe64a 100644 --- a/test/integration/samples/TextSyncGroup.java +++ b/test/integration/samples/TextSyncGroup.java @@ -1,3 +1,8 @@ +// This Java code is taken from a public GitHub repository +// and is used inside Aibolit only for integration testing +// purposes. The code is never compiled or executed. + + /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file diff --git a/test/integration/samples/ThreadData.java b/test/integration/samples/ThreadData.java index 6ab68b51..14beda17 100644 --- a/test/integration/samples/ThreadData.java +++ b/test/integration/samples/ThreadData.java @@ -1,3 +1,8 @@ +// This Java code is taken from a public GitHub repository +// and is used inside Aibolit only for integration testing +// purposes. The code is never compiled or executed. + + /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file diff --git a/test/integration/samples/ToolWizardPageLog.java b/test/integration/samples/ToolWizardPageLog.java index ccff801b..e354c882 100644 --- a/test/integration/samples/ToolWizardPageLog.java +++ b/test/integration/samples/ToolWizardPageLog.java @@ -1,3 +1,8 @@ +// This Java code is taken from a public GitHub repository +// and is used inside Aibolit only for integration testing +// purposes. The code is never compiled or executed. + + /* * DBeaver - Universal Database Manager * Copyright (C) 2010-2020 DBeaver Corp and others diff --git a/test/integration/samples/TreeGraphLayout.java b/test/integration/samples/TreeGraphLayout.java index 7015b514..d7f3ff8e 100644 --- a/test/integration/samples/TreeGraphLayout.java +++ b/test/integration/samples/TreeGraphLayout.java @@ -1,3 +1,8 @@ +// This Java code is taken from a public GitHub repository +// and is used inside Aibolit only for integration testing +// purposes. The code is never compiled or executed. + + /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file diff --git a/test/integration/samples/TrieDictionary.java b/test/integration/samples/TrieDictionary.java index c01e00ce..2fd5bf82 100644 --- a/test/integration/samples/TrieDictionary.java +++ b/test/integration/samples/TrieDictionary.java @@ -1,3 +1,8 @@ +// This Java code is taken from a public GitHub repository +// and is used inside Aibolit only for integration testing +// purposes. The code is never compiled or executed. + + /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file diff --git a/test/integration/samples/TruffleAccess.java b/test/integration/samples/TruffleAccess.java index 386d5653..03b775a7 100644 --- a/test/integration/samples/TruffleAccess.java +++ b/test/integration/samples/TruffleAccess.java @@ -1,3 +1,8 @@ +// This Java code is taken from a public GitHub repository +// and is used inside Aibolit only for integration testing +// purposes. The code is never compiled or executed. + + /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file diff --git a/test/integration/samples/Utils.java b/test/integration/samples/Utils.java index 90487202..18a222da 100644 --- a/test/integration/samples/Utils.java +++ b/test/integration/samples/Utils.java @@ -1,3 +1,8 @@ +// This Java code is taken from a public GitHub repository +// and is used inside Aibolit only for integration testing +// purposes. The code is never compiled or executed. + + /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file diff --git a/test/integration/samples/VersionFileHandler.java b/test/integration/samples/VersionFileHandler.java index 571236d1..401dee60 100644 --- a/test/integration/samples/VersionFileHandler.java +++ b/test/integration/samples/VersionFileHandler.java @@ -1,3 +1,8 @@ +// This Java code is taken from a public GitHub repository +// and is used inside Aibolit only for integration testing +// purposes. The code is never compiled or executed. + + /* ### * IP: GHIDRA * REVIEWED: YES diff --git a/test/integration/samples/WatchesTreeModel.java b/test/integration/samples/WatchesTreeModel.java index bc130fd2..5ec14347 100644 --- a/test/integration/samples/WatchesTreeModel.java +++ b/test/integration/samples/WatchesTreeModel.java @@ -1,3 +1,8 @@ +// This Java code is taken from a public GitHub repository +// and is used inside Aibolit only for integration testing +// purposes. The code is never compiled or executed. + + /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file diff --git a/test/integration/samples/WindowManagerImpl.java b/test/integration/samples/WindowManagerImpl.java index 82cecc43..4dc15827 100644 --- a/test/integration/samples/WindowManagerImpl.java +++ b/test/integration/samples/WindowManagerImpl.java @@ -1,3 +1,8 @@ +// This Java code is taken from a public GitHub repository +// and is used inside Aibolit only for integration testing +// purposes. The code is never compiled or executed. + + /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file diff --git a/test/integration/samples/WorkspaceDocumentManagerImpl.java b/test/integration/samples/WorkspaceDocumentManagerImpl.java index 99dd39a2..e644f71b 100644 --- a/test/integration/samples/WorkspaceDocumentManagerImpl.java +++ b/test/integration/samples/WorkspaceDocumentManagerImpl.java @@ -1,3 +1,8 @@ +// This Java code is taken from a public GitHub repository +// and is used inside Aibolit only for integration testing +// purposes. The code is never compiled or executed. + + /* * Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. * From ce83308f0897802e2af0fd5bc595ef769d34fde2 Mon Sep 17 00:00:00 2001 From: Evgeny Maslov Date: Wed, 8 Jul 2020 13:01:34 +0300 Subject: [PATCH 34/44] Add tests with function --- aibolit/__main__.py | 27 ++++++++ .../annotations/ClassAnnotations.java | 61 +++++++++++++++++ test/recommend/annotations/Lambda.java | 45 +++++++++++++ .../annotations/MutipleAnnotations.java | 66 +++++++++++++++++++ .../annotations/OneLineFunction.java | 33 ++++++++++ test/recommend/test_recommend_pipeline.py | 34 +++++++++- 6 files changed, 265 insertions(+), 1 deletion(-) create mode 100644 test/recommend/annotations/ClassAnnotations.java create mode 100644 test/recommend/annotations/Lambda.java create mode 100644 test/recommend/annotations/MutipleAnnotations.java create mode 100644 test/recommend/annotations/OneLineFunction.java diff --git a/aibolit/__main__.py b/aibolit/__main__.py index e0ead5fa..4369607c 100644 --- a/aibolit/__main__.py +++ b/aibolit/__main__.py @@ -33,6 +33,7 @@ import sys import time import traceback +from collections import defaultdict from os import scandir from pathlib import Path from sys import stdout @@ -162,6 +163,32 @@ def flatten(l): return [item for sublist in l for item in sublist] +def find_annotation_by_node_type(tree, node_type): + """Search nodes with annotations. + + :param tree: javalang.tree + :param node_type: Node type of javalang.tree + :return + dict with annotations, where key is node, value is list of string annotations; + """ + annonations = defaultdict(list) + for _, node in tree.filter(node_type): + if node.annotations: + for a in node.annotations: + if hasattr(a.element, 'value'): + if 'aibolit' in a.element.value: + annonations[node].append( + a.element.value.split('.')[1].rstrip('\"') + ) + elif hasattr(a.element, 'values'): + for j in a.element.values: + if 'aibolit' in j.value: + annonations[node].append( + j.value.split('.')[1].rstrip('\"') + ) + return annonations + + def find_start_and_end_lines(node): max_line = node.position.line diff --git a/test/recommend/annotations/ClassAnnotations.java b/test/recommend/annotations/ClassAnnotations.java new file mode 100644 index 00000000..e35416b4 --- /dev/null +++ b/test/recommend/annotations/ClassAnnotations.java @@ -0,0 +1,61 @@ +package com.airbnb.lottie; + +import android.graphics.Bitmap; +import androidx.annotation.Nullable; +import androidx.annotation.RestrictTo; + +/** + * Data class describing an image asset exported by bodymovin. + */ +@SuppressWarnings("aibolit.P11") +public class LottieImageAsset { + private final int width; + private final int height; + private final String id; + @SuppressWarnings("aibolit.P27") + private final String fileName; + @SuppressWarnings({"aibolit.P23", "aibolit.P22"}) + private final String dirName; + /** Pre-set a bitmap for this asset */ + @SuppressWarnings({"aibolit.P23", "aibolit.P11"}) + @Nullable private Bitmap bitmap; + + @RestrictTo(RestrictTo.Scope.LIBRARY) + public LottieImageAsset(int width, int height, String id, String fileName, String dirName) { + this.width = width; + this.height = height; + this.id = id; + this.fileName = fileName; + this.dirName = dirName; + } + + private XMLStreamReader2 getStreamReader(Resource wrapper, boolean quiet) + throws XMLStreamException, IOException { + Object resource = wrapper.getResource(); + boolean isRestricted = wrapper.isParserRestricted(); + XMLStreamReader2 reader = null; + if (resource instanceof URL) { // an URL resource + reader = (XMLStreamReader2)parse((URL)resource, isRestricted); + } else if (resource instanceof String) { // a CLASSPATH resource + URL url = getResource((String)resource); + reader = (XMLStreamReader2)parse(url, isRestricted); + } else if (resource instanceof Path) { // a file resource + // Can't use FileSystem API or we get an infinite loop + // since FileSystem uses Configuration API. Use java.io.File instead. + File file = new File(((Path)resource).toUri().getPath()) + .getAbsoluteFile(); + if (file.exists()) { + if (!quiet) { + LOG.debug("parsing File " + file); + } + reader = (XMLStreamReader2)parse(new BufferedInputStream( + Files.newInputStream(file.toPath())), ((Path) resource).toString(), + isRestricted); + } + } else if (resource instanceof InputStream) { + reader = (XMLStreamReader2)parse((InputStream)resource, null, + isRestricted); + } + return reader; + } +} diff --git a/test/recommend/annotations/Lambda.java b/test/recommend/annotations/Lambda.java new file mode 100644 index 00000000..1ce5e716 --- /dev/null +++ b/test/recommend/annotations/Lambda.java @@ -0,0 +1,45 @@ +package com.airbnb.lottie; + +import android.graphics.Bitmap; +import androidx.annotation.Nullable; +import androidx.annotation.RestrictTo; + +/** + * Data class describing an image asset exported by bodymovin. + */ +@SuppressWarnings({"aibolit.P23", "aibolit.P11"}) +public class LottieImageAsset { + private final int width; + private final int height; + private final String id; + @SuppressWarnings("aibolit.P27") + private final String fileName; + @SuppressWarnings({"aibolit.P23", "aibolit.P22"}) + private final String dirName; + /** Pre-set a bitmap for this asset */ + @SuppressWarnings({"aibolit.P23", "aibolit.P11"}) + @Nullable private Bitmap bitmap; + + @RestrictTo(RestrictTo.Scope.LIBRARY) + public LottieImageAsset(int width, int height, String id, String fileName, String dirName) { + this.width = width; + this.height = height; + this.id = id; + this.fileName = fileName; + this.dirName = dirName; + } + + public ArrayList filterWithOptionalEmpty(Long threshold) { + Function filter = last -> { + final Optional size; + if (last >= threshold) { + size = Optional.empty(); + } else { + size = Optional.of(last); + } + return size; + }; + + return array.map(filter); + } +} diff --git a/test/recommend/annotations/MutipleAnnotations.java b/test/recommend/annotations/MutipleAnnotations.java new file mode 100644 index 00000000..da65a5f2 --- /dev/null +++ b/test/recommend/annotations/MutipleAnnotations.java @@ -0,0 +1,66 @@ +package com.airbnb.lottie; + +import android.graphics.Bitmap; +import androidx.annotation.Nullable; +import androidx.annotation.RestrictTo; + +/** + * Data class describing an image asset exported by bodymovin. + */ +@SuppressWarnings({"aibolit.P23", "aibolit.P11"}) +public class LottieImageAsset { + private final int width; + private final int height; + private final String id; + @SuppressWarnings("aibolit.P23") + private final String fileName; + @SuppressWarnings({"aibolit.P23", "aibolit.P22"}) + private final String dirName; + /** Pre-set a bitmap for this asset */ + @Nullable private Bitmap bitmap; + + @SuppressWarnings("aibolit.P23") + public void set() { + this.dirName = "level"; + } + + @RestrictTo(RestrictTo.Scope.LIBRARY) + public LottieImageAsset(int width, int height, String id, String fileName, String dirName) { + this.width = width; + this.height = height; + this.id = id; + this.fileName = fileName; + this.dirName = dirName; + } + + @SuppressWarnings({"aibolit.P23", "aibolit.P22"}) + private XMLStreamReader2 getStreamReader(Resource wrapper, boolean quiet) + throws XMLStreamException, IOException { + Object resource = wrapper.getResource(); + boolean isRestricted = wrapper.isParserRestricted(); + XMLStreamReader2 reader = null; + if (resource instanceof URL) { // an URL resource + reader = (XMLStreamReader2)parse((URL)resource, isRestricted); + } else if (resource instanceof String) { // a CLASSPATH resource + URL url = getResource((String)resource); + reader = (XMLStreamReader2)parse(url, isRestricted); + } else if (resource instanceof Path) { // a file resource + // Can't use FileSystem API or we get an infinite loop + // since FileSystem uses Configuration API. Use java.io.File instead. + File file = new File(((Path)resource).toUri().getPath()) + .getAbsoluteFile(); + if (file.exists()) { + if (!quiet) { + LOG.debug("parsing File " + file); + } + reader = (XMLStreamReader2)parse(new BufferedInputStream( + Files.newInputStream(file.toPath())), ((Path) resource).toString(), + isRestricted); + } + } else if (resource instanceof InputStream) { + reader = (XMLStreamReader2)parse((InputStream)resource, null, + isRestricted); + } + return reader; + } +} diff --git a/test/recommend/annotations/OneLineFunction.java b/test/recommend/annotations/OneLineFunction.java new file mode 100644 index 00000000..e4dfb879 --- /dev/null +++ b/test/recommend/annotations/OneLineFunction.java @@ -0,0 +1,33 @@ +package com.airbnb.lottie; + +import android.graphics.Bitmap; +import androidx.annotation.Nullable; +import androidx.annotation.RestrictTo; + +/** + * Data class describing an image asset exported by bodymovin. + */ +@SuppressWarnings({"aibolit.P23", "aibolit.P11"}) +public class LottieImageAsset { + private final int width; + private final int height; + private final String id; + @SuppressWarnings("aibolit.P27") + private final String fileName; + @SuppressWarnings({"aibolit.P23", "aibolit.P22"}) + private final String dirName; + /** Pre-set a bitmap for this asset */ + @SuppressWarnings({"aibolit.P23", "aibolit.P11"}) + @Nullable private Bitmap bitmap; + + @RestrictTo(RestrictTo.Scope.LIBRARY) + public LottieImageAsset(int width, int height, String id, String fileName, String dirName) { + this.width = width; + this.height = height; + this.id = id; + this.fileName = fileName; + this.dirName = dirName; + } + + public int getWidth() { int a = 0; int b = 0;} +} diff --git a/test/recommend/test_recommend_pipeline.py b/test/recommend/test_recommend_pipeline.py index 985bb4ba..87a7eb3e 100644 --- a/test/recommend/test_recommend_pipeline.py +++ b/test/recommend/test_recommend_pipeline.py @@ -30,7 +30,7 @@ from aibolit.config import Config from aibolit.__main__ import list_dir, calculate_patterns_and_metrics, \ - create_xml_tree, create_text, format_converter_for_pattern, find_start_and_end_lines + create_xml_tree, create_text, format_converter_for_pattern, find_start_and_end_lines, find_annotation_by_node_type class TestRecommendPipeline(TestCase): @@ -255,3 +255,35 @@ def test_find_start_end_line_in_class(self): start, end = find_start_and_end_lines(method) self.assertEqual(start, 11) self.assertEqual(end, 59) + + def test_find_annotation_by_class_declaration(self): + file = Path(self.cur_file_dir, 'annotations/ClassAnnotations.java') + with open(file, 'r', encoding='utf-8') as f: + tree = javalang.parse.parse(f.read()) + classes_with_annonations = find_annotation_by_node_type(tree, javalang.tree.ClassDeclaration) + pattern_found = list(classes_with_annonations.values())[0][0] + self.assertEqual(pattern_found, 'P11') + + def test_find_mutiple_annotations_by_class_declaration(self): + file = Path(self.cur_file_dir, 'annotations/MutipleAnnotations.java') + with open(file, 'r', encoding='utf-8') as f: + tree = javalang.parse.parse(f.read()) + classes_with_annonations = find_annotation_by_node_type(tree, javalang.tree.ClassDeclaration) + patterns_found = list(classes_with_annonations.values())[0] + self.assertEqual(patterns_found, ['P23', 'P11']) + + def test_find_annotation_method_declaration(self): + file = Path(self.cur_file_dir, 'annotations/MutipleAnnotations.java') + with open(file, 'r', encoding='utf-8') as f: + tree = javalang.parse.parse(f.read()) + functions_with_annotations = find_annotation_by_node_type(tree, javalang.tree.MethodDeclaration) + patterns_found_with_functions = [(x.name, y) for x, y in functions_with_annotations.items()] + self.assertEqual(patterns_found_with_functions, [('set', ['P23']), ('getStreamReader', ['P23', 'P22'])]) + + def test_find_annotation_by_field_declaration(self): + file = Path(self.cur_file_dir, 'annotations/MutipleAnnotations.java') + with open(file, 'r', encoding='utf-8') as f: + tree = javalang.parse.parse(f.read()) + fields_with_annotations = find_annotation_by_node_type(tree, javalang.tree.FieldDeclaration) + patterns_found_with_fields = list(fields_with_annotations.values()) + self.assertEqual(patterns_found_with_fields, [['P23'], ['P23', 'P22']]) From cd99e448986c54f8cd04dba89c365a4a78dca7f0 Mon Sep 17 00:00:00 2001 From: yegor256 Date: Wed, 8 Jul 2020 15:08:08 +0300 Subject: [PATCH 35/44] appveyor fixed --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 5e7357ad..d1e2dbab 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ [![PyPi version](https://img.shields.io/pypi/v/aibolit.svg)](https://pypi.org/project/aibolit/) [![Build Status](https://travis-ci.org/cqfn/aibolit.svg)](https://travis-ci.org/cqfn/aibolit) -[![Build status](https://ci.appveyor.com/api/projects/status/wjjcd6amnt3p2tdg?svg=true)](https://ci.appveyor.com/project/yegor256/aibolit-lyf56) +[![Build status](https://ci.appveyor.com/api/projects/status/gr3eqxq5pr87kpwg?svg=true)](https://ci.appveyor.com/project/yegor256/aibolit) [![Hits-of-Code](https://hitsofcode.com/github/cqfn/aibolit)](https://hitsofcode.com/view/github/cqfn/aibolit) [![Test Coverage](https://img.shields.io/codecov/c/github/cqfn/aibolit.svg)](https://codecov.io/github/cqfn/aibolit?branch=master) [![Maintainability](https://api.codeclimate.com/v1/badges/fd7e32d8472b4d5e8ecb/maintainability)](https://codeclimate.com/github/cqfn/aibolit/maintainability) From b0275a9e1f5cab63fa747c88cc8931e4f2e00004 Mon Sep 17 00:00:00 2001 From: Evgeny Maslov Date: Wed, 8 Jul 2020 15:35:58 +0300 Subject: [PATCH 36/44] Remve files --- test/recommend/annotations/Lambda.java | 45 ------------------- .../annotations/OneLineFunction.java | 33 -------------- 2 files changed, 78 deletions(-) delete mode 100644 test/recommend/annotations/Lambda.java delete mode 100644 test/recommend/annotations/OneLineFunction.java diff --git a/test/recommend/annotations/Lambda.java b/test/recommend/annotations/Lambda.java deleted file mode 100644 index 1ce5e716..00000000 --- a/test/recommend/annotations/Lambda.java +++ /dev/null @@ -1,45 +0,0 @@ -package com.airbnb.lottie; - -import android.graphics.Bitmap; -import androidx.annotation.Nullable; -import androidx.annotation.RestrictTo; - -/** - * Data class describing an image asset exported by bodymovin. - */ -@SuppressWarnings({"aibolit.P23", "aibolit.P11"}) -public class LottieImageAsset { - private final int width; - private final int height; - private final String id; - @SuppressWarnings("aibolit.P27") - private final String fileName; - @SuppressWarnings({"aibolit.P23", "aibolit.P22"}) - private final String dirName; - /** Pre-set a bitmap for this asset */ - @SuppressWarnings({"aibolit.P23", "aibolit.P11"}) - @Nullable private Bitmap bitmap; - - @RestrictTo(RestrictTo.Scope.LIBRARY) - public LottieImageAsset(int width, int height, String id, String fileName, String dirName) { - this.width = width; - this.height = height; - this.id = id; - this.fileName = fileName; - this.dirName = dirName; - } - - public ArrayList filterWithOptionalEmpty(Long threshold) { - Function filter = last -> { - final Optional size; - if (last >= threshold) { - size = Optional.empty(); - } else { - size = Optional.of(last); - } - return size; - }; - - return array.map(filter); - } -} diff --git a/test/recommend/annotations/OneLineFunction.java b/test/recommend/annotations/OneLineFunction.java deleted file mode 100644 index e4dfb879..00000000 --- a/test/recommend/annotations/OneLineFunction.java +++ /dev/null @@ -1,33 +0,0 @@ -package com.airbnb.lottie; - -import android.graphics.Bitmap; -import androidx.annotation.Nullable; -import androidx.annotation.RestrictTo; - -/** - * Data class describing an image asset exported by bodymovin. - */ -@SuppressWarnings({"aibolit.P23", "aibolit.P11"}) -public class LottieImageAsset { - private final int width; - private final int height; - private final String id; - @SuppressWarnings("aibolit.P27") - private final String fileName; - @SuppressWarnings({"aibolit.P23", "aibolit.P22"}) - private final String dirName; - /** Pre-set a bitmap for this asset */ - @SuppressWarnings({"aibolit.P23", "aibolit.P11"}) - @Nullable private Bitmap bitmap; - - @RestrictTo(RestrictTo.Scope.LIBRARY) - public LottieImageAsset(int width, int height, String id, String fileName, String dirName) { - this.width = width; - this.height = height; - this.id = id; - this.fileName = fileName; - this.dirName = dirName; - } - - public int getWidth() { int a = 0; int b = 0;} -} From 3462bc485671017b6cc8f4c59bcd3ca5b536f1d1 Mon Sep 17 00:00:00 2001 From: Evgeny Maslov Date: Wed, 8 Jul 2020 16:09:15 +0300 Subject: [PATCH 37/44] Fix --- aibolit/__main__.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/aibolit/__main__.py b/aibolit/__main__.py index 4369607c..7957aaf7 100644 --- a/aibolit/__main__.py +++ b/aibolit/__main__.py @@ -38,6 +38,8 @@ from pathlib import Path from sys import stdout from typing import List + +import javalang import numpy as np # type: ignore import requests from lxml import etree # type: ignore @@ -163,7 +165,7 @@ def flatten(l): return [item for sublist in l for item in sublist] -def find_annotation_by_node_type(tree, node_type): +def find_annotation_by_node_type(tree: javalang.tree.CompilationUnit, node_type: javalang.tree.Node): """Search nodes with annotations. :param tree: javalang.tree From 628ed45fd9b03949af8f26f9a667d7319b7fe235 Mon Sep 17 00:00:00 2001 From: Evgeny Maslov Date: Wed, 8 Jul 2020 16:17:21 +0300 Subject: [PATCH 38/44] Fix typing --- aibolit/__main__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/aibolit/__main__.py b/aibolit/__main__.py index 7957aaf7..87a55e16 100644 --- a/aibolit/__main__.py +++ b/aibolit/__main__.py @@ -37,7 +37,7 @@ from os import scandir from pathlib import Path from sys import stdout -from typing import List +from typing import List, Any, Dict import javalang import numpy as np # type: ignore @@ -173,7 +173,7 @@ def find_annotation_by_node_type(tree: javalang.tree.CompilationUnit, node_type: :return dict with annotations, where key is node, value is list of string annotations; """ - annonations = defaultdict(list) + annonations: Dict[Any, Any] = defaultdict(list) for _, node in tree.filter(node_type): if node.annotations: for a in node.annotations: From dc64c29f617c228c78683d6ae531aecb189b64ae Mon Sep 17 00:00:00 2001 From: Evgeny Maslov Date: Wed, 8 Jul 2020 16:23:21 +0300 Subject: [PATCH 39/44] Fix type. Remove type --- aibolit/__main__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/aibolit/__main__.py b/aibolit/__main__.py index 87a55e16..fe4c4f05 100644 --- a/aibolit/__main__.py +++ b/aibolit/__main__.py @@ -165,7 +165,7 @@ def flatten(l): return [item for sublist in l for item in sublist] -def find_annotation_by_node_type(tree: javalang.tree.CompilationUnit, node_type: javalang.tree.Node): +def find_annotation_by_node_type(tree: javalang.tree.CompilationUnit, node_type): """Search nodes with annotations. :param tree: javalang.tree From a3e089d69e34ea3ac0e490fe109f8732b0dfacc7 Mon Sep 17 00:00:00 2001 From: Evgeny Maslov Date: Wed, 8 Jul 2020 17:15:36 +0300 Subject: [PATCH 40/44] dirty temp --- aibolit/__main__.py | 32 ++++++++++++++++++++++- test/recommend/test_recommend_pipeline.py | 23 +++++++++++++++- 2 files changed, 53 insertions(+), 2 deletions(-) diff --git a/aibolit/__main__.py b/aibolit/__main__.py index e0ead5fa..8ee909c5 100644 --- a/aibolit/__main__.py +++ b/aibolit/__main__.py @@ -36,7 +36,7 @@ from os import scandir from pathlib import Path from sys import stdout -from typing import List +from typing import List, Dict, Any import numpy as np # type: ignore import requests from lxml import etree # type: ignore @@ -162,6 +162,36 @@ def flatten(l): return [item for sublist in l for item in sublist] +def add_pattern_if_ignored( + dct: Dict[str, Any], + pattern_item: Dict[Any, Any], + results_list: List[Any]): + """ If pattern code is not ignored, add it to the result list + + :param dct: dict, where key is pattern, value is list of lines range to ignore + :param pattern_item: pattern dict which was get after `inference` function + :param results_list: result list to add + + """ + ignored_lines = dct.get(pattern_item['pattern_code']) + if ignored_lines: + for place in ignored_lines: + # ger liens range of ignored code + start_line_to_ignore = place[0] + end_line_to_ignore = place[1] + new_code_lines = [] + for line in pattern_item['code_lines']: + if (line >= start_line_to_ignore) and (line <= end_line_to_ignore): + continue + else: + new_code_lines.append(line) + pattern_item['code_lines'] = new_code_lines + if len(pattern_item['code_lines']) > 0: + results_list.append(pattern_item) + else: + results_list.append(pattern_item) + + def find_start_and_end_lines(node): max_line = node.position.line diff --git a/test/recommend/test_recommend_pipeline.py b/test/recommend/test_recommend_pipeline.py index 985bb4ba..f1a1c006 100644 --- a/test/recommend/test_recommend_pipeline.py +++ b/test/recommend/test_recommend_pipeline.py @@ -30,7 +30,7 @@ from aibolit.config import Config from aibolit.__main__ import list_dir, calculate_patterns_and_metrics, \ - create_xml_tree, create_text, format_converter_for_pattern, find_start_and_end_lines + create_xml_tree, create_text, format_converter_for_pattern, find_start_and_end_lines, add_pattern_if_ignored class TestRecommendPipeline(TestCase): @@ -255,3 +255,24 @@ def test_find_start_end_line_in_class(self): start, end = find_start_and_end_lines(method) self.assertEqual(start, 11) self.assertEqual(end, 59) + + def test_add_patterns_if_ignored(self): + file = Path(self.cur_file_dir, 'start_end/LottieImageAsset.java') + with open(file, 'r', encoding='utf-8') as f: + tree = javalang.parse.parse(f.read()) + patterns = []{'code_lines': [294, 391], + 'pattern_code': 'P13', + 'pattern_name': 'Null check', + 'importance': 30.95612931128819} + start, end = add_pattern_if_ignored() + self.assertEqual(start, 11) + self.assertEqual(end, 59) + + def test_add_patterns_if_ignored(self): + file = Path(self.cur_file_dir, 'start_end/LottieImageAsset.java') + with open(file, 'r', encoding='utf-8') as f: + tree = javalang.parse.parse(f.read()) + patterns = [] + start, end = add_pattern_if_ignored() + self.assertEqual(start, 11) + self.assertEqual(end, 59) \ No newline at end of file From fd2b02f65bf232c8444282d56137278abfa3eb2d Mon Sep 17 00:00:00 2001 From: Evgeny Maslov Date: Wed, 8 Jul 2020 17:18:31 +0300 Subject: [PATCH 41/44] Fix mypy --- aibolit/__main__.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/aibolit/__main__.py b/aibolit/__main__.py index fe4c4f05..77309356 100644 --- a/aibolit/__main__.py +++ b/aibolit/__main__.py @@ -37,7 +37,7 @@ from os import scandir from pathlib import Path from sys import stdout -from typing import List, Any, Dict +from typing import List, Any, Dict, Tuple import javalang import numpy as np # type: ignore @@ -165,7 +165,9 @@ def flatten(l): return [item for sublist in l for item in sublist] -def find_annotation_by_node_type(tree: javalang.tree.CompilationUnit, node_type): +def find_annotation_by_node_type( + tree: javalang.tree.CompilationUnit, + node_type) -> Dict[Any, Any]: """Search nodes with annotations. :param tree: javalang.tree @@ -173,7 +175,7 @@ def find_annotation_by_node_type(tree: javalang.tree.CompilationUnit, node_type) :return dict with annotations, where key is node, value is list of string annotations; """ - annonations: Dict[Any, Any] = defaultdict(list) + annonations = defaultdict(list) for _, node in tree.filter(node_type): if node.annotations: for a in node.annotations: @@ -191,7 +193,7 @@ def find_annotation_by_node_type(tree: javalang.tree.CompilationUnit, node_type) return annonations -def find_start_and_end_lines(node): +def find_start_and_end_lines(node) -> Tuple[int, int]: max_line = node.position.line def traverse(node): From c7e5029c1e2ce3be86652fa9324452d266d2f161 Mon Sep 17 00:00:00 2001 From: Evgeny Maslov Date: Wed, 8 Jul 2020 17:55:10 +0300 Subject: [PATCH 42/44] Add tests --- aibolit/__main__.py | 4 ++++ test/recommend/test_recommend_pipeline.py | 20 ++++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/aibolit/__main__.py b/aibolit/__main__.py index e6a18701..b7e3badf 100644 --- a/aibolit/__main__.py +++ b/aibolit/__main__.py @@ -37,9 +37,13 @@ from os import scandir from pathlib import Path from sys import stdout +<<<<<<< Updated upstream from typing import List, Any, Dict, Tuple import javalang +======= +from typing import List, Dict, Any, Tuple +>>>>>>> Stashed changes import numpy as np # type: ignore import requests from lxml import etree # type: ignore diff --git a/test/recommend/test_recommend_pipeline.py b/test/recommend/test_recommend_pipeline.py index 9f7ad963..73b1d8e4 100644 --- a/test/recommend/test_recommend_pipeline.py +++ b/test/recommend/test_recommend_pipeline.py @@ -288,3 +288,23 @@ def test_find_annotation_by_field_declaration(self): fields_with_annotations = find_annotation_by_node_type(tree, javalang.tree.FieldDeclaration) patterns_found_with_fields = list(fields_with_annotations.values()) self.assertEqual(patterns_found_with_fields, [['P23'], ['P23', 'P22']]) + + def test_pattern_ignore(self): + pattern_item = {'code_lines': [20], + 'pattern_code': 'P13', + 'pattern_name': 'Null check', + 'importance': 30.95612931128819} + results = [] + pattern_ignored = {'P13': [[10, 20]]} + add_pattern_if_ignored(pattern_ignored, pattern_item, results) + self.assertEqual(results, []) + + def test_pattern_not_ignore(self): + pattern_item = {'code_lines': [20, 30], + 'pattern_code': 'P14', + 'pattern_name': 'Null check', + 'importance': 30.95612931128819} + results = [] + pattern_ignored = {'P14': [[60, 100]]} + add_pattern_if_ignored(pattern_ignored, pattern_item, results) + self.assertEqual(results[0]['code_lines'], pattern_item['code_lines']) From 47ad32ee79237beed5b1aa02d91afe7fb61e7674 Mon Sep 17 00:00:00 2001 From: Evgeny Maslov Date: Wed, 8 Jul 2020 17:57:50 +0300 Subject: [PATCH 43/44] Fix --- aibolit/__main__.py | 4 ---- test/recommend/test_recommend_pipeline.py | 4 ++-- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/aibolit/__main__.py b/aibolit/__main__.py index b7e3badf..e6a18701 100644 --- a/aibolit/__main__.py +++ b/aibolit/__main__.py @@ -37,13 +37,9 @@ from os import scandir from pathlib import Path from sys import stdout -<<<<<<< Updated upstream from typing import List, Any, Dict, Tuple import javalang -======= -from typing import List, Dict, Any, Tuple ->>>>>>> Stashed changes import numpy as np # type: ignore import requests from lxml import etree # type: ignore diff --git a/test/recommend/test_recommend_pipeline.py b/test/recommend/test_recommend_pipeline.py index 73b1d8e4..f1ba8dec 100644 --- a/test/recommend/test_recommend_pipeline.py +++ b/test/recommend/test_recommend_pipeline.py @@ -30,8 +30,8 @@ from aibolit.config import Config from aibolit.__main__ import list_dir, calculate_patterns_and_metrics, \ - create_xml_tree, create_text, format_converter_for_pattern, find_start_and_end_lines, find_annotation_by_node_type, \ - add_pattern_if_ignored + create_xml_tree, create_text, format_converter_for_pattern, find_start_and_end_lines, \ + find_annotation_by_node_type, add_pattern_if_ignored class TestRecommendPipeline(TestCase): From ef9744baf11cfa91b42fb8e738eb174f73d7873f Mon Sep 17 00:00:00 2001 From: Evgeny Maslov Date: Thu, 9 Jul 2020 10:34:51 +0300 Subject: [PATCH 44/44] Fix mypy --- aibolit/__main__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/aibolit/__main__.py b/aibolit/__main__.py index e6a18701..56d1e6f7 100644 --- a/aibolit/__main__.py +++ b/aibolit/__main__.py @@ -168,7 +168,7 @@ def flatten(l): def add_pattern_if_ignored( dct: Dict[str, Any], pattern_item: Dict[Any, Any], - results_list: List[Any]): + results_list: List[Any]) -> None: """ If pattern code is not ignored, add it to the result list :param dct: dict, where key is pattern, value is list of lines range to ignore @@ -179,7 +179,7 @@ def add_pattern_if_ignored( ignored_lines = dct.get(pattern_item['pattern_code']) if ignored_lines: for place in ignored_lines: - # ger liens range of ignored code + # get lines range of ignored code start_line_to_ignore = place[0] end_line_to_ignore = place[1] new_code_lines = []