Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Throw error in generator(Throwing error during code generation process)
Throw error in generator [message #1809744] Mon, 22 July 2019 11:01 Go to next message
Maharajan Nagarajan is currently offline Maharajan NagarajanFriend
Messages: 2
Registered: July 2019
Junior Member
Greetings everyone !

I am trying to generate code, i have to do lot of validation(just throw error) and it should be performed only just prior to generation.

I have created a class with all validation logics inside DeepValidation class
class DeepValidation extends AbstractMemDesignValidator
{
    def init(IResourceDescriptions resDescription)
    {
        //Initializations for validation
    }
    @Check(CheckType.NORMAL)
    def validation()
    {
    // Validation logics
    }
}


I am invoking the above validation in my code generation logic, the function just halts at

...
error('Error', obj, Package.Literals.FEATURE)
...


neither it proceed further nor throws error. The code just halts here !

Background.
1) I have defined proper Grammer
2) I have defined validations, which was working fine.
3) I have defined generator and I was able to generate code properly as expected

Points to consider:
1) I have multiple dsl files (a.dsl, b.dsl, ...)
2) I have multiple grammers in my project ( a.dsl1, b.dsl1, .... a.dsl2, b.dsl2, ....)

My Questions:
1) What is going wrong ? Can't I throw error from generator package ? What is your suggestion ?
Ans: ....

2) I am Injecting IResourceDescriptions in my Generator class
class Generator extends AbstractGenerator implements IGenerator2
{
	@Inject
	IResourceDescriptions  resourceDescription
       override doGenerate(Resource input, IFileSystemAccess2 fsa, IGeneratorContext context)
	{
		var CSourceGenerator sourceCodeGenerator = new CSourceGenerator()
		sourceCodeGenerator.SourceCodeGenerator(resourceDescription, fsa)
	}
}

resourceDescription is loaded(with all data from all dsl files) only after a change in resource. What should I do to load data into resourceDescription immediately after the tool starts ?
Ans: ...

** I am basically from embedded domain, novice in xtext & xtend **
Mit freundlichen Grüßen / Regards
Maha
Re: Throw error in generator [message #1809749 is a reply to message #1809744] Mon, 22 July 2019 13:30 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
hi, i cannot really follow you.
the normal validator is called before the generator already
you can mark the check method with @Check(CheckType.NORMAL) so that they are executed on save/build only
the resourceDescription point i dont understand. which usecase does this target (standalone, eclipse,..., that is the "tool")

p.s. the general pattern is

@Inject
ResourceDescriptionsProvider resourceDescriptionsProvider

override void doGenerate(Resource resource, IFileSystemAccess2 fsa, IGeneratorContext context) {
System.err.println(resourceDescriptionsProvider.getResourceDescriptions(resource))


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de

[Updated on: Mon, 22 July 2019 13:49]

Report message to a moderator

Re: Throw error in generator [message #1809754 is a reply to message #1809749] Mon, 22 July 2019 15:27 Go to previous messageGo to next message
Maharajan Nagarajan is currently offline Maharajan NagarajanFriend
Messages: 2
Registered: July 2019
Junior Member
Thanks for response.

My project is in eclipse environment.

1) I was intend to perform some additional validations(apart from regular validations in validator) at generator. I thought generator is the correct place, to access dsl-data from multiple dsl files.

At validator, I was only able to access dsl-data from one file at a time and my validations are only bound to that particular file. I was not successful in working with multiple dsl-data from multiple dsl files in validator.

I was wondering if validations could be done at the generator. If this is not possible, is there a suggested way If I could seamlessly access whole dsl-data from my model project in validator without impacting the performance.

note: I was using "Generate Code" option in context menu to trigger generator.
2) Consider, I've newly opened the tool(eclipse with my xtext plugin) and the model project is already loaded. Right click on dsl file and press "Generate Code" without any modifications done. resourceDescription content at that moment is null(see below).

class DesignGenerator extends AbstractGenerator implements IGenerator2
{
	@Inject
	IResourceDescriptions  resourceDescription
	
	override doGenerate(Resource input, IFileSystemAccess2 fsa, IGeneratorContext context)
	{
		println(resourceDescription)
		println(resourceDescription.getExportedObjectsByType(DesignPackage.Literals.ENUM_LIST).toList)
	}
}
		
Output:
org.eclipse.xtext.builder.impl.DirtyStateAwareResourceDescriptions@6309e4fb
[]


resourceDescription gets loaded with dsl-data only after there is any modifications done at the dsl file. I was wondering, if there is a way to update resourceDescription with dsl-data during tool/project loading phase itself.

Re: Throw error in generator [message #1809760 is a reply to message #1809754] Mon, 22 July 2019 17:51 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
1) the generator is called for one file too
1b) you May have a look at Xtext & expensive checks

2) are you sure the Enums are in the index


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Previous Topic:Configuring Log4J
Next Topic:Auto-Completion cross-reference from a non-xtext model
Goto Forum:
  


Current Time: Fri Apr 19 11:29:45 GMT 2024

Powered by FUDForum. Page generated in 0.02583 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top