1. ExtendJ
  2. ExtendJ
  3. ExtendJ


Clone wiki

ExtendJ / splash2015tutorial

SPLASH 2015 Tutorial on ExtendJ

Slides for this tutorial are here.

Getting started with the Extension Base project

We recommend that you start with these steps early to avoid waiting for downloads during the tutorial.

Download the Extension Base project as a Zip file (~5 MiB download):

curl -LOk https://bitbucket.org/extendj/extension-base/downloads/extension-base.zip
unzip extension-base.zip
cd extension-base

Alternatively, you can use Git (~35 MiB download):

git clone --recursive git@bitbucket.org:extendj/extension-base.git
cd extension-base

Then build using the Bash build script:


Alternatively, you can use Gradle to build. If you don't have Gradle installed, run the Gradle wrapper scripts (will download some libraries and Gradle itself, and then build):


After the build completes you should have a file called extension-base.jar in the project directory. Try running that:

java -jar extension-base.jar testfiles/Test.java

You can also get a printout of the AST by using JavaDumpTree:

java -cp extension-base.jar org.extendj.JavaDumpTree testfiles/Test.java

Then, you can look for these AST classes in the ExtendJ API documentation (see link below), to see what attributes they have.

Experiment with ExtendJ attributes

See the tutorial slides for how to do a simple analyzer that prints the method names in classes.

Add your own attributes

Your next step is to define new computations by defining your own attributes. Get started by adding a new aspect file myAspect.jrag to the directory src/jastadd where you add a simple attribute:

aspect MyAspect {
  syn int CompilationUnit.myAttribute() = 7;

Change the process method in src/jastadd/ExtensionBase.jrag to print the new attribute:

aspect ExtensionBase {
  public void CompilationUnit.process() {
    System.out.println(pathName() + " contained no errors");
    System.out.println("myAttribute is: " + myAttribute());

All .jrag files in src/jastadd are automatically included when you build with gradle. If you use the build.sh script, you need to update it. Rebuild, and run the main program again to see your attribute being printed.

Look at other examples of extensions

See the link to SimpleCFG below.

Useful References

Tool Versions

Versions of tools used in the tutorial:

  • Java 7+ JDK
  • ExtendJ 8.0.1
  • JastAdd 2.1.13
  • JastAddGradle 1.9.9
  • Gradle 2.7