KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > soot > dava > toolkits > base > AST > transformations > SuperFirstStmtHandler


1 /* Soot - a J*va Optimization Framework
2  * Copyright (C) 2005-2006 Nomair A. Naeem (nomair.naeem@mail.mcgill.ca)
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the
16  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17  * Boston, MA 02111-1307, USA.
18  */

19
20
21
22
23
24 /*
25  * Deal with the problem that super has to be the first stmt in a method body
26  * The problem is as follows:
27  * Suppose you had a call to super with some complicated arguments
28  * or suppose an Aspect added some preinitialization
29  * In both cases some code gets decompiled BEFORE the call to super
30  * this is just initializing the arguments.
31  * However the call to super() has to be the first stmt
32  *
33  *
34  * January 23rd 2006 Writing New Algorithm...
35  *
36  * Original constructor ONE:Changed Constructor
37  *
38  * B(args1){ B(args1){
39  * ---------- this(..args1..,B.preInit1(args1));
40  * X ---------- }
41  * ----------
42  * super(args2);
43  * ----------
44  * Y ----------
45  * ----------
46  *
47  *
48  ********************************************************************
49  * New method in Class being Decompiled
50  *
51  * private static preInit1(args1){
52  *
53  * ----------
54  * X ----------
55  * ----------
56  *
57  * DavaSuperHandler handler = new DavaSuperHandler();
58  * //code to evaluate all args in args2
59  *
60  * //evaluate 1st arg in args2
61  * ---------
62  * handler.store(firstArg);
63  *
64  * //evaluate 2nd arg in args2
65  * ---------
66  * handler.store(secondArg);
67  *
68  * //AND SO ON TILL ALL ARGS ARE FINISHED
69  *
70  * return handler;
71  * }
72  *
73  *
74  ********************************************************************
75  * New Constructor Introduced
76  *
77  * B(..args1.., DavaSuperHandler handler){
78  *
79  * super(
80  * (CAST-TYPE)handler.get(0),
81  * ((CAST-TYPE)handler.get(1)).CONVERSION(),
82  * .......);
83  *
84  * ----------
85  * Y ----------
86  * ----------
87  * }
88  *
89  *
90  ***********************************************************************
91  * New Class Created (Inner class will work best)
92  *
93  * class DavaSuperHandler{
94  * Vector myVector = new Vector();
95  *
96  * public Object get(int pos){
97  * return myVector.elementAt(pos);
98  * }
99  *
100  * public void store(Object obj){
101  * myVector.add(obj);
102  * }
103  * }
104  *
105  ***********************************************************************
106  *
107  *
108  *
109  * ONE: Important to check that the parent of the call to super is the ASTMethodNode
110  * This is important because of the super call is nested within some control flow
111  * we cannot simply remove the super call (Although this shouldnt happen but just for completness)
112  *
113  * TWO: It is necessary to run on AST Analysis on the new SootMethod since
114  * the DavaBody usually invokes these anlayses
115  * but our newly created method will never go through that process
116  *
117  */

