compare java source files as logical structure
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.

Compare java source files as logical structure

About differentia-javaica

TL;DR parse Abstract Syntax Tree (AST) of generated Java source and compare the structure with AST of expected source.

This utility was born some years ago when I was writing huge amount of code generators for our toolchain at Nordic Consulting & Development Company. It was part of our Model Driven Architecture approach where UML models and product metadata were used to generate updatable domain model, data access layer, parts of UI, etc.

Each generator was accompanied with test suites verifying generated source code by comparing it to expected Java files. While the generators were being develop continuously, I discovered that just comparing textual content is not flexible enough and instead we have to verify the logical structure of generated code.

Note: this project is only supporting Java 1.5. These days I would rather use:



ANTLR stands for ANother Tool for Language Recognition, perfect tool for building parsers for any possible languages. In our case it produces Java AST.


This project provides very handy ANTLRv3 AST grammar for Java 1.5.


Command Line

While having differentia-javaica jar in your classpath run:

$ java pl.ncdc.differentia.Differentia src1 src2


import static com.xemantic.differentia.DifferentiaAssert.assertSourcesEqual;

public class CodeGeneratorTest {
  public void shouldGenerateCode() {
    assertSourcesEqual("expected/com/company/", "actual/com/company/");