[svn] r6391: nemerle/trunk: lib/hashtable.n ncc/completion/CodeCompletionEngine.n

VladD2 svnadmin at nemerle.org
Mon Jun 12 02:42:40 CEST 2006


Log:
Move Hierarchy initialization (prevent NulReferenceException). 


Author: VladD2
Date: Mon Jun 12 02:42:38 2006
New Revision: 6391

Modified:
   nemerle/trunk/lib/hashtable.n
   nemerle/trunk/ncc/completion/CodeCompletionEngine.n

Modified: nemerle/trunk/lib/hashtable.n
==============================================================================
--- nemerle/trunk/lib/hashtable.n	(original)
+++ nemerle/trunk/lib/hashtable.n	Mon Jun 12 02:42:38 2006
@@ -112,9 +112,13 @@
       if (TryGetValue (key, out value))
         (value, true)
       else
-        (Nemerle.Extensions.DefaultValue ('b), false)
+        (value, false)
     }
 
+    /**
+     * Returns value associated with the specified key or default value (null for 
+     * referece type and result of parameterless constractor for value type).
+     */
     public GetValueOrDefault (key : 'a) : 'b
     {
       mutable value;
@@ -124,6 +128,9 @@
       value
     }    
     
+    /**
+     * Returns value associated with the specified key or defaultValue.
+     */
     public GetValueOrDefault (key : 'a, defaultValue : 'b) : 'b
     {
       mutable value;
@@ -135,6 +142,45 @@
     }
     
     /**
+     * Returns value associated with the specified key or result of call getDefaultValue().
+     * The getDefaultValue() called only if key not exists in collection.
+     */
+    public GetValueOrDefault (key : 'a, getDefaultValue : void -> 'b) : 'b
+    {
+      mutable value;
+      
+      if (TryGetValue (key, out value))
+        value
+      else
+        getDefaultValue()
+    }
+    
+    /**
+     * Returns value associated with the specified key or new value.
+     * The new value obtain by call getNewValue(). The new value add 
+     * to collection before return to caller.
+     * The getNewValue() called only if key not exists in collection.
+     * Example:
+     * def map = Hashtable();
+     * Console.WriteLine(map.GetValue("1", () => 1)); // Write "1"
+     * Console.WriteLine(map.GetValue("1", () => 2)); // Write "1"
+     * Console.WriteLine(map["1"]);                   // Write "1"
+     */
+    public GetValue (key : 'a, getNewValue : void -> 'b) : 'b
+    {
+      mutable value;
+      
+      if (TryGetValue (key, out value))
+        value
+      else
+      {
+        value = getNewValue();
+        Add(key, value);
+        value
+      }
+    }
+    
+    /**
      * This is different from add, which can fail if the key is
      * already in the underlying Framework hashtable.
      */

Modified: nemerle/trunk/ncc/completion/CodeCompletionEngine.n
==============================================================================
--- nemerle/trunk/ncc/completion/CodeCompletionEngine.n	(original)
+++ nemerle/trunk/ncc/completion/CodeCompletionEngine.n	Mon Jun 12 02:42:38 2006
@@ -418,6 +418,9 @@
         
             // lexing of the NotParsed files
             // we save the parsed files to improve performance
+
+            this.Hierarchy = TypesManager (this);
+    
             mutable trees = [];
             try
             {
@@ -446,8 +449,6 @@
                   {}
             }
              
-            this.Hierarchy = TypesManager (this);
-    
             // create N.C.TypeBuilders for all parsed types and add them to namespace hierarchy
             try
             {



More information about the svn mailing list