Esempio n. 1
0
 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, [])
Esempio n. 2
0
 def test_else_bad(self):
     pattern = VarMiddle()
     lines = pattern.value(os.path.dirname(os.path.realpath(__file__)) + '/14.java')
     self.assertEqual(lines, [88])
Esempio n. 3
0
 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, [])
Esempio n. 4
0
 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])
Esempio n. 5
0
 def test_variable_inside_lambda(self):
     pattern = VarMiddle()
     lines = pattern.value(
         os.path.dirname(os.path.realpath(__file__)) + '/16.java')
     self.assertEqual(lines, [])
Esempio n. 6
0
 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, [])
Esempio n. 7
0
 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])
Esempio n. 8
0
 def test_case_with_empty_lines(self):
     pattern = VarMiddle()
     lines = pattern.value(os.path.dirname(os.path.realpath(__file__)) + '/4.java')
     self.assertEqual(lines, [])
Esempio n. 9
0
 def test_case_autoclosable(self):
     pattern = VarMiddle()
     lines = pattern.value(os.path.dirname(os.path.realpath(__file__)) + '/5.java')
     self.assertEqual(lines, [])
Esempio n. 10
0
 def test_bad_class(self):
     pattern = VarMiddle()
     lines = pattern.value(os.path.dirname(os.path.realpath(__file__)) + '/2.java')
     self.assertEqual(lines, [9, 16])
Esempio n. 11
0
 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, [])
Esempio n. 12
0
 def test_good_class(self):
     pattern = VarMiddle()
     lines = pattern.value(
         os.path.dirname(os.path.realpath(__file__)) + '/1.java')
     assert lines == []
Esempio n. 13
0
 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])
Esempio n. 14
0
 def test_annotation_with_parameters(self):
     pattern = VarMiddle()
     lines = pattern.value(
         os.path.dirname(os.path.realpath(__file__)) + '/17.java')
     self.assertEqual(lines, [22])
Esempio n. 15
0
 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])
Esempio n. 16
0
 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])
Esempio n. 17
0
 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, [])
Esempio n. 18
0
 def test_for_scope_bad(self):
     pattern = VarMiddle()
     lines = pattern.value(os.path.dirname(os.path.realpath(__file__)) + '/9.java')
     self.assertEqual(lines, [11])
Esempio n. 19
0
 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])
Esempio n. 20
0
 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])
Esempio n. 21
0
 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])
Esempio n. 22
0
 def test_catch_good(self):
     pattern = VarMiddle()
     lines = pattern.value(os.path.dirname(os.path.realpath(__file__)) + '/12.java')
     self.assertEqual(lines, [])
Esempio n. 23
0
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,
Esempio n. 24
0
 def test_variable_after_curly_braces(self):
     pattern = VarMiddle()
     lines = pattern.value(
         os.path.dirname(os.path.realpath(__file__)) + '/15.java')
     self.assertEqual(lines, [])