void CPPHeaderCodeClassFieldDeclarationBlock::updateContent() { UMLObject *umlparent = CodeClassFieldDeclarationBlock::getParentObject(); if (umlparent == NULL) { return; } CodeClassField * cf = getParentClassField(); CPPCodeClassField * hcppcf = dynamic_cast<CPPCodeClassField*>(cf); // Check for dynamic casting failure! if (hcppcf == NULL) { uError() << "hcppcf: invalid dynamic cast"; return; } // Set the comment QString notes = umlparent->doc(); getComment()->setText(notes); if (notes.isEmpty()) getComment()->setWriteOutText(false); else getComment()->setWriteOutText(true); // Set the body QString staticValue = umlparent->isStatic() ? QLatin1String("static ") : QString(); QString typeName = hcppcf->getTypeName(); QString fieldName = hcppcf->getFieldName(); // Ugh. Sloppy exception. if (!cf->parentIsAttribute() && !cf->fieldIsSingleValue()) typeName = hcppcf->getListFieldClassName(); QString body = staticValue + QLatin1Char(' ') + typeName + QLatin1Char(' ') + fieldName + QLatin1Char(';'); setText(body); }
// This method will cause the class to rebuild its text representation. // based on the parent classifier object. // For any situation in which this is called, we are either building the code // document up, or replacing/regenerating the existing auto-generated parts. As // such, we will want to insert everything we resonablely will want // during creation. We can set various parts of the document (esp. the // comments) to appear or not, as needed. void RubyClassifierCodeDocument::updateContent() { // Gather info on the various fields and parent objects of this class... UMLClassifier * c = getParentClassifier(); RubyCodeGenerator * gen = dynamic_cast<RubyCodeGenerator*>(UMLApp::app()->generator()); // first, set the global flag on whether or not to show classfield info // This depends on whether or not we have attribute/association classes const CodeClassFieldList * cfList = getCodeClassFieldList(); CodeClassFieldList::const_iterator it = cfList->begin(); CodeClassFieldList::const_iterator end = cfList->end(); for (; it != end; ++it) { CodeClassField * field = *it; if (field->parentIsAttribute()) field->setWriteOutMethods(gen->getAutoGenerateAttribAccessors()); else field->setWriteOutMethods(gen->getAutoGenerateAssocAccessors()); } // attribute-based ClassFields // we do it this way to have the static fields sorted out from regular ones CodeClassFieldList staticPublicAttribClassFields = getSpecificClassFields (CodeClassField::Attribute, true, Uml::Visibility::Public); CodeClassFieldList publicAttribClassFields = getSpecificClassFields (CodeClassField::Attribute, false, Uml::Visibility::Public); CodeClassFieldList staticProtectedAttribClassFields = getSpecificClassFields (CodeClassField::Attribute, true, Uml::Visibility::Protected); CodeClassFieldList protectedAttribClassFields = getSpecificClassFields (CodeClassField::Attribute, false, Uml::Visibility::Protected); CodeClassFieldList staticPrivateAttribClassFields = getSpecificClassFields (CodeClassField::Attribute, true, Uml::Visibility::Private); CodeClassFieldList privateAttribClassFields = getSpecificClassFields (CodeClassField::Attribute, false, Uml::Visibility::Private); // association-based ClassFields // don't care if they are static or not..all are lumped together CodeClassFieldList publicPlainAssocClassFields = getSpecificClassFields (CodeClassField::PlainAssociation, Uml::Visibility::Public); CodeClassFieldList publicAggregationClassFields = getSpecificClassFields (CodeClassField::Aggregation, Uml::Visibility::Public); CodeClassFieldList publicCompositionClassFields = getSpecificClassFields (CodeClassField::Composition, Uml::Visibility::Public); CodeClassFieldList protPlainAssocClassFields = getSpecificClassFields (CodeClassField::PlainAssociation, Uml::Visibility::Protected); CodeClassFieldList protAggregationClassFields = getSpecificClassFields (CodeClassField::Aggregation, Uml::Visibility::Protected); CodeClassFieldList protCompositionClassFields = getSpecificClassFields (CodeClassField::Composition, Uml::Visibility::Protected); CodeClassFieldList privPlainAssocClassFields = getSpecificClassFields (CodeClassField::PlainAssociation, Uml::Visibility::Private); CodeClassFieldList privAggregationClassFields = getSpecificClassFields (CodeClassField::Aggregation, Uml::Visibility::Private); CodeClassFieldList privCompositionClassFields = getSpecificClassFields (CodeClassField::Composition, Uml::Visibility::Private); bool isInterface = parentIsInterface(); bool hasOperationMethods = false; Q_ASSERT(c != NULL); if (c) { UMLOperationList list = c->getOpList(); hasOperationMethods = ! list.isEmpty(); } CodeGenerationPolicy *pol = UMLApp::app()->commonPolicy(); QString endLine = pol->getNewLineEndingChars(); // a shortcut..so we don't have to call this all the time // // START GENERATING CODE/TEXT BLOCKS and COMMENTS FOR THE DOCUMENT // // CLASS DECLARATION BLOCK // // get the declaration block. If it is not already present, add it too RubyClassDeclarationBlock * myClassDeclCodeBlock = getClassDecl(); addTextBlock(myClassDeclCodeBlock); // note: wont add if already present // declare public, protected and private methods, attributes (fields). // set the start text ONLY if this is the first time we created the objects. bool createdPublicBlock = publicBlock == 0 ? true : false; publicBlock = myClassDeclCodeBlock->getHierarchicalCodeBlock(QLatin1String("publicBlock"), QLatin1String("Public Items"), 0); if (createdPublicBlock) publicBlock->setStartText(QLatin1String("public")); bool createdProtBlock = protectedBlock == 0 ? true : false; protectedBlock = myClassDeclCodeBlock->getHierarchicalCodeBlock(QLatin1String("protectedBlock"), QLatin1String("Protected Items"), 0); if (createdProtBlock) protectedBlock->setStartText(QLatin1String("protected")); bool createdPrivBlock = privateBlock == 0 ? true : false; privateBlock = myClassDeclCodeBlock->getHierarchicalCodeBlock(QLatin1String("privateBlock"), QLatin1String("Private Items"), 0); if (createdPrivBlock) privateBlock->setStartText(QLatin1String("private")); // NOW create document in sections.. // now we want to populate the body of our class // our layout is the following general groupings of code blocks: // start ruby classifier document // header comment // class declaration // section: // section: // - methods section comment // sub-section: constructor ops // - constructor method section comment // - constructor methods (0+ codeblocks) // sub-section: accessors // - accessor method section comment // - static accessor methods (0+ codeblocks) // - non-static accessor methods (0+ codeblocks) // sub-section: non-constructor ops // - operation method section comment // - operations (0+ codeblocks) // end class declaration // end ruby classifier document // Q: Why use the more complicated scheme of arranging code blocks within codeblocks? // A: This will allow us later to preserve the format of our document so that if // codeblocks are added, they may be easily added in the correct place, rather than at // the end of the document, or by using a difficult algorithm to find the location of // the last appropriate code block sibling (which may not exist.. for example user adds // a constructor operation, but there currently are no constructor code blocks // within the document). // // METHODS section // // get/create the method codeblock // public methods HierarchicalCodeBlock * pubMethodsBlock = publicBlock->getHierarchicalCodeBlock(QLatin1String("pubMethodsBlock"), QString(), 1); CodeComment * pubMethodsComment = pubMethodsBlock->getComment(); bool forceDoc = pol->getCodeVerboseDocumentComments(); // set conditions for showing this comment if (!forceDoc && !hasClassFields() && !hasOperationMethods) pubMethodsComment->setWriteOutText(false); else pubMethodsComment->setWriteOutText(true); // protected methods HierarchicalCodeBlock * protMethodsBlock = protectedBlock->getHierarchicalCodeBlock(QLatin1String("protMethodsBlock"), QString(), 1); CodeComment * protMethodsComment = protMethodsBlock->getComment(); // set conditions for showing this comment if (!forceDoc && !hasClassFields() && !hasOperationMethods) protMethodsComment->setWriteOutText(false); else protMethodsComment->setWriteOutText(true); // private methods HierarchicalCodeBlock * privMethodsBlock = privateBlock->getHierarchicalCodeBlock(QLatin1String("privMethodsBlock"), QString(), 1); CodeComment * privMethodsComment = privMethodsBlock->getComment(); // set conditions for showing this comment if (!forceDoc && !hasClassFields() && !hasOperationMethods) privMethodsComment->setWriteOutText(false); else privMethodsComment->setWriteOutText(true); // METHODS sub-section : constructor methods // // public pubConstructorBlock = pubMethodsBlock->getHierarchicalCodeBlock(QLatin1String("constructionMethods"), QLatin1String("Constructors"), 1); // special condiions for showing comment: only when autogenerateding empty constructors // Although, we *should* check for other constructor methods too CodeComment * pubConstComment = pubConstructorBlock->getComment(); if (!forceDoc && (isInterface || !pol->getAutoGenerateConstructors())) pubConstComment->setWriteOutText(false); else pubConstComment->setWriteOutText(true); // protected protConstructorBlock = protMethodsBlock->getHierarchicalCodeBlock(QLatin1String("constructionMethods"), QLatin1String("Constructors"), 1); // special condiions for showing comment: only when autogenerateding empty constructors // Although, we *should* check for other constructor methods too CodeComment * protConstComment = protConstructorBlock->getComment(); if (!forceDoc && (isInterface || !pol->getAutoGenerateConstructors())) protConstComment->setWriteOutText(false); else protConstComment->setWriteOutText(true); // private privConstructorBlock = privMethodsBlock->getHierarchicalCodeBlock(QLatin1String("constructionMethods"), QLatin1String("Constructors"), 1); // special condiions for showing comment: only when autogenerateding empty constructors // Although, we *should* check for other constructor methods too CodeComment * privConstComment = privConstructorBlock->getComment(); if (!forceDoc && (isInterface || !pol->getAutoGenerateConstructors())) privConstComment->setWriteOutText(false); else privConstComment->setWriteOutText(true); // get/create the accessor codeblock // public HierarchicalCodeBlock * pubAccessorBlock = pubMethodsBlock->getHierarchicalCodeBlock(QLatin1String("accessorMethods"), QLatin1String("Accessor Methods"), 1); // set conditions for showing section comment CodeComment * pubAccessComment = pubAccessorBlock->getComment(); if (!forceDoc && !hasClassFields()) pubAccessComment->setWriteOutText(false); else pubAccessComment->setWriteOutText(true); // protected HierarchicalCodeBlock * protAccessorBlock = protMethodsBlock->getHierarchicalCodeBlock(QLatin1String("accessorMethods"), QLatin1String("Accessor Methods"), 1); // set conditions for showing section comment CodeComment * protAccessComment = protAccessorBlock->getComment(); if (!forceDoc && !hasClassFields()) protAccessComment->setWriteOutText(false); else protAccessComment->setWriteOutText(true); // private HierarchicalCodeBlock * privAccessorBlock = privMethodsBlock->getHierarchicalCodeBlock(QLatin1String("accessorMethods"), QLatin1String("Accessor Methods"), 1); // set conditions for showing section comment CodeComment * privAccessComment = privAccessorBlock->getComment(); if (!forceDoc && !hasClassFields()) privAccessComment->setWriteOutText(false); else privAccessComment->setWriteOutText(true); // now, 2 sub-sub sections in accessor block // add/update accessor methods for attributes HierarchicalCodeBlock * pubStaticAccessors = pubAccessorBlock->getHierarchicalCodeBlock(QLatin1String("pubStaticAccessorMethods"), QString(), 1); HierarchicalCodeBlock * pubRegularAccessors = pubAccessorBlock->getHierarchicalCodeBlock(QLatin1String("pubRegularAccessorMethods"), QString(), 1); pubStaticAccessors->getComment()->setWriteOutText(false); // never write block comment pubRegularAccessors->getComment()->setWriteOutText(false); // never write block comment HierarchicalCodeBlock * protStaticAccessors = protAccessorBlock->getHierarchicalCodeBlock(QLatin1String("protStaticAccessorMethods"), QString(), 1); HierarchicalCodeBlock * protRegularAccessors = protAccessorBlock->getHierarchicalCodeBlock(QLatin1String("protRegularAccessorMethods"), QString(), 1); protStaticAccessors->getComment()->setWriteOutText(false); // never write block comment protRegularAccessors->getComment()->setWriteOutText(false); // never write block comment HierarchicalCodeBlock * privStaticAccessors = privAccessorBlock->getHierarchicalCodeBlock(QLatin1String("privStaticAccessorMethods"), QString(), 1); HierarchicalCodeBlock * privRegularAccessors = privAccessorBlock->getHierarchicalCodeBlock(QLatin1String("privRegularAccessorMethods"), QString(), 1); privStaticAccessors->getComment()->setWriteOutText(false); // never write block comment privRegularAccessors->getComment()->setWriteOutText(false); // never write block comment // now add in accessors as appropriate // public stuff pubStaticAccessors->addCodeClassFieldMethods(staticPublicAttribClassFields); pubRegularAccessors->addCodeClassFieldMethods(publicAttribClassFields); pubRegularAccessors->addCodeClassFieldMethods(publicPlainAssocClassFields); pubRegularAccessors->addCodeClassFieldMethods(publicAggregationClassFields); pubRegularAccessors->addCodeClassFieldMethods(publicCompositionClassFields); // protected stuff protStaticAccessors->addCodeClassFieldMethods(staticProtectedAttribClassFields); protRegularAccessors->addCodeClassFieldMethods(protectedAttribClassFields); protRegularAccessors->addCodeClassFieldMethods(protPlainAssocClassFields); protRegularAccessors->addCodeClassFieldMethods(protAggregationClassFields); protRegularAccessors->addCodeClassFieldMethods(protCompositionClassFields); // private stuff privStaticAccessors->addCodeClassFieldMethods(staticPrivateAttribClassFields); privRegularAccessors->addCodeClassFieldMethods(privateAttribClassFields); privRegularAccessors->addCodeClassFieldMethods(privPlainAssocClassFields); privRegularAccessors->addCodeClassFieldMethods(privAggregationClassFields); privRegularAccessors->addCodeClassFieldMethods(privCompositionClassFields); // METHODS subsection : Operation methods (which aren't constructors) // // setup/get/create the operations codeblock // public pubOperationsBlock = pubMethodsBlock->getHierarchicalCodeBlock(QLatin1String("operationMethods"), QLatin1String("Operations"), 1); // set conditions for showing section comment CodeComment * pubOcomment = pubOperationsBlock->getComment(); if (!forceDoc && !hasOperationMethods) pubOcomment->setWriteOutText(false); else pubOcomment->setWriteOutText(true); //protected protOperationsBlock = protMethodsBlock->getHierarchicalCodeBlock(QLatin1String("operationMethods"), QLatin1String("Operations"), 1); // set conditions for showing section comment CodeComment * protOcomment = protOperationsBlock->getComment(); if (!forceDoc && !hasOperationMethods) protOcomment->setWriteOutText(false); else protOcomment->setWriteOutText(true); //private privOperationsBlock = privMethodsBlock->getHierarchicalCodeBlock(QLatin1String("operationMethods"), QLatin1String("Operations"), 1); // set conditions for showing section comment CodeComment * privOcomment = privOperationsBlock->getComment(); if (!forceDoc && !hasOperationMethods) privOcomment->setWriteOutText(false); else privOcomment->setWriteOutText(true); }
/** * This will be called by syncToParent whenever the parent object is "modified". */ void DCodeClassFieldDeclarationBlock::updateContent() { CodeClassField * cf = getParentClassField(); DCodeClassField * jcf = dynamic_cast<DCodeClassField*>(cf); if (!jcf) { uError() << "jcf: invalid dynamic cast"; return; } CodeGenerationPolicy * commonpolicy = UMLApp::app()->commonPolicy(); Uml::Visibility::Enum scopePolicy = commonpolicy->getAssociationFieldScope(); // Set the comment QString notes = getParentObject()->doc(); getComment()->setText(notes); // Set the body QString staticValue = getParentObject()->isStatic() ? QLatin1String("static ") : QString(); QString scopeStr = Uml::Visibility::toString(getParentObject()->visibility()); // IF this is from an association, then scope taken as appropriate to policy if (!jcf->parentIsAttribute()) { switch (scopePolicy) { case Uml::Visibility::Public: case Uml::Visibility::Private: case Uml::Visibility::Protected: scopeStr = Uml::Visibility::toString(scopePolicy); break; default: case Uml::Visibility::FromParent: // do nothing here... will leave as from parent object break; } } QString typeName = jcf->getTypeName(); QString fieldName = jcf->getFieldName(); QString initialV = jcf->getInitialValue(); if (!cf->parentIsAttribute() && !cf->fieldIsSingleValue()) typeName = QLatin1String("List"); QString body = staticValue + scopeStr + QLatin1Char(' ') + typeName + QLatin1Char(' ') + fieldName; if (!initialV.isEmpty()) body.append(QLatin1String(" = ") + initialV); else if (!cf->parentIsAttribute()) { UMLRole * role = dynamic_cast<UMLRole*>(cf->getParentObject()); // Check for dynamic casting failure! if (role == NULL) { uError() << "role: invalid dynamic cast"; return; } if (role->object()->baseType() == UMLObject::ot_Interface) { // do nothing.. can't instantiate an interface } else { // FIX?: IF a constructor method exists in the classifiercodedoc // of the parent Object, then we can use that instead (if its empty). if(cf->fieldIsSingleValue()) { if(!typeName.isEmpty()) body.append(QLatin1String(" = new ") + typeName + QLatin1String(" ()")); } else body.append(QLatin1String(" = new Vector ()")); } } setText(body + QLatin1Char(';')); }
void RubyCodeClassFieldDeclarationBlock::updateContent( ) { CodeClassField * cf = getParentClassField(); ClassifierCodeDocument * doc = cf->getParentDocument(); RubyCodeClassField * rcf = dynamic_cast<RubyCodeClassField*>(cf); RubyClassifierCodeDocument* rdoc = dynamic_cast<RubyClassifierCodeDocument*>(doc); CodeGenerationPolicy * p = UMLApp::app()->getCommonPolicy(); CodeGenerationPolicy::ScopePolicy scopePolicy = p->getAssociationFieldScope(); // Set the comment QString notes = getParentObject()->getDoc(); getComment()->setText(notes); // Set the body QString staticValue = getParentObject()->getStatic() ? "static " : ""; QString scopeStr = rdoc->scopeToRubyDecl(getParentObject()->getVisibility()); // IF this is from an association, then scope taken as appropriate to policy if(!rcf->parentIsAttribute()) { switch (scopePolicy) { case CodeGenerationPolicy::Public: case CodeGenerationPolicy::Private: case CodeGenerationPolicy::Protected: scopeStr = rdoc->scopeToRubyDecl((Uml::Visibility::Value) scopePolicy); break; default: case CodeGenerationPolicy::FromParent: // do nothing here... will leave as from parent object break; } } QString typeName = rcf->getTypeName(); QString fieldName = rcf->getFieldName(); QString initialV = rcf->getInitialValue(); if (!cf->parentIsAttribute() && !cf->fieldIsSingleValue()) typeName = "Array"; QString body = staticValue+scopeStr+' '+typeName+' '+fieldName; if (!initialV.isEmpty()) body.append(" = " + initialV); else if (!cf->parentIsAttribute()) { UMLRole * role = dynamic_cast<UMLRole*>(cf->getParentObject()); if (role->getObject()->getBaseType() == Uml::ot_Interface) { // do nothing.. can't instanciate an interface } else { // FIX?: IF a constructor method exists in the classifiercodedoc // of the parent Object, then we can use that instead (if its empty). if(cf->fieldIsSingleValue()) { if(!typeName.isEmpty()) body.append(" = " + typeName + ".new()"); } else body.append(" = []"); } } setText(body); }
// This method will cause the class to rebuild its text representation. // based on the parent classifier object. // For any situation in which this is called, we are either building the code // document up, or replacing/regenerating the existing auto-generated parts. As // such, we will want to insert everything we resonablely will want // during creation. We can set various parts of the document (esp. the // comments) to appear or not, as needed. void DClassifierCodeDocument::updateContent() { // Gather info on the various fields and parent objects of this class... UMLClassifier * c = getParentClassifier(); Q_ASSERT(c != 0); CodeGenerationPolicy * commonPolicy = UMLApp::app()->commonPolicy(); CodeGenPolicyExt * pe = UMLApp::app()->policyExt(); DCodeGenerationPolicy * policy = dynamic_cast<DCodeGenerationPolicy*>(pe); // first, set the global flag on whether or not to show classfield info // This depends on whether or not we have attribute/association classes const CodeClassFieldList * cfList = getCodeClassFieldList(); CodeClassFieldList::const_iterator it = cfList->begin(); CodeClassFieldList::const_iterator end = cfList->end(); for (; it != end; ++it) { CodeClassField * field = *it; if (field->parentIsAttribute()) field->setWriteOutMethods(policy->getAutoGenerateAttribAccessors()); else field->setWriteOutMethods(policy->getAutoGenerateAssocAccessors()); } // attribute-based ClassFields // we do it this way to have the static fields sorted out from regular ones CodeClassFieldList staticAttribClassFields = getSpecificClassFields (CodeClassField::Attribute, true); CodeClassFieldList attribClassFields = getSpecificClassFields (CodeClassField::Attribute, false); // association-based ClassFields // don't care if they are static or not..all are lumped together CodeClassFieldList plainAssocClassFields = getSpecificClassFields (CodeClassField::PlainAssociation); CodeClassFieldList aggregationClassFields = getSpecificClassFields (CodeClassField::Aggregation); CodeClassFieldList compositionClassFields = getSpecificClassFields (CodeClassField::Composition); bool isInterface = parentIsInterface(); bool hasOperationMethods = false; UMLOperationList list = c->getOpList(); hasOperationMethods = ! list.isEmpty(); QString endLine = commonPolicy->getNewLineEndingChars(); // a shortcut..so we don't have to call this all the time // // START GENERATING CODE/TEXT BLOCKS and COMMENTS FOR THE DOCUMENT // // // PACKAGE CODE BLOCK // QString pkgs = getPackage(); pkgs.replace(QRegExp(QLatin1String("::")), QLatin1String(".")); QString packageText = getPackage().isEmpty() ? QString() : QString(QLatin1String("package ")+pkgs+QLatin1Char(';')+endLine); CodeBlockWithComments * pblock = addOrUpdateTaggedCodeBlockWithComments(QLatin1String("packages"), packageText, QString(), 0, false); if (packageText.isEmpty() && pblock->contentType() == CodeBlock::AutoGenerated) pblock->setWriteOutText(false); else pblock->setWriteOutText(true); // IMPORT CODEBLOCK // // Q: Why all utils? Aren't just List and Vector the only classes we are using? // A: doesn't matter at all; it is more readable to just include '*' and d compilers // don't slow down or anything. (TZ) QString importStatement; if (hasObjectVectorClassFields()) importStatement.append(QLatin1String("import d.util.*;")); //only import classes in a different package from this class UMLPackageList imports; QMap<UMLPackage*, QString> packageMap; // so we don't repeat packages CodeGenerator::findObjectsRelated(c, imports); for (UMLPackageListIt importsIt(imports); importsIt.hasNext();) { UMLPackage *con = importsIt.next(); // NO (default) datatypes in the import statement.. use defined // ones whould be possible, but no idea how to do that...at least for now. // Dynamic casting is slow..not an optimal way to do this. if (!packageMap.contains(con) && !con->isUMLDatatype()) { packageMap.insert(con, con->package()); // now, we DON'T need to import classes that are already in our own package // (that is, IF a package is specified). Otherwise, we should have a declaration. if (con->package() != c->package() || (c->package().isEmpty() && con->package().isEmpty())) { importStatement.append(endLine+QLatin1String("import ")); if (!con->package().isEmpty()) importStatement.append(con->package()+QLatin1Char('.')); importStatement.append(CodeGenerator::cleanName(con->name())+QLatin1Char(';')); } } } // now, add/update the imports codeblock CodeBlockWithComments * iblock = addOrUpdateTaggedCodeBlockWithComments(QLatin1String("imports"), importStatement, QString(), 0, false); if (importStatement.isEmpty() && iblock->contentType() == CodeBlock::AutoGenerated) iblock->setWriteOutText(false); else iblock->setWriteOutText(true); // CLASS DECLARATION BLOCK // // get the declaration block. If it is not already present, add it too DClassDeclarationBlock * myClassDeclCodeBlock = getClassDecl(); addTextBlock(myClassDeclCodeBlock); // note: wont add if already present // NOW create document in sections.. // now we want to populate the body of our class // our layout is the following general groupings of code blocks: // start d classifier document // header comment // package code block // import code block // class declaration // section: // - class field declaration section comment // - class field declarations (0+ codeblocks) // section: // - methods section comment // sub-section: constructor ops // - constructor method section comment // - constructor methods (0+ codeblocks) // sub-section: accessors // - accessor method section comment // - static accessor methods (0+ codeblocks) // - non-static accessor methods (0+ codeblocks) // sub-section: non-constructor ops // - operation method section comment // - operations (0+ codeblocks) // end class declaration // end d classifier document // Q: Why use the more complicated scheme of arranging code blocks within codeblocks? // A: This will allow us later to preserve the format of our document so that if // codeblocks are added, they may be easily added in the correct place, rather than at // the end of the document, or by using a difficult algorithm to find the location of // the last appropriate code block sibling (which may not exist.. for example user adds // a constructor operation, but there currently are no constructor code blocks // within the document). // // * CLASS FIELD declaration section // // get/create the field declaration code block HierarchicalCodeBlock * fieldDeclBlock = myClassDeclCodeBlock->getHierarchicalCodeBlock(QLatin1String("fieldsDecl"), QLatin1String("Fields"), 1); // Update the comment: we only set comment to appear under the following conditions CodeComment * fcomment = fieldDeclBlock->getComment(); if (isInterface || (!forceDoc() && !hasClassFields())) fcomment->setWriteOutText(false); else fcomment->setWriteOutText(true); // now actually declare the fields within the appropriate HCodeBlock declareClassFields(staticAttribClassFields, fieldDeclBlock); declareClassFields(attribClassFields, fieldDeclBlock); declareClassFields(plainAssocClassFields, fieldDeclBlock); declareClassFields(aggregationClassFields, fieldDeclBlock); declareClassFields(compositionClassFields, fieldDeclBlock); // // METHODS section // // get/create the method codeblock HierarchicalCodeBlock * methodsBlock = myClassDeclCodeBlock->getHierarchicalCodeBlock(QLatin1String("methodsBlock"), QLatin1String("Methods"), 1); // Update the section comment CodeComment * methodsComment = methodsBlock->getComment(); // set conditions for showing this comment if (!forceDoc() && !hasClassFields() && !hasOperationMethods) methodsComment->setWriteOutText(false); else methodsComment->setWriteOutText(true); // METHODS sub-section : constructor methods // // get/create the constructor codeblock HierarchicalCodeBlock * constBlock = methodsBlock->getHierarchicalCodeBlock(QLatin1String("constructorMethods"), QLatin1String("Constructors"), 1); constructorBlock = constBlock; // record this codeblock for later, when operations are updated // special condiions for showing comment: only when autogenerateding empty constructors // Although, we *should* check for other constructor methods too CodeComment * constComment = constBlock->getComment(); CodeGenerationPolicy *pol = UMLApp::app()->commonPolicy(); if (!forceDoc() && (isInterface || !pol->getAutoGenerateConstructors())) constComment->setWriteOutText(false); else constComment->setWriteOutText(true); // add/get the empty constructor QString DClassName = getDClassName(c->name()); QString emptyConstStatement = QLatin1String("public ")+DClassName+QLatin1String(" () { }"); CodeBlockWithComments * emptyConstBlock = constBlock->addOrUpdateTaggedCodeBlockWithComments(QLatin1String("emptyconstructor"), emptyConstStatement, QLatin1String("Empty Constructor"), 1, false); // Now, as an additional condition we only show the empty constructor block // IF it was desired to be shown if (parentIsClass() && pol->getAutoGenerateConstructors()) emptyConstBlock->setWriteOutText(true); else emptyConstBlock->setWriteOutText(false); // METHODS subsection : ACCESSOR METHODS // // get/create the accessor codeblock HierarchicalCodeBlock * accessorBlock = methodsBlock->getHierarchicalCodeBlock(QLatin1String("accessorMethods"), QLatin1String("Accessor Methods"), 1); // set conditions for showing section comment CodeComment * accessComment = accessorBlock->getComment(); if (!forceDoc() && !hasClassFields()) accessComment->setWriteOutText(false); else accessComment->setWriteOutText(true); // now, 2 sub-sub sections in accessor block // add/update accessor methods for attributes HierarchicalCodeBlock * staticAccessors = accessorBlock->getHierarchicalCodeBlock(QLatin1String("staticAccessorMethods"), QString(), 1); staticAccessors->getComment()->setWriteOutText(false); // never write block comment staticAccessors->addCodeClassFieldMethods(staticAttribClassFields); staticAccessors->addCodeClassFieldMethods(attribClassFields); // add/update accessor methods for associations HierarchicalCodeBlock * regularAccessors = accessorBlock->getHierarchicalCodeBlock(QLatin1String("regularAccessorMethods"), QString(), 1); regularAccessors->getComment()->setWriteOutText(false); // never write block comment regularAccessors->addCodeClassFieldMethods(plainAssocClassFields); regularAccessors->addCodeClassFieldMethods(aggregationClassFields); regularAccessors->addCodeClassFieldMethods(compositionClassFields); // METHODS subsection : Operation methods (which arent constructors) // // get/create the operations codeblock operationsBlock = methodsBlock->getHierarchicalCodeBlock(QLatin1String("operationMethods"), QLatin1String("Operations"), 1); // set conditions for showing section comment CodeComment * ocomment = operationsBlock->getComment(); if (!forceDoc() && !hasOperationMethods) ocomment->setWriteOutText(false); else ocomment->setWriteOutText(true); }