Login | Register
My pages Projects Community openCollabNet

Discussions > commits > svn commit: r6 - trunk/src/org/argouml/ruby

argouml-ruby
Discussion topic

Back to topic list

svn commit: r6 - trunk/src/org/argouml/ruby

Author tfmorris
Full name Tom Morris
Date 2006-09-06 04:39:04 PDT
Message Author: tfmorris
Date: 2006-09-06 04:39:04-0700
New Revision: 6

Modified:
   trunk/src/org/argoum​l/ruby/RubyGenerator​.java (contents, props changed)
   trunk/src/org/argoum​l/ruby/RubyModule.ja​va (contents, props changed)

Log:
Conformance to ArgoUML coding style.

Modified: trunk/src/org/argoum​l/ruby/RubyGenerator​.java
Url: http://argouml-ruby.​tigris.org/source/br​owse/argouml-ruby/tr​unk/src/org/argouml/​ruby/RubyGenerator.j​ava?view=diff&re​v=6&p1=trunk/src​/org/argouml/ruby/Ru​byGenerator.java​&p2=trunk/src/org/ar​gouml/ruby/RubyGener​ator.java&r1=5​&r2=6
====================​====================​====================​==================
--- trunk/src/org/argoum​l/ruby/RubyGenerator​.java (original)
+++ trunk/src/org/argoum​l/ruby/RubyGenerator​.java 2006-09-06 04:39:04-0700
@@ -1,4 +1,4 @@
-// $Id: RubyGenerator.java,v 1.1 2006/02/28 20:56:45 linus Exp $
+// $Id$
 // Copyright (c) 2006 The Regents of the University of California. All
 // Rights Reserved. Permission to use, copy, modify, and distribute this
 // software and its documentation without fee, and without a written
@@ -34,7 +34,6 @@
 import java.util.Iterator;
 
 import org.argouml.model.Model;
-import org.argouml.model.Facade;
 import org.argouml.uml.gene​rator.CodeGenerator;​
 import org.argouml.uml.gene​rator.SourceUnit;
 
