Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Validator inheritance doesn't seem to work - fails to add inherited EPackage to getEPackages
Validator inheritance doesn't seem to work - fails to add inherited EPackage to getEPackages [message #1710561] Wed, 07 October 2015 14:26 Go to next message
Rene Schneider is currently offline Rene SchneiderFriend
Messages: 2
Registered: October 2015
Junior Member
I have two DSLs: DSL A and B. DSL B "inherits" DSL A by a "grammar BBB with AAA" line in its grammar definition.

DSL A supplies custom validation code in a validator class. The Xtend validator class of DSL B that is generated automatically seems to inherit from DSL A, which is nice Very Happy that's exactly what I intended. But however, the validation code from validator class A was never called.

After some debugging, I found the problem: the method "getEPackages", which apparently should return all the EPackages that a validator is responsible for, was overwritten in validator B and returns only the EPackage of DSL B, but NOT the one from DSL A (even though it inherited all the actual validation methods). I fixed this by manually creating another override in which I return both EPackages, and suddenly, my validator executed validation code for both DSLs Smile.

I'm a bit unsure now as to whether I am simply missing some kind of option for the generation process, or whether this is a bug in the generation process. I traced the code that generates the package list in question to the ValidatorFragment, and found something that might be such a bug:

def getGeneratedPackagesToValidate() {
	grammar.metamodelDeclarations.filter(GeneratedMetamodel).map[EPackage]
}

def protected getRegistryPackagesToValidate() {
	val packages = allEPackagesToValidate(grammar)
	packages.removeAll(allMetamodelDeclarations(grammar).filter(GeneratedMetamodel).map[EPackage].toList
	)
	packages
}


Shouldn't the two segments "grammar.metamodelDeclarations" and "allMetamodelDeclarations(grammar)" be practically identical? The first method finds all "generated" packages, and the second one finds "everything else", which is "everything" minus the "generated" ones.

I'm not very experienced in debugging Xtend code, so I basically left it as it is after finding a solution to my immediate problem. But it still looks strange to me, and I would expect both DSLs to be included in the generated list.
Re: Validator inheritance doesn't seem to work - fails to add inherited EPackage to getEPackages [message #1710745 is a reply to message #1710561] Thu, 08 October 2015 19:44 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14716
Registered: July 2009
Senior Member
Hmmm i actually cannot reproduce that

in my case the following gets generated

	@Override
	protected List<EPackage> getEPackages() {
	    List<EPackage> result = new ArrayList<EPackage>(super.getEPackages());
	    result.add(org.xtext.example.mydslb.myDslB.MyDslBPackage.eINSTANCE);
		return result;
	}


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Validator inheritance doesn't seem to work - fails to add inherited EPackage to getEPackages [message #1710766 is a reply to message #1710745] Fri, 09 October 2015 06:48 Go to previous message
Rene Schneider is currently offline Rene SchneiderFriend
Messages: 2
Registered: October 2015
Junior Member
Oh sorry, you're right. I didn't expect the problem to be in the missing super call, but somehow assumed that the lists themselves would be wrong, so I just investigated into that direction. I re-checked the generation code for that particular super call and found the difference - there's been a commit to the ValidatorFragment on 20 Aug 2014 that specifically added it: https://github.com/eclipse/xtext/commit/2d45d98bc2332760567a37b30385451ab8a30907

Unfortunately, due to project dependency requirements, I still need to use Xtext 2.6.2 for the moment, but that commit isn't included in versions below 2.7.0. So it's basically my fault for being outdated Wink

Thanks for taking a look at this nevertheless!
Previous Topic:[Xtext] Format Converter for Enums
Next Topic:Using several xtext grammars in standalone mode gives errors during doSetup
Goto Forum:
  


Current Time: Sat Sep 21 14:00:52 GMT 2024

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

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

Back to the top