Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Scalagen development

Vesa Marttila edited this page · 4 revisions
Clone this wiki locally

Scalagen is based on a simple AST transformation pipeline.

The main logic is defined in com.mysema.scalagen.Converter.

The following declaration declares the conversion pipeline

  private def createConverter(version: ScalaVersion) = {
    new Converter("UTF-8",List[UnitTransformer](
      Rethrows, // unwraps try/catch blocks with simple rethrows
      VarToVal, // changes var to val if no reassignments are done
      Synchronized, // converts synchronized modifier to synchronized block
      RemoveAsserts, // unwraps assertion method calls
      new Annotations(version), // turns Annotation type declarations into normal classes which extend StaticAnnotation
      Enums, // converts Java enum type declarations into Scala enumerations
      Primitives, // modifies primitive type related constants and method calls
      SerialVersionUID, // turns serialVersionUID fields into annotations
      ControlStatements, // transform ForStmt, SwitchEntryStmt and If statements
      CompanionObject, // moves static members into companion objects
      Underscores, // strips off underscore prefixes from field names with related Bean properties
      BeanProperties, // turns field + accessor combinations into @BeanProperty annotated Scala properties
      Properties, // turns field + accessor combinations into annotated Scala properties
      Constructors, // reorders and normalizes constructors
      Initializers, // normalizes initializer blocks
      SimpleEquals)) // simplfies equals method implementations
  }

The transformers extend UnitTransformerBase which provides a template for conversion, the subclasses just override the visitor methods of the AST types that should be converted.

The serialization logic is defined in com.mysema.scalagen.ScalaDumpVisitor.

For new test cases (and fixes) a new Java file can be added into src/test/scala/com/mysema/examples. It will be automatically picked up by the tests.

Something went wrong with that request. Please try again.