# HG changeset patch # User Stefan Vogel # Date 1467041359 -7200 # Node ID 74774e1ee05dbadd75da170ce28d7169864ea4e6 # Parent 2ba574fda7ab1fb8ea627b0109d1381b96bf6a85 #REFACTORING by stefan class: Method comment/format in: #overwrittenMethod: #rawSourceStreamUsingCache: changed: #flushSourceStreamCache #overwrites: #overwrittenMethod #source diff -r 2ba574fda7ab -r 74774e1ee05d Method.st --- a/Method.st Mon Jun 27 17:22:58 2016 +0200 +++ b/Method.st Mon Jun 27 17:29:19 2016 +0200 @@ -331,8 +331,8 @@ flushSourceStreamCache LastFileLock critical:[ - LastSourceFileName := LastMethodSources := nil. - LastFileReference at:1 put:0. + LastSourceFileName := LastMethodSources := nil. + LastFileReference at:1 put:nil. ]. " @@ -685,21 +685,21 @@ overwrittenMethod "Answers overridden method or nil." - - Overrides isNil ifTrue:[^ nil]. - ^ (Overrides includesKey: self) - ifTrue:[Overrides at: self] + + Overrides isNil ifTrue:[ + ^ nil + ]. + ^ Overrides at:self ifAbsent:nil. "Created: / 05-07-2012 / 10:49:44 / Jan Vrany " ! overwrittenMethod: aMethod - "Set overridden method to aMethod" Overrides isNil ifTrue:[Overrides := WeakIdentityDictionary new:10]. aMethod notNil ifTrue:[aMethod makeLocalStringSource]. - Overrides at: self put: aMethod + Overrides at:self put:aMethod "Created: / 05-07-2012 / 10:50:00 / Jan Vrany " ! @@ -805,76 +805,78 @@ sourcePosition isNil ifTrue:[^ source]. source isNil ifTrue:[^ nil]. - self class lastMethodSourcesLock critical:[ - LastMethodSources notNil ifTrue:[ - chunk := LastMethodSources at:self ifAbsent:nil. - ]. - ]. - chunk notNil ifTrue:[ - ^ chunk + LastMethodSources notNil ifTrue:[ + self class lastMethodSourcesLock critical:[ + LastMethodSources notNil ifTrue:[ + chunk := LastMethodSources at:self ifAbsent:nil. + ]. + ]. + chunk notNil ifTrue:[ + ^ chunk + ]. ]. LastFileLock - critical:[ - "have to protect sourceStream from being closed as a side effect - of some other process fetching some the source from a different source file" - - sourceStream := self sourceStreamUsingCache:true. - sourceStream notNil ifTrue:[ - [ - chunk := self sourceChunkFromStream:sourceStream. - ] on:DecodingError do:[:ex| - "CharacterEncoder>>#guessEncoding is not fail safe - retry with plain unencoded data" - - ('DecodingError ignored when reading <1p> (<2p>)' expandMacrosWith:self whoString with:ex description) infoPrintCR. - sourceStream := self rawSourceStreamUsingCache:true. - ex restart. - ]. - ]. - ] - timeoutMs:100 - ifBlocking:[ - "take care if LastFileLock is not available - maybe we are - called by a debugger while someone holds the lock. - Use uncached source streams" - sourceStream := self sourceStreamUsingCache:false. - sourceStream notNil ifTrue:[ - [ - chunk := self sourceChunkFromStream:sourceStream. - sourceStream close. - ] on:DecodingError do:[:ex| - "CharacterEncoder>>#guessEncoding is not fail safe - retry with plain unencoded data" - ('DecodingError ignored when reading <1p> (<2p>)' expandMacrosWith:self whoString with:ex description) infoPrintCR. - sourceStream close. - sourceStream := self rawSourceStreamUsingCache:false. - ex restart. - ]. - ]. - ]. + critical:[ + "have to protect sourceStream from being closed as a side effect + of some other process fetching some the source from a different source file" + + sourceStream := self sourceStreamUsingCache:true. + sourceStream notNil ifTrue:[ + [ + chunk := self sourceChunkFromStream:sourceStream. + ] on:DecodingError do:[:ex| + "CharacterEncoder>>#guessEncoding is not fail safe - retry with plain unencoded data" + + Logger info:'DecodingError ignored when reading %1 (%2)' with:self whoString with:ex description. + sourceStream := self rawSourceStreamUsingCache:true. + ex restart. + ]. + ]. + ] + timeoutMs:100 + ifBlocking:[ + "take care if LastFileLock is not available - maybe we are + called by a debugger while someone holds the lock. + Use uncached source streams" + sourceStream := self sourceStreamUsingCache:false. + sourceStream notNil ifTrue:[ + [ + chunk := self sourceChunkFromStream:sourceStream. + sourceStream close. + ] on:DecodingError do:[:ex| + "CharacterEncoder>>#guessEncoding is not fail safe - retry with plain unencoded data" + Logger info:'DecodingError ignored when reading %1 (%2)' with:self whoString with:ex description. + sourceStream close. + sourceStream := self rawSourceStreamUsingCache:false. + ex restart. + ]. + ]. + ]. "Cache the source of recently used methods" chunk notNil ifTrue:[ - "JV@2013-08-19: Don't consult UserPreferences if the system is initilizing. This may - lead in funny side-effect as #initializeDefaultPreferences is called which tries to - initialize some colors. But Color itsels is likely not yet initialized, so DNU is - thrown. - CG: also care for standalone non-GUI progs, which have no userPreferences class" - (Smalltalk isInitialized - and:[UserPreferences notNil - and:[UserPreferences current keepMethodSourceCode]]) ifTrue:[ - source := chunk. - sourcePosition := nil. - ^ source. - ]. - - CacheDictionary notNil ifTrue:[ - self class lastMethodSourcesLock critical:[ - LastMethodSources isNil ifTrue:[ - LastMethodSources := CacheDictionary new:50. - ]. - LastMethodSources at:self put:chunk. - ] - ]. + "JV@2013-08-19: Don't consult UserPreferences if the system is initializing. This may + lead in funny side-effect as #initializeDefaultPreferences is called which tries to + initialize some colors. But Color itself is likely not yet initialized, so DNU is + thrown. + CG: also care for standalone non-GUI progs, which have no userPreferences class" + (Smalltalk isInitialized + and:[UserPreferences notNil + and:[UserPreferences current keepMethodSourceCode]]) ifTrue:[ + source := chunk. + sourcePosition := nil. + ^ source. + ]. + + CacheDictionary notNil ifTrue:[ + self class lastMethodSourcesLock critical:[ + LastMethodSources isNil ifTrue:[ + LastMethodSources := CacheDictionary new:50. + ]. + LastMethodSources at:self put:chunk. + ] + ]. ]. ^ chunk @@ -2166,30 +2168,31 @@ sourcePosition isNil ifTrue:[^ source readStream]. usingCacheBoolean ifTrue:[ - (package notNil and:[package ~= PackageId noProjectID]) ifTrue:[ - "/ keep the last source file open, because open/close - "/ operations maybe slow on NFS-mounted file systems. - "/ Since the reference to the file is weak, it will be closed - "/ automatically if the file is not referenced for a while. - "/ Neat trick. - - LastFileLock critical:[ - aStream := LastFileReference at:1. - (aStream isNil - or:[aStream class == SmallInteger - or:[aStream isOpen not]]) ifTrue:[ - aStream := nil. - LastFileReference at:1 put:nil. - ]. - (aStream notNil and:[LastSourceFileName ~= (package,'/',source)]) ifTrue:[ - aStream := nil. - ]. - ]. - - aStream notNil ifTrue:[ - ^ aStream - ]. - ]. + (package notNil and:[package ~= PackageId noProjectID]) ifTrue:[ + "/ keep the last source file open, because open/close + "/ operations maybe slow on NFS-mounted file systems. + "/ Since the reference to the file is weak, it will be closed + "/ automatically if the file is not referenced for a while. + "/ Neat trick. + + LastFileLock critical:[ + aStream := LastFileReference at:1. + (aStream isNil + or:[aStream class == SmallInteger + or:[aStream isOpen not]]) ifTrue:[ + aStream := nil. + LastFileReference at:1 put:nil. + ]. + (aStream notNil + and:[LastSourceFileName ~= (package,'/',source)]) ifTrue:[ + aStream := nil. + ]. + ]. + + aStream notNil ifTrue:[ + ^ aStream + ]. + ]. ]. "/ a negative sourcePosition indicates @@ -2200,47 +2203,47 @@ "/ and having a clue for which file is meant later. sourcePosition < 0 ifTrue:[ - aStream := source asFilename readStreamOrNil. - aStream isNil ifTrue:[ - "/ search in some standard places - fileName := Smalltalk getSourceFileName:source. - fileName notNil ifTrue:[ - aStream := fileName asFilename readStreamOrNil. - ]. - ]. - aStream notNil ifTrue:[ - usingCacheBoolean ifTrue:[ - self cacheSourceStream:aStream. - ]. - ^ aStream - ]. + aStream := source asFilename readStreamOrNil. + aStream isNil ifTrue:[ + "/ search in some standard places + fileName := Smalltalk getSourceFileName:source. + fileName notNil ifTrue:[ + aStream := fileName asFilename readStreamOrNil. + ]. + ]. + aStream notNil ifTrue:[ + usingCacheBoolean ifTrue:[ + self cacheSourceStream:aStream. + ]. + ^ aStream + ]. ]. "/ "/ if there is no SourceManager, look in local standard places first "/ (mclass notNil and:[package == mclass package]) ifTrue:[ - mgr := mclass sourceCodeManagerFromBinaryRevision + mgr := mclass sourceCodeManagerFromBinaryRevision ] ifFalse:[ - "I'm an extension and we don't have binary revision info (!!) - for extensions, try to guess here" - pkgDef := ProjectDefinition definitionClassForPackage: package. - pkgDef notNil ifTrue:[ - mgr := pkgDef sourceCodeManagerFromBinaryRevision - ] ifFalse:[ - "OK, trust the configuration" - mgr := AbstractSourceCodeManager managerForPackage: package - ] + "I'm an extension and we don't have binary revision info (!!) + for extensions, try to guess here" + pkgDef := ProjectDefinition definitionClassForPackage: package. + pkgDef notNil ifTrue:[ + mgr := pkgDef sourceCodeManagerFromBinaryRevision + ] ifFalse:[ + "OK, trust the configuration" + mgr := AbstractSourceCodeManager managerForPackage: package + ] ]. (Class tryLocalSourceFirst or:[mgr isNil]) ifTrue:[ - aStream := self localSourceStream. - aStream notNil ifTrue:[ - usingCacheBoolean ifTrue:[ - self cacheSourceStream:aStream. - ]. - ^ aStream - ]. + aStream := self localSourceStream. + aStream notNil ifTrue:[ + usingCacheBoolean ifTrue:[ + self cacheSourceStream:aStream. + ]. + ^ aStream + ]. ]. "/ @@ -2248,39 +2251,39 @@ "/ who := self who. who notNil ifTrue:[ - myClass := who methodClass. - - (package notNil and:[package ~= myClass package and:[package ~= #'__NoProject__']]) ifTrue:[ - "/ I am an extension - mgr notNil ifTrue:[ - "/ try to get the source using my package information ... - mod := package asPackageId module. - dir := package asPackageId directory. - aStream := mgr streamForExtensionFile:source package:package directory:dir module:mod cache:true. - aStream notNil ifTrue:[ - usingCacheBoolean ifTrue:[ - self cacheSourceStream:aStream. - ]. - ^ aStream - ]. - ]. - "/ consult the local fileSystem - aStream := self localSourceStream. - aStream notNil ifTrue:[ - usingCacheBoolean ifTrue:[ - self cacheSourceStream:aStream. - ]. - ^ aStream - ] - ]. - - aStream := myClass sourceStreamFor:source. - aStream notNil ifTrue:[ - usingCacheBoolean ifTrue:[ - self cacheSourceStream:aStream. - ]. - ^ aStream - ]. + myClass := who methodClass. + + (package notNil and:[package ~= myClass package and:[package ~= #'__NoProject__']]) ifTrue:[ + "/ I am an extension + mgr notNil ifTrue:[ + "/ try to get the source using my package information ... + mod := package asPackageId module. + dir := package asPackageId directory. + aStream := mgr streamForExtensionFile:source package:package directory:dir module:mod cache:true. + aStream notNil ifTrue:[ + usingCacheBoolean ifTrue:[ + self cacheSourceStream:aStream. + ]. + ^ aStream + ]. + ]. + "/ consult the local fileSystem + aStream := self localSourceStream. + aStream notNil ifTrue:[ + usingCacheBoolean ifTrue:[ + self cacheSourceStream:aStream. + ]. + ^ aStream + ] + ]. + + aStream := myClass sourceStreamFor:source. + aStream notNil ifTrue:[ + usingCacheBoolean ifTrue:[ + self cacheSourceStream:aStream. + ]. + ^ aStream + ]. ]. "/ @@ -2288,49 +2291,49 @@ "/ (if there is a source-code manager - otherwise, we already did that) "/ (mgr notNil and:[Class tryLocalSourceFirst not]) ifTrue:[ - aStream := self localSourceStream. - aStream notNil ifTrue:[ - usingCacheBoolean ifTrue:[ - self cacheSourceStream:aStream. - ]. - ^ aStream - ]. + aStream := self localSourceStream. + aStream notNil ifTrue:[ + usingCacheBoolean ifTrue:[ + self cacheSourceStream:aStream. + ]. + ^ aStream + ]. ]. "/ "/ final chance: try current directory "/ aStream isNil ifTrue:[ - aStream := source asFilename readStreamOrNil. - aStream notNil ifTrue:[ - usingCacheBoolean ifTrue:[ - self cacheSourceStream:aStream. - ]. - ^ aStream - ]. + aStream := source asFilename readStreamOrNil. + aStream notNil ifTrue:[ + usingCacheBoolean ifTrue:[ + self cacheSourceStream:aStream. + ]. + ^ aStream + ]. ]. (who isNil and:[source notNil]) ifTrue:[ - "/ - "/ mhmh - seems to be a method which used to be in some - "/ class, but has been overwritten by another or removed. - "/ (i.e. it has no containing class anyMore) - "/ try to guess the class from the sourceFileName. - "/ and retry. - "/ - className := Smalltalk classNameForFile:source. - (classNameSymbol := className asSymbolIfInterned) notNil ifTrue:[ - myClass := Smalltalk at:classNameSymbol ifAbsent:nil. - myClass notNil ifTrue:[ - aStream := myClass sourceStreamFor:source. - aStream notNil ifTrue:[ - usingCacheBoolean ifTrue:[ - self cacheSourceStream:aStream. - ]. - ^ aStream - ]. - ] - ] + "/ + "/ mhmh - seems to be a method which used to be in some + "/ class, but has been overwritten by another or removed. + "/ (i.e. it has no containing class anyMore) + "/ try to guess the class from the sourceFileName. + "/ and retry. + "/ + className := Smalltalk classNameForFile:source. + (classNameSymbol := className asSymbolIfInterned) notNil ifTrue:[ + myClass := Smalltalk at:classNameSymbol ifAbsent:nil. + myClass notNil ifTrue:[ + aStream := myClass sourceStreamFor:source. + aStream notNil ifTrue:[ + usingCacheBoolean ifTrue:[ + self cacheSourceStream:aStream. + ]. + ^ aStream + ]. + ] + ] ]. ^ nil @@ -3048,14 +3051,16 @@ "Modified: / 05-07-2012 / 10:52:38 / Jan Vrany " ! -overwrites: aMethod - - | mth | - mth := self overwrittenMethod. - [ mth notNil ] whileTrue: - [mth == aMethod ifTrue:[^true]. - mth := mth overwrittenMethod]. - ^false +overwrites:aMethod + |mth| + + mth := self. + [ mth := mth overwrittenMethod. mth notNil ] whileTrue:[ + mth == aMethod ifTrue:[ + ^ true + ]. + ]. + ^ false "Created: / 05-07-2012 / 10:52:04 / Jan Vrany " !