lib : Add class name support
[nit.git] / lib / standard / string.nit
index 791be80..bcd0445 100644 (file)
@@ -22,7 +22,7 @@ import hash
 ###############################################################################
 
 abstract class AbstractString
-special AbstractArrayRead[Char]
+       super AbstractArrayRead[Char]
        readable private var _items: NativeString
 
        redef fun [](index) do return _items[index]
@@ -160,8 +160,8 @@ end
 
 
 class String
-special Comparable
-special AbstractString
+       super Comparable
+       super AbstractString
        redef type OTHER: String
 
        # Create a new string from a given char *.
@@ -265,10 +265,10 @@ end
 
 # Strings are arrays of characters.
 class Buffer
-special AbstractString
-special Comparable
-special StringCapable
-special AbstractArray[Char]
+       super AbstractString
+       super Comparable
+       super StringCapable
+       super AbstractArray[Char]
 
        redef type OTHER: String
 
@@ -398,23 +398,28 @@ redef class Object
        # User redeable representation of `self'.
        fun to_s: String do return inspect
 
+       # The class name of the object in NativeString format.
+       private fun native_class_name: NativeString is intern
+
+       # The class name of the object.
+       # FIXME: real type information is not available at runtime. Therefore, for instance, an instance of List[Bool] has just "List" for classname
+       fun class_name: String do return new String.from_cstring(native_class_name)
+
        # Developper readable representation of `self'.
        # Usualy, it uses the form "<CLASSNAME:#OBJECTID bla bla bla>"
        fun inspect: String
        do
-               var r = inspect_head
-               # r.add('>')
-               return r
+               return "<{inspect_head}>"
        end
 
-       # Return "<CLASSNAME:#OBJECTID".
-       # This fuction is mainly used with the redefinition of the inspect(0) method
+       # Return "CLASSNAME:#OBJECTID".
+       # This fuction is mainly used with the redefinition of the inspect method
        protected fun inspect_head: String
        do
-               return "<{object_id.to_hex}"
+               return "{class_name}:#{object_id.to_hex}"
        end
 
-       protected fun args: IndexedCollection[String]
+       protected fun args: Sequence[String]
        do
                return sys.args
        end
@@ -602,9 +607,9 @@ class StringCapable
 end
 
 redef class Sys
-       var _args_cache: nullable IndexedCollection[String]
+       var _args_cache: nullable Sequence[String]
 
-       redef fun args: IndexedCollection[String]
+       redef fun args: Sequence[String]
        do
                if _args_cache == null then init_args
                return _args_cache.as(not null)