我正在做一个项目,我必须为使用 COFOJA 的方法编写合同,并且必须使用启发式方法从合同中生成方法代码。
1) 我如何能够扫描 COFOJA 中使用的注释,例如 @requires、@ensures 等?2)如果我生成抽象语法树,AST是否也会包含注释/合同语言?
例如:考虑对我的项目进行以下输入
class Test{
@requires( { a> 0})
@ensures( {a==0 implies fact(a)=1 , and a>0 implies fact(a) = fact(a-1)*a } )
public int fact (int a)
{
}
}
// Output of first version of code: (Its a rough estimate of code,)
class Test1{
public int fact (int a)
{
if (a==0)
return 1;
if(a >0)
return a*fact(a-1);
if(a<0) throw new AssertionException("Precondition failed/violated a<0 ");
}
} // end of class