Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Implicit parameters
Implicit parameters [message #1082255] Thu, 08 August 2013 09:54 Go to next message
Thomas Goossens is currently offline Thomas GoossensFriend
Messages: 32
Registered: August 2013
Member
In the DSL I'm creating I want in some special cases to have methods that implicitly have parameters (that you don't have to type, because they are ALWAYS there)

So:
function example(int a){

}

Should expand to:

public void example(int a, MyClass x){

}


For given parameters I could do:
parameter.toParameter(parameter.name, parameter.parameterType)


But I'm not sure what to do.

I don't expect a fully detailed answer, just some hints would make me already very happy :)

[Updated on: Thu, 08 August 2013 09:54]

Report message to a moderator

Re: Implicit parameters [message #1082326 is a reply to message #1082255] Thu, 08 August 2013 12:15 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi

you are talking about the jvmmodelinferrer right

so what about using

org.eclipse.xtext.common.types.util.TypeReferences.getTypeForName(String, Notifier, JvmTypeReference...)
to get a new type (first param is name of the class, second the context (in this case your funktion or the first parameter)

function.toParameter("x", type)


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Implicit parameters [message #1082334 is a reply to message #1082255] Thu, 08 August 2013 12:28 Go to previous messageGo to next message
Ian McDevitt is currently offline Ian McDevittFriend
Messages: 70
Registered: December 2012
Location: Belfast
Member
I have done something like this. If it helps here is a snippet if you are hard coding the values.

members += function.toMethod(function.name, function.newTypeRef("void")) [
  for (parameter : function.parameters) {
    parameters += parameter.toParameter(parameter.name, parameter.parameterType)
  }
  parameters += function.toParameter("x", function.newTypeRef("MyClass"))
]

Re: Implicit parameters [message #1082343 is a reply to message #1082334] Thu, 08 August 2013 12:39 Go to previous message
Thomas Goossens is currently offline Thomas GoossensFriend
Messages: 32
Registered: August 2013
Member
Hi thanks for the help both

The snippet did the trick btw
Previous Topic: Editor could not be initialized | java.lang.NoClassDefFoundError: olang/OlangRuntimeModule
Next Topic:importURI of ecore-only based model
Goto Forum:
  


Current Time: Fri Apr 26 05:58:58 GMT 2024

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

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

Back to the top