118
119
120 package soot.dava.toolkits.base.AST.transformations;
121
122 import java.util.*;
123 import soot.*;
124 import soot.jimple.*;
125 import soot.jimple.internal.*;
126 import soot.dava.*;
127 import soot.grimp.internal.*;
128 import soot.dava.internal.AST.*;
129 import soot.dava.internal.asg.*;
130 import soot.dava.internal.javaRep.*;
131 import soot.dava.toolkits.base.AST.analysis.*;
132 import soot.dava.toolkits.base.AST.traversals.*;
133
134
135 public class SuperFirstStmtHandler extends DepthFirstAdapter{
136     
137     public final boolean DEBUG = false;
138     
139     ASTMethodNode originalASTMethod; //contains the entire method which was being decompiled
140
DavaBody originalDavaBody; //originalASTMethod.getDavaBody
141
Unit originalConstructorUnit; //contains this.init<>
142
InstanceInvokeExpr originalConstructorExpr; //contains the expr within the ConstructorUni
143
SootMethod originalSootMethod; //originalDavaBody.getMethod();
144
SootClass originalSootClass; //originalSootMethod.getDeclaringClass();
145
Map originalPMap;
146     
147     
148     List argsOneTypes=null; //initialized to the ParameterTypes of the original method
149
List argsOneValues=null; //initialized to the values of these parameters of the original method
150

151     List argsTwoValues=null; //initialized to the Parameter values of the call to super
152
List argsTwoTypes=null; //initialized to the ParameterTypes of the call to super
153

154     //PreInit fields
155
SootMethod newSootPreInitMethod=null;//only initialized by createMethod
156
DavaBody newPreInitDavaBody=null; //only initialized by createMethod
157
ASTMethodNode newASTPreInitMethod=null; //only initialized by createNewASTPreInitMethod
158

159     //Constructor fields
160
SootMethod newConstructor = null; //initialized by createNewConstructor
161
DavaBody newConstructorDavaBody=null; //initialized by createNewConstructor
162
ASTMethodNode newASTConstructorMethod=null; //only initialized by createNewASTConstructor
163

164
165
166
167
168     public SuperFirstStmtHandler(ASTMethodNode AST){
169     this.originalASTMethod=AST;
170     initialize();
171     }
172
173     public SuperFirstStmtHandler(boolean verbose,ASTMethodNode AST){
174     super(verbose);
175     this.originalASTMethod=AST;
176     initialize();
177     }
178
179     public void initialize(){
180     originalDavaBody = originalASTMethod.getDavaBody();
181     originalConstructorUnit = originalDavaBody.get_ConstructorUnit();
182
183     originalConstructorExpr = originalDavaBody.get_ConstructorExpr();
184     if(originalConstructorExpr != null){
185         //should get the values and the types of these into lists for later use
186
argsTwoValues = originalConstructorExpr.getArgs();
187
188         argsTwoTypes = new ArrayList();
189
190         //get also the types of these args
191
Iterator valIt = argsTwoValues.iterator();
192         while(valIt.hasNext()){
193         Value val = (Value)valIt.next();
194         Type type = val.getType();
195         argsTwoTypes.add(type);
196         }
197     }
198
199
200
201     originalSootMethod = originalDavaBody.getMethod();
202     originalSootClass = originalSootMethod.getDeclaringClass();
203
204     originalPMap = originalDavaBody.get_ParamMap();
205     
206     argsOneTypes = originalSootMethod.getParameterTypes();
207
208     //initialize argsOneValues
209
argsOneValues = new ArrayList();
210         Iterator typeIt = argsOneTypes.iterator();
211         int count = 0;
212         while (typeIt.hasNext()) {
213             Type t = (Type) typeIt.next();
214         
215         argsOneValues.add(originalPMap.get(new Integer JavaDoc(count)));
216         count++;
217     }
218
219     }
220
221
222
223     /*
224      * looking for an init stmt
225      */

226     public void inASTStatementSequenceNode(ASTStatementSequenceNode node){
227     List stmts = node.getStatements();
228     Iterator it = stmts.iterator();
229     while(it.hasNext()){
230         AugmentedStmt as = (AugmentedStmt)it.next();
231         Unit u = as.get_Stmt();
232
233         if (u == originalConstructorUnit){
234         //System.out.println("Found the constructorUnit"+u);
235

236         //ONE: make sure the parent of the super() call is an ASTMethodNode
237
ASTParentNodeFinder parentFinder = new ASTParentNodeFinder();
238         originalASTMethod.apply(parentFinder);
239
240         Object JavaDoc tempParent = parentFinder.getParentOf(node);
241         if( tempParent != originalASTMethod){
242             //System.out.println("ASTMethod node is not the parent of constructorUnit");
243
//notice since we cant remove one call of super there is no point
244
//in trying to remove any other calls to super
245
removeInit();
246             return;
247         }
248
249         //only gets here if the call to super is not nested within some other construct
250

251         /**********************************************************/
252         /****************** CREATING PREINIT METHOD ***************/
253         /**********************************************************/
254         
255         //CREATE UNIQUE METHOD
256
createSootPreInitMethod(); //new method is initalized in newSootPreInitMethod
257

258         //Create ASTMethodNode for this SootMethod
259
createNewASTPreInitMethod(node); //the field newASTPreInitMethod is initialized
260

261         //newASTPreInitMethod should be non null if we can go ahead
262

263         if(newASTPreInitMethod == null){
264             //could not create ASTMethodNode for some reason or the other
265
//just silently return
266
//System.out.println(">>>>>>>>>>>>>>>>Couldnt not create ASTMethodNode for the new PreInitMethod");
267
removeInit();
268             return;
269         }
270
271         if(!finalizePreInitMethod()){
272             //shouldnt be creating PreInit
273
//System.out.println(">>>>>>>>>>>>>>SHOULDNT BE CREATING PREINIT");
274
removeInit();
275             return;
276         }
277
278
279
280         /**********************************************************/
281         /************** CREATING NEW CONSTRUCTOR ******************/
282         /**********************************************************/
283         
284         //create SootMethod for the constructor
285
createNewConstructor();
286         
287         createNewASTConstructor(node);
288
289         if(!createCallToSuper()){
290             //could not create call to super
291
//still safe to simply exit
292
//System.out.println(">>>>>>>>>>>>>>>>>>>>>>>>>>Could not create call to super...SuperFirstStmtHandler");
293
removeInit();
294             return;
295         }
296         finalizeConstructor();
297
298
299
300         /**********************************************************/
301         /************** CHANGE ORIGINAL CONSTRUCTOR ***************/
302         /**********************************************************/
303         if(changeOriginalAST()){
304             //System.out.println("Done Done Done");
305

306             debug("SuperFirstStmtHandler....inASTStatementSeuqneNode","Added PreInit");
307             G.v().SootMethodAddedByDava=true;
308             G.v().SootMethodsAdded.add(newSootPreInitMethod);
309             G.v().SootMethodsAdded.add(newConstructor);
310
311
312             /**********************************************************/
313             /****************** CREATING INNER CLASS ******************/
314             /**********************************************************/
315             
316             //notice that inner class is created by DavaPrinter in the printTo method
317
//all we do is set a Global to true and later on when the SootClass is being
318
//output the inner class will be output also
319
G.v().SootClassNeedsDavaSuperHandlerClass.add(originalSootClass);
320
321             //System.out.println("\n\nSet SootMethodAddedByDava to true\n\n");
322
}
323         
324
325         }
326     }
327     }
328
329     /*
330      * When we havent created the indirection to take care of super bug be it cos we dont need to
331      * or that we CANT cos of some limitation....should atleast remove the jimple this.init call from the
332      * statements
333      */

334     public void removeInit(){
335     //remove constructorUnit from originalASTMethod
336
List newBody = new ArrayList();
337     
338     List subBody = (List)originalASTMethod.get_SubBodies();
339     if(subBody.size()!=1)
340         return;
341
342     List oldBody = (List)subBody.get(0);
343     Iterator oldIt = oldBody.iterator();
344     while(oldIt.hasNext()){
345         //going through each node in the old body
346
ASTNode node = (ASTNode)oldIt.next();
347
348         //copy the node as is unless its an ASTStatementSequence
349
if(!(node instanceof ASTStatementSequenceNode)){
350         newBody.add(node);
351         continue;
352         }
353
354         //if the node is an ASTStatementSequenceNode
355
//copy all stmts unless it is a constructorUnit
356
ASTStatementSequenceNode seqNode = (ASTStatementSequenceNode)node;
357
358         List newStmtList = new ArrayList();
359
360         List stmts = seqNode.getStatements();
361         Iterator it = stmts.iterator();
362         while(it.hasNext()){
363         AugmentedStmt augStmt = (AugmentedStmt)it.next();
364         Stmt stmtTemp = augStmt.get_Stmt();
365         if(stmtTemp == originalConstructorUnit){
366             //do nothing
367
}
368         else{
369             newStmtList.add(augStmt);
370         }
371         }
372         if(newStmtList.size()!=0){
373         newBody.add(new ASTStatementSequenceNode(newStmtList));
374         }
375     }
376     
377     originalASTMethod.replaceBody(newBody);
378     
379     }
380
381
382
383
384
385
386     /*
387      * Remove the entire body and replace with the statement
388      * this(args1, B.preInit(args1));
389      */

390     public boolean changeOriginalAST(){
391     //originalDavaBody has to be changed
392

393     //fix up the call within the constructorUnit....the args should be argsOne followed by a method call to preInit
394
if(originalConstructorExpr == null){
395         //hmm that means there was no call to super in the original code
396
//System.out.println("originalConstructorExpr is null");
397
return false;
398     }
399
400     List thisArgList = new ArrayList();
401     thisArgList.addAll(argsOneValues);
402
403     DStaticInvokeExpr newInvokeExpr = new DStaticInvokeExpr(newSootPreInitMethod.makeRef(),argsOneValues);
404     thisArgList.add(newInvokeExpr);
405     
406
407     //the methodRef of themethod to be called is the new constructor we created
408
InstanceInvokeExpr tempExpr =
409         new DSpecialInvokeExpr(originalConstructorExpr.getBase(),newConstructor.makeRef(),thisArgList);
410
411     originalDavaBody.set_ConstructorExpr(tempExpr);
412     
413     //create Invoke Stmt with tempExpr as the expression
414
GInvokeStmt s = new GInvokeStmt(tempExpr);
415     
416     originalDavaBody.set_ConstructorUnit((Unit)s);
417
418     //originalASTMethod has to be made empty
419
originalASTMethod.setDeclarations(new ASTStatementSequenceNode(new ArrayList()));
420     originalASTMethod.replaceBody(new ArrayList());
421     return true;
422
423     }
424
425     private SootMethodRef makeMethodRef(String JavaDoc methodName,ArrayList args){
426     //make MethodRef for methodName
427

428     SootMethod method = new SootMethod(methodName,args,RefType.v("java.lang.Object"));
429
430     //set the declaring class of new method to be the DavaSuperHandler class
431
method.setDeclaringClass(new SootClass("DavaSuperHandler"));
432     return method.makeRef();
433     }
434
435
436     /*
437      * super(
438      * (CAST-TYPE)handler.get(0),
439      * ((CAST-TYPE)handler.get(1)).CONVERSION(),
440      * .......);
441      *
442      * returns false if we cant create the call to super
443      */

444     private boolean createCallToSuper(){
445     
446     //check that whether this call is even to be made or not
447
if (originalConstructorExpr == null) {
448         //hmm that means there was no call to super in the original code
449
//System.out.println("originalConstructorExpr is null");
450
return false;
451     }
452     //System.out.println("ConstructorExpr is non null...call to super has to be made");
453

454     //find the parent class of the current method being decompiled
455
SootClass parentClass =originalSootClass.getSuperclass();
456     
457     //retrieve the constructor of the super class that we want to call
458
//remember argsTwoTypes contains the ParameterType to the call to the super method
459
if(!(parentClass.declaresMethod("<init>",argsTwoTypes))){
460         //System.out.println("parentClass does not have a constructor with this name and ParamTypes");
461
return false;
462     }
463
464     SootMethod superConstructor = parentClass.getMethod("<init>",argsTwoTypes);
465
466     //create InstanceInvokeExpr
467

468     //need Value base: this??
469
//need SootMethod Ref...make sootmethoref of the super constructor found
470
//need list of thisLocals.........try empty arrayList since it doesnt seem to be used anywhere??
471

472     List argsForConstructor = new ArrayList();
473     int count=0;
474
475     //have to make arg as "handler.get(0)"
476

477     //create new ReftType for DavaSuperHandler
478
RefType type = (new SootClass("DavaSuperHandler")).getType();
479
480     //make JimpleLocal to be used in each arg
481
Local jimpleLocal = new JimpleLocal("handler",type);//takes care of handler
482

483     //make reference to a method of name get takes one int arg belongs to DavaSuperHandler
484
ArrayList tempList = new ArrayList();
485     tempList.add(IntType.v());
486     SootMethodRef getMethodRef = makeMethodRef("get",tempList);
487
488     List tempArgList = null;
489
490     Iterator typeIt = argsTwoTypes.iterator();
491     while(typeIt.hasNext()){
492         Type tempType = (Type)typeIt.next();
493
494         DIntConstant arg = DIntConstant.v(count,IntType.v());//takes care of the index
495
count++;
496         tempArgList = new ArrayList();
497         tempArgList.add(arg);
498
499         DVirtualInvokeExpr tempInvokeExpr =
500         new DVirtualInvokeExpr(jimpleLocal,getMethodRef,tempArgList,new HashSet());
501
502         //System.out.println("Type is:"+tempType);
503
//System.out.println("VirtualInvoke for this is:"+tempInvokeExpr);
504

505
506         //NECESASARY CASTING OR RETRIEVAL OF PRIM TYPES TO BE DONE HERE
507
Value toAddExpr = null;
508         if(tempType instanceof RefType){
509         //System.out.println("This is a reftype:"+tempType);
510
toAddExpr = new GCastExpr(tempInvokeExpr,tempType);
511         }
512         else if(tempType instanceof PrimType){
513         //The argument has a primType however get will return an object
514
//Cast to Wrapper class and then extract primtype
515
//System.out.println("This is a primType:"+tempType);
516
Type wrapperType=null;
517         
518         
519         PrimType t = (PrimType)tempType;
520         //BooleanType, ByteType, CharType, DoubleType, FloatType, IntType, LongType, ShortType
521

522                 if (t == BooleanType.v()){
523             Value tempExpr = new GCastExpr(tempInvokeExpr,RefType.v("java.lang.Boolean"));
524             //booleanValue
525

526             SootMethod tempMethod = new SootMethod("booleanValue",new ArrayList(),BooleanType.v());
527             tempMethod.setDeclaringClass(new SootClass("java.lang.Boolean"));
528
529             SootMethodRef tempMethodRef = tempMethod.makeRef();
530             toAddExpr =
531             new DVirtualInvokeExpr(tempExpr,tempMethodRef,new ArrayList(),new HashSet());
532         }
533                 else if (t == ByteType.v()){
534             Value tempExpr = new GCastExpr(tempInvokeExpr,RefType.v("java.lang.Byte"));
535             //byteValue
536

537             SootMethod tempMethod = new SootMethod("byteValue",new ArrayList(),ByteType.v());
538             tempMethod.setDeclaringClass(new SootClass("java.lang.Byte"));
539
540             SootMethodRef tempMethodRef = tempMethod.makeRef();
541             toAddExpr =
542             new DVirtualInvokeExpr(tempExpr,tempMethodRef,new ArrayList(),new HashSet());
543         }
544                 else if (t == CharType.v()){
545             Value tempExpr = new GCastExpr(tempInvokeExpr,RefType.v("java.lang.Character"));
546             //charValue
547

548             SootMethod tempMethod = new SootMethod("charValue",new ArrayList(),CharType.v());
549             tempMethod.setDeclaringClass(new SootClass("java.lang.Character"));
550
551             SootMethodRef tempMethodRef = tempMethod.makeRef();
552             toAddExpr =
553             new DVirtualInvokeExpr(tempExpr,tempMethodRef,new ArrayList(),new HashSet());
554         }
555                 else if (t == DoubleType.v()){
556             Value tempExpr = toAddExpr = new GCastExpr(tempInvokeExpr,RefType.v("java.lang.Double"));
557             //doubleValue
558

559             SootMethod tempMethod = new SootMethod("doubleValue",new ArrayList(),DoubleType.v());
560             tempMethod.setDeclaringClass(new SootClass("java.lang.Double"));
561
562             SootMethodRef tempMethodRef = tempMethod.makeRef();
563             toAddExpr =
564             new DVirtualInvokeExpr(tempExpr,tempMethodRef,new ArrayList(),new HashSet());
565         }
566                 else if (t == FloatType.v()){
567             Value tempExpr = new GCastExpr(tempInvokeExpr,RefType.v("java.lang.Float"));
568             //floatValue
569

570             SootMethod tempMethod = new SootMethod("floatValue",new ArrayList(),FloatType.v());
571             tempMethod.setDeclaringClass(new SootClass("java.lang.Float"));
572
573             SootMethodRef tempMethodRef = tempMethod.makeRef();
574             toAddExpr =
575             new DVirtualInvokeExpr(tempExpr,tempMethodRef,new ArrayList(),new HashSet());
576         }
577                 else if (t == IntType.v()){
578             Value tempExpr = new GCastExpr(tempInvokeExpr,RefType.v("java.lang.Integer"));
579             //intValue
580

581             SootMethod tempMethod = new SootMethod("intValue",new ArrayList(),IntType.v());
582             tempMethod.setDeclaringClass(new SootClass("java.lang.Integer"));
583
584             SootMethodRef tempMethodRef = tempMethod.makeRef();
585             toAddExpr =
586             new DVirtualInvokeExpr(tempExpr,tempMethodRef,new ArrayList(),new HashSet());
587         }
588                 else if (t == LongType.v()){
589             Value tempExpr = new GCastExpr(tempInvokeExpr,RefType.v("java.lang.Long"));
590             //longValue
591

592             SootMethod tempMethod = new SootMethod("longValue",new ArrayList(),LongType.v());
593             tempMethod.setDeclaringClass(new SootClass("java.lang.Long"));
594
595             SootMethodRef tempMethodRef = tempMethod.makeRef();
596             toAddExpr =
597             new DVirtualInvokeExpr(tempExpr,tempMethodRef,new ArrayList(),new HashSet());
598         }
599                 else if (t == ShortType.v()){
600             Value tempExpr = new GCastExpr(tempInvokeExpr,RefType.v("java.lang.Short"));
601             //shortValue
602

603             SootMethod tempMethod = new SootMethod("shortValue",new ArrayList(),ShortType.v());
604             tempMethod.setDeclaringClass(new SootClass("java.lang.Short"));
605
606             SootMethodRef tempMethodRef = tempMethod.makeRef();
607             toAddExpr =
608             new DVirtualInvokeExpr(tempExpr,tempMethodRef,new ArrayList(),new HashSet());
609         }
610                 else {
611             throw new DecompilationException("Unhandle primType:"+tempType);
612         }
613         }
614         else{
615         throw new DecompilationException("The type:"+tempType+" was not a reftye or primtype. PLEASE REPORT.");
616         }
617
618         if(toAddExpr == null)
619         throw new DecompilationException("UNABLE TO CREATE TOADDEXPR:"+tempType);
620
621
622         //the above virtualInvokeExpr is one of the args for the constructor
623
argsForConstructor.add(toAddExpr);
624     }
625
626     //we are done with creating all necessary args to the virtualinvoke expr constructor
627

628     DVirtualInvokeExpr virtualInvoke = new DVirtualInvokeExpr(originalConstructorExpr.getBase(),superConstructor.makeRef(),
629                               argsForConstructor,new HashSet());
630
631     //set the constructors constructorExpr
632
newConstructorDavaBody.set_ConstructorExpr(virtualInvoke);
633
634     //create Invoke Stmt with virtualInvoke as the expression
635
GInvokeStmt s = new GInvokeStmt(virtualInvoke);
636     
637     newConstructorDavaBody.set_ConstructorUnit((Unit)s);
638
639     //return true if super call created
640
return true;
641     }
642
643     private void finalizeConstructor(){
644     //set davaBody...totally redundant but have to do as this is checked by toString of ASTMethodNode
645
newASTConstructorMethod.setDavaBody(newConstructorDavaBody);
646
647     newConstructorDavaBody.getUnits().clear();
648     newConstructorDavaBody.getUnits().addLast(newASTConstructorMethod);
649     
650     System.out.println("Setting declaring class of method"+newConstructor.getSubSignature());
651     newConstructor.setDeclaringClass(originalSootClass);
652
653     //run all the analysis on the newly created method
654
//commenting as analyzeAST will be invoked onthis once its added to the SootClass
655
//newConstructorDavaBody.analyzeAST(newASTConstructorMethod);
656
}
657
658
659     //method should return false if the PreInit body(ASTBody that is) is empty meaning there is no need to create it all
660
private boolean finalizePreInitMethod(){
661     //set davaBody...totally redundant but have to do as this is checked by toString of ASTMethodNode
662
newASTPreInitMethod.setDavaBody(newPreInitDavaBody);
663
664
665     //newPreInitDavaBody is the active body
666
newPreInitDavaBody.getUnits().clear();
667     newPreInitDavaBody.getUnits().addLast(newASTPreInitMethod);
668     
669             
670     //run all the analysis on the newly created method
671
// newPreInitDavaBody.analyzeAST(newASTPreInitMethod);
672

673
674
675
676
677
678
679
680
681     //check whether there is something in side the ASTBody
682
//if its empty (maybe there were only declarations and that got removed
683
//then no point in creating the preInit method
684
List subBodies = (List)newASTPreInitMethod.get_SubBodies();
685     if(subBodies.size()!=1)
686         return false;
687
688     List body = (List)subBodies.get(0);
689
690     //body is NOT allowed to contain one declaration node with whatever in it
691
//after that it is NOT allowed all ASTStatement nodes with empty bodies
692

693     Iterator it = body.iterator();
694     boolean empty = true; //indicating that method is empty
695

696     while(it.hasNext()){
697         ASTNode tempNode = (ASTNode)it.next();
698         if(!(tempNode instanceof ASTStatementSequenceNode)){
699         //found some node other than stmtseq...body not empty return true
700
empty = false;
701         break;
702         }
703
704         List stmts = ((ASTStatementSequenceNode)tempNode).getStatements();
705
706         //all declaration stmts are allowed
707
Iterator stmtIt = stmts.iterator();
708         while(stmtIt.hasNext()){
709         AugmentedStmt as = (AugmentedStmt)stmtIt.next();
710         Stmt s = as.get_Stmt();
711         if(!(s instanceof DVariableDeclarationStmt)){
712             empty=false;
713             break;
714         }
715         }
716         if(!empty)
717         break;
718     }
719
720     if(empty){
721         //System.out.println("Method is empty not creating it");
722
return false;//should not be creating the method
723
}
724          
725     //about to return true enter all DavaSuperHandler stmts to make it part of the preinit method
726
createDavaStoreStmts();
727     return true;
728     }
729
730
731
732
733
734
735
736
737
738
739     public void createNewASTConstructor(ASTStatementSequenceNode initNode){
740
741     List newConstructorBody = new ArrayList();
742
743     //add any statements following the this.<init> statement
744
List newStmts = new ArrayList();
745
746     Iterator it = initNode.getStatements().iterator();
747     while(it.hasNext()){
748         AugmentedStmt augStmt = (AugmentedStmt)it.next();
749         Stmt stmtTemp = augStmt.get_Stmt();
750         if(stmtTemp == originalConstructorUnit){
751         break;
752         }
753     }
754     while(it.hasNext()){
755         /*
756           notice we dont need to clone these because these will be removed from the other method from which
757           we are copying these
758         */

759         newStmts.add(it.next());
760     }
761     if(newStmts.size()>0){
762         newConstructorBody.add(new ASTStatementSequenceNode(newStmts));
763     }
764
765
766
767
768     //adding body Y now
769
List originalASTMethodSubBodies = (List)originalASTMethod.get_SubBodies();
770     if(originalASTMethodSubBodies.size() != 1)
771         throw new CorruptASTException("size of ASTMethodNode subBody not 1");
772
773     List oldASTBody = (List)originalASTMethodSubBodies.get(0);
774
775     it = oldASTBody.iterator();
776     boolean sanity=false;
777     while(it.hasNext()){
778         //going through originalASTMethodNode's ASTNodes
779
ASTNode tempNode = (ASTNode)it.next();
780         
781         //enter only if its not the initNode
782
if(tempNode instanceof ASTStatementSequenceNode){
783         if( (((ASTStatementSequenceNode)tempNode).getStatements()).equals(initNode.getStatements()) ){
784             sanity = true;
785             break;
786         }
787         }
788     }
789
790     if(!sanity){
791         //means we never found the initNode which shouldnt happen
792
throw new DecompilationException("never found the init node");
793     }
794
795     //so we have found the init node
796
//Y are all the nodes following the initNode
797
while(it.hasNext()){
798         newConstructorBody.add(it.next());
799     }
800
801
802     
803
804
805
806
807     //setDeclarations in newNode
808
//The LocalVariableCleaner which is called in the end of DavaBody will clear up any declarations that are not required
809

810     List newConstructorDeclarations = new ArrayList();
811     Iterator originalDeclarationsIterator = originalASTMethod.getDeclarations().getStatements().iterator();
812     while(originalDeclarationsIterator.hasNext()){
813         AugmentedStmt as = (AugmentedStmt)originalDeclarationsIterator.next();
814         DVariableDeclarationStmt varDecStmt = (DVariableDeclarationStmt)as.get_Stmt();
815         newConstructorDeclarations.add(new AugmentedStmt((DVariableDeclarationStmt)varDecStmt.clone()));
816     }
817     ASTStatementSequenceNode newDecs = new ASTStatementSequenceNode(new ArrayList());
818     if(newConstructorDeclarations.size()>0){
819         newDecs = new ASTStatementSequenceNode(newConstructorDeclarations);
820         //DONT FORGET TO SET THE DECLARATIONS IN THE METHOD ONCE IT IS CREATED
821
//newASTConstructorMethod.setDeclarations(newDecs);
822

823         //declarations are always the first element
824
newConstructorBody.add(0,newDecs);
825     }
826
827
828     //so we have any declarations followed by body Y
829

830
831     //have to put the newConstructorBody into an list of subBodies which goes into the newASTConstructorMethod
832
newASTConstructorMethod = new ASTMethodNode(newConstructorBody);
833
834     //dont forget to set the declarations
835
newASTConstructorMethod.setDeclarations(newDecs);
836     }
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874     private void createNewConstructor(){
875     
876     //the constructor name has to be <init>
877
String JavaDoc uniqueName = "<init>";
878
879     //NOTICE args of this constructor are argsOne followed by the DavaSuperHandler
880

881     List args = new ArrayList();
882     args.addAll(argsOneTypes);
883
884     //create new ReftType for DavaSuperHandler
885
RefType type = (new SootClass("DavaSuperHandler")).getType();
886     args.add(type);
887
888     //create SOOTMETHOD
889
newConstructor = new SootMethod(uniqueName,args,IntType.v());
890
891     //set the declaring class of new method to be the originalSootClass
892
newConstructor.setDeclaringClass(originalSootClass);
893
894     //set method to public
895
newConstructor.setModifiers(soot.Modifier.PUBLIC);
896
897     //initalize a new DavaBody, notice this causes all DavaBody vars to be null
898
newConstructorDavaBody = Dava.v().newBody(newConstructor);
899
900     //setting params is really important if you want the args to have proper names in the new method
901

902     //make a copy of the originalHashMap
903
Map tempMap = new HashMap();
904         Iterator typeIt = argsOneTypes.iterator();
905         int count = 0;
906         while (typeIt.hasNext()) {
907             Type t = (Type) typeIt.next();
908         
909         tempMap.put(new Integer JavaDoc(count),originalPMap.get(new Integer JavaDoc(count)));
910         count++;
911     }
912
913     //add the DavaSuperHandler var name in the Parameters
914
tempMap.put(new Integer JavaDoc(argsOneTypes.size()),"handler");
915
916     //add the ParamMap to the constructor's DavaBody
917
newConstructorDavaBody.set_ParamMap(tempMap);
918
919     //set as activeBody
920
newConstructor.setActiveBody(newConstructorDavaBody);
921     }
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943     /*
944      * January 23rd New Algorithm
945      * Leave originalASTMethod unchanged
946      * Clone everything and copy only those which are needed in the newASTPreInitMethod
947      */

948     private void createNewASTPreInitMethod(ASTStatementSequenceNode initNode){
949     List newPreinitBody = new ArrayList();
950     //start adding ASTNodes into newPreinitBody from the originalASTMethod's body until we reach initNode
951

952     List originalASTMethodSubBodies = (List)originalASTMethod.get_SubBodies();
953     if(originalASTMethodSubBodies.size() != 1)
954         throw new CorruptASTException("size of ASTMethodNode subBody not 1");
955
956     List oldASTBody = (List)originalASTMethodSubBodies.get(0);
957
958     Iterator it = oldASTBody.iterator();
959     boolean sanity=false;
960     while(it.hasNext()){
961         //going through originalASTMethodNode's ASTNodes
962
ASTNode tempNode = (ASTNode)it.next();
963         
964         //enter only if its not the initNode
965
if(tempNode instanceof ASTStatementSequenceNode){
966         if( (((ASTStatementSequenceNode)tempNode).getStatements()).equals(initNode.getStatements()) ){
967             sanity = true;
968             break;
969         }
970         else{
971             //this was not the initNode so we add
972
newPreinitBody.add(tempNode);
973         }
974         }
975         else{
976         //not a stmtseq so simply add it
977
newPreinitBody.add(tempNode);
978         }
979     }
980     if(!sanity){
981         //means we never found the initNode which shouldnt happen
982
throw new DecompilationException("never found the init node");
983     }
984     
985
986     //at this moment newPreinitBody contains all of X except for any stmts above the this.init call in the stmtseq node
987
//copy those
988
List newStmts = new ArrayList();
989
990     it = initNode.getStatements().iterator();
991     while(it.hasNext()){
992         AugmentedStmt augStmt = (AugmentedStmt)it.next();
993         Stmt stmtTemp = augStmt.get_Stmt();
994         if(stmtTemp == originalConstructorUnit){
995         break;
996         }
997         //adding any stmt until constructorUnit into topList for newMethodNode
998
/*
999           notice we dont need to clone these because these will be removed from the other method from which
1000          we are copying these
1001        */

1002        newStmts.add(augStmt);
1003    }
1004    if(newStmts.size()>0){
1005        newPreinitBody.add(new ASTStatementSequenceNode(newStmts));
1006    }
1007
1008
1009
1010
1011    //setDeclarations in newNode
1012
//The LocalVariableCleaner which is called in the end of DavaBody will clear up any declarations that are not required
1013
List newPreinitDeclarations = new ArrayList();
1014    Iterator originalDeclarationsIterator = originalASTMethod.getDeclarations().getStatements().iterator();
1015    while(originalDeclarationsIterator.hasNext()){
1016        AugmentedStmt as = (AugmentedStmt)originalDeclarationsIterator.next();
1017        DVariableDeclarationStmt varDecStmt = (DVariableDeclarationStmt)as.get_Stmt();
1018        newPreinitDeclarations.add(new AugmentedStmt((DVariableDeclarationStmt)varDecStmt.clone()));
1019    }
1020    ASTStatementSequenceNode newDecs = new ASTStatementSequenceNode(new ArrayList());
1021    if(newPreinitDeclarations.size()>0){
1022        newDecs = new ASTStatementSequenceNode(newPreinitDeclarations);
1023        //DONT FORGET TO SET THE DECLARATIONS IN THE METHOD ONCE IT IS CREATED
1024
//newASTPreInitMethod.setDeclarations(newDecs);
1025

1026        //when we copied the body X the first Node copied was the Declarations from the originalASTMethod
1027
//replace that with this new one
1028

1029        newPreinitBody.remove(0);
1030        newPreinitBody.add(0,newDecs);
1031    }
1032
1033
1034    //At this moment we have the newPreInitBody containing declarations followed by code X
1035
//we need to check whether this actually contains anything cos otherwise super is infact the first stmt
1036
if(newPreinitBody.size()<1){
1037        //System.out.println("Method node empty doing nothing returning");
1038
newASTPreInitMethod = null;//meaning ASTMethodNode for this method not created
1039
return;
1040    }
1041
1042
1043    //so we have any declarations followed by body X
1044

1045
1046    //NEXT THING SHOULD BE CODE TO CREATE A DAVAHANDLER AND STORE THE ARGS TO SUPER IN IT
1047

1048    //HOWEVER WE WILL DELAY THIS TILL UNTIL WE ARE READY TO FINALIZE the PREINIT
1049

1050    //reason for delaying is that even though we know that the body is not empty the body
1051
//could be made empty by the transformations which act in the finalize method
1052

1053
1054    
1055    //have to put the newPreinitBody into an list of subBodies which goes into the newASTPreInitMethod
1056
newASTPreInitMethod = new ASTMethodNode(newPreinitBody);
1057    
1058    //dont forget to set the declarations
1059
newASTPreInitMethod.setDeclarations(newDecs);
1060
1061    }
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092    /*
1093     * Create a unique private static method name starts with preInit
1094     */

1095    private void createSootPreInitMethod(){
1096    //get a unique name for the method
1097
String JavaDoc uniqueName = getUniqueName();
1098
1099    //NOTICE WE ARE DEFINING ARGS AS SAME AS THE ORIGINAL METHOD
1100
newSootPreInitMethod = new SootMethod(uniqueName,argsOneTypes,(new SootClass("DavaSuperHandler")).getType());
1101
1102
1103    //set the declaring class of new method to be the originalSootClass
1104
newSootPreInitMethod.setDeclaringClass(originalSootClass);
1105
1106    //set method to private and static
1107
newSootPreInitMethod.setModifiers(soot.Modifier.PRIVATE | soot.Modifier.STATIC);
1108
1109    //initalize a new DavaBody, notice this causes all DavaBody vars to be null
1110
newPreInitDavaBody = Dava.v().newBody(newSootPreInitMethod);
1111
1112    //setting params is really important if you want the args to have proper names in the new method
1113
newPreInitDavaBody.set_ParamMap(originalPMap);
1114
1115    //set as activeBody
1116
newSootPreInitMethod.setActiveBody(newPreInitDavaBody);
1117    }
1118    
1119
1120
1121
1122
1123    /*
1124     * Check the sootClass that it doesnt have a name we have suggested
1125     * ALSO VERY IMPORTANT TO CHECK THE NAMES IN THE SOOTMETHODSADDED Variable since these will be added
1126     * to this sootclass by the PackManager
1127     */

1128    private String JavaDoc getUniqueName(){
1129    String JavaDoc toReturn = "preInit";
1130    int counter=0;
1131
1132    List methodList = originalSootClass.getMethods();
1133
1134    boolean done = false; //havent found the name
1135
while(!done){//as long as name not found
1136
done = true; //assume name found
1137
Iterator it = methodList.iterator();
1138        while(it.hasNext()){
1139        Object JavaDoc temp = it.next();
1140        if(temp instanceof SootMethod){
1141            SootMethod method = (SootMethod)temp;
1142            String JavaDoc name = method.getName();
1143            if(toReturn.compareTo(name)==0){
1144            //method exists with this name so change the name
1145
counter++;
1146            toReturn = "preInit"+counter;
1147            done = false; //name was not found
1148
break;//breaks the inner while since the name has been changed
1149
}
1150        }
1151        else
1152            throw new DecompilationException("SootClass returned a non SootMethod method");
1153        }
1154        
1155        //if we get here this means that the orignal names are different
1156
//check the to be added names also
1157
it = G.v().SootMethodsAdded.iterator();
1158        while(it.hasNext()){
1159        //are sure its a sootMethod
1160
SootMethod method = (SootMethod)it.next();
1161        String JavaDoc name = method.getName();
1162        if(toReturn.compareTo(name)==0){
1163            //method exists with this name so change the name
1164
counter++;
1165            toReturn = "preInit"+counter;
1166            done = false; //name was not found
1167
break;//breaks the inner while since the name has been changed
1168
}
1169        }
1170        
1171    }// end outer while
1172
return toReturn;
1173    }
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187    /*
1188     * Create the following code:
1189     *
1190     * DavaSuperHandler handler;
1191     * handler = new DavaSuperHandler();
1192     * //code to evaluate all args in args2
1193     *
1194     * //evaluate 1st arg in args2
1195     * ---------
1196     * handler.store(firstArg);
1197     *
1198     * //evaluate 2nd arg in args2
1199     * ---------
1200     * handler.store(secondArg);
1201     *
1202     * //AND SO ON TILL ALL ARGS ARE FINISHED
1203     *
1204     * return handler;
1205     *
1206     */

1207
1208
1209    private void createDavaStoreStmts(){
1210    List davaHandlerStmts = new ArrayList();
1211
1212
1213    //create object of DavaSuperHandler handler
1214
SootClass sootClass = new SootClass("DavaSuperHandler");
1215
1216    Type localType = sootClass.getType();
1217    Local newLocal = new JimpleLocal("handler",localType);
1218
1219
1220
1221
1222    /*
1223      Create * DavaSuperHandler handler; *
1224    */

1225    DVariableDeclarationStmt varStmt = null;
1226    varStmt = new DVariableDeclarationStmt(localType,newPreInitDavaBody);
1227    varStmt.addLocal(newLocal);
1228    AugmentedStmt as = new AugmentedStmt(varStmt);
1229    davaHandlerStmts.add(as);
1230
1231
1232
1233
1234    /*
1235     * create * handler = new DavaSuperHandler(); *
1236     */

1237    
1238    //create RHS
1239
DNewInvokeExpr invokeExpr =
1240        new DNewInvokeExpr(RefType.v(sootClass),makeMethodRef("DavaSuperHandler",new ArrayList()),new ArrayList());
1241
1242    //create LHS
1243
GAssignStmt initialization = new GAssignStmt(newLocal,invokeExpr);
1244
1245    //add to stmts
1246
davaHandlerStmts.add(new AugmentedStmt(initialization));
1247
1248
1249
1250
1251
1252
1253
1254    /*
1255     * create * handler.store(firstArg); *
1256     */

1257
1258
1259
1260
1261    //best done in a loop for all args
1262
Iterator typeIt = argsTwoTypes.iterator();
1263    Iterator valIt = argsTwoValues.iterator();
1264
1265    //make reference to a method of name store takes one Object arg belongs to DavaSuperHandler
1266

1267    ArrayList tempList = new ArrayList();
1268    tempList.add(RefType.v("java.lang.Object"));//SHOULD BE OBJECT
1269

1270    SootMethod method = new SootMethod("store",tempList,VoidType.v());
1271
1272    //set the declaring class of new method to be the DavaSuperHandler class
1273
method.setDeclaringClass(sootClass);
1274    SootMethodRef getMethodRef = method.makeRef();
1275
1276
1277    //everything is ready all we need is the object argument before we can create the invokeStmt with the invokeexpr
1278
//once that is done wrap it in augmented stmt and add to davaHandlerStmt
1279

1280
1281    while(typeIt.hasNext() && valIt.hasNext()){
1282        Type tempType = (Type)typeIt.next();
1283        Value tempVal = (Value)valIt.next();
1284
1285        if(tempType instanceof RefType){
1286        //simply add this to the handler using handler.store(tempVal);
1287
//System.out.println("This is a reftype:"+tempType);
1288

1289        davaHandlerStmts.add(createAugmentedStmtToAdd(newLocal,getMethodRef,tempVal));
1290        }
1291        else if(tempType instanceof PrimType){
1292        //The value is a primitive type
1293
//create wrapper object new Integer(tempVal)
1294
PrimType t = (PrimType)tempType;
1295        
1296        //create ArgList to be sent to DNewInvokeExpr constructor
1297
ArrayList argList = new ArrayList();
1298        argList.add(tempVal);
1299
1300        //BooleanType, ByteType, CharType, DoubleType, FloatType, IntType, LongType, ShortType
1301
if (t == BooleanType.v()){
1302
1303            //create TypeList to be sent to makeMethodRef
1304
ArrayList typeList = new ArrayList();
1305            typeList.add(IntType.v());
1306            
1307            DNewInvokeExpr argForStore =
1308            new DNewInvokeExpr(RefType.v("java.lang.Boolean"),
1309                       makeMethodRef("Boolean",typeList),argList);
1310            
1311            davaHandlerStmts.add(createAugmentedStmtToAdd(newLocal,getMethodRef,argForStore));
1312        }
1313        else if (t == ByteType.v()){
1314            //create TypeList to be sent to makeMethodRef
1315
ArrayList typeList = new ArrayList();
1316            typeList.add(ByteType.v());
1317
1318            DNewInvokeExpr argForStore =
1319            new DNewInvokeExpr(RefType.v("java.lang.Byte"),
1320                             makeMethodRef("Byte",typeList),argList);
1321              
1322            davaHandlerStmts.add(createAugmentedStmtToAdd(newLocal,getMethodRef,argForStore));
1323
1324        }
1325        else if (t == CharType.v()){
1326            //create TypeList to be sent to makeMethodRef
1327
ArrayList typeList = new ArrayList();
1328            typeList.add(CharType.v());
1329
1330            DNewInvokeExpr argForStore =
1331            new DNewInvokeExpr(RefType.v("java.lang.Character"),
1332                             makeMethodRef("Character",typeList),argList);
1333              
1334            davaHandlerStmts.add(createAugmentedStmtToAdd(newLocal,getMethodRef,argForStore));
1335        }
1336        else if (t == DoubleType.v()){
1337            //create TypeList to be sent to makeMethodRef
1338
ArrayList typeList = new ArrayList();
1339            typeList.add(DoubleType.v());
1340
1341            DNewInvokeExpr argForStore =
1342            new DNewInvokeExpr(RefType.v("java.lang.Double"),
1343                             makeMethodRef("Double",typeList),argList);
1344              
1345            davaHandlerStmts.add(createAugmentedStmtToAdd(newLocal,getMethodRef,argForStore));
1346        }
1347        else if (t == FloatType.v()){
1348            //create TypeList to be sent to makeMethodRef
1349
ArrayList typeList = new ArrayList();
1350            typeList.add(FloatType.v());
1351
1352            DNewInvokeExpr argForStore =
1353            new DNewInvokeExpr(RefType.v("java.lang.Float"),
1354                             makeMethodRef("Float",typeList),argList);
1355            
1356            davaHandlerStmts.add(createAugmentedStmtToAdd(newLocal,getMethodRef,argForStore));
1357        }
1358        else if (t == IntType.v()){
1359            //create TypeList to be sent to makeMethodRef
1360
ArrayList typeList = new ArrayList();
1361            typeList.add(IntType.v());
1362
1363            DNewInvokeExpr argForStore =
1364            new DNewInvokeExpr(RefType.v("java.lang.Integer"),
1365                             makeMethodRef("Integer",typeList),argList);
1366            
1367            davaHandlerStmts.add(createAugmentedStmtToAdd(newLocal,getMethodRef,argForStore));
1368        }
1369        else if (t == LongType.v()){
1370            //create TypeList to be sent to makeMethodRef
1371
ArrayList typeList = new ArrayList();
1372            typeList.add(LongType.v());
1373
1374            DNewInvokeExpr argForStore =
1375            new DNewInvokeExpr(RefType.v("java.lang.Long"),
1376                             makeMethodRef("Long",typeList),argList);
1377            
1378            davaHandlerStmts.add(createAugmentedStmtToAdd(newLocal,getMethodRef,argForStore));
1379        }
1380        else if (t == ShortType.v()){
1381            //create TypeList to be sent to makeMethodRef
1382
ArrayList typeList = new ArrayList();
1383            typeList.add(ShortType.v());
1384
1385            DNewInvokeExpr argForStore =
1386            new DNewInvokeExpr(RefType.v("java.lang.Short"),
1387                             makeMethodRef("Short",typeList),argList);
1388            
1389            davaHandlerStmts.add(createAugmentedStmtToAdd(newLocal,getMethodRef,argForStore));
1390        }
1391                else {
1392            throw new DecompilationException("UNHANDLED PRIMTYPE:"+tempType);
1393        }
1394        }//end of primitivetypes
1395
else{
1396        throw new DecompilationException("The type:"+tempType+" is neither a reftype or a primtype");
1397        }
1398    }//end of going through all the types and vals
1399
//sanity check
1400
if(typeIt.hasNext() || valIt.hasNext())
1401        throw new DecompilationException("Error creating DavaHandler stmts");
1402
1403
1404    /*
1405     * create * return handler; *
1406     */

1407
1408    GReturnStmt returnStmt = new GReturnStmt(newLocal);
1409    davaHandlerStmts.add(new AugmentedStmt(returnStmt));
1410
1411
1412    //the appropriate dava handler stmts are all in place within davaHandlerStmts
1413

1414    //store them in an ASTSTatementSequenceNode
1415
ASTStatementSequenceNode addedNode = new ASTStatementSequenceNode(davaHandlerStmts);
1416
1417
1418    //add to method body
1419
List subBodies = (List)newASTPreInitMethod.get_SubBodies();
1420    if(subBodies.size()!=1)
1421        throw new CorruptASTException("ASTMethodNode does not have one subBody");
1422    List body = (List)subBodies.get(0);
1423    body.add(addedNode);
1424
1425    newASTPreInitMethod.replaceBody(body);
1426    }
1427
1428
1429
1430
1431
1432    private AugmentedStmt createAugmentedStmtToAdd(Local newLocal,SootMethodRef getMethodRef, Value tempVal){
1433    ArrayList tempArgList = new ArrayList();
1434    tempArgList.add(tempVal);
1435    
1436    DVirtualInvokeExpr tempInvokeExpr =
1437        new DVirtualInvokeExpr(newLocal,getMethodRef,tempArgList,new HashSet());
1438    
1439    //create Invoke Stmt with virtualInvoke as the expression
1440
GInvokeStmt s = new GInvokeStmt(tempInvokeExpr);
1441    
1442    return new AugmentedStmt(s);
1443    }
1444
1445    public void debug(String JavaDoc methodName, String JavaDoc debug){
1446        if(DEBUG)
1447            System.out.println(methodName+ " DEBUG: "+debug);
1448    }
1449
1450}
Popular Tags