Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.


Scala compiler plugin template

This project is a template that can be used for creating compiler
plugins for the Scala compiler.

To install the compiler plugin, run "ant install". This will create
an sbaz package for the template plugin and install it in the scala
installation available in your PATH.
The install command will also create a script for running the plugin
as standalone application. The command is called "runplugintemplate"
and available in your scala installation as well.
To uninstall the plugin again, run "and uninstall".

Alternatively, copy the file build/pack/plugintemplate.jar, generated
by "ant pack", to the directory misc/scala-devel/plugins of your
scala distribution. The scala compiler will then find and integrate
the new plugin.

The following files need to be edited when creating a new plugin
- misc/scalac-plugin.xml
- src / test / doc/examples: The source files of the template plugin
  are located a package called "plugintemplate". This will most likely
  be changed for new plugins.

When using eclipse for development, make sure "scala-compiler.jar" is
in the Java Build Path: Right-Click the project and select "Properties".
Then go to "Java Build Path" -> "Libraries" and add the jar file

Traverse, Transform, Check
There are several pre-defined components that can be used to code
the behavior of a plugin:
- TemplateTraverseComponent: a template for tree traversers. Used
  to analyze and collect data about compiler trees.
  -> implement the "check" method

- TemplateTransformComponent: a template for tree transformers.
  -> implement "preTransform" and / or "postTransform"

- TemplateInfoTransformComponent: also a tree transformer, which
  additionally is an InfoTransformer. Allows changing the type
  of some symbols for later phases.
  -> implement "preTransform" and / or "postTransform", and the
     "apply" method of the "infoTransformer".

- TemplateAnnotationChecker: a plugin for the typechecker, useful
  for pluggable type systems. Computes the subtyping between two
  annotated types, and allows providing inferred type information.
  -> implement "annotationsConform" and optionally "addAnnotations"

- TemplateComponent: the most general component. Can do anything it
  likes with the CompilationUnits.
  -> implement the "run" method

Ant tasks
"build.xml" defines Ant tasks for building, testing and packing a
plugin. The tests are written using the ScalaTest framework
Run the tests using "ant test", or "ant guitest".
Something went wrong with that request. Please try again.