pod afPlastic

(Internal) A library for dynamically generating and compiling Fantom code

Mixins

SrcCodeErr

A mixin for Errs that report errors in source code.

Classes

PlasticClassModel

Models a Fantom class.

PlasticCompiler

Compiles Fantom source code and afPlastic models into usable Fantom code.

PlasticCtorModel

Models a Fantom ctor.

PlasticFacetModel

Models a Fantom facet.

PlasticFieldModel

Models a Fantom field.

PlasticMethodModel

Models a Fantom method.

PlasticUsingModel

Models a Fantom using statement.

SrcCodeSnippet

Generates snippets of source code, often used to report errors.

TypeCache

Converts Java types to more usable Str signatures.

Enums

PlasticVisibility

A list of Fantom visibilities.

Errs

PlasticCompilationErr

As throw by PlasticCompiler should Fantom code compilation fail.

PlasticErr

As throw by afPlastic.

Overview

Plastic is a support library that aids Alien-Factory in the development of other libraries, frameworks and applications. Though you are welcome to use it, you may find features are missing and the documentation incomplete.

Plastic is a library for dynamically generating and compiling Fantom code.

Plastic is the cornerstone of IoC proxied services and Embedded Fantom (efan) templates.

Install

Install Plastic with the Fantom Repository Manager ( fanr ):

C:\> fanr install -r http://repo.status302.com/fanr/ afPlastic

To use in a Fantom project, add a dependency to build.fan:

depends = ["sys 1.0", ..., "afPlastic 1.0+"]

Documentation

Full API & fandocs are available on the Status302 repository.

Quick Start

model := PlasticClassModel("MyClass", true)
model.addMethod(Str#, "greet", "Str name", """ "Hello \${name}!" """)

model.toFantomCode // -->

// const class MyClass {
//   new make(|This|? f := null) {
//     f?.call(this)
//   }
//
//   sys::Str greet(Str name) {
//      "Hello ${name}!"
//   }
// }

myType := PlasticCompiler().compileModel(model)
myType.make->greet("Mum")

// --> Hello Mum!

Release Notes

v1.0.18

  • Bug: Java types could not be used as fields or method return types. See BitBucket Issue: Error using java class
  • Bug: Fields could not have get and set bodies with an intial value.

v1.0.16

v1.0.14

  • New: Plastic now attempts to guess the default values for overridden methods.
  • New: Compiled Pod code is logged at debug level.
  • Chg: Now depends on Bean Utils for guessing the default values.

v1.0.12

  • New: Added PlasticCompiler.compileModels() for compiling multiple models at once.
  • Chg: Deprecated PlasticClassModel.extendClass() and PlasticClassModel.extendMixin() in favour of a single extend() method.
  • Chg: Exposed the lists in PlasticClassModel.

v1.0.10

  • New: Added PlasticUsingModel.

v1.0.8

v1.0.6

  • New: Added PlasticFacetModel to classes, ctors, methods and fields.
  • New: Added PlasticClassModel.hasField(Str name)

v1.0.4

  • New: Fields can have init values.
  • Chg: the PlasticClassModel add methods now return sub-model classes.
  • Chg: Fantom compilation is silent to reduce noise on std out. We raise afPlastic Errs in event of a compilation failure.
  • Bug: Fields can not be const if they have a getter.

v1.0.2

  • New: Added ctor models.
  • New: Updates to ensure backwards compatibility with IoC.
  • Chg: Made PlasticCompiler.srcCodePadding mutable so it may be (re)set by afBedSheet.
  • Chg: Added msg() to SrcCodeErr so Err msgs can be reported.
  • Bug: The wrong compilation line could be reported in PlasticErr.toStr()

v1.0.0

  • New: Initial release.
  • Chg: Plastic was jail breaked from IoC and updated for use by efan