[Uml-devel] [Bug 126262] Crashes while loading file (Advanced Code Generators enabled)

Oliver Kellogg okellogg at users.sourceforge.net
Mon Mar 26 16:47:59 UTC 2007


------- You are receiving this mail because: -------
You are the assignee for the bug, or are watching the assignee.
         
http://bugs.kde.org/show_bug.cgi?id=126262         




------- Additional Comments From okellogg users sourceforge net  2007-03-26 18:47 -------
SVN commit 646768 by okellogg:

Use dynamic_cast in lieu of C-style pointer cast.
CCBUG:126262


 M  +4 -3      cppheaderclassdeclarationblock.cpp  
 M  +1 -1      cppheadercodeaccessormethod.cpp  
 M  +1 -1      cppheadercodeclassfielddeclarationblock.cpp  
 M  +6 -5      cppheadercodeoperation.cpp  
 M  +1 -1      cppsourcecodeaccessormethod.cpp  
 M  +2 -2      cppsourcecodeclassfielddeclarationblock.cpp  
 M  +2 -2      cppsourcecodeoperation.cpp  
 M  +4 -3      javaclassdeclarationblock.cpp  
 M  +5 -5      javacodeaccessormethod.cpp  
 M  +2 -2      javacodeclassfielddeclarationblock.cpp  
 M  +1 -1      javacodedocumentation.cpp  
 M  +4 -3      javacodeoperation.cpp  
 M  +4 -3      rubyclassdeclarationblock.cpp  
 M  +6 -7      rubycodeaccessormethod.cpp  
 M  +2 -2      rubycodeclassfielddeclarationblock.cpp  
 M  +2 -2      rubycodeoperation.cpp  


--- branches/KDE/3.5/kdesdk/umbrello/umbrello/codegenerators/cppheaderclassdeclarationblock.cpp #646767:646768
 @ -24,8 +24,9  @
 // Constructors/Destructors
 //
 
-CPPHeaderClassDeclarationBlock::CPPHeaderClassDeclarationBlock ( CPPHeaderCodeDocument * parentDoc, const QString &startText, const QString &endText, const QString &comment)
-        : OwnedHierarchicalCodeBlock((UMLObject*) parentDoc->getParentClassifier(), (CodeDocument*)parentDoc, startText, endText, comment)
+CPPHeaderClassDeclarationBlock::CPPHeaderClassDeclarationBlock
+  ( CPPHeaderCodeDocument * parentDoc, const QString &startText, const QString &endText, const QString &comment)
+        : OwnedHierarchicalCodeBlock(parentDoc->getParentClassifier(), parentDoc, startText, endText, comment)
 {
     init(parentDoc, comment);
 }
 @ -74,7 +75,7  @
 void CPPHeaderClassDeclarationBlock::updateContent ( )
 {
 
-    CPPHeaderCodeDocument *parentDoc = (CPPHeaderCodeDocument*)getParentDocument();
+    CPPHeaderCodeDocument *parentDoc = dynamic_cast<CPPHeaderCodeDocument*>(getParentDocument());
     UMLClassifier *c = parentDoc->getParentClassifier();
     QString endLine = UMLApp::app()->getCommonPolicy()->getNewLineEndingChars();
     bool isInterface = parentDoc->parentIsInterface(); // a little shortcut
--- branches/KDE/3.5/kdesdk/umbrello/umbrello/codegenerators/cppheadercodeaccessormethod.cpp #646767:646768
 @ -93,7 +93,7  @
     ClassifierCodeDocument * doc = parentField->getParentDocument();
     CodeGenPolicyExt *pe = UMLApp::app()->getPolicyExt();
     CPPCodeGenerationPolicy * policy = dynamic_cast<CPPCodeGenerationPolicy*>(pe);
-    CPPCodeClassField * cppfield = (CPPCodeClassField*) parentField;
+    CPPCodeClassField * cppfield = dynamic_cast<CPPCodeClassField*>(parentField);
 
     bool isInlineMethod = policy->getAccessorsAreInline( );
 
--- branches/KDE/3.5/kdesdk/umbrello/umbrello/codegenerators/cppheadercodeclassfielddeclarationblock.cpp #646767:646768
 @ -47,7 +47,7  @
     }
 
     CodeClassField * cf = getParentClassField();
