osate / osate2

Open Source AADL2 Tool Environment
http://osate.org
Eclipse Public License 2.0
39 stars 8 forks source link

Xtext Cross-Reference to Properties and Property Constants #606

Closed brlarson closed 9 years ago

brlarson commented 9 years ago

I had been unable to cross-reference both properties and property types in Xtext. The following grammar is accepted by Xtext (mwe2), but tries to cross reference everything as property constants:

ValueConstant:
constant=[aadl2::PropertyConstant|PNAME]
| property=[aadl2::Property|PNAME] | integer_literal=INTEGER_LIT . . .

This of course throws scads of errors when applied to my existing models. I’m going back to just properties, but it would really be nice to also be able to reference property constants, too.

reteprelief commented 9 years ago

In your grammar the alternatives as not syntactically unique: Both the property reference and the property constant use PNAME as token – so the parser picks the first rule – thus you only get constants. You want a rule that uses PNAME but as type a supertype of the two you are looking for. It is then the job of the name resolver/scope mechanism to determine the acceptable values.

The properties grammar allows you to use property constants and properties as values. In the Properties Ecore model there is a super class AbstractNamedValue that includes those two as well as EnumerationLiteral as subclasses. You could use it as the desirable type for references and just offer Property and PropertyConstants as legal candidates.

At this time there is not a super class in that meta model that only contains only Property and PropertyConstant. You can get such a class by writing a grammar rule for it in your xtext grammar and let xtext generate it. You can then use it as the desirable class for the reference.

Peter

joeseibel commented 9 years ago

The type ArraySizeProperty is a super type of Property and PropertyConstant only.

brlarson commented 9 years ago

Thanks, Joe. I tried to make a superclass of Property and PropertyConstant myself, but Xtext complained however I thought to write it. Using ArraySizeProperty appears to work. I'll have to try a few more projects before I'm sure.

reteprelief commented 9 years ago

Brian, my proposal to introduce a superclass does nto work – I had forgotten about this limitation of Xtext. The reason is that we have an existing Ecore model (that of Properties). The grammar rule introduces a new super type but Xtext cannot add it into type hierarchy of an existing Ecore model and generated Java. Good thing Joe found this super class ArraySizeProperty – although the name suggests a very limited use ☺

From: Brian R Larson [mailto:notifications@github.com] Sent: Tuesday, June 09, 2015 3:34 PM To: osate/osate2-core Cc: Peter Feiler Subject: Re: [osate2-core] Xtext Cross-Reference to Properties and Property Constants (#606)

Thanks, Joe. I tried to make a superclass of Property and PropertyConstant myself, but Xtext complained however I thought to write it. Using ArraySizeProperty appears to work. I'll have to try a few more projects before I'm sure.

— Reply to this email directly or view it on GitHubhttps://github.com/osate/osate2-core/issues/606#issuecomment-110478613.

brlarson commented 9 years ago

Unfortunately, ArraySizeProperty does not have a qualifiedName() method.

reteprelief commented 9 years ago

Because of single inheritance the qualifiedName method is associated with NamedElement, which is also a superclass of Property and PropertyConstant. Recast the object to NamedElement and you have the method.

brlarson commented 9 years ago

Using in the Xtext grammar:

ValueConstant:
property=[aadl2::ArraySizeProperty
PNAME] //both Property and PropertyConstant

Then in the Xtend that processes the parsed result:

def dispatch BAST toAST(ValueConstant e) { . . . else if (e.property!=null) //AADL property (e.property as NamedElement).qualifiedName().makeBASTforPropertyName(e)

at least does not give inexplicable error messages. It will be a while before I can actually run the code though, but it appears that Peter's suggestion is the fix. Thanks, guys.

lwrage commented 9 years ago

There does not seem to be a bug.