EMFContext

public class EMFContext extends StandaloneContext

A Coco Context that is able to handle EMF Coco elements.

This means that EMF elements can be directly loaded (see the new overrides for loadModule), and coco Node’s can be transformed back to the EMF equivalents.

Constructors

EMFContext

public EMFContext(APIClient client)

Methods

fromNode

public final EObject fromNode(ResourceSet resourceSet, Node node)

Returns the EMF node that corresponds to the given node, assuming that the node is part of a ModuleDecl that has been loaded into this context.

loadModule

public final Node loadModule(ModuleDecl moduleData)

Loads the given module using the specified data as its contents.

Parameters:
  • moduleData – The EMF element for the given module.
Returns:

The root Coco element. If loading fails this will be an invalid node in which case diagnostics will be reported to this Context’s DiagnosticConsumer.

loadModule

public final Node loadModule(ModuleDecl moduleData, boolean log)

printModule

public final String printModule(ModuleDecl moduleData)

Pretty prints the given module without loading it, using the specified data as its contents. This will result in a more human-readable file: for example ‘==’ will be used as opposed to ‘Eq.equals’.

Parameters:
  • moduleData – The EMF element for the given module.
Returns:

The pretty printed version of the module.

printModule

public final String printModule(String fileName)

printModule

public final String printModule(ModuleDecl moduleData, String cocoFormatSpec)

Pretty prints the given module without loading it, using the specified data as its contents. This will result in a more human-readable file: for example ‘==’ will be used as opposed to ‘Eq.equals’.

Parameters:
  • moduleData – The EMF element for the given module.
  • cocoFormatSpec – A Coco format specification given as a JSON dictionary. For example, “{“ColumnLimit”: “120” }”.
Returns:

The pretty printed version of the module.

printModule

public final String printModule(String fileName, String cocoFormatSpec)

toNode

public final Node toNode(BaseNode node)

Returns the internal Coco node that corresponds to the passed EMF node, assuming that the EMF node is part of a ModuleDecl that has been passed to loadModule.

toResource

public final ModuleDecl toResource(Node node)

Exports a node representing a Coco module

Parameters:
  • node – The module node to export.

toResourceSet

public final ResourceSet toResourceSet()

Exports all nodes loaded into this context into a single ResourceSet.