MCPcopy Create free account
hub / github.com/Persper/code-analytics / prepare_env_class

Function prepare_env_class

persper/graphs/call_graph/java.py:281–339  ·  view source on GitHub ↗

Official Access Level Tutorial: https://docs.oracle.com/javase/tutorial/java/javaOO/accesscontrol.html Node Structure: node can have node or node as its direct child Assumptions and TODOs: 1. We assume every class meth

(class_node, env)

Source from the content-addressed store, hash-verified

279
280
281def prepare_env_class(class_node, env):
282 """
283 Official Access Level Tutorial:
284 https://docs.oracle.com/javase/tutorial/java/javaOO/accesscontrol.html
285
286 Node Structure:
287 <super> node can have <extends> node or <implements> node
288 as its direct child
289
290 Assumptions and TODOs:
291 1. We assume every class method has modifiers (package private is rare)
292 2. We currently don&#x27;t distinguish between `protected` and `public`
293 3. We don't keep record of methods' return types and arguments&#x27; types
294 """
295 class_name = get_name(class_node)
296 filename = class_node.getparent().attrib['filename']
297 # Class members are made of 2 things:
298 # 1. class's variable
299 # 2. class's methods
300 cl_env = {'var': {}, 'method': {}, 'filename': filename}
301 env[class_name] = cl_env
302
303 # `this` and `super`
304 cl_env['var']['this'] = {'is_public': False,
305 'is_static': False,
306 'type': class_name}
307 super_node = class_node.find('./srcml:super', ns)
308 if super_node is not None:
309 extends_node = super_node.find('./srcml:extends', ns)
310 if extends_node is not None:
311 super_cl_name = get_name(extends_node)
312 cl_env['var']['super'] = {'is_public': False,
313 'is_static': True,
314 'type': super_cl_name}
315
316 block_node = class_node.find('./srcml:block', ns)
317
318 # member variables
319 decl_stmt_nodes = block_node.findall('./srcml:decl_stmt', ns)
320 for decl_stmt_node in decl_stmt_nodes:
321 decl_node = decl_stmt_node.find('./srcml:decl', ns)
322 var_name = get_name(decl_node)
323 var_type = get_type(decl_node)
324 specifiers = get_specifiers(decl_node)
325 is_public = 'protected' in specifiers or 'public' in specifiers
326 is_static = 'static' in specifiers
327 cl_env['var'][var_name] = {'is_public': is_public,
328 'is_static': is_static,
329 'type': var_type}
330
331 # member methods
332 func_nodes = block_node.findall('./srcml:function', ns)
333 for func_node in func_nodes:
334 func_name = get_name(func_node)
335 specifiers = get_specifiers(func_node)
336 is_public = 'protected' in specifiers or 'public' in specifiers
337 is_static = 'static' in specifiers
338 cl_env['method'][func_name] = {'is_public': is_public,

Callers 1

prepare_envFunction · 0.70

Calls 3

get_nameFunction · 0.70
get_typeFunction · 0.70
get_specifiersFunction · 0.70

Tested by

no test coverage detected