Skip to main content



      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 17:13 Go to next message
Eclipse UserFriend
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 03:35 Go to previous messageGo to next message
Eclipse UserFriend
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))
]
]
Re: Inferring a class with generics in JvmModelInferrer [message #1807481 is a reply to message #1807438] Thu, 30 May 2019 16:43 Go to previous message
Eclipse UserFriend
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 Mar 22 19:17:52 EDT 2025

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

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

Back to the top