[e-cvs] cvs commit: e/src/jsrc/org/erights/e/ui/jed EditGroup.java

markm@eros.cs.jhu.edu markm@eros.cs.jhu.edu
Sun, 16 Dec 2001 05:10:30 -0500


markm       01/12/16 05:10:30

  Modified:    src/jsrc/net/captp/tables SwissTable.java
               src/jsrc/org/erights/e/elib/base ClassDesc.java
                        MessageDesc.java ParamDesc.java TypeDesc.java
               src/jsrc/org/erights/e/elib/prim MirandaMethods.java
                        StaticMaker.java VarSetterNode.java
               src/jsrc/org/erights/e/elib/slot NullOkMaker.java
                        VoidMaker.java
               src/jsrc/org/erights/e/elib/tables Column.java
                        CycleBreaker.java EList.java ESet.java
                        Equalizer.java FlexSet.java VoidColumn.java
               src/jsrc/org/erights/e/ui/jed EditGroup.java
  Log:
  Void.TYPE changed to class, fixing asSet().  Java types now have proper guards and print cleanly.

Revision  Changes    Path
1.10      +1 -1      e/src/jsrc/net/captp/tables/SwissTable.java

Index: SwissTable.java
===================================================================
RCS file: /cvs/e/src/jsrc/net/captp/tables/SwissTable.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- SwissTable.java	2001/12/02 06:01:39	1.9
+++ SwissTable.java	2001/12/16 10:10:29	1.10
@@ -86,7 +86,7 @@
         mySelfishToSwiss = new WeakKeyMap(Object.class, BigInteger.class);
         mySwissToRef = new WeakValueMap(BigInteger.class, Object.class);
         myEntropy = entropy;
-        mySwissDBs = FlexMap.fromTypes(OneArgFunc.class, Void.TYPE);
+        mySwissDBs = FlexMap.fromTypes(OneArgFunc.class, Void.class);
     }
 
     /**



1.33      +48 -3     e/src/jsrc/org/erights/e/elib/base/ClassDesc.java

Index: ClassDesc.java
===================================================================
RCS file: /cvs/e/src/jsrc/org/erights/e/elib/base/ClassDesc.java,v
retrieving revision 1.32
retrieving revision 1.33
diff -u -r1.32 -r1.33
--- ClassDesc.java	2001/12/14 00:06:00	1.32
+++ ClassDesc.java	2001/12/16 10:10:29	1.33
@@ -32,6 +32,10 @@
 import org.erights.e.elib.tables.FlexMap;
 import org.erights.e.elib.util.ClassCache;
 import org.erights.e.elib.util.OneArgFunc;
+import org.erights.e.elib.slot.BothGuard;
+import org.erights.e.elib.slot.NullOkMaker;
+import org.erights.e.elib.slot.SimpleSlotMaker;
+import org.erights.e.elib.slot.VoidMaker;
 import org.erights.e.meta.java.lang.ArrayGuardSugar;
 import org.erights.e.meta.java.lang.InterfaceGuardSugar;
 
@@ -156,7 +160,7 @@
                 System.arraycopy(ifaces, 0, supers, 1, ifaces.length);
                 supers[0] = optSuper;
             }
-            FlexMap superSugarSet = FlexMap.fromTypes(Class.class, Void.TYPE);
+            FlexMap superSugarSet = FlexMap.fromTypes(Class.class, Void.class);
             for (int i = 0; i < supers.length; i++) {
                 Class superSugar = GetGuard(supers[i]);
                 if (ClassDesc.class != superSugar &&
@@ -199,8 +203,49 @@
       FlexMap.fromTypes(Class.class, ClassDesc.class);
 
     /**
-     * Returns the E-object that a Java Class object promotes to. <p>
-     *
+     * Returns a guard that corresponds more closely than make/1, in two ways,
+     * to Java's type conformance rules.
+     * <p>
+     * 1) In Java, what a class is used to declare a variable, parameter, or
+     * return type, unless the class is primitive, it accepts
+     * <code>null</code> in addition to instances of its type.  If the class
+     * is primitive (ie, a scalar, like <code>char</code>, then it accepts
+     * only instances of its type.
+     * <p>
+     * By contrast, when a Java class is used as an E guard, it accepts only
+     * instances of its type.  In order to form a guard that accepts either
+     * <code>null</code> or any instance of class T, one uses the
+     * <code>nullOk</code> function: <pre>
+     *     def x :nullOk(T)
+     * </pre>
+     * The byJavaRules/1 method will turn a class into a guard in the same way
+     * as make/1, except that if the Class parameter isn't primitive, it'll
+     * then wrap the result in a call to nullOk/1.
+     * <p>
+     * 2) The class Object.class is turned into the equivalent of
+     * <code>:any</code> rather than using a ClassDesc on the class object.
+     * This reflects that Java parameters of type Object will also accept
+     * non-near pointers.  Likewise, it converts Void.class and Void.TYPE into
+     * the equivalent of <code>:void</code>.
+     */
+    static public BothGuard byJavaRules(Class clazz) {
+        if (Object.class == clazz) {
+            return SimpleSlotMaker.THE_ONE;
+        }
+        if (Void.class == clazz || Void.TYPE == clazz) {
+            return VoidMaker.THE_ONE;
+        }
+        BothGuard result = make(clazz);
+        if (clazz.isPrimitive()) {
+            return result;
+        } else {
+            return NullOkMaker.THE_ONE.run(result);
+        }
+    }
+
+    /**
+     * Returns the E-object that a Java Class object promotes to.
+     * <p>
      * This provides two services: 1) A descriptions of the messages that may
      * be sent to members of this type. 2) ValueGuard (coerce/2) behavior and
      * SlotGuard (makeSlot/2) behavior, enabling a Class to be used as a



1.12      +39 -22    e/src/jsrc/org/erights/e/elib/base/MessageDesc.java

Index: MessageDesc.java
===================================================================
RCS file: /cvs/e/src/jsrc/org/erights/e/elib/base/MessageDesc.java,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- MessageDesc.java	2001/12/10 18:27:00	1.11
+++ MessageDesc.java	2001/12/16 10:10:29	1.12
@@ -27,6 +27,7 @@
 import org.erights.e.elib.serial.Persistent;
 import org.erights.e.elib.slot.NullOkMaker;
 import org.erights.e.elib.slot.ValueGuard;
+import org.erights.e.elib.slot.VoidMaker;
 import org.erights.e.elib.tables.ConstList;
 
 import java.io.IOException;
@@ -51,6 +52,9 @@
 
     private Object myRetType;
 
+    /**
+     *
+     */
     static /*package*/ void synopsize(TextWriter out, String str)
       throws IOException {
         out.print("/**");
@@ -73,56 +77,69 @@
         myRetType = retType;
     }
 
