Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Couldn't resolve reference to PanelType 'NavigationBar'(Value is added through autocompletion but cannot be resolved)
Couldn't resolve reference to PanelType 'NavigationBar' [message #1800718] Mon, 07 January 2019 08:26 Go to next message
Bert Roos is currently offline Bert RoosFriend
Messages: 6
Registered: January 2019
Junior Member
Hi,

I'm doing a little experiment with Xtext.

In my grammar, I have this:
Panel:
	'panel' '(' ('type' ':' type=[PanelType] ')'	
;

PanelType: name=ID;


My test involves trying to provide a set of values for different types of panels. To accomplish that, I wrote a simple scope provider:

class LayoutScopeProvider extends AbstractLayoutScopeProvider {
	val panelTypes = newArrayList('NavigationBar', 'Patients', 'Results', 'Result', 'Chats', 'Chat')

	override getScope(EObject context, EReference reference) {
		if (context instanceof Panel && reference == LayoutPackage.Literals.PANEL__TYPE) {
			val eclass = reference.eClass
			return MapBasedScope.createScope(IScope.NULLSCOPE, panelTypes.stream().map(n|QualifiedName.create(n)).map([ qn |
				EObjectDescription.create(qn, eclass)]).collect(Collectors.toList));
		}
		return super.getScope(context, reference);
	}
}


With this scope provider, autocompletion works, resulting in a line like this:
panel ( type : NavigationBar )


However, Eclipse shows an error:
Couldn't resolve reference to PanelType 'NavigationBar'.


Any idea what I'm doing wrong?

Thanks in advance,
Bert
Re: Couldn't resolve reference to PanelType 'NavigationBar' [message #1800749 is a reply to message #1800718] Mon, 07 January 2019 19:13 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14664
Registered: July 2009
Senior Member
I don't understand your code.
You don't reference panel types. In your scope.
You reference to Paneltype Eclass (Switch metalevels)
This makes no sense to me


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Couldn't resolve reference to PanelType 'NavigationBar' [message #1800777 is a reply to message #1800749] Tue, 08 January 2019 07:42 Go to previous messageGo to next message
Bert Roos is currently offline Bert RoosFriend
Messages: 6
Registered: January 2019
Junior Member
Hi Christian,

I think I understand what you mean, but I'm totally new to Xtext and Xtend, so please bear with me.
As you might have derived from my code, I intend to create panel types through code rather than defining them in the DSL. I thought an EObjectDescription was representing something on the metalevel of the DSL and I thought I could instantiate that by creating an EObjectDescription instance through calling EObjectDescription.create with an EClass.

Do you have any pointers to material that describes the right way to do what I want to do?

Thanks in advance,
Bert
Re: Couldn't resolve reference to PanelType 'NavigationBar' [message #1800778 is a reply to message #1800777] Tue, 08 January 2019 07:52 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14664
Registered: July 2009
Senior Member
You should create EObjects Descriptions that point to PanelType no to EClass

thus i would have exepcted something line MyDslFactory.eINSTANCE.createPanelType()=>[name="somename"]


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Couldn't resolve reference to PanelType 'NavigationBar' [message #1800800 is a reply to message #1800778] Tue, 08 January 2019 13:51 Go to previous messageGo to next message
Bert Roos is currently offline Bert RoosFriend
Messages: 6
Registered: January 2019
Junior Member
Thanks Christian!
That brings me a step forward, I believe. I've changed the code into this:
class LayoutScopeProvider extends AbstractLayoutScopeProvider {
	val panelTypes = createPanelTypes()

	override getScope(EObject context, EReference reference) {
		if (context instanceof Panel && reference == LayoutPackage.Literals.PANEL__TYPE) {
			return MapBasedScope.createScope(IScope.NULLSCOPE, panelTypes);
		}
		return super.getScope(context, reference);
	}

	def static createPanelTypes() {
		val panelTypeNames = newArrayList('NavigationBar', 'Patients', 'Results', 'Result', 'Chats', 'Chat')
		return panelTypeNames.stream().map([ n |
			EObjectDescription.create(QualifiedName.create(n), LayoutFactory.eINSTANCE.createPanelType() => [name = n])
		]).collect(Collectors.toList)
	}
}


Now I get a different error message:
The feature 'type' of 'com.us.dsl.layout.impl.PanelImpl@4ae0e2dc{platform:/resource/MyDslTest/Patient.phlayout#//@elements.0}'
   contains a dangling reference 'com.us.dsl.layout.impl.PanelTypeImpl@373442ad{#//}'


According to this forum posting, I should implement an IResourceServiceProvider. Unfortunately, that article does have any information on how to do this. It mentions GenericResourceServiceProvider, but the JavaDoc for that class is nearly empty and Google doesn't find any examples.

Do you have any suggestions?
Re: Couldn't resolve reference to PanelType 'NavigationBar' [message #1800802 is a reply to message #1800800] Tue, 08 January 2019 14:02 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14664
Registered: July 2009
Senior Member
no thats a different problem
i think the problem is that the objects are not contained in a resource.
can you give some background why you want to let the panel types be invented by a sting array?


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Couldn't resolve reference to PanelType 'NavigationBar' [message #1800804 is a reply to message #1800802] Tue, 08 January 2019 14:07 Go to previous messageGo to next message
Bert Roos is currently offline Bert RoosFriend
Messages: 6
Registered: January 2019
Junior Member
It is an experiment to create types based on external data, outside the DSL.
Re: Couldn't resolve reference to PanelType 'NavigationBar' [message #1800806 is a reply to message #1800804] Tue, 08 January 2019 14:21 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14664
Registered: July 2009
Senior Member
maybe you can use an IDerivedStateComputer to add the stuff to a resource. (or do it in the scope provider)

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de

[Updated on: Tue, 08 January 2019 14:26]

Report message to a moderator

Re: Couldn't resolve reference to PanelType 'NavigationBar' [message #1800807 is a reply to message #1800806] Tue, 08 January 2019 14:28 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14664
Registered: July 2009
Senior Member
have a look at https://stackoverflow.com/questions/29365891/xtext-cross-reference-to-an-non-dsl-resource too

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Couldn't resolve reference to PanelType 'NavigationBar' [message #1800808 is a reply to message #1800806] Tue, 08 January 2019 14:29 Go to previous messageGo to next message
Bert Roos is currently offline Bert RoosFriend
Messages: 6
Registered: January 2019
Junior Member
In the posting of Knuth, he says the following:
Quote:

1. Presumably the Concept and Property instances are created based on some
other external, persisted data. If possible and feasible it would make sense
to implement an IResourceServiceProvider (see also
GenericResourceServiceProvider) for this external content. That way you could
add the Concept and Property instances to the Xtext index and link against that.


That sounds like a good match with the problem I have at hand, as I have "other persisted data" rather than "derived state", but I have no idea how to use resource providers.
Re: Couldn't resolve reference to PanelType 'NavigationBar' [message #1800809 is a reply to message #1800808] Tue, 08 January 2019 14:30 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14664
Registered: July 2009
Senior Member
no in the context external content means a separate file e.g. based on emf

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Couldn't resolve reference to PanelType 'NavigationBar' [message #1800810 is a reply to message #1800808] Tue, 08 January 2019 14:32 Go to previous message
Bert Roos is currently offline Bert RoosFriend
Messages: 6
Registered: January 2019
Junior Member
Thanks! I'm going to try the approach of the StackOverflow posting you linked.
Previous Topic:How does the XVariableDeclaration rule result in an ecore class that extends JvmIdentifiableElement?
Next Topic:Creating two xtext files for two file extensions
Goto Forum:
  


Current Time: Tue Apr 16 09:55:12 GMT 2024

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

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

Back to the top