[Uml-devel] java import problem

Oliver Kellogg okellogg at users.sourceforge.net
Thu Jul 20 18:27:20 UTC 2006


JP Fournier wrote:
>
> I've noticed a problem with java import that I cannot see
> an obvious solution for.  Normally java classes belong to
> packages, like:
> [...]
>
> The thing is that when Test1 is imported, it doesn't know that
> Test2 is actually test.Test2.  If the above 2 classes are imported,
> then I end up with 3 imported classes : test.Test1, test.Test2 and
> Test2.  In this example test.Test1 is considered a subclass of Test2
> instead of test.Test2.
>

Good point. The ambiguity stems from C++, here is an example:

#include <iostream>
using namespace std;

struct Ambiguous {
   void f() {
     cout << "::Ambiguous::f" << endl;
   }
};

namespace n1 {
   struct Ambiguous {
     void f() {
       cout << "n1::Ambiguous::f" << endl;
     }
   };
}

struct Unambiguous_in_global_scope {
   void f() {
     cout << "::Unambiguous::f" << endl;
   }
};

namespace n1 {
   // ambiguous
   struct Child_of_n1_Ambiguous : public Ambiguous
   {
   };
   // not unbiguous
   struct Child_of_global_Ambiguous : public ::Ambiguous
   {
   };
   // not unbiguous
   struct Child : public Unambiguous_in_global_scope
   {
   };
}

int main ()
{
   n1::Child_of_n1_Ambiguous n1_child;
   n1::Child_of_global_Ambiguous g_child;
   n1::Child unambig;
   n1_child.f();
   g_child.f();
   unambig.f();
   return 0;
}

The program produces the following output:

  n1::Ambiguous::f
  ::Ambiguous::f
  ::Unambiguous::f


However, if we import n1::Child_of_n1_Ambiguous without having seen 
n1::Ambiguous then C++ happily takes the Ambiguous from the global
scope.

I think I will change the logic around Import_Utils::createUMLObject()
such that it follows the Java style, i.e. in this last case where we
haven't seen n1::Ambiguous then Ambiguous is synthesized inside
n1. That just means that peole importing C++ code will need to be
aware of the class dependencies and make sure that classes closer
to the root of the hierarchy are imported before dependent classes.
(Or, always prefix "::" when the global scope is intended.)

Oliver




More information about the umbrello-devel mailing list