+    /**
+     *
+     */
     public String getDocComment() {
         return myDocComment;
     }
 
+    /**
+     *
+     */
     public String getVerb() {
         return myVerb;
     }
 
+    /**
+     *
+     */
     public ConstList getParams() {
         return myParams;
     }
 
+    /**
+     *
+     */
     public ValueGuard getReturnType() {
         if (myRetType instanceof Class) {
-            Class clazz = (Class)myRetType;
-            myRetType = ClassDesc.make(clazz);
-            if (! clazz.isPrimitive()) {
-                myRetType = NullOkMaker.THE_ONE.run((ValueGuard)myRetType);
-            }
+            myRetType = ClassDesc.byJavaRules((Class)myRetType);
         }
         return (ValueGuard)myRetType;
     }
 
+    /**
+     *
+     */
     public void printOn(TextWriter out) throws IOException {
         synopsize(out, myDocComment);
-        out.lnPrint("to " + myVerb);
-        int len = myParams.size();
-        if (len >= 1) {
-            out.print("(", myParams.get(0));
-            for (int i = 1; i < len; i++) {
-                out.print(", ", myParams.get(i));
-            }
-            out.print(")");
-        }
-        //XXX should suppress if myRetType == :void
-        out.print(" :", E.call(myRetType, "getName"));
+        printDeclOn(out);
     }
 
+    /**
+     *
+     */
     public void printHelpOn(TextWriter out) throws IOException {
-        out.lnPrint("to " + myVerb);
+        printDeclOn(out);
+        out.indent().lnPrint(myDocComment);
+    }
+
+    /**
+     *
+     */
+    private void printDeclOn(TextWriter out) throws IOException {
+        out.lnPrint("to " + myVerb + "(");
         int len = myParams.size();
         if (len >= 1) {
-            out.print("(", myParams.get(0));
+            out.print(myParams.get(0));
             for (int i = 1; i < len; i++) {
                 out.print(", ", myParams.get(i));
             }
-            out.print(")");
         }
-        //XXX should suppress if myRetType == :void
-        out.print(" :", E.call(myRetType, "getName"));
-        out.indent().lnPrint(myDocComment);
+        out.print(")");
+        ValueGuard guard = getReturnType();
+        if (VoidMaker.THE_ONE != guard) {
+            out.print(" :", guard.getName());
+        }
     }
 }



1.12      +7 -7      e/src/jsrc/org/erights/e/elib/base/ParamDesc.java

Index: ParamDesc.java
===================================================================
RCS file: /cvs/e/src/jsrc/org/erights/e/elib/base/ParamDesc.java,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- ParamDesc.java	2001/12/10 18:27:00	1.11
+++ ParamDesc.java	2001/12/16 10:10:29	1.12
@@ -28,6 +28,7 @@
 import org.erights.e.elib.slot.NullOkMaker;
 import org.erights.e.elib.slot.SlotGuard;
 import org.erights.e.elib.slot.ValueGuard;
+import org.erights.e.elib.slot.SimpleSlotMaker;
 
 import java.io.IOException;
 
@@ -76,11 +77,7 @@
      */
     public SlotGuard getType() {
         if (myType instanceof Class) {
-            Class clazz = (Class)myType;
-            myType = ClassDesc.make(clazz);
-            if (! clazz.isPrimitive()) {
-                myType = NullOkMaker.THE_ONE.run((ValueGuard)myType);
-            }
+            myType = ClassDesc.byJavaRules((Class)myType);
         }
         return (SlotGuard)myType;
     }
@@ -89,7 +86,10 @@
      * Prints 'name :type'
      */
     public void printOn(TextWriter out) throws IOException {
-        //XXX should suppress ':any'
-        out.print(myName, " :", E.call(myType, "getName"));
+        out.print(myName);
+        SlotGuard guard = getType();
+        if (SimpleSlotMaker.THE_ONE != guard) {
+            out.print(" :", guard.getName());
+        }
     }
 }



1.17      +2 -1      e/src/jsrc/org/erights/e/elib/base/TypeDesc.java

Index: TypeDesc.java
===================================================================
RCS file: /cvs/e/src/jsrc/org/erights/e/elib/base/TypeDesc.java,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -r1.16 -r1.17
--- TypeDesc.java	2001/12/14 00:06:00	1.16
+++ TypeDesc.java	2001/12/16 10:10:29	1.17
@@ -138,6 +138,7 @@
      * position, ":type" is equivalent to ":settable(type)".
      */
     public Slot makeSlot(Object specimen, OneArgFunc optEjector) {
-        return SettableSlotMaker.THE_ONE.run(this).makeSlot(specimen, optEjector);
+        SettableSlotMaker settable = SettableSlotMaker.THE_ONE;
+        return settable.run(this).makeSlot(specimen, optEjector);
     }
 }



1.44      +1 -1      e/src/jsrc/org/erights/e/elib/prim/MirandaMethods.java

Index: MirandaMethods.java
===================================================================
RCS file: /cvs/e/src/jsrc/org/erights/e/elib/prim/MirandaMethods.java,v
retrieving revision 1.43
retrieving revision 1.44
diff -u -r1.43 -r1.44
--- MirandaMethods.java	2001/12/02 06:01:45	1.43
+++ MirandaMethods.java	2001/12/16 10:10:29	1.44
@@ -142,7 +142,7 @@
         }
         Class selfClass;
         if (self == null) {
-            selfClass = Void.TYPE;
+            selfClass = Void.class;
         } else {
             selfClass = self.getClass();
         }



1.25      +1 -1      e/src/jsrc/org/erights/e/elib/prim/StaticMaker.java

