Git Product home page Git Product logo

halstead_cyclomatic's Introduction

Halstead Metric and Cyclomatic Complexity for java

calculates Halstead Metric and Cyclomatic Complexity for a given java file

installation

py -m venv venv
venv/Scripts/python -m pip install -r requirements.txt

args

(venv) $ py -m halstead_cyclomatic -h
usage: __main__.py [-h] JAVA_FILE

outputs Halstead metrics and cyclomatic complexity for a given java file

positional arguments:
  JAVA_FILE   path to the java file

options:
  -h, --help  show this help message and exit

examples

java examples can be found in the examples folder

3.java

Java

class Test2 {
    public static void main(String[] args) {
        int[][] a = { { 00, 01 }, { 10, 11 } };
        int i = 99;
        try {
            a[val()][i = 1]++;
        } catch (Exception e) {
            System.out.println(e + ", i=" + i);
        }
    }
    static int val() throws Exception {
        throw new Exception("unimplemented");
    }
}

Output

(venv) $ py -m halstead_cyclomatic examples/3.java
╒═══════════════════════╤═══╕
│ Cyclomatic complexity │ 1 │
╘═══════════════════════╧═══╛

 Halstead Metrics:

╒══════════════════════════════╤═════════════╕
│ Metric                       │       Value │
╞══════════════════════════════╪═════════════╡
│ Number of Distinct Operators │    22       │
├──────────────────────────────┼─────────────┤
│ Number of Distinct Operands  │    20       │
├──────────────────────────────┼─────────────┤
│ Number of Operators          │    67       │
├──────────────────────────────┼─────────────┤
│ Number of Operands           │    27       │
├──────────────────────────────┼─────────────┤
│ Program vocabulary           │    42       │
├──────────────────────────────┼─────────────┤
│ Program length               │    94       │
├──────────────────────────────┼─────────────┤
│ Estimated length             │   184.546   │
├──────────────────────────────┼─────────────┤
│ Purity ratio                 │     1.96326 │
├──────────────────────────────┼─────────────┤
│ Volume                       │   995.131   │
├──────────────────────────────┼─────────────┤
│ Difficulty                   │    14.85    │
├──────────────────────────────┼─────────────┤
│ Program effort               │ 14777.7     │
├──────────────────────────────┼─────────────┤
│ Time required to program     │   820.983   │
├──────────────────────────────┼─────────────┤
│ Number of delivered bugs     │     0.33171 │
╘══════════════════════════════╧═════════════╛

 Operators:

╒════════════╤═════════╕
│ Operator   │   Count │
╞════════════╪═════════╡
│ class      │       1 │
├────────────┼─────────┤
│ {          │       8 │
├────────────┼─────────┤
│ public     │       1 │
├────────────┼─────────┤
│ static     │       2 │
├────────────┼─────────┤
│ void       │       1 │
├────────────┼─────────┤
│ (          │       6 │
├────────────┼─────────┤
│ [          │       5 │
├────────────┼─────────┤
│ ]          │       5 │
├────────────┼─────────┤
│ )          │       6 │
├────────────┼─────────┤
│ int        │       3 │
├────────────┼─────────┤
│ =          │       3 │
├────────────┼─────────┤
│ ,          │       3 │
├────────────┼─────────┤
│ }          │       8 │
├────────────┼─────────┤
│ ;          │       5 │
├────────────┼─────────┤
│ try        │       1 │
├────────────┼─────────┤
│ ++         │       1 │
├────────────┼─────────┤
│ catch      │       1 │
├────────────┼─────────┤
│ .          │       2 │
├────────────┼─────────┤
│ +          │       2 │
├────────────┼─────────┤
│ throws     │       1 │
├────────────┼─────────┤
│ throw      │       1 │
├────────────┼─────────┤
│ new        │       1 │
╘════════════╧═════════╛

 Operands:

╒═════════════════╤═════════╕
│ Operand         │   Count │
╞═════════════════╪═════════╡
│ Test2           │       1 │
├─────────────────┼─────────┤
│ main            │       1 │
├─────────────────┼─────────┤
│ String          │       1 │
├─────────────────┼─────────┤
│ args            │       1 │
├─────────────────┼─────────┤
│ a               │       2 │
├─────────────────┼─────────┤
│ 00              │       1 │
├─────────────────┼─────────┤
│ 01              │       1 │
├─────────────────┼─────────┤
│ 10              │       1 │
├─────────────────┼─────────┤
│ 11              │       1 │
├─────────────────┼─────────┤
│ i               │       3 │
├─────────────────┼─────────┤
│ 99              │       1 │
├─────────────────┼─────────┤
│ val             │       2 │
├─────────────────┼─────────┤
│ 1               │       1 │
├─────────────────┼─────────┤
│ Exception       │       3 │
├─────────────────┼─────────┤
│ e               │       2 │
├─────────────────┼─────────┤
│ System          │       1 │
├─────────────────┼─────────┤
│ out             │       1 │
├─────────────────┼─────────┤
│ println         │       1 │
├─────────────────┼─────────┤
│ ", i="          │       1 │
├─────────────────┼─────────┤
│ "unimplemented" │       1 │
╘═════════════════╧═════════╛

halstead_cyclomatic's People

Contributors

mohamedsaidsallam avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.