【问题标题】:Xtext and Xtend: Interfaces inside folderXtext 和 Xtend:文件夹内的接口
【发布时间】:2016-02-09 03:29:36
【问题描述】:

我看到这些类是在单独的文件夹/包中生成的。但是接口文件是在根目录下生成的,而不是在具体包里面生成的。

这是 JVM Inferrer 的代码:

   def dispatch void infer(Repository repo, 
                IJvmDeclaredTypeAcceptor acceptor, 
                boolean isPrelinkingPhase) {   
      acceptor.accept(repo.toInterface(repo.name, [])) [      
          documentation = repo.documentation
          annotations += annotationRef(REPOSITORY);
          superTypes += JPAREPOSITORY.typeRef(repo.type.cloneWithProxies,Long.typeRef); 
    ]
  }

这是模型:

import dsltest.models.Plant
import dsltest.models.Customer

package dsltest.repositories {

 repo PlantRepository : Plant {}
 repo CustomerRepository : Customer {}
}

这是生成的文件:

screen shot of src-gen

如何在 dsltest-> respositories -> CustomerRepository.java 中生成接口

【问题讨论】:

    标签: jvm xtext xtend


    【解决方案1】:

    toInterface 方法的第一个参数应该是一个qualifiedName,例如

    accept(entity.toInterface(entity.fullyQualifiedName,[]))[
    ...
    ]
    

    accept(entity.toInterface(EcoreUtil2.getContainerOfType(entity,  Package).name+"."+entity.name,[]))[
    ...
    ]
    

    【讨论】:

    • toInterface(字符串,初始化程序)。所以类型不匹配:无法从 QualifiedName 转换为字符串。第二个是:边界不匹配:类型参数 不是方法 getContainerOfType(EObject, Class) 的有界类型参数 的有效替代品
    • 我之前已经尝试过了。无法解决这个问题。有没有其他方法可以做到这一点?
    • 你能分享一个完整的语法和推断器,我可以复制和粘贴
    • 很长。在这里很难分享。问题是,我无法将 fullyQualifiedName 添加为 toInterface() 参数类型。它只接受字符串。
    • 有没有办法通过在JvmInferrer中更改包名来生成不同包中的类?
    猜你喜欢
    • 2012-12-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多