NameSpace.st
author Claus Gittinger <cg@exept.de>
Thu, 02 Jan 1997 18:47:18 +0100
changeset 2025 9ab95f23af33
parent 2024 71a088db4583
child 2030 94800ed9cdc5
permissions -rw-r--r--
*** empty log message ***
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1827
fa0017393e3b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1816
diff changeset
     1
"
fa0017393e3b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1816
diff changeset
     2
 COPYRIGHT (c) 1996 by Claus Gittinger
fa0017393e3b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1816
diff changeset
     3
              All Rights Reserved
fa0017393e3b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1816
diff changeset
     4
fa0017393e3b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1816
diff changeset
     5
 This software is furnished under a license and may be used
fa0017393e3b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1816
diff changeset
     6
 only in accordance with the terms of that license and with the
fa0017393e3b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1816
diff changeset
     7
 inclusion of the above copyright notice.   This software may not
fa0017393e3b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1816
diff changeset
     8
 be provided or otherwise made available to, or used by, any
fa0017393e3b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1816
diff changeset
     9
 other person.  No title to or ownership of the software is
fa0017393e3b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1816
diff changeset
    10
 hereby transferred.
fa0017393e3b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1816
diff changeset
    11
"
fa0017393e3b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1816
diff changeset
    12
1943
0ec17e4627ae better displayString & commentary
Claus Gittinger <cg@exept.de>
parents: 1934
diff changeset
    13
1933
74a0bff1ad19 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1931
diff changeset
    14
Object subclass:#Namespace
1943
0ec17e4627ae better displayString & commentary
Claus Gittinger <cg@exept.de>
parents: 1934
diff changeset
    15
	instanceVariableNames:''
0ec17e4627ae better displayString & commentary
Claus Gittinger <cg@exept.de>
parents: 1934
diff changeset
    16
	classVariableNames:''
0ec17e4627ae better displayString & commentary
Claus Gittinger <cg@exept.de>
parents: 1934
diff changeset
    17
	poolDictionaries:''
0ec17e4627ae better displayString & commentary
Claus Gittinger <cg@exept.de>
parents: 1934
diff changeset
    18
	category:'Kernel-Classes'
1933
74a0bff1ad19 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1931
diff changeset
    19
!
1827
fa0017393e3b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1816
diff changeset
    20
fa0017393e3b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1816
diff changeset
    21
!Namespace class methodsFor:'documentation'!
fa0017393e3b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1816
diff changeset
    22
fa0017393e3b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1816
diff changeset
    23
copyright
fa0017393e3b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1816
diff changeset
    24
"
fa0017393e3b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1816
diff changeset
    25
 COPYRIGHT (c) 1996 by Claus Gittinger
fa0017393e3b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1816
diff changeset
    26
              All Rights Reserved
fa0017393e3b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1816
diff changeset
    27
fa0017393e3b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1816
diff changeset
    28
 This software is furnished under a license and may be used
fa0017393e3b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1816
diff changeset
    29
 only in accordance with the terms of that license and with the
fa0017393e3b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1816
diff changeset
    30
 inclusion of the above copyright notice.   This software may not
fa0017393e3b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1816
diff changeset
    31
 be provided or otherwise made available to, or used by, any
fa0017393e3b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1816
diff changeset
    32
 other person.  No title to or ownership of the software is
fa0017393e3b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1816
diff changeset
    33
 hereby transferred.
fa0017393e3b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1816
diff changeset
    34
"
fa0017393e3b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1816
diff changeset
    35
1816
b063c5b47433 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    36
!
b063c5b47433 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    37
1827
fa0017393e3b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1816
diff changeset
    38
documentation
fa0017393e3b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1816
diff changeset
    39
"
fa0017393e3b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1816
diff changeset
    40
    A Namespace is actually a dummy class, providing a home
2010
eaaa38e8bad0 commentary
Claus Gittinger <cg@exept.de>
parents: 2007
diff changeset
    41
    for its private classes. 
eaaa38e8bad0 commentary
Claus Gittinger <cg@exept.de>
parents: 2007
diff changeset
    42
    Thus, internally, the same mechanism is used for classes in
eaaa38e8bad0 commentary
Claus Gittinger <cg@exept.de>
parents: 2007
diff changeset
    43
    a namespace and private classes.
eaaa38e8bad0 commentary
Claus Gittinger <cg@exept.de>
parents: 2007
diff changeset
    44
    This has two advantages:
1828
92e8ede212e7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1827
diff changeset
    45
        - we only need one mechanism for both namespaces
92e8ede212e7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1827
diff changeset
    46
          and private classes
92e8ede212e7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1827
diff changeset
    47
