Unused Methods

Business forums, including business opportunities, employment opportunities and job requests
ConvertFromOldNGs
Posts: 5321
Joined: Wed Aug 05, 2009 5:19 pm

Unused Methods

Postby ConvertFromOldNGs » Fri Aug 07, 2009 10:20 am

by Anonymous >> Tue, 22 Aug 2006 18:55:29 GMT

I am trying to write a method where I can scane through all methods in a schema, and then determine if that method is not used.

I've tried quite a few techniques, and it seems like none of them work completely.

the class.getImplementors, doesn't help, because it still returns implementations (I don't know what based on), even when nothing has used the method. To test that I created a blank method with nothing calling it, but it still turned up 3 references to it.

I'm certainly lost here...

ConvertFromOldNGs
Posts: 5321
Joined: Wed Aug 05, 2009 5:19 pm

Re: Unused Methods

Postby ConvertFromOldNGs » Fri Aug 07, 2009 10:20 am

by Michael J >> Wed, 23 Aug 2006 0:07:31 GMT

Wrong forum, but here is an answer,

The class representing the metadata for a jade 'method' has a method that will achieve this.

A simple usage would look something like; (where Class is whatever class the method resides on)

constants
METHOD_NAME : String = 'validateData'
vars
oMethodSet : MethodSet;
begin
create oMethodSet transient;
Class.getMethod( METHOD_NAME ).getMethodRefs( oMethodSet );
oMethodSet.inspectModal;
delete oMethodSet;
end;

ConvertFromOldNGs
Posts: 5321
Joined: Wed Aug 05, 2009 5:19 pm

Re: Unused Methods

Postby ConvertFromOldNGs » Fri Aug 07, 2009 10:20 am

by Patwos >> Wed, 23 Aug 2006 2:45:09 GMT

Michael has already indicated a way to get a list of method references for a given method, but you haven't indicated why you wanted to write such a script.

Are you intending to use this to "clean up" unused methods in your schema or are you just using this as a learning exercise to better understand the meta-data model in Jade?

If you're using it to identify methods that are candidates for removal in a clean-up process, be aware that the method may not be directly referenced but may still be used. eg: A reimplementation of a superclass method that gets executed at runtime via polymorphism, or constructors and destructors which are not directly referenced but are automatically executed at object create/delete respectively.

Also keep in mind that methods may be referenced by way of string literals using sendMessage, setPropertyValue/getPropertyValue or TcpIp asynchronous call-back methods. Hopefully by now most people are using the new meta-data notation in this situation, rather than string literals, but systems that have been around for some time may still contain liberal usage of string literals of this nature.

Hope that helps,
Pat.

ConvertFromOldNGs
Posts: 5321
Joined: Wed Aug 05, 2009 5:19 pm

Re: Unused Methods

Postby ConvertFromOldNGs » Fri Aug 07, 2009 10:20 am

by Shahzad >> Wed, 23 Aug 2006 14:22:03 GMT

First, sorry for the post in the wrong forum.

Yes, my purpose was to clean up methods that are not in use.

Thanks for the help with the code, and the information from both of you.

I guess I need to get more creative with additional code to try the best I can to discover the other possible accesses to the methods.

I'll post some code back here if I feel I've accomplished anything significant.

Thanks

Shahzad

ConvertFromOldNGs
Posts: 5321
Joined: Wed Aug 05, 2009 5:19 pm

Re: Unused Methods

Postby ConvertFromOldNGs » Fri Aug 07, 2009 10:20 am

by Torrie >> Wed, 23 Aug 2006 21:31:23 GMT

I've done something similar. Not sure if I've covered all the bases but it might be a starting point. I'm not quite sure about the numScriptRefs method (assuming it returns the number of methods that refer to this one,) it is visible but not documented. Perhaps someone with more knowledge can enlighten us.

I would suggest that you do a full recompile prior to using this (right click on object and choose compile, check all the options.)

Note, the code only checks if the method or any super class implementations for a particular are referenced. It does not check to see that implementations of that method on subclasses are reimplemented. The assumption was that if the method is only ever used on the subclass (and does not inherit) then it is not needed on the super class.

I haven't fully tested this so if you are using it to remove unreferenced methods, I suggest that you backup your schemas first as it may not work as expected!

Torrie




JadeMethod::isReferenced() : Boolean
begin

// Does another method refer to this one
if numScriptRefs > 0; then
return true;

// Is this subclassed method and the super class method is referenced elseif superMethod <> null then
return superMethod.isReferenced;

// Is this an event method (eg click)
elseif isEventMethod then
return isEventMethodUsed();

// Does an application use this as its initialisation method
elseif isApplicationInitializeMethod then
return true;

// Is this method a mapping method for a property
elseif isMappingMethod then
return schemaType.findProperty( self.name ).celIsReferenced;

else
// Not Referenced
return false;
endif;
end;

ConvertFromOldNGs
Posts: 5321
Joined: Wed Aug 05, 2009 5:19 pm

Re: Unused Methods

Postby ConvertFromOldNGs » Fri Aug 07, 2009 10:21 am

by Patwos >> Thu, 24 Aug 2006 20:28:32 GMT

Alternately you could use the Browse -> Unreference Methods menu option in Jade to list the methods that appear to be not directly referenced.

You still have the same issue of potential reference via string literals in code to be aware of before removing the apparently unused methods.

Hope that helps,
Pat.


Return to “Business Discussions”

Who is online

Users browsing this forum: No registered users and 3 guests

cron