Detecting a class is abstract

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Detecting a class is abstract

HilaireFernandes
Hi,

Can Nautilius indicate when a class is abstract (i.e.  at least one
method in the class, then its hierarchy is definted respond
subclassResponsability?)

I did not find it in the Analyze menu.


Thanks

Hilaire

--
Dr. Geo
http://drgeo.eu


Reply | Threaded
Open this post in threaded view
|

Re: Detecting a class is abstract

Peter Uhnak
1. To tell whether a class is abstract:

isAbstract := [ :aClass |
(aClass whichSelectorsReferTo: #subclassResponsibility) isNotEmpty or: [ (aClass respondsTo: #isAbstract) and: [ aClass isAbstract ] ]
]

Just be aware that some classes are "abstract", but you can actually instantiate them, because in #new they return something else.

isAbstract value: String "true"


2. To change an icon for a single class (and it's children), add a method to class-side named "systemIcon"

3. To conditionally change an icon for all classes

3.a.) override Object>>systemIcon and make a test based on the isAbstract in 1)
3.b.) or do the same, but in AbstractNautilusUI>>#classIconFor: , this is where test icons are added for example

Peter

On Mon, Apr 4, 2016 at 11:49 AM, Hilaire <[hidden email]> wrote:
Hi,

Can Nautilius indicate when a class is abstract (i.e.  at least one
method in the class, then its hierarchy is definted respond
subclassResponsability?)

I did not find it in the Analyze menu.


Thanks

Hilaire

--
Dr. Geo
http://drgeo.eu



Reply | Threaded
Open this post in threaded view
|

Re: Detecting a class is abstract

HilaireFernandes
Thanks Peter.
So I guess, Nautilus does not offer this functionnality.

Hilaire
--
Dr. Geo
http://drgeo.eu


Reply | Threaded
Open this post in threaded view
|

Re: Detecting a class is abstract

Henrik Nergaard
In reply to this post by HilaireFernandes
One could extend ClassWidget>>#buildTabbedNameOf: to include this functionality.

Quick hack:

ClassWidget>>#isAbstract: aClass
  ^(aClass whichSelectorsReferTo: #subclassResponsibility) isNotEmpty or: [ (aClass respondsTo: #isAbstract) and: [ aClass isAbstract ] ]

Last part of #buildTabbedNameOf:
        ^ self model selectedPackage
                ifNil: [result, anElement name]
                ifNotNil: [:package |
                                | mrph |
                        mrph :=
                        (package includesClass: anElement)
                                ifTrue: [ (result, anElement name) asStringMorph ]
                                ifFalse: [ (result , anElement name)asStringMorph color: self model extensionColor;yourself].
                        (self isAbstract: anElement) ifTrue: [ mrph emphasis: 3; color: Color orange ].
                        mrph.
                ]

Best regards,
Henrik

-----Original Message-----
From: Pharo-users [mailto:[hidden email]] On Behalf Of Hilaire
Sent: Monday, April 4, 2016 11:49 AM
To: [hidden email]
Subject: [Pharo-users] Detecting a class is abstract

Hi,

Can Nautilius indicate when a class is abstract (i.e.  at least one method in the class, then its hierarchy is definted respond
subclassResponsability?)

I did not find it in the Analyze menu.


Thanks

Hilaire

--
Dr. Geo
http://drgeo.eu



stuff.PNG (100K) Download Attachment