'From Cuis 2.6 of 10 August 2010 [latest update: #540] on 1 September 2010 at 2:14:33 pm'!

!SmalltalkEditor methodsFor: 'menu messages' stamp: 'jmv 9/1/2010 13:37'!
methodSourceContainingIt
	"Open a browser on methods which contain the current selection in their source (case-sensitive full-text search of source).   EXTREMELY slow!!"

	self lineSelectAndEmptyCheck: [^ self].
	(self confirm: 'This will take a few moments.
Shall I proceed?') ifFalse: [^ self].
	Smalltalk browseMethodsWithSourceString: self selection string! !


!SystemDictionary methodsFor: 'housekeeping' stamp: 'jmv 9/1/2010 13:37'!
removeAllLineFeeds    "Smalltalk removeAllLineFeeds"
	"Scan all methods for source code with lineFeeds.
	Replaces all occurrences of <CR><LF> by <CR>, noted by beep.
	Halts with a message if any other LFs are found."
	 | oldCodeString n crlf cr newCodeString oldStamp oldCategory m lf |
	crlf _ String crlf.
	cr _ String cr.
	lf _ String lf.
	Smalltalk forgetDoIts.
'Scanning sources for LineFeeds.
This will take a few moments...'
displayProgressAt: Sensor cursorPoint
from: 0 to: CompiledMethod instanceCount
during: [:bar | n _ 0. m _ 0.
	Smalltalk allBehaviorsDo:
		[:cls | 
		cls selectors do:
			[:selector | (n _ n+1) \\ 100 = 0 ifTrue: [bar value: n].
			oldCodeString _ (cls sourceCodeAt: selector) asString.
			(oldCodeString indexOf: Character lf startingAt: 1) > 0 ifTrue: [
				newCodeString _ oldCodeString copyReplaceAll: crlf with: cr.
				newCodeString _ oldCodeString copyReplaceAll: lf with: cr.
				oldStamp _ Utilities timeStampForMethod: (cls compiledMethodAt: selector).
				oldCategory _ cls whichCategoryIncludesSelector: selector.
				cls compile: newCodeString classified: oldCategory withStamp: oldStamp notifying: nil.
				m _ m + 1]]].
].
	Transcript cr; show: m printString , ' methods stripped of LFs.'.
! !

!SystemDictionary methodsFor: 'housekeeping' stamp: 'jmv 9/1/2010 13:37'!
removeTextCode    "Smalltalk removeTextCode"
	"Scan all methods for source code that is Text (i.e. with attributes)
	Replace it with simpleStrings"
	 | oldCodeString n newCodeString oldStamp oldCategory m classComment c o stamp |
	Smalltalk forgetDoIts.
	'Scanning sources for Text.
This will take a few moments...'
		displayProgressAt: Sensor cursorPoint
		from: 0 
		to: CompiledMethod instanceCount
		during: [:bar | 
			n _ 0.
			m _ 0.
			c _ 0.
			Smalltalk allBehaviorsDo: [ :cls | 
				cls selectors do: [ :selector  | 
					(n _ n+1) \\ 100 = 0 ifTrue: [bar value: n].
					oldCodeString _ cls sourceCodeAt: selector.
					oldCodeString class = String ifFalse: [
						newCodeString _ oldCodeString asString.
						oldStamp _ Utilities timeStampForMethod: (cls compiledMethodAt: selector).
						oldCategory _ cls whichCategoryIncludesSelector: selector.
						cls compile: newCodeString classified: oldCategory withStamp: oldStamp notifying: nil.
						m _ m + 1]].
				cls isMeta ifFalse: [
					o _ cls organization.
					classComment _ o classComment.
					stamp _ o commentStamp.
					classComment class == String ifFalse: [
						classComment hasAnyAttribute ifTrue: [
							self halt "review" ].
						cls classComment: classComment asString stamp: stamp.
						c _ c + 1 ]].
			].
		].
		Transcript cr; show: m printString , ' text methods converted to strings.'.
		Transcript cr; show: c printString , ' text class comments converted to strings.'.! !

!SystemDictionary methodsFor: 'retrieving' stamp: 'jmv 9/1/2010 13:40'!
allCallsOn: aLiteral   "Smalltalk browseAllCallsOn: #open:label:."
	"Answer a Collection of all the methods that call on aLiteral."
	| aCollection special aList byte |

	#(23 48 'fred' (new open:label:)) size.
"Example above should find #open:label:, though it is deeply embedded here."

	aCollection _ OrderedCollection new.
	special _ self hasSpecialSelector: aLiteral ifTrueSetByte: [:b | byte _ b ].
	Cursor wait showWhile: [
		self allBehaviorsDo: [:class |
			aList _ class whichSelectorsReferTo: aLiteral special: special byte: byte.
			aList do: [ :sel |
				sel == #DoIt ifFalse: [
					
					"For special selectors, look for the literal in the source code.
					Otherwise, for example, searching for senders of #== will include senders of #ifNil:"
					(byte isNil or: [
						((class sourceCodeAt: sel)
							findString: aLiteral) > 0]) ifTrue: [

						aCollection add: (
							MethodReference new
								setStandardClass: class 
								methodSymbol: sel
						)
					]
				]
			]
		]
	].
	^ aCollection! !

