How to insert non-existing fields into the scope [message #1032571] |
Wed, 03 April 2013 02:51  |
Eclipse User |
|
|
|
Hi all,
I am interested in defining a DSL, whose expressions use existing class' fields, as well as fields that are not declared in any class (yet). The reason for doing so is that those "non-existing" fields are to be declared by generated AspectJ aspects (using Inter Type Declarations, see http://www.eclipse.org/aspectj/doc/next/progguide/language-interType.html).
As an example, consider the following DSL code:
Logger my.MyClass {
log when (sum > 0 && sum < 1000)
log when (_sum != sum)
}
The field sum is declared in the class MyClass, and is inserted into the scope in the regular way (ScopeProvider). However, the field _sum (note the leading underscore) is not defined in the class during the parsing of the DSL code, and as a result a compilation error is shown. I would like to remove that error for all identifiers starting with an underscore.
Is there a way to insert such identifiers into the scope although they are not defined anywhere?
Thanks,
Oren
|
|
|
|
Re: How to insert non-existing fields into the scope [message #1033426 is a reply to message #1033354] |
Thu, 04 April 2013 04:09  |
Eclipse User |
|
|
|
Am 04.04.13 08:39, schrieb Oren Mishali:
> Perhaps a better title for this question would be "How to insert
> arbitrary identifiers into the scope?". Hope that would make the
> question more clear...
>
Provide a custom implemenation of IScope that returns a meaningful
description when asked for something starting with an underscore. It's a
fairly small interface, especially if you inherit from
org.eclipse.xtext.scoping.impl.AbstractScope. You'd only have to return
an empty collection from #getAllLocalElements() and a proper result from
#getLocalElementsByName(QualifiedName)
Regards,
Sebastian
--
Looking for professional support for Xtext, Xtend or Eclipse Modeling?
Go visit: http://xtext.itemis.com
|
|
|
Powered by
FUDForum. Page generated in 0.04755 seconds