def test_multiple_statements_per_line_method(self): self._test_helper( "multipleStatementsPerLine", [ StatementSemantic(used_methods={"localMethod"}, used_objects={"x"}), StatementSemantic(used_methods={"localMethod"}, used_objects={"y"}), ], )
def test_several_statement_method(self): self._test_helper( "severalStatements", [ objects_semantic("x"), objects_semantic("x"), StatementSemantic(used_objects={"System.out", "x"}, used_methods={"println"}), objects_semantic("x"), StatementSemantic(), ], )
def test_complex_expressions_method(self): self._test_helper( "complexExpressions", [ objects_semantic("x", "y"), objects_semantic("o1", "o2"), StatementSemantic( used_objects={"o1", "x", "y", "z"}, used_methods={"method", "secondMethod"} ), StatementSemantic( used_objects={"o1", "o2", "z"}, used_methods={"method", "thirdMethod", "fourthMethod", "temporalMethod"}, ), ], )
def _create_statement_semantic_stub( statements_qty: int) -> Dict[Statement, StatementSemantic]: graph = DiGraph() return { ASTNode(graph, id): StatementSemantic() for id in range(statements_qty) }
def test_nested_object_method_call_method(self): self._test_helper( "nestedObjectMethodCall", [ StatementSemantic(used_objects={"o.nestedObject"}, used_methods={"method"}) ], )
def test_for_cycle_method(self): self._test_helper( "forCycle", [ objects_semantic("x", "i"), objects_semantic("x", "i", "result"), StatementSemantic() ], )
def _create_statements_semantic( *used_object_name: Union[str, Set[str]] ) -> Dict[Statement, StatementSemantic]: graph = DiGraph() return { ASTNode(graph, id): StatementSemantic(used_objects=object_name if isinstance( object_name, set) else {object_name}) for id, object_name in enumerate(used_object_name) }
def test_switch_branching_method(self): self._test_helper( "switchBranching", [ objects_semantic("x"), objects_semantic("x"), objects_semantic("x"), objects_semantic("x"), StatementSemantic(), ], )
def test_deep_nesting_method(self): self._test_helper( "deepNesting", [ objects_semantic("i"), objects_semantic("i"), StatementSemantic(), StatementSemantic(), StatementSemantic(used_objects={"System.out", "i"}, used_methods={"println"}), StatementSemantic(), StatementSemantic(used_objects={"System.out"}, used_methods={"println"}), StatementSemantic(), StatementSemantic(), StatementSemantic(), ], )
def test_try_block_method(self): self._test_helper( "tryBlock", [ StatementSemantic(), StatementSemantic(), objects_semantic("x", "resource"), StatementSemantic(), StatementSemantic(), objects_semantic("x"), StatementSemantic(), objects_semantic("x"), StatementSemantic(), objects_semantic("x"), StatementSemantic(), ], )
def test_local_method_call_method(self): self._test_helper("localMethodCall", [StatementSemantic(used_methods={"localMethod"})])
def test_continue_statement_method(self): self._test_helper( "continueStatement", [StatementSemantic(), StatementSemantic(), StatementSemantic()] )
def test_break_statement_method(self): self._test_helper("breakStatement", [StatementSemantic(), StatementSemantic(), StatementSemantic()])
def test_synchronized_block_method(self): self._test_helper( "synchronizedBlock", [objects_semantic("x"), objects_semantic("x"), StatementSemantic()] )
def test_do_while_cycle_method(self): self._test_helper("doWhileCycle", [objects_semantic("x"), objects_semantic("x"), StatementSemantic()])
def test_nested_object_method(self): self._test_helper("nestedObject", [StatementSemantic(used_objects={"o.x"})])
def test_block_method(self): self._test_helper("block", [StatementSemantic(), objects_semantic("x"), StatementSemantic()])
def objects_semantic(*objects_names: str) -> StatementSemantic: return StatementSemantic(used_objects=set(objects_names))