简体   繁体   中英

How to scan Annotations used in contracts written using COFOJA?

I am working on a project, where I have to write a contract for a method using COFOJA, and I have to generate code for method from the contracts using heuristics.

1) How will I be able to scan Annotations used in COFOJA like @ requires, @ensures etc? 2) IF I generate Abstract syntax tree, whether the AST will contain annotations / contract language also?

for ex: consider following input to my project

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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