Bug 132035 - java import - array types not resolved correctly
Summary: java import - array types not resolved correctly
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-08 01:06 UTC by JP Fournier
Modified: 2006-08-08 08:01 UTC (History)
0 users

See Also:
Latest Commit:
Version Fixed In:


Attachments
patch : add support for resolving array types correctly (4.24 KB, patch)
2006-08-08 01:08 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-08 01:06:48 UTC
Version:           1.5.4+ : svn 570819 (using KDE KDE 3.5.0)
Installed from:    Slackware Packages
Compiler:          gcc 
OS:                Linux

Import Test10 below.  Test11 is not resolved correctly.


public class Test10{

	private Test11[] data;

}


public class Test11{

}

The problem also occurs in classes not belonging to the default package.
Comment 1 JP Fournier 2006-08-08 01:08:14 UTC
Created attachment 17283 [details]
patch : add support for resolving array types correctly
Comment 2 Oliver Kellogg 2006-08-08 08:01:41 UTC
SVN commit 570932 by okellogg:

Attachment 17283 [details] from JP Fournier fixes type resolution for array types.
BUG:132035


 M  +1 -0      ChangeLog  
 M  +28 -9     umbrello/codeimport/javaimport.cpp  


--- branches/KDE/3.5/kdesdk/umbrello/ChangeLog #570931:570932
@@ -7,6 +7,7 @@
 * Java import - method parameter types not resolved correctly (131825)
 * Java import: unable to import AzareusCore (131961)
 * Java import: error on multidimensional arrays (132017)
+* Java import - array types not resolved correctly (132035)
 
 Version 1.5.4
 
--- branches/KDE/3.5/kdesdk/umbrello/umbrello/codeimport/javaimport.cpp #570931:570932
@@ -161,6 +161,16 @@
 
 ///Resolve the specified className 
 UMLObject* JavaImport::resolveClass (QString className) {
+    kdDebug() << "importJava trying to resolve " << className << endl; 
+    // keep track if we are dealing with an array
+    //
+    bool isArray = className.contains('[');
+    // remove any [] so that the class itself can be resolved
+    //
+    QString baseClassName = className;
+    baseClassName.remove('[');
+    baseClassName.remove(']');
+
     // java has a few implicit imports.  Most relevant for this is the 
     // current package, which is in the same directory as the current file
     // being parsed
@@ -175,10 +185,15 @@
     // current class
     //
     QString myDir = file.join( "/" );
-    QString myFile = "/" + myDir + "/" + className + ".java";
+    QString myFile = "/" + myDir + "/" + baseClassName + ".java";
     if ( QFile::exists(myFile) ) {
         spawnImport( myFile );
-        return findObject ( className, m_scope[m_scopeIndex]);
+        if ( isArray ) {
+            // we have imported the type. For arrays we want to return 
+            // the array type
+            return Import_Utils::createUMLObject(Uml::ot_Class, className, m_scope[m_scopeIndex]);
+        }
+        return findObject(baseClassName, m_scope[m_scopeIndex]);
     }
 
     // the class we want is not in the same package as the one being imported.
@@ -200,11 +215,11 @@
         QString import = (*pathIt);
         QStringList split = QStringList::split( '.', import );
         split.pop_back(); // remove the * or the classname
-        if ( import.endsWith( "*" ) || import.endsWith( className) ) {
+        if ( import.endsWith( "*" ) || import.endsWith( baseClassName) ) {
             // check if the file we want is in this imported package
             // convert the org.test type package into a filename
             //
-            QString aFile = sourceRoot + split.join("/") + "/" + className + ".java";
+            QString aFile = sourceRoot + split.join("/") + "/" + baseClassName + ".java";
             if ( QFile::exists(aFile) ) {
                 spawnImport( aFile );
                 // we need to set the package for the class that will be resolved
@@ -215,13 +230,17 @@
                 for (QStringList::Iterator it = split.begin(); it != split.end(); ++it) {
                     QString name = (*it);
                     UMLObject *ns = Import_Utils::createUMLObject(Uml::ot_Package,
-                            name, parent);
+                                                                  name, parent);
                     current = static_cast<UMLPackage*>(ns);
                     parent = current;
                 } // for
+                if ( isArray ) {
+                    // we have imported the type. For arrays we want to return 
+                    // the array type
+                    return Import_Utils::createUMLObject(Uml::ot_Class, className, current);
+                }
                 // now that we have the right package, the class should be findable
-                //
-                return findObject ( className, current);
+                return findObject(baseClassName, current);
             } // if file exists
         } // if import matches
     } //foreach import
@@ -491,7 +510,7 @@
                 // by prepending the package, unwanted placeholder types will not get created
                 typeName = obj->getFullyQualifiedName(".");
             }
-            UMLAttribute *att = Import_Utils::addMethodParameter(op, typeName, parName);
+            /* UMLAttribute *att = */ Import_Utils::addMethodParameter(op, typeName, parName);
             if (advance() != ",")
                 break;
             m_srcIndex++;
@@ -556,7 +575,7 @@
             o = Import_Utils::insertAttribute(m_klass, m_currentAccess, name,
                                                   typeName, m_comment, m_isStatic);
         }
-        UMLAttribute *attr = static_cast<UMLAttribute*>(o);
+        // UMLAttribute *attr = static_cast<UMLAttribute*>(o);
         if (nextToken != ",") {
             // reset the modifiers
             m_isStatic = m_isAbstract = false;