我有这样的语法:
Entity:
'entity' name=ID '{'
(properties+=Property)*
(revision=Revision)?
'}'
Revision:
'revision' '{'
(properties+=Property)+
'}'
编辑器为修订版提供了很多错误,因为它们没有名称。由于修订版始终是实体的子代,我可以自动为其指定名称吗?像name=this.parent.name + "_REV"
?
答案 0 :(得分:2)
解决方案是扩展DefaultDeclarativeQualifiedNameProvider
:
import org.eclipse.xtext.naming.DefaultDeclarativeQualifiedNameProvider;
import org.eclipse.xtext.naming.QualifiedName;
import model.Revision;
public class ModelQualifiedNameProvider extends DefaultDeclarativeQualifiedNameProvider {
public final static String REVISION_TABLE_EXTENSION = "_REV";
public final static String REVISION_TYPE_EXTENSION = "Rev";
public QualifiedName qualifiedName( Revision obj ) {
QualifiedName qn = getFullyQualifiedName( obj.eContainer() );
String typeName = qn.getLastSegment() + REVISION_TABLE_EXTENSION;
QualifiedName result = qn.skipLast( 1 );
result = result.append( typeName );
return result;
}
}
确保您获得正确的方法签名! Xtext反射性地调用QualifiedName qualifiedName(MyType ele)
,如果您从1.0升级到2.0,请不要忘记更新签名:将返回类型从String
更改为QualifiedName