def create_sourcefile(self, java_file_path, abs_dir, packagename=""): # pylint:disable=R0201 abs_source_path = os.path.abspath(java_file_path) rel_source_path = os.path.relpath(abs_source_path, abs_dir) filename = os.path.basename(abs_source_path) ast = java.parse(abs_source_path) return SourceFile(abs_source_path, rel_source_path, filename, ast, packagename)
def __init__( self, abs_path, rel_path, name, imports, concrete_classes, abstract_classes, interfaces, enums, ): WSourceFile.__init__(self, abs_path, rel_path, name, ast=None) self.imports = imports self.concrete_classes = concrete_classes self.abstract_classes = abstract_classes self.interfaces = interfaces self.enums = enums self.tles = self._top_level_elements()
def test_parser_returns_private_classes(self): input_ast = javalang.parse.parse("""package dummy; private class pClass1 {} private class pClass2 {} class Class {} """) result = sut.parse(SourceFile("", "", "", input_ast, "")) self.assertEqual(len(result), 3) self.assertEqual(result[0].name, "pClass1") self.assertEqual(result[1].name, "pClass2") self.assertEqual(result[2].name, "Class")
def test_parser_returns_nested_types(self): input_ast = javalang.parse.parse("""package dummy; class Class { class IClass { enum IIEnum { }}}""") result = sut.parse(SourceFile("", "", "", input_ast, "")) self.assertEqual(len(result), 3) self.assertEqual(result[0].name, "Class") self.assertEqual(result[1].name, "IClass") self.assertEqual(result[2].name, "IIEnum")
def test_parser_parses_empty_methods(self): input_ast = javalang.parse.parse("""package dummy; class Class { private static void staticFoo(){} private void foo(){} } """) result = sut.parse(SourceFile("", "", "", input_ast, "")) self.assertEqual(len(result), 1) methods = result[0].methods self.assertEqual(methods[0].name, "staticFoo") self.assertEqual(methods[1].name, "foo")
def test_parser_returns_interface(self): input_ast = javalang.parse.parse("package dummy; interface Test {}") result = sut.parse(SourceFile("", "", "", input_ast, "")) self.assertEqual(len(result), 1) self.assertEqual(result[0].name, "Test")
def test_parser_returns_empty_list_for_none_ast(self): result = sut.parse(SourceFile("", "", "", [], "")) self.assertEqual(len(result), 0)
def __init__(self, abs_path, rel_path, name, types, ast=None): WSourcefile.__init__(self, abs_path, rel_path, name, ast) self.types = types
def __init__(self, abs_path, rel_path, name, change, ast=None): WSourcefile.__init__(self, abs_path, rel_path, name, ast) self.change = change