Git Product home page Git Product logo

java-parser's Introduction

Java-Parser

ANTLR based Java parser that writes output to .csv file.

Prerequisites:

Java Runtime Environment 8:

Ubuntu:

sudo apt install default-jre

Windows:

Download:

Download latest .jar file from: Github Releases

Usage:

java -jar <java-parser-x.x.jar> <input-directory-path> [output-file-path.csv]
  • input-directory-path - path to the directory from which .java files will be read. Specifying a path that does not point to a directory results in an error:
/example/path/to/resource is not a directory. Please provide valid directory path.
  • output-file-path.csv - optional, default is output.csv in working directory. Specifying file without extension results in adding .csv:
output => output.csv
output.csv => output.csv
output.txt => output.txt.csv

Examples:

This example is based on code fragment in example resources

  • Run .jar file from cmd with command:
java -jar java-parser-1.1.jar /home/user/example-code /home/user/example-code/output.csv
  • The command logs should look like this:
[main] INFO FileExplorer - Parsed directory: '/home/user/example-code'
[main] INFO FileExplorer - Output file:      '/home/user/example-code/output.csv'
[main] INFO FileExplorer - Parsing file: '/home/user/example-code/Example.java'
[main] INFO DataCollector - Found 6 structures
[main] INFO DataWriter - Saving structures...
[main] INFO FileExplorer - Parsed 1 files
[main] INFO FileExplorer - Found 6 structures
  • Results should appear in folder given previously. The output for this example is here
  • antlr v4 grammar plugin can be used to easily generate structure tree of parsed code

  • Import data using Python:
import pandas as pd

df = pd.read_csv(path_to_output_csv)
df.head()

Recognized structures:

  1. Statements:
  • Method Invocation
  • Return Statement
  • If Then Statement
  • If Then Else Statement
  • Try With Resources Statement
  • Try Statement
  • For Statement
  • Do Statement
  • While Statement
  • Switch Statement
  1. Declarations:
  • Import Declaration
  • Package Declaration
  • Constant Declaration
  • Interface Declaration
  • Enum Declaration
  • Class Declaration
  • Constructor Declaration
  • Field Declaration
  • Method Declaration

Authors

java-parser's People

Contributors

kajkal avatar falanadamian avatar mefffiu avatar jaroslawblak avatar

Stargazers

 avatar  avatar

Watchers

James Cloos avatar  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.