umbrello API Documentation

javacodegenerator.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   : Thu Jun 19 2003
00015  */
00016 
00017 // own header
00018 #include "javacodegenerator.h"
00019 
00020 // qt/kde includes
00021 #include <qregexp.h>
00022 #include <kconfig.h>
00023 #include <kdebug.h>
00024 #include <klocale.h>
00025 #include <kmessagebox.h>
00026 
00027 // local includes
00028 #include "javacodecomment.h"
00029 #include "codeviewerdialog.h"
00030 #include "../uml.h"
00031 
00032 const bool JavaCodeGenerator::DEFAULT_BUILD_ANT_DOC = false;
00033 
00034 // Constructors/Destructors
00035 //
00036 
00037 JavaCodeGenerator::JavaCodeGenerator (QDomElement & elem)
00038   : CodeGenerator(elem)
00039 {
00040     init();
00041 }
00042 
00043 JavaCodeGenerator::JavaCodeGenerator ()
00044 {
00045     init();
00046 }
00047 
00048 JavaCodeGenerator::~JavaCodeGenerator ( ) { }
00049 
00050 //
00051 // Methods
00052 //
00053 
00054 // Accessor methods
00055 //
00056 
00057 // return our language
00058 Uml::Programming_Language JavaCodeGenerator::getLanguage() {
00059     return Uml::pl_Java;
00060 }
00061 
00066 void JavaCodeGenerator::setCreateANTBuildFile ( bool buildIt) {
00067     m_createANTBuildFile = buildIt;
00068     CodeDocument * antDoc = findCodeDocumentByID("ANTDOC");
00069     if (antDoc)
00070         antDoc->setWriteOutCode(buildIt);
00071 }
00072 
00077 bool JavaCodeGenerator::getCreateANTBuildFile ( ) {
00078     return m_createANTBuildFile;
00079 }
00080 
00081 // In the Java version, we make the ANT build file also available.
00082 CodeViewerDialog * JavaCodeGenerator::getCodeViewerDialog ( QWidget* parent, CodeDocument *doc,
00083         Settings::CodeViewerState state)
00084 {
00085     CodeViewerDialog *dialog = new CodeViewerDialog(parent, doc, state);
00086     if(getCreateANTBuildFile())
00087         dialog->addCodeDocument(findCodeDocumentByID("ANTDOC"));
00088     return dialog;
00089 }
00090 
00091 
00092 JavaCodeGenerationPolicy * JavaCodeGenerator::getJavaPolicy() {
00093     return dynamic_cast<JavaCodeGenerationPolicy*>(UMLApp::app()->getPolicyExt());
00094 }
00095 
00096 bool JavaCodeGenerator::getAutoGenerateAttribAccessors ( )
00097 {
00098     return getJavaPolicy()->getAutoGenerateAttribAccessors ();
00099 }
00100 
00101 bool JavaCodeGenerator::getAutoGenerateAssocAccessors ( )
00102 {
00103     return getJavaPolicy()->getAutoGenerateAssocAccessors ();
00104 }
00105 
00106 QString JavaCodeGenerator::getListFieldClassName () {
00107     return QString("Vector");
00108 }
00109 
00110 // Other methods
00111 //
00112 
00113 QString JavaCodeGenerator::capitalizeFirstLetter(const QString &string)
00114 {
00115     // we could lowercase everything tostart and then capitalize? Nah, it would
00116     // screw up formatting like getMyRadicalVariable() to getMyradicalvariable(). Bah.
00117     QChar firstChar = string.at(0);
00118     return firstChar.upper() + string.mid(1);
00119 }
00120 
00121 // IF the type is "string" we need to declare it as
00122 // the Java Object "String" (there is no string primative in Java).
00123 // Same thing again for "bool" to "boolean"
00124 QString JavaCodeGenerator::fixTypeName(const QString &string)
00125 {
00126     if (string.isEmpty() || string.contains(QRegExp("^\\s+$")))
00127         return "void";
00128     if (string == "string")
00129         return "String";
00130     if (string == "bool")
00131         return "boolean";
00132     return cleanName(string);
00133 }
00134 
00138 JavaANTCodeDocument * JavaCodeGenerator::newANTCodeDocument ( ) {
00139     return new JavaANTCodeDocument();
00140 }
00141 
00146 CodeDocument * JavaCodeGenerator::newClassifierCodeDocument ( UMLClassifier * c)
00147 {
00148     JavaClassifierCodeDocument * doc = new JavaClassifierCodeDocument(c);
00149     doc->initCodeClassFields();
00150     return doc;
00151 }
00152 
00153 void JavaCodeGenerator::init() {
00154     // load Classifier documents from parent document
00155     //initFromParentDocument();
00156 
00157     // add in an ANT document
00158     JavaANTCodeDocument * buildDoc = newANTCodeDocument( );
00159     addCodeDocument(buildDoc);
00160 
00161     // set our 'writeout' policy for that code document
00162     setCreateANTBuildFile(DEFAULT_BUILD_ANT_DOC);
00163 }
00164 
00165 QStringList JavaCodeGenerator::defaultDatatypes() {
00166     QStringList l;
00167     l.append("int");
00168     l.append("char");
00169     l.append("boolean");
00170     l.append("float");
00171     l.append("double");
00172     l.append("byte");
00173     l.append("short");
00174     l.append("long");
00175     l.append("String");
00176     return l;
00177 }
00178 
00179 const QStringList JavaCodeGenerator::reservedKeywords() const {
00180 
00181     static QStringList keywords;
00182 
00183     if (keywords.isEmpty()) {
00184         keywords << "abstract"
00185         << "AbstractMethodError"
00186         << "ArithmeticException"
00187         << "ArrayIndexOutOfBoundsException"
00188         << "ArrayStoreException"
00189         << "assert"
00190         << "AssertionError"
00191         << "auto"
00192         << "boolean"
00193         << "Boolean"
00194         << "break"
00195         << "byte"
00196         << "Byte"
00197         << "catch"
00198         << "char"
00199         << "Character"
00200         << "CharSequence"
00201         << "Class"
00202         << "ClassCastException"
00203         << "ClassCircularityError"
00204         << "ClassFormatError"
00205         << "ClassLoader"
00206         << "ClassNotFoundException"
00207         << "clone"
00208         << "Cloneable"
00209         << "CloneNotSupportedException"
00210         << "Comparable"
00211         << "Compiler"
00212         << "const"
00213         << "continue"
00214         << "default"
00215         << "delete"
00216         << "do"
00217         << "double"
00218         << "Double"
00219         << "else"
00220         << "enum"
00221         << "equals"
00222         << "Error"
00223         << "Exception"
00224         << "ExceptionInInitializerError"
00225         << "extends"
00226         << "extern"
00227         << "false"
00228         << "final"
00229         << "finalize"
00230         << "finally"
00231         << "float"
00232         << "Float"
00233         << "for"
00234         << "friend"
00235         << "getClass"
00236         << "goto"
00237         << "hashCode"
00238         << "if"
00239         << "IllegalAccessError"
00240         << "IllegalAccessException"
00241         << "IllegalArgumentException"
00242         << "IllegalMonitorStateException"
00243         << "IllegalStateException"
00244         << "IllegalThreadStateException"
00245         << "implements"
00246         << "import"
00247         << "IncompatibleClassChangeError"
00248         << "IndexOutOfBoundsException"
00249         << "InheritableThreadLocal"
00250         << "inline"
00251         << "instanceof"
00252         << "InstantiationError"
00253         << "InstantiationException"
00254         << "int"
00255         << "Integer"
00256         << "interface"
00257         << "InternalError"
00258         << "InterruptedException"
00259         << "LinkageError"
00260         << "long"
00261         << "Long"
00262         << "Math"
00263         << "native"
00264         << "NegativeArraySizeException"
00265         << "new"
00266         << "nextgroup=javaUserLabelRef"
00267         << "NoClassDefFoundError"
00268         << "NoSuchFieldError"
00269         << "NoSuchFieldException"
00270         << "NoSuchMethodError"
00271         << "NoSuchMethodException"
00272         << "notify"
00273         << "notifyAll"
00274         << "null"
00275         << "NullPointerException"
00276         << "Number"
00277         << "NumberFormatException"
00278         << "Object"
00279         << "operator"
00280         << "OutOfMemoryError"
00281         << "package"
00282         << "Package"
00283         << "private"
00284         << "Process"
00285         << "protected"
00286         << "public"
00287         << "redeclared"
00288         << "register"
00289         << "return"
00290         << "Runnable"
00291         << "Runtime"
00292         << "RuntimeException"
00293         << "RuntimePermission"
00294         << "SecurityException"
00295         << "SecurityManager"
00296         << "serializable"
00297         << "short"
00298         << "Short"
00299         << "signed"
00300         << "sizeof"
00301         << "skipwhite"
00302         << "StackOverflowError"
00303         << "StackTraceElement"
00304         << "static"
00305         << "strictfp"
00306         << "StrictMath"
00307         << "String"
00308         << "StringBuffer"
00309         << "StringIndexOutOfBoundsException"
00310         << "struct"
00311         << "super"
00312         << "switch"
00313         << "synchronized"
00314         << "template"
00315         << "this"
00316         << "Thread"
00317         << "ThreadDeath"
00318         << "ThreadGroup"
00319         << "ThreadLocal"
00320         << "throw"
00321         << "Throwable"
00322         << "throws"
00323         << "toString"
00324         << "transient"
00325         << "true"
00326         << "try"
00327         << "typedef"
00328         << "union"
00329         << "UnknownError"
00330         << "UnsatisfiedLinkError"
00331         << "unsigned"
00332         << "UnsupportedClassVersionError"
00333         << "UnsupportedOperationException"
00334         << "VerifyError"
00335         << "VirtualMachineError"
00336         << "void"
00337         << "Void"
00338         << "volatile"
00339         << "wait"
00340         << "while";
00341     }
00342 
00343     return keywords;
00344 }
00345 
00346 #include "javacodegenerator.moc"
00347 
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