Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Method Inspection Squeak/Smalltalk

I am trying to do some method inspection (in Squeak - Smalltalk).

I wanted to ask what is the way to check if a method is an abstract method? Meaning I want to write, A method which gets a class and a symbol and will check if there is such a symbol in the list of methods in an object which is of this class type and if found will return true if abstract (else not). How can I check if a method is an abstract method or not?

Thanks in advance.

like image 997
user550413 Avatar asked Jan 27 '26 16:01

user550413


1 Answers

A method is abstract (in the sense Java or C++ people mean) if it looks like this:

myMethod
  self subclassResponsibility.

So all you need to do to answer "is MyObject>>#myMethod abstract?" is to answer "is MyObject>>#myMethod a sender of #subclassResponsibility?"

You can answer that question by adding this method to Object:

isMethodAbstract: aSelector on: aClass
    ^ (self systemNavigation allCallsOn: #subclassResponsibility)
        anySatisfy: [:each | each selector == aSelector
            and: [each classSymbol == aClass name]]

or simply evaluating this in a Workspace (with suitable replacements for #samplesPerFrame and SoundCodec of course):

(SystemNavigation default allCallsOn: #subclassResponsibility)
    anySatisfy: [:each | each selector == #samplesPerFrame
        and: [each classSymbol == SoundCodec name]]
like image 194
Frank Shearar Avatar answered Jan 31 '26 02:01

Frank Shearar