System for modifying object oriented code
Abstract
The system receives three sets of inputs: program class definitions, a set of rules, and additional class definitions to be merged with the program class definitions. There are three types of rules: the first rule is used to substitute the allocation of an object of a new class for the allocation of the object based on an original class; the second rule is used to change code that allocates an object of an original class to code that calls a static method that allocates the object of the original class; and the third rule is used to a replace a new static field for an original static field. The system separately reads each of the original class definitions into a class data structure and performs the modifications to the class data structure according to the set of rules. The resulting class data structure is written to an output stream.
Claims
exact text as granted — not AI-modifiedI claim:
1 . A method of modifying object oriented code, comprising the steps of:
reading a rule defining a change to object code, said object code including a definition of an object oriented class; modifying said object code based on said rule; and writing said modified object code.
2 . A method according to claim 1 , wherein said step of modifying includes:
changing first code that allocates a first object of a first class to second code that allocates said first object based on a second class.
3 . A method according to claim 2 , wherein:
said second class extends said first class.
4 . A method according to claim 3 , further including the step of:
merging said second class with said first class.
5 . A method according to claim 3 , wherein said step of modifying includes the steps of:
looking for a creation instruction in said which includes a first reference to said first class; changing said first reference to refer to said second class, if said step of looking for said creation instruction found said creation instruction; looking for a first instruction which invokes a constructor for said first class; and changing said first instruction to a second instruction which invokes a constructor for said second class, if said step of looking for said first instruction found said first instruction.
6 . A method according to claim 5 , further including the step of:
reading said object code into a data structure, said data structure includes a table of constant information, said step of changing said first reference changes an index into said table of constant information.
7 . A method according to claim 6 , wherein said step of modifying further includes the steps of:
searching said data structure for a reference to said first class; and adding to said data structure a reference to said second class if said step of searching finds said reference to said first class; said step of changing said first reference changes an index which points to a reference to said first class to an index which points to a reference to said second class; said step of changing said first instruction to a second instruction includes the step of adding a reference to said constructor for said second class, said second instruction including an index pointing to said reference to said constructor for said second class.
8 . A method according to claim 1 , wherein:
said object oriented class has a superclass; said object code including code identifying said superclass; and said step of modifying includes changing said identification of said superclass from a first class to a second class, said second class extends said first class.
9 . A method according to claim 1 , wherein said step of modifying includes:
changing first code that allocates a first object of a first class to second code that invokes a static method that allocates said first object of said first class.
10 . A method according to claim 9 , wherein:
said first class is a final class.
11 . A method according to claim 9 , wherein said step of modifying includes the steps of:
looking for a creation instruction which includes a first reference to said first class; and changing said creation instruction to a nop.
12 . A method according to claim 9 , further including the step of:
reading said object code into a data structure, said data structure includes a table of constant information; said step of modifying further includes the steps of:
searching said data structure for a reference to said first class,
adding to said data structure a reference to said second class if said step of searching finds said reference to said first class,
searching said data structure for a first instruction that invokes a constructor of said first class,
adding to said table a reference to said static method, and
changing said first instruction to a second instruction, said second instruction invokes said static method.
13 . A method according to claim 1 , wherein said step of modifying includes:
changing a reference to a first static field to a reference to a second static field.
14 . A method according to claim 13 , further including the step of:
reading said object code into a data structure, said data structure includes a table of constant information.
15 . A method according to claim 14 , wherein said step of changing a reference to a first static field includes:
searching said table for a first reference to said first static field; adding to said table a second reference to said second static field; and changing a third reference to a fourth reference, said third reference points to said first reference and said fourth reference points to said second reference.
16 . A method according to claim 1 , further including the step of:
reading said object code into a data structure, said step of modifying includes modifying said data structure.
17 . A method according to claim 1 , wherein:
said object code is java object code.
18 . A method according to claim 1 , wherein:
said object code includes definitions of a plurality of object oriented classes; and said steps of modifying and writing are performed for each of said object oriented classes.
19 . A method of modifying object oriented code, comprising the steps of:
reading a rule defining a substitution of a new class for an original class; reviewing an input class definition; and if said step of reviewing finds an allocation of an object based on said original class, changing said allocation of said object to be based on said new class.
20 . A method according to claim 19 , wherein:
said new class extends said original class.
21 . A method according to claim 19 , further including the steps of:
reading said input class definition into a data structure, said data structure including a reference to said original class; and adding to said data structure a reference to said new class, said step of changing said allocation of said object includes changing an index to said reference to said original class to be an index to said reference to said replacement class.
22 . A method according to claim 19 , wherein:
said input class has a superclass; said input class definition including code identifying said superclass; and said method of modifying object oriented code further includes the step of changing said identification of said superclass from said original class to said new class if said input class is a subclass of said original class.
23 . A method according to claim 19 , wherein:
said object oriented code is java object code.
24 . A method according to claim 19 , further including the steps of:
reading a rule defining a proxy of a final class by a proxy class; reviewing said input class definition; and if said step of reviewing finds an allocation of an object based on said final class, changing said allocation of said object based on said final class to be an invocation of a static method in said proxy class, said static method allocating said object based on said final class.
25 . A method according to claim 19 , further including the steps of:
receiving a set of rules; receiving a set of additional classes including said new class; receiving a set of program classes including said input class; and writing at least a portion of said input class to a stream after said step of changing said allocation.
26 . A processor readable storage medium having processor readable code embodied on said processor readable storage medium, said processor readable code for programming a processor to perform a method comprising the steps of:
reading a rule defining a change to object code, said object code defining an object oriented class; and modifying said object code based on said rule.
27 . A processor readable storage medium according to claim 26 , wherein said step of modifying includes:
changing first code that allocates a first object of a first class to second code that allocates said first object based on a second class, said second class extends said first class.
28 . A processor readable storage medium according to claim 26 , wherein said step of modifying includes the steps of:
looking for a creation instruction which includes a first reference to said first class; changing said first reference to refer to said second class, if said step of looking for said creation instruction found said creation instruction; looking for a first instruction which invokes a constructor for said first class; and changing said first instruction to a second instruction which invokes a constructor for said second class, if said step of looking for said first instruction found said first instruction.
29 . A processor readable storage medium according to claim 26 , wherein:
said object oriented class has a superclass; said object code including code identifying said superclass; and said step of modifying includes changing said identification of said superclass from a first class to a second class, said second class extends said first class.
30 . A processor readable storage medium according to claim 26 , wherein said step of modifying includes:
changing first code that allocates a first object of a first class to second code that calls a static method that allocates said first object of said first class, said first class is a final class.
31 . A processor readable storage medium according to claim 26 , wherein said step of modifying includes:
changing a reference to a first static field to a reference to a second static field.
32 . A processor readable storage medium according to claim 26 wherein:
said object code is java object code.
33 . An apparatus capable of modifying object oriented code, comprising:
one or more input devices; one or more output devices; a processor in communication with said input device and said output device; a storage unit in communication with said processor, said storage device adapted to store program code, said program code programs said processor to perform the step of:
reading a rule defining a change to object code, said object code defining an object oriented class, and
modifying said object code based on said rule.
34 . An apparatus according to claim 33 , wherein said step of modifying includes:
changing first code that allocates a first object of a first class to second code that allocates said first object of a second class, said second class extends said first class.
35 . An apparatus according to claim 33 , wherein:
said object oriented class has a superclass; said object code including code identifying said superclass; and said step of modifying includes changing said identification of said superclass from a first class to a second class, said second class extends said first class.
36 . An apparatus according to claim 33 , wherein said step of modifying includes:
changing first code that allocates a first object of a first class to second code that calls a static method that allocates said first object of said first class, said first class is a final class.
37 . An apparatus according to claim 33 , wherein said step of modifying includes:
changing a reference to a first static field to a reference to a second static field.
38 . An apparatus according to claim 33 , wherein:
said object code is java object code.Cited by (0)
No later patents cite this yet.
References (0)
No backward citations on record.