Index: /trunk/ProjectFortress/src/com/sun/fortress/repository/ForeignJava.java
===================================================================
--- /trunk/ProjectFortress/src/com/sun/fortress/repository/ForeignJava.java (revision 3289)
+++ /trunk/ProjectFortress/src/com/sun/fortress/repository/ForeignJava.java (revision 3291)
@@ -36,4 +36,5 @@
 import com.sun.fortress.nodes.Api;
 import com.sun.fortress.nodes.BaseType;
+import com.sun.fortress.nodes.CompilationUnit;
 import com.sun.fortress.nodes.Decl;
 import com.sun.fortress.nodes.Expr;
@@ -56,5 +57,8 @@
 import com.sun.fortress.nodes_util.Span;
 import com.sun.fortress.useful.Bijection;
+import com.sun.fortress.useful.F;
 import com.sun.fortress.useful.HashBijection;
+import com.sun.fortress.useful.IMultiMap;
+import com.sun.fortress.useful.MapOfMapOfSet;
 import com.sun.fortress.useful.MultiMap;
 import com.sun.fortress.useful.Useful;
@@ -72,5 +76,5 @@
      * Given a foreign API Name, what other (foreign) APIs does it import?
      */
-    MultiMap<APIName, APIName> generatedImports = new MultiMap<APIName, APIName>();
+    MapOfMapOfSet<APIName, APIName, Id> generatedImports = new MapOfMapOfSet<APIName, APIName, Id>();
     
     /**
@@ -126,5 +130,5 @@
     
     static void s(Class cl, APIName api, String str) {
-        specialCases.put(cl, NodeFactory.makeTraitType(span, false, NodeFactory.makeId(span, api, str)));
+        specialCases.put(cl, NodeFactory.makeTraitType(span, false, NodeFactory.makeId(span, str)));
     }
     
@@ -140,5 +144,6 @@
         s(Double.class, fortLib, "RR64");
         s(Double.TYPE, fortLib, "RR64");
-        s(String.class, fortLib, "String");
+        s(Object.class, fortLib, "Any");
+        s(String.class, fortLib, "FlatString");
         s(BigInteger.class, fortLib, "ZZ");
         specialCases.put(Void.TYPE, NodeFactory.makeVoidType(span));
@@ -256,10 +261,11 @@
         Package p = imported_class.getPackage();
         APIName api_name = packageToAPIName(p);
-        
+        Id name = NodeFactory.makeId(span, imported_class.getSimpleName());
+
         /* Though the class may have been previously referenced, the import
          * may still need to be recorded.  Re-recording an existing import
          * is harmless.
          */
-        generatedImports.putItem(importing_package, api_name);
+        generatedImports.putItem(importing_package, api_name, name);
         
         /*
@@ -268,5 +274,4 @@
         javaImplementedAPIs.putItem(api_name,imported_class);
         
-        Id name = NodeFactory.makeId(span, imported_class.getSimpleName());
         
         /*
@@ -282,5 +287,6 @@
         };
         
-        name = NodeFactory.makeId(api_name, name);
+        // LOSE THE DOTTED REFERENCE, at least for now.
+        // name = NodeFactory.makeId(api_name, name);
         // Note: a TraitType is a reference to a trait.
         return NodeFactory.makeTraitType(span, false, name);
@@ -365,12 +371,15 @@
         for (Class pt : pts) {
             Type type = recurOnOpaqueClass(importing_package, pt);
-            Id id = NodeFactory.makeId(span, "p"+(i++));
+            Span param_span = NodeFactory.makeSpan(m.toString() + " p#" + i);
+            Id id = NodeFactory.makeId(param_span, "p"+(i++));
             Param p = NodeFactory.makeParam(id, type);
             params.add(p);
         }
+        
+        Span fn_span = NodeFactory.makeSpan(m.toString());
         Id id = is_static ?
-                NodeFactory.makeId(span, cl.getSimpleName()+"."+ m.getName()) :
-            NodeFactory.makeId(span, m.getName());
-        FnDecl fndecl = NodeFactory.makeFnDecl(span, Modifiers.None,
+                NodeFactory.makeId(fn_span, cl.getSimpleName()+"."+ m.getName()) :
+            NodeFactory.makeId(fn_span, m.getName());
+        FnDecl fndecl = NodeFactory.makeFnDecl(fn_span, Modifiers.None,
                 id, params,Option.some(return_type), Option.<Expr>none());
         methodToDecl.put(m, fndecl);
@@ -399,11 +408,9 @@
 
             List<Import> imports = new ArrayList<Import>();
-            Set<APIName> gi = generatedImports.get(name);
+            IMultiMap<APIName, Id> gi = generatedImports.get(name);
             if (gi != null)
-                for (APIName a : gi) {
-                    importAnApi(imports, a);
+                for (APIName a : gi.keySet()) {
+                    importAnApi(imports, a, gi.get(a));
                 }
-            // Implicitly import.
-            importAnApi(imports, NodeFactory.makeAPIName(span, "FortressLibrary"));
             
             List<Decl> decls = new ArrayList<Decl>();
@@ -420,19 +427,16 @@
     }
 
-    private void importAnApi(List<Import> imports, APIName a) {
-        AliasedAPIName aan = NodeFactory.makeAliasedAPIName(a);
-        /*
-         * Hoping to lie, slightly, to static analysis. This is
-         * technically speaking a "foreign" import, but the import
-         * is already known to the ForeignJava data structures, and
-         * this allows use of fully qualified (hence unambiguous)
-         * references to classes from other packages in the
-         * generated API.
-         * 
-         * So, one lie -- no foreign annotation.
-         */
-        ImportApi iapi = NodeFactory.makeImportApi(span, Option
-                .<String> none(), Useful.list(aan));
-        imports.add(iapi);
+    private void importAnApi(List<Import> imports, APIName a, Set<Id> items) {
+        
+        List<AliasedSimpleName> lasn = new ArrayList<AliasedSimpleName>();
+        lasn = Useful.applyToAllAppending(items, new F<Id, AliasedSimpleName>() {
+            @Override
+            public AliasedSimpleName apply(Id x) {
+                return NodeFactory.makeAliasedSimpleName(x);
+            } }, lasn);
+        
+        ImportNames imp_names = NodeFactory.makeImportNames(span, Option.some("java"), a, lasn);
+       
+        imports.add(imp_names);
     }
     
