Page 1 of 3
Autmatically renaming methods
Posted: Thu Oct 07, 2010 9:03 am
by Lorcan
Hi,
I am trying to automatically rename a bunch of methods in a production system I have no IDE access to ("to which I have no IDE access" is, I suppose, better english). I'm pretty sure you can only rename classes and properties via a JCF - anyone know if there is a JCF way of method renaming?
Alternatively, does anyone know if there is a method call on the Method class that renames itself i.e. effectively does what the IDE rename method does. Doesn't seem to be one and the help files don't mention one. If there was I could write a script with my renames that the release could run automatically.
Thanks in advance.....Solution provider wins a chocolate bar
Lorcan
Re: Autmatically renaming methods
Posted: Thu Oct 07, 2010 9:21 am
by Dennis
All you need to do is create your own method on the Method or JadeMethod class
eg.
Code: Select all
setMyName(pName: String) updating;
begin
name := pName;
end;
and have the method call sandwiched between a beginTransaction and commitTransaction.
I used the name setMyName as setName is a reserved name used by Jade. Hope this helps.
Re: Autmatically renaming methods
Posted: Thu Oct 07, 2010 9:38 am
by Lorcan
Thanks Dennis,
That will do what it says on the tin as they say... it renames the method.
The bad news is that the method source remains the same i.e. with the old name in the signiture .... and all methods that call the renamed method still have the old method name in the source.
I suppose you could hack the source code to replace the method name, find all the calling methods and do a find-and-replace in each calling method but this sounds like it will take more than one line in a JadeScript (which is waht I really want).
The really, really bad news is that you don't get the chocolate bar just yet
Lorcan
Re: Autmatically renaming methods
Posted: Thu Oct 07, 2010 10:06 am
by Dennis
Sorry I forgot about the method header within the source. Try this second version:
Code: Select all
setMyName(pName: String) updating;
vars
pos: Integer;
src: String;
begin
pos := 1;
src := source;
src := pName & src[src.pos("(", pos):end];
name := pName;
source := src;
end;
Re: Autmatically renaming methods
Posted: Thu Oct 07, 2010 10:23 am
by Lorcan
Thanks Dennis,
This does change the name in the source but it still doesn't so anything about the associated methods that CALL this (now renamed) method. These sit compiled with the old method name in them but if you try to recompile they fail.
The IDE rename goes off and finds all calling methods and updates them correctly - and, like I said, you can do this in code but it is not trivial. I was hoping someone out there had either a) done all the heavy lifting already or b) knows about the secret call the IDE does that I can hack into
How about I email you half a chocolate bar.
Lorcan
Re: Autmatically renaming methods
Posted: Thu Oct 07, 2010 10:39 am
by allistar
Hi Lorcan,
The problem is that even if you did change the source of the other methods, you then have to force Jade to recompile them, and there's no easy way to do that programatically. One approach is from the IDE - recompile all code underneath "Object". Another approach is to do an extract then an import of the full schema.
I have discovered a method on the SchemaEntity class with this signature:
Code: Select all
___changeName(newName : String; userName : String; sysVer : String; patchVer : Integer; ts : TimeStamp; scriptsChanged : ScriptSet input; latest : Boolean; versionAll : Boolean):Boolean public updating JadeMethod;
Which sounds like it may do what you want. I've not tested it though. I don't think we're supposed to know these things exist, but I have found such "hidden" features to be handy in the past.
Cheers,
Allistar.
Re: Autmatically renaming methods
Posted: Thu Oct 07, 2010 10:53 am
by Lorcan
Allistar,
Cheers buddy - I have found the
_changeName method and been trying to use it with sendMsgWithParams but jade wont let me do this (exception 1236 Cannot crate an instance of this class). My guess is that using this means you are cloning the method to keep a history of it and Jade raps you on the knuckles as it knows you not a internal system user (i.e the IDE).
So half a choclate bar is being emailed to you too....
Lorcan
Re: Autmatically renaming methods
Posted: Thu Oct 07, 2010 11:10 am
by Lorcan
Allistar,
Actually we have tried _changeName on Method not SchemaEntity and that caused the exception.
The SchemaEntity::___changeName is a different animal and I can't get it to work (always returns false) after playing with the different input parameters.... and even if I did get it to work bit worried about whether it might screw up the meta-data if used in isolation.
Shark-infested waters lie ahead.
Lorcan
Re: Autmatically renaming methods
Posted: Thu Oct 07, 2010 11:19 am
by Dennis
Funnily enough I tried doing the same thing with a sendMsgWithParams() but ended up with the
same 1236 exception where I was failing to create/update a JadePatchDetails object. It could
be that doing a find/replace is the best way to go.
May be worthwhile making an NFS contact on PARSYS if you have access.
Re: Autmatically renaming methods
Posted: Thu Oct 07, 2010 12:07 pm
by Dennis
You may be interested in having a look at the FeatureUsage class. You can do a [JadeMethod].sendMsgWithParams("_getScriptRefsIncslusive", [FeatureUsageSet io]) and
then getting the values for following FeatureUsage properties (schemaScript, textPosition, textLength).
It could be interesting doing a find/replace especially if the renamed method is called several times within the other method.