4. API Documentation¶
The 2 main modules of coastSHARK at the moment are the extract_ast.py
and smartshark_plugin.py
.
The first contains all classes used for AST extraction and the latter contains the code for recursively finding the files in the folder, calling the classes from extract_ast.py and then saving them in the MongoDB. In version 1.0.1 the complexity_java.py
module was added.
It uses the already extracted AST to compute method complexity metrics.
For saving the information into the MongoDB the util.write_mongo
module contains a class that wraps the code for the operations on the pycoshark models.
4.1. util.extract_ast¶
This module contains the AST node types and the classes for extracting them from Java and Python.
The most important classes here are ExtractAstPython and ExtractAstJava.
-
class
util.extract_ast.
ExtractAstJava
(filename)[source]¶ Extracts the AST from .java Files.
Uses the javalang Library.
-
class
util.extract_ast.
ExtractAstPython
(filename)[source]¶ Extracts the AST from .py Files.
Uses the build in ast and the visitor pattern.
-
class
util.extract_ast.
NodePathVisitor
[source]¶ Overwrite ast.NodeVisitor because we also want the level for pretty printing.
This just includes the level for the NodePrintVisitor.
4.2. util.complexity_java¶
In this module we extract complexity measures from Java ASTs.
-
class
util.complexity_java.
ComplexityJava
(compilation_unit_ast)[source]¶ Extracts complexity measures from the AST.
-
cognitive_complexity_sonar
(method)[source]¶ Extract cognitive complexity.
Description here: https://www.sonarsource.com/docs/CognitiveComplexity.pdf
-