Indeed. I took again a look at it, and I found two bugs. The method looks
like this:

TBehavior>>referencedClasses
"Return the set of classes that are directly referenced by my methods"
| answer |
answer := Set new.
self methods do: [ :cm |
answer addAll:
( cm literals select: [ :l | l isKindOf: Association ] thenCollect: #value
) ].
^ answer


1. The last literal of a method because the last literal always points to
the class of the method.

Object methods collectAsSet: [ : cm | cm literals last value ]
==>  "a Set(Object)"

So, we need to ignore the last literal


2. The literals that are Associations can also point to other global
literals that are not classes:
(ASTCache class>>#initialize) literals allButLast
select: [ :l | l isKindOf: Association ]
thenCollect: #value
==> "{Smalltalk}"

So, a better implementation for a method is:


(Object>>#actionMap)  literals *allButLast*
select: [ :l | l *value* isKindOf: *Class* ]
thenCollect: #value

I opened a bug:
https://pharo.fogbugz.com/f/cases/15550/TBehavior-referencedClasses-is-wrong

Cheers,
Doru



On Sun, May 17, 2015 at 12:24 PM, Nicolai Hess <[email protected]> wrote:

>
>
> 2015-05-17 11:34 GMT+02:00 stepharo <[email protected]>:
>
>>
>>
>> Le 17/5/15 11:07, Yuriy Tymchuk a écrit :
>>
>>> Hi, it want to rewrite the SmallLint rule which checks whether an
>>> abstract class is referenced. First question is whether the rule is really
>>> important, because sometimes there are abstract classes with some utility
>>> class methods, so maybe we should check whether they are “instantiated”
>>> with #new or #basicNew.
>>>
>>
>> indeed this rule is not really revelant.
>>
>>
>>> Now the real question is how do you get all classes referenced by a
>>> method. So instead of performing a rule check on a class, do it on a method
>>> and find if any of the accessed classes is abstract.
>>>
>>
>> check the literal frame of the methods. When a method refers to a class
>> the class binding is in the literal frame of the compiled method.
>>
>
> There is one method to get all referenced classes by a class
>
> Morph referencedClasses -> MorphLostFocus MorphChanged PolygonMorph
> SystemWindow IdentityTransform GLMUIThemeExtraIcons RGMethodDefinition
> GTObjectPrinter .....
>
> It is defined by TBehavior.
>
>
>
>
>
>
>>
>>
>>> Uko
>>>
>>>
>>
>>
>


-- 
www.tudorgirba.com

"Every thing has its own flow"

Reply via email to