@@ -441,6 +445,17 @@
             map.put(a, fakeApi(a));
         }
+        
+        dumpGenerated();
+        
         return map;
     }
+    
+    public void dumpGenerated() {
+        for (APIName a : javaImplementedAPIs.keySet()) {
+            System.out.println(a);
+            CompilationUnit cu = fakeApi(a).ast();
+            System.out.println(cu.toStringVerbose());
+        }
+    }
 
 }
Index: /trunk/ProjectFortress/src/com/sun/fortress/useful/UsefulPLT.java
===================================================================
--- /trunk/ProjectFortress/src/com/sun/fortress/useful/UsefulPLT.java (revision 3134)
+++ /trunk/ProjectFortress/src/com/sun/fortress/useful/UsefulPLT.java (revision 3291)
@@ -1,4 +1,4 @@
 /*******************************************************************************
-    Copyright 2008 Sun Microsystems, Inc.,
+    Copyright 2009 Sun Microsystems, Inc.,
     4150 Network Circle, Santa Clara, California 95054, U.S.A.
     All rights reserved.
@@ -109,6 +109,7 @@
                 public void addInverse(Map<V, K> m) { error(); }
                 public Set<V> putItem(K k, V v) { return error(); }
-                public Set<V> putItems(K k, Set<V> vs) { return error(); }
+                public Set<V> putItems(K k, Collection<V> vs) { return error(); }
                 public Set<V> removeItem(K k, V v) { return error(); }
+                public Set<V> putKey(K k) {return error();}
                 };
         }
Index: /trunk/ProjectFortress/src/com/sun/fortress/useful/MapOfMapOfSet.java
===================================================================
--- /trunk/ProjectFortress/src/com/sun/fortress/useful/MapOfMapOfSet.java (revision 3291)
+++ /trunk/ProjectFortress/src/com/sun/fortress/useful/MapOfMapOfSet.java (revision 3291)
@@ -0,0 +1,56 @@
+/*******************************************************************************
+    Copyright 2009 Sun Microsystems, Inc.,
+    4150 Network Circle, Santa Clara, California 95054, U.S.A.
+    All rights reserved.
+
+    U.S. Government Rights - Commercial software.
+    Government users are subject to the Sun Microsystems, Inc. standard
+    license agreement and applicable provisions of the FAR and its supplements.
+
+    Use is subject to license terms.
+
+    This distribution may include materials developed by third parties.
+
+    Sun, Sun Microsystems, the Sun logo and Java are trademarks or registered
+    trademarks of Sun Microsystems, Inc. in the U.S. and other countries.
+ ******************************************************************************/
+
+package com.sun.fortress.useful;
+
+import java.util.Collection;
+import java.util.HashMap;
+
+public class MapOfMapOfSet<K, L, T> extends HashMap<K, IMultiMap<L, T>> {
+
+    public IMultiMap<L,T> putItem(K k, L l, T t) {
+        IMultiMap<L, T> map = get(k);
+        if (map == null) {
+            map = new MultiMap<L,T>();
+            put(k,map);
+        }
+        map.putItem(l, t);
+        return map;
+    }
+    
+    public IMultiMap<L,T> putItems(K k, L l, Collection<T> s) {
+        IMultiMap<L, T> map = get(k);
+        if (map == null) {
+            map = new MultiMap<L,T>();
+            put(k,map);
+        }
+        map.putItems(l, s);
+        return map;
+    }
+    
+    
+    public IMultiMap<L,T> putItem(K k, L l) {
+        IMultiMap<L, T> map = get(k);
+        if (map == null) {
+            map = new MultiMap<L,T>();
+            put(k,map);
+        }
+        map.putKey(l);
+        return map;
+    }
+
+}
Index: /trunk/ProjectFortress/src/com/sun/fortress/useful/IMultiMap.java
===================================================================
--- /trunk/ProjectFortress/src/com/sun/fortress/useful/IMultiMap.java (revision 2725)
+++ /trunk/ProjectFortress/src/com/sun/fortress/useful/IMultiMap.java (revision 3291)
@@ -1,4 +1,4 @@
 /*******************************************************************************
-    Copyright 2008 Sun Microsystems, Inc.,
+    Copyright 2009 Sun Microsystems, Inc.,
     4150 Network Circle, Santa Clara, California 95054, U.S.A.
     All rights reserved.
@@ -29,13 +29,16 @@
     public Set<V> putItem(K k, V v);
 
-    public Set<V> putItems(K k, Set<V> vs);
+    public Set<V> putItems(K k, Collection<V> vs);
 
     public Set<V> removeItem(K k, V v);
+    
+    public Set<V> putKey(K k);
 
     public final static IMultiMap EMPTY_MULTIMAP = new IMultiMap() {
         private <T> T error() { throw new IllegalStateException("Empty IMultiMap is immutable."); }
         public void addInverse(Map m) { error(); }
+        public Set putKey(Object k) { return error(); }
         public Set putItem(Object k, Object v) { return error(); }
-        public Set putItems(Object k, Set vs) { return error(); }
+        public Set putItems(Object k, Collection vs) { return error(); }
         public Set removeItem(Object k, Object v) { return error(); }
         public void clear() { error(); }
Index: /trunk/ProjectFortress/src/com/sun/fortress/useful/UsefulJUTest.java
===================================================================
--- /trunk/ProjectFortress/src/com/sun/fortress/useful/UsefulJUTest.java (revision 3259)
+++ /trunk/ProjectFortress/src/com/sun/fortress/useful/UsefulJUTest.java (revision 3291)
@@ -1,4 +1,4 @@
 /*******************************************************************************
-    Copyright 2008 Sun Microsystems, Inc.,
+    Copyright 2009 Sun Microsystems, Inc.,
     4150 Network Circle, Santa Clara, California 95054, U.S.A.
     All rights reserved.
@@ -227,6 +227,23 @@
         map.remove("too");
         assertEquals(true, map.validate());
-
-        
-    }
+    }
+    
+    public void testMOMOS() {
+        MapOfMapOfSet<String, String, String> reln = new MapOfMapOfSet<String, String, String>();
+        
+        reln.putItem("eats", "cow", "grass");
+        reln.putItem("eats", "cow", "corn");
+        reln.putItem("eats", "rat", "cheese");
+        reln.putItem("chases", "dog", "cat");
+        reln.putItem("chases", "cat", "rat");
+        
+        IMultiMap<String, String> eats = reln.get("eats");
+        IMultiMap<String, String> chases = reln.get("chases");
+        
+        assertEquals(eats.get("cow"), Useful.set("grass", "corn"));
+        assertEquals(eats.get("rat"), Useful.set("cheese"));
+        assertEquals(chases.get("dog"), Useful.set("cat"));             
+        assertEquals(chases.get("cat"), Useful.set("rat"));             
+    }
+    
 }
Index: /trunk/ProjectFortress/src/com/sun/fortress/useful/MultiMap.java
===================================================================
--- /trunk/ProjectFortress/src/com/sun/fortress/useful/MultiMap.java (revision 3259)
+++ /trunk/ProjectFortress/src/com/sun/fortress/useful/MultiMap.java (revision 3291)
@@ -1,4 +1,4 @@
 /*******************************************************************************
-    Copyright 2008 Sun Microsystems, Inc.,
+    Copyright 2009 Sun Microsystems, Inc.,
     4150 Network Circle, Santa Clara, California 95054, U.S.A.
     All rights reserved.
@@ -18,4 +18,5 @@
 package com.sun.fortress.useful;
 
+import java.util.Collection;
 import java.util.HashMap;
 import java.util.HashSet;
@@ -77,5 +78,5 @@
         return s;
     }
-    public Set<V> putItems(K k, Set<V> vs) {
+    public Set<V> putItems(K k, Collection<V> vs) {
         Set<V> s = get(k);
         if (s == null) {
Index: /trunk/ProjectFortress/src/com/sun/fortress/interpreter/Driver.java
===================================================================
--- /trunk/ProjectFortress/src/com/sun/fortress/interpreter/Driver.java (revision 3252)
+++ /trunk/ProjectFortress/src/com/sun/fortress/interpreter/Driver.java (revision 3291)
@@ -1,4 +1,4 @@
 /*******************************************************************************
-    Copyright 2008 Sun Microsystems, Inc.,
+    Copyright 2009 Sun Microsystems, Inc.,
     4150 Network Circle, Santa Clara, California 95054, U.S.A.
     All rights reserved.