92e8ede212e7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1827
diff changeset
    48
        - there are no possible conflicts between a class
92e8ede212e7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1827
diff changeset
    49
          and a namespace named alike.
92e8ede212e7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1827
diff changeset
    50
1816
b063c5b47433 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    51
1827
fa0017393e3b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1816
diff changeset
    52
    [author:]
fa0017393e3b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1816
diff changeset
    53
        Claus Gittinger
fa0017393e3b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1816
diff changeset
    54
fa0017393e3b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1816
diff changeset
    55
    [see also:]
fa0017393e3b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1816
diff changeset
    56
        Behavior ClassDescription Class Metaclass
fa0017393e3b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1816
diff changeset
    57
        PrivateMetaclass
fa0017393e3b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1816
diff changeset
    58
"
fa0017393e3b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1816
diff changeset
    59
fa0017393e3b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1816
diff changeset
    60
! !
fa0017393e3b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1816
diff changeset
    61
1828
92e8ede212e7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1827
diff changeset
    62
!Namespace class methodsFor:'instance creation'!
92e8ede212e7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1827
diff changeset
    63
1931
5f60d3e5ba6e moved namespace creation completely to Namespace class.
Claus Gittinger <cg@exept.de>
parents: 1908
diff changeset
    64
fullName:aFullNameSpacePathName
2007
57434c08d720 namespace itself is not a namespace
Claus Gittinger <cg@exept.de>
parents: 1943
diff changeset
    65
    "given a possibly nested name of a namespace, create all required
1931
5f60d3e5ba6e moved namespace creation completely to Namespace class.
Claus Gittinger <cg@exept.de>
parents: 1908
diff changeset
    66
     intermediate spaces (if not already existing) and return the
5f60d3e5ba6e moved namespace creation completely to Namespace class.
Claus Gittinger <cg@exept.de>
parents: 1908
diff changeset
    67
     bottom-level space."
5f60d3e5ba6e moved namespace creation completely to Namespace class.
Claus Gittinger <cg@exept.de>
parents: 1908
diff changeset
    68
5f60d3e5ba6e moved namespace creation completely to Namespace class.
Claus Gittinger <cg@exept.de>
parents: 1908
diff changeset
    69
    "/ break it up, check for all intermediate spaces to exist
5f60d3e5ba6e moved namespace creation completely to Namespace class.
Claus Gittinger <cg@exept.de>
parents: 1908
diff changeset
    70
    "/ create them as required.
5f60d3e5ba6e moved namespace creation completely to Namespace class.
Claus Gittinger <cg@exept.de>
parents: 1908
diff changeset
    71
5f60d3e5ba6e moved namespace creation completely to Namespace class.
Claus Gittinger <cg@exept.de>
parents: 1908
diff changeset
    72
    |list idx0 idx superSpace done thisNamespace|
5f60d3e5ba6e moved namespace creation completely to Namespace class.
Claus Gittinger <cg@exept.de>
parents: 1908
diff changeset
    73
5f60d3e5ba6e moved namespace creation completely to Namespace class.
Claus Gittinger <cg@exept.de>
parents: 1908
diff changeset
    74
    list := OrderedCollection new.
5f60d3e5ba6e moved namespace creation completely to Namespace class.
Claus Gittinger <cg@exept.de>
parents: 1908
diff changeset
    75
    idx0 := 1.
5f60d3e5ba6e moved namespace creation completely to Namespace class.
Claus Gittinger <cg@exept.de>
parents: 1908
diff changeset
    76
    done := false.
