'From Cuis 2.5 of 9 August 2010 [latest update: #534] on 10 August 2010 at 9:51:08 am'!

!Behavior methodsFor: 'testing method dictionary' stamp: 'jmv 8/10/2010 09:48'!
whichSelectorsReferTo: literal special: specialFlag byte: specialByte
	"Answer a set of selectors whose methods access the argument as a literal."

	| who |

	Preferences thoroughSenders ifTrue: [
		^self thoroughWhichSelectorsReferTo: literal special: specialFlag byte: specialByte ].

	who _ Set new.
	self selectorsAndMethodsDo: 
		[:sel :method |
		((method hasLiteral: literal) or: [specialFlag and: [method scanFor: specialByte]])
			ifTrue:
				[((literal isVariableBinding) not
					or: [method sendsToSuper not
					or: [method literals allButLast includes: literal]])
						ifTrue: [who add: sel]]].
	^ who! !


!SystemDictionary methodsFor: 'retrieving' stamp: 'jmv 8/10/2010 09:50'!
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: [
					aCollection add: (
						MethodReference new
							setStandardClass: class 
							methodSymbol: sel
					)
				]
			]
		]
	].
	^ aCollection! !

!SystemDictionary methodsFor: 'retrieving' stamp: 'jmv 8/10/2010 09:38'!
allCallsOn: firstLiteral and: secondLiteral
	"Answer a SortedCollection of all the methods that call on both aLiteral 
	and secondLiteral."

	| aCollection secondArray firstSpecial secondSpecial firstByte secondByte |
	aCollection _ SortedCollection new.
	firstSpecial _ self hasSpecialSelector: firstLiteral ifTrueSetByte: [:b | firstByte _ b].
	secondSpecial _ self hasSpecialSelector: secondLiteral ifTrueSetByte: [:b | secondByte _ b].
	Cursor wait showWhile: [
		self allBehaviorsDo: [:class |
			secondArray _ class 
				whichSelectorsReferTo: secondLiteral
				special: secondSpecial
				byte: secondByte.
			((class whichSelectorsReferTo: firstLiteral special: firstSpecial byte: firstByte) select:
				[:aSel | (secondArray includes: aSel)]) do:
						[:sel | 
							aCollection add: (
								MethodReference new
									setStandardClass: class 
									methodSymbol: sel
							)
						]
		]
	].
	^aCollection! !

