Class.st
changeset 6077 d777721e42c8
parent 6023 63f7111fd2f9
child 6097 276766efb318
equal deleted inserted replaced
6076:2f75076b5597 6077:d777721e42c8
  1175     self wasAutoloaded ifFalse:[
  1175     self wasAutoloaded ifFalse:[
  1176         "
  1176         "
  1177          can it be done ?
  1177          can it be done ?
  1178          (all of my methods must have a source)
  1178          (all of my methods must have a source)
  1179         "
  1179         "
  1180         self allSelectorsAndMethodsDo:[:sel :aMethod |
  1180         self instAndClassSelectorsAndMethodsDo:[:sel :aMethod |
  1181             aMethod source isNil ifTrue:[^false].
  1181             aMethod source isNil ifTrue:[^false].
  1182             aMethod hasPrimitiveCode ifTrue:[^ false].
  1182             aMethod hasPrimitiveCode ifTrue:[^ false].
  1183         ].
  1183         ].
  1184     ].
  1184     ].
  1185 
  1185 
  1399     owner notNil ifTrue:[
  1399     owner notNil ifTrue:[
  1400         newClass setCategory:nil.
  1400         newClass setCategory:nil.
  1401     ] ifFalse:[
  1401     ] ifFalse:[
  1402         newClass setPackage:package.
  1402         newClass setPackage:package.
  1403     ].
  1403     ].
  1404     newClass allSelectorsAndMethodsDo:[:sel :mthd | mthd setPackage:package].
  1404     newClass instAndClassSelectorsAndMethodsDo:[:sel :mthd | mthd setPackage:package].
  1405 
  1405 
  1406     newClass methodDictionary:methods.
  1406     newClass methodDictionary:methods.
  1407     newClass class methodDictionary:cmethods.
  1407     newClass class methodDictionary:cmethods.
  1408 
  1408 
  1409     newClass initializeWithAllPrivateClasses.
  1409     newClass initializeWithAllPrivateClasses.
  1911 !
  1911 !
  1912 
  1912 
  1913 basicFileOutDefinitionOn:aStream withNameSpace:forceNameSpace withPackage:showPackage
  1913 basicFileOutDefinitionOn:aStream withNameSpace:forceNameSpace withPackage:showPackage
  1914     "append an expression on aStream, which defines myself."
  1914     "append an expression on aStream, which defines myself."
  1915 
  1915 
  1916     |s owner ns nsName fullName superName cls topOwner
  1916     |s owner ns nsName fullName superNameWithoutNameSpacePrefix cls topOwner
  1917      syntaxHilighting|
  1917      syntaxHilighting superclassNamespace|
  1918 
  1918 
  1919     UserPreferences isNil ifTrue:[
  1919     UserPreferences isNil ifTrue:[
  1920         syntaxHilighting := false
  1920         syntaxHilighting := false
  1921     ] ifFalse:[
  1921     ] ifFalse:[
  1922         syntaxHilighting := UserPreferences current syntaxColoring.
  1922         syntaxHilighting := UserPreferences current syntaxColoring.
  1923     ].
  1923     ].
  1924 
  1924 
       
  1925     fullName := FileOutNameSpaceQuerySignal query == true.
       
  1926 
  1925     owner := self owningClass.
  1927     owner := self owningClass.
  1926 
       
  1927     owner isNil ifTrue:[
  1928     owner isNil ifTrue:[
  1928         ns := self nameSpace.
  1929         ns := self nameSpace.
  1929     ] ifFalse:[
  1930     ] ifFalse:[
  1930         ns := self topOwningClass nameSpace
  1931         ns := self topOwningClass nameSpace.
  1931     ].
  1932     ].
  1932     fullName := FileOutNameSpaceQuerySignal query == true.
       
  1933         
  1933         
  1934     (showPackage and:[owner isNil]) ifTrue:[
  1934     (showPackage and:[owner isNil]) ifTrue:[
  1935         aStream nextPutAll:'"{ Package: '''.
  1935         aStream nextPutAll:'"{ Package: '''.
  1936         aStream nextPutAll:self package asString.
  1936         aStream nextPutAll:self package asString.
  1937         aStream nextPutAll:''' }"'; cr; cr.
  1937         aStream nextPutAll:''' }"'; cr; cr.
  1938     ].
  1938     ].
  1939 
  1939 
  1940     ((owner isNil and:[fullName not])
  1940     "/ the backward compatible namespace directive is only used
  1941     or:[owner notNil and:[forceNameSpace and:[fullName not]]]) ifTrue:[
  1941     "/ for non-private classes.
  1942         (ns notNil and:[ns ~~ Smalltalk]) ifTrue:[
  1942     "/ Private classes cannot be filed into another smalltalk anyway,
  1943             nsName := ns name.
  1943     "/ and there is no need to complicate global lookup in stc...
  1944             (nsName includes:$:) ifTrue:[
  1944 
  1945                 nsName := '''' , nsName , ''''
  1945     owner notNil ifTrue:[
  1946             ].
  1946         fullName := true.    
  1947 "/            aStream nextPutLine:'"{ NameSpace: ' , nsName , ' }"'; cr.
  1947     ].
  1948             aStream nextPutAll:'"{ NameSpace: '.
  1948 
  1949             syntaxHilighting ifTrue:[aStream bold].
  1949     fullName ifFalse:[
  1950             aStream nextPutAll:nsName.
  1950         (owner isNil or:[forceNameSpace]) ifTrue:[
  1951             syntaxHilighting ifTrue:[aStream normal].
  1951             (ns notNil and:[ns ~~ Smalltalk]) ifTrue:[
  1952             aStream nextPutAll:' }"'; cr; cr.
  1952                 nsName := ns name.
  1953         ]
  1953                 (nsName includes:$:) ifTrue:[
       
  1954                     nsName := '''' , nsName , ''''
       
  1955                 ].
       
  1956                 aStream nextPutAll:'"{ NameSpace: '.
       
  1957                 syntaxHilighting ifTrue:[aStream bold].
       
  1958                 aStream nextPutAll:nsName.
       
  1959                 syntaxHilighting ifTrue:[aStream normal].
       
  1960                 aStream nextPutAll:' }"'; cr; cr.
       
  1961             ]
       
  1962         ].
  1954     ].
  1963     ].
  1955 
  1964 
  1956     "take care of nil-superclass"
  1965     "take care of nil-superclass"
  1957     superclass isNil ifTrue:[
  1966     superclass isNil ifTrue:[
  1958         s := 'nil'
  1967         s := 'nil'
  1959     ] ifFalse:[
  1968     ] ifFalse:[
       
  1969         superclassNamespace := superclass nameSpace.
       
  1970 
  1960         fullName ifTrue:[
  1971         fullName ifTrue:[
  1961             superclass == owner ifTrue:[
  1972             s := superclass name.
  1962                 s := superclass nameWithoutNameSpacePrefix
  1973 "/            superclass == owner ifTrue:[
  1963             ] ifFalse:[
  1974 "/                s := superclass nameWithoutNameSpacePrefix
  1964                 s := superclass name
  1975 "/            ]
  1965             ]
       
  1966         ] ifFalse:[
  1976         ] ifFalse:[
  1967             (ns == superclass nameSpace 
  1977             (ns == superclassNamespace 
  1968             and:[superclass owningClass isNil]) ifTrue:[
  1978             and:[superclass owningClass isNil]) ifTrue:[
  1969                 "/ superclass is in the same namespace;
  1979                 "/ superclass is in the same namespace;
  1970                 "/ still prepend namespace prefix, to avoid
  1980                 "/ still prepend namespace prefix, to avoid
  1971                 "/ confusing stc, which needs that information ...
  1981                 "/ confusing stc, which needs that information ...
  1972                 s := superclass nameWithoutPrefix
  1982                 s := superclass nameWithoutPrefix
  1974                 "/ a very special (rare) situation:
  1984                 "/ a very special (rare) situation:
  1975                 "/ my superclass resides in another nameSpace,
  1985                 "/ my superclass resides in another nameSpace,
  1976                 "/ but there is something else named like this
  1986                 "/ but there is something else named like this
  1977                 "/ to be found in my nameSpace (or a private class)
  1987                 "/ to be found in my nameSpace (or a private class)
  1978 
  1988 
  1979                 superName := superclass nameWithoutNameSpacePrefix asSymbol.
  1989                 superNameWithoutNameSpacePrefix := superclass nameWithoutNameSpacePrefix asSymbol.
  1980                 cls := self privateClassesAt:superName.
  1990                 cls := self privateClassesAt:superNameWithoutNameSpacePrefix.
  1981                 cls isNil ifTrue:[
  1991                 cls isNil ifTrue:[
  1982                     (topOwner := self topOwningClass) isNil ifTrue:[
  1992                     (topOwner := self topOwningClass) isNil ifTrue:[
  1983                         ns := self nameSpace.
  1993                         ns := self nameSpace.
  1984                         ns notNil ifTrue:[
  1994                         ns notNil ifTrue:[
  1985                             cls := ns privateClassesAt:superName
  1995                             cls := ns privateClassesAt:superNameWithoutNameSpacePrefix
  1986                         ] ifFalse:[
  1996                         ] ifFalse:[
  1987                             "/ self error:'unexpected nil namespace'
  1997                             "/ self error:'unexpected nil namespace'
  1988                         ]
  1998                         ]
  1989                     ] ifFalse:[
  1999                     ] ifFalse:[
  1990                         cls := topOwner nameSpace at:superName.
  2000                         cls := topOwner nameSpace at:superNameWithoutNameSpacePrefix.
  1991                     ]
  2001                     ]
  1992                 ].
  2002                 ].
  1993                 (cls notNil and:[cls ~~ superclass]) ifTrue:[
  2003                 (cls notNil and:[cls ~~ superclass]) ifTrue:[
  1994                     s := superclass nameSpace name , '::' , superName
  2004                     s := superclassNamespace name , '::' , superNameWithoutNameSpacePrefix
  1995                 ] ifFalse:[
  2005                 ] ifFalse:[
  1996                     "/ no class with that name found in my namespace ...
  2006                     "/ no class with that name found in my namespace ...
  1997                     "/ if the superclass resides in Smalltalk,
  2007                     "/ if the superclass resides in Smalltalk,
  1998                     "/ suppress prefix; otherwise, use full prefix.
  2008                     "/ suppress prefix; otherwise, use full prefix.
  1999                     (superclass nameSpace notNil 
  2009                     (superclassNamespace notNil 
  2000                     and:[superclass nameSpace ~~ Smalltalk]) ifTrue:[
  2010                     and:[superclassNamespace ~~ Smalltalk]) ifTrue:[
  2001                         (owner notNil 
  2011                         (owner notNil 
  2002                         and:[owner nameSpace == superclass owningClass nameSpace])
  2012                         and:[owner nameSpace == superclass owningClass nameSpace])
  2003                         ifTrue:[
  2013                         ifTrue:[
  2004                             s := superclass nameWithoutNameSpacePrefix
  2014                             s := superNameWithoutNameSpacePrefix
  2005                         ] ifFalse:[
  2015                         ] ifFalse:[
  2006                             s := superclass name
  2016                             s := superclass name
  2007                         ]
  2017                         ]
  2008                     ] ifFalse:[
  2018                     ] ifFalse:[
  2009                         s := superName
  2019                         s := superNameWithoutNameSpacePrefix
  2010                     ]
  2020                     ]
  2011                 ]
  2021                 ]
  2012             ]
  2022             ]
  2013         ]
  2023         ]
  2014     ].
  2024     ].
  2066         fullName ifTrue:[
  2076         fullName ifTrue:[
  2067             s := owner name.
  2077             s := owner name.
  2068         ] ifFalse:[
  2078         ] ifFalse:[
  2069             s := owner nameWithoutNameSpacePrefix.
  2079             s := owner nameWithoutNameSpacePrefix.
  2070         ].
  2080         ].
  2071 "/        s := owner nameWithoutNameSpacePrefix.
       
  2072         aStream nextPutAll:s.
  2081         aStream nextPutAll:s.
  2073         syntaxHilighting ifTrue:[aStream normal].
  2082         syntaxHilighting ifTrue:[aStream normal].
  2074     ].
  2083     ].
  2075     aStream cr
  2084     aStream cr
  2076 
  2085 
  2228 
  2237 
  2229         "/ check carefully - maybe, my source does not really come from that
  2238         "/ check carefully - maybe, my source does not really come from that
  2230         "/ file (i.e. all of my methods have their source as string)
  2239         "/ file (i.e. all of my methods have their source as string)
  2231 
  2240 
  2232         anySourceRef := false.
  2241         anySourceRef := false.
  2233         self methodDictionary do:[:m|
  2242         self instAndClassMethodsDo:[:m |
  2234             m sourcePosition notNil ifTrue:[
       
  2235                 anySourceRef := true
       
  2236             ]
       
  2237         ].
       
  2238         self class methodDictionary do:[:m|
       
  2239             m sourcePosition notNil ifTrue:[
  2243             m sourcePosition notNil ifTrue:[
  2240                 anySourceRef := true
  2244                 anySourceRef := true
  2241             ]
  2245             ]
  2242         ].
  2246         ].
  2243 
  2247 
  2282         "/ the same as the written one AND the new files directory
  2286         "/ the same as the written one AND the new files directory
  2283         "/ is along the sourcePath, we also need a temporary file
  2287         "/ is along the sourcePath, we also need a temporary file
  2284         "/ first, to avoid accessing the newly written file.
  2288         "/ first, to avoid accessing the newly written file.
  2285 
  2289 
  2286         anySourceRef := false.
  2290         anySourceRef := false.
  2287         self methodDictionary do:[:m|
  2291         self instAndClassMethodsDo:[:m |
  2288             |mSrc|
       
  2289 
       
  2290             (mSrc := m sourceFilename) notNil ifTrue:[
       
  2291                 mSrc asFilename baseName = fileName baseName ifTrue:[
       
  2292                     anySourceRef := true
       
  2293                 ]
       
  2294             ]
       
  2295         ].
       
  2296         self class methodDictionary do:[:m|
       
  2297             |mSrc|
  2292             |mSrc|
  2298 
  2293 
  2299             (mSrc := m sourceFilename) notNil ifTrue:[
  2294             (mSrc := m sourceFilename) notNil ifTrue:[
  2300                 mSrc asFilename baseName = fileName baseName ifTrue:[
  2295                 mSrc asFilename baseName = fileName baseName ifTrue:[
  2301                     anySourceRef := true
  2296                     anySourceRef := true
  3472      into the sourceCode repository. (extensions are stored separate)" 
  3467      into the sourceCode repository. (extensions are stored separate)" 
  3473 
  3468 
  3474     |pkg|
  3469     |pkg|
  3475 
  3470 
  3476     pkg := self package.
  3471     pkg := self package.
  3477     self allSelectorsAndMethodsDo:[:sel :mthd |
  3472     self instAndClassSelectorsAndMethodsDo:[:sel :mthd |
  3478         mthd package ~= pkg ifTrue:[^ true].
  3473         mthd package ~= pkg ifTrue:[^ true].
  3479     ].
  3474     ].
  3480     ^ false
  3475     ^ false
  3481 
  3476 
  3482     "
  3477     "
  3488     "return true, if there are methods in the receiver, which belong to
  3483     "return true, if there are methods in the receiver, which belong to
  3489      the package with aPackageID (i.e. package of class ~= package of method).
  3484      the package with aPackageID (i.e. package of class ~= package of method).
  3490      Those are class extensions, which must be treated specially when checking classes
  3485      Those are class extensions, which must be treated specially when checking classes
  3491      into the sourceCode repository. (extensions are stored separate)" 
  3486      into the sourceCode repository. (extensions are stored separate)" 
  3492 
  3487 
  3493     self allSelectorsAndMethodsDo:[:sel :mthd |
  3488     self instAndClassSelectorsAndMethodsDo:[:sel :mthd |
  3494         mthd package = aPackageID ifTrue:[^ true].
  3489         mthd package = aPackageID ifTrue:[^ true].
  3495     ].
  3490     ].
  3496     ^ false
  3491     ^ false
  3497 
  3492 
  3498     "
  3493     "
  4649 ! !
  4644 ! !
  4650 
  4645 
  4651 !Class class methodsFor:'documentation'!
  4646 !Class class methodsFor:'documentation'!
  4652 
  4647 
  4653 version
  4648 version
  4654     ^ '$Header: /cvs/stx/stx/libbasic/Class.st,v 1.399 2001-09-10 14:18:40 cg Exp $'
  4649     ^ '$Header: /cvs/stx/stx/libbasic/Class.st,v 1.400 2001-10-08 09:17:34 cg Exp $'
  4655 ! !
  4650 ! !