Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » resource descriptions in unit tests
resource descriptions in unit tests [message #879607] Thu, 31 May 2012 14:04 Go to next message
Vlad Dumitrescu is currently offline Vlad DumitrescuFriend
Messages: 431
Registered: July 2009
Location: Gothenburg
Senior Member
Hi!

I tried to write unit tests to check the descriptions for the resources, but I can't make it work with models created from strings.

	
val module = parser.parse('''
     code here
''')
val res = module.eResource
val descriptionIndex = indexProvider.getResourceDescriptions(res)


The descriptionIndex is always empty. I suppose this information is created by the builder and I have to call it first, but how do I do that? Or maybe I am doing it all wrong?

best regards,
Vlad


Re: resource descriptions in unit tests [message #879614 is a reply to message #879607] Thu, 31 May 2012 14:15 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi,

i cannot reproduce this.
can you share a complete runnable example. and make sure you imported the correct ResourceDescriptionsProvider

~Christian


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: resource descriptions in unit tests [message #880006 is a reply to message #879614] Fri, 01 June 2012 09:15 Go to previous messageGo to next message
Vlad Dumitrescu is currently offline Vlad DumitrescuFriend
Messages: 431
Registered: July 2009
Location: Gothenburg
Senior Member
I found the problem: I am declaring several file extensions for the language files and the ParserHelper uses their concatenation when creating a synthetic name for a resource.

	@Inject
	@Named(Constants.FILE_EXTENSIONS)
	public String fileExtension;

I suppose that parsing the value and taking the first extension will fix this. Something like

	protected URI computeUnusedUri(ResourceSet resourceSet) {
		String name = "__synthetic";
                String ext = firstItem(fileExtension)
		for (int i = 0; i < Integer.MAX_VALUE; i++) {
			URI syntheticUri = URI.createURI(name + i + "." + ext);
			if (resourceSet.getResource(syntheticUri, false) == null)
				return syntheticUri;
		}
		throw new IllegalStateException();
	}

	private String firstItem(String list) {
	    list = list.trim();
	    int ix = list.indexOf(',');
            if(ix<0)
                return list;
	    return list.substring(0, ix);
	}

best regards,
Vlad

[Updated on: Fri, 01 June 2012 09:15]

Report message to a moderator

Re: resource descriptions in unit tests [message #880009 is a reply to message #880006] Fri, 01 June 2012 09:21 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Please file a bugzilla

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: resource descriptions in unit tests [message #880021 is a reply to message #880009] Fri, 01 June 2012 09:36 Go to previous message
Vlad Dumitrescu is currently offline Vlad DumitrescuFriend
Messages: 431
Registered: July 2009
Location: Gothenburg
Senior Member
Done! https://bugs.eclipse.org/bugs/show_bug.cgi?id=381335
/Vlad
Previous Topic:How do I create a FOR loop that runs once?
Next Topic:Xtext hangs
Goto Forum:
  


Current Time: Thu Apr 25 18:08:12 GMT 2024

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

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

Back to the top