umbrello API Documentation

rubycodeclassfielddeclarationblock.cpp

00001 /***************************************************************************
00002  *                                                                         *
00003  *   This program is free software; you can redistribute it and/or modify  *
00004  *   it under the terms of the GNU General Public License as published by  *
00005  *   the Free Software Foundation; either version 2 of the License, or     *
00006  *   (at your option) any later version.                                   *
00007  *                                                                         *
00008  *   copyright (C) 2006                                                    *
00009  *   Umbrello UML Modeller Authors <uml-devel@uml.sf.net>                  *
00010  ***************************************************************************/
00011 
00012 #include "rubycodeclassfielddeclarationblock.h"
00013 
00014 #include "rubycodeclassfield.h"
00015 #include "rubyclassifiercodedocument.h"
00016 #include "rubycodegenerationpolicy.h"
00017 #include "../classifier.h"
00018 #include "../umlrole.h"
00019 #include "../codegenerator.h"
00020 #include "../uml.h"
00021 
00022 // Constructors/Destructors
00023 //
00024 
00025 RubyCodeClassFieldDeclarationBlock::RubyCodeClassFieldDeclarationBlock ( CodeClassField * parent )
00026         : CodeClassFieldDeclarationBlock ( parent )
00027 {
00028     setOverallIndentationLevel(1);
00029     updateContent();
00030 }
00031 
00032 RubyCodeClassFieldDeclarationBlock::~RubyCodeClassFieldDeclarationBlock ( ) { }
00033 
00034 //
00035 // Methods
00036 //
00037 
00038 
00039 
00040 // Other methods
00041 //
00042 
00045 void RubyCodeClassFieldDeclarationBlock::updateContent( )
00046 {
00047 
00048     CodeClassField * cf = getParentClassField();
00049     ClassifierCodeDocument * doc = cf->getParentDocument();
00050     RubyCodeClassField * rcf = dynamic_cast<RubyCodeClassField*>(cf);
00051     RubyClassifierCodeDocument* rdoc = dynamic_cast<RubyClassifierCodeDocument*>(doc);
00052     CodeGenerationPolicy * p = UMLApp::app()->getCommonPolicy();
00053     CodeGenerationPolicy::ScopePolicy scopePolicy = p->getAssociationFieldScope();
00054 
00055     // Set the comment
00056     QString notes = getParentObject()->getDoc();
00057     getComment()->setText(notes);
00058 
00059     // Set the body
00060     QString staticValue = getParentObject()->getStatic() ? "static " : "";
00061     QString scopeStr = rdoc->scopeToRubyDecl(getParentObject()->getVisibility());
00062 
00063     // IF this is from an association, then scope taken as appropriate to policy
00064     if(!rcf->parentIsAttribute())
00065     {
00066         switch (scopePolicy) {
00067         case CodeGenerationPolicy::Public:
00068         case CodeGenerationPolicy::Private:
00069         case CodeGenerationPolicy::Protected:
00070             scopeStr = rdoc->scopeToRubyDecl((Uml::Visibility::Value) scopePolicy);
00071             break;
00072         default:
00073         case CodeGenerationPolicy::FromParent:
00074             // do nothing here... will leave as from parent object
00075             break;
00076         }
00077     }
00078 
00079     QString typeName = rcf->getTypeName();
00080     QString fieldName = rcf->getFieldName();
00081     QString initialV = rcf->getInitialValue();
00082 
00083     if (!cf->parentIsAttribute() && !cf->fieldIsSingleValue())
00084         typeName = "Array";
00085 
00086     QString body = staticValue+scopeStr+' '+typeName+' '+fieldName;
00087     if (!initialV.isEmpty())
00088         body.append(" = " + initialV);
00089     else if (!cf->parentIsAttribute())
00090     {
00091         UMLRole * role = dynamic_cast<UMLRole*>(cf->getParentObject());
00092         if (role->getObject()->getBaseType() == Uml::ot_Interface)
00093         {
00094             // do nothing.. can't instanciate an interface
00095         } else {
00096 
00097             // FIX?: IF a constructor method exists in the classifiercodedoc
00098             // of the parent Object, then we can use that instead (if its empty).
00099             if(cf->fieldIsSingleValue())
00100             {
00101                 if(!typeName.isEmpty())
00102                     body.append(" = " + typeName + ".new()");
00103             } else
00104                 body.append(" = []");
00105         }
00106     }
00107 
00108     setText(body);
00109 
00110 }
00111 
00112 #include "rubycodeclassfielddeclarationblock.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