Skip to content

McConnell’s simplified approach for complexity analysis using java

Notifications You must be signed in to change notification settings

aman224/ComplexityAnalyser

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ComplexityAnalyser

Advanced Software Engineering COMP5911M CourseWork 2 Q4 complexity calculator

Introduction

This application calculates the average and maximum complexity of classes / files using McConnell’s simplified approach for complexity analysis. We make use of antlr4 which is a tool that can be used to generate a parser based on a given grammar. This tool had been used to generate a parser for parsing Java and Python code (more language support may be added). The grammar used is the grammar for java and python provided by antlr4. More information about the parser generation is given in the section Parser Generation.

Requirements

  • Java 11+

How to Build

This application uses gradle to build the jar file. To build the application follow the below steps

  1. Navigate to the root directory of the zip file

  2. Run the command

    ./gradlew build

This will generate a .jar file inside the ./build/libs folder called task2-1.0-SNAPSHOT.jar

Running the application

Navigate to the directory with the .jar file that was build in the previous step.

cd /path/to/jar/file

Run the command

java -jar task2-1.0-SNAPSHOT.jar <directory_argument> <file_types_argument>

Parameters

The application takes two command line arguments to run

  • directory_argument: The directory to be considered for the complexity analysis. If the directory argument is not given the current working directory will be considered for the analysis
  • file_types_argument: A list of the file extensions to be analysed. Currently supported [java, py]. If the argument is not given a default value of java is assumed if not specified.

eg:

java -jar task2-1.0-SNAPSHOT.jar /home/tmp/ java py

This code snippet will find the complexity of all java and python files in the /home/tmp/ directory

Run Tests

The unit tests for the application can be run using

./gradlew test

Parser Generation

We use antlr4 to generate parsers for any given programming languages. This version of the application contains parsers for java and python. The .g4 files used for generating the parser has been provided in the src/main/antlr4 folder. The command to generate the parser is given below

antlr4 -o <output_path> -package <parser_output_package_name> -listener -visitor -lib <location_grammars> <grammar_path>
  • output_path: Specifies the output location of the generated parser
  • parser_output_package_name: Specifies the package name to be used for the generated parser java files
  • location_grammars: Specifies the directory where the grammar files are located
  • grammar_path: Specifies the path to the .g4 grammar file to be used to generate the parser

Please note this requires antlr4 to be installed in the system.

Output

Upon running the application a report will be generated in the console with the average and maximum complexity of all classes in the specified directory. Please note the absolute path of each class will be used to display the results.

About

McConnell’s simplified approach for complexity analysis using java

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published