简体   繁体   English

在Xtext / Xbase语法中引用生成的类型

[英]Referring to generated types in Xtext/Xbase grammar

I am working on an Xtext grammar using Xbase. 我正在使用Xbase编写Xtext语法。 The grammar permits the user to create a set of Java classes with supertypes from one DSL file. 该语法允许用户从一个DSL文件创建一组具有超类型的Java类。 I therefore created a rule like the following: 因此,我创建了如下规则:

javaClass:
  name=ID ':' supertype=JvmParameterizedTypeReference

My generator for the class files works very well as long as the type does not refer to a class file that is being created by the DSL. 只要类型不引用DSL正在创建的类文件,我的类文件生成器就可以很好地工作。 When a class ClassA is created for example in line 3, and another class ClassB with supertype=ClassA defined in line 4, the parser does not accept the file. 例如,在第3行中创建一个类ClassA,并在第4行中定义了另一个具有supertype = ClassA的类ClassB时,解析器不接受该文件。

I know this is because ClassA is not a known type when ClassB is parsed, because the generator is started after the whole file have been parsed. 我知道这是因为在解析ClassB时ClassA不是已知类型,因为在解析整个文件之后启动了生成器。

Is it nevertheless possible to solve my problem and enable users to refer to classes that were declared earlier in the same DSL file? 但是,是否有可能解决我的问题并使用户能够引用先前在同一DSL文件中声明的类?

Do you infer a JVM model? 您是否推断JVM模型? It allows first index available classes and then infers JVM models for them when all classes are known. 它允许首先索引可用的类,然后在所有类都已知时为其推断JVM模型。 See: https://eclipse.org/Xtext/documentation/305_xbase.html#xbase-inferred-type 请参阅: https//eclipse.org/Xtext/documentation/305_xbase.html#xbase-inferred-type

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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