umbrello API Documentation

rubycodeclassfield.cpp

00001 /***************************************************************************
00002                           rubycodeclassfield.cpp
00003                           Derived from the Java code generator by thomas
00004 
00005     begin                : Thur Jul 21 2005
00006     author               : Richard Dale
00007  ***************************************************************************/
00008 
00009 /***************************************************************************
00010  *                                                                         *
00011  *   This program is free software; you can redistribute it and/or modify  *
00012  *   it under the terms of the GNU General Public License as published by  *
00013  *   the Free Software Foundation; either version 2 of the License, or     *
00014  *   (at your option) any later version.                                   *
00015  *                                                                         *
00016  *   copyright (C) 2006-2007                                               *
00017  *   Umbrello UML Modeller Authors <uml-devel@uml.sf.net>                  *
00018  ***************************************************************************/
00019 
00020 // own header
00021 #include "rubycodeclassfield.h"
00022 
00023 // qt/kde includes
00024 #include <qregexp.h>
00025 #include <kdebug.h>
00026 
00027 // local includes
00028 #include "rubycodecomment.h"
00029 #include "rubycodegenerator.h"
00030 
00031 #include "../attribute.h"
00032 #include "../umlobject.h"
00033 #include "../umlrole.h"
00034 #include "../uml.h"
00035 
00036 #include "rubyclassifiercodedocument.h"
00037 
00038 // Constructors/Destructors
00039 //
00040 
00041 RubyCodeClassField::RubyCodeClassField (ClassifierCodeDocument * parentDoc, UMLRole * role)
00042         : CodeClassField(parentDoc, role)
00043 {
00044 
00045 }
00046 
00047 RubyCodeClassField::RubyCodeClassField (ClassifierCodeDocument * parentDoc, UMLAttribute * attrib)
00048         : CodeClassField(parentDoc, attrib)
00049 {
00050 
00051 }
00052 
00053 RubyCodeClassField::~RubyCodeClassField ( ) { }
00054 
00055 //
00056 // Methods
00057 //
00058 
00059 // Other methods
00060 //
00061 
00062 QString RubyCodeClassField::getFieldName() {
00063     if (parentIsAttribute())
00064     {
00065         UMLAttribute * at = (UMLAttribute*) getParentObject();
00066         return cleanName(at->getName());
00067     }
00068     else
00069     {
00070         UMLRole * role = (UMLRole*) getParentObject();
00071         QString roleName = role->getName();
00072         if(fieldIsSingleValue()) {
00073             return roleName.replace(0, 1, roleName.left(1).lower());
00074         } else {
00075             return roleName.lower() + "Array";
00076         }
00077     }
00078 }
00079 
00080 
00081 QString RubyCodeClassField::getInitialValue() {
00082 
00083     if (parentIsAttribute())
00084     {
00085         UMLAttribute * at = dynamic_cast<UMLAttribute*>( getParentObject() );
00086         if (at) {
00087             return fixInitialStringDeclValue(at->getInitialValue(), getTypeName());
00088         } else {
00089             kError() << "RubyodeClassField::getInitialValue: parent object is not a UMLAttribute"
00090             << endl;
00091             return "";
00092         }
00093         return fixInitialStringDeclValue(at->getInitialValue(), getTypeName());
00094     }
00095     else
00096     {
00097         if(fieldIsSingleValue()) {
00098             // FIX : IF the multiplicity is "1" then we should init a new object here, if its 0 or 1,
00099             //       then we can just return 'empty' string (minor problem).
00100             return QString("");
00101         } else {
00102             return RubyCodeGenerator::getListFieldClassName()+".new()";
00103         }
00104     }
00105 
00106 }
00107 
00108 QString RubyCodeClassField::getTypeName ( )
00109 {
00110     return RubyCodeGenerator::cppToRubyType(CodeClassField::getTypeName());
00111 }
00112 
00113 #include "rubycodeclassfield.moc"
KDE Logo
This file is part of the documentation for umbrello Version 3.1.0.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Tue Jun 26 08:08:00 2007 by doxygen 1.4.1 written by Dimitri van Heesch, © 1997-2003