Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Validation: Proper way to check for errors in related resources
Validation: Proper way to check for errors in related resources [message #1810037] Mon, 29 July 2019 18:20 Go to next message
Konrad Jünemann is currently offline Konrad JünemannFriend
Messages: 93
Registered: December 2018
Member
Hi,

I got two related files A and B, where B depends on A having no errors. There exists a reference within A to B. Of course, I already validate A and report those errors.

I would now like to create an error in file B, if any errors where reported in A in order to prevent the compilation of unit / file B. What is the proper way to do this?

Right now I implemented it like this:

@Check
def check(Entity ent) {
	val res = ent.eResource
	val validator = res?.resourceServiceProvider?.resourceValidator
	if (validator !== null) {
		val issues = validator.validate(res, CheckMode.ALL, CancelIndicator.NullImpl);
	
		if (issues.exists[it.severity == Severity.ERROR]) {
			// create error here, e.g. "An error in related file A exists."
		}

	}
}


This works, but I am fearful that now resource A is checked multiple times. Is there a better way to implement this?

Thanks,
Konrad
Re: Validation: Proper way to check for errors in related resources [message #1810038 is a reply to message #1810037] Mon, 29 July 2019 18:31 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
i dont think that requirement is a good idea. anyway: you may port the CachingResourceValidatorImpl class from Xtend (https://github.com/eclipse/xtext-xtend) to avoid duplicate validation.
maybe you should move the stuff to IShouldGenerate - where it belongs if you want to prevent generation) instead of doing it as a check


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Validation: Proper way to check for errors in related resources [message #1810064 is a reply to message #1810038] Tue, 30 July 2019 08:29 Go to previous messageGo to next message
Konrad Jünemann is currently offline Konrad JünemannFriend
Messages: 93
Registered: December 2018
Member
Hi Christian,

great, thanks for the hint. The IShouldGenerate Interface worked perfectly. I created my own IShouldGenerate delegator that delegates to EclipseBasedShouldGenerate and adds the necessary dependency check.

Thank you also for the Link to the CachingResourceValidatorImpl - I will look deeper into my validations in order to see, if I can save some performance there.

Regarding your quote:
Quote:
i dont think that requirement is a good idea.

I don't fully understand your reservations here, maybe you can shed some light on this?

In my case, I would like to generate a SQL connection table, which must contain the primary keys of both tables connected to them. There are, thus, dependencies to both connected tables.

Anyway, thanks for your help and effort!

Re: Validation: Proper way to check for errors in related resources [message #1810065 is a reply to message #1810064] Tue, 30 July 2019 08:33 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
i dont understand:

- if a has errors b should not generate
- shouldt then the validation go to b completely
- should you generate a even if it has errors and make the generation more robust?


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Validation: Proper way to check for errors in related resources [message #1810091 is a reply to message #1810065] Tue, 30 July 2019 15:51 Go to previous message
Konrad Jünemann is currently offline Konrad JünemannFriend
Messages: 93
Registered: December 2018
Member
Hi christian,

Sorry for the confusion. Let me try to clear that up.

Standalone setup: We dont generate anything if there is any error in any file. So no problems here.

Eclipse setup (autobuild): It would be nice to generate as many files as possible, even if there are errors, so that the user can check all "unspoiled" files.
In out case we are talking about Entities (E) and Relations (R), from which we want to create DB tables. Relations contain foreign keys for each connected Entity.

So when do we want to generate what?
- E has an error, R has no error: Generate nothing
- E has no error, R has an error: Generate E
- E has no error, R has no error: Generate both

Also consider, that there might be multiple Es per R (E1, E2, ...).
Also, there does not have to be an R, so there are Es that possess no R.

Maybe it would be possible to validate the Relations (and all connected Es) and then only those Entities, that possess no Rs. This could work, but it feels unelegant to me.

Previous Topic:Injected Index Class is always Null in my DerivedStateComputer
Next Topic:Creating custom appender for log4j
Goto Forum:
  


Current Time: Thu Apr 25 21:16:11 GMT 2024

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

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

Back to the top