我想验证与以下语法片段对应的输入:
Declaration:
name = ID "=" brCon=BracketContent
;
BracketContent:
decCon=DecContent (comp+=COMPARATOR content+=DecContent)*
;
DecContent:
(neg=("!"|"not"))? singleContent=VarContent (op+=OPERATOR nextCon+=VarContent)*
;我的验证如下:
@Check
def checkNoCycleInHierarchy(Declaration dec) {
if(dec.decCon.singleContent.reference == null) {
return
}
var names = newArrayList
var con = dec.decCon.singleContent
while(con.reference != null) {
con = getThatReference(con).singleContent
if(names.contains(getParentName(con))) {
val errorMsg = "Cycle in hierarchy!"
error(errorMsg,
SQFPackage.eINSTANCE.bracketContent_DecCon,
CYCLE_IN_HIERARCHY)
return
}
names.add(getParentName(con))
}
}但是,当我用testCaseit测试此验证时,将返回一条错误消息:
Expected ERROR 'raven.sqf.CycleInHierarchy' on Declaration at [-1:-1] but got
ERROR (org.eclipse.emf.ecore.impl.EClassImpl@5a7fe64f (name: Declaration) (instanceClassName: null) (abstract: false, interface: false).0) 'Error executing EValidator', offset null, length null
ERROR (org.eclipse.emf.ecore.impl.EClassImpl@5a7fe64f (name: Declaration) (instanceClassName: null) (abstract: false, interface: false).0) 'Error executing EValidator', offset null, length null我只是不知道这是怎么回事,所以我希望你们中的某个人能有个主意。
问候Krzmbrzl
发布于 2015-05-31 15:44:47
结果发现这是一个内部错误.我仍然不确定到底出了什么问题,但是我已经重写了我的验证方法,现在它像预期的那样工作了。
现在,该方法如下所示:
enter code here@Check
def checkNoCycleInHierarchy(Declaration dec) {
if(dec.varContent.reference == null) {
//proceed only if there is a reference
return
}
var content = dec.varContent
var names = newArrayList
while(content.reference != null && !names.contains(getParentName(content))) {
names.add(getParentName(content))
content = content.reference.varContent
if(names.contains(getParentName(content))) {
val errorMsg = "Cycle in hierarchy!"
error(errorMsg,
SQFPackage.eINSTANCE.declaration_BrCon,
CYCLE_IN_HIERARCHY)
return
}
}
}我怀疑在这种情况下,我的"getThatReference“的用法有问题。
问候Krzmbrzl
发布于 2015-05-29 14:50:01
您的测试实用程序告诉您,验证器没有生成预期的验证错误("CycleInHierarchy")。相反,验证器产生了“执行EValidator错误”。这意味着在执行验证程序时引发了异常。
https://stackoverflow.com/questions/30532135
复制相似问题