繁体   English   中英

Xtend:使用接口扩展接口

[英]Xtend: Extending interface with interface

我是Xtext的新手。 我需要使用interface扩展接口。 我需要这样的东西:

import org.springframework.data.jpa.repository.JpaRepository;

@Repository
public interface PHRRepository extends
        JpaRepository<PlantHireRequest, Long> {

}

我的语法:

Repository:
  'repo' name=ValidID ':' type=JvmTypeReference
     body=XBlockExpression;

我的JVMinferrer代码:

 @Inject
  private TypesFactory typesFactory;

  @Inject
  private TypeReferences references;

  public static String REPOSITORY = "org.springframework.stereotype.Repository";
  public static String JPAREPOSITORY = "org.springframework.data.jpa.repository.JpaRepository";

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

这给出了:

@Repository
public interface PHRRepository {
}

有人可以帮我吗?

以下对我来说很好

    accept(entity.toInterface("I"+entity.name,[]))[
        superTypes += IEntity.typeRef
    ]

要么

    accept(entity.toInterface("I"+entity.name,[]))[
         if (entity.superType != null) //asuming entity.supertype is modeled to be an interface
             superTypes += entity.superType.cloneWithProxies
    ]

如果您想使用泛型,可以使用

JpaRepository.typeRef(PlantHireRequest.typeRef, Long.typeRef) 

要么

"x.y.Z".typeRef("a.b.C".typeRef(), "java.lang.Long".typeRef())

混合当前无法正常工作,因此可以使用一种解决方法

superTypes += "x.y.Z".typeRef(entity.superType.qualifiedName.typeRef(), "java.lang.Long".typeRef())

暂无
暂无

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

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