Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » How @Inject ParseHelper<> is supposed to work ?
How @Inject ParseHelper<> is supposed to work ? [message #902319] Fri, 17 August 2012 03:35 Go to next message
Cristiano Gavião is currently offline Cristiano GaviãoFriend
Messages: 279
Registered: July 2009
Senior Member
Hi,

I've create a test using only one ParseHelper and it worked. But when I tryed to add two parsers, both points to same class (ParserHelp<Library>). They have different object Id numbers (at debug) but same fileExtension.

In my case Company model is being imported in Library DSL.

I couldn't find where and how ParseHelper is binded.

Could someone explain me?

thanks

class TestComponentTemplateLibraryParsing extends AbstractXtextCommonTest {

	@Inject
	 ParseHelper<Library> parserLibrary

	@Inject
	 ParseHelper<Company> parserOrg
	

[Updated on: Fri, 17 August 2012 03:50]

Report message to a moderator

Re: How @Inject ParseHelper<> is supposed to work ? [message #902326 is a reply to message #902319] Fri, 17 August 2012 05:44 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi,

there is no binding.

you need an

@RunWith(typeof(XtextRunner))
@InjectWith(typeof(MyDslInjectorProvider))

at your class

~Christian


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: How @Inject ParseHelper<> is supposed to work ? [message #902383 is a reply to message #902326] Fri, 17 August 2012 12:02 Go to previous messageGo to next message
Cristiano Gavião is currently offline Cristiano GaviãoFriend
Messages: 279
Registered: July 2009
Senior Member
Hi Christian,

I already have that in my common super class.

@InjectWith(typeof(LibraryDslInjectorProvider))
@RunWith(typeof(XtextRunner))

abstract class AbstractXtextCommonTest {
	
	protected static XtextResourceSet resourceSet



What I would like to know is why both parserLibrary and parserOrg is being filled with the same (ParserHelp<Library>). They have different object Id numbers (at debug) but same fileExtension.
When parsing the organization model I got a classcast exception.
:
@Inject
	 ParseHelper<Library> parserLibrary

	@Inject
	 ParseHelper<Company> parserOrg

@Test
	def void ensureComponentTemplateLibraryFileAreBeingParsed() {
		organization = parseTestFile("tests/data/my.organization", parserOrg)
		assertNotNull(organization)
		library2 = parseTestFile("tests/data/core.analysis.base.library", parserLibrary)
		assertNotNull(library2)
}

Re: How @Inject ParseHelper&lt;&gt; is supposed to work ? [message #902388 is a reply to message #902383] Fri, 17 August 2012 12:21 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi the parse helper is language specific. There was a topic on that
some weeks ago.

--
Need training, onsite consulting or any other kind of help for Xtext?
Go visit http://xtext.itemis.com or send a mail to xtext at itemis dot de


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: How @Inject ParseHelper&lt;&gt; is supposed to work ? [message #902394 is a reply to message #902388] Fri, 17 August 2012 13:03 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Here is a patched parsehelper

public class ParseHelper2<T extends EObject> extends ParseHelper<T> {
	
	public T parse(InputStream in, URI uriToUse, Map<?, ?> options, ResourceSet resourceSet) {
		Resource resource = resourceSet.createResource(uriToUse);
		resourceSet.getResources().add(resource);
		try {
			resource.load(in, options);
			final T root = (T) (resource.getContents().isEmpty() ? null : resource.getContents().get(0));
			return root;
		} catch (IOException e) {
			throw new WrappedException(e);
		}
	}

}


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: How @Inject ParseHelper&lt;&gt; is supposed to work ? [message #902395 is a reply to message #902388] Fri, 17 August 2012 13:04 Go to previous messageGo to next message
Cristiano Gavião is currently offline Cristiano GaviãoFriend
Messages: 279
Registered: July 2009
Senior Member
humm, I've searched the forum for ParseHelper and could not find the topic you talked about.

So I can conclude that I must not use ParseHelper<Company> parserOrg and load the organization model resource using the same resourceset that I used in the ParseHelper<Library>. right ?
Re: How @Inject ParseHelper&lt;&gt; is supposed to work ? [message #902398 is a reply to message #902394] Fri, 17 August 2012 13:13 Go to previous messageGo to next message
Cristiano Gavião is currently offline Cristiano GaviãoFriend
Messages: 279
Registered: July 2009
Senior Member
Christian Dietrich wrote on Fri, 17 August 2012 16:03
Here is a patched parsehelper



Hi,

Well I still in doubt about guice and this ParseHelper2. I don't need to bind the ParseHelper2 ?
Re: How @Inject ParseHelper&amp;lt;&amp;gt; is supposed to work ? [message #902402 is a reply to message #902398] Fri, 17 August 2012 13:20 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi inject parsehelper2 directly

--
Need training, onsite consulting or any other kind of help for Xtext?
Go visit http://xtext.itemis.com or send a mail to xtext at itemis dot de


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: How @Inject ParseHelper&amp;lt;&amp;gt; is supposed to work ? [message #902432 is a reply to message #902402] Fri, 17 August 2012 14:44 Go to previous messageGo to next message
Cristiano Gavião is currently offline Cristiano GaviãoFriend
Messages: 279
Registered: July 2009
Senior Member
I couldn't make it work with ParseHelper2 too... I mean, I can load the resource of main dsl but not its associated model.

I don't understand. In the workflow I have this:
    bean = StandaloneSetup {
            scanClassPath = true
            platformUri = "${runtimeProject}/.."

            registerGeneratedEPackage = "organization.en.organizationDsl.OrganizationDslPackage"
            registerGenModelFile = "platform:/resource/organization.en/src-gen/organization/en/OrganizationDsl.genmodel"
        }


At runtime I can refer to the organization models from library editor without problems.



But at test it seems that organization is not being registered. this part of ParseHelp2 do not work because there isn't a resource factory in the registry:
Resource resource = resourceSet.createResource(uriToUse);


So, how can I load both resources using same resourceset?

regards,

Cristiano

[Updated on: Fri, 17 August 2012 14:46]

Report message to a moderator

Re: How @Inject ParseHelper&amp;amp;lt;&amp;amp;gt; is supposed to work ? [message #902439 is a reply to message #902432] Fri, 17 August 2012 15:02 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Mrke sure that both stand alone setups are called. (E.g. by changing
the injector provider or by calling do setup from within the test

--
Need training, onsite consulting or any other kind of help for Xtext?
Go visit http://xtext.itemis.com or send a mail to xtext at itemis dot de


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: How @Inject ParseHelper&amp;amp;lt;&amp;amp;gt; is supposed to work ? [message #902489 is a reply to message #902439] Fri, 17 August 2012 21:40 Go to previous message
Cristiano Gavião is currently offline Cristiano GaviãoFriend
Messages: 279
Registered: July 2009
Senior Member
Hi Christian,

Create a custom injector provider and calling all the DslStandaloneSetup.doSetup() method inside it was the solution.

Thanks again for the support !

cheers,

Cristiano
Previous Topic:How do you extract DSL out of Java objects?
Next Topic:Infer types for inferred jvm model
Goto Forum:
  


Current Time: Thu Apr 25 03:39:20 GMT 2024

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

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

Back to the top