New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

java-complexity

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

java-complexity

This tool approximates the [cyclomatic complexity](https://en.wikipedia.org/wiki/Cyclomatic_complexity) of a snippet of Java code, based loosely on [these rules](https://www.leepoint.net/principles_and_practices/complexity/complexity-java-method.html).

latest
Source
npmnpm
Version
0.8.0
Version published
Maintainers
1
Created
Source

java-complexity

This tool approximates the cyclomatic complexity of a snippet of Java code, based loosely on these rules.

const javaComplexity = require('java-complexity');

const input = `
void main() {
    int number = 5;
    double pi = 22.0 / 7.0;

    if (number < 0) return;

    switch (number) {
    case 'a': break;
    case 2: break;
    case 5:
        System.out.println("pi is " + (pi > 3 ? "higher" : "lower") + " than 3.");
        break;
    default: break;
    }
}
`

const complexity = javaComplexity(input) // => { complexityValues: { main: 6 }, total: 6 }

When invoked from the command line, java-complexity reads input from stdin.

API

javaComplexity(input, [suppressErrors], [root])

input is a string of Java code to process. suppressErrors is an optional flag that will suppress error logging. root is an optional (string) root grammar rule.

This function returns a map of method names to cyclomatic complexity values. Unless root is specified, it attempts to parse the input as

  • an entire compilation unit (i.e package declaration, imports and class definitions)
  • the inside of a class body
  • the inside of a method

If all of these fail, the function returns null.

Invoking from the command-line

java-complexity [-s] [input]

The -s flag suppresses error logging. If input is not provided as an argument, it is read from stdin. This program exits with code 1 if it fails to parse the input string.

FAQs

Package last updated on 10 Apr 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts