[Uml-devel] kdesdk/umbrello/umbrello/codegenerators

Brian Thomas thomas at mail630.gsfc.nasa.gov
Thu Dec 4 09:52:01 UTC 2003


CVS commit by thomas: 

fix bug : 68188. Java code generation now handles import/package statements better 


  M +25 -8     javaclassifiercodedocument.cpp   1.20


--- kdesdk/umbrello/umbrello/codegenerators/javaclassifiercodedocument.cpp  #1.19:1.20
@@ -386,5 +386,9 @@ void JavaClassifierCodeDocument::updateC
         //
         QString packageText = getPackage().isEmpty() ? "" : "package "+getPackage()+";"+endLine;
-        addOrUpdateTaggedCodeBlockWithComments("packages", packageText, "", 0, false);
+        CodeBlockWithComments * pblock = addOrUpdateTaggedCodeBlockWithComments("packages", packageText, "", 0, false);
+        if(packageText.isEmpty() && pblock->getContentType() == CodeBlock::AutoGenerated)
+                pblock->setWriteOutText(false);
+        else
+                pblock->setWriteOutText(true);
 
         // IMPORT CODEBLOCK
@@ -403,12 +407,25 @@ void JavaClassifierCodeDocument::updateC
         gen->findObjectsRelated(c,imports);
         for(UMLClassifier *con = imports.first(); con ; con = imports.next())
-        if ((con->getPackage() != c->getPackage())
-                && !(packageMap->contains(con)))
+                if (!(packageMap->contains(con)))
         {
                 packageMap->insert(con,con->getPackage());
-                importStatement.append(endLine+"import "+con->getPackage()+"."+gen->cleanName(con->getName())+";");
+
+                        // now, we DONT 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->getPackage() != c->getPackage() || 
+                               (c->getPackage().isEmpty() && con->getPackage().isEmpty()))
+                        {
+                                importStatement.append(endLine+"import ");
+                                if(!con->getPackage().isEmpty())
+                                        importStatement.append(con->getPackage()+".");
+                                importStatement.append(gen->cleanName(con->getName())+";");
+                        }
         }
         // now, add/update the imports codeblock
-        addOrUpdateTaggedCodeBlockWithComments("imports", importStatement, "", 0, false);
+        CodeBlockWithComments * iblock = addOrUpdateTaggedCodeBlockWithComments("imports", importStatement, "", 0, false);
+        if(importStatement.isEmpty() && iblock->getContentType() == CodeBlock::AutoGenerated)
+                iblock->setWriteOutText(false);
+        else
+                iblock->setWriteOutText(true);
 
         // CLASS DECLARATION BLOCK






More information about the umbrello-devel mailing list