@@ -45,227 +44,243 @@
  *
  */
 public class RubyGenerator implements CodeGenerator {
- /**
- * TODO: Where should we put the files?
- */
- private String whereToGenerate = "/tmp/generatedRuby";
- private String ext = ".rb";
-
- /**
- * Do the actual generation for an object.
- *
- * @param o
- * The object.
- * @return a SourceUnit.
- */
- private SourceUnit generateForObject(Object o) {
- if (Model.getFacade().isAClass(o))
- return generateClass(o);
-
- return null;
- }
-
- /**
- * Generate Code for class.
- *
- * @param o The object.
- * @return a SourceUnit.
- */
- private SourceUnit generateClass(Object o) {
- // TODO:use string buffer!?
- String className = capitalize(Model.get​Facade().getName(o))​;
- String src = "class " + className;
-
- // generalization:
- String baseClass = generateGeneralizati​on(Model.getFacade()​
- .getGeneralizations(o));
- if (!baseClass.equals("")) {
- src += " < " + capitalize(baseClass);
- }
- src += "\n";
-
- src += getAttributes(o);
- src += getOperations(o);
- src += "\nend";
- return new SourceUnit(capitaliz​e(Model.getFacade().​getName(o))+ext,wher​eToGenerate,
- src);
-
- }
-
- /**
- * Generate code for generalizations of class.
- *
- * @param generalizations The list of generalizations.
- * @return code fo generalization.
- */
- private String generateGeneralizati​on(Collection generalizations) {
- if (generalizations == null) {
- return "";
- }
- String baseClass = "";
- Iterator iter = generalizations.iterator();
- while (iter.hasNext()) {
- Object generalization = iter.next();
- Object generalizableElement = Model.getFacade().getParent(
- generalization);
- if (generalizableElement != null) {
- baseClass = generateClassifierNa​me(generalizableElem​ent);
- break;
- }
- }
- return baseClass;
- }
-
- public String generateClassifierName(Object cls) {
- if (cls == null)
- return "";
- return Model.getFacade().getName(cls);
- }
-
-private String getAttributes(Object o){
- String attrsSrc = "";
- Collection attrs = Model.getFacade().ge​tAttributes(o);
- // get classifier attributes
- for (Iterator i = attrs.iterator(); i.hasNext();) {
- Object attr = i.next();
- String varType="@";
- String dafaultValue="";
- String attrName = Model.getFacade().ge​tName(attr);
- // is static?
- if (Model.getFacade().i​sClassifierScope(att​r)){
- varType+="@";
- dafaultValue="=nil";
- }
- // Get initial value of attribut
- Object init=(Model.getFacad​e().getInitialValue(​attr));
- if(init!=null ){
- dafaultValue="="+((S​tring)(Model.getFaca​de().getBody(init)))​.trim();
- //need more elegant solution ;)
- }
- attrsSrc+=varType+at​trName+dafaultValue+​"\n";
- }
- attrsSrc+="\n";
- return attrsSrc;
+ /**
+ * TODO: Where should we put the files?
+ */
+ private String whereToGenerate = "/tmp/generatedRuby";
+ private String ext = ".rb";
+
+ /**
+ * Do the actual generation for an object.
+ *
+ * @param o
+ * The object.
+ * @return a SourceUnit.
+ */
+ private SourceUnit generateForObject(Object o) {
+ if (Model.getFacade().isAClass(o))
+ return generateClass(o);
+
+ return null;
+ }
+
+ /**
+ * Generate Code for class.
+ *
+ * @param o The object.
+ * @return a SourceUnit.
+ */
+ private SourceUnit generateClass(Object o) {
+ // TODO:use string buffer!?
+ String className = capitalize(Model.get​Facade().getName(o))​;
+ String src = "class " + className;
+
+ // generalization:
+ String baseClass = generateGeneralizati​on(Model.getFacade()​
+ .getGeneralizations(o));
+ if (!baseClass.equals("")) {
+ src += " < " + capitalize(baseClass);
+ }
+ src += "\n";
+
+ src += getAttributes(o);
+ src += getOperations(o);
+ src += "\nend";
+ return new SourceUnit(
+ capitalize(Model.get​Facade().getName(o))​ + ext,
+ whereToGenerate, src);
+
+ }
+
+ /**
+ * Generate code for generalizations of class.
+ *
+ * @param generalizations The list of generalizations.
+ * @return code fo generalization.
+ */
+ private String generateGeneralizati​on(Collection generalizations) {
+ if (generalizations == null) {
+ return "";
+ }
+ String baseClass = "";
+ Iterator iter = generalizations.iterator();
+ while (iter.hasNext()) {
+ Object generalization = iter.next();
+ Object generalizableElement = Model.getFacade().getParent(
+ generalization);
+ if (generalizableElement != null) {
+ baseClass = generateClassifierNa​me(generalizableElem​ent);
+ break;
+ }
+ }
+ return baseClass;
+ }
+
+ public String generateClassifierName(Object cls) {
+ if (cls == null) {
+ return "";
+ }
+ return Model.getFacade().getName(cls);
+ }
+
+ private String getAttributes(Object o) {
+ String attrsSrc = "";
+ Collection attrs = Model.getFacade().ge​tAttributes(o);
+ // get classifier attributes
+ for (Iterator i = attrs.iterator(); i.hasNext();) {
+ Object attr = i.next();
+ String varType = "@";
+ String defaultValue = "";
+ String attrName = Model.getFacade().ge​tName(attr);
+ // is static?
+ if (Model.getFacade().i​sClassifierScope(att​r)) {
+ varType += "@";
+ defaultValue = "=nil";
+ }
+ // Get initial value of attribut
+ Object init = (Model.getFacade().g​etInitialValue(attr)​);
+ if (init != null) {
+ defaultValue = "="
+ + ((String) (Model.getFacade().g​etBody(init))).trim(​);
+ // need more elegant solution ;)
+ }
+ attrsSrc += varType + attrName + defaultValue + "\n";
+ }
+ attrsSrc += "\n";
+ return attrsSrc;
     }
 
-private String getOperations(Object o){
- String opersSrc="";
- String protectedList="";
- String privateList = "";
- Collection opers = Model.getFacade().ge​tOperations(o);
- for (Iterator i = opers.iterator(); i.hasNext();) {
- Object oper = i.next();
- String operName = Model.getFacade().ge​tName(oper);
- opersSrc+="def "+operName;
- // get params
- String params = getOperationsParams(oper);
- if (!params.equals(""))
- opersSrc+="("+params+")";
- opersSrc+="\nend\n";
- // get visibility of operation
- if(Model.getFacade()​.isProtected(oper)){​
- protectedList+=":"+o​perName+",";
- }
- else if (Model.getFacade().i​sPrivate(oper))
- privateList+=":"+operName+",";
- }
- // write visibility of all operations
- if (!protectedList.equals(""))
- opersSrc+= "protected "+protectedList.subs​tring(0,protectedLis​t.length()-1)+"\n";​
- if (!privateList.equals(""))
- opersSrc+= "private "+privateList.substr​ing(0,privateList.le​ngth()-1)+"\n";
- return opersSrc;
+ private String getOperations(Object o) {
+ String opersSrc = "";
+ String protectedList = "";
+ String privateList = "";
+ Collection opers = Model.getFacade().ge​tOperations(o);
+ for (Iterator i = opers.iterator(); i.hasNext();) {
+ Object oper = i.next();
+ String operName = Model.getFacade().ge​tName(oper);
+ opersSrc += "def " + operName;
+ // get params
+ String params = getOperationsParams(oper);
+ if (!params.equals("")) {
+ opersSrc += "(" + params + ")";
+ }
+ opersSrc += "\nend\n";
+ // get visibility of operation
+ if (Model.getFacade().i​sProtected(oper)) {
+ protectedList += ":" + operName + ",";
+ }
+ else if (Model.getFacade().i​sPrivate(oper)) {
+ privateList += ":" + operName + ",";
+ }
+ }
+ // write visibility of all operations
+ if (!protectedList.equals("")) {
+ opersSrc += "protected "
+ + protectedList.substring(0, protectedList.length() - 1)
+ + "\n";
+ }
+ if (!privateList.equals("")) {
+ opersSrc += "private "
+ + privateList.substring(0, privateList.length() - 1) + "\n";
+ }
+ return opersSrc;
     }
 
 
- private String getOperationsParams(Object o) {
- String paramsSrc = "";
- Collection params = Model.getFacade().ge​tParameters(o);
- // get operation params
- for (Iterator i = params.iterator(); i.hasNext();) {
- Object param = i.next();
- String dafaultValue="";
- String paramName = Model.getFacade().ge​tName(param);
- //skip return
- if(paramName.equals("return"))
- continue;
- // Get dafault value of param
- Object init=(Model.getFacad​e().getDefaultValue(​param));
- if(init!=null ){
- dafaultValue="="+((S​tring)(Model.getFaca​de().getBody(init)))​.trim();
- }
- paramsSrc+=paramName​+dafaultValue+",";
- }
- if(!paramsSrc.equals(""))
- paramsSrc=paramsSrc.​substring(0,paramsSr​c.length()-1);
- return paramsSrc;
- }
-
- private String capitalize(String str){
- if (str.length()>1)
- return str.substring(0,1).t​oUpperCase()+str.sub​string(1);
- else return str.toUpperCase();
- }
-
- /**
- * @see org.argouml.uml.gene​rator.CodeGenerator#​generate(java.util.C​ollection,
- * boolean)
- */
- public Collection generate(Collection elements, boolean deps) {
- Collection res = new ArrayList();
-
- for (Iterator i = elements.iterator(); i.hasNext();) {
- Object o = i.next();
- SourceUnit su = generateForObject(o);
- if(su!=null)
- res.add(su);
- }
- return res;
- }
-
- /**
- * @see org.argouml.uml.gene​rator.CodeGenerator#​generateFiles(java.u​til.Collection,
- * java.lang.String, boolean)
- */
- public Collection generateFiles(Collection elements, String path,
- boolean deps) {
- Collection res = new ArrayList();
-
- for (Iterator i = elements.iterator(); i.hasNext();) {
- Object o = i.next();
- SourceUnit su = generateForObject(o);
- if (su != null) {
- su.setBasePath(path);
- File file = new File(su.getFullName());
- try {
- OutputStream os = new FileOutputStream(file);
- OutputStreamWriter osw = new OutputStreamWriter(os);
- osw.write(su.getContent());
- osw.close();
- } catch (IOException e) {
- // TODO: The file could not be created.
- }
- res.add(file.getName());
- }
- }
- return res;
- }
-
- /**
- * @see org.argouml.uml.gene​rator.CodeGenerator#​generateFileList(jav​a.util.Collection,
- * boolean)
- */
- public Collection generateFileList(Collection elements, boolean deps) {
- Collection res = new ArrayList();
-
- for (Iterator i = elements.iterator(); i.hasNext();) {
- Object o = i.next();
- SourceUnit su = generateForObject(o);
- System.out.println(s​u.getFullName());
- File file = new File(su.getFullName());
- res.add(file.getName());
- }
- return res;
- }
+ private String getOperationsParams(Object o) {
+ String paramsSrc = "";
+ Collection params = Model.getFacade().ge​tParameters(o);
+ // get operation params
+ for (Iterator i = params.iterator(); i.hasNext();) {
+ Object param = i.next();
+ String defaultValue = "";
+ String paramName = Model.getFacade().ge​tName(param);
+ // skip return
+ if (paramName.equals("return")) {
+ continue;
+ }
+ // Get default value of param
+ Object init = (Model.getFacade().g​etDefaultValue(param​));
+ if (init != null) {
+ defaultValue = "="
+ + ((String) (Model.getFacade().g​etBody(init))).trim(​);
+ }
+ paramsSrc += paramName + defaultValue + ",";
+ }
+ if (!paramsSrc.equals("")) {
+ paramsSrc = paramsSrc.substring(0, paramsSrc.length() - 1);
+ }
+ return paramsSrc;
+ }
+
+ private String capitalize(String str) {
+ if (str.length() > 1) {
+ return str.substring(0, 1).toUpperCase() + str.substring(1);
+ } else {
+ return str.toUpperCase();
+ }
+ }
+
+ /**
+ * @see org.argouml.uml.gene​rator.CodeGenerator#​generate(java.util.C​ollection,
+ * boolean)
+ */
+ public Collection generate(Collection elements, boolean deps) {
+ Collection res = new ArrayList();
+
+ for (Iterator i = elements.iterator(); i.hasNext();) {
+ Object o = i.next();
+ SourceUnit su = generateForObject(o);
+ if (su != null) {
+ res.add(su);
+ }
+ }
+ return res;
+ }
+
+ /**
+ * @see org.argouml.uml.gene​rator.CodeGenerator#​generateFiles(java.u​til.Collection,
+ * java.lang.String, boolean)
+ */
+ public Collection generateFiles(Collection elements, String path,
+ boolean deps) {
+ Collection res = new ArrayList();
+
+ for (Iterator i = elements.iterator(); i.hasNext();) {
+ Object o = i.next();
+ SourceUnit su = generateForObject(o);
+ if (su != null) {
+ su.setBasePath(path);
+ File file = new File(su.getFullName());
+ try {
+ OutputStream os = new FileOutputStream(file);
+ OutputStreamWriter osw = new OutputStreamWriter(os);
+ osw.write(su.getContent());
+ osw.close();
+ } catch (IOException e) {
+ // TODO: The file could not be created.
+ }
+ res.add(file.getName());
+ }
+ }
+ return res;
+ }
+
+ /**
+ * @see org.argouml.uml.gene​rator.CodeGenerator#​generateFileList(jav​a.util.Collection,
+ * boolean)
+ */
+ public Collection generateFileList(Collection elements, boolean deps) {
+ Collection res = new ArrayList();
+
+ for (Iterator i = elements.iterator(); i.hasNext();) {
+ Object o = i.next();
+ SourceUnit su = generateForObject(o);
+ System.out.println(s​u.getFullName());
+ File file = new File(su.getFullName());
+ res.add(file.getName());
+ }
+ return res;
+ }
 
 }
\ No newline at end of file

Modified: trunk/src/org/argoum​l/ruby/RubyModule.ja​va
Url: http://argouml-ruby.​tigris.org/source/br​owse/argouml-ruby/tr​unk/src/org/argouml/​ruby/RubyModule.java​?view=diff&rev=6​&p1=trunk/src/or​g/argouml/ruby/RubyM​odule.java&p2=tr​unk/src/org/argouml/​ruby/RubyModule.java​&r1=5&r2=6
====================​====================​====================​==================
--- trunk/src/org/argoum​l/ruby/RubyModule.ja​va (original)
+++ trunk/src/org/argoum​l/ruby/RubyModule.ja​va 2006-09-06 04:39:04-0700
@@ -1,4 +1,4 @@
-// $Id: RubyModule.java,v 1.1 2006/02/28 20:56:45 linus Exp $
+// $Id$
 // Copyright (c) 2006 The Regents of the University of California. All
 // Rights Reserved. Permission to use, copy, modify, and distribute this
 // software and its documentation without fee, and without a written
@@ -41,7 +41,8 @@
      * @see org.argouml.modulelo​ader.ModuleInterface​#enable()
      */
     public boolean enable() {
- GeneratorManager.get​Instance().addGenera​tor(myLang, new RubyGenerator());
+ GeneratorManager.get​Instance().addGenera​tor(myLang,
+ new RubyGenerator());
         return true;
     }
 
@@ -70,7 +71,7 @@
         case AUTHOR:
             return "Jacek Bojarski";
         case VERSION:
- return "0.0.1";
+ return "0.0.1";
         }
         return null;
     }

« Previous message in topic | 1 of 1 | Next message in topic »

Messages

Show all messages in topic

svn commit: r6 - trunk/src/org/argouml/ruby tfmorris Tom Morris 2006-09-06 04:39:04 PDT
Messages per page: