1 18 19 package alt.jiapi.instrumentor; 20 21 import java.util.Iterator ; 22 import java.util.List ; 23 24 import org.apache.log4j.Category; 25 26 import alt.jiapi.Instrumentor; 27 import alt.jiapi.Runtime; 28 import alt.jiapi.Rule; 29 import alt.jiapi.reflect.InstructionList; 30 31 62 public class GrepInstrumentor extends AbstractInstrumentor { 63 private static Category log = Runtime.getLogCategory(GrepInstrumentor.class); 64 65 private Strategy strategy; 66 67 68 77 public GrepInstrumentor(Strategy strategy) { 78 log.info("GrepInstrumentor: " + strategy); 79 80 this.strategy = strategy; 81 } 82 83 84 87 public void instrument(InstructionList il) { 88 log.info("Instrumenting " + getCurrentClass().getName() + "." + 89 il.getDeclaringMethod().getName()); 90 91 ((AbstractStrategy)strategy).setInstrumentation(getInstrumentation()); 92 List hotSpots = strategy.findHotSpots(il); 94 95 Iterator iter = hotSpots.iterator(); 96 while (iter.hasNext()) { 97 HotSpot hs = (HotSpot)iter.next(); 98 InstructionList view = il.createView(hs.getStart(), hs.getEnd()); 99 102 forward(view); 103 } 104 } 105 106 107 113 public void setResolution(String resolution) { 114 setResolutions(new String [] {resolution}); 115 } 116 117 123 public void setResolutions(String [] resolutions) { 124 if (strategy instanceof AbstractStrategy) { 125 ((AbstractStrategy)strategy).setResolutions(resolutions); 126 } 127 else { 128 log.warn("Cannot set resolutions to " + strategy + 132 ": It is not an instanceof AbstractStrategy"); 133 } 134 } 135 136 137 140 public String toString() { 141 return super.toString() + "#" + strategy.toString(); 142 } 143 } 144 | Popular Tags |