A cool automatic method categoriser

Hi

I have been enhancing the old method classifier developed by Diego Fernandez and I release it now so that others can have a look and that as part of the process we get a better method categorizer. Check the package comment at the end of this blog to see possibilities.

You can install

MCSmalltalkhubRepository owner: ‘Pharo’ project: ‘Pharo60Inbox’ user: ” password: ”

Example

Here is a typical example:

| myRule | 
myRule := MethodCategorizationRule whenSelectorMatches: 'initialize*' categorizeIn: #initialization. 

(AutomaticMethodCategorizer using: myRule) categorizeAllMethodsOf: MyClass

API You can categorize at different levels of granularity.

  • categorizeAllMethodsOf: aClass
  • categorizeAllUncategorizedMethodsOf: aClass
  • categorizeMethod: aMethod
  • categorizeMethods: methods

Now the package includes also a little tool: a ProtocolAnalyzer

ProtocolAnalyzer to the Rescue

ProtocolAnalyzer is a tool to collect some analyses on selectors categorisation.

 First some simple statistics

The following shows that in the image in which this comment was written most of the printOn: messages are all categorized in printing.

self new statisticFor: #printOn:

{377->#printing. 3->#accessing. 1->#ui. 1->#private. 1->#transmitting}

 

Now for initialize we see that it is not the case.

 self new statisticFor: #initialize

{934->#initialization. 85->#’initialize-release’. 50->#initialize. 10->#’as yet unclassified’. 7->#accessing. 5->#initializing. 3->#’instance initalization’. 1->#’initalize-release’. 1->#testing. 1->#’class initialization’. 1->#actions. 1->#drawing. 1->#displaying. 1->#tests. 1->#shout} {867->#initialization. 85->#’initialize-release’. 12->#’as yet unclassified’. 8->#initializing. 6->#accessing. 3->#’instance initalization’. 1->#’initalize-release’. 1->#testing. 1->#’class initialization’. 1->#’updating screen’. 1->#actions. 1->#drawing. 1->#displaying. 1->#tests. 1->#shout}

 

Miscategorized methods

Now we can get a list of all miscategorized method definitions.

self new findInconsistenciesForASelector: #initialize thatIsNotInProtocol: ‘initialization’

 

Fixing miscategorized methods

 

self new fixInconsistenciesOf: #printOn: toBeInProtocol: ‘printing’

 

Package Comment as a Kind of Analysis

I’m a package to support the analysis and application of consistent rule-based method categorisation. I have been designed some years ago by Diego Fernandez and evolved by Stéphane Ducasse. Now it got released so that people can play with it and decide what to do. My main classes are AutomaticMethodCategorizer MethodCategorizationRule and ProtocolAnalyzer

Now the design of this method categoriser is less efficient than the default one. AutomaticMethodCategorizer is based on first class rules while MethodCategorizer is based on dictionaries.

AutomaticMethodCategorizer is more flexible:

  • It can manage different rules groups
  • The order of the rules can be changed.

One possibilty can be to

  • Extract ProtocolAnalyzer as a separate project
  • Create classes out of the dictionaries of MethodCategorizer and make the lookup customizable In any case it would be good
  • To generate refactorings so that we can use the current tools to see the result of a classification
  • To put the classification on so that methods are automatically classified on accept.

Now if you want to help please contact me. stephane.ducasse@inria.fr

 

Stef

Advertisements

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: