Skip to content


Switch branches/tags

Latest commit


Git stats


Failed to load latest commit information.
Latest commit message
Commit time

🚀 Clarpse

Clarpse is a multi-language architectural code analysis library for building better software tools.


maintained-by Maven Central Java CI codecov License: MIT PRs Welcome

Clarpse facilitates the development of tools that operate over the higher level, architectural details of source code, which are exposed via an easy to use, object oriented API. Checkout the power of Clarpse in striff-lib.


  • Supports Java and GoLang. Development is currently underway for JavaScript(ES6 Syntax), Python, and C#.
  • Light weight
  • Performant
  • Easy to use
  • Clean API built on top of AST
  • Support for parsing 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 A reference between an original component to a target component, which typically exist in the form of import statements, variable declarations, method calls, and so on.

Getting Started

Execute mvn generate-resources to generate necessary Antlr files. Execute mvn clean package assembly:single to compile and build the entire project.

Using The API

Clarpse abstracts source code into a higher level model in a language-agnostic way. This model focuses on the architectural properties of the original code. The code snippet below illustrates how this model can be generated from a ProjectFiles object which represents the source code to be analyzed.

final String code = " package;  "
		       +  " public class SampleClass extends AbstractClass {                                                 "
		       +  "     /** Sample Doc Comment */                                              "
		       +  "     @SampleAnnotation                                                      "
		       +  "     public void sampleMethod(String sampleMethodParam) throws AnException {"   
		       +  "     SampleClassB.fooMethod();
		       +  "     }                                                                      "
		       +  " }                                                                          ";;
final ProjectFiles projectFiles = new ProjectFiles(Lang.JAVA);
projectFiles.insertFile(new ProjectFile("", code));
final ClarpseProject project = new ClarpseProject(projectFiles);
OOPSourceCodeModel generatedSourceModel = project.result();

Note, the ProjectFiles object can be initialized from a local directory, a local zip file, or an input stream to a zip file - see for more information. Next, the compiled OOPSourceCodeModel is the polygot representation of our source code through a collection of Component objects. Details about these components and the relationships between them can be fetched in the following way:

generatedSourceModel.components().forEach(component -> {
	// Check out the Component class for a full list of component attributes that can be retrieved

We can also get specific components by their unique name:

Component mainClassComponent = generatedSourceCodeModel.get("");;           // --> "SampleClass"
mainClassComponent.type();           // --> CLASS
mainClassComponent.comment();        // --> "Sample Doc Comment"
mainClassComponent.modifiers();      // --> ["public"]
mainClassComponent.children();       // --> [""]
mainClassComponent.sourceFile();     // --> ""
mainClassComponent.references();     // --> ["SimpleTypeReference: String", "TypeExtensionReference:", "SimpleTypeReference:"]
// Fetch the the inner method component
methodComponent = generatedSourceCodeModel.get(mainClassComponent.children().get(0));;              // --> "sampleMethod"
methodComponent.type();              // --> METHOD
methodComponent.modifiers();         // --> ["public"]
methodComponent.children();          // --> [""]
methodComopnent.codeFragment();      // --> "sampleMethod(String)"
methodComponent.sourceFile();        // --> ""
methodComponent.references();		 // --> ["SimpleTypeReference: String"]

Contributing A Patch

  • Submit an issue describing your proposed change.
  • Fork the 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.