1 19 20 package edu.umd.cs.findbugs.ba.bcp; 21 22 23 24 31 public class ByteCodePattern { 32 private PatternElement first, last; 33 private int interElementWild; 34 private int numElements; 35 private int dummyVariableCount; 36 37 43 public ByteCodePattern add(PatternElement element) { 44 if (first != null) 45 addInterElementWild(); 46 addElement(element); 47 return this; 48 } 49 50 58 public ByteCodePattern addWild(int numWild) { 59 Wild wild = isLastWild(); 60 if (wild != null) 61 wild.setMinAndMax(0, numWild); 62 else 63 addElement(new Wild(numWild)); 64 return this; 65 } 66 67 76 public ByteCodePattern setInterElementWild(int numWild) { 77 this.interElementWild = numWild; 78 return this; 79 } 80 81 84 public PatternElement getFirst() { 85 return first; 86 } 87 88 96 public String dummyVariable() { 97 StringBuffer buf = new StringBuffer (); 98 buf.append("$_"); 99 buf.append(dummyVariableCount++); 100 return buf.toString(); 101 } 102 103 private void addInterElementWild() { 104 if (interElementWild > 0 && isLastWild() == null) 105 addElement(new Wild(interElementWild)); 106 } 107 108 private void addElement(PatternElement element) { 109 element.setIndex(numElements++); 110 if (first == null) { 111 first = last = element; 112 } else { 113 last.setNext(element); 114 last = element; 115 } 116 } 117 118 private Wild isLastWild() { 119 if (last != null && last instanceof Wild) 120 return (Wild) last; 121 else 122 return null; 123 } 124 } 125 126 | Popular Tags |