5f60d3e5ba6e moved namespace creation completely to Namespace class.
Claus Gittinger <cg@exept.de>
parents: 1908
diff changeset
    77
    [done] whileFalse:[
5f60d3e5ba6e moved namespace creation completely to Namespace class.
Claus Gittinger <cg@exept.de>
parents: 1908
diff changeset
    78
        idx := aFullNameSpacePathName indexOf:$: startingAt:idx0.
5f60d3e5ba6e moved namespace creation completely to Namespace class.
Claus Gittinger <cg@exept.de>
parents: 1908
diff changeset
    79
        (idx ~~ 0) ifTrue:[
5f60d3e5ba6e moved namespace creation completely to Namespace class.
Claus Gittinger <cg@exept.de>
parents: 1908
diff changeset
    80
            (idx < aFullNameSpacePathName size and:[(aFullNameSpacePathName at:(idx+1)) == $:]) ifTrue:[
5f60d3e5ba6e moved namespace creation completely to Namespace class.
Claus Gittinger <cg@exept.de>
parents: 1908
diff changeset
    81
                superSpace := aFullNameSpacePathName copyFrom:idx0 to:(idx-1).
5f60d3e5ba6e moved namespace creation completely to Namespace class.
Claus Gittinger <cg@exept.de>
parents: 1908
diff changeset
    82
                list add:superSpace.
5f60d3e5ba6e moved namespace creation completely to Namespace class.
Claus Gittinger <cg@exept.de>
parents: 1908
diff changeset
    83
                idx0 := idx +2.
5f60d3e5ba6e moved namespace creation completely to Namespace class.
Claus Gittinger <cg@exept.de>
parents: 1908
diff changeset
    84
            ] ifFalse:[
5f60d3e5ba6e moved namespace creation completely to Namespace class.
Claus Gittinger <cg@exept.de>
parents: 1908
diff changeset
    85
                done := true
5f60d3e5ba6e moved namespace creation completely to Namespace class.
Claus Gittinger <cg@exept.de>
parents: 1908
diff changeset
    86
            ]
5f60d3e5ba6e moved namespace creation completely to Namespace class.
Claus Gittinger <cg@exept.de>
parents: 1908
diff changeset
    87
        ] ifFalse:[
5f60d3e5ba6e moved namespace creation completely to Namespace class.
Claus Gittinger <cg@exept.de>
parents: 1908
diff changeset
    88
            done := true.
5f60d3e5ba6e moved namespace creation completely to Namespace class.
Claus Gittinger <cg@exept.de>
parents: 1908
diff changeset
    89
        ]
5f60d3e5ba6e moved namespace creation completely to Namespace class.
Claus Gittinger <cg@exept.de>
parents: 1908
diff changeset
    90
    ].
5f60d3e5ba6e moved namespace creation completely to Namespace class.
Claus Gittinger <cg@exept.de>
parents: 1908
diff changeset
    91
    list add:(aFullNameSpacePathName copyFrom:idx0).
5f60d3e5ba6e moved namespace creation completely to Namespace class.
Claus Gittinger <cg@exept.de>
parents: 1908
diff changeset
    92
5f60d3e5ba6e moved namespace creation completely to Namespace class.
Claus Gittinger <cg@exept.de>
parents: 1908
diff changeset
    93
    "/ now, look and create 'em
5f60d3e5ba6e moved namespace creation completely to Namespace class.
Claus Gittinger <cg@exept.de>
parents: 1908
diff changeset
    94
5f60d3e5ba6e moved namespace creation completely to Namespace class.
Claus Gittinger <cg@exept.de>
parents: 1908
diff changeset
    95
    thisNamespace := nil.
