Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » JvmOperation and JvmField in dsl
JvmOperation and JvmField in dsl [message #714471] Wed, 10 August 2011 15:12 Go to next message
Markus Schindler is currently offline Markus SchindlerFriend
Messages: 30
Registered: July 2009
Member
Hello,

in my dsl I have following rule:
Method:
name=[jvmTypes::JvmOperation|QualifiedName]'('request=[jvmTypes::JvmType|QualifiedName]')'{'
'field:' field=[jvmTypes::JvmField|QualifiedName]
'}'
;

QualifiedName:
ID('.'ID)*
;

At runtime I got a lot of proposals for the request element (JvmType), but NO proposals for name (JvmOperation) and field (JvmField). Is my approach
completely wrong, or what did I miss?

What I want to achieve is, that I got a list of Java method proposals for name(JvmOperation) and a list of field proposals for the field (JvmField).
How can I get this to run?

Thanks in advance,
Markus
Re: JvmOperation and JvmField in dsl [message #714476 is a reply to message #714471] Wed, 10 August 2011 15:26 Go to previous messageGo to next message
Sebastian Zarnekow is currently offline Sebastian ZarnekowFriend
Messages: 3118
Registered: July 2009
Senior Member
Hi Markus,

there is no index for all operations or all fields easily accessible in
the jdt. Therefore I doubt that you will be able to provide field
proposals in with your approach. Consider something like

FieldReference: type=[JvmType|QualifiedName] '.' field=[JvmField];

and customize the scoping to return only the fields that are defined in
the type on the left side.

Regards,
Sebastian
--
Need professional support for Eclipse Modeling?
Go visit: http://xtext.itemis.com

On 10.08.11 17:12, Markus Schindler wrote:
> Hello,
>
> in my dsl I have following rule:
> Method:
> name=[jvmTypes::JvmOperation|QualifiedName]'('request=[jvmTypes::JvmType|QualifiedName]')'{'
>
> 'field:' field=[jvmTypes::JvmField|QualifiedName]
> '}'
> ;
>
> QualifiedName:
> ID('.'ID)*
> ;
>
> At runtime I got a lot of proposals for the request element (JvmType),
> but NO proposals for name (JvmOperation) and field (JvmField). Is my
> approach completely wrong, or what did I miss?
>
> What I want to achieve is, that I got a list of Java method proposals
> for name(JvmOperation) and a list of field proposals for the field
> (JvmField).
> How can I get this to run?
>
> Thanks in advance,
> Markus
Re: JvmOperation and JvmField in dsl [message #714654 is a reply to message #714476] Thu, 11 August 2011 07:05 Go to previous messageGo to next message
Markus Schindler is currently offline Markus SchindlerFriend
Messages: 30
Registered: July 2009
Member
Hi Sebastian,

thanks for the quick response. Works like a charme!
Here is my scoping method. Could you please take a look on it, if that's the way to go, or could this be simpler with same Helper classes (Which I
don't know).

public IScope scope_Method_name(WebService ws, EReference ref) {
JvmType wsType = ws.getClazz().getName();
List<IEObjectDescription> descriptions = new ArrayList<IEObjectDescription>();;
if (wsType instanceof JvmGenericType) {
JvmGenericType gt = (JvmGenericType) wsType;
for (JvmMember member : gt.getMembers()) {
if (member instanceof JvmOperation) {
descriptions.add(EObjectDescription.create(QualifiedName.create(((JvmOperation) member).getSimpleName()), member));
}
}
}
return new SimpleScope(descriptions);
}


Regards,
Markus
Re: JvmOperation and JvmField in dsl [message #714848 is a reply to message #714654] Thu, 11 August 2011 15:25 Go to previous message
Sebastian Zarnekow is currently offline Sebastian ZarnekowFriend
Messages: 3118
Registered: July 2009
Senior Member
Hi Markus,

looks good to me.

Some minor remarks:
There is EObjectDescription.create(String, EObject) which takes care of
converting the simple string to a qualified name. There is
JvmDeclaredType#getDeclaredOperations which renders your cast and the
instanceof check obsolete.

Regards,
Sebastian
--
Need professional support for Eclipse Modeling?
Go visit: http://xtext.itemis.com

On 11.08.11 09:05, Markus Schindler wrote:
>
> Hi Sebastian,
>
> thanks for the quick response. Works like a charme!
> Here is my scoping method. Could you please take a look on it, if that's
> the way to go, or could this be simpler with same Helper classes (Which
> I don't know).
>
> public IScope scope_Method_name(WebService ws, EReference ref) {
> JvmType wsType = ws.getClazz().getName();
> List<IEObjectDescription> descriptions = new
> ArrayList<IEObjectDescription>();;
> if (wsType instanceof JvmGenericType) {
> JvmGenericType gt = (JvmGenericType) wsType;
> for (JvmMember member : gt.getMembers()) {
> if (member instanceof JvmOperation) {
> descriptions.add(EObjectDescription.create(QualifiedName.create(((JvmOperation)
> member).getSimpleName()), member));
> }
> }
> }
> return new SimpleScope(descriptions);
> }
>
>
> Regards,
> Markus
>
Previous Topic:Xtext 2.0 plugin product installed
Next Topic:Template proposals despite "Too many constants"
Goto Forum:
  


Current Time: Tue Apr 23 11:00:50 GMT 2024

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

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

Back to the top