Bug 132017 - java import : ERROR on multidimensional arrays
Summary: java import : ERROR on multidimensional arrays
Status: RESOLVED FIXED
Alias: None
Product: umbrello
Classification: Applications
Component: general (show other bugs)
Version: unspecified
Platform: Slackware Linux
: NOR normal
Target Milestone: ---
Assignee: Umbrello Development Group
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-08-07 18:34 UTC by JP Fournier
Modified: 2006-08-07 20:50 UTC (History)
0 users

See Also:
Latest Commit:
Version Fixed In:


Attachments
patch: Handle multidimensional arrays by recusively calling joinTypename (4.37 KB, patch)
2006-08-07 18:36 UTC, JP Fournier
Details

Note You need to log in before you can comment on or make changes to this bug.
Description JP Fournier 2006-08-07 18:34:20 UTC
Version:           1.5.4+ : svn 570599 (using KDE KDE 3.5.0)
Installed from:    Slackware Packages
Compiler:          gcc 
OS:                Linux

Importing the class below results in an ERROR log:



public class Test10{

	private int [] [] values;


}
Comment 1 JP Fournier 2006-08-07 18:36:05 UTC
Created attachment 17270 [details]
patch: Handle multidimensional arrays by recusively calling joinTypename
Comment 2 Oliver Kellogg 2006-08-07 20:50:11 UTC
SVN commit 570799 by okellogg:

Attachment 17270 [details] from JP Fournier fixes handling of multidimensional arrays by
 recusively calling joinTypename().
Renamed the static members to conform to the naming convention (prefix s_)
BUG:132017


 M  +1 -0      ChangeLog  
 M  +21 -15    umbrello/codeimport/javaimport.cpp  
 M  +10 -3     umbrello/codeimport/javaimport.h  


--- branches/KDE/3.5/kdesdk/umbrello/ChangeLog #570798:570799
@@ -6,6 +6,7 @@
 * Python code generation not independent of diagram view (131790)
 * Java import - method parameter types not resolved correctly (131825)
 * Java import: unable to import AzareusCore (131961)
+* Java import: error on multidimensional arrays (132017)
 
 Version 1.5.4
 
--- branches/KDE/3.5/kdesdk/umbrello/umbrello/codeimport/javaimport.cpp #570798:570799
@@ -29,12 +29,11 @@
 #include "../operation.h"
 #include "../attribute.h"
 
-QStringList JavaImport::m_filesAlreadyParsed;
-int JavaImport::m_parseDepth = 0;
+QStringList JavaImport::s_filesAlreadyParsed;
+int JavaImport::s_parseDepth = 0;
 
 JavaImport::JavaImport() : NativeImportBase("//") {
     setMultiLineComment("/*", "*/");
-    //m_parseDepth = 0;
     initVars();
 }
 
@@ -46,8 +45,7 @@
 }
 
 /// Catenate possible template arguments/array dimensions to the end of the type name.
-QString JavaImport::joinTypename() {
-    QString typeName = m_source[m_srcIndex];
+QString JavaImport::joinTypename(QString typeName) {
     if (m_source[m_srcIndex + 1] == "<" ||
         m_source[m_srcIndex + 1] == "[") {
         uint start = ++m_srcIndex;
@@ -57,6 +55,10 @@
             typeName += m_source[i];
         }
     }
+    // to handle multidimensional arrays, call recursively
+    if (m_source[m_srcIndex + 1] == "[") {
+        typeName = joinTypename( typeName );
+    }
     return typeName;
 }
 
@@ -136,16 +138,15 @@
 void JavaImport::spawnImport( QString file ) {
     // if the file is being parsed, don't bother
     //
-    if (m_filesAlreadyParsed.contains( file ) ) {
+    if (s_filesAlreadyParsed.contains( file ) ) {
         return;
     }
     if (QFile::exists(file)) {
           JavaImport importer;
           QStringList fileList;
           fileList.append( file );
-          m_filesAlreadyParsed.append( file );
+          s_filesAlreadyParsed.append( file );
           importer.importFiles( fileList ); 
-
     }
 }
 
@@ -236,14 +237,17 @@
     // public for member vars and methods
     m_defaultCurrentAccess = Uml::Visibility::Implementation;
     m_currentAccess = m_defaultCurrentAccess;
-    m_parseDepth++;
+    s_parseDepth++;
+    // in the case of self referencing types, we can avoid parsing the 
+    // file twice by adding it to the list
+    s_filesAlreadyParsed.append(filename);
     NativeImportBase::parseFile(filename);
-    m_parseDepth--;
-    if ( m_parseDepth <= 0 ) {
+    s_parseDepth--;
+    if ( s_parseDepth <= 0 ) {
         // if the user decides to clear things out and reparse, we need
         // to honour the request, so reset things for next time.
-        m_filesAlreadyParsed.clear();
-        m_parseDepth = 0;
+        s_filesAlreadyParsed.clear();
+        s_parseDepth = 0;
     }
 }
 
@@ -452,7 +456,8 @@
         kdError() << "importJava: ignoring " << keyword << endl;
         return false;
     }
-    QString typeName = joinTypename();
+    QString typeName = m_source[m_srcIndex];
+    typeName = joinTypename(typeName);
     // At this point we need a class.
     if (m_klass == NULL) {
         kdError() << "importJava: no class set for " << typeName << endl;
@@ -477,7 +482,8 @@
         UMLOperation *op = Import_Utils::makeOperation(m_klass, name);
         m_srcIndex++;
         while (m_srcIndex < srcLength && m_source[m_srcIndex] != ")") {
-            QString typeName = joinTypename();
+            QString typeName = m_source[m_srcIndex];
+            typeName = joinTypename(typeName);
             QString parName = advance();
             // the Class might not be resolved yet so resolve it if necessary
             UMLObject *obj = resolveClass(typeName);
--- branches/KDE/3.5/kdesdk/umbrello/umbrello/codeimport/javaimport.h #570798:570799
@@ -68,7 +68,14 @@
      */
     void spawnImport(QString file);
 
-    QString joinTypename();
+    /**
+     * figure out if the type is really an array or template of the given typeName
+     */
+    QString joinTypename(QString typeName);
+    
+    /**
+     * true if the member var or method is declared static
+     */
     bool m_isStatic;
 
     /**
@@ -90,13 +97,13 @@
      * Keep track of the files we have already parsed so we don't
      * reparse the same ones over and over again.
      */
-    static QStringList m_filesAlreadyParsed;
+    static QStringList s_filesAlreadyParsed;
 
     /**
      * Keep track of the parses so that the filesAlreadyParsed 
      * can be reset when we're done.
      */
-    static int m_parseDepth;
+    static int s_parseDepth;
 
     /**
      * The current visibility for when the visibility is absent