5f60d3e5ba6e moved namespace creation completely to Namespace class.
Claus Gittinger <cg@exept.de>
parents: 1908
diff changeset
    96
    list do:[:aName |
5f60d3e5ba6e moved namespace creation completely to Namespace class.
Claus Gittinger <cg@exept.de>
parents: 1908
diff changeset
    97
        |key x|
5f60d3e5ba6e moved namespace creation completely to Namespace class.
Claus Gittinger <cg@exept.de>
parents: 1908
diff changeset
    98
5f60d3e5ba6e moved namespace creation completely to Namespace class.
Claus Gittinger <cg@exept.de>
parents: 1908
diff changeset
    99
        key := aName asSymbol.
5f60d3e5ba6e moved namespace creation completely to Namespace class.
Claus Gittinger <cg@exept.de>
parents: 1908
diff changeset
   100
5f60d3e5ba6e moved namespace creation completely to Namespace class.
Claus Gittinger <cg@exept.de>
parents: 1908
diff changeset
   101
        thisNamespace isNil ifTrue:[
5f60d3e5ba6e moved namespace creation completely to Namespace class.
Claus Gittinger <cg@exept.de>
parents: 1908
diff changeset
   102
            (Smalltalk includesKey:key) ifTrue:[
5f60d3e5ba6e moved namespace creation completely to Namespace class.
Claus Gittinger <cg@exept.de>
parents: 1908
diff changeset
   103
                thisNamespace := Smalltalk at:key.
5f60d3e5ba6e moved namespace creation completely to Namespace class.
Claus Gittinger <cg@exept.de>
parents: 1908
diff changeset
   104
                (thisNamespace notNil
5f60d3e5ba6e moved namespace creation completely to Namespace class.
Claus Gittinger <cg@exept.de>
parents: 1908
diff changeset
   105
                and:[thisNamespace isBehavior not]) ifTrue:[
5f60d3e5ba6e moved namespace creation completely to Namespace class.
Claus Gittinger <cg@exept.de>
parents: 1908
diff changeset
   106
                    ^ self error:'name conflict: namespace ' , aName , ' vs. global'.
5f60d3e5ba6e moved namespace creation completely to Namespace class.
Claus Gittinger <cg@exept.de>
parents: 1908
diff changeset
   107
                ]
5f60d3e5ba6e moved namespace creation completely to Namespace class.
Claus Gittinger <cg@exept.de>
parents: 1908
diff changeset
   108
            ].
5f60d3e5ba6e moved namespace creation completely to Namespace class.
Claus Gittinger <cg@exept.de>
parents: 1908
diff changeset
   109
            thisNamespace isNil ifTrue:[
5f60d3e5ba6e moved namespace creation completely to Namespace class.
Claus Gittinger <cg@exept.de>
parents: 1908
diff changeset
   110
                thisNamespace := self name:key
5f60d3e5ba6e moved namespace creation completely to Namespace class.
Claus Gittinger <cg@exept.de>
parents: 1908
diff changeset
   111
            ]
5f60d3e5ba6e moved namespace creation completely to Namespace class.
Claus Gittinger <cg@exept.de>
parents: 1908
diff changeset
   112
        ] ifFalse:[
5f60d3e5ba6e moved namespace creation completely to Namespace class.
Claus Gittinger <cg@exept.de>
parents: 1908
diff changeset
   113
            x := thisNamespace privateClassesAt:key.
5f60d3e5ba6e moved namespace creation completely to Namespace class.
Claus Gittinger <cg@exept.de>
parents: 1908
diff changeset
   114
            x notNil ifTrue:[
5f60d3e5ba6e moved namespace creation completely to Namespace class.
Claus Gittinger <cg@exept.de>
parents: 1908
diff changeset
   115
                thisNamespace := x
5f60d3e5ba6e moved namespace creation completely to Namespace class.
Claus Gittinger <cg@exept.de>
parents: 1908
diff changeset
   116
            ] ifFalse:[
5f60d3e5ba6e moved namespace creation completely to Namespace class.
Claus Gittinger <cg@exept.de>
parents: 1908
diff changeset
   117
                thisNamespace :=
5f60d3e5ba6e moved namespace creation completely to Namespace class.
Claus Gittinger <cg@exept.de>
parents: 1908
diff changeset
   118
                    self subclass:key
5f60d3e5ba6e moved namespace creation completely to Namespace class.
Claus Gittinger <cg@exept.de>
parents: 1908
diff changeset
   119
                       instanceVariableNames:''
5f60d3e5ba6e moved namespace creation completely to Namespace class.
Claus Gittinger <cg@exept.de>
parents: 1908
diff changeset
   120
                       classVariableNames:''
5f60d3e5ba6e moved namespace creation completely to Namespace class.
Claus Gittinger <cg@exept.de>
parents: 1908
diff changeset
   121
                       poolDictionaries:''
5f60d3e5ba6e moved namespace creation completely to Namespace class.
Claus Gittinger <cg@exept.de>
parents: 1908
diff changeset
   122
                       privateIn:thisNamespace
5f60d3e5ba6e moved namespace creation completely to Namespace class.
Claus Gittinger <cg@exept.de>
parents: 1908
diff changeset
   123
            ]    
5f60d3e5ba6e moved namespace creation completely to Namespace class.
Claus Gittinger <cg@exept.de>
parents: 1908
diff changeset
   124
        ]
5f60d3e5ba6e moved namespace creation completely to Namespace class.
Claus Gittinger <cg@exept.de>
parents: 1908
diff changeset
   125
    ].
5f60d3e5ba6e moved namespace creation completely to Namespace class.
Claus Gittinger <cg@exept.de>
parents: 1908
diff changeset
   126
5f60d3e5ba6e moved namespace creation completely to Namespace class.
Claus Gittinger <cg@exept.de>
parents: 1908
diff changeset
   127
    ^ thisNamespace
5f60d3e5ba6e moved namespace creation completely to Namespace class.
Claus Gittinger <cg@exept.de>
parents: 1908
diff changeset
   128
5f60d3e5ba6e moved namespace creation completely to Namespace class.
Claus Gittinger <cg@exept.de>
parents: 1908
diff changeset
   129
    "Created: 8.11.1996 / 13:41:59 / cg"
2007
57434c08d720 namespace itself is not a namespace
Claus Gittinger <cg@exept.de>
parents: 1943
diff changeset
   130
    "Modified: 20.12.1996 / 15:17:07 / cg"
1931
5f60d3e5ba6e moved namespace creation completely to Namespace class.
Claus Gittinger <cg@exept.de>
parents: 1908
diff changeset
   131
!
5f60d3e5ba6e moved namespace creation completely to Namespace class.
Claus Gittinger <cg@exept.de>
parents: 1908
diff changeset
   132
