rubycodeclassfielddeclarationblock.cpp
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #include "rubycodeclassfielddeclarationblock.h"
00013
00014 #include "rubycodeclassfield.h"
00015 #include "rubyclassifiercodedocument.h"
00016 #include "rubycodegenerationpolicy.h"
00017 #include "../classifier.h"
00018 #include "../umlrole.h"
00019 #include "../codegenerator.h"
00020 #include "../uml.h"
00021
00022
00023
00024
00025 RubyCodeClassFieldDeclarationBlock::RubyCodeClassFieldDeclarationBlock ( CodeClassField * parent )
00026 : CodeClassFieldDeclarationBlock ( parent )
00027 {
00028 setOverallIndentationLevel(1);
00029 updateContent();
00030 }
00031
00032 RubyCodeClassFieldDeclarationBlock::~RubyCodeClassFieldDeclarationBlock ( ) { }
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00045 void RubyCodeClassFieldDeclarationBlock::updateContent( )
00046 {
00047
00048 CodeClassField * cf = getParentClassField();
00049 ClassifierCodeDocument * doc = cf->getParentDocument();
00050 RubyCodeClassField * rcf = dynamic_cast<RubyCodeClassField*>(cf);
00051 RubyClassifierCodeDocument* rdoc = dynamic_cast<RubyClassifierCodeDocument*>(doc);
00052 CodeGenerationPolicy * p = UMLApp::app()->getCommonPolicy();
00053 CodeGenerationPolicy::ScopePolicy scopePolicy = p->getAssociationFieldScope();
00054
00055
00056 QString notes = getParentObject()->getDoc();
00057 getComment()->setText(notes);
00058
00059
00060 QString staticValue = getParentObject()->getStatic() ? "static " : "";
00061 QString scopeStr = rdoc->scopeToRubyDecl(getParentObject()->getVisibility());
00062
00063
00064 if(!rcf->parentIsAttribute())
00065 {
00066 switch (scopePolicy) {
00067 case CodeGenerationPolicy::Public:
00068 case CodeGenerationPolicy::Private:
00069 case CodeGenerationPolicy::Protected:
00070 scopeStr = rdoc->scopeToRubyDecl((Uml::Visibility::Value) scopePolicy);
00071 break;
00072 default:
00073 case CodeGenerationPolicy::FromParent:
00074
00075 break;
00076 }
00077 }
00078
00079 QString typeName = rcf->getTypeName();
00080 QString fieldName = rcf->getFieldName();
00081 QString initialV = rcf->getInitialValue();
00082
00083 if (!cf->parentIsAttribute() && !cf->fieldIsSingleValue())
00084 typeName = "Array";
00085
00086 QString body = staticValue+scopeStr+' '+typeName+' '+fieldName;
00087 if (!initialV.isEmpty())
00088 body.append(" = " + initialV);
00089 else if (!cf->parentIsAttribute())
00090 {
00091 UMLRole * role = dynamic_cast<UMLRole*>(cf->getParentObject());
00092 if (role->getObject()->getBaseType() == Uml::ot_Interface)
00093 {
00094
00095 } else {
00096
00097
00098
00099 if(cf->fieldIsSingleValue())
00100 {
00101 if(!typeName.isEmpty())
00102 body.append(" = " + typeName + ".new()");
00103 } else
00104 body.append(" = []");
00105 }
00106 }
00107
00108 setText(body);
00109
00110 }
00111
00112 #include "rubycodeclassfielddeclarationblock.moc"
This file is part of the documentation for umbrello Version 3.1.0.