10.07.2015 Views

Enhancing Source-Level Programming Tools with An Awareness of ...

Enhancing Source-Level Programming Tools with An Awareness of ...

Enhancing Source-Level Programming Tools with An Awareness of ...

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

AddClass(〈C〉p, 〈C + 〉p) = ∪ i∈C 〈i〉p ∪ ∪ j∈C +〈j〉pAddSuperClass(〈C〉p , 〈C + 〉p) = ∪ i∈C 〈i〉p ext ∪ j∈C + 〈j〉pRemoveSuperClass(〈C〉p, 〈C − 07〉p) = ∪ i∈C 〈i〉p \ ∪ j∈C −〈j〉pAddSuperInterface(〈I〉c , 〈I + 〉c) = ∪ i∈I 〈i〉c impl ∪ j∈I + 〈j〉cRemoveSuperInterface(〈R〉c, 〈R − 10〉c) = ∪ i∈R 〈i〉c \ ∪ j∈R −〈j〉cAddMethod(〈M〉c, 〈M + 〉c) = ∪ i∈M 〈i〉c ∪ ∪ j∈M +〈j〉cRemoveMethod(〈M〉c, 〈M − 13 End〉c) = ∪ i∈M 〈i〉c \ ∪ j∈M −〈j〉cReplicateMethod(〈M〉c) = 〈M〉c ↦→ 〈M ′ 14〉c = ∪ i∈M 〈i〉c ∪ ∪ j∈M ′〈j〉cAddField(〈F 〉c, 〈F + 〉c) = ∪ i∈F 〈i〉c ∪ ∪ j∈F +〈j〉cRemoveField(〈F 〉c, 〈F − 〉c) = ∪ i∈F 〈i〉c \ ∪ j∈F −〈j〉cField[Get | Set]Replacer(〈F 〉c) = 〈F 〉c ↦→ 〈M ′ 〉c = ∪ i∈F 〈i〉c ∪ ∪ j∈M 〈j〉c ∪ ∪ k∈M ′〈k〉c010203040506080911121516Figure 6. Structural Enhancement Operations.Program REMOTINGBeginModule REMOTING_PROXYBeginVar Pattern fieldPBeginmodifiers = "private"type = REMOTING_IFACE.EnhClass.Namename = "obj"EndEnhClass.AddField(fieldP).......Module REMOTING_IFACEBegin.......Describing the JDO EnhancementFigure 7 shows the SER script, which documents the enhancementsperformed by the JDO enhancer, discussed inSection 2. The script starts <strong>with</strong> the keyword Program followedby the name <strong>of</strong> the script. SER scripts can use eachother by means <strong>of</strong> the keyword Using. The body <strong>of</strong> thescript is delineated by the Begin and End keywords ratherthan curly braces. We have deliberately made SER look differentfrom the C family <strong>of</strong> languages. <strong>An</strong>other distinctivefeature <strong>of</strong> SER is not using semicolons to terminate programstatements–each statement is expected to start from a newline. Each script makes available to the programmer two reflectiveobjects, OrgClass and EnhClass, representing theoriginal class and the enhanced class, respectively. This designdecision is guided by the observation that bytecode enhancementeither modifies an existing class or generates abrand new class, using some original class as a template.In both cases, the program in the enhanced class can beexpressed as a function <strong>of</strong> the corresponding constructs inthe original class. Each reflective class object has built-inattributes Name and Type, which represent their name andclass type (i.e., class or interface), respectively. The statementon line 3 expresses that the enhancer will modify theoriginal class rather than generate a brand new one.In addition, to the attributes, the reflective class objectsmake available to the programmer both accessor and modifiermethods. The accessor methods <strong>of</strong> SER mirror the onesin the Java Reflection API [19], <strong>with</strong> two notable exceptions.First, SER accessor methods return declarative iterators,which can only be passed as parameters to SER modifiermethods as we discuss later. Second, accessor methodscan accept as parameters Pattern objects, which describeproperties <strong>of</strong> program constructs. For example, the Patternstarting on line 5 is named fieldP, and it describes all thefields or methods that are private. The statement on line0102030405060708091011121314Program JDO Using SUPER_JDO_SERBeginEnhClass.Name = OrgClass.NameEnhClass.AddInterface("javax.jdo.spi.PersistenceCapable")Var Pattern fieldPBeginmodifiers = "private"EndVar Iterator fieldIter =OrgClass.Fields(fieldP)-- add method that’ll have prefix,-- ‘jdoSet’ or ‘jdoGet’.EnhClass.AddMethod(FieldSetReplacer("jdoSet", fieldIter))EnhClass.AddMethod(FieldGetReplacer("jdoGet", fieldIter))EndFigure 7. SER Script for the JDO Enhancement.9 uses the fieldP Pattern to obtain an Iterator <strong>of</strong> allthe private fields in the original class. SER Patterns providerecords describing every existing property <strong>of</strong> a programconstruct, including its name, type, modifiers, and signature.A Pattern can include any combination <strong>of</strong> records, as necessary.The SER modifier methods can only be applied to theEnhClass reflective object. SER provides modifier methodsfor adding and deleting all the language constructs,including constructors, fields, and methods. Changing aconstruct can be expressed by removing it first and thenadding a new construct back. The statement on line 4 documentsthe enhanced class modified to implement interfacePersistenceCapable. Every modifier method can acceptAccepted to OOPSLA 2009 6 2009/5/14

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!