2007
57434c08d720 namespace itself is not a namespace
Claus Gittinger <cg@exept.de>
parents: 1943
diff changeset
   133
name:aStringOrSymbol
57434c08d720 namespace itself is not a namespace
Claus Gittinger <cg@exept.de>
parents: 1943
diff changeset
   134
    "create a new nameSpace, named aStringOrSymbol"
1908
aff3d44e4399 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1901
diff changeset
   135
2024
71a088db4583 validate nameSpaces name for being a valid identifier.
Claus Gittinger <cg@exept.de>
parents: 2015
diff changeset
   136
    |newNamespace existing ok|
1828
92e8ede212e7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1827
diff changeset
   137
2024
71a088db4583 validate nameSpaces name for being a valid identifier.
Claus Gittinger <cg@exept.de>
parents: 2015
diff changeset
   138
    ok := aStringOrSymbol first isLetter.
71a088db4583 validate nameSpaces name for being a valid identifier.
Claus Gittinger <cg@exept.de>
parents: 2015
diff changeset
   139
    ok ifTrue:[
71a088db4583 validate nameSpaces name for being a valid identifier.
Claus Gittinger <cg@exept.de>
parents: 2015
diff changeset
   140
        2 to:aStringOrSymbol size do:[:idx | |ch|
71a088db4583 validate nameSpaces name for being a valid identifier.
Claus Gittinger <cg@exept.de>
parents: 2015
diff changeset
   141
            ch := aStringOrSymbol at:idx.
71a088db4583 validate nameSpaces name for being a valid identifier.
Claus Gittinger <cg@exept.de>
parents: 2015
diff changeset
   142
            ok ifTrue:[
71a088db4583 validate nameSpaces name for being a valid identifier.
Claus Gittinger <cg@exept.de>
parents: 2015
diff changeset
   143
                ok := ch isLetterOrDigit or:[ch == $_].
71a088db4583 validate nameSpaces name for being a valid identifier.
Claus Gittinger <cg@exept.de>
parents: 2015
diff changeset
   144
            ]
71a088db4583 validate nameSpaces name for being a valid identifier.
Claus Gittinger <cg@exept.de>
parents: 2015
diff changeset
   145
        ]
71a088db4583 validate nameSpaces name for being a valid identifier.
Claus Gittinger <cg@exept.de>
parents: 2015
diff changeset
   146
    ].
71a088db4583 validate nameSpaces name for being a valid identifier.
Claus Gittinger <cg@exept.de>
parents: 2015
diff changeset
   147
