umbrello API Documentation

rubyclassdeclarationblock.cpp

00001 /***************************************************************************
00002                           rubyclassdeclarationblock.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                                                    *
00017  *   Umbrello UML Modeller Authors <uml-devel@uml.sf.net>                  *
00018  ***************************************************************************/
00019 
00020 #include "rubyclassdeclarationblock.h"
00021 #include "rubycodedocumentation.h"
00022 #include "rubycodegenerator.h"
00023 #include "../uml.h"
00024 
00025 // Constructors/Destructors
00026 //
00027 
00028 RubyClassDeclarationBlock::RubyClassDeclarationBlock
00029  ( RubyClassifierCodeDocument * parentDoc, const QString &startText, const QString &endText, const QString &comment)
00030         : OwnedHierarchicalCodeBlock(parentDoc->getParentClassifier(), parentDoc, startText, endText, comment)
00031 {
00032     init(parentDoc, comment);
00033 }
00034 
00035 RubyClassDeclarationBlock::~RubyClassDeclarationBlock ( ) { }
00036 
00037 //
00038 // Methods
00039 //
00040 
00044 void RubyClassDeclarationBlock::saveToXMI ( QDomDocument & doc, QDomElement & root ) {
00045     QDomElement blockElement = doc.createElement( "rubyclassdeclarationblock" );
00046 
00047     setAttributesOnNode(doc, blockElement);
00048 
00049     root.appendChild( blockElement );
00050 }
00051 
00055 void RubyClassDeclarationBlock::loadFromXMI ( QDomElement & root )
00056 {
00057     setAttributesFromNode(root);
00058 }
00059 
00060 // Accessor methods
00061 //
00062 
00063 // Other methods
00064 //
00065 
00069 void RubyClassDeclarationBlock::updateContent ( )
00070 {
00071 
00072     RubyClassifierCodeDocument *parentDoc = dynamic_cast<RubyClassifierCodeDocument*>(getParentDocument());
00073     UMLClassifier *c = parentDoc->getParentClassifier();
00074     CodeGenerationPolicy * p = UMLApp::app()->getCommonPolicy();
00075     QString endLine = p->getNewLineEndingChars();
00076     bool isInterface = parentDoc->parentIsInterface(); // a little shortcut
00077     QString RubyClassName = parentDoc->getRubyClassName(c->getName());
00078     bool forceDoc = p->getCodeVerboseDocumentComments();
00079 
00080     // COMMENT
00081     QString comment = c->getDoc();
00082     comment.replace("@ref ", "");
00083     comment.replace("@see", "_See_");
00084     comment.replace("@short", "_Summary_");
00085     comment.replace("@author", "_Author_");
00086 
00087     if (isInterface)
00088         getComment()->setText("Module " + RubyClassName + endLine + comment);
00089     else
00090         getComment()->setText("Class " + RubyClassName + endLine + comment);
00091 
00092     if(forceDoc || !c->getDoc().isEmpty())
00093         getComment()->setWriteOutText(true);
00094     else
00095         getComment()->setWriteOutText(false);
00096 
00097 
00098     // Now set START/ENDING Text
00099     QString startText = "";
00100 
00101     if (parentDoc->parentIsInterface()) {
00102         startText.append("module ");
00103     } else {
00104         startText.append("class ");
00105     }
00106 
00107     UMLClassifierList superclasses = c->findSuperClassConcepts(UMLClassifier::CLASS);
00108     UMLClassifierList superinterfaces = c->findSuperClassConcepts(UMLClassifier::INTERFACE);
00109 
00110     // write out inheritance
00111     startText.append(RubyClassName);
00112 
00113     int i = 0;
00114     for (UMLClassifier * concept= superclasses.first(); concept; concept = superclasses.next()) {
00115         if (i == 0) {
00116             startText.append(QString(" < ") + RubyCodeGenerator::cppToRubyType(concept->getName()) + endLine);
00117         } else {
00118             // After the first superclass name in the list, assume the classes
00119             // are ruby modules that can be mixed in,
00120             startText.append("include " + RubyCodeGenerator::cppToRubyType(concept->getName()) + endLine);
00121         }
00122         i++;
00123     }
00124 
00125     // Write out the interfaces we 'implement'. Are these modules to be mixed in, in Ruby?
00126     for (UMLClassifier * concept= superinterfaces.first(); concept; concept = superinterfaces.next()) {
00127         startText.append(QString("include ") + RubyCodeGenerator::cppToRubyType(concept->getName()) + endLine);
00128     }
00129 
00130     // Set the header and end text for the hier.codeblock
00131     setStartText(startText);
00132 }
00133 
00134 void RubyClassDeclarationBlock::init (RubyClassifierCodeDocument *parentDoc, const QString &comment)
00135 {
00136 
00137     setComment(new RubyCodeDocumentation(parentDoc));
00138     getComment()->setText(comment);
00139 
00140     setEndText("end");
00141 
00142     updateContent();
00143 
00144 }
00145 
00146 
00147 #include "rubyclassdeclarationblock.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:07:59 2007 by doxygen 1.4.1 written by Dimitri van Heesch, © 1997-2003