Index: StaticMaker.java
===================================================================
RCS file: /cvs/e/src/jsrc/org/erights/e/elib/prim/StaticMaker.java,v
retrieving revision 1.24
retrieving revision 1.25
diff -u -r1.24 -r1.25
--- StaticMaker.java	2001/12/02 06:01:46	1.24
+++ StaticMaker.java	2001/12/16 10:10:29	1.25
@@ -113,7 +113,7 @@
 
     static {
         int len = ApprovedClassList.length;
-        FlexMap map = FlexMap.fromTypes(String.class, Void.TYPE, len);
+        FlexMap map = FlexMap.fromTypes(String.class, Void.class, len);
         for (int i = 0; i < len; i++) {
             map.put(ApprovedClassList[i], null, true);
         }



1.16      +1 -1      e/src/jsrc/org/erights/e/elib/prim/VarSetterNode.java

Index: VarSetterNode.java
===================================================================
RCS file: /cvs/e/src/jsrc/org/erights/e/elib/prim/VarSetterNode.java,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -r1.15 -r1.16
--- VarSetterNode.java	2001/12/10 18:27:00	1.15
+++ VarSetterNode.java	2001/12/16 10:10:29	1.16
@@ -72,7 +72,7 @@
      *
      */
     protected Class returnType() {
-        return Void.TYPE;
+        return Void.class;
     }
 
     /**



1.11      +6 -6      e/src/jsrc/org/erights/e/elib/slot/NullOkMaker.java

Index: NullOkMaker.java
===================================================================
RCS file: /cvs/e/src/jsrc/org/erights/e/elib/slot/NullOkMaker.java,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- NullOkMaker.java	2001/12/14 00:06:01	1.10
+++ NullOkMaker.java	2001/12/16 10:10:29	1.11
@@ -102,7 +102,11 @@
      * "nullOk"
      */
     public String getName() {
-        return "nullOk";
+        if (null == myOptValueGuard) {
+            return "nullOk";
+        } else {
+            return "nullOk(" + myOptValueGuard.getName() + ")";
+        }
     }
 
     /**
@@ -116,10 +120,6 @@
      *
      */
     public void printOn(TextWriter out) throws IOException {
-        if (myOptValueGuard == null) {
-            out.print("<nullOk>");
-        } else {
-            out.print("<nullOk(", myOptValueGuard, ")>");
-        }
+        out.print("<", getName(), ">");
     }
 }



1.7       +11 -1     e/src/jsrc/org/erights/e/elib/slot/VoidMaker.java

Index: VoidMaker.java
===================================================================
RCS file: /cvs/e/src/jsrc/org/erights/e/elib/slot/VoidMaker.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- VoidMaker.java	2001/11/10 19:40:48	1.6
+++ VoidMaker.java	2001/12/16 10:10:29	1.7
@@ -32,7 +32,7 @@
  *
  * @author <a href="mailto:markm@erights.org">Mark S. Miller</a>
  */
