0

我有这样的语法:

Entity:
    'entity' name=ID '{'
        (properties+=Property)*

        (revision=Revision)?
    '}'

Revision:
    'revision' '{'
        (properties+=Property)+
    '}'

编辑给了我很多修改错误,因为它们没有名字。由于修订始终是 Entity 的子项,我可以自动为其分配名称吗?像name=this.parent.name + "_REV"什么?

4

1 回答 1

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,请不要忘记更新签名:将返回类型从更改StringQualifiedName

于 2011-08-30T08:57:15.743 回答