-    CPPCodeClassField * hcppcf = (CPPCodeClassField*) cf;
+    CPPCodeClassField * hcppcf = dynamic_cast<CPPCodeClassField*>(cf);
 
     // Set the comment
     QString notes = umlparent->getDoc();
--- branches/KDE/3.5/kdesdk/umbrello/umbrello/codegenerators/cppheadercodeoperation.cpp #646767:646768
 @ -25,8 +25,9  @
 // Constructors/Destructors
 //
 
-CPPHeaderCodeOperation::CPPHeaderCodeOperation ( CPPHeaderCodeDocument * doc, UMLOperation *parent, const QString & body, const QString & comment )
-        : CodeOperation ((ClassifierCodeDocument*)doc, parent, body, comment)
+CPPHeaderCodeOperation::CPPHeaderCodeOperation
+ ( CPPHeaderCodeDocument * doc, UMLOperation *parent, const QString & body, const QString & comment )
+        : CodeOperation (doc, parent, body, comment)
 {
     // lets not go with the default comment and instead use
     // full-blown cpp documentation object instead
 @ -66,8 +67,8  @
 // we basically want to update the doc and start text of this method
 void CPPHeaderCodeOperation::updateMethodDeclaration()
 {
-
-    bool isInterface = ((ClassifierCodeDocument*)getParentDocument())->parentIsInterface();
+    ClassifierCodeDocument *ccd = dynamic_cast<ClassifierCodeDocument*>(getParentDocument());
+    bool isInterface = ccd->parentIsInterface();
     UMLOperation * o = getParentOperation();
 
     CodeGenPolicyExt *pe = UMLApp::app()->getPolicyExt();
 @ -131,7 +132,7  @
 }
 
 int CPPHeaderCodeOperation::lastEditableLine() {
-    ClassifierCodeDocument * doc = (ClassifierCodeDocument*)getParentDocument();
+    ClassifierCodeDocument * doc = dynamic_cast<ClassifierCodeDocument*>(getParentDocument());
     UMLOperation * o = getParentOperation();
     if(doc->parentIsInterface() || o->getAbstract())
         return -1; // very last line is NOT editable as its a one-line declaration w/ no body in
--- branches/KDE/3.5/kdesdk/umbrello/umbrello/codegenerators/cppsourcecodeaccessormethod.cpp #646767:646768
 @ -93,7 +93,7  @
     ClassifierCodeDocument * doc = parentField->getParentDocument();
     CodeGenPolicyExt *pe = UMLApp::app()->getPolicyExt();
     CPPCodeGenerationPolicy * policy = dynamic_cast<CPPCodeGenerationPolicy*>(pe);
-    CPPCodeClassField * cppfield = (CPPCodeClassField*) parentField;
+    CPPCodeClassField * cppfield = dynamic_cast<CPPCodeClassField*>(parentField);
     UMLClassifier * c = doc->getParentClassifier();
 
     bool isInlineMethod = policy->getAccessorsAreInline( );
--- branches/KDE/3.5/kdesdk/umbrello/umbrello/codegenerators/cppsourcecodeclassfielddeclarationblock.cpp #646767:646768
 @ -44,8 +44,8  @
     /*
     CodeClassField * cf = getParentClassField();
     ClassifierCodeDocument * doc = cf->getParentDocument();
-    CPPCodeClassField * jcf = (CPPCodeClassField*) cf;
-    CPPClassifierCodeDocument* jdoc = (CPPClassifierCodeDocument*) doc;
+    CPPCodeClassField * jcf = dynamic_cast<CPPCodeClassField*>(cf);
+    CPPClassifierCodeDocument* jdoc = dynamic_cast<CPPClassifierCodeDocument*>(doc);
 
     // Set the comment
     QString notes = getParentObject()->getDoc();
--- branches/KDE/3.5/kdesdk/umbrello/umbrello/codegenerators/cppsourcecodeoperation.cpp #646767:646768
 @ -26,7 +26,7  @
 //
 
 CPPSourceCodeOperation::CPPSourceCodeOperation ( CPPSourceCodeDocument * doc, UMLOperation *parent, const QString & body, const QString & comment )
-        : CodeOperation ((ClassifierCodeDocument*)doc, parent, body, comment)
+        : CodeOperation (doc, parent, body, comment)
 {
     // lets not go with the default comment and instead use
     // full-blown cpp documentation object instead
 @ -126,7 +126,7  @
 void CPPSourceCodeOperation::updateMethodDeclaration()
 {
 
-    CPPSourceCodeDocument * doc = (CPPSourceCodeDocument*) getParentDocument();
+    CPPSourceCodeDocument * doc = dynamic_cast<CPPSourceCodeDocument*>(getParentDocument());
     CodeGenPolicyExt *pe = UMLApp::app()->getPolicyExt();
     CPPCodeGenerationPolicy * policy = dynamic_cast<CPPCodeGenerationPolicy*>(pe);
     UMLClassifier * c = doc->getParentClassifier();
--- branches/KDE/3.5/kdesdk/umbrello/umbrello/codegenerators/javaclassdeclarationblock.cpp #646767:646768
 @ -22,8 +22,9  @
 // Constructors/Destructors
 //
 
-JavaClassDeclarationBlock::JavaClassDeclarationBlock ( JavaClassifierCodeDocument * parentDoc, const QString &startText, const QString &endText, const QString &comment)
-        : OwnedHierarchicalCodeBlock((UMLObject*) parentDoc->getParentClassifier(), (CodeDocument*)parentDoc, startText, endText, comment)
+JavaClassDeclarationBlock::JavaClassDeclarationBlock
+ ( JavaClassifierCodeDocument * parentDoc, const QString &startText, const QString &endText, const QString &comment)
+        : OwnedHierarchicalCodeBlock(parentDoc->getParentClassifier(), parentDoc, startText, endText, comment)
 {
     init(parentDoc, comment);
 }
 @ -65,7 +66,7  @
 void JavaClassDeclarationBlock::updateContent ( )
 {
 
-    JavaClassifierCodeDocument *parentDoc = (JavaClassifierCodeDocument*)getParentDocument();
+    JavaClassifierCodeDocument *parentDoc = dynamic_cast<JavaClassifierCodeDocument*>(getParentDocument());
     UMLClassifier *c = parentDoc->getParentClassifier();
     CodeGenerationPolicy *commonPolicy = UMLApp::app()->getCommonPolicy();
     QString endLine = commonPolicy->getNewLineEndingChars();
--- branches/KDE/3.5/kdesdk/umbrello/umbrello/codegenerators/javacodeaccessormethod.cpp #646767:646768
 @ -39,8 +39,8  @
     setType(type);
 
     // lets use full-blown comment
-    setComment(new JavaCodeDocumentation((JavaClassifierCodeDocument*)field->getParentDocument()));
-
+    JavaClassifierCodeDocument* jccd = dynamic_cast<JavaClassifierCodeDocument*>(field->getParentDocument());
+    setComment(new JavaCodeDocumentation(jccd));
 }
 
 JavaCodeAccessorMethod::~JavaCodeAccessorMethod ( ) { }
 @ -71,7 +71,7  @
 {
 
     CodeClassField * parentField = getParentClassField();
-    JavaCodeClassField * javafield = (JavaCodeClassField*)parentField;
+    JavaCodeClassField * javafield = dynamic_cast<JavaCodeClassField*>(parentField);
     QString fieldName = javafield->getFieldName();
 
     QString text = "";
 @ -130,8 +130,8  @
 void JavaCodeAccessorMethod::updateMethodDeclaration()
 {
 
-    JavaCodeClassField * javafield = (JavaCodeClassField*) getParentClassField();
-    JavaClassifierCodeDocument * javadoc = (JavaClassifierCodeDocument*) javafield->getParentDocument();
+    JavaCodeClassField * javafield = dynamic_cast<JavaCodeClassField*>(getParentClassField());
+    JavaClassifierCodeDocument * javadoc = dynamic_cast<JavaClassifierCodeDocument*>(javafield->getParentDocument());
     CodeGenerationPolicy *commonpolicy = UMLApp::app()->getCommonPolicy();
 
     // gather defs
--- branches/KDE/3.5/kdesdk/umbrello/umbrello/codegenerators/javacodeclassfielddeclarationblock.cpp #646767:646768
 @ -52,8 +52,8  @
 
     CodeClassField * cf = getParentClassField();
     ClassifierCodeDocument * doc = cf->getParentDocument();
-    JavaCodeClassField * jcf = (JavaCodeClassField*) cf;
-    JavaClassifierCodeDocument* jdoc = (JavaClassifierCodeDocument*) doc;
+    JavaCodeClassField * jcf = dynamic_cast<JavaCodeClassField*>(cf);
+    JavaClassifierCodeDocument* jdoc = dynamic_cast<JavaClassifierCodeDocument*>(doc);
     CodeGenerationPolicy * commonpolicy = UMLApp::app()->getCommonPolicy();
 
     CodeGenerationPolicy::ScopePolicy scopePolicy = commonpolicy->getAssociationFieldScope();
--- branches/KDE/3.5/kdesdk/umbrello/umbrello/codegenerators/javacodedocumentation.cpp #646767:646768
 @ -28,7 +28,7  @
 //
 
 JavaCodeDocumentation::JavaCodeDocumentation ( JavaClassifierCodeDocument * doc, const QString & text )
-        : CodeComment ((CodeDocument*) doc, text)
+        : CodeComment(doc, text)
 {
 
 }
--- branches/KDE/3.5/kdesdk/umbrello/umbrello/codegenerators/javacodeoperation.cpp #646767:646768
 @ -24,8 +24,9  @
 // Constructors/Destructors
 //
 
-JavaCodeOperation::JavaCodeOperation ( JavaClassifierCodeDocument * doc, UMLOperation *parent, const QString & body, const QString & comment )
-        : CodeOperation ((ClassifierCodeDocument*)doc, parent, body, comment)
+JavaCodeOperation::JavaCodeOperation
+ ( JavaClassifierCodeDocument * doc, UMLOperation *parent, const QString & body, const QString & comment )
+        : CodeOperation (doc, parent, body, comment)
 {
     // lets not go with the default comment and instead use
     // full-blown java documentation object instead
 @ -121,7 +122,7  @
 }
 
 int JavaCodeOperation::lastEditableLine() {
-    ClassifierCodeDocument * doc = (ClassifierCodeDocument*)getParentDocument();
+    ClassifierCodeDocument * doc = dynamic_cast<ClassifierCodeDocument*>(getParentDocument());
     if(doc->parentIsInterface())
         return -1; // very last line is NOT editable as its a one-line declaration w/ no body in
     // an interface.
--- branches/KDE/3.5/kdesdk/umbrello/umbrello/codegenerators/rubyclassdeclarationblock.cpp #646767:646768
 @ -25,8 +25,9  @
 // Constructors/Destructors
 //
 
-RubyClassDeclarationBlock::RubyClassDeclarationBlock ( RubyClassifierCodeDocument * parentDoc, const QString &startText, const QString &endText, const QString &comment)
-        : OwnedHierarchicalCodeBlock((UMLObject*) parentDoc->getParentClassifier(), (CodeDocument*)parentDoc, startText, endText, comment)
+RubyClassDeclarationBlock::RubyClassDeclarationBlock
+ ( RubyClassifierCodeDocument * parentDoc, const QString &startText, const QString &endText, const QString &comment)
+        : OwnedHierarchicalCodeBlock(parentDoc->getParentClassifier(), parentDoc, startText, endText, comment)
 {
     init(parentDoc, comment);
 }
 @ -68,7 +69,7  @
 void RubyClassDeclarationBlock::updateContent ( )
 {
 
-    RubyClassifierCodeDocument *parentDoc = (RubyClassifierCodeDocument*)getParentDocument();
+    RubyClassifierCodeDocument *parentDoc = dynamic_cast<RubyClassifierCodeDocument*>(getParentDocument());
     UMLClassifier *c = parentDoc->getParentClassifier();
     CodeGenerationPolicy * p = UMLApp::app()->getCommonPolicy();
     QString endLine = p->getNewLineEndingChars();
--- branches/KDE/3.5/kdesdk/umbrello/umbrello/codegenerators/rubycodeaccessormethod.cpp #646767:646768
 @ -45,8 +45,8  @
     setType(type);
 
     // lets use full-blown comment
-    setComment(new RubyCodeDocumentation((RubyClassifierCodeDocument*)field->getParentDocument()));
-
+    RubyClassifierCodeDocument *rccd = dynamic_cast<RubyClassifierCodeDocument*>(field->getParentDocument());
+    setComment(new RubyCodeDocumentation(rccd));
 }
 
 RubyCodeAccessorMethod::~RubyCodeAccessorMethod ( ) { }
 @ -77,7 +77,7  @
 {
 
     CodeClassField * parentField = getParentClassField();
-    RubyCodeClassField * rubyfield = (RubyCodeClassField*)parentField;
+    RubyCodeClassField * rubyfield = dynamic_cast<RubyCodeClassField*>(parentField);
     QString fieldName = rubyfield->getFieldName();
     QString endLine = UMLApp::app()->getCommonPolicy()->getNewLineEndingChars();
 
 @ -86,7 +86,6  @
     case CodeAccessorMethod::ADD:
         {
             int maxOccurs = rubyfield->maximumListOccurances();
-            RubyClassifierCodeDocument * rubydoc = (RubyClassifierCodeDocument*) rubyfield->getParentDocument();
             QString fieldType = rubyfield->getTypeName();
             QString indent = getIndentation();
             if(maxOccurs > 0)
 @ -108,7 +107,7  @
     case CodeAccessorMethod::REMOVE:
         {
             int minOccurs = rubyfield->minimumListOccurances();
-            RubyClassifierCodeDocument * rubydoc = (RubyClassifierCodeDocument*) rubyfield->getParentDocument();
+            RubyClassifierCodeDocument * rubydoc = dynamic_cast<RubyClassifierCodeDocument*>(rubyfield->getParentDocument());
             QString fieldType = rubyfield->getTypeName();
             QString indent = getIndentation();
 
 @ -137,8 +136,8  @
 void RubyCodeAccessorMethod::updateMethodDeclaration()
 {
 
-    RubyCodeClassField * rubyfield = (RubyCodeClassField*) getParentClassField();
-    RubyClassifierCodeDocument * rubydoc = (RubyClassifierCodeDocument*) rubyfield->getParentDocument();
+    RubyCodeClassField * rubyfield = dynamic_cast<RubyCodeClassField*>(getParentClassField());
+    RubyClassifierCodeDocument * rubydoc = dynamic_cast<RubyClassifierCodeDocument*>(rubyfield->getParentDocument());
 
     // gather defs
     CodeGenerationPolicy *p = UMLApp::app()->getCommonPolicy();
--- branches/KDE/3.5/kdesdk/umbrello/umbrello/codegenerators/rubycodeclassfielddeclarationblock.cpp #646767:646768
 @ -47,8 +47,8  @
 
     CodeClassField * cf = getParentClassField();
     ClassifierCodeDocument * doc = cf->getParentDocument();
-    RubyCodeClassField * rcf = (RubyCodeClassField*) cf;
-    RubyClassifierCodeDocument* rdoc = (RubyClassifierCodeDocument*) doc;
+    RubyCodeClassField * rcf = dynamic_cast<RubyCodeClassField*>(cf);
+    RubyClassifierCodeDocument* rdoc = dynamic_cast<RubyClassifierCodeDocument*>(doc);
     CodeGenerationPolicy * p = UMLApp::app()->getCommonPolicy();
     CodeGenerationPolicy::ScopePolicy scopePolicy = p->getAssociationFieldScope();
 
--- branches/KDE/3.5/kdesdk/umbrello/umbrello/codegenerators/rubycodeoperation.cpp #646767:646768
 @ -28,7 +28,7  @
 //
 
 RubyCodeOperation::RubyCodeOperation ( RubyClassifierCodeDocument * doc, UMLOperation *parent, const QString & body, const QString & comment )
-        : CodeOperation ((ClassifierCodeDocument*)doc, parent, body, comment)
+        : CodeOperation (doc, parent, body, comment)
 {
     // lets not go with the default comment and instead use
     // full-blown ruby documentation object instead
 @ -211,7 +211,7  @
 }
 
 int RubyCodeOperation::lastEditableLine() {
-    ClassifierCodeDocument * doc = (ClassifierCodeDocument*)getParentDocument();
+    ClassifierCodeDocument * doc = dynamic_cast<ClassifierCodeDocument*>(getParentDocument());
     if(doc->parentIsInterface())
         return -1; // very last line is NOT editable as its a one-line declaration w/ no body in
     // an interface.




More information about the umbrello-devel mailing list