-public class VoidMaker implements ValueGuard {
+public class VoidMaker implements BothGuard {
 
     static public final VoidMaker THE_ONE = new VoidMaker();
 
@@ -47,6 +47,16 @@
      */
     public Object coerce(Object specimen, OneArgFunc optEjector) {
         return null;
+    }
+
+    /**
+     * Used in a void's almost useless role as a SlotGuard.
+     * <p>
+     * In SlotGuard position, ":void" is equivalent to ":settable(void)".
+     */
+    public Slot makeSlot(Object specimen, OneArgFunc optEjector) {
+        SettableSlotMaker settable = SettableSlotMaker.THE_ONE;
+        return settable.run(this).makeSlot(specimen, optEjector);
     }
 
     /**



1.19      +1 -1      e/src/jsrc/org/erights/e/elib/tables/Column.java

Index: Column.java
===================================================================
RCS file: /cvs/e/src/jsrc/org/erights/e/elib/tables/Column.java,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -r1.18 -r1.19
--- Column.java	2001/12/02 06:01:47	1.18
+++ Column.java	2001/12/16 10:10:29	1.19
@@ -103,7 +103,7 @@
 
         memberType = EList.scalarize(memberType);
 
-        if (memberType == Void.TYPE) {
+        if (memberType == Void.class) {
             return new VoidColumn(capacity);
 
         } else if (memberType == Integer.TYPE) {



1.5       +2 -2      e/src/jsrc/org/erights/e/elib/tables/CycleBreaker.java

Index: CycleBreaker.java
===================================================================
RCS file: /cvs/e/src/jsrc/org/erights/e/elib/tables/CycleBreaker.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- CycleBreaker.java	2001/11/10 19:40:48	1.4
+++ CycleBreaker.java	2001/12/16 10:10:29	1.5
@@ -17,8 +17,8 @@
      *
      */
     public CycleBreaker() {
-        myIdMap = new IdentityMap(Object.class, Void.TYPE);
-        myFlexMap = new FlexMapImpl(Object.class, Void.TYPE);
+        myIdMap = new IdentityMap(Object.class, Void.class);
+        myFlexMap = new FlexMapImpl(Object.class, Void.class);
     }
 
 



1.34      +2 -2      e/src/jsrc/org/erights/e/elib/tables/EList.java

Index: EList.java
===================================================================
RCS file: /cvs/e/src/jsrc/org/erights/e/elib/tables/EList.java,v
retrieving revision 1.33
retrieving revision 1.34
diff -u -r1.33 -r1.34
--- EList.java	2001/12/02 06:01:47	1.33
+++ EList.java	2001/12/16 10:10:29	1.34
@@ -180,7 +180,7 @@
             Array.set(array, index, val);
         } catch (IllegalArgumentException iae) {
             Class type = array.getClass().getComponentType();
-            if ((Void.class == type || Void.TYPE == type) && null == val) {
+            if (Void.class == type && null == val) {
                 return;
             }
             val = E.as(val, type);
@@ -188,7 +188,7 @@
                 Array.set(array, index, val);
             } catch (IllegalArgumentException iae2) {
                 throw new NestedException(
-                  E.toString(val) + " doesn't fit in array of " + type,
+                  E.toQuote(val) + " doesn't fit in array of " + type,
                   iae2);
             }
         }



1.4       +1 -1      e/src/jsrc/org/erights/e/elib/tables/ESet.java

Index: ESet.java
===================================================================
RCS file: /cvs/e/src/jsrc/org/erights/e/elib/tables/ESet.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- ESet.java	2001/12/02 06:01:47	1.3
+++ ESet.java	2001/12/16 10:10:29	1.4
@@ -75,7 +75,7 @@
      * The new set is constrained to only hold object of type 'type'.
      */
     public FlexSet diverge(Class type) {
-        return FlexSet.make(myMap.diverge(type, Void.TYPE));
+        return FlexSet.make(myMap.diverge(type, Void.class));
     }
 
     /**



1.31      +1 -1      e/src/jsrc/org/erights/e/elib/tables/Equalizer.java

Index: Equalizer.java
===================================================================
RCS file: /cvs/e/src/jsrc/org/erights/e/elib/tables/Equalizer.java,v
retrieving revision 1.30
retrieving revision 1.31
diff -u -r1.30 -r1.31
--- Equalizer.java	2001/11/11 17:51:14	1.30
+++ Equalizer.java	2001/12/16 10:10:29	1.31
@@ -272,7 +272,7 @@
      * @see org.erights.e.elib.ref.Ref#isSettled(Object)
      */
     static public boolean isSettled(Object obj) {
-        IdentityMap sofar = new IdentityMap(Object.class, Void.TYPE);
+        IdentityMap sofar = new IdentityMap(Object.class, Void.class);
         return isSettled(obj, sofar);
     }
 



1.4       +2 -2      e/src/jsrc/org/erights/e/elib/tables/FlexSet.java

Index: FlexSet.java
===================================================================
RCS file: /cvs/e/src/jsrc/org/erights/e/elib/tables/FlexSet.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- FlexSet.java	2001/12/02 06:01:47	1.3
+++ FlexSet.java	2001/12/16 10:10:29	1.4
@@ -29,14 +29,14 @@
      *
      */
     static public FlexSet fromType(Class type) {
-        return new FlexSet(FlexMap.fromTypes(type, Void.TYPE));
+        return new FlexSet(FlexMap.fromTypes(type, Void.class));
     }
 
     /**
      *
      */
     static public FlexSet fromType(Class type, int capacity) {
-        return new FlexSet(FlexMap.fromTypes(type, Void.TYPE, capacity));
+        return new FlexSet(FlexMap.fromTypes(type, Void.class, capacity));
     }
 
     /**



1.14      +1 -1      e/src/jsrc/org/erights/e/elib/tables/VoidColumn.java

Index: VoidColumn.java
===================================================================
RCS file: /cvs/e/src/jsrc/org/erights/e/elib/tables/VoidColumn.java,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -r1.13 -r1.14
--- VoidColumn.java	2001/12/02 06:01:47	1.13
+++ VoidColumn.java	2001/12/16 10:10:29	1.14
@@ -60,7 +60,7 @@
      */
     /*package*/
     Class memberType() {
-        return Void.TYPE;
+        return Void.class;
     }
 
     /**



1.25      +1 -1      e/src/jsrc/org/erights/e/ui/jed/EditGroup.java

Index: EditGroup.java
===================================================================
RCS file: /cvs/e/src/jsrc/org/erights/e/ui/jed/EditGroup.java,v
retrieving revision 1.24
retrieving revision 1.25
diff -u -r1.24 -r1.25
--- EditGroup.java	2001/12/02 06:01:50	1.24
+++ EditGroup.java	2001/12/16 10:10:30	1.25
@@ -38,7 +38,7 @@
 
     static private boolean WasInitCalled = false;
 
-    private FlexMap myJeds = FlexMap.fromTypes(JedMain.class, Void.TYPE);
+    private FlexMap myJeds = FlexMap.fromTypes(JedMain.class, Void.class);
 
     private String myOptPattern = null;