Skip to content
A lightweight polyglot object oriented source code analysis tool.
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.

🚀 Clarpse

Build Status codecov Codacy Badge License PRs Welcome

Clarpse is a lightweight polyglot source code analysis tool designed to represent a codebase as a collection of language agnostic components representing common source code constructs such as classes, methods, and fields. Clarpse exposes these objects via an easy to use, object oriented API.

If you have any questions or are interested in adding new functionality, feel free to create an issue to discuss your thoughts/plans.


  • Supports Java, GoLang and JavaScript(ES6 Syntax).
  • Light weight
  • Performant
  • Easy to use
  • Clean API built on top of AST
  • Support of comments


Term Definition
Component A language independent source unit of the code, typically represented by a class, method, interface, field variable, local variable, enum, etc ..
OOPSourceCodeModel A representation of a codebase through a collection of Component objects.
Component Reference Any given component may contain a number of "Component References" which simply represent its dependency on those referenced components. These references typically exist through import statements, variable declarations, method calls, and so on.

Getting Started

First execute mvn generate-resources to generate neccessary Antlr files. An excellent way to get familiar with Clarpse is to check out some unit tests.

   // Create a new ParseRequestContent Object representing a codebase
   final String code =                       " package;  "
                                               +  " public class SampleClass extends AbstractClass {                                                 "
                                               +  "     /** Sample Doc Comment */                                              "
                                               +  "     @SampleAnnotation                                                      "
                                               +  "     public void sampleMethod(String sampleMethodParam) throws AnException {"   
                                               +  "     SampleClassB.fooMethod();
                                               +  "     }                                                                      "
                                               +  " }                                                                          ";";
    final SourceFiles rawData = new SourceFiles(Lang.JAVA);
    // insert a sample source file
    rawData.insertFile(new RawFile("file2", code));
    final ClarpseProject project = new ClarpseProject(rawData);
    // get the parsed result.
    OOPSourceCodeModel generatedSourceModel = project.result();

The compiled OOPSourceCodeModel is the polygot representation of our project through a collection of Component objects.

 // extract data from the OOPSourceCodeModel's components
 // get the main class component
 Component mainClassComponent = generatedSourceCodeModel.get("");;           // --> "SampleClass"
 mainClassComponent.type();           // --> CLASS
 mainClassComponent.comment();        // --> "Sample Doc Comment"
 mainClassComponent.modifiers();      // --> ["public"]
 mainClassComponent.children();       // --> [""]
 mainClassComponent.sourceFile();     // --> ""
 // get the inner method component
 methodComponent = generatedSourceCodeModel.get(mainClassComponent.getChildren().get(0));;              // --> "sampleMethod"
 methodComponent.type();              // --> METHOD
 methodComponent.modifiers();         // --> ["public"]
 methodComponent.children();          // --> [""]
 methodComopnent.codeFragment();      // --> "sampleMethod(String)"
 methodComponent.sourceFile();        // --> ""

Compile Sources

If you have checkout the project from GitHub you can build the project with maven using:

mvn clean package assembly:single

Latest Version

Clarpse can be pulled in via gradle or maven, and is served using jitpack.


Contributing A Patch

  • Submit an issue describing your proposed change to the repo in question. The repo owner will respond to your issue promptly.
  • Fork the desired repo, develop and test your code changes.
  • Run a local maven build using "clean package assembly:single" to ensure all tests pass and the jar is produced
  • Update the versioning in the pom.xml and using the x.y.z scheme:
    • x = main version number, Increase if introducing API breaking changes.
    • y = feature number, Increase this number if the change contains new features with or without bug fixes.
    • z = hotfix number, Increase this number if the change only contains bug fixes.
  • Submit a pull request.
You can’t perform that action at this time.