View Javadoc

1   /*
2    * Created on Aug 12, 2005 11:33:18 PM
3    *
4    * by Arnoldo Jose Muller Molina: arnoldoMuller@gmail.com
5    */
6   package org.kit.furia.fragment.soot;
7   import java.util.Iterator;
8   import java.util.LinkedList;
9   import java.util.List;
10  import java.util.Map;
11  import java.util.Vector;
12  
13  import soot.*;
14  /*
15      Furia-chan: An Open Source software license violation detector.    
16      Copyright (C) 2008 Kyushu Institute of Technology
17  
18    	This program is free software: you can redistribute it and/or modify
19      it under the terms of the GNU General Public License as published by
20      the Free Software Foundation, either version 3 of the License, or
21      (at your option) any later version.
22  
23      This program is distributed in the hope that it will be useful,
24      but WITHOUT ANY WARRANTY; without even the implied warranty of
25      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
26      GNU General Public License for more details.
27  
28      You should have received a copy of the GNU General Public License
29      along with this program.  If not, see <http://www.gnu.org/licenses/>.
30  */
31  /** 
32  	*  BodyStealer 
33  	*  
34    *  @author      Arnoldo Jose Muller Molina    
35  	* This class steals bodies from the transformation pipe, and recovers them
36    * so that we can generate fragments later.
37    */
38  public class BodyStealer extends BodyTransformer {
39      
40      private String signature;
41      private boolean found;
42      
43      private List<Body> bodies;
44      private boolean getAll = false;
45      
46      public BodyStealer(){
47          this("");
48          getAll = true;
49          
50      }
51      
52      public void reset(){
53      	found = false;
54      	signature = "";
55      
56          getAll = true;
57          bodies = new LinkedList<Body>();
58      }
59      
60      
61      
62      public BodyStealer(String methodSignature){
63          signature = methodSignature;
64          
65          found = false;
66          bodies = new LinkedList<Body>();
67      }
68      
69      public BodyStealer(String className, String methodSignature){
70          this("<" + className + ": " + methodSignature + ">");     
71      }
72      
73      protected void addBody(Body b){
74          
75          bodies.add(b);
76          
77      }
78      
79      /* (non-Javadoc)
80       * @see soot.BodyTransformer#internalTransform(soot.Body, java.lang.String, java.util.Map)
81       */
82      protected void internalTransform(Body b, String phaseName, Map options) {
83         
84          //G.v().out.println("Stealer In with: " + b.getMethod().getDeclaringClass().getName() + " " + b.getMethod().getSignature() );
85          //signature looks like: <furia.testsamples.T: int doubleLoop(int)>
86         if(getAll ||b.getMethod().getSignature().equals(signature) ){ 
87            
88             addBody(b);
89             found = true;
90             //G.v().out.println("Stealer: found your jewels");
91         }
92      }
93  
94      
95      /**
96       * Tells the stealer to steal all the bodies
97       *
98       */
99      public void gettAll(boolean getAll){
100         this.getAll = getAll;
101     }
102 
103     /**
104      * @return Returns the signature.
105      */
106     public String getSignature() {
107         return signature;
108     }
109 
110     /**
111      * @return Returns true if the body was found
112      */
113     public boolean isFound() {
114         return found;
115     }
116 
117     
118     public Iterator<Body> getIterator(){
119         return bodies.iterator();
120     }
121 
122 }