def test_variable_inside_lambda(self): filepath = self.current_directory / "16.java" ast = AST.build_from_javalang(build_ast(filepath)) pattern = VarMiddle() lines = pattern.value(ast) self.assertEqual(lines, [])
def test_else_bad(self): pattern = VarMiddle() lines = pattern.value(os.path.dirname(os.path.realpath(__file__)) + '/14.java') self.assertEqual(lines, [88])
def test_variable_after_curly_braces(self): filepath = self.current_directory / "15.java" ast = AST.build_from_javalang(build_ast(filepath)) pattern = VarMiddle() lines = pattern.value(ast) self.assertEqual(lines, [])
def test_variable_declared_after_for(self): filepath = self.current_directory / "10.java" ast = AST.build_from_javalang(build_ast(filepath)) pattern = VarMiddle() lines = pattern.value(ast) self.assertEqual(lines, [11])
def test_variable_inside_lambda(self): pattern = VarMiddle() lines = pattern.value( os.path.dirname(os.path.realpath(__file__)) + '/16.java') self.assertEqual(lines, [])
def test_case_autoclosable(self): filepath = self.current_directory / "5.java" ast = AST.build_from_javalang(build_ast(filepath)) pattern = VarMiddle() lines = pattern.value(ast) self.assertEqual(lines, [])
def test_declaration_after_super_class_method_call(self): filepath = self.current_directory / "7.java" ast = AST.build_from_javalang(build_ast(filepath)) pattern = VarMiddle() lines = pattern.value(ast) self.assertEqual(lines, [14])
def test_case_with_empty_lines(self): pattern = VarMiddle() lines = pattern.value(os.path.dirname(os.path.realpath(__file__)) + '/4.java') self.assertEqual(lines, [])
def test_case_autoclosable(self): pattern = VarMiddle() lines = pattern.value(os.path.dirname(os.path.realpath(__file__)) + '/5.java') self.assertEqual(lines, [])
def test_bad_class(self): pattern = VarMiddle() lines = pattern.value(os.path.dirname(os.path.realpath(__file__)) + '/2.java') self.assertEqual(lines, [9, 16])
def test_case_with_multiline_method_declaration(self): pattern = VarMiddle() lines = pattern.value(os.path.dirname(os.path.realpath(__file__)) + '/3.java') self.assertEqual(lines, [])
def test_good_class(self): pattern = VarMiddle() lines = pattern.value( os.path.dirname(os.path.realpath(__file__)) + '/1.java') assert lines == []
def test_declaration_after_super_class_method_call(self): pattern = VarMiddle() lines = pattern.value( os.path.dirname(os.path.realpath(__file__)) + '/7.java') self.assertEqual(lines, [14])
def test_annotation_with_parameters(self): pattern = VarMiddle() lines = pattern.value( os.path.dirname(os.path.realpath(__file__)) + '/17.java') self.assertEqual(lines, [22])
def test_annotation_with_parameters(self): filepath = self.current_directory / "17.java" ast = AST.build_from_javalang(build_ast(filepath)) pattern = VarMiddle() lines = pattern.value(ast) self.assertEqual(lines, [22])
def test_case_nested_class(self): pattern = VarMiddle() lines = pattern.value(os.path.dirname(os.path.realpath(__file__)) + '/6.java') self.assertEqual(lines, [10, 22, 30, 33])
def test_case_with_multiline_method_declaration(self): filepath = self.current_directory / "3.java" ast = AST.build_from_javalang(build_ast(filepath)) pattern = VarMiddle() lines = pattern.value(ast) self.assertEqual(lines, [])
def test_for_scope_bad(self): pattern = VarMiddle() lines = pattern.value(os.path.dirname(os.path.realpath(__file__)) + '/9.java') self.assertEqual(lines, [11])
def test_case_nested_class(self): filepath = self.current_directory / "6.java" ast = AST.build_from_javalang(build_ast(filepath)) pattern = VarMiddle() lines = pattern.value(ast) self.assertEqual(lines, [30, 33])
def test_variable_declared_after_for(self): pattern = VarMiddle() lines = pattern.value(os.path.dirname(os.path.realpath(__file__)) + '/10.java') self.assertEqual(lines, [11])
def test_for_scope_bad(self): filepath = self.current_directory / "9.java" ast = AST.build_from_javalang(build_ast(filepath)) pattern = VarMiddle() lines = pattern.value(ast) self.assertEqual(lines, [11])
def test_catch_good(self): pattern = VarMiddle() lines = pattern.value(os.path.dirname(os.path.realpath(__file__)) + '/12.java') self.assertEqual(lines, [])
FILEPATH_TO_READ = '/01/found-java-files.txt' DIR_TO_CREATE = '03' FILE_TO_SAVE = 'patterns.csv' current_location: str = os.path.realpath( os.path.join(os.getcwd(), os.path.dirname(__file__)) ) pattern_for = NestedBlocks(2, BlockType.FOR) pattern_if = NestedBlocks(2, BlockType.IF) pattern_var_middle = VarMiddle() data = [] with open(current_location + FILEPATH_TO_READ) as fp: for line in fp.readlines(): filename = line.strip() var_middle = list(map(format_f, pattern_var_middle.value(filename))) nested_fors = list(map(format_f, pattern_for.value(filename))) nested_ifs = list(map(format_f, pattern_if.value(filename))) data += [( filename, ';'.join(nested_fors), ';'.join(nested_ifs), ';'.join(var_middle) )] if not os.path.isdir(DIR_TO_CREATE): os.makedirs(DIR_TO_CREATE) pd.DataFrame( data, columns=['filename', 'for2', 'if2', 'var_middle'] ).to_csv( current_location + '/' + DIR_TO_CREATE + '/' + FILE_TO_SAVE,
def test_variable_after_curly_braces(self): pattern = VarMiddle() lines = pattern.value( os.path.dirname(os.path.realpath(__file__)) + '/15.java') self.assertEqual(lines, [])