Get the entire AST for this file :param filename str: :param lang_params LanguageParams: :rtype: ast
(filename, lang_params)
| 202 | |
| 203 | @staticmethod |
| 204 | def get_tree(filename, lang_params): |
| 205 | """ |
| 206 | Get the entire AST for this file |
| 207 | |
| 208 | :param filename str: |
| 209 | :param lang_params LanguageParams: |
| 210 | :rtype: ast |
| 211 | """ |
| 212 | version_flag = "--" + lang_params.ruby_version |
| 213 | cmd = ["ruby-parse", "--emit-json", version_flag, filename] |
| 214 | output = subprocess.check_output(cmd, stderr=subprocess.PIPE) |
| 215 | try: |
| 216 | tree = json.loads(output) |
| 217 | except json.decoder.JSONDecodeError: |
| 218 | raise AssertionError( |
| 219 | "Ruby-parse could not parse file %r. You may have a syntax error. " |
| 220 | "For more detail, try running the command `ruby-parse %s`. " % |
| 221 | (filename, filename)) from None |
| 222 | assert isinstance(tree, list) |
| 223 | |
| 224 | if tree[0] not in ('module', 'begin'): |
| 225 | # one-line files |
| 226 | tree = [tree] |
| 227 | return tree |
| 228 | |
| 229 | @staticmethod |
| 230 | def separate_namespaces(tree): |
nothing calls this directly
no outgoing calls
no test coverage detected