Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Inferring a class with generics in JvmModelInferrer
Inferring a class with generics in JvmModelInferrer [message #1807431] Wed, 29 May 2019 21:13 Go to next message
Ben Holland is currently offline Ben HollandFriend
Messages: 12
Registered: April 2019
Junior Member
Hello, I would like to infer an interface with the following example generics inside a JvmModelInferrer. I see that the toClass method has a:
Procedure1<? super JvmGenericType> initializer
parameter, but I can't seem to figure out how to use it properly. How could I complete the generator code snippet below to infer the following interface with generics?

Snippet:
it.members += toClass(element, "Foo", GENERICS_INFO_HERE) [
   it.visibility = JvmVisibility.PUBLIC;
   it.interface = true;
   ...		
]


Java code to infer:
public interface Foo<X extends com.example.A, Y>  {
   public void test(X x, Y y);
}


Thanks!
Re: Inferring a class with generics in JvmModelInferrer [message #1807438 is a reply to message #1807431] Thu, 30 May 2019 07:35 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13223
Registered: July 2009
Senior Member
having a look into the internas of the utils and types should help you come up with solutions for such advanced things (please dont expect to get an answer for such advanced questions always)

@Inject private org.eclipse.xtext.common.types.TypesFactory typesFactory

def dispatch infer(Entity entity, extension IJvmDeclaredTypeAcceptor acceptor, boolean prelinkingPhase) {
accept(entity.toInterface("demo.I"+entity.name,[])) [
val p1 = typesFactory.createJvmTypeParameter => [
name = "X"
val upper = typesFactory.createJvmUpperBound()
upper.typeReference = typeRef("com.example.A")
constraints += upper
]
val p2 = typesFactory.createJvmTypeParameter => [
name = "Y"
]
typeParameters += p1
typeParameters += p2
members+= entity.toMethod("demo", Void.TYPE.typeRef) [
parameters += entity.toParameter("a", typeRef(p1))
parameters += entity.toParameter("b", typeRef(p1))
]
]


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/xtext/
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Inferring a class with generics in JvmModelInferrer [message #1807481 is a reply to message #1807438] Thu, 30 May 2019 20:43 Go to previous message
Ben Holland is currently offline Ben HollandFriend
Messages: 12
Registered: April 2019
Junior Member
Perfect! Thanks you so very much.
Previous Topic:Call quickfix validation from Problems View
Next Topic:[LS] Access to server configuration values
Goto Forum:
  


Current Time: Sat Nov 23 01:42:29 GMT 2019

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

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

Back to the top