Unprotected Blocks

MOFScript supports the notion of unprotected blocks. These blocks are created with the use of the unprotect keyword in the transformation code, as illustrated in the transformation code for operations below.

self.ownedOperation->forEach(o:uml.Operation){
    '\n  'o.visibility' void ' o.name'(){'
    unprotect{
       '    //User code here for operation'
    }
    '  }\n'
}

The resulting code, shown below, represents the unprotected block as comments containing a #BlockStart and a #BlockEnd and an identifier for the source model element.                 

  public void printAuthor(){
//#BlockStart number=4 id=_MeMJULEPEdu-Vepu7rgPLg
  //User code here for operation      
 
//#BlockEnd number=4

  }
Between the block comments, the user can insert or remove code, and the changes will be preserved the next time the transformation is run. All the traces that have references to the file after the block will also be generated in accordance with their new position in the file.