Book a Demo

Author Topic: Pre/Post Conditions as Comments  (Read 4102 times)

TomPre

  • EA Novice
  • *
  • Posts: 12
  • Karma: +0/-0
  • I love YaBB 1G - SP1!
    • View Profile
Pre/Post Conditions as Comments
« on: October 26, 2006, 12:24:07 am »
Is there a way to make Pre / Post Conditions appear in the code as comments? Thanks in advance

Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 8110
  • Karma: +119/-20
    • View Profile
Re: Pre/Post Conditions as Comments
« Reply #1 on: October 26, 2006, 03:04:41 pm »
Code Generation Templates don't directly support getting constraints, including pre/post conditions.  However if you want them you can access them using the EXEC_ADD_IN call from the templates.

C# method
Code: [Select]
// sample EXEC_ADD_IN call
public object GetPreConditions(EA.Repository r, object argsObject)
{
 String constraints;
 Array p = (Array)args;
 String classGUID = (String)p.GetValue(0);
 String methodGUID = (String)p.GetValue(1);
 EA.Element e = r.GetElementByGuid(classGUID);
 for(short i = 0; i < e.Methods.Count; i ++)
 {
   EA.Method m = (EA.Method)e.Methods.GetAt(i);
   if(m.MethodGUID != methodGUID)
     continue;
   // Iterate over the constraints of this method.
 }
 return constraints;
}

Template
Code: [Select]
%EXEC_ADD_IN ("MyAddin", "GetPreConditions", classGUID, opGUID)%
Hope that gets you going.

robject

  • EA Novice
  • *
  • Posts: 18
  • Karma: +0/-0
  • Small talk
    • View Profile
Re: Pre/Post Conditions as Comments
« Reply #2 on: November 27, 2006, 03:46:27 am »
This looks interesting, however I am not at all clear where and how I could add this capability. Am I changing code generation templates? Where can I find these?

Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 8110
  • Karma: +119/-20
    • View Profile
Re: Pre/Post Conditions as Comments
« Reply #3 on: November 27, 2006, 12:58:16 pm »
The code templates are available at Settings | Code Generation Templates.

The code sample given belongs to an EA addin, and I'll let you look up the documentation for that.

robject

  • EA Novice
  • *
  • Posts: 18
  • Karma: +0/-0
  • Small talk
    • View Profile
Re: Pre/Post Conditions as Comments
« Reply #4 on: December 20, 2006, 05:08:22 am »
"the code belongs to an EA add in"
which one, where can I find it? Where can I look up the documentation on that?

«Midnight»

  • EA Guru
  • *****
  • Posts: 5651
  • Karma: +0/-0
  • That nice Mister Grey
    • View Profile
Re: Pre/Post Conditions as Comments
« Reply #5 on: December 20, 2006, 05:59:30 am »
In the EA User Guide or Help, go to the Automation and Scripting section.
No, you can't have it!