71a088db4583 validate nameSpaces name for being a valid identifier.
Claus Gittinger <cg@exept.de>
parents: 2015
diff changeset
   148
    ok ifFalse:[
2025
9ab95f23af33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2024
diff changeset
   149
        self error:'invalid namespace name:''' , aStringOrSymbol printString , ''' (must be a valid identifier)'.
1931
5f60d3e5ba6e moved namespace creation completely to Namespace class.
Claus Gittinger <cg@exept.de>
parents: 1908
diff changeset
   150
        ^ nil.
5f60d3e5ba6e moved namespace creation completely to Namespace class.
Claus Gittinger <cg@exept.de>
parents: 1908
diff changeset
   151
    ].
5f60d3e5ba6e moved namespace creation completely to Namespace class.
Claus Gittinger <cg@exept.de>
parents: 1908
diff changeset
   152
2015
7e6375a8e0f2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2010
diff changeset
   153
    (existing := Smalltalk at:aStringOrSymbol asSymbol) notNil ifTrue:[
7e6375a8e0f2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2010
diff changeset
   154
        ^ existing
7e6375a8e0f2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2010
diff changeset
   155
    ].
7e6375a8e0f2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2010
diff changeset
   156
2007
57434c08d720 namespace itself is not a namespace
Claus Gittinger <cg@exept.de>
parents: 1943
diff changeset
   157
    newNamespace := self subclass:aStringOrSymbol asSymbol
1931
5f60d3e5ba6e moved namespace creation completely to Namespace class.
Claus Gittinger <cg@exept.de>
parents: 1908
diff changeset
   158
                         instanceVariableNames:''
5f60d3e5ba6e moved namespace creation completely to Namespace class.
Claus Gittinger <cg@exept.de>
parents: 1908
diff changeset
   159
                         classVariableNames:''
5f60d3e5ba6e moved namespace creation completely to Namespace class.
Claus Gittinger <cg@exept.de>
parents: 1908
diff changeset
   160
                         poolDictionaries:''
5f60d3e5ba6e moved namespace creation completely to Namespace class.
Claus Gittinger <cg@exept.de>
parents: 1908
diff changeset
   161
                         category:'uncategorized namespace'.
1908
aff3d44e4399 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1901
diff changeset
   162
1828
92e8ede212e7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1827
diff changeset
   163
    ^ newNamespace
1901
8eebbd3c7232 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   164
8eebbd3c7232 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   165
    "
8eebbd3c7232 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   166
     Namespace name:'foo'
8eebbd3c7232 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   167
     (Namespace name:'foo') category:'my name space'
2007
57434c08d720 namespace itself is not a namespace
Claus Gittinger <cg@exept.de>
parents: 1943
diff changeset
   168
     foo at:#bar put:(Metaclass new new)
1901
8eebbd3c7232 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1828
diff changeset
   169
    "
1931
5f60d3e5ba6e moved namespace creation completely to Namespace class.
Claus Gittinger <cg@exept.de>
parents: 1908
diff changeset
   170
2024
71a088db4583 validate nameSpaces name for being a valid identifier.
Claus Gittinger <cg@exept.de>
parents: 2015
diff changeset
   171
    "Modified: 2.1.1997 / 18:41:22 / cg"
1828
92e8ede212e7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1827
diff changeset
   172
!
92e8ede212e7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1827
diff changeset
   173
92e8ede212e7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1827
diff changeset
   174
new
1943
0ec17e4627ae better displayString & commentary
Claus Gittinger <cg@exept.de>
parents: 1934
diff changeset
   175
    "catch new - namespaces are not to be created by the user"
0ec17e4627ae better displayString & commentary
Claus Gittinger <cg@exept.de>
parents: 1934
diff changeset
   176
1828
92e8ede212e7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1827
diff changeset
   177
    self error:'namespaces are not to be created with new'
1943
0ec17e4627ae better displayString & commentary
Claus Gittinger <cg@exept.de>
parents: 1934
diff changeset
   178
0ec17e4627ae better displayString & commentary
Claus Gittinger <cg@exept.de>
parents: 1934
diff changeset
   179
    "Modified: 8.11.1996 / 21:38:00 / cg"
1828
92e8ede212e7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1827
diff changeset
   180
! !
92e8ede212e7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1827
diff changeset
   181
1908
aff3d44e4399 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1901
diff changeset
   182
!Namespace class methodsFor:'accessing'!
1827
fa0017393e3b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1816
diff changeset
   183
2007
57434c08d720 namespace itself is not a namespace
Claus Gittinger <cg@exept.de>
parents: 1943
diff changeset
   184
allClasses
57434c08d720 namespace itself is not a namespace
Claus Gittinger <cg@exept.de>
parents: 1943
diff changeset
   185
    |classes|
57434c08d720 namespace itself is not a namespace
Claus Gittinger <cg@exept.de>
parents: 1943
diff changeset
   186
57434c08d720 namespace itself is not a namespace
Claus Gittinger <cg@exept.de>
parents: 1943
diff changeset
   187
    classes := IdentitySet new.
57434c08d720 namespace itself is not a namespace
Claus Gittinger <cg@exept.de>
parents: 1943
diff changeset
   188
    self allBehaviorsDo:[:aClass | classes add:aClass].
57434c08d720 namespace itself is not a namespace
Claus Gittinger <cg@exept.de>
parents: 1943
diff changeset
   189
    ^ classes
57434c08d720 namespace itself is not a namespace
Claus Gittinger <cg@exept.de>
parents: 1943
diff changeset
   190
57434c08d720 namespace itself is not a namespace
Claus Gittinger <cg@exept.de>
parents: 1943
diff changeset
   191
    "Modified: 20.12.1996 / 15:34:50 / cg"
57434c08d720 namespace itself is not a namespace
Claus Gittinger <cg@exept.de>
parents: 1943
diff changeset
   192
!
57434c08d720 namespace itself is not a namespace
Claus Gittinger <cg@exept.de>
parents: 1943
diff changeset
   193
1827
fa0017393e3b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1816
diff changeset
   194
at:classNameSymbol
1943
0ec17e4627ae better displayString & commentary
Claus Gittinger <cg@exept.de>
parents: 1934
diff changeset
   195
    "return a class from the namespace defined by the receiver"
0ec17e4627ae better displayString & commentary
Claus Gittinger <cg@exept.de>
parents: 1934
diff changeset
   196
1828
92e8ede212e7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1827
diff changeset
   197
    ^ self privateClassesAt:classNameSymbol
1943
0ec17e4627ae better displayString & commentary
Claus Gittinger <cg@exept.de>
parents: 1934
diff changeset
   198
0ec17e4627ae better displayString & commentary
Claus Gittinger <cg@exept.de>
parents: 1934
diff changeset
   199
    "Modified: 8.11.1996 / 21:39:41 / cg"
1827
fa0017393e3b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1816
diff changeset
   200
!
fa0017393e3b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1816
diff changeset
   201
fa0017393e3b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1816
diff changeset
   202
at:classNameSymbol ifAbsent:exceptionBlock
1943
0ec17e4627ae better displayString & commentary
Claus Gittinger <cg@exept.de>
parents: 1934
diff changeset
   203
    "return a class or an alternative
0ec17e4627ae better displayString & commentary
Claus Gittinger <cg@exept.de>
parents: 1934
diff changeset
   204
     from the namespace defined by the receiver"
0ec17e4627ae better displayString & commentary
Claus Gittinger <cg@exept.de>
parents: 1934
diff changeset
   205
1827
fa0017393e3b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1816
diff changeset
   206
    |cls|
fa0017393e3b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1816
diff changeset
   207
1828
92e8ede212e7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1827
diff changeset
   208
    cls := self privateClassesAt:classNameSymbol.
1827
fa0017393e3b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1816
diff changeset
   209
    cls isNil ifTrue:[
fa0017393e3b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1816
diff changeset
   210
        ^ exceptionBlock value
fa0017393e3b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1816
diff changeset
   211
    ].
fa0017393e3b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1816
diff changeset
   212
    ^ cls
1943
0ec17e4627ae better displayString & commentary
Claus Gittinger <cg@exept.de>
parents: 1934
diff changeset
   213
0ec17e4627ae better displayString & commentary
Claus Gittinger <cg@exept.de>
parents: 1934
diff changeset
   214
    "Modified: 8.11.1996 / 21:40:01 / cg"
1827
fa0017393e3b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1816
diff changeset
   215
!
fa0017393e3b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1816
diff changeset
   216
fa0017393e3b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1816
diff changeset
   217
at:classNameSymbol put:aClass
1943
0ec17e4627ae better displayString & commentary
Claus Gittinger <cg@exept.de>
parents: 1934
diff changeset
   218
    "add a class to the namespace defined by the receiver"
0ec17e4627ae better displayString & commentary
Claus Gittinger <cg@exept.de>
parents: 1934
diff changeset
   219
1828
92e8ede212e7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1827
diff changeset
   220
    ^ self privateClassesAt:classNameSymbol put:aClass
1943
0ec17e4627ae better displayString & commentary
Claus Gittinger <cg@exept.de>
parents: 1934
diff changeset
   221
0ec17e4627ae better displayString & commentary
Claus Gittinger <cg@exept.de>
parents: 1934
diff changeset
   222
    "Modified: 8.11.1996 / 21:40:12 / cg"
1827
fa0017393e3b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1816
diff changeset
   223
! !
fa0017393e3b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1816
diff changeset
   224
1908
aff3d44e4399 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1901
diff changeset
   225
!Namespace class methodsFor:'enumerating'!
1816
b063c5b47433 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   226
b063c5b47433 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   227
allBehaviorsDo:aBlock
1943
0ec17e4627ae better displayString & commentary
Claus Gittinger <cg@exept.de>
parents: 1934
diff changeset
   228
    "enumerate all classes in this namespace"
0ec17e4627ae better displayString & commentary
Claus Gittinger <cg@exept.de>
parents: 1934
diff changeset
   229
1828
92e8ede212e7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1827
diff changeset
   230
    self privateClassesDo:aBlock
1816
b063c5b47433 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   231
b063c5b47433 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   232
    "Created: 26.10.1996 / 12:29:01 / cg"
1943
0ec17e4627ae better displayString & commentary
Claus Gittinger <cg@exept.de>
parents: 1934
diff changeset
   233
    "Modified: 8.11.1996 / 21:39:20 / cg"
1816
b063c5b47433 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   234
! !
b063c5b47433 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   235
1908
aff3d44e4399 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1901
diff changeset
   236
!Namespace class methodsFor:'fileOut'!
1828
92e8ede212e7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1827
diff changeset
   237
92e8ede212e7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1827
diff changeset
   238
basicFileOutDefinitionOn:aStream
1943
0ec17e4627ae better displayString & commentary
Claus Gittinger <cg@exept.de>
parents: 1934
diff changeset
   239
    "redefined to generate another definition message"
0ec17e4627ae better displayString & commentary
Claus Gittinger <cg@exept.de>
parents: 1934
diff changeset
   240
1934
f21f70387dc4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1933
diff changeset
   241
    self == Namespace ifTrue:[
1943
0ec17e4627ae better displayString & commentary
Claus Gittinger <cg@exept.de>
parents: 1934
diff changeset
   242
        super basicFileOutDefinitionOn:aStream
1934
f21f70387dc4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1933
diff changeset
   243
    ] ifFalse:[
f21f70387dc4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1933
diff changeset
   244
        aStream nextPutAll:('Namespace name:' , self name storeString)
f21f70387dc4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1933
diff changeset
   245
    ]
1943
0ec17e4627ae better displayString & commentary
Claus Gittinger <cg@exept.de>
parents: 1934
diff changeset
   246
0ec17e4627ae better displayString & commentary
Claus Gittinger <cg@exept.de>
parents: 1934
diff changeset
   247
    "Modified: 8.11.1996 / 21:39:03 / cg"
0ec17e4627ae better displayString & commentary
Claus Gittinger <cg@exept.de>
parents: 1934
diff changeset
   248
! !
0ec17e4627ae better displayString & commentary
Claus Gittinger <cg@exept.de>
parents: 1934
diff changeset
   249
0ec17e4627ae better displayString & commentary
Claus Gittinger <cg@exept.de>
parents: 1934
diff changeset
   250
!Namespace class methodsFor:'printing & storing'!
0ec17e4627ae better displayString & commentary
Claus Gittinger <cg@exept.de>
parents: 1934
diff changeset
   251
0ec17e4627ae better displayString & commentary
Claus Gittinger <cg@exept.de>
parents: 1934
diff changeset
   252
displayString
0ec17e4627ae better displayString & commentary
Claus Gittinger <cg@exept.de>
parents: 1934
diff changeset
   253
    "return a printed represenation - here, a reminder is appended,
0ec17e4627ae better displayString & commentary
Claus Gittinger <cg@exept.de>
parents: 1934
diff changeset
   254
     that this is not a regular class"
0ec17e4627ae better displayString & commentary
Claus Gittinger <cg@exept.de>
parents: 1934
diff changeset
   255
2007
57434c08d720 namespace itself is not a namespace
Claus Gittinger <cg@exept.de>
parents: 1943
diff changeset
   256
    self == Namespace ifTrue:[
57434c08d720 namespace itself is not a namespace
Claus Gittinger <cg@exept.de>
parents: 1943
diff changeset
   257
        ^ super displayString
57434c08d720 namespace itself is not a namespace
Claus Gittinger <cg@exept.de>
parents: 1943
diff changeset
   258
    ].
1943
0ec17e4627ae better displayString & commentary
Claus Gittinger <cg@exept.de>
parents: 1934
diff changeset
   259
    ^ self name , ' (* namespace *)'
0ec17e4627ae better displayString & commentary
Claus Gittinger <cg@exept.de>
parents: 1934
diff changeset
   260
0ec17e4627ae better displayString & commentary
Claus Gittinger <cg@exept.de>
parents: 1934
diff changeset
   261
    "Created: 8.11.1996 / 21:37:24 / cg"
2007
57434c08d720 namespace itself is not a namespace
Claus Gittinger <cg@exept.de>
parents: 1943
diff changeset
   262
    "Modified: 20.12.1996 / 15:11:31 / cg"
1828
92e8ede212e7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1827
diff changeset
   263
! !
92e8ede212e7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1827
diff changeset
   264
1908
aff3d44e4399 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1901
diff changeset
   265
!Namespace class methodsFor:'queries'!
1816
b063c5b47433 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   266
b063c5b47433 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   267
isNamespace
1943
0ec17e4627ae better displayString & commentary
Claus Gittinger <cg@exept.de>
parents: 1934
diff changeset
   268
    "return true - I am a namespace"
0ec17e4627ae better displayString & commentary
Claus Gittinger <cg@exept.de>
parents: 1934
diff changeset
   269
2007
57434c08d720 namespace itself is not a namespace
Claus Gittinger <cg@exept.de>
parents: 1943
diff changeset
   270
    self == Namespace ifTrue:[^ false].
1816
b063c5b47433 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   271
    ^ true
b063c5b47433 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   272
b063c5b47433 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   273
    "Created: 26.10.1996 / 11:13:36 / cg"
2007
57434c08d720 namespace itself is not a namespace
Claus Gittinger <cg@exept.de>
parents: 1943
diff changeset
   274
    "Modified: 20.12.1996 / 15:11:45 / cg"
1816
b063c5b47433 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   275
! !
b063c5b47433 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   276
b063c5b47433 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   277
!Namespace class methodsFor:'documentation'!
b063c5b47433 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   278
b063c5b47433 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   279
version
2025
9ab95f23af33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2024
diff changeset
   280
    ^ '$Header: /cvs/stx/stx/libbasic/NameSpace.st,v 1.14 1997-01-02 17:47:18 cg Exp $'
1816
b063c5b47433 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   281
! !