umbrello API Documentation

javaclassdeclarationblock.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) 2004-2006                                               *
00009  *   Umbrello UML Modeller Authors <uml-devel@uml.sf.net>                  *
00010  ***************************************************************************/
00011 
00012 /*  This code generated by:
00013  *      Author : thomas
00014  *      Date   : Wed Jul 16 2003
00015  */
00016 #include "javaclassdeclarationblock.h"
00017 #include "javacodedocumentation.h"
00018 #include "../codegenerator.h"
00019 #include "../codegenerationpolicy.h"
00020 #include "../uml.h"
00021 
00022 // Constructors/Destructors
00023 //
00024 
00025 JavaClassDeclarationBlock::JavaClassDeclarationBlock
00026  ( JavaClassifierCodeDocument * parentDoc, const QString &startText, const QString &endText, const QString &comment)
00027         : OwnedHierarchicalCodeBlock(parentDoc->getParentClassifier(), parentDoc, startText, endText, comment)
00028 {
00029     init(parentDoc, comment);
00030 }
00031 
00032 JavaClassDeclarationBlock::~JavaClassDeclarationBlock ( ) { }
00033 
00034 //
00035 // Methods
00036 //
00037 
00041 void JavaClassDeclarationBlock::saveToXMI ( QDomDocument & doc, QDomElement & root ) {
00042     QDomElement blockElement = doc.createElement( "javaclassdeclarationblock" );
00043 
00044     setAttributesOnNode(doc, blockElement);
00045 
00046     root.appendChild( blockElement );
00047 }
00048 
00052 void JavaClassDeclarationBlock::loadFromXMI ( QDomElement & root )
00053 {
00054     setAttributesFromNode(root);
00055 }
00056 
00057 // Accessor methods
00058 //
00059 
00060 // Other methods
00061 //
00062 
00066 void JavaClassDeclarationBlock::updateContent ( )
00067 {
00068 
00069     JavaClassifierCodeDocument *parentDoc = dynamic_cast<JavaClassifierCodeDocument*>(getParentDocument());
00070     UMLClassifier *c = parentDoc->getParentClassifier();
00071     CodeGenerationPolicy *commonPolicy = UMLApp::app()->getCommonPolicy();
00072     QString endLine = commonPolicy->getNewLineEndingChars();
00073     bool isInterface = parentDoc->parentIsInterface(); // a little shortcut
00074     QString JavaClassName = parentDoc->getJavaClassName(c->getName());
00075 
00076     // COMMENT
00077     if(isInterface)
00078         getComment()->setText("Interface "+JavaClassName+endLine+c->getDoc());
00079     else
00080         getComment()->setText("Class "+JavaClassName+endLine+c->getDoc());
00081 
00082     bool forceDoc = UMLApp::app()->getCommonPolicy()->getCodeVerboseDocumentComments();
00083     if(forceDoc || !c->getDoc().isEmpty())
00084         getComment()->setWriteOutText(true);
00085     else
00086         getComment()->setWriteOutText(false);
00087 
00088 
00089     // Now set START/ENDING Text
00090     QString startText = "";
00091     // In Java, we need declare abstract only on classes
00092     if (c->getAbstract() && !isInterface)
00093         startText.append("abstract ");
00094 
00095     if (c->getVisibility() != Uml::Visibility::Public) {
00096         // We should probably emit a warning in here .. java doesn't like to allow
00097         // private/protected classes. The best we can do (I believe)
00098         // is to let these declarations default to "package visibility"
00099         // which is a level between traditional "private" and "protected"
00100         // scopes. To get this visibility level we just print nothing..
00101     } else
00102         startText.append("public ");
00103 
00104     if(parentDoc->parentIsInterface())
00105         startText.append("interface ");
00106     else
00107         startText.append("class ");
00108 
00109     startText.append(JavaClassName);
00110 
00111     // write inheritances out
00112     UMLClassifierList superclasses =
00113         c->findSuperClassConcepts(UMLClassifier::CLASS);
00114     UMLClassifierList superinterfaces =
00115         c->findSuperClassConcepts(UMLClassifier::INTERFACE);
00116     int nrof_superclasses = superclasses.count();
00117     int nrof_superinterfaces = superinterfaces.count();
00118 
00119     // write out inheritance
00120     int i = 0;
00121     if(nrof_superclasses >0)
00122         startText.append(" extends ");
00123     for (UMLClassifier * concept= superclasses.first(); concept; concept = superclasses.next())
00124     {
00125         startText.append(parentDoc->cleanName(concept->getName()));
00126         if(i != (nrof_superclasses-1))
00127             startText.append(", ");
00128         i++;
00129     }
00130 
00131     // write out what we 'implement'
00132     i = 0;
00133     if(nrof_superinterfaces >0)
00134     {
00135         // In Java interfaces "extend" other interfaces. Classes "implement" interfaces
00136         if(isInterface)
00137             startText.append(" extends ");
00138         else
00139             startText.append(" implements ");
00140     }
00141     for (UMLClassifier * concept= superinterfaces.first(); concept; concept = superinterfaces.next())
00142     {
00143         startText.append(parentDoc->cleanName(concept->getName()));
00144         if(i != (nrof_superinterfaces-1))
00145             startText.append(", ");
00146         i++;
00147     }
00148 
00149     // Set the header and end text for the hier.codeblock
00150     setStartText(startText+" {");
00151 
00152     // setEndText("}"); // not needed
00153 
00154 }
00155 
00156 void JavaClassDeclarationBlock::init (JavaClassifierCodeDocument *parentDoc, const QString &comment)
00157 {
00158 
00159     setComment(new JavaCodeDocumentation(parentDoc));
00160     getComment()->setText(comment);
00161 
00162     setEndText("}");
00163 
00164     updateContent();
00165 
00166 }
00167 
00168 
00169 #include "javaclassdeclarationblock.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:57 2007 by doxygen 1.4.1 written by Dimitri van Heesch, © 1997-2003