Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Custom ResourceDescriptionStrategy - works in Unit Test but not runtime eclipse?
Custom ResourceDescriptionStrategy - works in Unit Test but not runtime eclipse? [message #1446707] Fri, 17 October 2014 07:27 Go to next message
Scott Finnie is currently offline Scott FinnieFriend
Messages: 94
Registered: October 2011
Member
Hi,

I have a custom ResourceDescriptionStrategy which appears to work in a Unit Test - but not when loaded into eclipse Runtime. Would appreciate any suggestions - thanks.

Context: I need to support singular and plural names for Classes in my DSL. RDS as follows:

public class FlujoResourceDescriptionStrategy extends
		DefaultResourceDescriptionStrategy {

	public boolean createEObjectDescriptions(EObject eObject, IAcceptor<IEObjectDescription> acceptor) {

		if (getQualifiedNameProvider() == null)
			return false;
		try  {
			QualifiedName qualifiedName = getQualifiedNameProvider().getFullyQualifiedName(eObject);
			if (qualifiedName != null) {
				acceptor.accept(EObjectDescription.create(qualifiedName, eObject));
			}
						
			if (eObject instanceof Class) {
				LOG.info("adding plural names for " + ((Class)eObject).getName());
				QualifiedName pluralName = ClassExtensions.getPluralQualifiedName((Class) eObject, getQualifiedNameProvider());
				int segments = pluralName.getSegmentCount();
				for (int i=0; i<segments; i++) {
					QualifiedName qn=pluralName.skipFirst(i);
					acceptor.accept(EObjectDescription.create(qn, eObject));					
					LOG.info("added name " + qn.toString());
				}
			}
		} catch (Exception exc) {
			LOG.error(exc.getMessage());
		}
		return true;
	}
}


It's configured in through the runtime module:

public class FlujoRuntimeModule extends org.flujo.AbstractFlujoRuntimeModule {

    @Override
    public void configure(Binder binder) {
    	System.out.println("binding Flujo Resource Description Strategy");
        super.configure(binder);
        binder
            .bind(IDefaultResourceDescriptionStrategy.class)
            .to(FlujoResourceDescriptionStrategy.class);
    }

}


And works in the Unit Test:

	@Test
	def testPluralsInAssociation() {
		val model='''
		    Datatype String {}
		    Datatype Number {}
		    Datatype Pedigree {}
		
		    Class Person plural People {
			    name: String
			    age:  Number
		    }
		
		    Class Dog {
			    name: String
			    pegigree: Pedigree
		    }
			Rel R1 {
				Each Dog "is owned by" zero or more People
				Each Person "owns" one or more Dogs
			}
		'''.parse
		model.assertNoErrors
	}


However: when I run the project in a runtime eclipse instance the same model fails: it can't link up the plurals.

It may be related to the RDS implementation; not sure why I have to register each segment of the plural QualifiedName separately when that's not done for the default case. However, if I don't, then the unit test fails too (unless I use the full QN for the plural reference).

For completeness, here's the relevant grammar rules:

Association:
	('Rel' | 'Relationship' | 'Association') name=REL_ID '{'	
	(roles+=RelRole)*
	'}'
;

RelRole:
	'Each' class1=[Class|QualifiedName] relPhrase=STRING multiplicity=Multiplicity class2=[Class|QualifiedName];

Class:
	"Class" name=ID  ('plural' plural=ID)? "{" 
		features+=Feature*
	"}"
;


Thanks.



Re: Custom ResourceDescriptionStrategy - works in Unit Test but not runtime eclipse? [message #1448607 is a reply to message #1446707] Mon, 20 October 2014 07:07 Go to previous messageGo to next message
Sebastian Zarnekow is currently offline Sebastian ZarnekowFriend
Messages: 3118
Registered: July 2009
Senior Member
Hi Scott,

I don't quite follow your description - especially the part about names
that have to registered per segment. That's not necessary and will
usually cause trouble.
There are two hooks that provide EObject descriptions. The resource
description strategy will provide the exported EObject whereas locally
you have to specialize
ImportedNamespaceAwareLocalScopeProvider.internalGetAllDescriptions(Resource)
and provide the plural forms, too. That should do the trick.

Best,
Sebastian
--
Looking for professional support for Xtext, Xtend or Eclipse Modeling?
Go visit: http://xtext.itemis.com
Re: Custom ResourceDescriptionStrategy - works in Unit Test but not runtime eclipse? [message #1448996 is a reply to message #1448607] Mon, 20 October 2014 19:21 Go to previous message
Scott Finnie is currently offline Scott FinnieFriend
Messages: 94
Registered: October 2011
Member
Hi Sebastia, thanks for the reply.

Sebastian Zarnekow wrote on Mon, 20 October 2014 08:07
Hi Scott,

I don't quite follow your description - especially the part about names
that have to registered per segment. That's not necessary and will
usually cause trouble.


Yes, I thought that was suspicious. It's currently producing each sub-segment of the full QN as a QN and so (presumably) creating separate EObjectDescriptions for each. Which isn't right.

Quote:
There are two hooks that provide EObject descriptions. The resource
description strategy will provide the exported EObject whereas locally
you have to specialize
ImportedNamespaceAwareLocalScopeProvider.internalGetAllDescriptions(Resource)
and provide the plural forms, too. That should do the trick.


Thanks - I think that's the bit I'm missing.

Previous Topic:Problem using DSL formatter
Next Topic:How to add custom compiler settings?
Goto Forum:
  


Current Time: Thu Apr 25 08:41:26 GMT 2024

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

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

Back to the top