umbrello API Documentation

rubycodedocumentation.cpp

00001 /***************************************************************************
00002                           rubycodedocumentation.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 "rubycodedocumentation.h"
00022 
00023 // qt/kde includes
00024 #include <qregexp.h>
00025 #include <kdebug.h>
00026 
00027 // local includes
00028 #include "rubyclassifiercodedocument.h"
00029 #include "rubycodegenerationpolicy.h"
00030 #include "../uml.h"
00031 
00032 // Constructors/Destructors
00033 //
00034 
00035 RubyCodeDocumentation::RubyCodeDocumentation ( RubyClassifierCodeDocument * doc, const QString & text )
00036         : CodeComment ((CodeDocument*) doc, text)
00037 {
00038 
00039 }
00040 
00041 RubyCodeDocumentation::~RubyCodeDocumentation ( ) { }
00042 
00043 //
00044 // Methods
00045 //
00046 
00047 
00048 // Accessor methods
00049 //
00050 
00051 // Other methods
00052 //
00053 
00057 void RubyCodeDocumentation::saveToXMI ( QDomDocument & doc, QDomElement & root ) {
00058     QDomElement blockElement = doc.createElement( "rubycodedocumentation" );
00059     setAttributesOnNode(doc, blockElement); // as we added no additional fields to this class we may
00060     // just use parent TextBlock method
00061     root.appendChild( blockElement );
00062 }
00063 
00067 QString RubyCodeDocumentation::toString ( )
00068 {
00069 
00070     QString output = "";
00071 
00072     // simple output method
00073     if(getWriteOutText())
00074     {
00075         bool  useHashOutput = true;
00076 
00077         // need to figure out output type from ruby policy
00078         CodeGenerationPolicy *p = UMLApp::app()->getCommonPolicy();
00079         if(p->getCommentStyle() == CodeGenerationPolicy::MultiLine)
00080              useHashOutput = false;
00081 
00082         QString indent = getIndentationString();
00083         QString endLine = getNewLineEndingChars();
00084         QString body = getText();
00085         if( useHashOutput)
00086         {
00087             if(!body.isEmpty())
00088                 output.append(formatMultiLineText (body, indent +"# ", endLine));
00089         } else {
00090             output.append("=begin rdoc"+endLine);
00091             output.append(formatMultiLineText (body, indent +' ', endLine));
00092             output.append("=end"+endLine);
00093         }
00094     }
00095 
00096     return output;
00097 }
00098 
00099 QString RubyCodeDocumentation::getNewEditorLine ( int amount )
00100 {
00101     CodeGenerationPolicy *p = UMLApp::app()->getCommonPolicy();
00102     if(p->getCommentStyle() == CodeGenerationPolicy::MultiLine)
00103         return getIndentationString(amount) + ' ';
00104     else
00105         return getIndentationString(amount) + "# ";
00106 }
00107 
00108 int RubyCodeDocumentation::firstEditableLine() {
00109     CodeGenerationPolicy *p = UMLApp::app()->getCommonPolicy();
00110     if(p->getCommentStyle() == CodeGenerationPolicy::MultiLine)
00111         return 1;
00112     return 0;
00113 }
00114 
00115 int RubyCodeDocumentation::lastEditableLine() {
00116     CodeGenerationPolicy *p = UMLApp::app()->getCommonPolicy();
00117     if(p->getCommentStyle() == CodeGenerationPolicy::MultiLine)
00118     {
00119         return -1; // very last line is NOT editable
00120     }
00121     return 0;
00122 }
00123 
00127 QString RubyCodeDocumentation::unformatText ( const QString & text , const QString & indent)
00128 {
00129 
00130     QString mytext = TextBlock::unformatText(text, indent);
00131     CodeGenerationPolicy *p = UMLApp::app()->getCommonPolicy();
00132     // remove leading or trailing comment stuff
00133     mytext.remove(QRegExp('^'+indent));
00134     if(p->getCommentStyle() == CodeGenerationPolicy::MultiLine)
00135     {
00136         mytext.remove(QRegExp("^=begin\\s*(rdoc)?\\s*\n?"));
00137         mytext.remove(QRegExp("^=end\\s*\n?$"));
00138     } else
00139         mytext.remove(QRegExp("^#\\s*"));
00140 
00141     return mytext;
00142 }
00143 
00144 
00145 #include "rubycodedocumentation.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