Commit a5f92b67 authored by Ralf Habacker's avatar Ralf Habacker
Browse files

Convert casts in UML model classes to use related casting methods.

CCBUG:368282
Reviewed-by: aaron.nottbeck at sag.eu
parent 668c6ad4
......@@ -637,7 +637,7 @@ bool UMLClipboard::pasteClip5(const QMimeData* data)
QString newName = parent->uniqChildName(UMLObject::ot_Attribute, obj->name());
obj->setName(newName);
}
UMLAttribute *att = static_cast<UMLAttribute*>(obj);
UMLAttribute *att = obj->asUMLAttribute();
if (parent->addAttribute(att, idchanges)) {
result = true;
} else {
......@@ -648,7 +648,7 @@ bool UMLClipboard::pasteClip5(const QMimeData* data)
}
case UMLObject::ot_Operation :
{
UMLOperation *op = static_cast<UMLOperation*>(obj);
UMLOperation *op = obj->asUMLOperation();
UMLOperation *exist = parent->checkOperationSignature(op->name(), op->getParmList());
if (exist) {
QString newName = parent->uniqChildName(UMLObject::ot_Operation, obj->name());
......@@ -664,7 +664,7 @@ bool UMLClipboard::pasteClip5(const QMimeData* data)
}
case UMLObject::ot_Template:
{
UMLTemplate* tp = static_cast<UMLTemplate*>(obj);
UMLTemplate* tp = obj->asUMLTemplate();
UMLTemplate* exist = parent->findTemplate(tp->name());
if (exist) {
QString newName = parent->uniqChildName(UMLObject::ot_Template, obj->name());
......@@ -680,7 +680,7 @@ bool UMLClipboard::pasteClip5(const QMimeData* data)
}
case UMLObject::ot_EnumLiteral:
{
UMLEnum* enumParent = dynamic_cast<UMLEnum*>(parent);
UMLEnum* enumParent = parent->asUMLEnum();
// if parent is not a UMLEnum, bail out immediately;
if (!enumParent) {
result = false;
......@@ -693,7 +693,7 @@ bool UMLClipboard::pasteClip5(const QMimeData* data)
QString newName = enumParent->uniqChildName(UMLObject::ot_EnumLiteral, obj->name());
obj->setName(newName);
}
UMLEnumLiteral* enl = static_cast<UMLEnumLiteral*>(obj);
UMLEnumLiteral* enl = obj->asUMLEnumLiteral();
if (enumParent->addEnumLiteral(enl, idchanges)) {
result = true;
......@@ -705,7 +705,7 @@ bool UMLClipboard::pasteClip5(const QMimeData* data)
}
case UMLObject::ot_EntityAttribute :
{
UMLEntity* entityParent = dynamic_cast<UMLEntity*>(parent);
UMLEntity* entityParent = parent->asUMLEntity();
// if parent is not a UMLEntity, bail out immediately;
if (!entityParent) {
result = false;
......@@ -717,7 +717,7 @@ bool UMLClipboard::pasteClip5(const QMimeData* data)
QString newName = entityParent->uniqChildName(UMLObject::ot_EntityAttribute, obj->name());
obj->setName(newName);
}
UMLEntityAttribute *att = static_cast<UMLEntityAttribute*>(obj);
UMLEntityAttribute *att = obj->asUMLEntityAttribute();
if (entityParent->addEntityAttribute(att, idchanges)) {
result = true;
......
......@@ -846,7 +846,7 @@ bool UMLDragData::decodeViews(QDomNode& umlviewsNode, UMLViewList& diagrams)
uError() << "Bad parent for view.";
return false;
}
UMLFolder *f = static_cast<UMLFolder*>(po);
UMLFolder *f = po->asUMLFolder();
UMLView* view = new UMLView(f);
view->umlScene()->loadFromXMI(diagramElement);
diagrams.append(view);
......
......@@ -122,7 +122,7 @@ QString AdaWriter::packageName(UMLPackage *p)
if (umlPkg == UMLApp::app()->document()->rootFolder(Uml::ModelType::Logical))
umlPkg = NULL;
UMLClassifier *c = dynamic_cast<UMLClassifier*>(p);
UMLClassifier *c = p->asUMLClassifier();
if (umlPkg == NULL) {
retval = className;
if (c == NULL || !isOOClass(c))
......@@ -309,7 +309,7 @@ void AdaWriter::writeClass(UMLClassifier *c)
}
if (c->baseType() == UMLObject::ot_Enum) {
UMLEnum *ue = static_cast<UMLEnum*>(c);
UMLEnum *ue = c->asUMLEnum();
UMLClassifierListItemList litList = ue->getFilteredList(UMLObject::ot_EnumLiteral);
uint i = 0;
ada << indent() << "type " << classname << " is (" << m_endl;
......
......@@ -49,7 +49,7 @@ void AdvancedCodeGenerator::checkAddUMLObject(UMLObject * obj)
return;
}
UMLClassifier * c = dynamic_cast<UMLClassifier*>(obj);
UMLClassifier * c = obj->asUMLClassifier();
if (c) {
CodeDocument * cDoc = newClassifierCodeDocument(c);
addCodeDocument(cDoc);
......@@ -65,7 +65,7 @@ void AdvancedCodeGenerator::checkRemoveUMLObject(UMLObject * obj)
return;
}
UMLClassifier * c = dynamic_cast<UMLClassifier*>(obj);
UMLClassifier * c = obj->asUMLClassifier();
if (c) {
ClassifierCodeDocument * cDoc = (ClassifierCodeDocument*) findCodeDocumentByClassifier(c);
if (cDoc) {
......
......@@ -301,7 +301,7 @@ QList<CodeOperation*> ClassifierCodeDocument::getCodeOperations ()
*/
void ClassifierCodeDocument::addOperation (UMLClassifierListItem * o)
{
UMLOperation *op = dynamic_cast<UMLOperation*>(o);
UMLOperation *op = o->asUMLOperation();
if (op == NULL) {
uError() << "arg is not a UMLOperation";
return;
......
......@@ -73,7 +73,7 @@ CodeClassField::~CodeClassField ()
*/
void CodeClassField::setParentUMLObject (UMLObject * obj)
{
UMLRole *role = dynamic_cast<UMLRole*>(obj);
UMLRole *role = obj->asUMLRole();
if(role) {
UMLAssociation * parentAssoc = role->parentAssociation();
Uml::AssociationType::Enum atype = parentAssoc->getAssocType();
......@@ -113,7 +113,7 @@ QString CodeClassField::getListObjectType()
{
if (!parentIsAttribute())
{
UMLRole * role = dynamic_cast<UMLRole*>(getParentObject());
UMLRole * role = getParentObject()->asUMLRole();
if (role)
return getUMLObjectName(role->object());
}
......@@ -330,7 +330,7 @@ int CodeClassField::minimumListOccurances()
{
if (!parentIsAttribute())
{
UMLRole * role = dynamic_cast<UMLRole*>(getParentObject());
UMLRole * role = getParentObject()->asUMLRole();
if (!role) {
uError() << "no valid parent object";
return -1;
......@@ -358,7 +358,7 @@ int CodeClassField::maximumListOccurances()
{
if (!parentIsAttribute())
{
UMLRole * role = dynamic_cast<UMLRole*>(getParentObject());
UMLRole * role = getParentObject()->asUMLRole();
if (!role) {
uError() << "no valid parent object";
return -1;
......@@ -527,7 +527,9 @@ void CodeClassField::updateContent()
method->setWriteOutText(m_writeOutMethods);
return;
}
UMLRole * role = dynamic_cast<UMLRole*>(getParentObject());
UMLRole * role = getParentObject()->asUMLRole();
if (!role)
return;
Uml::Changeability::Enum changeType = role->changeability();
bool isSingleValue = fieldIsSingleValue();
bool isEmptyRole = role->name().isEmpty() ? true : false;
......@@ -620,7 +622,7 @@ bool CodeClassField::fieldIsSingleValue ()
if(parentIsAttribute())
return true;
UMLRole * role = dynamic_cast<UMLRole*>(getParentObject());
UMLRole * role = getParentObject()->asUMLRole();
if(!role)
return true; // it is really an attribute
......
......@@ -139,7 +139,7 @@ void CodeClassFieldDeclarationBlock::syncToParent ()
// the name of the role is not defined.
if (!(getParentClassField()->parentIsAttribute()))
{
UMLRole * parent = dynamic_cast<UMLRole*>(getParentObject());
UMLRole * parent = getParentObject()->asUMLRole();
if (parent == NULL)
return;
if (parent->name().isEmpty())
......
......@@ -397,11 +397,11 @@ void CodeDocument::setAttributesFromNode (QDomElement & root)
// suspecting pre-1.5.3 file format where the package name was
// saved instead of the package ID.
UMLObject *o = umldoc->findUMLObject(pkgStr);
m_package = dynamic_cast<UMLPackage*>(o);
m_package = o->asUMLPackage();
}
if (m_package == NULL) {
UMLObject *o = umldoc->findObjectById(Uml::ID::fromString(pkgStr));
m_package = dynamic_cast<UMLPackage*>(o);
m_package = o->asUMLPackage();
}
}
const QString trueStr = QLatin1String("true");
......
......@@ -227,7 +227,7 @@ void CodeGenerator::loadCodeForOperation(const QString& idStr, const QDomElement
UMLObject::ObjectType t = obj->baseType();
if (t == UMLObject::ot_Operation) {
UMLOperation *op = static_cast<UMLOperation*>(obj);
UMLOperation *op = obj->asUMLOperation();
op->setSourceCode(value);
}
else {
......@@ -642,7 +642,7 @@ void CodeGenerator::findObjectsRelated(UMLClassifier *c, UMLPackageList &cList)
UMLObject *objA = a->getObject(Uml::RoleType::A);
UMLObject *objB = a->getObject(Uml::RoleType::B);
if (objA == c) {
temp = static_cast<UMLPackage*>(objB);
temp = objB->asUMLPackage();
}
}
break;
......@@ -653,7 +653,7 @@ void CodeGenerator::findObjectsRelated(UMLClassifier *c, UMLPackageList &cList)
UMLObject *objA = a->getObject(Uml::RoleType::A);
UMLObject *objB = a->getObject(Uml::RoleType::B);
if (objA == c && objB->baseType() != UMLObject::ot_Datatype) {
temp = static_cast<UMLPackage*>(objB);
temp = objB->asUMLPackage();
}
}
break;
......
......@@ -465,7 +465,7 @@ void CodeGenObjectWithTextBlocks::loadChildTextBlocksFromNode (QDomElement & roo
// 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);
UMLOperation * op = obj->asUMLOperation();
if (op) {
CodeOperation * block = CodeGenFactory::newCodeOperation(dynamic_cast<ClassifierCodeDocument*>(m_pCodeDoc), op);
block->loadFromXMI(element);
......
......@@ -63,7 +63,7 @@ QList<CodeParameter*> CodeOperation::getParameterList ()
UMLOperation * CodeOperation::getParentOperation()
{
return dynamic_cast<UMLOperation*>(getParentObject());
return getParentObject()->asUMLOperation();
}
/**
......@@ -119,7 +119,7 @@ void CodeOperation::setAttributesFromNode (QDomElement & element)
QString idStr = element.attribute(QLatin1String("parent_id"), QLatin1String("-1"));
Uml::ID::Type id = Uml::ID::fromString(idStr);
UMLObject * obj = UMLApp::app()->document()->findObjectById(id);
UMLOperation * op = dynamic_cast<UMLOperation*>(obj);
UMLOperation * op = obj->asUMLOperation();
if (op)
init(op);
......
......@@ -147,7 +147,7 @@ UMLObject * CodeParameter::getParentObject()
// this is kind of broken for UMLRoles.
QString CodeParameter::ID()
{
UMLRole * role = dynamic_cast<UMLRole*>(m_parentObject);
UMLRole * role = m_parentObject->asUMLRole();
if (role)
{
// cant use Role "ID" as that is used to distinquish if its
......@@ -171,7 +171,7 @@ void CodeParameter::setAttributesOnNode(QDomDocument & doc, QDomElement & blockE
// setting ID's takes special treatment
// as UMLRoles arent properly stored in the XMI right now.
// (change would break the XMI format..save for big version change)
UMLRole * role = dynamic_cast<UMLRole*>(m_parentObject);
UMLRole * role = m_parentObject->asUMLRole();
if (role)
blockElement.setAttribute(QLatin1String("role_id"), role->role());
else
......@@ -212,7 +212,7 @@ void CodeParameter::setAttributesFromNode(QDomElement & root)
// might ripple throughout the code and cause problems. Thus, since the
// change appears to be needed for only this part, I'll do this crappy
// change instead. -b.t.
UMLAssociation * assoc = dynamic_cast<UMLAssociation*>(obj);
UMLAssociation * assoc = obj->asUMLAssociation();
if (assoc) {
// In this case we init with indicated role child obj.
UMLRole * role = 0;
......
......@@ -66,7 +66,7 @@ QString CPPCodeClassField::getInitialValue()
{
if (parentIsAttribute())
{
UMLAttribute * at = dynamic_cast<UMLAttribute*>(getParentObject());
UMLAttribute * at = getParentObject()->asUMLAttribute();
if (at) {
return fixInitialStringDeclValue(at->getInitialValue(), getTypeName());
} else {
......
......@@ -348,7 +348,7 @@ void CPPCodeGenerator::checkAddUMLObject(UMLObject * obj)
if (isReservedKeyword(obj->name()))
return;
UMLClassifier * c = dynamic_cast<UMLClassifier*>(obj);
UMLClassifier * c = obj->asUMLClassifier();
if(c) {
CodeDocument * cDoc = newClassifierCodeDocument(c);
CPPHeaderCodeDocument * hcodeDoc = newHeaderClassifierCodeDocument(c);
......@@ -370,7 +370,7 @@ void CPPCodeGenerator::checkRemoveUMLObject(UMLObject * obj)
if (!obj)
return;
UMLClassifier * c = dynamic_cast<UMLClassifier*>(obj);
UMLClassifier * c = obj->asUMLClassifier();
if(c) {
// source
ClassifierCodeDocument * cDoc = (ClassifierCodeDocument*) findCodeDocumentByClassifier(c);
......
......@@ -160,7 +160,7 @@ void CPPHeaderCodeDocument::loadChildTextBlocksFromNode (QDomElement & root)
// 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);
UMLOperation * op = obj->asUMLOperation();
if(op) {
CodeOperation * block = new CPPHeaderCodeOperation(this, op);
block->updateMethodDeclaration();
......@@ -481,7 +481,7 @@ void CPPHeaderCodeDocument::updateContent()
if (!isInterface) {
QString enumStatement;
QString indent = UMLApp::app()->commonPolicy()->getIndentation();
UMLEnum* e = dynamic_cast<UMLEnum*>(c);
UMLEnum* e = c->asUMLEnum();
if (e) {
enumStatement.append(indent + QLatin1String("enum ") + cppClassName + QLatin1String(" {") + endLine);
......
......@@ -200,7 +200,7 @@ void CSharpWriter::writeClass(UMLClassifier *c)
if (includes.count()) {
foreach (UMLPackage* p, includes) {
UMLClassifier *cl = dynamic_cast<UMLClassifier*>(p);
UMLClassifier *cl = p->asUMLClassifier();
if (cl)
p = cl->umlPackage();
if (p != logicalView && m_seenIncludes.indexOf(p) == -1 && p != container) {
......
......@@ -202,7 +202,7 @@ void DClassifierCodeDocument::loadChildTextBlocksFromNode(QDomElement & root)
// 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);
UMLOperation * op = obj->asUMLOperation();
if (op) {
CodeOperation * block = new DCodeOperation(this, op);
block->loadFromXMI(element);
......
......@@ -66,7 +66,7 @@ QString DCodeClassField::getInitialValue()
{
if (parentIsAttribute())
{
UMLAttribute * at = dynamic_cast<UMLAttribute*>(getParentObject());
UMLAttribute * at = getParentObject()->asUMLAttribute();
if (at) {
return fixInitialStringDeclValue(at->getInitialValue(), getTypeName());
} else {
......
......@@ -127,7 +127,7 @@ void JavaANTCodeDocument::loadChildTextBlocksFromNode (QDomElement & root)
// 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);
UMLOperation * op = obj->asUMLOperation();
if (op) {
CodeOperation * block = 0;
uError() << "TODO: implement CodeGenFactory::newCodeOperation() for JavaANTCodeDocument";
......
......@@ -199,7 +199,7 @@ void JavaClassifierCodeDocument::loadChildTextBlocksFromNode (QDomElement & root
// 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);
UMLOperation * op = obj->asUMLOperation();
if (op) {
CodeOperation * block = new JavaCodeOperation(this, op);
block->loadFromXMI(element);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment