[Uml-devel] KDE/kdesdk/umbrello/umbrello/codegenerators
Andi Fischer
andi.fischer at hispeed.ch
Mon Dec 17 20:46:18 UTC 2007
SVN commit 749772 by fischer:
adding code to the body of an operation if it exists
M +25 -20 aswriter.cpp
M +23 -20 aswriter.h
M +26 -22 jswriter.cpp
M +23 -20 jswriter.h
M +16 -7 pascalwriter.cpp
M +11 -9 pascalwriter.h
--- trunk/KDE/kdesdk/umbrello/umbrello/codegenerators/aswriter.cpp #749771:749772
@@ -26,15 +26,17 @@
#include <qregexp.h>
#include <qtextstream.h>
-ASWriter::ASWriter() {
+ASWriter::ASWriter()
+{
}
-ASWriter::~ASWriter() {}
+ASWriter::~ASWriter()
+{
+}
-
void ASWriter::writeClass(UMLClassifier *c)
{
- if(!c)
+ if (!c)
{
uDebug()<<"Cannot write class of NULL concept!";
return;
@@ -52,7 +54,7 @@
}
QFile fileas;
- if(!openFile(fileas,fileName))
+ if (!openFile(fileas,fileName))
{
emit codeGenerated(c, false);
return;
@@ -63,18 +65,16 @@
//Start generating the code!!
/////////////////////////////
-
//try to find a heading file (license, coments, etc)
QString str;
str = getHeadingFile(".as");
- if(!str.isEmpty())
+ if (!str.isEmpty())
{
str.replace(QRegExp("%filename%"),fileName+".as");
str.replace(QRegExp("%filepath%"),fileas.fileName());
as << str << m_endl;
}
-
//write includes
UMLPackageList includes;
findObjectsRelated(c,includes);
@@ -88,7 +88,7 @@
as << m_endl;
//Write class Documentation if there is somthing or if force option
- if(forceDoc() || !c->getDoc().isEmpty())
+ if (forceDoc() || !c->getDoc().isEmpty())
{
as << m_endl << "/**" << m_endl;
as << " * class " << classname << m_endl;
@@ -101,7 +101,7 @@
UMLAssociationList compositions = c->getCompositions();
//check if class is abstract and / or has abstract methods
- if(c->getAbstract() && !hasAbstractOps(c))
+ if (c->getAbstract() && !hasAbstractOps(c))
as << "/******************************* Abstract Class ****************************" << m_endl << " "
<< classname << " does not have any pure virtual methods, but its author" << m_endl
<< " defined it as an abstract class, so you should not use it directly." << m_endl
@@ -152,14 +152,14 @@
}
//associations
- if (forceSections() || !aggregations.isEmpty ())
+ if (forceSections() || !aggregations.isEmpty())
{
as << m_endl << m_indentation << "/**Aggregations: */" << m_endl;
writeAssociation(classname, aggregations , as );
}
- if( forceSections() || !compositions.isEmpty())
+ if (forceSections() || !compositions.isEmpty())
{
as << m_endl << m_indentation << "/**Compositions: */" << m_endl;
writeAssociation(classname, compositions , as );
@@ -304,21 +304,26 @@
<< (!(at->getInitialValue().isEmpty()) ? (QString(" = ")+at->getInitialValue()) : QString(""))
<< ((j < i-1)?", ":"");
}
- as << ")" << m_endl << "{" << m_endl <<
- m_indentation << m_endl << "}" << m_endl;
+ as << ")" << m_endl << "{" << m_endl;
+ QString sourceCode = op->getSourceCode();
+ if (sourceCode.isEmpty()) {
+ as << m_indentation << m_endl;
+ }
+ else {
+ as << formatSourceCode(sourceCode, m_indentation);
+ }
+ as << "}" << m_endl;
as << m_endl << m_endl;
}//end for
}
-/**
- * returns "ActionScript"
- */
-Uml::Programming_Language ASWriter::getLanguage() {
+Uml::Programming_Language ASWriter::getLanguage()
+{
return Uml::pl_ActionScript;
}
-const QStringList ASWriter::reservedKeywords() const {
-
+const QStringList ASWriter::reservedKeywords() const
+{
static QStringList keywords;
if ( keywords.isEmpty() ) {
--- trunk/KDE/kdesdk/umbrello/umbrello/codegenerators/aswriter.h #749771:749772
@@ -23,10 +23,11 @@
#include "../umlassociationlist.h"
/**
- * class ASWriter is a ActionScript code generator for UMLClassifier objects
- * Just call writeClass and feed it a UMLClassifier;
- */
-class ASWriter : public SimpleCodeGenerator {
+ * Class ASWriter is a ActionScript code generator for UMLClassifier objects.
+ * Just call writeClass and feed it a UMLClassifier.
+ */
+class ASWriter : public SimpleCodeGenerator
+{
Q_OBJECT
public:
@@ -34,18 +35,20 @@
virtual ~ASWriter();
/**
- * call this method to generate Actionscript code for a UMLClassifier
- * @param c the class you want to generate code for.
- */
+ * Call this method to generate Actionscript code for a UMLClassifier.
+ * @param c the class you want to generate code for
+ */
virtual void writeClass(UMLClassifier *c);
/**
- * returns "ActionScript"
+ * Returns "ActionScript".
+ * @return the programming language identifier
*/
virtual Uml::Programming_Language getLanguage();
/**
- * get list of reserved keywords
+ * Get list of reserved keywords.
+ * @return the list of reserved keywords
*/
virtual const QStringList reservedKeywords() const;
@@ -53,25 +56,25 @@
private:
/**
- * we do not want to write the comment "Private methods" twice
+ * We do not want to write the comment "Private methods" twice.
*/
bool bPrivateSectionCommentIsWritten;
/**
- * write a list of class operations
- *
- * @param classname the name of the class
- * @param opList the list of operations
- * @param as output stream for the AS file
- */
+ * Write a list of class operations.
+ *
+ * @param classname the name of the class
+ * @param opList the list of operations
+ * @param as output stream for the AS file
+ */
void writeOperations(QString classname, UMLOperationList *opList, QTextStream &as);
/**
- * write a list of associations
+ * Write a list of associations.
*
- * @param classname the name of the class
- * @param assocList the list of associations
- * @param as output stream for the AS file
+ * @param classname the name of the class
+ * @param assocList the list of associations
+ * @param as output stream for the AS file
*/
void writeAssociation(QString& classname, UMLAssociationList& assoclist , QTextStream &as);
--- trunk/KDE/kdesdk/umbrello/umbrello/codegenerators/jswriter.cpp #749771:749772
@@ -27,15 +27,17 @@
#include <qregexp.h>
#include <qtextstream.h>
-JSWriter::JSWriter() {
+JSWriter::JSWriter()
+{
}
-JSWriter::~JSWriter() {}
+JSWriter::~JSWriter()
+{
+}
-
void JSWriter::writeClass(UMLClassifier *c)
{
- if(!c)
+ if (!c)
{
uDebug()<<"Cannot write class of NULL concept!";
return;
@@ -53,7 +55,7 @@
}
QFile filejs;
- if(!openFile(filejs, fileName))
+ if (!openFile(filejs, fileName))
{
emit codeGenerated(c, false);
return;
@@ -68,14 +70,13 @@
//try to find a heading file (license, coments, etc)
QString str;
str = getHeadingFile(".js");
- if(!str.isEmpty())
+ if (!str.isEmpty())
{
str.replace(QRegExp("%filename%"),fileName);
str.replace(QRegExp("%filepath%"),filejs.fileName());
js << str << m_endl;
}
-
//write includes
UMLPackageList includes;
findObjectsRelated(c,includes);
@@ -89,7 +90,7 @@
js << m_endl;
//Write class Documentation if there is somthing or if force option
- if(forceDoc() || !c->getDoc().isEmpty())
+ if (forceDoc() || !c->getDoc().isEmpty())
{
js << m_endl << "/**" << m_endl;
js << " * class " << classname << m_endl;
@@ -97,9 +98,8 @@
js << " */" << m_endl << m_endl;
}
-
//check if class is abstract and / or has abstract methods
- if(c->getAbstract() && !hasAbstractOps(c))
+ if (c->getAbstract() && !hasAbstractOps(c))
js << "/******************************* Abstract Class ****************************" << m_endl << " "
<< classname << " does not have any pure virtual methods, but its author" << m_endl
<< " defined it as an abstract class, so you should not use it directly." << m_endl
@@ -136,7 +136,7 @@
<< formatDoc(at->getDoc(), m_indentation + " * ")
<< m_indentation << " */" << m_endl;
}
- if(!at->getInitialValue().isEmpty())
+ if (!at->getInitialValue().isEmpty())
{
js << m_indentation << "this.m_" << cleanName(at->getName()) << " = " << at->getInitialValue() << ";" << m_endl;
}
@@ -149,14 +149,14 @@
//associations
UMLAssociationList aggregations = c->getAggregations();
- if (forceSections() || !aggregations.isEmpty ())
+ if (forceSections() || !aggregations.isEmpty())
{
js << m_endl << m_indentation << "/**Aggregations: */" << m_endl;
writeAssociation(classname, aggregations , js );
}
UMLAssociationList compositions = c->getCompositions();
- if( forceSections() || !compositions.isEmpty())
+ if (forceSections() || !compositions.isEmpty())
{
js << m_endl << m_indentation << "/**Compositions: */" << m_endl;
writeAssociation(classname, compositions , js );
@@ -226,7 +226,6 @@
void JSWriter::writeOperations(QString classname, UMLOperationList *opList, QTextStream &js)
{
-
foreach (UMLOperation* op , *opList )
{
UMLAttributeList atl = op->getParmList();
@@ -260,21 +259,26 @@
<< ((j < i-1)?", ":"");
j++;
}
- js << ")" << m_endl << "{" << m_endl <<
- m_indentation << m_endl << "}" << m_endl;
+ js << ")" << m_endl << "{" << m_endl;
+ QString sourceCode = op->getSourceCode();
+ if (sourceCode.isEmpty()) {
+ js << m_indentation << m_endl;
+ }
+ else {
+ js << formatSourceCode(sourceCode, m_indentation);
+ }
+ js << "}" << m_endl;
js << m_endl << m_endl;
}//end for
}
-/**
- * returns "JavaScript"
- */
-Uml::Programming_Language JSWriter::getLanguage() {
+Uml::Programming_Language JSWriter::getLanguage()
+{
return Uml::pl_JavaScript;
}
-const QStringList JSWriter::reservedKeywords() const {
-
+const QStringList JSWriter::reservedKeywords() const
+{
static QStringList keywords;
if (keywords.isEmpty()) {
--- trunk/KDE/kdesdk/umbrello/umbrello/codegenerators/jswriter.h #749771:749772
@@ -23,10 +23,11 @@
#include "../umlassociationlist.h"
/**
- * class JSWriter is a JavaScript code generator for UMLClassifier objects
- * Just call writeClass and feed it a UMLClassifier;
- */
-class JSWriter : public SimpleCodeGenerator {
+ * Class JSWriter is a JavaScript code generator for UMLClassifier objects.
+ * Just call writeClass and feed it a UMLClassifier.
+ */
+class JSWriter : public SimpleCodeGenerator
+{
Q_OBJECT
public:
@@ -34,43 +35,45 @@
virtual ~JSWriter();
/**
- * call this method to generate Actionscript code for a UMLClassifier
- * @param c the class you want to generate code for.
- */
+ * Call this method to generate Actionscript code for a UMLClassifier.
+ * @param c the class you want to generate code for
+ */
virtual void writeClass(UMLClassifier *c);
/**
- * returns "JavaScript"
+ * Returns "JavaScript".
+ * @return the programming language identifier
*/
virtual Uml::Programming_Language getLanguage();
/**
- * get list of reserved keywords
+ * Get list of reserved keywords.
+ * @return the list of reserved keywords
*/
virtual const QStringList reservedKeywords() const;
private:
/**
- * we do not want to write the comment "Private methods" twice
+ * We do not want to write the comment "Private methods" twice.
*/
bool bPrivateSectionCommentIsWritten;
/**
- * write a list of class operations
- *
- * @param classname the name of the class
- * @param opList the list of operations
- * @param js output stream for the JS file
- */
+ * Write a list of class operations.
+ *
+ * @param classname the name of the class
+ * @param opList the list of operations
+ * @param js output stream for the JS file
+ */
void writeOperations(QString classname, UMLOperationList *opList, QTextStream &js);
/**
- * write a list of associations
+ * Write a list of associations.
*
- * @param classname the name of the class
- * @param assocList the list of associations
- * @param as output stream for the AS file
+ * @param classname the name of the class
+ * @param assocList the list of associations
+ * @param js output stream for the JS file
*/
void writeAssociation(QString& classname, UMLAssociationList& assoclist , QTextStream &js);
};
--- trunk/KDE/kdesdk/umbrello/umbrello/codegenerators/pascalwriter.cpp #749771:749772
@@ -39,9 +39,6 @@
PascalWriter::~PascalWriter() {}
-/**
- * returns "Pascal"
- */
Uml::Programming_Language PascalWriter::getLanguage() {
return Uml::pl_Pascal;
}
@@ -358,10 +355,22 @@
pas << ")";
}
if (! use_procedure)
- pas << " : " << rettype;
- pas << "; virtual; abstract;" << m_endl << m_endl;
- // TBH, we make the methods abstract here because we don't have the means
- // for generating meaningful implementations.
+ pas << " : " << rettype << ";";
+
+ QString sourceCode = op->getSourceCode();
+ if (sourceCode.isEmpty()) {
+ pas << " virtual; abstract;" << m_endl << m_endl;
+ // TBH, we make the methods abstract here because we don't have the means
+ // for generating meaningful implementations.
+ }
+ else {
+ pas << m_endl;
+ pas << getIndent() << "begin" << m_endl;
+ m_indentLevel++;
+ pas << formatSourceCode(sourceCode, getIndent());
+ m_indentLevel--;
+ pas << getIndent() << "end;" << m_endl << m_endl;
+ }
}
QStringList PascalWriter::defaultDatatypes() {
--- trunk/KDE/kdesdk/umbrello/umbrello/codegenerators/pascalwriter.h #749771:749772
@@ -18,9 +18,9 @@
class UMLOperation;
/**
- * Pascal class writer
+ * Pascal class writer.
* @author Oliver Kellogg
- * Bugs and comments to uml-devel at lists.sf.net or http://bugs.kde.org
+ * Bugs and comments to uml-devel at lists.sf.net or http://bugs.kde.org.
*/
class PascalWriter : public SimpleCodeGenerator
{
@@ -38,13 +38,14 @@
virtual ~PascalWriter ();
/**
- * call this method to generate Ada code for a UMLClassifier
- * @param c the class to generate code for
+ * Call this method to generate Pascal code for a UMLClassifier.
+ * @param c the class to generate code for
*/
virtual void writeClass (UMLClassifier *c);
/**
- * returns "Pascal"
+ * Returns "Pascal".
+ * @return the programming language identifier
*/
virtual Uml::Programming_Language getLanguage();
@@ -52,21 +53,22 @@
/**
* Check whether the given string is a reserved word for the
- * language of this code generator
+ * language of this code generator.
*
- * @param rPossiblyReservedKeyword The string to check.
+ * @param rPossiblyReservedKeyword the string to check
*/
virtual bool isReservedKeyword(const QString & rPossiblyReservedKeyword);
/**
- * get list of reserved keywords
+ * Get list of reserved keywords.
+ * @return the list of reserved keywords
*/
virtual const QStringList reservedKeywords() const;
private:
/**
- * write one operation
+ * Write one operation.
* @param op the class for which we are generating code
* @param ada the stream associated with the output file
*/
More information about the umbrello-devel
mailing list