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']])
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'])