简体   繁体   中英

cross link Java classes from xtext

Problem :

I would like to have a xtext DSL where I can cross link to java types included in a JAR.

Example :

Let's suppose we have a simple DSL like:

Object:
    'object' name=ID '{'
    property=Property
    '}';

Property:
    'property' name=ID '{'
    object=ObjectOrInclude
    '}';

ObjectOrInclude:
    Include | Object;

Include:
    'include' include=[Object|ID];

In addition, there is a JAR in our classpath providing several classes that implement the interface

public interface IObject{
…
}

The cross link include should than allow us to refer to the EObjects coming from my DSLSs but also to the classes supplied by the JAR. I assume that I must integrate my Java Interface somehow into the xtext index and provide an ID and ResourceDescription for every class, so that the linker can resolve the classes. Yet, I have no idea how to implement this extension of the index.

Question :

How do I get my Java classes into the xtext index so that cross linking works?

This is ususally done by using Xtype or Xbase. unfortunately you want to refer to both EObjects and JvmTypes. you could do this by implement a jvmmodelinferrer that maps your Objects to JvmTypes. have a look at https://www.eclipse.org/Xtext/documentation/104_jvmdomainmodel.html to get an idea how to do that

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM