// Sigh. NOT optimal. The only reason that we need to have this // is so we can create the CPPHeaderClassDeclarationBlock. // would be better if we could create a handler interface that each // codeblock used so all we have to do here is add the handler void CPPHeaderCodeDocument::loadChildTextBlocksFromNode (QDomElement & root) { QDomNode tnode = root.firstChild(); QDomElement telement = tnode.toElement(); bool loadCheckForChildrenOK = false; while(!telement.isNull()) { QString nodeName = telement.tagName(); if(nodeName == QLatin1String("textblocks")) { QDomNode node = telement.firstChild(); QDomElement element = node.toElement(); // if there is nothing to begin with, then we don't worry about it loadCheckForChildrenOK = element.isNull() ? true : false; while(!element.isNull()) { QString name = element.tagName(); if(name == QLatin1String("codecomment")) { CodeComment * block = new CPPCodeDocumentation(this); block->loadFromXMI(element); if(!addTextBlock(block)) { uError()<<"Unable to add codeComment to :"<<this; delete block; } else loadCheckForChildrenOK= true; } else if(name == QLatin1String("codeaccessormethod") || name == QLatin1String("ccfdeclarationcodeblock")) { QString acctag = element.attribute(QLatin1String("tag")); // search for our method in the TextBlock * tb = findCodeClassFieldTextBlockByTag(acctag); if(!tb || !addTextBlock(tb)) { uError()<<"Unable to add codeclassfield child method to:"<<this; // DON'T delete } else loadCheckForChildrenOK= true; } else if(name == QLatin1String("codeblock")) { CodeBlock * block = newCodeBlock(); block->loadFromXMI(element); if(!addTextBlock(block)) { uError()<<"Unable to add codeBlock to :"<<this; delete block; } else loadCheckForChildrenOK= true; } else if(name == QLatin1String("codeblockwithcomments")) { CodeBlockWithComments * block = newCodeBlockWithComments(); block->loadFromXMI(element); if(!addTextBlock(block)) { uError()<<"Unable to add codeBlockwithcomments to:"<<this; delete block; } else loadCheckForChildrenOK= true; } else if(name == QLatin1String("header")) { // do nothing.. this is treated elsewhere } else if(name == QLatin1String("hierarchicalcodeblock")) { HierarchicalCodeBlock * block = newHierarchicalCodeBlock(); block->loadFromXMI(element); if(!addTextBlock(block)) { uError()<<"Unable to add hierarchicalcodeBlock to:"<<this; delete block; } else loadCheckForChildrenOK= true; } else if(name == QLatin1String("codeoperation")) { // find the code operation by id QString id = element.attribute(QLatin1String("parent_id"),QLatin1String("-1")); UMLObject * obj = UMLApp::app()->document()->findObjectById(Uml::ID::fromString(id)); UMLOperation * op = dynamic_cast<UMLOperation*>(obj); if(op) { CodeOperation * block = new CPPHeaderCodeOperation(this, op); block->updateMethodDeclaration(); block->updateContent(); block->loadFromXMI(element); if(addTextBlock(block)) loadCheckForChildrenOK= true; else { uError()<<"Unable to add codeoperation to:"<<this; block->deleteLater(); } } else uError()<<"Unable to find operation create codeoperation for:"<<this; } else if(name == QLatin1String("cppheaderclassdeclarationblock")) { CPPHeaderClassDeclarationBlock * block = getClassDecl(); block->loadFromXMI(element); // normally this would be populated by the following syncToparent // call, but we cant wait for it, so lets just do it now. m_namespaceBlock = getHierarchicalCodeBlock(QLatin1String("namespace"), QLatin1String("Namespace"), 0); if(!m_namespaceBlock || !m_namespaceBlock->addTextBlock(block)) { uError()<<"Error:cant add class declaration codeblock"; // DON'T delete/release block // block->release(); } else loadCheckForChildrenOK= true; } // only needed for extreme debugging conditions (E.g. making new codeclassdocument loader) //else //uDebug()<<" LoadFromXMI: Got strange tag in text block stack:"<<name<<", ignorning"; node = element.nextSibling(); element = node.toElement(); } break; } tnode = telement.nextSibling(); telement = tnode.toElement(); } if(!loadCheckForChildrenOK) { uWarning() << "loadChildBlocks : unable to initialize any child blocks in doc: " << getFileName() << " " << this; } }
/** * Need to overwrite this for ruby since we need to pick up the * ruby class declaration block. * Sigh. NOT optimal. The only reason that we need to have this * is so we can create the RubyClassDeclarationBlock. * would be better if we could create a handler interface that each * codeblock used so all we have to do here is add the handler * for "rubyclassdeclarationblock". */ void RubyClassifierCodeDocument::loadChildTextBlocksFromNode(QDomElement & root) { QDomNode tnode = root.firstChild(); QDomElement telement = tnode.toElement(); bool loadCheckForChildrenOK = false; while (!telement.isNull()) { QString nodeName = telement.tagName(); if (nodeName == QLatin1String("textblocks")) { QDomNode node = telement.firstChild(); QDomElement element = node.toElement(); // if there is nothing to begin with, then we don't worry about it loadCheckForChildrenOK = element.isNull() ? true : false; while (!element.isNull()) { QString name = element.tagName(); if (name == QLatin1String("codecomment")) { CodeComment * block = new RubyCodeComment(this); block->loadFromXMI(element); if (!addTextBlock(block)) { uError()<<"loadFromXMI : unable to add codeComment to :"<<this; delete block; } else { loadCheckForChildrenOK= true; } } else if (name == QLatin1String("codeaccessormethod") || name == QLatin1String("ccfdeclarationcodeblock")) { QString acctag = element.attribute(QLatin1String("tag")); // search for our method in the TextBlock * tb = findCodeClassFieldTextBlockByTag(acctag); if (!tb || !addTextBlock(tb)) { uError()<<"loadFromXMI : unable to add codeclassfield child method to:"<<this; // DON'T delete } else { loadCheckForChildrenOK= true; } } else if (name == QLatin1String("codeblock")) { CodeBlock * block = newCodeBlock(); block->loadFromXMI(element); if (!addTextBlock(block)) { uError()<<"loadFromXMI : unable to add codeBlock to :"<<this; delete block; } else { loadCheckForChildrenOK= true; } } else if (name == QLatin1String("codeblockwithcomments")) { CodeBlockWithComments * block = newCodeBlockWithComments(); block->loadFromXMI(element); if (!addTextBlock(block)) { uError()<<"loadFromXMI : unable to add codeBlockwithcomments to:"<<this; delete block; } else { loadCheckForChildrenOK= true; } } else if (name == QLatin1String("header")) { // do nothing.. this is treated elsewhere } else if (name == QLatin1String("hierarchicalcodeblock")) { HierarchicalCodeBlock * block = newHierarchicalCodeBlock(); block->loadFromXMI(element); if (!addTextBlock(block)) { uError()<<"Unable to add hierarchicalcodeBlock to:"<<this; delete block; } else { loadCheckForChildrenOK= true; } } else if (name == QLatin1String("codeoperation")) { // find the code operation by id QString id = element.attribute(QLatin1String("parent_id"), QLatin1String("-1")); UMLObject * obj = UMLApp::app()->document()->findObjectById(Uml::ID::fromString(id)); UMLOperation * op = dynamic_cast<UMLOperation*>(obj); if (op) { CodeOperation * block = new RubyCodeOperation(this, op); block->loadFromXMI(element); if (addTextBlock(block)) { loadCheckForChildrenOK= true; } else { uError()<<"Unable to add codeoperation to:"<<this; block->deleteLater(); } } else { uError()<<"Unable to find operation create codeoperation for:"<<this; } } else if (name == QLatin1String("rubyclassdeclarationblock")) { RubyClassDeclarationBlock * block = getClassDecl(); block->loadFromXMI(element); if (!addTextBlock(block)) { uError()<<"Unable to add ruby code declaration block to:"<<this; // DON'T delete. // block->deleteLater(); } else { loadCheckForChildrenOK= true; } } else { uDebug()<<" LoadFromXMI: Got strange tag in text block stack:"<<name<<", ignoring"; } node = element.nextSibling(); element = node.toElement(); } break; } tnode = telement.nextSibling(); telement = tnode.toElement(); } if (!loadCheckForChildrenOK) { CodeDocument * test = dynamic_cast<CodeDocument*>(this); if (test) { uWarning()<<" loadChildBlocks : unable to initialize any child blocks in doc: "<<test->getFileName()<<" "<<this; } else { HierarchicalCodeBlock * hb = dynamic_cast<HierarchicalCodeBlock*>(this); if (hb) uWarning()<<" loadChildBlocks : unable to initialize any child blocks in Hblock: "<<hb->getTag()<<" "<<this; else uDebug()<<" loadChildBlocks : unable to initialize any child blocks in UNKNOWN OBJ:"<<this; } } }
// Sigh. NOT optimal. The only reason that we need to have this // is so we can create the XMLNodes, if needed. // would be better if we could create a handler interface that each // codeblock used so all we have to do here is add the handler void JavaANTCodeDocument::loadChildTextBlocksFromNode (QDomElement & root) { QDomNode tnode = root.firstChild(); QDomElement telement = tnode.toElement(); bool loadCheckForChildrenOK = false; while (!telement.isNull()) { QString nodeName = telement.tagName(); if (nodeName == QLatin1String("textblocks")) { QDomNode node = telement.firstChild(); QDomElement element = node.toElement(); // if there is nothing to begin with, then we don't worry about it loadCheckForChildrenOK = element.isNull() ? true : false; while (!element.isNull()) { QString name = element.tagName(); if (name == QLatin1String("codecomment")) { CodeComment * block = new XMLCodeComment(this); block->loadFromXMI(element); if (!addTextBlock(block)) { uError()<<"Unable to add codeComment to :"<<this; delete block; } else loadCheckForChildrenOK= true; } else if (name == QLatin1String("codeaccessormethod") || name == QLatin1String("ccfdeclarationcodeblock")) { QString acctag = element.attribute(QLatin1String("tag")); // search for our method in the TextBlock * tb = findCodeClassFieldTextBlockByTag(acctag); if (!tb || !addTextBlock(tb)) { uError()<<"Unable to add codeclassfield child method to:"<<this; // DON'T delete } else { loadCheckForChildrenOK= true; } } else if (name == QLatin1String("codeblock")) { CodeBlock * block = newCodeBlock(); block->loadFromXMI(element); if (!addTextBlock(block)) { uError()<<"Unable to add codeBlock to :"<<this; delete block; } else { loadCheckForChildrenOK= true; } } else if (name == QLatin1String("codeblockwithcomments")) { CodeBlockWithComments * block = newCodeBlockWithComments(); block->loadFromXMI(element); if (!addTextBlock(block)) { uError()<<"Unable to add codeBlockwithcomments to:"<<this; delete block; } else { loadCheckForChildrenOK= true; } } else if (name == QLatin1String("header")) { // do nothing.. this is treated elsewhere } else if (name == QLatin1String("hierarchicalcodeblock")) { HierarchicalCodeBlock * block = newHierarchicalCodeBlock(); block->loadFromXMI(element); if (!addTextBlock(block)) { uError()<<"Unable to add hierarchicalcodeBlock to:"<<this; delete block; } else { loadCheckForChildrenOK= true; } } else if (name == QLatin1String("codeoperation")) { // find the code operation by id QString id = element.attribute(QLatin1String("parent_id"),QLatin1String("-1")); UMLObject * obj = UMLApp::app()->document()->findObjectById(Uml::ID::fromString(id)); UMLOperation * op = obj->asUMLOperation(); if (op) { CodeOperation * block = 0; uError() << "TODO: implement CodeGenFactory::newCodeOperation() for JavaANTCodeDocument"; break; // remove when above is implemented block->loadFromXMI(element); if (addTextBlock(block)) { loadCheckForChildrenOK= true; } else { uError()<<"Unable to add codeoperation to:"<<this; block->deleteLater(); } } else { uError()<<"Unable to find operation create codeoperation for:"<<this; } } else if (name == QLatin1String("xmlelementblock")) { QString xmltag = element.attribute(QLatin1String("nodeName"),QLatin1String("UNKNOWN")); XMLElementCodeBlock * block = new XMLElementCodeBlock(this, xmltag); block->loadFromXMI(element); if (!addTextBlock(block)) { uError()<<"Unable to add XMLelement to Java ANT document:"<<this; delete block; } else { loadCheckForChildrenOK= true; } } else { uDebug()<<" LoadFromXMI: Got strange tag in text block stack:"<<name<<", ignoring"; } node = element.nextSibling(); element = node.toElement(); } break; } tnode = telement.nextSibling(); telement = tnode.toElement(); } if (!loadCheckForChildrenOK) { uWarning() << " loadChildBlocks : unable to initialize any child blocks in doc: " << getFileName() << " " << this; } }