Using utility class in generator leads to compilation errors

Hi,

I am working on a generator for my DSL. I've created a utility class 'GeneratorUtils' in a model 'util'  and added it as a dependency to my generator, like the documentation has recommended: "Create a new model inside the generator. Make sure it does not have the generator stereotype attached to it. The model should typically depend on BaseLanguage so that you can create classes in it. The original generator model should then import the utility model.") I also followed the "Generator User Guide Demo5", where a utility class is used in a post-processing script.

In my generator, I want to use methods from GeneratorUtils in a macro, such as 'GeneratorUtils.method()'. But after rebuilding my language I receive compilation errors:

"The import of generator.util.GeneratorUtils cannot be resolved."

 

Is it not possible to use a utility class in a macro or why does it not work?

 

I hope someone can help me. Thanks!

 

7 comments
Comment actions Permalink

Hi,

this must be something particular to your generator, as this approach is supposed to work as described in the doc, including calling the utility methods from within macros.

Do you get those when compiling your language or when rebuilding the sandbox solution? Are you using generation plans?

Vaclav

 

1
Comment actions Permalink

Hi,

thanks for your reply.

I think I should explain some details of my generator: I have a DSL called 'RoleAnnie' and a DSL called ' Documents'. With 'Documents' I can create a 'document file' and afterwards it is generated to text. This works perfectly. In the 'RoleAnnie' generator, I want to transform to a 'document file' and then generate text. Therefor, I added in main@generator a 'Document_Fiile' based on my 'Documents' DSL, and in 'main' I registered a root mapping rule for my root concept 'Roles' to the 'Document_File'. In the 'Document_File' I started to use some macros and to use my utility class as well. Here are some images:

 

 

To answer your questions: 

When I compile the 'RoleAnnie' DSL, I get compilation problems in main/QueriesGenerated.java: 'The import RoleAnnie.generator.util.GeneratorUtils cannot be resolved'.

When rebuilding the sandbox solution, I receive 'Couldn't compute generation steps for model 'Role.sandbox', which is caused by java.lang.NoClassDefFoundError: main/QueriesGenerated'.

I don't use generation plans and I don't know what this is.

Just one last information: If I delete the 'GeneratorUtils.method()' calls in the macros, the compiling of the language, the rebuilding of the sandbox solution, and also the generation works perfectly without any errors.

 

Regards,

Annika

0
Comment actions Permalink

So, the problem is not being able to compile the generator - "When I compile the 'RoleAnnie' DSL, I get compilation problems in main/QueriesGenerated.java: 'The import RoleAnnie.generator.util.GeneratorUtils cannot be resolved'."

Do you "rebuild" the whole RoleAnnie language? Are there any other error messages reported? What if you rebuild the "util" model explicitly?

Vaclav

 

1
Comment actions Permalink

Hi,

 

I rebuild the whole language and then I receive the following error messages:

[jetbrains.mps.make.CompilationErrorsHandler@410088e] Compilation problems

[jetbrains.mps.make.CompilationErrorsHandler@410088e] main/QueriesGenerated.java : The import RoleAnnie.generator.util.GeneratorUtils cannot be resolved (line: 14)
[jetbrains.mps.make.CompilationErrorsHandler@410088e] main/QueriesGenerated.java : GeneratorUtils cannot be resolved (line: 135)
Compilation finished: 2 errors, 0 warnings.
Error executing target jetbrains.mps.make.facets.JavaCompile.compile
Rebuild failed. See previous messages for details.

 

If I only rebuild the "util" model, I receive the same error messages. Also rebuilding the generator itself, leads to the same messages.

 

Regards,

Annika

0
Comment actions Permalink

Can I see the GeneratorUtils class itself? Are there any errors reported from it?

Alternatively, can you share the project so II can have a look at it?

Vaclav

 

1
Comment actions Permalink

Hi,

 

I solved  this. Actually, I was a little bit stupid. My GeneratorUtils class was a template and not a java class. So I changed this and everything works perfectly. Thank you so much for your time and I hope I didn't bother you.

 

Regards,

Annika

0
Comment actions Permalink

Good to hear you succeeded!

0

Please sign in to leave a comment.