1 18 19 package alt.jiapi.instrumentor; 20 21 import java.util.ArrayList ; 22 import java.util.Iterator ; 23 import java.util.List ; 24 25 import org.apache.log4j.Category; 26 27 import alt.jiapi.Instrumentor; 28 import alt.jiapi.Runtime; 29 import alt.jiapi.reflect.InstructionList; 30 31 40 public class HeadInstrumentor extends AbstractInstrumentor { 41 private static Category log = Runtime.getLogCategory(HeadInstrumentor.class); 42 45 protected int instructionCount = 0; 46 47 51 public HeadInstrumentor() { 52 this(0); 53 } 54 55 60 public HeadInstrumentor(int instructionCount) { 61 log.info("Instruction count=" + instructionCount); 62 63 if (instructionCount < 0) { 64 throw new IllegalArgumentException (instructionCount + " < 0"); 65 } 66 67 this.instructionCount = instructionCount; 68 } 69 70 77 public void instrument(InstructionList il) { 78 log.info("Instrumenting " + getCurrentClass().getName() + "." + 79 il.getDeclaringMethod().getName()); 80 81 82 InstructionList view = null; 83 84 if (instructionCount > il.size()) { 85 log.warn("List size exceeded: instructions needed : " + 86 instructionCount + ", available " + il.size() + 87 ". Using all that is available."); 88 89 view = il.createView(0, il.size()); 90 } 91 else { 92 view = il.createView(0, instructionCount); 93 } 94 95 forward(view); 96 } 97 } 98 | Popular Tags |