umbrello API Documentation

javacodeclassfielddeclarationblock.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   : Fri Jul 25 2003
00015  */
00016 
00017 #include "javacodeclassfielddeclarationblock.h"
00018 
00019 #include "javacodeclassfield.h"
00020 #include "javaclassifiercodedocument.h"
00021 #include "javacodegenerationpolicy.h"
00022 #include "../codegenerator.h"
00023 #include "../classifier.h"
00024 #include "../umlrole.h"
00025 #include "../uml.h"
00026 
00027 // Constructors/Destructors
00028 //
00029 
00030 JavaCodeClassFieldDeclarationBlock::JavaCodeClassFieldDeclarationBlock ( CodeClassField * parent )
00031         : CodeClassFieldDeclarationBlock ( parent )
00032 {
00033     setOverallIndentationLevel(1);
00034     updateContent();
00035 }
00036 
00037 JavaCodeClassFieldDeclarationBlock::~JavaCodeClassFieldDeclarationBlock ( ) { }
00038 
00039 //
00040 // Methods
00041 //
00042 
00043 
00044 
00045 // Other methods
00046 //
00047 
00050 void JavaCodeClassFieldDeclarationBlock::updateContent( )
00051 {
00052 
00053     CodeClassField * cf = getParentClassField();
00054     ClassifierCodeDocument * doc = cf->getParentDocument();
00055     JavaCodeClassField * jcf = dynamic_cast<JavaCodeClassField*>(cf);
00056     JavaClassifierCodeDocument* jdoc = dynamic_cast<JavaClassifierCodeDocument*>(doc);
00057     CodeGenerationPolicy * commonpolicy = UMLApp::app()->getCommonPolicy();
00058 
00059     CodeGenerationPolicy::ScopePolicy scopePolicy = commonpolicy->getAssociationFieldScope();
00060 
00061     // Set the comment
00062     QString notes = getParentObject()->getDoc();
00063     getComment()->setText(notes);
00064 
00065     // Set the body
00066     QString staticValue = getParentObject()->getStatic() ? "static " : "";
00067     QString scopeStr = jdoc->scopeToJavaDecl(getParentObject()->getVisibility());
00068 
00069     // IF this is from an association, then scope taken as appropriate to policy
00070     if(!jcf->parentIsAttribute())
00071     {
00072         switch (scopePolicy) {
00073         case CodeGenerationPolicy::Public:
00074         case CodeGenerationPolicy::Private:
00075         case CodeGenerationPolicy::Protected:
00076               scopeStr = jdoc->scopeToJavaDecl((Uml::Visibility::Value) scopePolicy);
00077             break;
00078         default:
00079         case CodeGenerationPolicy::FromParent:
00080             // do nothing here... will leave as from parent object
00081             break;
00082         }
00083     }
00084 
00085     QString typeName = jcf->getTypeName();
00086     QString fieldName = jcf->getFieldName();
00087     QString initialV = jcf->getInitialValue();
00088 
00089     if (!cf->parentIsAttribute() && !cf->fieldIsSingleValue())
00090         typeName = "List";
00091 
00092     QString body = staticValue+scopeStr+' '+typeName+' '+fieldName;
00093     if (!initialV.isEmpty())
00094         body.append(" = " + initialV);
00095     else if (!cf->parentIsAttribute())
00096     {
00097         UMLRole * role = dynamic_cast<UMLRole*>(cf->getParentObject());
00098         if (role->getObject()->getBaseType() == Uml::ot_Interface)
00099         {
00100             // do nothing.. can't instanciate an interface
00101         } else {
00102 
00103             // FIX?: IF a constructor method exists in the classifiercodedoc
00104             // of the parent Object, then we can use that instead (if its empty).
00105             if(cf->fieldIsSingleValue())
00106             {
00107                 if(!typeName.isEmpty())
00108                     body.append(" = new " + typeName + " ( )");
00109             } else
00110                 body.append(" = new Vector ( )");
00111         }
00112     }
00113 
00114     setText(body+';');
00115 
00116 }
00117 
00118 #include "javacodeclassfielddeclarationblock.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