Search code examples
smalltalkpharo

Pharo get all setter from a class


I am new in pharo. I have a problem. I want to get all setter from a class in this language. But i don't any idea for do that. For example, we have ClassA that have a method like:

Object SubClass: #ClassA
    instanceVariableNames: 'name age'
    classVariableNames: ''
    package: 'MyPackage'
name:aName
    name:= aName
age:anAge
    age:= anAge

and i have a protocol setters.

How to get the two setters methods in other class?


Solution

  • I think the main problem is what do you mean by "getting"

    If you want to have setters/getters for a Class you need to create them. For example, if you have a Class Person then you would need to create setter #age: and getter #age.

    If you want to see all the accessors available for the class you need to check the protocol of the class. The accessing is the protocol where you can find messages which enable you to access the inner values of the object.

    If you want to list all the messages available in some protocol you can use (@Pharo 10):

    | selectors |
    selectors := OrderedCollection allSelectorsInProtocol: #'accessing'.
    

    Which will give you the following result:

    a Set(#yourself #enclosedElement #atPin: #before: #first:
    #lastIndexOf:startingAt:ifAbsent: #fourth #replaceAll:with: #basicSize
    #allButFirst #at:ifAbsent: #atLast: #allButFirst: #lastIndexOf: #size
    #indexOfAnyOf:startingAt: #ninth #before:ifAbsent: #at:put: #last
    #after:ifAbsent: #basicAt:put: #at: #indexOf:ifAbsent: #atLast:put:
    #indexOfAnyOf: #atAll: #replaceFrom:to:with:startingAt: #nextToLast
    #replaceFrom:to:with: #middle #first #fifth #at:incrementBy:
    #lastIndexOf:ifAbsent: #allButLast: #indexOfSubCollection:startingAt: #atAllPut:
    #indexOf:startingAt: #basicAt: #identityIndexOf: #atAll:putAll: #third #indexOf:
    #atLast:ifAbsent: #last: #after: #capacity #anyOne #seventh #allButLast
    #lastIndexOfAnyOf:startingAt:ifAbsent: #sixth #second #eighth #atAll:put:
    #from:to:put: #indexOfAnyOf:ifAbsent: #atWrap:put:
    #indexOfAnyOf:startingAt:ifAbsent: #indexOf:startingAt:ifAbsent: #swap:with:
    #identityIndexOf:ifAbsent: #atWrap: #indexOfSubCollection:startingAt:ifAbsent:)