Main Menu
Login
SSL SecureMode
Username:
Password:  
Lost Password?
Register now!
ChangeVision Members Map
Search
Forum Index   -   Topic Index
   How to use of Astah (Pro/SysML/GSN/Com)
     rapidly create operations/attributes part2

Threaded | Newest First Previous Topic | Next Topic | Bottom
Poster Thread
xenocide
Posted on: 2012/10/15 15:46
Just popping in
Joined: 2012/9/4
From:
Posts: 15
rapidly create operations/attributes part2
As a preface, I am using Astah to model Perl software built with the Moose object system. Perl has no programmatic-ally enforced encapsulation, and Moose attributes can automatically create getters and setters depending on setting read-only, read-write, or bare (none).

I notice that Astah has the ability to create getter/setter from an attribute, this seems neat, but I have the problem that it uses Java-esque naming conventions. Perl's naming conventions are completely different. Generally with moose I leave my getter/setter to have the same name as the attribute. Can I change the template Astah uses to create these names? Even better can I set it so that when I create an attribute it automatically creates an appropriately named getter?
Joba
Posted on: 2012/10/16 15:58
Developer
Joined: 2006/6/6
From:
Posts: 969
Re: rapidly create operations/attributes part2
Hi, thank you for your additional post.

Unfortunately there is no way to customize to do so, but I'd suggest you to use "Script Plug-in" which is the easiest way to access Astah via scripting languages. For details and download, please visit Astah Script Plug-in page. We've created java script for you, so here's the step to use.

1. Install Astah Script Plug-in
2. In the structure tree (Top left pane of Astah) select Attributes you want to change the setter/getter names of
3. Go to [Tool] - [Script], copy and paste the java script below (Customize the scripts in red below) and run it

importPackage(com.change_vision.jude.api.inf.editor);
importPackage(com.change_vision.jude.api.inf.model);

run();

function run() {
     var attributes = getSelectedAttributesInProjectView();
     
     if (attributes.length === 0) {
         println('Please select attributes you want to add setter/getter in StructureTree');
         return;
     }
     
     TransactionManager.beginTransaction();
     for (var i in attributes) {
         addSetterGetter(attributes[i]);
     }
     TransactionManager.endTransaction();
 }

function getSelectedAttributesInProjectView() {
     var attributes = [];
     var projectViewManager = astah.getViewManager().getProjectViewManager();
     var selectedEntities = projectViewManager.getSelectedEntities();
     for (var i in selectedEntities) {
         var entity = selectedEntities[i];
         if (entity instanceof IAttribute) {
             attributes.push(entity);
             println('HIT: ' + entity.getName());
         }
     }
      
     return attributes;
}

function addSetterGetter(attribute) {
     createSetter(attribute.getOwner(), attribute);
     createGetter(attribute.getOwner(), attribute);
}

function createSetter(iClass, iAtt) {
     var bme = astah.getModelEditorFactory().getBasicModelEditor();
     var name =  convertToSetterName(iAtt.getName());
     println('createSetter: ' + name);
     var iOperation = bme.createOperation(iClass, name, 'void');
     bme.createParameter(iOperation, "parameter1", iAtt.getType());
}

function convertToSetterName(attName) {
     //do something
     return "set_"+ attName;
}

function createGetter(iClass, iAtt) {
     var bme = astah.getModelEditorFactory().getBasicModelEditor();
     bme.createOperation(iClass, convertToGetterName(iAtt.getName()), iAtt.getType().getName());
}

function convertToGetterName(attName) {
     //do something
     return "get_"+ attName;
}


Hope this helps. If you have any further questions, let us know.

Cheers,
SJ
Threaded | Newest First Previous Topic | Next Topic | Top