2

Currently I'm modifying a project that uses xText to parse a custom DSL. I want to add functionality to the generated classes but unfortunately I failed implementing the generation gap pattern. I used this article as a basis:

http://heikobehrens.net/2009/04/23/generation-gap-pattern/

My problem is that we're using a lot of Fragments to customize the org.eclipse.xtext.generator.Generator. It seems I cannot reuse those fragments for org.eclipse.xpand2.Generator.

So in conclusion:

  • how can I implement the generation gap pattern for the xtext generator
  • OR how can I use Fragments with the xpand2-Generator
  • OR is there a third solution that allows me to use fragments and implement the generation gap pattern?

After researching the matter, I'm thoroughly confused.

Ed Staub
  • 15,480
  • 3
  • 61
  • 91
Lichtblitz
  • 213
  • 2
  • 10

1 Answers1

2

The generation gap pattern described in the article will work with almost any general purpose code generation framework. Xtext is no exception to this.

Besides that, Xtext offers another nifty solution to fill the generation gap. This is Xbase. But Xbase forces you to tightly integrate with java, so this is not always an alternative.

Consider following steps adding generation gap pattern to the existing Xtext project:

  • Locate generated file with the gap (with the code fragment you want to write by hand). Let it be e.g. MyClass.
  • Alter generator so that
    • the generated file get renamed to the AbstractMyClass.
    • the abstract keyword get added to the AbstractMyClass class definition.
    • the gap get moved to a single method.
    • an abstract method get generated for the gap.
    • the abstract method get called from the generated code.
  • Add 'MyClass extends AbstractMyClass' by hand and implement the abstract gap-method

If you have concrete problems with some Xtend2 code, post questions here or in Xtend forum.

Boris Brodski
  • 8,425
  • 4
  • 40
  • 55
  • I haven't got the slightest clue where to even start. I'm new to xtext and xtend and until now everything worked out of the box. If I switched over to the xtend-Generator how do I add fragments like ` fragment = validation.JavaValidatorFragment { composedCheck = "org.eclipse.xtext.validation.NamesAreUniqueValidator" }` to it? – Lichtblitz Apr 18 '13 at 12:41
  • You mean Workflow (MWE) fragments! Ok, why do you need it? This controls only workflow generator phase. Was your software implemented as a set of such fragments? – Boris Brodski Apr 18 '13 at 13:43